From ad1e8ab6a1c31d58ee6aaec3866e2dfc3d03ca1c Mon Sep 17 00:00:00 2001 From: schlatterbeck Date: Sun, 27 Dec 2009 20:05:32 +0000 Subject: [PATCH] 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. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4417 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 3 +++ roundup/mailer.py | 14 ++++++++------ test/test_mailgw.py | 9 +++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 082f072..7cc3007 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) diff --git a/roundup/mailer.py b/roundup/mailer.py index 453a1de..f1a1af3 100644 --- a/roundup/mailer.py +++ b/roundup/mailer.py @@ -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 diff --git a/test/test_mailgw.py b/test/test_mailgw.py index 251b47c..b35f356 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -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" +From: =?utf-8?b?w6TDtsO8w4TDlsOcw58sIE1hcnk=?= + Reply-To: Roundup issue tracker MIME-Version: 1.0 Message-Id: @@ -1213,7 +1217,8 @@ X-Roundup-Issue-Status: chatting Content-Transfer-Encoding: quoted-printable -Contrary, Mary added the comment: +=C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F, Mary added the= + comment: A message with encoding (encoded oe =C3=B6) -- 2.30.2