Created
January 21, 2025 13:37
Revisions
-
vadimkantorov created this gist
Jan 21, 2025 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ # Usage: to extract all eml files in current directory into the current directory: python uneml.py *.eml import os import sys import email import email.policy for input_path in sys.argv[1:]: print('eml', repr(input_path)) eml = email.message_from_file(open(input_path), policy = email.policy.default) for part in eml.walk(): for attachment in part.iter_attachments(): if not attachment.get_filename(): continue output_filename = os.path.basename(input_path) + ' ' + attachment.get_filename() print('img', repr(output_filename)) with open(output_filename, 'wb') as f: f.write(attachment.get_payload(decode = True))