-----Original Message-----
From: David W. Tamkin
Sent: Sunday, December 28, 2003 9:46 PM
[...]
Gary Funck has this code:
> FROM=`formail -rx To: | sed -e 's/^[ ]*//'`
Oy. You don't need the calls to sed and $SHELL:
FROM=`formail -rzxTo:`
> REALLY_FROM=`formail -x From: | sed -e 's/^[ ]*//'`
Oy gevalt. You don't need any outside programs at all:
:0 # .* to the left of \/ is stingy
* ^From:.*\/[^ ].*
{ REALLY_FROM=$MATCH }
Hey, I after I run this mail through Spamassassin, a couple of extra $SHELL
invocations aren't going to matter. <g> Thanks for the tips though.
> LOG="REALLY FROM: $REALLY_FROM$NL"
OK.
Glad I got that right. <g>
[...] You can try this; it does add
one invocation of formail per message, but I just saved you one formail,
two seds, and two shells up top:
LOGABSTRACT=off
TRAP='echo "Really from $REALLY_FROM"
formail -l "$LASTFOLDER"
echo'
It isn't fully proof against interleaving, but incidences should be
extremely rare. You could throw calls to lockfile and rm in there, but
I would venture that the two extra forks per message are not worth it,
since their help will almost never be needed.
This is even closer to being atomic:
LOGABSTRACT=off
TRAP=`ABSTRACT=`formail -l "$LASTFOLDER"`
echo "Really from $REALLY_FROM$NL$ABSTRACT$NL"'
since all writing to the logfile by the trap is collected into a single
echo command.
Reading "man procmailrc":
TRAP When procmail terminates of its own accord and not because
it received a signal, it will execute the contents of this
variable. A copy of the mail can be read from stdin.
Any output produced by this command will be appended to $LOGFILE.
Possible uses for TRAP are: removal of temporary
files, logging customised abstracts, etc.
See also EXITCODE and LOGABSTRACT.
I haven't looked at the source code, but it isn't difficult to contemplate
an implementation where procmail first gathers all the output from $TRAP
before
writing it to the log, and thus the two implementations are equivalent. I'm
guessing that you've read the source code, though. <g>
Question regarding TRAP: are assignments additive (ie, TRAP=A followed by
TRAP=B is
equivalant to TRAP="A;B")? If one wants to tack some actions onto the
existing
set of TRAP actions, is this the way to go?
TRAP="$TRAP; <additional commands>"
where <additional commands> is the set of additional commands to be run.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail