-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
email.Utils.parseaddr fails to parse valid addresses #40889
Comments
email.Utils.parseaddr() does not successfully parse a i.e., it is successfully parses this: "God" <@hop1.org:[email protected]> to get the address <[email protected]>, but it fails to do "God" <@hop1.org,@hop2.net:[email protected]> In this case, it gets the comment ("God") right, but Multi-hop source routes, while deprecated, are still |
# 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('[email protected]')
('', '[email protected]')
>>> parseaddr('"Full Name" <[email protected]>')
('Full Name', '[email protected]')
>>> parseaddr('[email protected] <[email protected]>')
('[email protected]', '[email protected]')
>>> parseaddr('"God" <@hop1.org,@hop2.net:[email protected]>')
('God', '[email protected]')
"""
#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 |
Ok, I see the '@' is technically not allowed in an atom. But it either |
Repeating because previous real life test case was rejected as 'spam': It also fails to parse:
>>> from email.Utils import parseaddr
>>> parseaddr('[email protected] <[email protected]>')
('', '[email protected]') Getting the wrong part as the actual email to boot! Checked 2.4 and 2.5. |
Same or related issues: bpo-1221, bpo-1409460 |
Test cases so far:
>>> parseaddr('[email protected]')
('', '[email protected]')
>>> parseaddr('"Full Name" <[email protected]>')
('Full Name', '[email protected]')
>>> parseaddr('[email protected] <[email protected]>')
('[email protected]', '[email protected]')
>>> parseaddr('God@heaven <@hop1.org,@hop2.net:[email protected]>')
('God@heaven', '[email protected]')
>>> parseaddr('Real Name ((comment)) <[email protected]>')
('Real Name', '[email protected]')
>>> parseaddr('a(WRONG)@b')
('', 'a@b') |
An example from bpo-1221: >>> email.Utils.parseaddr("a(WRONG)@b")
('WRONG WRONG', 'a@b') |
tiran: yes, but that is the wrong answer, and that example is already in |
from 3.6:
>>> AddrlistClass('John Smith <john.smith(comment)@example.org>').getcomment()
''
>>> AddrlistClass('John Smith <john.smith(comment)@example.org>').getdomain()
'JohnSmith' totally messed up :) |
looks like these were meant to be internal methods, retracting new issues |
…tiple intermediate hops
…tiple intermediate hops
…tiple intermediate hops
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
email.utils.parseaddr
to handle multiple hops #123311The text was updated successfully, but these errors were encountered: