Code

Fix handling of non-ascii in realname in the nosy mailer, this used to
authorschlatterbeck <schlatterbeck@57a73879-2fb5-44c3-a270-3262357dd7e2>
Sun, 27 Dec 2009 20:05:32 +0000 (20:05 +0000)
committerschlatterbeck <schlatterbeck@57a73879-2fb5-44c3-a270-3262357dd7e2>
Sun, 27 Dec 2009 20:05:32 +0000 (20:05 +0000)
mangle the email address making it unusable when replying. Thanks to
intevation for funding the fix.

git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4417 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/mailer.py
test/test_mailgw.py

index 082f0728f0f6e7f3e291969d0de519ea0bf09385..7cc30077c37dcc7b0b3ed9541b0825c5ce4c5c54 100644 (file)
@@ -10,6 +10,9 @@ Fixes:
   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)
 
index 453a1ded0ed45c614eba34d5414bb0c6080e374a..f1a1af3bdf45a20f469dd7132b022449cf922df1 100644 (file)
@@ -61,10 +61,15 @@ class Mailer:
         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 @@ class Mailer:
         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
index 251b47cde591f84dbf720ffbf94d4ad2dd305be5..b35f3567b374e9393fdfa9df1c2511eed2fd2314 100644 (file)
@@ -1181,6 +1181,9 @@ This is a test submission of a new issue.
 ''')
 
     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 @@ TO: chef@bork.bork.bork, richard@test.test
 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 @@ X-Roundup-Issue-Status: chatting
 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)