procmail
[Top] [All Lists]

Re: Counting Content-Length ?

1998-01-02 16:40:44
Vikas Agnihotri asked about the following recipe:

| :0 B        # use HB to measure both head and body
| * 1^1 .
| * 1^1 ^.*$
| { textsize = $= }

Actually, there's a better way.  For one thing, the second condition always
counts one too many (the final newline plus the closing putative newline
create the extra match); second, after making that correction, an empty body
would score zero and leave the variable undefined.  So even in its day it was
modified thus:

  :0 B        # use HB to measure both head and body
  * 1^1 .
  * 1^1 ^.*$
  * -1^0
  { }
  textsize = $=

The reason we used it at all was that size conditions worked only on the
entire text regardless of H or B or HB flags at the top of the recipe.
Nowadays we can do this and get the accurate figure in one condition:

# leave `B ??' out to measure the entire message
  :0
  * 1^1 B ?? > 1
  { }
  size = $=

If you want to be silly about it (as some of us very often do),

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

gives the same result, and as long as the search area is non-empty, so do
these, which are even sillier:

  :0
  * 1^-1 B ?? < 1
  { }
  size = $=

  :0
  * -1^-1 B ?? < -1
  { }
  size = $=

David W. Tamkin  (Silly is my middle name, but I spell it with a W.)

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