1
0
Fork 1
mirror of https://github.com/andrewferrier/email2pdf.git synced 2025-03-18 05:52:59 +00:00

Add basic email headers to PDF.

This commit is contained in:
Andrew Ferrier 2014-09-20 14:11:53 +01:00
parent b677462103
commit 089e4e133b

View file

@ -10,6 +10,8 @@ import os
import os.path
import sys
HEADERS = ('Subject', 'From', 'To', 'Date')
def main(argv):
inputFile = ''
outputFile = ''
@ -40,6 +42,13 @@ def main(argv):
data = inputHandle.read()
myEmail = email.message_from_string(data)
headerInfo = ''
for header in HEADERS:
headerInfo = headerInfo + '<b>' + header + '</b>: ' + myEmail[header] + '<br/>'
headerInfo = headerInfo + '<br/>'
payload = find_depth_first(myEmail, "text/html")
if payload == False:
payload = find_depth_first(myEmail, "text/plain")
@ -48,6 +57,8 @@ def main(argv):
else:
payload = "<html><body><pre>\n" + payload + "\n</pre></body></html>"
payload = headerInfo + payload
p = Popen(['wkhtmltopdf', '-q', '--load-error-handling', 'ignore', '--load-media-error-handling', 'ignore', '-', outputFile], stdin=PIPE)
output = p.communicate(input = payload)