Skip to content

Commit 1904eb2

Browse files
author
Andrey Lebedev
committed
more pedantic rfc2822 header qp encoding
1 parent 725ef41 commit 1904eb2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

roundup/rfc2822.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from string import letters, digits
23
from binascii import b2a_base64, a2b_base64
34

45
ecre = re.compile(r'''
@@ -11,7 +12,7 @@
1112
\?= # literal ?=
1213
''', re.VERBOSE | re.IGNORECASE)
1314

14-
hqre = re.compile(r'^[-a-zA-Z0-9!*+/\[\]., ]+$')
15+
hqre = re.compile(r'^[A-z0-9!"#$%%&\'()*+,-./:;<=>?@\[\]^_`{|}~ ]+$')
1516

1617
def base64_decode(s, convert_eols=None):
1718
"""Decode a raw base64 string.

test/test_mailgw.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_mailgw.py,v 1.45 2003-04-27 02:16:47 richard Exp $
11+
# $Id: test_mailgw.py,v 1.46 2003-05-06 21:49:20 kedder Exp $
1212

1313
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
1414
import rfc822
@@ -22,7 +22,7 @@
2222
# import rfc822 as email
2323

2424
from roundup.mailgw import MailGW, Unauthorized, uidFromAddress
25-
from roundup import init, instance
25+
from roundup import init, instance, rfc2822
2626

2727
# TODO: make this output only enough equal lines for context, not all of
2828
# them
@@ -952,6 +952,13 @@ def testUserCreate(self):
952952
i = uidFromAddress(self.db, ('', '[email protected]'), 1)
953953
self.assertNotEqual(uidFromAddress(self.db, ('', '[email protected]'), 1), i)
954954

955+
def testRFC2822(self):
956+
ascii_header = "[issue243] This is a \"test\" - with 'quotation' marks"
957+
unicode_header = '[issue244] \xd0\xb0\xd0\xbd\xd0\xb4\xd1\x80\xd0\xb5\xd0\xb9'
958+
unicode_encoded = '=?utf-8?q?[issue244]_=D0=B0=D0=BD=D0=B4=D1=80=D0=B5=D0=B9?='
959+
self.assertEqual(rfc2822.encode_header(ascii_header), ascii_header)
960+
self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded)
961+
955962
def suite():
956963
l = [unittest.makeSuite(MailgwTestCase),
957964
]

0 commit comments

Comments
 (0)