From bcacba04065753a318f475ac3306f89ca9d1f138 Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Sat, 2 May 2015 21:44:39 +0200 Subject: [PATCH] Try to fix encoding problems in Python 2 --- emailtunnel/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/emailtunnel/__init__.py b/emailtunnel/__init__.py index d0f8a57..6f22d9e 100644 --- a/emailtunnel/__init__.py +++ b/emailtunnel/__init__.py @@ -317,7 +317,8 @@ def handle_error(self): class SMTPReceiver(smtpd.SMTPServer): - channel_class = ResilientSMTPChannel + if six.PY3: + channel_class = ResilientSMTPChannel def __init__(self, host, port): self.host = host @@ -371,7 +372,12 @@ def process_message(self, peer, mailfrom, rcpttos, str_data): bytestring, which we unpack here. """ - data = str_data.encode('latin1') + if six.PY3: + data = str_data.encode('latin1') + else: + data = str_data + logging.debug("Type of str_data is %s" % (type(str_data),)) + if six.PY2: if data.startswith('From nobody'): # Remove first line which contains useless envelope info