procmail
[Top] [All Lists]

Re: Problem with auto-reply: mail received twice!

1999-04-18 22:27:39
Serge Koudrya <serge7(_at_)usa(_dot_)net> writes:
 I tried to use the following rc for vacation auto-reply.
 It works fine but when this recipe...:
...
  ...matches its condition I get mail once (it's what I want) but
  when id DOES NOT I receive TWO copies of each incoming mail (it's
  what I DO NOT want).
  Please help me get rid of duplicate mails.

The outer recipe has an nested block action and the 'c' flag and
therefore results in procmail forking with the parent skipping the
block.  The recipe you included appears to assume that the child
process which process the nested block will die when it hits the end of
the block.  This is not true: the child will continue past the end of
the block and will perform whatever actions are given there, including
the implicit delivery performed upon falling off the end of the
.procmailrc.  If this is not wanted then either a delivering recipe
needs to be placed at the end of the block, or the structure needs to
be changed.

...
:0ch
* $ ^TO($USER|$MY_ADDR|$MY_NAMES)
* ? test -f $ACKMSG -o -f $VACAMSG
* ! ^FROM_DAEMON
* !$ $FROM(Majordomo|Listserv)
* ! ^Subject: .*(\[(ack(nowledge?ment)?|on vacation)\]|\
               auto(matic)[- ]reply|\
               away from mail|\
               out of town|\
               can ?not (reply|answer)|\
               (on |via )vacation( program)?)
* !$ ^X-Loop: $MY_ADDR
* !$ $FROM($NOACKS)$POST_ADDR_SPAN
{

The 'h' flag has no effect on nested block recipes.


...
   # Get either the string "on vacation" or "acknowledgement"
   ACKM="`if [ -f $VACAMSG ]; then echo 'on vacation' ; else echo acknowledgm
ent ; fi`"

   # Check the cache for a recent ack
   :0:$ACKS.$LOCKEXT
   * !? fgrep -s "$FROMADDR $DATE" $ACKS
   | ( fgrep -v "$FROMADDR" $ACKS ; echo "$FROMADDR $DATE" ) >$ACKS.new ; \
     rm -f $ACKS ; mv $ACKS.new $ACKS ; \
     ( formail -rI"From:       $FROMSIG" \
                -I"Reply-To:   $MY_ADDR" \
                -I"Precedence: junk" \
                -I"Subject:    Re: $SUBJ [$ACKM]" \
                -I"X-Loop:     $MY_ADDR" \
                -I"References:" ; \
       sed -e "s~\$SUBJECT~$SUBJ~" $ACKFILE ) \
     | $SENDMAIL -oi -t

Hmm, the rm is probable superfluous (mv will happily rename over
files).  This recipe should probably have the 'h' flag from the outer
recipe.  You may also want to change the last line from:

        | $SENDMAIL -oi -t
to
        | $SENDMAIL ${SENDMAILFLAGS--oi} -t

(that'll work on with versions of procmail both before and after
3.11pre4 which was when the SENDMAILFLAGS variable was added.)


More importantly, this is where the child needs to be stopped if the
recipe didn't deliver the message and thereby stop it.  The clearest
and safest way to do this is to add the recipe:

        :0
        /dev/null

before the close brace (of course).


Philip Guenther

<Prev in Thread] Current Thread [Next in Thread>