[Checkins] SVN: zope.sendmail/branches/3.5/ Merge r117102 from trunk; encode usernames and passwords to utf-8 if unicode

Martijn Pieters mj at zopatista.com
Fri Oct 1 08:22:16 EDT 2010


Log message for revision 117109:
  Merge r117102 from trunk; encode usernames and passwords to utf-8 if unicode

Changed:
  U   zope.sendmail/branches/3.5/CHANGES.txt
  U   zope.sendmail/branches/3.5/src/zope/sendmail/mailer.py
  U   zope.sendmail/branches/3.5/src/zope/sendmail/tests/test_mailer.py

-=-
Modified: zope.sendmail/branches/3.5/CHANGES.txt
===================================================================
--- zope.sendmail/branches/3.5/CHANGES.txt	2010-10-01 12:16:04 UTC (rev 117108)
+++ zope.sendmail/branches/3.5/CHANGES.txt	2010-10-01 12:22:16 UTC (rev 117109)
@@ -4,7 +4,10 @@
 3.5.2 (unreleased)
 ------------------
 
+- Handle unicode usernames and passwords, encoding them to UTF-8. Fix for
+  https://bugs.launchpad.net/zope.sendmail/+bug/597143
 
+
 3.5.1 (2009-01-26)
 ------------------
 

Modified: zope.sendmail/branches/3.5/src/zope/sendmail/mailer.py
===================================================================
--- zope.sendmail/branches/3.5/src/zope/sendmail/mailer.py	2010-10-01 12:16:04 UTC (rev 117108)
+++ zope.sendmail/branches/3.5/src/zope/sendmail/mailer.py	2010-10-01 12:22:16 UTC (rev 117109)
@@ -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.5/src/zope/sendmail/tests/test_mailer.py
===================================================================
--- zope.sendmail/branches/3.5/src/zope/sendmail/tests/test_mailer.py	2010-10-01 12:16:04 UTC (rev 117108)
+++ zope.sendmail/branches/3.5/src/zope/sendmail/tests/test_mailer.py	2010-10-01 12:22:16 UTC (rev 117109)
@@ -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