Author jpic
Recipients Dain Dwarf, Windson Yang, barry, bortzmeyer, cnicodeme, jpic, kal.sze, msapiro, ned.deily, nicoe, r.david.murray, vstinner, xtreak
Date 2019-05-04.13:02:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAC6Op18kkWgxFXEfgrgzQiU8RuDyT4uOWNWc1f-_sysL0FS-bQ@mail.gmail.com>
In-reply-to <1556936180.55.0.64812418912.issue34155@roundup.psfhosted.org>
Content
At is allowed in the local part if quoted, the proposed patch acts within
get_domain() and getdomain() and does not affect local part parsing. This
still works:

>>> parseaddr('"fo@bar"@bar.com')
('', '"fo@bar"@bar.com')

>>> email.message_from_string('From: "a@b"@ex.com
',policy=email.policy.default)['from'].addresses
(Address(display_name='', username='a@b', domain='ex.com'),)

I'm not against raising an exception in parseaddr, but you should know that
currently nothing in parseaddr seems to raise an exception:

jpic@ci:~/cpython$ grep raise Lib/email/_parseaddr.py
jpic@ci:~/cpython$

For example:

>>> parseaddr('aoeu')
('', 'aoeu')
>>> parseaddr('a@')
('', 'a@')

None of the above calls raised an exception. That is the reason why I did
not introduce a new Exception in the getdomain() change: I thought it would
be more consistent with the rest of the API as such.

As for the new API, the patch does raise a parse error:

 # this detect that the next caracter right after the parsed domain is
another @
if value and value[0] == '@':
      raise errors.HeaderParseError('Multiple domains')

But that's in the lower level API that is planned for going public later on
(probably when it will have unit tests), it's just the higher level API
that the user faces that swallows it. As a user you can still know about
that parse problem using the defects attribute:

>>> email.message_from_string('From: a@malicious.org@example.com',
policy=email.policy.default)['from'].defects[0]
InvalidHeaderDefect('invalid address in address-list')
History
Date User Action Args
2019-05-04 13:02:09jpicsetrecipients: + jpic, barry, vstinner, msapiro, ned.deily, r.david.murray, nicoe, kal.sze, Windson Yang, xtreak, cnicodeme, bortzmeyer, Dain Dwarf
2019-05-04 13:02:09jpiclinkissue34155 messages
2019-05-04 13:02:08jpiccreate