From 79e9b940ac5795c7227394f861bf0e6dcdec8ae1 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 1 Feb 2010 05:46:59 +0000 Subject: [PATCH] handle quoting/escaping specials after encoding; fix tests to handle new, more consistent header wrapping git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4444 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/mailer.py | 21 ++++++++++-------- test/test_mailgw.py | 53 ++++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/roundup/mailer.py b/roundup/mailer.py index 729aaea..58fc33b 100644 --- a/roundup/mailer.py +++ b/roundup/mailer.py @@ -28,17 +28,20 @@ def encode_quopri(msg): def nice_sender_header(name, address, charset): # construct an address header so it's as human-readable as possible # even in the presence of a non-ASCII name part - h = Header(charset=charset) - # the important bits of formataddr() - if specialsre.search(name): - name = '"%s"'%escapesre.sub(r'\\\g<0>', name) + if not name: + return address try: - name.encode('ASCII') - h.append(name, 'ASCII') + encname = name.encode('ASCII') except UnicodeEncodeError: - h.append(name) - h.append('<%s>'%address, 'ASCII') - return str(h) + # use Header to encode correctly. + encname = Header(name, charset=charset).encode() + + # the important bits of formataddr() + if specialsre.search(encname): + encname = '"%s"'%escapesre.sub(r'\\\g<0>', encname) + + # now use Header again to wrap the line if necessary + return '%s <%s>'%(encname, address) class Mailer: """Roundup-specific mail sending.""" diff --git a/test/test_mailgw.py b/test/test_mailgw.py index b35f356..a3c95af 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -78,7 +78,7 @@ class DiffHelper: res.extend(body_diff) if res: - res.insert(0, 'Generated message not correct (diff follows):') + res.insert(0, 'Generated message not correct (diff follows, expected vs. actual):') raise AssertionError, '\n'.join(res) def compareStrings(self, s2, s1, replace={}): @@ -257,7 +257,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, mary@test.test, richard@test.test From: "Bork, Chef" -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: X-Roundup-Name: Roundup issue tracker @@ -301,7 +302,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: mary@test.test, richard@test.test From: "Bork, Chef" -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: X-Roundup-Name: Roundup issue tracker @@ -342,7 +344,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: mary@test.test, richard@test.test From: "Bork, Chef" -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: X-Roundup-Name: Roundup issue tracker @@ -485,7 +488,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, richard@test.test From: "Contrary, Mary" -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -533,7 +537,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, john@test.test, mary@test.test From: richard -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -591,7 +596,8 @@ X-Roundup-Loop: hello X-Roundup-Issue-Status: unread X-Roundup-Version: 1.3.3 MIME-Version: 1.0 -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + Content-Transfer-Encoding: quoted-printable @@ -629,7 +635,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, john@test.test, mary@test.test From: richard -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -742,7 +749,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, richard@test.test From: John Doe -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -788,7 +796,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork From: richard -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -834,7 +843,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, john@test.test, richard@test.test From: John Doe -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -879,7 +889,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, richard@test.test From: John Doe -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -924,7 +935,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork From: richard -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -1207,7 +1219,8 @@ Subject: [issue1] Testing... To: chef@bork.bork.bork, richard@test.test From: =?utf-8?b?w6TDtsO8w4TDlsOcw58sIE1hcnk=?= -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -1255,7 +1268,8 @@ Content-Type: text/plain; charset="iso-8859-1" Subject: [issue1] Testing... To: chef@bork.bork.bork, richard@test.test From: "Contrary, Mary" -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -1309,7 +1323,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork, richard@test.test From: "Contrary, Mary" -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -1386,7 +1401,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: chef@bork.bork.bork From: richard -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: In-Reply-To: @@ -1930,7 +1946,8 @@ Content-Type: text/plain; charset="utf-8" Subject: [issue1] Testing... To: richard@test.test From: "Bork, Chef" -Reply-To: Roundup issue tracker +Reply-To: Roundup issue tracker + MIME-Version: 1.0 Message-Id: X-Roundup-Name: Roundup issue tracker -- 2.30.2