summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-05-28 00:45:01 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-05-28 00:45:01 (GMT)
commitadbdcdbd9527a3c4000cd4ff0678ff60151f1f79 (patch)
tree00f76f4304feb96a32a8140efae37c5935d10bd6 /Lib/email
parent2c172d04bb6af565dcb1217aaba1b347c99b54ea (diff)
downloadcpython-adbdcdbd9527a3c4000cd4ff0678ff60151f1f79.zip
cpython-adbdcdbd9527a3c4000cd4ff0678ff60151f1f79.tar.gz
cpython-adbdcdbd9527a3c4000cd4ff0678ff60151f1f79.tar.bz2
#14925: email now registers a defect for missing header/body separator.
This patch also deprecates the MalformedHeaderDefect. My best guess is that this defect was rendered obsolete by a refactoring of the parser, and the corresponding defect for the new parser (which this patch introduces) was overlooked.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/errors.py6
-rw-r--r--Lib/email/feedparser.py10
2 files changed, 9 insertions, 7 deletions
diff --git a/Lib/email/errors.py b/Lib/email/errors.py
index f916229..aa836d4 100644
--- a/Lib/email/errors.py
+++ b/Lib/email/errors.py
@@ -48,8 +48,10 @@ class FirstHeaderLineIsContinuationDefect(MessageDefect):
class MisplacedEnvelopeHeaderDefect(MessageDefect):
"""A 'Unix-from' header was found in the middle of a header block."""
-class MalformedHeaderDefect(MessageDefect):
- """Found a header that was missing a colon, or was otherwise malformed."""
+class MissingHeaderBodySeparatorDefect(MessageDefect):
+ """Found line with no leading whitespace and no colon before blank line."""
+# XXX: backward compatibility, just in case (it was never emitted).
+MalformedHeaderDefect = MissingHeaderBodySeparatorDefect
class MultipartInvariantViolationDefect(MessageDefect):
"""A message claimed to be a multipart but no subparts were found."""
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
index 0706cae..c3a67c0 100644
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -219,6 +219,8 @@ class FeedParser:
# (i.e. newline), just throw it away. Otherwise the line is
# part of the body so push it back.
if not NLCRE.match(line):
+ defect = errors.MissingHeaderBodySeparatorDefect()
+ self.policy.handle_defect(self._cur, defect)
self._input.unreadline(line)
break
headers.append(line)
@@ -488,12 +490,10 @@ class FeedParser:
self._cur.defects.append(defect)
continue
# Split the line on the colon separating field name from value.
+ # There will always be a colon, because if there wasn't the part of
+ # the parser that calls us would have started parsing the body.
i = line.find(':')
- if i < 0:
- defect = errors.MalformedHeaderDefect(line)
- # XXX: fixme (defect not going through policy)
- self._cur.defects.append(defect)
- continue
+ assert i>0, "_parse_headers fed line with no : and no leading WS"
lastheader = line[:i]
lastvalue = [line]
# Done with all the lines, so handle the last header.