I'm trying to filter emails that have attachments, but in the system I'm using I only have access to the headers (for filtering). Is there a consistent way of determining if an e-mail contains attachments using only headers? (Perhaps checking if the content-type is multipart?)
For Mime attachments, emails with a
Content-Type: multipart/mixed would often have attachments (but don't have to). Emails with a
Content-Type: other than
multipart/* would not have attachments. Anything else (
multipart/alternative being the most common) may have attachments.
And in any case, that depends what is meant by attachment. If by attachment, you mean only those mime parts that have a
Content-Disposition, then you won't find it out in the email header, only in the corresponding part mime headers.
Things you may not want to consider as attachments are for instance email signatures, parts of a
multipart/related message that are for instance images embedded in the signature of an html message...
I got email header using belowe code:
msg_header = @imap.fetch(message_id, 'RFC822.HEADER').first.attr['RFC822.HEADER'] headers = msg_header.split(/\r\n|: /) email_header = headers[headers.index('Content-Type')+1].split(/;/)
Then you can decide on header this mail has attachment or not without get body.
you can check header information from here Hope this helps you.