procmail
[Top] [All Lists]

Re: Auto-reply according file extension.

2008-06-04 07:56:16
At 12:12 2008-06-04 +0100, Eduardo Luís wrote:
Hi,

I'm asking again if someone could help me.

How can I return an email to sender if it contains a specific
attachment  file type?

Start by taking one of the messages you're interested in, and saving it to its own file (say, from your MUA), complete. Open it with your favourite editor and chop out all the ENCODED material (oh, keep a few lines if you wish, just cut out all the solid blocks of encoded muck). You should be left with the original headers (complete), and in the body, some mime chunks describing those parts. Post the file to your webspace someplace THEN post the URL here for discussion.

Once you have this file, it'll provide a roadmap for how to identify the messages -- first looking for the Content-Type: header in the message headers, and identifying it as multipart for instance, then looking in the body

This is really just pseudo-code, based on NO understanding of the actual messages you're dealing with. It isn't tested, nor really vetted for function -- merely presented for you to get a basic idea of the structure.

:0
* ^Content-Type:.*multipart/
* B ?? ^Content-Type: application/pdf;
{
        # Have a message which APPEARS to have a PDF in tow.
        # (discussions, usually on a list such as procmail, can refer
        # to headers within the body, and might flag true)
        # see 'man procmailex' for examples of autoreplying
}


Of course, if the attachment IS the entirety of the message (not multiple attachments, no text message accompanying it), you could end up with headers similar to:

Content-Type: application/octet-stream;
        name="SomeDocument.pdf"
Content-Description: SomeDocument.pdf
Content-Disposition: attachment;
        filename="SomeDocument.pdf"

And then the first line of the message body is encoded, rather than a sub header for a mime chunk.

There are a lot of ways to attach files in email, and a lot of broken MUAs that don't do it correctly - which forces a lot of other MUAs to have to interpret the broken messages so that they're handled correctly anyway, so don't expect the above to be the only ways you might get an attachment (and these assume MIME - there's other formats too, which are thankfully not used much these days).

---
 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