File tree Expand file tree Collapse file tree
Open diff view settings
Expand file tree Collapse file tree
Open diff view settings
Original file line number Diff line number Diff line change @@ -337,6 +337,10 @@ def collapse_rfc2231_value(value, errors='replace',
337337 # object. We do not want bytes() normal utf-8 decoder, we want a straight
338338 # interpretation of the string as character bytes.
339339 charset , language , text = value
340+ if charset is None :
341+ # Issue 17369: if charset/lang is None, decode_rfc2231 couldn't parse
342+ # the value, so use the fallback_charset.
343+ charset = fallback_charset
340344 rawbytes = bytes (text , 'raw-unicode-escape' )
341345 try :
342346 return str (rawbytes , charset , errors )
Original file line number Diff line number Diff line change @@ -5018,6 +5018,26 @@ def test_rfc2231_single_tick_in_filename(self):
50185018 self .assertNotIsInstance (param , tuple )
50195019 self .assertEqual (param , "Frank's Document" )
50205020
5021+ def test_rfc2231_missing_tick (self ):
5022+ m = '''\
5023+ Content-Disposition: inline;
5024+ \t filename*0*="'This%20is%20broken";
5025+ '''
5026+ msg = email .message_from_string (m )
5027+ self .assertEqual (
5028+ msg .get_filename (),
5029+ "'This is broken" )
5030+
5031+ def test_rfc2231_missing_tick_with_encoded_non_ascii (self ):
5032+ m = '''\
5033+ Content-Disposition: inline;
5034+ \t filename*0*="'This%20is%E2broken";
5035+ '''
5036+ msg = email .message_from_string (m )
5037+ self .assertEqual (
5038+ msg .get_filename (),
5039+ "'This is\ufffd broken" )
5040+
50215041 # test_headerregistry.TestContentTypeHeader.rfc2231_single_quote_in_value_with_charset_and_lang
50225042 def test_rfc2231_tick_attack_extended (self ):
50235043 eq = self .assertEqual
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ Core and Builtins
4545Library
4646-------
4747
48+ - Issue #17369: get_filename was raising an exception if the filename
49+ parameter's RFC2231 encoding was broken in certain ways. This was
50+ a regression relative to python2.
51+
4852- Issue #20013: Some imap servers disconnect if the current mailbox is
4953 deleted, and imaplib did not handle that case gracefully. Now it
5054 handles the 'bye' correctly.
You can’t perform that action at this time.
0 commit comments