Skip to content

Commit 17d90b4

Browse files
author
Ralf Schlatterbeck
committed
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.
1 parent f09825b commit 17d90b4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Fixes:
1010
http://thread.gmane.org/gmane.comp.bug-tracking.roundup.devel/5133
1111
Add regression tests for proper handling of 'Create' and 'Edit'
1212
permissions.
13+
- Fix handling of non-ascii in realname in the nosy mailer, this used to
14+
mangle the email address making it unusable when replying. Thanks to
15+
intevation for funding the fix.
1316

1417
2009-12-21 1.4.11 (r4411)
1518

roundup/mailer.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ def get_standard_message(self, to, subject, author=None, multipart=False):
6161
charset = getattr(self.config, 'EMAIL_CHARSET', 'utf-8')
6262
tracker_name = unicode(self.config.TRACKER_NAME, 'utf-8')
6363
if not author:
64-
author = formataddr((tracker_name, self.config.ADMIN_EMAIL))
64+
author = (tracker_name, self.config.ADMIN_EMAIL)
65+
name = author[0]
6566
else:
6667
name = unicode(author[0], 'utf-8')
67-
author = formataddr((name, author[1]))
68+
try:
69+
name = name.encode('ascii')
70+
except UnicodeError:
71+
name = Header(name, charset).encode()
72+
author = formataddr((name, author[1]))
6873

6974
if multipart:
7075
message = MIMEMultipart()
@@ -77,10 +82,7 @@ def get_standard_message(self, to, subject, author=None, multipart=False):
7782
except UnicodeError:
7883
message['Subject'] = Header(subject, charset)
7984
message['To'] = ', '.join(to)
80-
try:
81-
message['From'] = author.encode('ascii')
82-
except UnicodeError:
83-
message['From'] = Header(author, charset)
85+
message['From'] = author
8486
message['Date'] = formatdate(localtime=True)
8587

8688
# add a Precedence header so autoresponders ignore us

test/test_mailgw.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,9 @@ def testUnknownUser(self):
11811181
''')
11821182

11831183
def testEnc01(self):
1184+
self.db.user.set(self.mary_id,
1185+
realname='\xe4\xf6\xfc\xc4\xd6\xdc\xdf, Mary'.decode
1186+
('latin-1').encode('utf-8'))
11841187
self.doNewIssue()
11851188
self._handle_mail('''Content-Type: text/plain;
11861189
charset="iso-8859-1"
@@ -1202,7 +1205,8 @@ def testEnc01(self):
12021205
Content-Type: text/plain; charset="utf-8"
12031206
Subject: [issue1] Testing...
12041207
1205-
From: "Contrary, Mary" <[email protected]>
1208+
From: =?utf-8?b?w6TDtsO8w4TDlsOcw58sIE1hcnk=?=
1209+
12061210
Reply-To: Roundup issue tracker <[email protected]>
12071211
MIME-Version: 1.0
12081212
Message-Id: <followup_dummy_id>
@@ -1213,7 +1217,8 @@ def testEnc01(self):
12131217
Content-Transfer-Encoding: quoted-printable
12141218
12151219
1216-
Contrary, Mary <[email protected]> added the comment:
1220+
=C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F, Mary <[email protected]> added the=
1221+
comment:
12171222
12181223
A message with encoding (encoded oe =C3=B6)
12191224

0 commit comments

Comments
 (0)