Issue1025395
Created on 2004-09-09 20:43 by melicertes, last changed 2009-07-04 02:42 by ezio.melotti.
|
msg22413 - (view) |
Author: Charles (melicertes) |
Date: 2004-09-09 20:43 |
|
email.Utils.parseaddr() does not successfully parse a
field value into a (comment, address) pair if the
address contains a source route with more than one hop.
i.e., it is successfully parses this:
"God" <@hop1.org:jeff@spec.org>
to get the address <jeff@spec.org>, but it fails to do
the same if supplied with a 2-hop source route:
"God" <@hop1.org,@hop2.net:jeff@spec.org>
In this case, it gets the comment ("God") right, but
fails to extract the address.
Multi-hop source routes, while deprecated, are still
valid in rfc2822.
|
|
msg59669 - (view) |
Author: Stuart D Gathman (sdgathman) |
Date: 2008-01-10 16:34 |
|
# A quick and very dirty fix for common broken cases, with test cases.
import rfc822
def parseaddr(t):
"""Split email into Fullname and address.
>>> parseaddr('user@example.com')
('', 'user@example.com')
>>> parseaddr('"Full Name" <foo@example.com>')
('Full Name', 'foo@example.com')
>>> parseaddr('spam@viagra.com <foo@example.com>')
('spam@viagra.com', 'foo@example.com')
>>> parseaddr('"God" <@hop1.org,@hop2.net:jeff@spec.org>')
('God', 'jeff@spec.org')
"""
#return email.Utils.parseaddr(t)
res = rfc822.parseaddr(t)
# dirty fix for some broken cases
if not res[0]:
pos = t.find('<')
if pos > 0 and t[-1] == '>':
addrspec = t[pos+1:-1]
pos1 = addrspec.rfind(':')
if pos1 > 0:
addrspec = addrspec[pos1+1:]
return rfc822.parseaddr('"%s" <%s>' % (t[:pos].strip(),addrspec))
if not res[1]:
pos = t.find('<')
if pos > 0 and t[-1] == '>':
addrspec = t[pos+1:-1]
pos1 = addrspec.rfind(':')
if pos1 > 0:
addrspec = addrspec[pos1+1:]
return rfc822.parseaddr('%s<%s>' % (t[:pos].strip(),addrspec))
return res
|
|
msg59670 - (view) |
Author: Stuart D Gathman (sdgathman) |
Date: 2008-01-10 16:37 |
|
Ok, I see the '@' is technically not allowed in an atom. But it either
needs to throw an invalid syntax exception, or heuristically return
something reasonable.
|
|
msg59671 - (view) |
Author: Stuart D Gathman (sdgathman) |
Date: 2008-01-10 16:39 |
|
Repeating because previous real life test case was rejected as 'spam':
It also fails to parse:
>>> from email.Utils import parseaddr
>>> parseaddr('foo@spammer.com <bar@baz.com>')
('', 'foo@spammer.com')
Getting the wrong part as the actual email to boot! Checked 2.4 and 2.5.
|
|
msg59735 - (view) |
Author: Stuart D Gathman (sdgathman) |
Date: 2008-01-11 19:08 |
|
Same or related issues: Issue1221, Issue1409460
|
|
msg59737 - (view) |
Author: Stuart D Gathman (sdgathman) |
Date: 2008-01-11 19:14 |
|
Test cases so far:
>>> parseaddr('user@example.com')
('', 'user@example.com')
>>> parseaddr('"Full Name" <foo@example.com>')
('Full Name', 'foo@example.com')
>>> parseaddr('spam@spammer.com <foo@example.com>')
('spam@spammer.com', 'foo@example.com')
>>> parseaddr('God@heaven <@hop1.org,@hop2.net:jeff@spec.org>')
('God@heaven', 'jeff@spec.org')
>>> parseaddr('Real Name ((comment)) <addr...@example.com>')
('Real Name', 'addr...@example.com')
>>> parseaddr('a(WRONG)@b')
('', 'a@b')
|
|
msg59751 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2008-01-11 21:18 |
|
An example from #1221:
>>> email.Utils.parseaddr("a(WRONG)@b")
('WRONG WRONG', 'a@b')
|
|
msg59753 - (view) |
Author: Stuart D Gathman (sdgathman) |
Date: 2008-01-11 21:21 |
|
tiran: yes, but that is the wrong answer, and that example is already in
the testcase list (with what I believe is the right answer).
|
|
| Date |
User |
Action |
Args |
| 2009-07-04 02:42:37 | ezio.melotti | set | stage: test needed versions:
+ Python 2.7, - Python 2.5, Python 2.4, Python 2.3 |
| 2008-01-28 08:33:42 | loewis | set | messages:
- msg59668 |
| 2008-01-11 21:21:47 | sdgathman | set | messages:
+ msg59753 |
| 2008-01-11 21:18:31 | christian.heimes | link | issue1221 superseder |
| 2008-01-11 21:18:11 | christian.heimes | set | nosy:
+ christian.heimes messages:
+ msg59751 |
| 2008-01-11 19:14:26 | sdgathman | set | messages:
+ msg59737 |
| 2008-01-11 19:08:47 | sdgathman | set | messages:
+ msg59735 |
| 2008-01-10 16:39:04 | sdgathman | set | messages:
+ msg59671 |
| 2008-01-10 16:37:37 | sdgathman | set | messages:
+ msg59670 |
| 2008-01-10 16:34:08 | sdgathman | set | messages:
+ msg59669 |
| 2008-01-10 16:22:47 | sdgathman | set | type: behavior |
| 2008-01-10 16:22:18 | sdgathman | set | nosy:
+ sdgathman messages:
+ msg59668 versions:
+ Python 2.5, Python 2.4 |
| 2004-09-09 20:43:42 | melicertes | create | |
|