On Mon, 25 Nov 2002, Rakesh-Shah-Exch wrote:
There may be a better way of doing this. If some one has one please send it
to me so that I can Improve on this. But so far All I found on the net was
only one action that would forward all emails to one account or using
.forward files of individual users. Where as this can be used on the
mailhost of any Corporate server that host multiple domains and need to
migrate users from one domain to other at the same time allowing to forward
the old emails to new ones.
I'm by no means a procmail guru but there are a few things I see that
could make you recipe better. I picked most of these tidbits out of the
FAQ available here:
http://mirror.ncsa.uiuc.edu/procmail/ssjaaa/pm-tips.html
You define $FORMAIL but never actually use it. You should use it whenever
you call formail to eliminate the wasted cycles on shell lookups.
You use echo 15 times in your shell scripts when really it probably needs
to only be run once. With GNU echo add the -e switch and explicitly
define your newlines as needed. That will cut some overhead.
You should probably use some sort of loop prevention in your recipe. It
wouldn't surprise me to see user(_at_)b(_dot_)com use their old vacation recipe
from
a.com that claims a From of user(_at_)a(_dot_)com(_dot_)
I'm pretty sure you could do everything you want from within procmail
itself without spawning external shells (2?) except for a few sed or cat
calls.
You also extract the from, date, subject, and cc but never do anything
with them. Multiple formail calls are expensive. Use them or lose them.
:)
I would imagine some of the enhancements would look something like this
(WARNING, this code probably doesn't work out of the box):
SHELL=/usr/bin/sh
PATH=/usr/local/bin:/usr/local/sbin:/usr/ucb:/usr/bin
LOGFILE=/var/log/procmailog
VERBOSE=on
FORMAIL=/usr/local/bin/formail
SENDMAIL=/usr/lib/sendmail
SED=/bin/sed
POSTMASTER-A="postmaster(_at_)a(_dot_)com"
POSTMASTER-b="postmaster(_at_)b(_dot_)com"
:0H
* ! ^FROM_DAEMON
* $ ! ^X-Loop: $POSTMASTER
{
# Extract subject and assign it to SUBJECT
:0
* ^Subject:[ ]*\/[^ ].*
{
SUBJECT=$MATCH
}
:0
* ^To:[ ]*\/.*
{
OLDTO=$MATCH
NEWTO=`echo $MATCH | sed -e "s/a.com/b.com/gi"`
}
:0fc
| ( formail -rt \
-I "From: Auto-foward Gremlin <$POSTMASTER-B>" \
-I "Subject: [Auto-forwarded message] $SUBJECT" \
-A "X-Loop: $POSTMASTER-A" ; \
echo -e "Dear E-mail Sender:\n" \
"Please be advised that your message for $OLDTO\n" \
"was forwarded to $NEWTO.\n" \
"The reason for this is that the above-mentioned
recipient(s)\n" \
"has/have "a.com" in the domain-portion of the
address(es).\n" \
"The "a.com" domain is obsolete and has been Changed
into the\n" \
"following domain:\n\n" \
" b.com for All Employees\n\n" \
"Please be aware, this a.com address will not\n" \
"be supported in the future.\n" \
"The correct address will contain the b.com domain\n" \
"So Please update any distribution lists that contain
addresses in
"the obsolete format.\n\n" \
"Thank you for your co-operation.\n" \
"$POSTMASTER-A\n" ; ) \
| $SENDMAIL -t -f $POSTMASTER-A
:0A
! $NEWTO
}
Like I said I make no claims on this because I'm definitely not a procmail
buff. I know some of these things could be done better like the NEWTO
assignment and my use of formail switches. I thought I'd take a stab at
it though. It might give you some ideas too.
Justin
PS==> If you didn't want to customize your auto-ack with OLDTO and NEWTO,
you could write that message out to file (with god formatting too) and cat
for about as much CPU time as it takes to echo all the lines IMHO.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail