"John P Connor" <john(_dot_)connor(_at_)icl(_dot_)net> writes:
I eventually worked out the following recipes:
...
:0
*
DELMAILBOX=| /usr/local/etc/procmail_process.pl
You can leave out that '*' line, as it's perfectly legal to have zero
conditions. Also, remember that procmail_process.pl should obtain the
username to be looked up from $ENV{'LOGNAME'}, and not from the To:
header in the incoming message (just think about the header on a
message from a mailing list).
...
OTO=`/usr/local/bin/formail -xTo: `
...
# If we haven't delivered locally, possibly forward the mail to another server
:0 E
* DELMAILBOX ?? @
|(formail -A "X-ServerInfo: $OTO" ; \
)|$SENDMAIL -oi $DELMAILBOX
You almost certainly want to be inserting the envelope recipient, not
the header recipient into the X-ServerInfo: field. You can find the
login of the user that procmail is running as in $LOGNAME. Combine
that with the appropriate domain (or even just $HOST) to get the
address to stick into the X-Serverinfo: header. Also, if you really
want the 'i' in "X-Serverinfo:" to be capitalized then you'll need
to put a '-' before it, as the canonical form for header names is
lowercase except for the first character and characters after '-'s.
Finallys, for paranoia, you should probably put a '--' before the
address argument to sendmail so that an address beginning with a minus
sign (which is quite legal) doesn't cause sendmail to treat it like an
option.
:0
* DELMAILBOX ?? @
| formail -A"X-Server-Info: $LOGNAME(_at_)$HOST" | \
$SENDMAIL $SENDMAILFLAGS -- $DELMAILBOX
# Bounce if non-local
:0 EWi
* ? test $DELMAILBOX = "INVALIDADDRESS"
|(formail -rkI "Subject: Returned Mail: the address $VIPTO is not valid.
Your message is attached" ; \
)|$SENDMAIL -oi -t -f postmaster(_at_)vip(_dot_)uk(_dot_)com
If the address is invalid then you should just return EX_USER (67) to
sendmail and let it generate the bounce message. Besides, you should
be sending the bounce message to the envelope sender, not the header
sender, which is what the above is doing. Sendmail will do that
corrently, watch for double-bounces, and attach the body when correct
to do so.
:0
* DELMAILBOX ?? ^^INVALIDADDRESS^^
{
EXITCODE = 67 # EX_USER
HOST # give up on delivery
}
Also, you probably want to put the following recipe at the bottom to
catch it when procmail_process.pl emits a bogus address.
# If we haven't delivered yet than procmail_process.pl is confused.
# Set our exitcode so that sendmail will bounce the message.
EXITCODE = 69 # EX_UNAVAILABLE
# Perhaps we should also send a note to root? (but that risks a big
# mailloop pile up if things really go wrong) Instead, we'll call
# "logger" with a log level of emergency to get attention. This will
# run when we actually exit.
TRAP = 'logger -p mail.emerg procmail_process.pl \
returned a bogus value "$DEFMAILBOX"'
# Okay, we've setup everything for when we exit. Do so now.
HOST
.. where procmail_process.pl always returns:
. nothing if the database is dead, so mail gets re-queued
. /var/mail/maildrop_file - so mail gets delivered locally
. an address with an @ in it - so mail is forwarded to its destination
server
. INVALIDADDRESS - which will hopefully bounce the mail.
What I still can't figure out is the final bit .. how to nicely bounce an
undeliverable mail in the correct fashion. Clearly what I currently
have is no good because the message IS NOT attached!
Hmm, I didn't see any recipes to enforce the 'nothing --> requeue' rule.
If you put the following right after the recipe where DELMAILBOX is
set, it should work:
:0
* DELMAILBOX ?? ^^^^
{
EXITCODE = 75 # EX_TEMPFAIL
HOST
}
Philip Guenther