Skip to content

email_validator.EmailSyntaxError: The email address contains invalid characters before the @-sign: (, ), .. #77

Description

@erika-humu

Currently validate_email raises an exception on valid emails with the form john.smith(comment)@example.com and (comment)john.smith@example.com due to the parenthesis, which are actually valid at the beginning and end of the local portion of the email address.

Activity

  1. JoshData commented on Apr 22, 2022

    @JoshData
    Owner

    This is new to me. I see in RFC2822 3.2.3 that parenthesized comments are allowed in various places. The RFC isn't super clear what the purpose of comments is, although it says that "Runs of FWS, comment or CFWS that occur between lexical tokens in a structured field header are semantically interpreted as a single space character," which I take to mean that comments should essentially be ignored (especially since a space would not be valid in an email address). In section 3.4 (Address Specification) it also says "Also, because some legacy implementations interpret the comment, comments generally SHOULD NOT be used in address fields to avoid confusing such implementations," which again I think means that a comment may appear within an address but it is not a part of the address.

    I think the specification then is pretty clear that email addresses cannot semantically contain a comment. So I think the behavior of this library is correct per the spec. The main use case for this project is supporting email-based web login forms, and in that case what we really want is an actual, deliverable email address without extraneous content that might be permitted in a MIME message but according to the spec should be discarded.

    On the other hand, I tried sending myself an email that added "(comment)" at the start or before the @-sign in my address, and the comment was "interpreted," i.e. considered a part of the address, and the email bounced because it didn't match a recipient mailbox. (I used Thunderbird on the client side and once with a postfix server and a second time with gmail as the recipient). Other MUAs and MTAs might have different behavior.) So this seems to be contrary to the spec.

    It might be that no software implements comments according to the intent of the spec, and the de facto state of things might be that comments are permitted and are a meaningful part of the address.

    Do you have reason to believe that john.smith(comment)@example.com can be a separate mailbox from (comment)john.smith@example.com and john.smith@example.com? If yes, then I should consider supporting it. If no, then I probably should not support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions