procmail
[Top] [All Lists]

Re: matching empty text/plain

2003-06-16 21:56:16
On Mon, 16 Jun 2003, Paul Chvostek wrote:

  WSPC=" ^I" # you-know
  NL="
"

A variable containing a newline is nearly always used for constructing
e.g. LOG assignments.  I don't think it works properly to use it as a
member of a character class as you suggest.  You're much better off using
($) to match a newline.

  :0 B
  * 1^1   ^Content-Type:
  { PARTS=$= }

Do you need to know the number of parts?  If not,

:0
* -2^0
*  1^1 B ?? ^Content-Type:

should be sufficient to test for "at least two parts".  However, it's
entirely possible to send a content-type: multipart containing only a
single part, so I'm not sure why you're bothering.  You also apparently
don't care whether there's a multipart inside a multipart with an empty
part in the inner multipart?

  *     ^Content-Type: multipart/.*boundary="\/[^"]+

* $ ^Content-Type:[$WSPC]*multipart/.*boundary="\/[^"]+

  * $ B ^--$MATCH${NL}(\
         
Content-Type:[${WSPC}]+text/plain;?([${WSPC}${NL}]+charset=${DQ}.+${DQ})${NL}|\
         Content-Transfer-Encoding:[${WSPC}]+.+${NL})+\
         ()[${WSPC}${NL}]+
        ^--$MATCH{NL}
  { W="empty text/plain block" }

(You find that easier to read than mimepart.txt was?)

Aside from the typos and missing definition of $DQ ...

The semicolon ater text/plain is only optional when no charset is present,
but you're requiring a charset to be present.  There's also no point in
looking explicitly for C-T-E, because a mime part can have all sorts of
headers (Content-Disposition, Content-Id, etc.) so really you only care
about either (a) Content-Type or (b) that there are no headers at all.
You just need to skip the other ones.

You should use $\MATCH to prevent things like dots in the boundary string
from being treated as pattern characters, and you should be prepared for
the closing boundary to be the end of the entire multipart.

So this might be more like it:

WSPC="  "
NL="($)"

:0
* $ ^Content-Type:[$WSPC]*multipart/.*boundary="\/[^"]+
* $ B ^--$\MATCH$NL(\
       (.+$NL)*\
       Content-Type:[$WSPC]+text/plain.*$NL\
       (.+$NL)*\
      )?$NL\
       ([$WSPC]*$NL)*\
      ^--$\MATCH(--)?$NL
{ W="empty text/plain block" }

I haven't tested that either, though.


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

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