summaryrefslogtreecommitdiffstats
path: root/Lib/email/_parseaddr.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-12-18 18:25:38 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-12-18 18:25:38 (GMT)
commit63563cdf9d3afe0bdffaece7b92b0a56d2360397 (patch)
tree6f3004bbefd6bd75e9f841307668676fb075aa51 /Lib/email/_parseaddr.py
parent2b37ce7f30b94fc5ec8adb042554f3cc320f7af2 (diff)
downloadcpython-63563cdf9d3afe0bdffaece7b92b0a56d2360397.zip
cpython-63563cdf9d3afe0bdffaece7b92b0a56d2360397.tar.gz
cpython-63563cdf9d3afe0bdffaece7b92b0a56d2360397.tar.bz2
#9286: Fix the rfc822 parser to preserve whitespace in address local part.
Such addresses are not RFC compliant except under the 'obsolete syntax' rules, but before this fix the whitespace was dropped from the input, concatenating the pieces. That breaks one of the principles of the email package, that of preserving the input as much as possible. It also denies the application program the opportunity to apply its own heuristics to interpretation of such non-compliant addresses. It is possible users of the email package were depending on the local part always being a single token, so this fix will not be backported.
Diffstat (limited to 'Lib/email/_parseaddr.py')
-rw-r--r--Lib/email/_parseaddr.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index 3bd4ba4..699d418 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -199,14 +199,18 @@ class AddrlistClass:
self.commentlist = []
def gotonext(self):
- """Parse up to the start of the next address."""
+ """Skip white space and extract comments."""
+ wslist = []
while self.pos < len(self.field):
if self.field[self.pos] in self.LWS + '\n\r':
+ if self.field[self.pos] not in '\n\r':
+ wslist.append(self.field[self.pos])
self.pos += 1
elif self.field[self.pos] == '(':
self.commentlist.append(self.getcomment())
else:
break
+ return EMPTYSTRING.join(wslist)
def getaddrlist(self):
"""Parse all addresses.
@@ -319,16 +323,24 @@ class AddrlistClass:
self.gotonext()
while self.pos < len(self.field):
+ preserve_ws = True
if self.field[self.pos] == '.':
+ if aslist and not aslist[-1].strip():
+ aslist.pop()
aslist.append('.')
self.pos += 1
+ preserve_ws = False
elif self.field[self.pos] == '"':
aslist.append('"%s"' % quote(self.getquote()))
elif self.field[self.pos] in self.atomends:
+ if aslist and not aslist[-1].strip():
+ aslist.pop()
break
else:
aslist.append(self.getatom())
- self.gotonext()
+ ws = self.gotonext()
+ if preserve_ws and ws:
+ aslist.append(ws)
if self.pos >= len(self.field) or self.field[self.pos] != '@':
return EMPTYSTRING.join(aslist)