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() gives arcane result #42808
Comments
email.Utils.parseaddr('Real Name ((comment))
<addr...@example.com>') returns ('comment <addr...@example.com>', 'Real') Granted the string above is invalid as RFC 2822 does rfc822.parseaddr() returns the same result in this case. If these functions aren't going to return their Note that parseaddr('Real Name <addr...@example.com> ((comment))') does return ('Real Name', 'addr...@example.com') as 'expected'. |
Logged In: YES It looks like this is addressed by patch 1464708 |
Fixed in trunk, so bpo-1464708 was probably forward ported. |
I wonder if this bug should be reopened. This behavior does not seem right to me: parsing 'merwok' parsing 'merwok wok@rusty' (Generated with a twenty-line script just doing a loop and prints, not attached because boring.) Are my expectations wrong? I don’t know if a string like “merwok” in my first example is a legal address in the relevant RFCs, nor do I know if the folding done in the second example is okay. For background, the thing I’m trying to achieve is to take a string and parse it into name and email address, and print a warning if there is no email. It’d be nice if I could always test for “not parseaddr(s)[1]”, or pass an argument to the function to get an exception. Maybe I’ll have to restrict my format and do my own parsing with str.[r]partition. |
I think ('', 'merwok') is the correct result. I think most if not all MUAs/MTAs will interpret an address without an '@', albeit invalid, as a local-part in the local domain, thus parsing 'merwok' as the address 'merwok' with no real name is probably the right thing to do with this input. The alternative would be to return ('', '') indicating failure.
Here, I think failure is a more appropriate return. In any case, I think this is a new bug deserving of a new report. It is not really relevant to this issue which has to do with nested parentheses. |
Thank you for the reply. The problem is that parseaddr is designed to not fail IIUC, that’s why it may return empty strings. Client code has to check for these values instead of catching an exception—a mere style issue, weren’t it for the second bug. So I’m going to report that separately, and restrict the format in my project so that my code can just use string methods. I think I won’t open a feature request for a parameter to get exceptions, since parseaddr is designed not to. |
Copied my inquiry and part of your reply in bpo-9286. |
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:
The text was updated successfully, but these errors were encountered: