Skip to content

Commit

Permalink
Fix support for MailHost 4.10 (see zopefoundation/Products.MailHost#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Oct 31, 2020
1 parent c3937a9 commit a7745fd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Products/PrintingMailHost/Patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
from Products.MailHost.MailHost import MailBase
from Products.PrintingMailHost import LOG, FIXED_ADDRESS
from six import StringIO
try:
# Python 3
from email import message_from_bytes
except ImportError:
# Python 2
from email import message_from_string as message_from_bytes

import email.parser
import six

PATCH_PREFIX = '_monkey_'

Expand Down Expand Up @@ -48,8 +54,8 @@ class PrintingMailHost:
def _send(self, mfrom, mto, messageText, debug=False, immediate=False):
"""Send the message."""
orig_messageText = messageText
if isinstance(messageText, str):
messageText = email.parser.Parser().parsestr(messageText)
if isinstance(messageText, six.binary_type):
messageText = message_from_bytes(messageText)
base64_note = ""
out = StringIO()
print("", file=out)
Expand All @@ -71,7 +77,7 @@ def _send(self, mfrom, mto, messageText, debug=False, immediate=False):
break
else:
try:
messageText.set_payload(decodestring(body))
messageText.set_payload(decodestring(body))
except TypeError: # Python 3
messageText.set_payload(decodestring(body).encode("utf8"))
print(messageText, file=out)
Expand Down

0 comments on commit a7745fd

Please sign in to comment.