Created
June 26, 2013 12:14
-
-
Save twinsant/5866929 to your computer and use it in GitHub Desktop.
Extracts attachments from EML file.
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 os | |
| import email | |
| if __name__ == '__main__': | |
| eml = '~/Downloads/wm_2013062618492006332.jpg.eml' | |
| try: | |
| os.mkdir(os.path.expanduser('%s_' % eml)) | |
| except OSError: | |
| pass | |
| f = open(os.path.expanduser(eml)) | |
| msg = email.message_from_file(f) | |
| f.close() | |
| for par in msg.walk(): | |
| if not par.is_multipart(): | |
| name = par.get_param('name') | |
| if name: | |
| fname = email.Header.decode_header(email.Header.Header(name))[0][0] | |
| print 'Extracting %s...' % fname | |
| data = par.get_payload(decode=True) | |
| f = open(os.path.expanduser('%s_/%s' % (eml, fname)), 'wb') | |
| f.write(data) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment