procmail
[Top] [All Lists]

Forwarding via procmail

2005-06-20 13:48:12
We're trying to set up forwarding via procmail. (Specifically, we're using Horde to provide a web interface for letting users edit .forward and .procmailrc files. The new version of Horde no longer supports .forward and does everything via .procmailrc, so we need to figure out the "proper" way to do forwarding in .procmailrc.)

I've seen several different suggestions on the procmailex page, mailing lists, and various online sites on how to do forwarding via procmail, but I haven't seen anywhere that addresses all of the concerns I had with forwarding. I think that I've figured out the proper approach, and I was hoping that I could have my suggested solution checked over here before rolling it out for 100+ students.

Here's my approach:

First, if the address to forward to is invalid, then the bounce should go to the original sender, rather than to the forwarded address (since the forwarded address likely isn't checked, and since errors to the forwarded address will be forwarded to the invalid address, generating more errors, generating more forwards...). Using sendmail -f to set the envelope sender should do this.

Second, as an extra precaution, in case the above measure fails and the forwarded address gets error messages from an invalid forwarded-to address anyway, avoid forwarding anything from MAILER_DAEMON. This shouldn't affect most users - if they forwarding email because they aren't checking the account, then they probably aren't sending mail from that account either, so they shouldn't be receiving MAILER_DAEMON emails.

Third, use the X-Loop header to avoid forwarding loops, as described in procmailex.

Here's my procmailrc recipe (bits of which are lifted from pm-lib.sourceforge.net):

TAB     = "     "               # \t character, you will not see it.
WSPC    = " $TAB"               # whitespace in procmail: space + tab
SPC     = "[$WSPC]"             # Regexp space/tab
NSPC    = "[^$WSPC]"            # Negation, non-whitespace

##### Forwards #####
:0
{
       :0
       *$ ! ^From *\/$NSPC+
       *$ ! ^Sender: *\/$NSPC.*
       *$ ! ^From: *\/$NSPC.*
       *$ ! ^Reply-to: *\/$NSPC.*
       {
               OUTPUT = `formail -zxFrom:`
       }
       :0 E
       {
               OUTPUT = $MATCH
       }

       :0 c
       * !^FROM_DAEMON
       * !^X-Loop: localaddress
| formail -A"X-Loop: localaddress" | $SENDMAIL -oi -f $OUTPUT address-to-forward-to(_at_)example(_dot_)com
       :0 E
       $DEFAULT
       :0
       /dev/null
}

Should this approach work?

Thanks.

Josh Kelley

____________________________________________________________
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

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