From: Barry Warsaw Date: Fri, 7 Mar 2003 22:46:41 +0000 (+0000) Subject: decode_rfc2231(): RFC 2231 allows leaving out both the charset and X-Git-Tag: v2.3c1~1524 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e1e7f5468f972891446f3caa078b85a1c920ccb;p=thirdparty%2FPython%2Fcpython.git decode_rfc2231(): RFC 2231 allows leaving out both the charset and language without including any single quotes. --- diff --git a/Lib/email/Utils.py b/Lib/email/Utils.py index 4b5394d34f97..28b445995420 100644 --- a/Lib/email/Utils.py +++ b/Lib/email/Utils.py @@ -280,9 +280,11 @@ def unquote(str): def decode_rfc2231(s): """Decode string according to RFC 2231""" import urllib - charset, language, s = s.split("'", 2) - s = urllib.unquote(s) - return charset, language, s + parts = s.split("'", 2) + if len(parts) == 1: + return None, None, s + charset, language, s = parts + return charset, language, urllib.unquote(s) def encode_rfc2231(s, charset=None, language=None): @@ -335,6 +337,6 @@ def decode_params(params): for num, continuation in continuations: value.append(continuation) charset, language, value = decode_rfc2231(EMPTYSTRING.join(value)) - new_params.append((name, - (charset, language, '"%s"' % quote(value)))) + new_params.append( + (name, (charset, language, '"%s"' % quote(value)))) return new_params