procmail
[Top] [All Lists]

Re: Auto-reply according file extension.

2008-06-09 02:14:55
At 12:33 2008-06-06 -0600, LuKreme wrote:
On 5-Jun-2008, at 18:28, Michelle Konzack wrote:
Am 2008-06-04 15:09:27, schrieb LuKreme:
:0
* ^Content-type:.*"\/\.pdf"
{ FILENAME = $MATCH }

This does not work

Yes it does.

I'd agree that it doesn't - at least not in MANY cases. Since it's checking the HEADERS, not the body, it is looking for a message which itself IS an attachment - no multipart with a message describing what is attached, etc, which would make it multipart and immediately push filenames and other attachment-specific elements into a per-attachment MIME chunk. Also, it presumes that the filename that MAY be in a multiline Content-Type header is actually encapsulated in doublequotes. This isn't always the case.

Here is an example from a message sent to me from someone using Apple Mail:

Content-Transfer-Encoding: base64
Content-Type: application/pdf;
        x-unix-mode=0644;
        name=6-08Monthly Extractor.pdf
Content-Disposition: inline;
        filename="6-08Monthly Extractor.pdf"

These appear within a MIME chunk, not in the message headers.

I honestly don't have the time to get into this, but I would first extract the MIME boundary, then use that to anchor for nabbing the filename portion (which, if you're looking for at least one file of a specific type, you probably should include the extension in the regexp). Something vaguely like the following should get you started down that path:

:0
* ^Content-Type:.*;[    ]*boundary=\/[^^]*
{
        MIMEBOUNDARY=$MATCH

        # then strip leading and trailing doublequotes - but only IF there's a
        # leading doublequote.
        :0
        * MATCH ?? ^^"\/[^"]*
        {
                MIMEBOUNDARY=$MATCH
        }

        # this could use some beefing up - I merely tweaked it so that it'd
        # work for a test corpus which I threw at it.

        :0
* $ B ?? ^--$\MIMEBOUNDARY(^Content-Transfer-Encoding:.*)?^Content-Type:(.*^?)*[ ]*(file)?name=\/[^^]*
        {
                ATTACHFILE=$MATCH

                # then strip leading and trailing doublequotes - but only
                # IF there's a leading doublequote.
                :0
                * MATCH ?? ^^"\/[^"]*
                {
                        ATTACHFILE=$MATCH
                }

                # You have a PDF file in tow (by filename at least), and
                # the filename (sans encapsulating quotes) should be in
                # $ATTACHFILE
        }
}

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail