procmail
[Top] [All Lists]

Re: Filtering out unwanted mime attachments

1997-10-15 08:57:40
Dan Smith wrote,

|      # reduce the body to just the first MIME part (plus a little extra
|      # garbage)
|      :0B
|      * $.*^--${boundary}\/(.|$)+^--${boundary}$
|      { part1=$MATCH }
|      :0wfib

Don't you want an `A' flag there, or perhaps to include this recipe inside
the same braces where part1 is defined?

|      | echo "$part1"

The problem there is that, since we've already seen that the body fits into
$LINEBUF, MATCH will suck up down through the *last* occurrence of the
boundary, not just through the second.  Wildcards to the right of \/ are
greedy.

By the way, if it did work, it could be condensed (and we should probably
leave the newline after the first boundary out of $MATCH):

       :0Bbfwi
       * $ ^--${boundary}$\/(.|$)+^--${boundary}$
       | echo "$MATCH"

I can't think of a straightforward way to stop extraction at the second
appearance of the boundary within procmail.  With a call to sed, though,
it is pretty easy (assuming there are no quotation marks in the boundary;
there might be slashes in it).

      :0Bbfw
      * $ ^--$boundary(.*$)+--$boundary$
      | sed -ne "1,\\\"^--$boundary$\"d" -e "\\\"^--$boundary$\"q" -e p

If there is some other character that will never appear in the boundary
(besides the quotation mark), it could be even easier.

If we can be sure that only boundary lines will begin with two hyphens
flush left, we don't need sed after all, just echo as Dan intended:

      :0Bbfwi
      * $ ^--$boundary$\/(.?([^-].*)?$)+
      | echo "$MATCH"