Created
May 12, 2015 12:06
-
-
Save wiesson/3a849a7de620b1eccf4e to your computer and use it in GitHub Desktop.
Separate attachments from mails files (*.eml) with Python 2/3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import email | |
if __name__ == '__main__': | |
files = glob.glob("/Users/wiesson/Downloads/mails/*.eml") | |
for each in files: | |
msg = email.message_from_file(open(each)) | |
attachments = msg.get_payload() | |
for attachment in attachments: | |
try: | |
fnam = attachment.get_filename() | |
f = open(fnam, 'wb').write(attachment.get_payload(decode=True,)) | |
f.close() | |
except Exception as detail: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment