Created
January 23, 2017 09:08
-
-
Save JasonSpine/647cd0f7776d326868cb1fedabaed74b to your computer and use it in GitHub Desktop.
Extract all attachments of *.eml files
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 email | |
import os | |
path = './' | |
listing = os.listdir(path) | |
for fle in listing: | |
if str.lower(fle[-3:])=="eml": | |
msg = email.message_from_file(open(fle)) | |
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: | |
#print detail | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment