mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Message.getaddrlist(): This now handles multiple occurances of the
named header, so that if a message has, e.g. multiple CC: lines, all will get returned by the call to getaddrlist(). It also correctly handles addresses which show up in continuation lines. AdderlistClass.__init__(): Added \n to self.CR which fixes a bug that sometimes, an address would contain a bogus trailing newline. Message.getaddress(): In final else clause, added a test for the character we're at being in self.specials. Without this, such characters never get consumed and we infloop. Case in point (as posted to c.l.py): To: <[smtp:dd47@mail.xxx.edu]_at_hmhq@hdq-mdm1-imgout.companay.com> ----------------------------^ otherwise we'd infloop here
This commit is contained in:
parent
f8ebb5521d
commit
8a578436f4
1 changed files with 21 additions and 12 deletions
|
@ -299,15 +299,24 @@ class Message:
|
||||||
def getaddrlist(self, name):
|
def getaddrlist(self, name):
|
||||||
"""Get a list of addresses from a header.
|
"""Get a list of addresses from a header.
|
||||||
|
|
||||||
Retrieves a list of addresses from a header, where each
|
Retrieves a list of addresses from a header, where each address is a
|
||||||
address is a tuple as returned by getaddr().
|
tuple as returned by getaddr(). Scans all named headers, so it works
|
||||||
|
properly with multiple To: or Cc: headers for example.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# New, by Ben Escoto
|
raw = []
|
||||||
try:
|
for h in self.getallmatchingheaders(name):
|
||||||
data = self[name]
|
if h[0] in ' \t':
|
||||||
except KeyError:
|
raw.append(h)
|
||||||
return []
|
else:
|
||||||
a = AddrlistClass(data)
|
if raw:
|
||||||
|
raw.append(', ')
|
||||||
|
i = string.find(h, ':')
|
||||||
|
if i > 0:
|
||||||
|
addr = h[i+1:]
|
||||||
|
raw.append(addr)
|
||||||
|
alladdrs = string.join(raw, '')
|
||||||
|
a = AddrlistClass(alladdrs)
|
||||||
return a.getaddrlist()
|
return a.getaddrlist()
|
||||||
|
|
||||||
def getdate(self, name):
|
def getdate(self, name):
|
||||||
|
@ -465,9 +474,8 @@ class AddrlistClass:
|
||||||
self.specials = '()<>@,:;.\"[]'
|
self.specials = '()<>@,:;.\"[]'
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
self.LWS = ' \t'
|
self.LWS = ' \t'
|
||||||
self.CR = '\r'
|
self.CR = '\r\n'
|
||||||
self.atomends = self.specials + self.LWS + self.CR
|
self.atomends = self.specials + self.LWS + self.CR
|
||||||
|
|
||||||
self.field = field
|
self.field = field
|
||||||
self.commentlist = []
|
self.commentlist = []
|
||||||
|
|
||||||
|
@ -539,6 +547,8 @@ class AddrlistClass:
|
||||||
else:
|
else:
|
||||||
if plist:
|
if plist:
|
||||||
returnlist = [(string.join(self.commentlist), plist[0])]
|
returnlist = [(string.join(self.commentlist), plist[0])]
|
||||||
|
elif self.field[self.pos] in self.specials:
|
||||||
|
self.pos = self.pos + 1
|
||||||
|
|
||||||
self.gotonext()
|
self.gotonext()
|
||||||
if self.pos < len(self.field) and self.field[self.pos] == ',':
|
if self.pos < len(self.field) and self.field[self.pos] == ',':
|
||||||
|
@ -618,7 +628,6 @@ class AddrlistClass:
|
||||||
elif self.field[self.pos] in self.atomends:
|
elif self.field[self.pos] in self.atomends:
|
||||||
break
|
break
|
||||||
else: sdlist.append(self.getatom())
|
else: sdlist.append(self.getatom())
|
||||||
|
|
||||||
return string.join(sdlist, '')
|
return string.join(sdlist, '')
|
||||||
|
|
||||||
def getdelimited(self, beginchar, endchars, allowcomments = 1):
|
def getdelimited(self, beginchar, endchars, allowcomments = 1):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue