Skip to content

Instantly share code, notes, and snippets.

@calebstewart
Created September 7, 2023 16:49
Show Gist options
  • Save calebstewart/c361d362212d7b51663e5ff41c186802 to your computer and use it in GitHub Desktop.
Save calebstewart/c361d362212d7b51663e5ff41c186802 to your computer and use it in GitHub Desktop.
Parse and Dump MIME Message
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