procmail
[Top] [All Lists]

Re: file name of attachment after line break

2001-09-05 16:14:15
Bart Schaefer <schaefer(_at_)zanshin(_dot_)com> writes:
On Wed, 5 Sep 2001, David W. Tamkin wrote:

 :0B # slow regexp there's no other way

I think you can speed it up with something like:

While it'll be more _accurate_, I'm not convinced it'll actually be
_faster_.


:0
* ^Content-Type:.*\<multipart\>.*\<boundary="\/[^"]*
{
BOUND="$MATCH"

If the boundary string is quoted, there may be backslashes protecting
special characters that need to be removed before you can match with it.

Something like this should work (untested, of course):

        :0
        * ^Content-Type:.*\<multipart\>.*\<boundary[    ]*=[    ]*\
                \/([^"  ]+|".*)
        {
                BOUND = $MATCH

                :0 i
                * BOUND ?? ^^"
                BOUND =| perl -e '$ENV{BOUND} =~ /^"((?:\\.|[^\\"]+)+)"/; '
                              -e '$_ = $1; s/\\(.)/$1/g; print; '


:0B
*$ ^--$\BOUND$(.+$)?Content-(Type|Disposition):(.|$[   
])*\.(list|of|bad|ex|ten|sions)
action

The '(.+$)?' should be '(.+$)*'.


The remaining problem with this is that it works only for the first bad
extension encountered.  I think that's OK in this case, but if the intent
is to do something with each such attachment, you have to resort to an
external program.

(Or a recursive INCLUDERC/SWITCHRC, but that's more complicated.)


(Aside:  It's too bad "formail -dcs" can't be told what string to split
the digest upon.  If it could be told to treat the MIME boundary string as
the message separator (and preserve it as such in the output), then
passing the body of the message once through formail could unfold all the
embedded Content- fields or be used to invoke procmail on each attachment
separately.)

Teaching formail how to split MIME multipart messages has been on the
todo list for quite a while, it just hasn't happened yet.


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