commit 29bdc8754503a2e1ead7c39b5b1207215926eee8 Author: Matthew Finkel sysrqb@torproject.org Date: Sat Jul 19 03:29:53 2014 +0000
Fix utf-8 encoding errors in email.autoresponder module.
* FIXES several write errors due to encoding issues on production server.
Signed-off-by: Isis Lovecruft isis@torproject.org These were part of the hotfixes to ponticum on 2014-07-16. --- lib/bridgedb/email/autoresponder.py | 18 +++++++++--------- lib/bridgedb/email/server.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/lib/bridgedb/email/autoresponder.py b/lib/bridgedb/email/autoresponder.py index add1d6c..e7dcdf2 100644 --- a/lib/bridgedb/email/autoresponder.py +++ b/lib/bridgedb/email/autoresponder.py @@ -136,9 +136,9 @@ def generateResponse(fromAddress, client, body, subject=None, """ response = EmailResponse(gpgContext) response.to = client - response.writeHeaders(fromAddress, str(client), subject, + response.writeHeaders(fromAddress.encode('utf-8'), str(client), subject, inReplyTo=messageID) - response.writeBody(body) + response.writeBody(body.encode('utf-8'))
# Only log the email text (including all headers) if SAFE_LOGGING is # disabled: @@ -221,9 +221,9 @@ class EmailResponse(object): self.__class__.__name__)) try: if size is not None: - contents = self.mailfile.read(int(size)) + contents = self.mailfile.read(int(size)).encode('utf-8') else: - contents = self.mailfile.read() + contents = self.mailfile.read().encode('utf-8') except Exception as error: # pragma: no cover logging.exception(error)
@@ -306,17 +306,17 @@ class EmailResponse(object): self.write("From: %s" % fromAddress) self.write("To: %s" % toAddress) if includeMessageID: - self.write("Message-ID: %s" % smtp.messageid()) + self.write("Message-ID: %s" % smtp.messageid().encode('utf-8')) if inReplyTo: - self.write("In-Reply-To: %s" % inReplyTo) - self.write("Content-Type: %s" % contentType) - self.write("Date: %s" % smtp.rfc822date()) + self.write("In-Reply-To: %s" % inReplyTo.encode('utf-8')) + self.write("Content-Type: %s" % contentType.encode('utf-8')) + self.write("Date: %s" % smtp.rfc822date().encode('utf-8'))
if not subject: subject = '[no subject]' if not subject.lower().startswith('re'): subject = "Re: " + subject - self.write("Subject: %s" % subject) + self.write("Subject: %s" % subject.encode('utf-8'))
if kwargs: for headerName, headerValue in kwargs.items(): diff --git a/lib/bridgedb/email/server.py b/lib/bridgedb/email/server.py index 1717958..4bcfed9 100644 --- a/lib/bridgedb/email/server.py +++ b/lib/bridgedb/email/server.py @@ -176,7 +176,7 @@ class SMTPMessage(object): self.lines.append(line) if not safelog.safe_logging: try: - logging.debug("> %s", line.rstrip("\r\n")) + logging.debug("> %s", line.rstrip("\r\n").encode('utf-8')) except UnicodeError: # pragma: no cover pass except Exception as error: # pragma: no cover
tor-commits@lists.torproject.org