Skip to content

Commit a65b4f0

Browse files
author
Richard Jones
committed
additional header encode/decode fixes
1 parent bf684d6 commit a65b4f0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

roundup/rfc2822.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def encode_header(header, charset='utf-8'):
141141
if c == ' ':
142142
quoted += '_'
143143
# These characters can be included verbatim
144-
elif hqre.match(c) and c != '_':
144+
elif hqre.match(c) and c not in '_=':
145145
quoted += c
146146
# Otherwise, replace with hex value like =E2
147147
else:

test/test_rfc2822.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from roundup.rfc2822 import decode_header, encode_header
2+
3+
import unittest, time
4+
5+
class RFC2822TestCase(unittest.TestCase):
6+
def testDecode(self):
7+
src = 'Re: [it_issue3] '\
8+
'=?ISO-8859-1?Q?Ren=E9s_[resp=3Dg=2Cstatus=3D?= '\
9+
'=?ISO-8859-1?Q?feedback]?='
10+
result = 'Re: [it_issue3] Ren\xc3\xa9s [resp=g,status=feedback]'
11+
self.assertEqual(decode_header(src), result)
12+
13+
src = 'Re: [it_issue3]'\
14+
' =?ISO-8859-1?Q?Ren=E9s_[resp=3Dg=2Cstatus=3D?=' \
15+
' =?ISO-8859-1?Q?feedback]?='
16+
result = 'Re: [it_issue3] Ren\xc3\xa9s [resp=g,status=feedback]'
17+
self.assertEqual(decode_header(src), result)
18+
19+
def testEncode(self):
20+
src = 'Re: [it_issue3] Ren\xc3\xa9s [status=feedback]'
21+
result = '=?utf-8?q?Re:_[it=5Fissue3]_Ren=C3=A9s_[status=3Dfeedback]?='
22+
self.assertEqual(encode_header(src), result)
23+
24+
def test_suite():
25+
suite = unittest.TestSuite()
26+
suite.addTest(unittest.makeSuite(RFC2822TestCase))
27+
return suite

0 commit comments

Comments
 (0)