procmail
[Top] [All Lists]

Re: How to match on empty body?

1996-12-09 14:52:22
Dan Smith wrote about receiving empty messages,

: So I'm paranoid and don't want to actually send such messages straight
: to /dev/null, rather I want to send a short reply back to the person ...

: Which results in the following:  Can this be improved any?  I already
: see I'm using a different regexp...

Yes, it can be improved.  Your different regexp is part of the problem: it
doesn't do the right job.

: :0WhcB:$MAILDIR/.blank.lock

OK, you have a `B' flag, so you are searching only the body.

: * !^FROM_DAEMON

You want to be sure that the body doesn't match ^FROM_DAEMON?

: * !^Precedence: ?(bulk|list|junk)

You want to be sure there is no low Precedence: header in the body?  Besides,
you already ruled those out by rejecting matches to ^FROM_DAEMON.

: * $!${VACA_SUBJECT}
: * ^^[         ]*$

Not good, Dan.  That will match on an empty first line even if there is
text on the second line or later.  You need to make sure that the entire
body, not just its first line, is whitespace (or nothingness).

: * $!^X-Loop: ${UNIQUE_NAME}

And of course, there should be no X-Loop header with your name in the body.

: | formail -rD 8192 $MAILDIR/.blank.cache

Let's try all of that again; inside the parentheses of the third condition
are space, pipe, tab, pipe, dollar.

  :0Whc:.blank.lock
  * !^FROM_DAEMON
  * $ !$VACA_SUBJECT
  * B ?? ^^( |  |$)*^^
  | formail -rD 8192 $MAILDIR/.blank.cache

:   :0f
:   | formail -rt -I "Precedence: junk" -A "X-Loop: ${UNIQUE_NAME}"
: 
:   :0bf
:   | (echo "Hi!" ;\
:   echo "" ;\
:   echo "This is just to let me know that the message you just sent" ;\
:   echo "to ${TO_LINE} about ${SUBJECT}" ;\
:   echo "was empty; and thus has automatically been deleted." ;\
:   echo "You may want to double-check to ensure that a mail-related" ;\
:   echo "problem did not occur someplace." ;\
:   echo "" ;\
:   echo "Thanks," ;\
:   echo "   Dan" ;\
:   cat ${HOME}/.signature )

You could combine those two into one recipe: even if there are endless runs
of blank lines in the incoming body, formail -r without -k will drop the
body anyway, so here:

    :0f
    | formail -rt -I "Precedence: junk" -A "X-Loop: ${UNIQUE_NAME}" ;\
    echo "Hi!" ;\
    echo "" ;\
    echo "This is just to let me know that the message you just sent" ;\
    echo "to ${TO_LINE} about ${SUBJECT}" ;\
    echo "was empty and thus has automatically been deleted." ;\
    echo "You may want to double-check to ensure that a mail-related" ;\
    echo "problem did not occur somewhere." ;\
    echo "" ;\
    echo "Thanks," ;\
    echo "   Dan" ;\
    cat ${HOME}/.signature

You could even, instead of having that as a filter before a recipe that
does ! -oi -t, take the filter flag off, put parentheses around the commands,
and pipe the output to $SENDMAIL -oi -t in the same recipe.

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