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:
parent
b677462103
commit
089e4e133b
1 changed files with 11 additions and 0 deletions
11
email2pdf
11
email2pdf
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue