summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-05-26 18:31:12 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-05-26 18:31:12 (GMT)
commit032eed3c4a42ca29de2c07fba2e0555eaff1700c (patch)
tree61a12aaf27af7c9a8a024bb2625c888226c6681c /Lib/email
parentd785cb3955e61098056a237b6f322bdda1461aa0 (diff)
downloadcpython-032eed3c4a42ca29de2c07fba2e0555eaff1700c.zip
cpython-032eed3c4a42ca29de2c07fba2e0555eaff1700c.tar.gz
cpython-032eed3c4a42ca29de2c07fba2e0555eaff1700c.tar.bz2
Recognize '<>' as a special case of an angle-addr in header_value_parser.
Although '<>' is invalid according to RFC 5322, SMTP uses it for various things, and it sometimes ends up in email headers. This patch changes get_angle_addr to recognize it and just register a Defect instead of raising a parsing error.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/_header_value_parser.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index 87d8f68..f4a01f1 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -791,6 +791,8 @@ class AngleAddr(TokenList):
for x in self:
if x.token_type == 'addr-spec':
return x.addr_spec
+ else:
+ return '<>'
class ObsRoute(TokenList):
@@ -1829,6 +1831,14 @@ def get_angle_addr(value):
"expected angle-addr but found '{}'".format(value))
angle_addr.append(ValueTerminal('<', 'angle-addr-start'))
value = value[1:]
+ # Although it is not legal per RFC5322, SMTP uses '<>' in certain
+ # circumstances.
+ if value[0] == '>':
+ angle_addr.append(ValueTerminal('>', 'angle-addr-end'))
+ angle_addr.defects.append(errors.InvalidHeaderDefect(
+ "null addr-spec in angle-addr"))
+ value = value[1:]
+ return angle_addr, value
try:
token, value = get_addr_spec(value)
except errors.HeaderParseError:
@@ -1838,7 +1848,7 @@ def get_angle_addr(value):
"obsolete route specification in angle-addr"))
except errors.HeaderParseError:
raise errors.HeaderParseError(
- "expected addr-spec or but found '{}'".format(value))
+ "expected addr-spec or obs-route but found '{}'".format(value))
angle_addr.append(token)
token, value = get_addr_spec(value)
angle_addr.append(token)