procmail
[Top] [All Lists]

Re: Several newbie questions

1996-11-03 15:22:56
On Sat, 2 Nov 1996, paul milligan wrote:

     1)  I've seen a file .mailog referenced, but I don't have one, and I
don't know how to create it / add to it.  I'd love to be able to keep a
running summary ( by count only ) of what my script has done.

Please read the "procmailrc" man page, paying attention to the "LOGFILE"
"MAILDIR", "VERBOSE", and "LOGABSTRACT" variables.

     2)  Seeing as most email does not seem to have a 'Lines:' header, how
can I bounce on a size criteria ?  How about 'bounce if there's _any_
attached file ' ?

Procmail counts the lines itself, and so doesn't need, nor necessarily
believe any "Lines:" header, which is a header generated by news
posting software but not most mailers.

Use the "<" or ">" condition operators.  See the "procmailrc" man page.

     3)   How can I include the original body with the added messages I
create for bounces ?

To add new text to the existing body, you would "filter the body", using
a "fb" recipe.  Anytime you filter the body without reading the existing
body text completely, you must also use the "i" flag.  The following
recipes are examples:

    :0 fb               # add some text before the body
    | echo "This is a line of text before the body" ; \
      cat -

    :0 fb               # add some text after the body
    | cat - ; \
      echo "This is a line of text after the body"

    :0 fb               # catenate a canned message before the body
    | cat msg.txt -

    :0 fbi              # replace the body with a canned message
    | cat msg.txt

     4)  How can I bounce based on 'this person already sent me 'xxx' mails
today, looks like a bomb - bounce it' ?  Preferably with a message to
indicate the reason for the bounce.

You must count the number of mails receiped per address, and then if the 
the number exceeds a threshold, bounce it with a suitable reply.  Here
is a sample recipe (you will have to edit it to make it actually work):

    SPAMSITES='(spam.com|foo.org|blah.com)'     # sites to check
    MAXFROM=10                  # more than 10 mails/day from 
    :0                          # check for mail from a spam site
    * $ ^(From|Sender:|Reply-To:)(_dot_)*(_at_)(_dot_)*$SPAMSITES
    { # ok -- mail is from a possible spam site -- check # of occurances
      FROM=`formail -rtzxTo:`   # get the best from
      DATE=`date +%Y%m%d`               # get YYYYMMDD
      SUBJ=`formail -zxSubject:`        # get the subject
      FROMLOG=from.log          # logfile of FROM addresses
      :0ci:                     # log this message
      | echo "$FROM $DATE : $SUBJ" >>$FROMLOG
      # Find out how many message have been received today
      COUNT=`fgrep -c "$FROM $DATE" $FROMLOG`
      :0                        # see if we've received too many
      * $ -$MAXFROM^0
      * $  $COUNT^0
      { # count was exceeded - generate a reply
        :0                      # clean up the subject
        * SUBJ ?? Re: *\/[^ ].*
        { SUBJ=$MATCH }
        :0 fh                   # generate a reply header
        * $ !^X-Loop: *$LOGNAME(_at_)$HOST
        | formail -rt   -I"From: ($LOGNAME's Mail-Agent) $LOGNAME" \
                        -I"Subject: Re: $SUBJ" \
                        -I"Precedence: junk" \
                        -I"X-Loop: $LOGNAME(_at_)$HOST"
        :0 afb                  # generate a reply body
        | echo "Your message is being returned because you've sent me" ; \
          echo "too many message today. Your original message follows:" ; \
          cat -
        :0 a                    # send it off
        ! -t
        :0 E                    # no reply generated
        error.log               # keep an error log
      }
      # mail count is okay, forge on
    }
    # normal mail processing follows

The recipe works by keeping a log of all recieved mail, with a
single line of "$FROM $DATE : $SUBJ" being appended to the log file.
Then, if the number of lines with the "$FROM $DATE" string exceeds
a threshold, a reply is generated.  If any error in the reply, or
if a mail loop is detected, file the mail to "error.log".

     5)  What do the flags on the action line ( ! -oi -t ) mean ?  I don't
understand how that works.

These are arguments to the $SENDMAIL command, which is used as the
implicit command for a "forward" action "!".  The '-t' tells sendmail
to read the destination from the "To:" line, and "-oi" tells
sendmail not to treate a line of "." as an end-of-input.

     6)  How do I add line feeds to my generated messages ?

Put them in.  See the "echo" commands on the "filter body" recipes
above.

G'luck.

___________________________________________________________
Alan Stebbens <aks(_at_)sgi(_dot_)com>      http://reality.sgi.com/aks

<Prev in Thread] Current Thread [Next in Thread>