views:

111

answers:

2

I am developing an email client in Python.

Is it possible to check if an email contains an attachement just from the e-mail header without downloading the whole E-Mail?

+3  A: 

"attachment" is quite a broad term. Is an image for HTML message an attachment?

In general, you can try analyzing content-type header. If it's multipart/mixed, most likely the message contains an attachment.

Eugene Mayevski 'EldoS Corp
yes its true , but its not always :)so is there any perfect solution ?
Avadhesh
I suppose the trouble with multipart/mixed is that people use it to send HTML emails with those dreadful image signature blocks on. There's no way to tell those from an attachment without looking quite closely.
Tom Anderson
Exactly, with HTML e-mails, images (technically) are attachments as well, and if we think deeper, they *are* attachments, as they are local and not external entities.
Eugene Mayevski 'EldoS Corp
+4  A: 

Try IMAP4.fetch(message_set, "BODYSTRUCTURE")

Read the RFC3501 for details about the FETCH BODYSTRUCTURE response.

teukkam