Skip to content

Instantly share code, notes, and snippets.

@davidmintz
Created August 22, 2019 14:45
Show Gist options
  • Save davidmintz/0a1c63be0973324326ffbcc4a16680a0 to your computer and use it in GitHub Desktop.
Save davidmintz/0a1c63be0973324326ffbcc4a16680a0 to your computer and use it in GitHub Desktop.
quick and dirty html extraction for .eml files
#!/usr/bin/env python3
# useful for development and testing, this gets the html payload from
# .eml files (e.g., as produced by Zend\Mail) and prints it to STDOUT
from email import parser;
import argparse;
args = argparse.ArgumentParser()
args.add_argument("filename", help="path to .eml file")
filename = args.parse_args().filename
data = open(filename)
msg = parser.Parser().parse(data)
html = msg.get_payload()[1]
thing = str(html.get_payload(decode=True))
print(thing.replace('\\n','\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment