Created
September 7, 2023 16:49
-
-
Save calebstewart/c361d362212d7b51663e5ff41c186802 to your computer and use it in GitHub Desktop.
Parse and Dump MIME Message
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
from email import message_from_file | |
import sys | |
def dump_content(message) -> bytes: | |
if message.is_multipart(): | |
return b"\n".join([dump_content(m) for m in message.get_payload()]) | |
else: | |
return message.get_payload(decode=True) | |
with open(sys.argv[1], "r") as filp: | |
message = message_from_file(filp) | |
print(dump_content(message).decode("utf-8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment