]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
RFC 2822 describes the characters allowed in a header field name. Conform to
authorBarry Warsaw <barry@python.org>
Mon, 29 Nov 2004 03:46:54 +0000 (03:46 +0000)
committerBarry Warsaw <barry@python.org>
Mon, 29 Nov 2004 03:46:54 +0000 (03:46 +0000)
this, and add test cases.

Lib/email/FeedParser.py
Lib/email/test/test_email.py

index 690b7c2866df84d160432e17fb50b2f75d33d3a7..f514728156522ae4c5db4dcf853767dd3f797343 100644 (file)
@@ -27,7 +27,9 @@ NLCRE = re.compile('\r\n|\r|\n')
 NLCRE_bol = re.compile('(\r\n|\r|\n)')
 NLCRE_eol = re.compile('(\r\n|\r|\n)$')
 NLCRE_crack = re.compile('(\r\n|\r|\n)')
-headerRE = re.compile(r'^(From |[-\w]{2,}:|[\t ])')
+# RFC 2822 $3.6.8 Optional fields.  ftext is %d33-57 / %d59-126, Any character
+# except controls, SP, and ":".
+headerRE = re.compile(r'^(From |[\041-\071\073-\176]{2,}:|[\t ])')
 EMPTYSTRING = ''
 NL = '\n'
 
index c62044245875c3211ddff8b4b2a40e0abef65ee5..2d3841b3148bbaef506cf88cef133ffaeb29b60b 100644 (file)
@@ -2402,6 +2402,22 @@ Here's the message body
         eq(msg.get('Header'), value1)
         eq(msg.get('Next-Header'), value2)
 
+    def test_rfc2822_header_syntax(self):
+        eq = self.assertEqual
+        m = '>From: foo\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
+        msg = email.message_from_string(m)
+        eq(len(msg.keys()), 3)
+        keys = msg.keys()
+        keys.sort()
+        eq(keys, ['!"#QUX;~', '>From', 'From'])
+        eq(msg.get_payload(), 'body')
+
+    def test_rfc2822_space_not_allowed_in_header(self):
+        eq = self.assertEqual
+        m = '>From foo@example.com 11:25:53\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
+        msg = email.message_from_string(m)
+        eq(len(msg.keys()), 0)
+
 
 \f
 class TestBase64(unittest.TestCase):