Created
November 16, 2017 08:47
-
-
Save srozb/6040e8940553f587b3622973947fbd7a to your computer and use it in GitHub Desktop.
dump eml attachments
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 characters
#!/usr/bin/env python3 | |
import email | |
import sys | |
import uuid | |
def print_usage(): | |
print("{} <filename>".format(sys.argv[0])) | |
def read_file(filename): | |
return email.message_from_file(open(filename)) | |
def dump_attachments(message): | |
for att in message.get_payload(): | |
if type(att.get_payload()) == str: | |
name = str(uuid.uuid4()) | |
print("writing {}.bin".format(name)) | |
open(name + '.bin', 'wb').write(att.get_payload(decode=True)) | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print_usage() | |
sys.exit(-1) | |
msg = read_file(sys.argv[1]) | |
dump_attachments(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment