summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2002-09-11 02:22:48 (GMT)
committerBarry Warsaw <barry@python.org>2002-09-11 02:22:48 (GMT)
commit184d55a8970142a18e2c9344b8bc97756d06d9f7 (patch)
treea4d1a609e868325cafdc5070f1034fa823f1324b
parent93ad6a7a3b18c3718d781d2f352df7aef7b5b292 (diff)
downloadcpython-184d55a8970142a18e2c9344b8bc97756d06d9f7.zip
cpython-184d55a8970142a18e2c9344b8bc97756d06d9f7.tar.gz
cpython-184d55a8970142a18e2c9344b8bc97756d06d9f7.tar.bz2
rfc822.unquote() doesn't properly de-backslash-ify in Python prior to
2.3. This patch (adapted from Quinn Dunkan's SF patch #573204) fixes the problem and should get ported to rfc822.py.
-rw-r--r--Lib/email/Utils.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/email/Utils.py b/Lib/email/Utils.py
index cc02f5e..78365be 100644
--- a/Lib/email/Utils.py
+++ b/Lib/email/Utils.py
@@ -13,7 +13,7 @@ import warnings
from cStringIO import StringIO
from types import ListType
-from rfc822 import unquote, quote
+from rfc822 import quote
from rfc822 import AddressList as _AddressList
from rfc822 import mktime_tz
@@ -260,6 +260,17 @@ def parseaddr(addr):
return addrs[0]
+# rfc822.unquote() doesn't properly de-backslash-ify in Python pre-2.3.
+def unquote(str):
+ """Remove quotes from a string."""
+ if len(str) > 1:
+ if str.startswith('"') and str.endswith('"'):
+ return str[1:-1].replace('\\\\', '\\').replace('\\"', '"')
+ if str.startswith('<') and str.endswith('>'):
+ return str[1:-1]
+ return str
+
+
# RFC2231-related functions - parameter encoding and decoding
def decode_rfc2231(s):