procmail
[Top] [All Lists]

Re: Phantom lines in empty body

2004-06-20 15:49:13
On Sun, Jun 20, 2004 at 02:59:19PM -0700, Jim Osborn wrote:
Using this recipe to detect an empty mail body:

#
# Test for empty body:
#
:0 B
*  1^0
* -1^1 ^.*[^   ]+.*$
{
    SPAMSCORE = "${SPAMSCORE}${SPAMSCORE:+, }NOBODY"
    :0 fwh
    * $!${addheaders:+!}
    | formail -A "X-Diagnostic: empty body"
}

I get the expected behavior at home, using procmail v3.15.1. (SuSE
Linux 7.3 on i686).  That is, when I throw a mail at that recipe
that has a body consisting of three linefeeds, it scores 1.

At my isp, using procmail v3.22 on SunOS 4.1.4, and various linuxes
I think on sun machines (I can check if it's relevant), I get this:

procmail: Score:       1       1 ""
procmail: Score:     -27     -26 "^.*[^     ]+.*$"

I checked the email with a binary viewer, and sure enough, after
the last header line, there are three 0x0As, then EOF.

I don't know the answer to the scoring anomaly, and I don't really
have time to think hard about that right this moment.  But I think
you don't need to use such a sledge-hammer type of test to look
for an empty body.  You're having procmail count every character
of every message body.  We don't need that at all.

First of all, we could not bother with messages that are long.
So we could use the < and > operators to our benefit.  Something
like

  SPACE = " "
  TAB = "       "
  WS = "$SPACE$TAB"
  NL = "
  "

  :0
  * B ??  1^1 > 1
  { BSIZE = $= }

  :0 E
  { LOG = "$NL Body was null! $NL"  HOST }

  THRESHOLD = 20  # or whatever you want that's small
  :0
  * $ $THRESHOLD^0     
  * $    -$BSIZE^0
  { # we're here because the body is pretty damn small
    # so let's do some more testing

    :0
    * B ! ?? [^$WS]|$
    { LOG = "$NL Body was very small and had no non-white chars $NL" }
  }

---
dman (Virus Snaggers now at 2.0.4; see <http://vsnag.spamless.us> )

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