This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: email message.get_params() and related methods sometimes fail.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: barry, l0nwlf, msapiro, r.david.murray, rcoyner
Priority: normal Keywords: easy, patch

Created on 2009-02-16 04:35 by msapiro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
message.patch msapiro, 2009-02-16 04:35 Patch to not count quoted quotes in _parseparams()
issue5277.patch rcoyner, 2010-03-04 07:21 email.get_param() properly escapes quotations.
Messages (4)
msg82215 - (view) Author: Mark Sapiro (msapiro) * (Python triager) Date: 2009-02-16 04:35
The message method get_params() and the related get_param() and
get_filename() do not properly decode an RFC 2231 encoded parameter such
as the following:

Content-Disposition: inline;
 filename*0="Re: [Mailman-Users] Messages shunted with \"TypeError: ";
 filename*1="decodingUnicode is not supported\".eml"

This is because the message helper function _parseparams() mistakenly
thinks the second semicolon is inside a quoted string because it counts
the quoted (escaped) quote and sees an odd number.

The attached patch will fix this.
msg100377 - (view) Author: Ryan Coyner (rcoyner) Date: 2010-03-04 07:21
Okay, bug confirmed:

>>> m = email.message_from_string('Content-Disposition: inline; filename*0="foo \\"test"; filename*1="\\"bar"')
>>> m.get_filename()
'foo "test"; filename*1=""bar'


And here is the result with the patch applied:

>>> m = email.message_from_string('Content-Disposition: inline; filename*0="foo \\"test"; filename*1="\\"bar"')
>>> m.get_filename()
'foo "test"bar'


Attached a patch. Unit test included.
msg102976 - (view) Author: Shashwat Anand (l0nwlf) Date: 2010-04-12 21:48
According to RFC2231 the named disposition (content disposition field) is provided by the MIME mechanism. The encoded parameter like the following:

Content-Disposition: inline;
 filename*0="Re: [Mailman-Users] Messages shunted with \"TypeError: ";
 filename*1="decodingUnicode is not supported\".eml"

is not behaving the way it should be.
The patch by rcoyner seems fine to me as it rectifies the wrong behaviour of _parseparam i.e. the counting issue of nested 'double quotes' and clears the unit tests.
msg103140 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-04-14 19:08
Thanks Mark and Ryan for the patches, and Shashwat for the review.  Committed to trunk in r80062, 2.6 in r80063, py3k in r80078, and 3.1 in r80079.
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49527
2010-04-14 19:08:09r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg103140

stage: patch review -> resolved
2010-04-12 21:48:44l0nwlfsetnosy: + l0nwlf
messages: + msg102976
2010-03-04 12:35:52r.david.murraysetassignee: r.david.murray

nosy: + r.david.murray
stage: test needed -> patch review
2010-03-04 07:21:45rcoynersetfiles: + issue5277.patch
nosy: + rcoyner
messages: + msg100377

2010-01-08 01:49:06r.david.murraysetpriority: normal
keywords: + easy
stage: test needed
versions: + Python 2.7, Python 3.2, - Python 2.5, Python 2.4, Python 3.0
2009-02-16 04:35:14msapirocreate