I can read attachments sent from all email clients I’ve tested except for androids default email app. It works through the gmail app in android though.
Here’s some of the code:
import email as emaillib
result, data = imap_conn.uid('fetch', email_id, '(RFC822)')
raw_email = data[0][1]
get_attachments(emaillib.message_from_string(raw_email))
def get_attachments(email_message_instance):
attachments = []
for part in email_message_instance.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
data = part.get_payload(decode=True)
if not data:
continue
filename = part.get_filename()
print 'appending attachment with filename: ', filename
attachments.append((filename, data))
return attachments
When I send one attachment from the default email app in android it prints:
appending attachment with filename: None
appending attachment with filename: None
appending attachment with filename: =?utf-8?B?SU1BRzAxOTMuanBn?=
Any ideas?
Ok I solved the problem, It seems my android default mail app writes content disposition for everything.
And the file name was all wicked as well.
So I solved the problem with (Since I’m only interested in media attachments):