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 set_param rfc2231 encoding incorrect
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: barry, iko, r.david.murray
Priority: normal Keywords: patch

Created on 2007-04-03 12:13 by iko, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
rfc2231_quoting.diff r.david.murray, 2010-12-23 23:07
Messages (5)
msg31692 - (view) Author: Anders Hammarquist (iko) Date: 2007-04-03 12:13
Reading the ABNF for the extended parameter values in RFC2231 reveals that they should not be quoted:

   extended-initial-value := [charset] "'" [language] "'"
                             extended-other-values

   extended-other-values := *(ext-octet / attribute-char)

however, set_param (really _formatparam) will always quote them unless requote is set to false. The fix is probably to force quote in _formatparam to False if faced with RFC2231 values, since they should never be quoted (and should not contain characters requiring quoting),
msg97661 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-01-12 21:58
Hmm.  The RFC text says:

   Note that quotes around parameter values are part of the value
   syntax; they are NOT part of the value itself.  Furthermore, it is
   explicitly permitted to have a mixture of quoted and unquoted
   continuation fields.

So this looks more like a bug in the RFC to me.
msg124572 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-23 23:07
Reading the RFC again, I think you are right.  The quoted vs unquoted sounds like it refers to the *n vs the [*n]* forms, and the latter doesn't use quoted strings but % encoding.

I'm attaching a patch that adds some tests and fixes this.  It's a visible behavior change so it won't be backported.  Clearly mailers accept the quoted form, but we prefer to be strictly RFC compliant on output.  The behavior change is that whereas previously unquoted values on parse got quotes added on serialization, now quoted values on parse will lose their quotes on serialization.
msg124574 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-23 23:16
I take it back.  Previously quotes didn't get added if they weren't already there.  So my simpleminded fix may not be the best choice.
msg124617 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-24 22:38
No, I was wrong.  This would only be an issue when a parameter's value is changed, and at that point we should be producing correctly (un)quoted values no matter what the original quoting of the individual value was.

So I've applied the patch in r87479.
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44799
2010-12-24 22:38:54r.david.murraysetstatus: open -> closed
nosy: barry, iko, r.david.murray
messages: + msg124617

resolution: fixed
stage: patch review -> resolved
2010-12-23 23:16:52r.david.murraysetnosy: barry, iko, r.david.murray
messages: + msg124574
2010-12-23 23:07:40r.david.murraysetfiles: + rfc2231_quoting.diff
versions: - Python 3.1, Python 2.7
nosy: barry, iko, r.david.murray
messages: + msg124572

keywords: + patch
stage: test needed -> patch review
2010-09-17 13:07:29BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6, Python 3.0
2010-05-05 13:36:31barrysetstatus: pending -> open
assignee: barry -> r.david.murray
2010-01-12 21:58:27r.david.murraysetstatus: open -> pending
nosy: + r.david.murray
messages: + msg97661

2009-03-30 23:13:42ajaksu2setversions: + Python 2.6, Python 3.0
nosy: + barry

assignee: barry
type: behavior
stage: test needed
2007-04-03 12:13:52ikocreate