Commit 8e1e7f54 authored by Barry Warsaw's avatar Barry Warsaw

decode_rfc2231(): RFC 2231 allows leaving out both the charset and

language without including any single quotes.
parent 21fcc4e2
...@@ -280,9 +280,11 @@ def unquote(str): ...@@ -280,9 +280,11 @@ def unquote(str):
def decode_rfc2231(s): def decode_rfc2231(s):
"""Decode string according to RFC 2231""" """Decode string according to RFC 2231"""
import urllib import urllib
charset, language, s = s.split("'", 2) parts = s.split("'", 2)
s = urllib.unquote(s) if len(parts) == 1:
return charset, language, s return None, None, s
charset, language, s = parts
return charset, language, urllib.unquote(s)
def encode_rfc2231(s, charset=None, language=None): def encode_rfc2231(s, charset=None, language=None):
...@@ -335,6 +337,6 @@ def decode_params(params): ...@@ -335,6 +337,6 @@ def decode_params(params):
for num, continuation in continuations: for num, continuation in continuations:
value.append(continuation) value.append(continuation)
charset, language, value = decode_rfc2231(EMPTYSTRING.join(value)) charset, language, value = decode_rfc2231(EMPTYSTRING.join(value))
new_params.append((name, new_params.append(
(charset, language, '"%s"' % quote(value)))) (name, (charset, language, '"%s"' % quote(value))))
return new_params return new_params
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment