procmail
[Top] [All Lists]

Re: attach filter

2001-08-01 11:43:39
PSE-L(_at_)mail(_dot_)professional(_dot_)org (Professional Software 
Engineering) writes:
...
There is *NO* guarantee that the name= will come from the same mime 
attachment as the content type previously matched (consider that the file 
IS multipart) - you may be better off piping mime messages through an 
external script to parse the MIME chunks individually.  No, I don't have 
any code sitting around to do this, and I'm not about to write it either.

There are ways... Heh heh heh:

        
        # This doesn't correctly handle comments in the header fields
        :0
        * ^Mime-Version:[       ]*1\.0
        * ^Content-Type:[       ]*multipart.*;\/.*
        * MATCH ?? boundary[    ]*=[    ]*\/.*
        {
                boundary = $MATCH

                # Strip quotes from the boundary.  This should handle
                # backslashes, but it doesn't
                :0
                * boundary ?? ^^"\/.*[^"]
                { boundary = $MATCH }

                # Regexps for things in the body.  We have to handle header
                # field continuations manually, matching on newlines that
                # are followed by whitespace.
                dotstar = ".*(^[        ].*)*"
                ws = "[         ]*(^[   ]+)*"
                
                # Zero or more header fields in the body
                headerfields = "^(.+:$dotstar^)*"

                # The header fields whose values we check for name=
                CTDheader = "Content-(Type|Disposition):"

                # The actual regexp for matching that header field
                target = "${CTDheader}${dotstar}name${ws}=${dotstar}\.doc

                # Look for a boundary, followed by zero or more header
                # fields and the header field value that we're targetting
                :0 B
                * $ ^--$\boundary${headerfields}${target}
                {
                        # DO SOMETHING HERE
                }
        }

There are ways to fix both the comment handling and the backslash bugs,
but they're minor points.


Philip Guenther
_______________________________________________
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>