procmail
[Top] [All Lists]

Re: how to capture the file name of an attachment?

2001-03-08 23:50:08
"Carlos Eduardo R. L. de Miranda" <consultor(_at_)linuxbr(_dot_)com(_dot_)br> 
writes:
My question is right on the subject of this. It is that simple but I am
having trouble on finding how to do that.
Any help will be appreciated.


:0 B
* $ ^Content-(Type|Disposition)*:${dotstar}name${ws}=${ws}${dq}.*${ext}${dq}
{
FILE_NAME=......
}

The syntax of MIME parameters allows quoting, such that a regex is not,
in general, sufficient.  However, you can put the unquoting in a seperate
step:

        # Yes, two of them.  This matches a literal backslash when expanded
        bs='\\'

        :0 B
        * $ ^Content-(Type|Disposition) *:${dotstar}name${ws}=${ws}\
                \/(${dq}.*\.${ext}${dq}|[^ "    ]*\.${ext})
        {
                :0
                * MATCH ?? ^^"
                MATCH=|echo "$MATCH" | sed 's:\\\(.\):\1:g'

                FILE_NAME=$MATCH
        }


That's completely untested, so run it over some test email to make sure
I didn't leave out something.

One thing to consider is that different pieces of software may be
lenient in their interpretation of the MIME standard in different ways.
This means that it isn't always possible to know whether a mail client
will accept and process a given message.  For example, the following:

        Content-Disposition: attachment; filename = foo.html

is illegal by the standard (periods must be quoted) but might be
acceptable to some MUAs.  The above regexp tries to be lenient, but
perhaps I've missed something.


Philip Guenther


Note that this problem is a real challenge for Intrusion Detection
systems: there are streams of IP packets that are interpreted as carrying
different data depending on what system is looking at them.
_______________________________________________
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>