changeset 4313:7a6c5c117879

Fix handling of non-ascii in realname in the nosy mailer... ...this used to mangle the email address making it unusable when replying. Thanks to intevation for funding the fix.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Sun, 27 Dec 2009 20:05:32 +0000
parents 594eee0d43fc
children b41a033bffcc
files CHANGES.txt roundup/mailer.py test/test_mailgw.py
diffstat 3 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Wed Dec 23 00:34:39 2009 +0000
+++ b/CHANGES.txt	Sun Dec 27 20:05:32 2009 +0000
@@ -10,6 +10,9 @@
   http://thread.gmane.org/gmane.comp.bug-tracking.roundup.devel/5133
   Add regression tests for proper handling of 'Create' and 'Edit'
   permissions.
+- Fix handling of non-ascii in realname in the nosy mailer, this used to
+  mangle the email address making it unusable when replying. Thanks to
+  intevation for funding the fix.
 
 2009-12-21 1.4.11 (r4411)
 
--- a/roundup/mailer.py	Wed Dec 23 00:34:39 2009 +0000
+++ b/roundup/mailer.py	Sun Dec 27 20:05:32 2009 +0000
@@ -61,10 +61,15 @@
         charset = getattr(self.config, 'EMAIL_CHARSET', 'utf-8')
         tracker_name = unicode(self.config.TRACKER_NAME, 'utf-8')
         if not author:
-            author = formataddr((tracker_name, self.config.ADMIN_EMAIL))
+            author = (tracker_name, self.config.ADMIN_EMAIL)
+            name = author[0]
         else:
             name = unicode(author[0], 'utf-8')
-            author = formataddr((name, author[1]))
+        try:
+            name = name.encode('ascii')
+        except UnicodeError:
+            name = Header(name, charset).encode()
+        author = formataddr((name, author[1]))
 
         if multipart:
             message = MIMEMultipart()
@@ -77,10 +82,7 @@
         except UnicodeError:
             message['Subject'] = Header(subject, charset)
         message['To'] = ', '.join(to)
-        try:
-            message['From'] = author.encode('ascii')
-        except UnicodeError:
-            message['From'] = Header(author, charset)
+        message['From'] = author
         message['Date'] = formatdate(localtime=True)
 
         # add a Precedence header so autoresponders ignore us
--- a/test/test_mailgw.py	Wed Dec 23 00:34:39 2009 +0000
+++ b/test/test_mailgw.py	Sun Dec 27 20:05:32 2009 +0000
@@ -1181,6 +1181,9 @@
 ''')
 
     def testEnc01(self):
+        self.db.user.set(self.mary_id,
+            realname='\xe4\xf6\xfc\xc4\xd6\xdc\xdf, Mary'.decode
+            ('latin-1').encode('utf-8'))
         self.doNewIssue()
         self._handle_mail('''Content-Type: text/plain;
   charset="iso-8859-1"
@@ -1202,7 +1205,8 @@
 Content-Type: text/plain; charset="utf-8"
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test.test
-From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
+From: =?utf-8?b?w6TDtsO8w4TDlsOcw58sIE1hcnk=?=
+ <issue_tracker@your.tracker.email.domain.example>
 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
 MIME-Version: 1.0
 Message-Id: <followup_dummy_id>
@@ -1213,7 +1217,8 @@
 Content-Transfer-Encoding: quoted-printable
 
 
-Contrary, Mary <mary@test.test> added the comment:
+=C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F, Mary <mary@test.test> added the=
+ comment:
 
 A message with encoding (encoded oe =C3=B6)
 

Roundup Issue Tracker: http://roundup-tracker.org/