summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-12-14 00:29:27 +0000
committerR. David Murray <rdmurray@bitdance.com>2010-12-14 00:29:27 +0000
commita9aa34c7cd3eb9bfc88d2a4eed0ad78a8e8c885a (patch)
treef2b39b0ec1c97707601eb1253ebffc4cd2357761 /Lib
parent910c52fcf4ef25ce4c765aa3f2733704b4adaab7 (diff)
downloadcpython-git-a9aa34c7cd3eb9bfc88d2a4eed0ad78a8e8c885a.tar.gz
#1078919: document requirement to use triples for non-ascii add_header parms.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/email/message.py9
-rw-r--r--Lib/email/test/test_email.py15
2 files changed, 22 insertions, 2 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py
index 40f808e8b5..7c93370984 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -38,7 +38,9 @@ def _splitparam(param):
def _formatparam(param, value=None, quote=True):
"""Convenience function to format and return a key=value pair.
- This will quote the value if needed or if quote is true.
+ This will quote the value if needed or if quote is true. If value is a
+ three tuple (charset, language, value), it will be encoded according
+ to RFC2231 rules.
"""
if value is not None and len(value) > 0:
# A tuple is used for RFC 2231 encoded parameter values where items
@@ -389,7 +391,10 @@ class Message:
name is the header field to add. keyword arguments can be used to set
additional parameters for the header field, with underscores converted
to dashes. Normally the parameter will be added as key="value" unless
- value is None, in which case only the key will be added.
+ value is None, in which case only the key will be added. If a
+ parameter value contains non-ASCII characters it must be specified as a
+ three-tuple of (charset, language, value), in which case it will be
+ encoded according to RFC2231 rules.
Example:
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index d93287a474..7a1d699cf6 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -3113,6 +3113,21 @@ A very long line that must get split to something other than at the
s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?='
raises(Errors.HeaderParseError, decode_header, s)
+ # Issue 1078919
+ def test_ascii_add_header(self):
+ msg = Message()
+ msg.add_header('Content-Disposition', 'attachment',
+ filename='bud.gif')
+ self.assertEqual('attachment; filename="bud.gif"',
+ msg['Content-Disposition'])
+
+ def test_nonascii_add_header_via_triple(self):
+ msg = Message()
+ msg.add_header('Content-Disposition', 'attachment',
+ filename=('iso-8859-1', '', 'Fu\xdfballer.ppt'))
+ self.assertEqual(
+ 'attachment; filename*="iso-8859-1\'\'Fu%DFballer.ppt"',
+ msg['Content-Disposition'])
# Test RFC 2231 header parameters (en/de)coding