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

Handle missing embedded images.

This commit is contained in:
Andrew Ferrier 2014-10-04 17:36:27 +01:00
parent 621665793b
commit 49544a4191
2 changed files with 13 additions and 3 deletions

View file

@ -80,10 +80,15 @@ def main():
payload = bytes(header_info, 'UTF-8') + payload
p = Popen(['wkhtmltopdf', '-q', '--load-error-handling', 'ignore', '--load-media-error-handling',
'ignore', '-', output_file_name], stdin=PIPE)
output = p.communicate(input=payload)
'ignore', '-', output_file_name], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, error = p.communicate(input=payload)
if p.returncode > 0:
raise ExitCodeException("wkhtmltopdf failed with exit code " + str(p.returncode))
if error == bytes('Exit with code 1 due to network error: ProtocolUnknownError\n', 'UTF-8'):
# WARNING: we should handle this better - see
# https://github.com/andrewferrier/email2pdf/issues/12
pass
else:
raise ExitCodeException("wkhtmltopdf failed with exit code " + str(p.returncode))
def handle_pdf_parts(email, output_directory):

View file

@ -191,6 +191,11 @@ class TestMIME(BaseTestClasses.Email2PDFTestCase):
self.assertEqual(self.invokeEmail2PDF(), 0)
self.assertTrue(os.path.exists(filename))
def test_embeddedImageEmail(self):
self.addHeaders("From", "To", "Subject")
self.attachHTML('<img src=cid:_1_C9C396E8C9C391380055638680257D67>')
self.assertEqual(self.invokeEmail2PDF(), 0)
def test_somethingElseAsOctetStream(self):
self.addHeaders("From", "To", "Subject")
self.attachText("Some basic textual content")