jstedfast / MimeKit

A .NET MIME creation and parser library with support for S/MIME, PGP, DKIM, TNEF and Unix mbox spools.
http://www.mimekit.net
MIT License
1.84k stars 373 forks source link

Error if the email address contains a dot before the '@' symbol. #1092

Closed vodoo777 closed 3 weeks ago

vodoo777 commented 3 weeks ago

If the email address contains a dot before the '@' symbol (e.g., john.@domain.com), the error 'Invalid local-part at offset 0' occurs.

Steps to reproduce the behavior: Execute the code: new MailboxAddress(Encoding.UTF8, "Name", " john.@domain.com")

Expected behavior This error should not be raised because email addresses with a dot before the '@' symbol are valid

new MailboxAddress(Encoding.UTF8, "Name", " john.@domain.com")
jstedfast commented 3 weeks ago

That's an invalid address.

The . character must be between atom tokens. For example, john.doe@domain.com is valid, but .doe@domain.com and john.@domain.com are not.

jstedfast commented 3 weeks ago

FWIW, you can enable Looser rfc-compliance which I believe should work for these addresses like this:

var options = ParserOptions.Default.Clone ();
options.AddressParserComplianceMode = RfcComplianceMode.Looser;

if (MailboxAddress.TryParse (options, "john.@domain.com", out var mailbox))
    mailbox.Name = "Name";
vodoo777 commented 3 weeks ago

That's an invalid address.

The . character must be between atom tokens. For example, john.doe@domain.com is valid, but .doe@domain.com and john.@domain.com are not.

I thought the same, but I investigated and found that addresses like john.@domain.com are valid. For example, you can send an email to an address like this, and the recipient will receive it. I tested it with my own email.

vodoo777 commented 3 weeks ago

FWIW, you can enable Looser rfc-compliance which I believe should work for these addresses like this:

var options = ParserOptions.Default.Clone ();
options.AddressParserComplianceMode = RfcComplianceMode.Looser;

if (MailboxAddress.TryParse (options, "john.@domain.com", out var mailbox))
    mailbox.Name = "Name";

Thank you, I will try

jstedfast commented 3 weeks ago

I thought the same, but I investigated and found that addresses like john.@domain.com are valid. For example, you can send an email to an address like this, and the recipient will receive it. I tested it with my own email.

They might technically work, but according to official specifications, they are not legal.

Things like this sometimes work but it's usually because the mail server strips all .'s in the local-part of the address. GMail, for example, does this.

With GMail, john.doe@gmail.com is the same as johndoe@gmail.com for example.

https://support.google.com/mail/answer/7436150?hl=en

vodoo777 commented 3 weeks ago

I thought the same, but I investigated and found that addresses like john.@domain.com are valid. For example, you can send an email to an address like this, and the recipient will receive it. I tested it with my own email.

They might technically work, but according to official specifications, they are not legal.

Things like this sometimes work but it's usually because the mail server strips all .'s in the local-part of the address. GMail, for example, does this.

With GMail, john.doe@gmail.com is the same as johndoe@gmail.com for example.

https://support.google.com/mail/answer/7436150?hl=en

Got it, thank you for the explanation!