procmail
[Top] [All Lists]

Need a formula for forwarding and rejecting email from lists

2006-07-06 21:46:52
I tried posting this earlier, but I think it was before I was verified.
I'm a first time user/poster - TIA for any experts who give me a hand.

First of all, my ISP switched to Procmail a while back and I asked
them for some help setting up some rules and had no luck (you'd think
they would want to help their users set it up).

ISP's root .procmailrc in/for my tree (not actually indented [FormMail.conf
at end of post]):

        INCLUDERC=/etc/ALAquota/overquotarc # checks if
        RECIP=$1
        MAILDIR=$HOME/<domain>-mail
        INCLUDERC=.procmailrc

The RC file starts like this currently (where 'domain' is my domain name):

        <domain>-mail .procmailrc
        DOMAIN=(<domain>.com)
        INCLUDERC=.rc.local.init

followed by the forwarding rules way below in this post.

I need to set up the following for my domain:

1) from a list of legit users file, forward the email to anyone found in the
list to a single address - normally my home PC.  (Could be hard-coded in the
rc or like second example below).

Sample legit users file (indented here just for looks) :

        joe
        pete

or it more likely would include a forwarding address (doesn't matter which
method, although this one may be more flexible for many people and I want to
share it) :

        joe ForwardToUser(_at_)somedomain
        pete ForwardToUser(_at_)somedomain

2) There will also be a file of bad users with the same format.

3) processing goes like this:

        a) First check the legit users and forward the email if the name is
        found; then quit processing for that email.  IE: [if legit user,
        forward and exit]

        This was my best guess on the syntax:

                :0
                * ? formail -x"To:" \
                    | egrep -is -f legit.lst
                !myusername(_at_)homePC(_dot_)com

        Or would using $RECIP | egrep ... be more appropriate since To may not
        even be set in spam ?

        How would that change if the forwarding address was present in the
        legit file rather than hard-coded ????  I could grep the files before
        any of the tests and split the user/fwd-address and save in $GOOD_FWD
        and $BAD_FWD I suppose.

        b) Then check the bad users and send a rejection back to the email
        sender saying the user does not exist on this server (user not found).
        Also forward this email on as with the legit users until the script
        is verified and then this forwarding can be commented out.  Then quit
        processing for that email.  IE: [if bad user, (temporarily forward)
        and send reject to sender]

        I was going to try something like this, but not sure of the right
        syntax for the not found exit:

                :0
                * ? formail -x"To:" \
                    | egrep -is -f bad.lst
                !myusername(_at_)homePC(_dot_)com               # comment out 
later
                exit 67                         # is this the right way to give 
user not found ?

        How would that change if the forwarding address was present in the
        legit file rather than hard-coded (I assume the same code as the
        legit code would apply) ?

        c) If there isn't a hit on either of the above rules, then continue
        on with the normal rc processing which consists of a set of these
        type of forwarding rules (these can eventually be removed when the
        legit file is working, but not necessarily) :

                :0
                * $RECIP ?? ^^bill(_at_)$DOMAIN
                {
                        :0
                        !myusername(_at_)homePC(_dot_)com
                }

Also any ideas on how to easily test the resultant rules without causing
any failures in legit traffic would be nice.  I plan on doing it late at
night to minimize traffic.  I could write a script that would flip the
old and new rc files in and out which would also probably help minimize
failures while testing by keeping the test file in as brief a time as
possible till debugged.

Thanks to all responders.  I plan on sharing this with my fellow website
users if I can get the ISP to make it available to them, so generic is a
plus.

---------------------------------------------

Here's my FormMail.conf file - /home/<me>/ForMail.conf (where <me> is my
username and <domain> is my domain (comment lines removed):

[DEBUGGING]
0
[/DEBUGGING]

[postmaster]
<me>@<domain>.com
[/postmaster]

[allow_mail_to]
<domain>.com
[/allow_mail_to]

[recipient_alias]
<me>=><me>@<domain>.com
[/recipient_alias]

[send_confirmation_mail]
0
[/send_confirmation_mail]

[confirmation_text]
From: <me>@<domain>.com
Subject: Your Form Submission

Thank you for your submission.
[/confirmation_text]

---------------------------------------------

/home/<me>/<domain>-mail/.emailuserquotarc :

SHELL=/bin/sh

:0
* $RECIP ?? ^\/[^(_at_)]+
{ USER_= `echo $MATCH | tr A-Z a-z` }

:0
* $MAIN_DOMAIN ?? ^^^^
{
  :0
  * $RECIP ?? @\/.*
  {
    DOMAIN_= `echo $MATCH | tr A-Z a-z`
  }
  MAIN_DOMAIN=$DOMAIN_
}

:0
* ^To: +\/.*
{ TOLINE_="$MATCH" }

:0
* ^Subject[     ]*:[    ]+\/[^ ].+
{ SUBJ_="$MATCH" }

QUOTA=`grep -e "^${USER_}:" ../.mm/${MAIN_DOMAIN}.passwd | awk -F ":" '{t=\$4} E
ND {print t+0}'`   # fill in the number, in bytes
INBOXSIZE=`ls -l ${USER_} | awk '{t=\$5} END {print t+0}'`

:0
* $ -${INBOXSIZE}^0
* $ ${QUOTA}^0

{
    MAXMSG = $=
    :0
    * $ > ${MAXMSG}
    {
        LOG="Bouncing (message too big!)${NL}"
        :0h
        * !^FROM_DAEMON
         * !^X-Loop: outOfSpace
         |(formail -rtk  -A"X-Loop: outOfSpace" -A"Precedence: junk"  \
          -I"Subject: MESSAGE NOT DELIVERED: ${SUBJ_}"; \
         cat .quotareply ) | ${SENDMAIL} -f${RECIP} -t

        :0
         /dev/null

        HOST
       }
}
:0E
{
    LOG="Bouncing (inbox already full!)${NL}"
        :0h
        * !^FROM_DAEMON
        * !^X-Loop: outOfSpace
         |(formail -rtk  -A"X-Loop: outOfSpace" -A"Precedence: junk"  \
          -I"Subject: MESSAGE NOT DELIVERED: ${SUBJ_}"; \
         cat .quotareply ) | ${SENDMAIL} -f${RECIP} -t

         :0
         /dev/null

        HOST
}



____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail