procmail
[Top] [All Lists]

Re: Forwarding mail from user+foo to foo

1997-12-09 13:52:35
On Tue, 09 Dec 1997 10:27:44 -0800, rsr(_at_)macromedia(_dot_)com wrote:
I'm trying to write a procmail recipe that, when it receives mail
to me (rsr) of the form rsr+<foo>, will
A) If <foo> is one of a small number of keywords, do something
specific (for example, rsr+pgp will send my public key).

Tangentially, you might want to look at the user+box(_at_)host addressing
FAQ at <http://www.netusa.net/~eli/faqs/addressing.html> 

B) Otherwise, forward the mail to <foo>
Now the problem is:
A) I know how to make delivering recipes non-delivering, but I
don't know how to do it the other way around -- mark a
non-delivering recipe as delivering (so processing stops); 

This is trivial. Delivering to /dev/null should take care of any
superfluous undelivered messages (but a recipe which merely delivers
to /dev/null unconditionally is usually a sign that you're doing
something wrong). 
  But that is not the problem here. Your recipe is delivering alright,
but it might deliver additional copies of the message to your account
again, starting a new instance of Procmail which will again forward it
to the same address(es), etc. etc.

B) When I tried this:
MTO = `/usr/local/bin/formail -xTo | sed 's/rsr\+//' | sed 
's/\(_at_)(_dot_)*//'`
:0
* ^To:.*rsr+
| /usr/local/bin/formail -c -z -i "To: $MTO" | $SENDMAIL -oi -t 
I kept getting weird mail bounces (mostly mail loops).

You are telling sendmail to grab whatever addresses are in the headers
of the message. You are replacing To: with a new address, but if there
are Cc: fields, etc, Sendmail will read those, too. 
  As long as you are looping mail back to yourself, inserting an
X-Loop header and dropping out whenever you see it on inbound mail
should suffice.
  Alternatively, or additionally, you might want to make Sendmail
disregard the headers of the message and tell it to only deliver to
the address you give it on the command line, and nowhere else. As
another improvement, the sed stuff can be optimized out -- this is
quite a bit more efficient than your original solution:

    :0
    *   ^To:(.*\<)?rsr\+\/[^(_at_)]+@macromedia\.com
    * ! ^X-Loop: rsr(_at_)macromedia\(_dot_)com
    {
        :0    # Strip off "@macromedia.com" part from MATCH
        * MATCH ?? ^^\/[^(_at_)]+
        | formail -A"X-Loop: rsr(_at_)macromedia(_dot_)com" | \
          $SENDMAIL $SENDMAILFLAGS $MATCH
    }

If you don't expect the To: line to always contain a domain part, the
^To: matching will have to be changed slightly. I thought it would be
a good idea to explicitly look for a match immediately followed by
your domain name because it would not seem completely unlikely that
other messages might contain the four characters "rsr+" more or less
by accident. Obviously it's up to you to assess whether this risk is
real. If it's not, the recipe can be trimmed quite a bit.

You forgot to mention C) that this will not catch mail BCC:ed to one
of your plussed addresses, but I gather you're prepared to live with
that. 

/* era */

I think I'd like to suggest that you tell us what you envision to use
this for. Perhaps there would be better solutions around.

-- 
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>