procmail
[Top] [All Lists]

RE: selective mail forwarding

2003-02-22 04:04:22
Henson Sturgill <vgfan(_at_)rootshell(_dot_)be> writes:

1. forwarded any mails formatted with 'send to address(_at_)wherever' in the 
subject.  that is if the address is a valid e-mail address.

Unfortunately, this prevents the users from having a subject field.  You
can either add more processing to deal with a combined subject and
send-to, both in the Subject: field...

:0
* ^Subject: Send-to: \/(_dot_)*(_at_)[^ ]+
{
  SEND_TO="$MATCH"
  :0fw
  * ^Subject:(_dot_)*(_at_)[^ ]+\/.*
  | formail -I "To: $SEND_TO" -I "Subject: $MATCH"
}

...or you could have the users create a custom field (like X-To: or
Send-To: or something) and then rename it.  The advantage here is the
user can list multiple To: addresses, as well as Cc: and Bcc:

:0fw
* ^X-To:
| formail -I "To:" -I "Bcc:" -I "Cc:" -R "X-To: To:" -R "X-Cc: Cc:" -R "X-Bcc: 
Bcc:"

I wrote the above recipes so they would work as "stand alones", which
would be sufficient for testing purposes, but they're not very efficient
that way, especially given what I'm going to say regarding your second
point....


2. only forward addresses from aol users (it's embaressing to be one, they 
deserve a mail forwarding service!)

So, you're handling outbound mail, but you're not rewriting the From:
address, so all the users now look like they're sending from the
procmail user's account.  Plus, if someone tries to respond to that
email, you don't have any way to get it back to the originating user.

I'm assuming you want to have multiple users on this forwarding service,
and you have one or more domains assigned to it, so that 
fred245(_at_)aol(_dot_)com
can be registered with you as 
Fred_Rogers(_at_)forwardingservice(_dot_)com(_dot_)
This may not be the most efficient, but here's one way to handle it:

NR="is not registered with forwardingservice.com;"
CS="check spelling of address?"
RME="rejected message enclosed"
:0
* ^From \/[^ ]+
{
  FROM_="$MATCH"
}
:0
* ^Delivered-To: alias-\/.*
{
  SENTTO="$MATCH"
}
:0E
* ^Delivered-To: \/.*
{
  SENTTO="$MATCH"
}
:0
* SENTTO ?? outbound(_at_)forwardingservice\(_dot_)com
{
  # Outbound translation
  # forwardfile has format 
user(_at_)originaldomain(_dot_)com#useralias@forwardservice.com
  # where # is some character guaranteed not to be in an email address
  XADDRESS=`fgrep "$FROM_" forwardfile | sed -e 's/.*#//'`
  
  :0
  * XADDRESS ?? ^^$
  {
    # handle failed translation here (ie non-registered address in From_ )
    # probably want to do other stuff besides dumping to a folder
    :0c:
    non-registered-from

    :0W
    | sed -e 's/^/  /' | formail -A "From: 
postmaster(_at_)forwardingservice(_dot_)com" \
                                 -A "X-Loop: 
postmaster(_at_)forwardingservice(_dot_)com" \
                                 -A "To: $FROM_" \
                                 -A "Subject: $FROM_ $NR $RME" \
                       | $SENDMAIL $SENDMAILFLAGS -t
  }
  :0EW
  {
    # put one of my solutions from question #1 here, except leave off the filter
    # flag, and append the following at the end of the formail command:
    -I "From: $XADDRESS" | $SENDMAIL $SENDMAILFLAGS -t
  }
}
:0E
{
  # Inbound translation
  # assumes what I consider to be "well behaved" Delivered-To: fields YMMV
  XADDRESS=`fgrep "$SENTTO" forwardfile | sed -e 's/#.*//'`
  
  :0
  * XADDRESS ?? ^^$
  {
    # handle failed translation here (ie misspelled or non-registered address 
in SENTTO)
    # probably want to do other stuff besides dumping to a folder
    :0c:
    non-registered-to

    :0W
    | sed -e 's/^/  /' | formail -A "From: 
postmaster(_at_)forwardingservice(_dot_)com" \
                                 -A "X-Loop: 
postmaster(_at_)forwardingservice(_dot_)com" \
                                 -A "To: $FROM_" \
                                 -A "Subject: $SENTTO $NR $CS $RME" \
                       | $SENDMAIL $SENDMAILFLAGS -t
  }
  :0EW
  | formail -I "To: $XADDRESS" | $SENDMAIL $SENDMAILFLAGS -t
}


3. junk the mail after forwarding.  is it right that after you forward a 
mail it still romps through your other recipes?  i had to add the dev/null 
just to get rid of it.

You're having this problem because you put an (unnecessary) f flag in
your innermost recipe, telling it to be a filter, which returns the
output of the action (mail) back to procmail for additional processing.
Or maybe the $MATCH ?? isn't working.  btw you don't need to say $ in
front of MATCH when you use the ??

:0
* ^Subject: +send +to +\/[^ ]+
{
      :0
      * $MATCH ?? [A-Z0-9a-z]+(_at_)(_dot_)+\(_dot_)(net|com|edu|be)
      {
              :0fb
              * ^From: (_dot_)+(_at_)aol\(_dot_)com
              | mail $MATCH -s"forwarded mail"
      }

      :0a
      /dev/null
}

If you make any money off of this forwarding service, be sure to send me
a small but non-negligable percentage.

Jeff

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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