commit 5092364f7e3ce42b61b0336a95519639d0e59308 Author: Matthew Finkel Matthew.Finkel@gmail.com Date: Sun Mar 30 12:42:06 2014 +0000
Use `email.message.Message` instead of `MimeWriter.MimeWriter`
`MimeWriter.MimeWriter` was deprecated in Python 2.3, now is a great time for us to switch to the replacement.
Fixes #11370 --- CHANGELOG | 4 ++++ lib/bridgedb/EmailServer.py | 39 ++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG index 4f36267..7f160df 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,10 @@ Changes in version 0.1.7 - descriptor reparsing into another thread and significantly increased the availability of bridgedb, as a result. + * FIXES #11370 We were using an old (and deprecated) module when + we created our email responses. Now we use the newer + version. This should only affect internal functionality + and should not result in any noticable user-visible changes.
And includes the following general changes: * BUMPS leekspin version to 0.1.3 diff --git a/lib/bridgedb/EmailServer.py b/lib/bridgedb/EmailServer.py index 8b7783f..90b22af 100644 --- a/lib/bridgedb/EmailServer.py +++ b/lib/bridgedb/EmailServer.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 ; test-case-name: bridgedb.test.test_EmailServer -*- # BridgeDB by Nick Mathewson. # Copyright (c) 2007-2013, The Tor Project, Inc. # See LICENSE for licensing information @@ -6,8 +7,10 @@ This module implements the email interface to the bridge database. """
-from StringIO import StringIO -import MimeWriter +from __future__ import unicode_literals + +from email import message +from io import StringIO import gettext import gpgme import logging @@ -430,17 +433,19 @@ def addSMTPServer(cfg, dist, sched): def composeEmail(fromAddr, clientAddr, subject, body, msgID=False, gpgContext=None):
- f = StringIO() - w = MimeWriter.MimeWriter(f) - w.addheader("From", fromAddr) - w.addheader("To", clientAddr) - w.addheader("Message-ID", twisted.mail.smtp.messageid()) + msg = message.Message() + msg.add_header("From", fromAddr) + msg.add_header("To", clientAddr) + msg.add_header("Message-ID", twisted.mail.smtp.messageid()) if not subject.startswith("Re:"): subject = "Re: %s"%subject - w.addheader("Subject", subject) + msg.add_header("Subject", subject) if msgID: - w.addheader("In-Reply-To", msgID) - w.addheader("Date", twisted.mail.smtp.rfc822date()) - mailbody = w.startbody("text/plain") + msg.add_header("In-Reply-To", msgID) + msg.add_header("Date", twisted.mail.smtp.rfc822date()) + msg.set_default_type("text/plain") + headers = [': '.join(m) for m in msg.items()] + mail = StringIO("\r\n".join(headers)) + mail.writelines(unicode(msg.as_string()))
# gpg-clearsign messages if gpgContext: @@ -450,20 +455,20 @@ def composeEmail(fromAddr, clientAddr, subject, body, msgID=False, if (len(sigs) != 1): logging.warn('Failed to sign message!') signature.seek(0) - [mailbody.write(l) for l in signature] + [mail.write(l) for l in signature] else: - mailbody.write(body) + mail.write(body)
# Only log the email text (including all headers) if SAFE_LOGGING is # disabled: if not Util.safe_logging: - f.seek(0) - logging.debug("Email contents:\n%s" % f.read()) + mail.seek(0) + logging.debug("Email contents:\n%s" % mail.read()) else: logging.debug("Email text for %r created." % Util.logSafely(clientAddr)) - f.seek(0) + mail.seek(0)
- return clientAddr, f + return clientAddr, mail
def getGPGContext(cfg): """Import a key from a file and initialise a context for GnuPG operations.