procmail
[Top] [All Lists]

Re: dealing with anti-spam bounces?

1997-04-25 16:18:00
When ariel(_at_)best(_dot_)com (Catherine Hampton) wrote:

H> :0 c
H> spamtemp

H> :0
H> | (formail -rt \
H>     -A"X-Loop: ${NOLOOP}";\
H>     cat $SBDIR/junk;\
H>     cat spamtemp;\
H>     rm -f spamtemp) \
H>     | $SENDMAIL -oi -t

Mike Rose responded,

R> I don't like temporary files if they're avoidable.

Neither do I, because things can happen that make them get left behind, and I
do agree with Mike's revised code that doesn't use the temporary file (which
I won't repeat).  However, I disagree with his particular objection to the
temporary file in Catherine's code:

R> The above will break if two spams come in at the same time.

If that were the only problem, a regional lockfile would take care of it:

# assuming we're already inside braces entered because the incoming message
# smells like spam:

    LOCKFILE=spamtemp.lock

    :0 c
    spamtemp

    :0
    | (formail -rt -A"X-Loop: ${NOLOOP}";\
        cat $SBDIR/junk; cat spamtemp; rm -f spamtemp) \
        | $SENDMAIL -oi -t

# in case of fall-through
    LOCKFILE

My own way of handling it, though, would avoid a temporary file, because
in general principle I agree with Mike Rose about this:

   :0hf # double the head
   | sed -e H -e '$ G'

   :0hf # invert first head, followed by $SBDIR/junk before second head
   | formail -rt -A"X-Loop: $NOLOOP" ; cat $SBDIR/junk

   :0 # send back; -oi is usually implicit
   ! -t

If you can be sure that the head fits into $LINEBUF, you can condense the
first two recipes into one:

  :0hf # H is implicit
  * ^^\/(.*$)+^^
  | formail -rt -A"X-Loop: $NOLOOP" ; echo "$MATCH" ; cat $SBDIR/junk

  :0 # send back
  ! -t