procmail
[Top] [All Lists]

Re: Interlocking log output and LOGABSTRACT?

2003-12-28 23:05:33
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 }

> LOG="REALLY FROM: $REALLY_FROM$NL"

OK.

> but since there's no locking discipline in place, the REALLY FROM
> lines can easily get jumbled in the output ...

Yes, that happens.

> I'd like the "really from" line to be next to the log abstract it is
> associated with. Perhaps TRAP would get me closer to the solution,
> but I'm wondering if I'd have to replicate the actions of LOGABSTRACT
> within the TRAP variable, or if I can depend upon procmail to log the
> output from TRAP and the log abstract in a single atomic operation?

You really can't.  I add information to the logfile with TRAP and it
gets interleaved with that from other incoming messages less often than
if I did it with LOG= assignments throughout the rcfiles, but it still
happens, particularly when a single incoming message generates more than one delivery (but not always even then). 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.


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