jstedfast / gmime

A C/C++ MIME creation and parser library with support for S/MIME, PGP, and Unix mbox spools.
GNU Lesser General Public License v2.1
111 stars 36 forks source link

GMime.RfcComplianceMode.LOOSE does not allow square bracets in email address #154

Closed bellegarde-c closed 9 months ago

bellegarde-c commented 11 months ago

See [geary#1385](https://gitlab.gnome.org/GNOME/geary/-/issues/1385)

Geary is using GMime.InternetAddressList.parse() to validate email addresses but it returns NULL when having square bracets.

jstedfast commented 11 months ago

The name is not allowed to contain raw []'s. From rfc5322:

   address         =   mailbox / group

   mailbox         =   name-addr / addr-spec

   name-addr       =   [display-name] angle-addr

   angle-addr      =   [CFWS] "<" addr-spec ">" [CFWS] /
                       obs-angle-addr

   group           =   display-name ":" [group-list] ";" [CFWS]

   display-name    =   phrase

   word            =   atom / quoted-string

   phrase          =   1*word / obs-phrase

   atext           =   ALPHA / DIGIT /    ; Printable US-ASCII
                       "!" / "#" /        ;  characters not including
                       "$" / "%" /        ;  specials.  Used for atoms.
                       "&" / "'" /
                       "*" / "+" /
                       "-" / "/" /
                       "=" / "?" /
                       "^" / "_" /
                       "`" / "{" /
                       "|" / "}" /
                       "~"

   atom            =   [CFWS] 1*atext [CFWS]

   specials        =   "(" / ")" /        ; Special characters that do
                       "<" / ">" /        ;  not appear in atext
                       "[" / "]" /
                       ":" / ";" /
                       "@" / "\" /
                       "," / "." /
                       DQUOTE

As you can see here, a display-name needs to match the phrase syntax, which is 1-or-more word tokens where each word token is either a quoted-string or an atom. An atom must only consist of Alpha-Numeric characters or one of the allowed punctuation characters from the atext definition which does not include [ or ].

bellegarde-c commented 11 months ago

Yes I know but Thunderbird and Outlook allow them... :(

jstedfast commented 11 months ago

Is this something that the user is typing into the To text box in the message composer? Or what is the scenario?

bellegarde-c commented 11 months ago

Mail received from a Thunderbird/Outlook client from "user[compagny] user@compagny.com", you reply and geary just fails to validate sender.

jstedfast commented 11 months ago

Okay, but that sounds like Geary isn't properly quoting the name when it stuffs it into the text field though, right?

Because obviously gmime properly parsed it from the From header in order for the []'s to end up in the To textbox when hitting reply.

bellegarde-c commented 10 months ago

You reply and Geary just fails to validate the sender means "send button disabled" because of textbox content.

jstedfast commented 10 months ago

What I'm suggesting is that Geary needs to format the email address such that the []'s are inside a quoted-string when it adds the email address to an address field in your composer window.

If Geary is using internet_address_to_string() or internet_address_list_to_string(), there might be a bug there, but it's not a bug in the parser.

bellegarde-c commented 10 months ago

Ok, wil give a look! Thanks!

jstedfast commented 10 months ago

Did that solve the problem?

bellegarde-c commented 9 months ago

Sorry, did not find time to but will.