[Checkins] SVN: zope.sendmail/branches/3.7/ Merge r117102 from trunk; encode usernames and passwords to utf-8 if unicode
Martijn Pieters
mj at zopatista.com
Fri Oct 1 05:28:30 EDT 2010
Log message for revision 117103:
Merge r117102 from trunk; encode usernames and passwords to utf-8 if unicode
Changed:
U zope.sendmail/branches/3.7/CHANGES.txt
U zope.sendmail/branches/3.7/src/zope/sendmail/mailer.py
U zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_mailer.py
-=-
Modified: zope.sendmail/branches/3.7/CHANGES.txt
===================================================================
--- zope.sendmail/branches/3.7/CHANGES.txt 2010-10-01 09:24:28 UTC (rev 117102)
+++ zope.sendmail/branches/3.7/CHANGES.txt 2010-10-01 09:28:29 UTC (rev 117103)
@@ -14,6 +14,9 @@
- Added not declared, but needed test dependency on `zope.component [test]`.
+- Handle unicode usernames and passwords, encoding them to UTF-8. Fix for
+ https://bugs.launchpad.net/zope.sendmail/+bug/597143
+
3.7.2 (2010-04-30)
------------------
Modified: zope.sendmail/branches/3.7/src/zope/sendmail/mailer.py
===================================================================
--- zope.sendmail/branches/3.7/src/zope/sendmail/mailer.py 2010-10-01 09:24:28 UTC (rev 117102)
+++ zope.sendmail/branches/3.7/src/zope/sendmail/mailer.py 2010-10-01 09:28:29 UTC (rev 117103)
@@ -64,7 +64,12 @@
if connection.does_esmtp:
if self.username is not None and self.password is not None:
- connection.login(self.username, self.password)
+ username, password = self.username, self.password
+ if isinstance(username, unicode):
+ username = username.encode('utf-8')
+ if isinstance(password, unicode):
+ password = password.encode('utf-8')
+ connection.login(username, password)
elif self.username:
raise RuntimeError('Mailhost does not support ESMTP but a username '
'is configured')
Modified: zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_mailer.py
===================================================================
--- zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_mailer.py 2010-10-01 09:24:28 UTC (rev 117102)
+++ zope.sendmail/branches/3.7/src/zope/sendmail/tests/test_mailer.py 2010-10-01 09:28:29 UTC (rev 117103)
@@ -112,6 +112,30 @@
self.assert_(self.smtp.quitted)
self.assert_(self.smtp.closed)
+ def test_send_auth_unicode(self):
+ fromaddr = 'me at example.com'
+ toaddrs = ('you at example.com', 'him at example.com')
+ msgtext = 'Headers: headers\n\nbodybodybody\n-- \nsig\n'
+ self.mailer.username = u'f\u00f8\u00f8' # double o slash
+ self.mailer.password = u'\u00e9vil' # e acute
+ self.mailer.hostname = 'spamrelay'
+ self.mailer.port = 31337
+ self.mailer.send(fromaddr, toaddrs, msgtext)
+ self.assertEquals(self.smtp.username, 'f\xc3\xb8\xc3\xb8')
+ self.assertEquals(self.smtp.password, '\xc3\xa9vil')
+
+ def test_send_auth_nonascii(self):
+ fromaddr = 'me at example.com'
+ toaddrs = ('you at example.com', 'him at example.com')
+ msgtext = 'Headers: headers\n\nbodybodybody\n-- \nsig\n'
+ self.mailer.username = 'f\xc3\xb8\xc3\xb8' # double o slash
+ self.mailer.password = '\xc3\xa9vil' # e acute
+ self.mailer.hostname = 'spamrelay'
+ self.mailer.port = 31337
+ self.mailer.send(fromaddr, toaddrs, msgtext)
+ self.assertEquals(self.smtp.username, 'f\xc3\xb8\xc3\xb8')
+ self.assertEquals(self.smtp.password, '\xc3\xa9vil')
+
def test_send_failQuit(self):
self.mailer.smtp.fail_on_quit = True
try:
@@ -162,6 +186,9 @@
# here, so pass.
pass
+ test_send_auth_unicode = test_send_auth
+ test_send_auth_nonascii = test_send_auth
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSMTPMailer))
More information about the checkins
mailing list