Skip to content

Commit 883a3c1

Browse files
author
Richard Jones
committed
handle quoting/escaping specials after encoding;
fix tests to handle new, more consistent header wrapping
1 parent be8fe86 commit 883a3c1

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed

roundup/mailer.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ def encode_quopri(msg):
2828
def nice_sender_header(name, address, charset):
2929
# construct an address header so it's as human-readable as possible
3030
# even in the presence of a non-ASCII name part
31-
h = Header(charset=charset)
32-
# the important bits of formataddr()
33-
if specialsre.search(name):
34-
name = '"%s"'%escapesre.sub(r'\\\g<0>', name)
31+
if not name:
32+
return address
3533
try:
36-
name.encode('ASCII')
37-
h.append(name, 'ASCII')
34+
encname = name.encode('ASCII')
3835
except UnicodeEncodeError:
39-
h.append(name)
40-
h.append('<%s>'%address, 'ASCII')
41-
return str(h)
36+
# use Header to encode correctly.
37+
encname = Header(name, charset=charset).encode()
38+
39+
# the important bits of formataddr()
40+
if specialsre.search(encname):
41+
encname = '"%s"'%escapesre.sub(r'\\\g<0>', encname)
42+
43+
# now use Header again to wrap the line if necessary
44+
return '%s <%s>'%(encname, address)
4245

4346
class Mailer:
4447
"""Roundup-specific mail sending."""

test/test_mailgw.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def compareMessages(self, new, old):
7878
res.extend(body_diff)
7979

8080
if res:
81-
res.insert(0, 'Generated message not correct (diff follows):')
81+
res.insert(0, 'Generated message not correct (diff follows, expected vs. actual):')
8282
raise AssertionError, '\n'.join(res)
8383

8484
def compareStrings(self, s2, s1, replace={}):
@@ -257,7 +257,8 @@ def testNewIssueAuthMsg(self):
257257
Subject: [issue1] Testing...
258258
259259
From: "Bork, Chef" <[email protected]>
260-
Reply-To: Roundup issue tracker <[email protected]>
260+
Reply-To: Roundup issue tracker
261+
261262
MIME-Version: 1.0
262263
Message-Id: <dummy_test_message_id>
263264
X-Roundup-Name: Roundup issue tracker
@@ -301,7 +302,8 @@ def testNewIssueNoAuthorInfo(self):
301302
Subject: [issue1] Testing...
302303
303304
From: "Bork, Chef" <[email protected]>
304-
Reply-To: Roundup issue tracker <[email protected]>
305+
Reply-To: Roundup issue tracker
306+
305307
MIME-Version: 1.0
306308
Message-Id: <dummy_test_message_id>
307309
X-Roundup-Name: Roundup issue tracker
@@ -342,7 +344,8 @@ def testNewIssueNoAuthorEmail(self):
342344
Subject: [issue1] Testing...
343345
344346
From: "Bork, Chef" <[email protected]>
345-
Reply-To: Roundup issue tracker <[email protected]>
347+
Reply-To: Roundup issue tracker
348+
346349
MIME-Version: 1.0
347350
Message-Id: <dummy_test_message_id>
348351
X-Roundup-Name: Roundup issue tracker
@@ -485,7 +488,8 @@ def testSimpleFollowup(self):
485488
Subject: [issue1] Testing...
486489
487490
From: "Contrary, Mary" <[email protected]>
488-
Reply-To: Roundup issue tracker <[email protected]>
491+
Reply-To: Roundup issue tracker
492+
489493
MIME-Version: 1.0
490494
Message-Id: <followup_dummy_id>
491495
In-Reply-To: <dummy_test_message_id>
@@ -533,7 +537,8 @@ def testFollowup(self):
533537
Subject: [issue1] Testing...
534538
535539
From: richard <[email protected]>
536-
Reply-To: Roundup issue tracker <[email protected]>
540+
Reply-To: Roundup issue tracker
541+
537542
MIME-Version: 1.0
538543
Message-Id: <followup_dummy_id>
539544
In-Reply-To: <dummy_test_message_id>
@@ -591,7 +596,8 @@ def testPropertyChangeOnly(self):
591596
X-Roundup-Issue-Status: unread
592597
X-Roundup-Version: 1.3.3
593598
MIME-Version: 1.0
594-
Reply-To: Roundup issue tracker <[email protected]>
599+
Reply-To: Roundup issue tracker
600+
595601
Content-Transfer-Encoding: quoted-printable
596602
597603
@@ -629,7 +635,8 @@ def testFollowupTitleMatch(self):
629635
Subject: [issue1] Testing...
630636
631637
From: richard <[email protected]>
632-
Reply-To: Roundup issue tracker <[email protected]>
638+
Reply-To: Roundup issue tracker
639+
633640
MIME-Version: 1.0
634641
Message-Id: <followup_dummy_id>
635642
In-Reply-To: <dummy_test_message_id>
@@ -742,7 +749,8 @@ def testFollowupNosyAuthor(self):
742749
Subject: [issue1] Testing...
743750
744751
From: John Doe <[email protected]>
745-
Reply-To: Roundup issue tracker <[email protected]>
752+
Reply-To: Roundup issue tracker
753+
746754
MIME-Version: 1.0
747755
Message-Id: <followup_dummy_id>
748756
In-Reply-To: <dummy_test_message_id>
@@ -788,7 +796,8 @@ def testFollowupNosyRecipients(self):
788796
Subject: [issue1] Testing...
789797
790798
From: richard <[email protected]>
791-
Reply-To: Roundup issue tracker <[email protected]>
799+
Reply-To: Roundup issue tracker
800+
792801
MIME-Version: 1.0
793802
Message-Id: <followup_dummy_id>
794803
In-Reply-To: <dummy_test_message_id>
@@ -834,7 +843,8 @@ def testFollowupNosyAuthorAndCopy(self):
834843
Subject: [issue1] Testing...
835844
836845
From: John Doe <[email protected]>
837-
Reply-To: Roundup issue tracker <[email protected]>
846+
Reply-To: Roundup issue tracker
847+
838848
MIME-Version: 1.0
839849
Message-Id: <followup_dummy_id>
840850
In-Reply-To: <dummy_test_message_id>
@@ -879,7 +889,8 @@ def testFollowupNoNosyAuthor(self):
879889
Subject: [issue1] Testing...
880890
881891
From: John Doe <[email protected]>
882-
Reply-To: Roundup issue tracker <[email protected]>
892+
Reply-To: Roundup issue tracker
893+
883894
MIME-Version: 1.0
884895
Message-Id: <followup_dummy_id>
885896
In-Reply-To: <dummy_test_message_id>
@@ -924,7 +935,8 @@ def testFollowupNoNosyRecipients(self):
924935
Subject: [issue1] Testing...
925936
926937
From: richard <[email protected]>
927-
Reply-To: Roundup issue tracker <[email protected]>
938+
Reply-To: Roundup issue tracker
939+
928940
MIME-Version: 1.0
929941
Message-Id: <followup_dummy_id>
930942
In-Reply-To: <dummy_test_message_id>
@@ -1207,7 +1219,8 @@ def testEnc01(self):
12071219
12081220
From: =?utf-8?b?w6TDtsO8w4TDlsOcw58sIE1hcnk=?=
12091221
1210-
Reply-To: Roundup issue tracker <[email protected]>
1222+
Reply-To: Roundup issue tracker
1223+
12111224
MIME-Version: 1.0
12121225
Message-Id: <followup_dummy_id>
12131226
In-Reply-To: <dummy_test_message_id>
@@ -1255,7 +1268,8 @@ def testEncNonUTF8(self):
12551268
Subject: [issue1] Testing...
12561269
12571270
From: "Contrary, Mary" <[email protected]>
1258-
Reply-To: Roundup issue tracker <[email protected]>
1271+
Reply-To: Roundup issue tracker
1272+
12591273
MIME-Version: 1.0
12601274
Message-Id: <followup_dummy_id>
12611275
In-Reply-To: <dummy_test_message_id>
@@ -1309,7 +1323,8 @@ def testMultipartEnc01(self):
13091323
Subject: [issue1] Testing...
13101324
13111325
From: "Contrary, Mary" <[email protected]>
1312-
Reply-To: Roundup issue tracker <[email protected]>
1326+
Reply-To: Roundup issue tracker
1327+
13131328
MIME-Version: 1.0
13141329
Message-Id: <followup_dummy_id>
13151330
In-Reply-To: <dummy_test_message_id>
@@ -1386,7 +1401,8 @@ def testFollowupStupidQuoting(self):
13861401
Subject: [issue1] Testing...
13871402
13881403
From: richard <[email protected]>
1389-
Reply-To: Roundup issue tracker <[email protected]>
1404+
Reply-To: Roundup issue tracker
1405+
13901406
MIME-Version: 1.0
13911407
Message-Id: <followup_dummy_id>
13921408
In-Reply-To: <dummy_test_message_id>
@@ -1930,7 +1946,8 @@ def testSecurityMessagePermissionContent(self):
19301946
Subject: [issue1] Testing...
19311947
19321948
From: "Bork, Chef" <[email protected]>
1933-
Reply-To: Roundup issue tracker <[email protected]>
1949+
Reply-To: Roundup issue tracker
1950+
19341951
MIME-Version: 1.0
19351952
Message-Id: <dummy_test_message_id>
19361953
X-Roundup-Name: Roundup issue tracker

0 commit comments

Comments
 (0)