emersion / go-smtp

📤 An SMTP client & server library written in Go
MIT License
1.72k stars 216 forks source link

Update MAIL FROM AUTH handling to accept mailbox without angle brackets #226

Closed bobobo1618 closed 1 year ago

bobobo1618 commented 1 year ago

I have a client that sends a message to an SMTP server using this library (the Protonmail bridge) and encounter problems because the client doesn't enclose the AUTH= parameter in angle brackets.

I looked at the relevant RFC and it doesn't appear that this parameter requires angle brackets. RFC2821 (referenced by the other RFC) section 4.1.2 requires angle brackets for a Path but not for a Mailbox. It explicitly allows Mailboxes without angle brackets:

Mailbox = Local-part "@" Domain
Local-part = Dot-string / Quoted-string
            ; MAY be case-sensitive
Dot-string = Atom *("." Atom)
Atom = 1*atext
(From https://datatracker.ietf.org/doc/html/rfc2822#section-3.2.4)
atext           =       ALPHA / DIGIT / ; Any character except controls,
                        "!" / "#" /     ;  SP, and specials.
                        "$" / "%" /     ;  Used for atoms
                        "&" / "'" /
                        "*" / "+" /
                        "-" / "/" /
                        "=" / "?" /
                        "^" / "_" /
                        "`" / "{" /
                        "|" / "}" /
                        "~"

In other words, the Local-part can be composed of a Dot-string, which is composed only alphanumerics plus some special characters (the list of which excludes angle brackets).

emersion commented 1 year ago

I agree that the current behavior is too restrictive, but I think what this PR does is too permissive. It would be nicer to have a proper parser.

Related is #218, although I don't think using regexp is warranted here.

emersion commented 1 year ago

My reading of the spec is that angle brackets are not allowed here, apart from the special case of <>. I've edited the PR accordingly.