File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1556,6 +1556,13 @@ def get_bare_quoted_string(value):
15561556 while value and value [0 ] != '"' :
15571557 if value [0 ] in WSP :
15581558 token , value = get_fws (value )
1559+ elif value [:2 ] == '=?' :
1560+ try :
1561+ token , value = get_encoded_word (value )
1562+ bare_quoted_string .defects .append (errors .InvalidHeaderDefect (
1563+ "encoded word inside quoted string" ))
1564+ except errors .HeaderParseError :
1565+ token , value = get_qcontent (value )
15591566 else :
15601567 token , value = get_qcontent (value )
15611568 bare_quoted_string .append (token )
Original file line number Diff line number Diff line change @@ -540,6 +540,15 @@ def test_get_bare_quoted_string_empty_quotes(self):
540540 self ._test_get_x (parser .get_bare_quoted_string ,
541541 '""' , '""' , '' , [], '' )
542542
543+ # Issue 16983: apply postel's law to some bad encoding.
544+ def test_encoded_word_inside_quotes (self ):
545+ self ._test_get_x (parser .get_bare_quoted_string ,
546+ '"=?utf-8?Q?not_really_valid?="' ,
547+ '"not really valid"' ,
548+ 'not really valid' ,
549+ [errors .InvalidHeaderDefect ],
550+ '' )
551+
543552 # get_comment
544553
545554 def test_get_comment_only (self ):
Original file line number Diff line number Diff line change @@ -1155,6 +1155,16 @@ class TestAddressHeader(TestHeaderBase):
11551155 'example.com' ,
11561156 None ),
11571157
1158+ 'rfc2047_atom_in_quoted_string_is_decoded' :
1159+ (
'"=?utf-8?q?=C3=89ric?=" <[email protected] >' ,
1160+ [errors .InvalidHeaderDefect ],
1161+ 1162+ 'Éric' ,
1163+ 1164+ 'foo' ,
1165+ 'example.com' ,
1166+ None ),
1167+
11581168 }
11591169
11601170 # XXX: Need many more examples, and in particular some with names in
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ Core and Builtins
2727Library
2828-------
2929
30+ - Issue #16983: the new email header parsing code will now decode encoded words
31+ that are (incorrectly) surrounded by quotes, and register a defect.
32+
3033- Issue #19772: email.generator no longer mutates the message object when
3134 doing a down-transform from 8bit to 7bit CTEs.
3235
You can’t perform that action at this time.
0 commit comments