Skip to content

MailAddress accepts invalid email address with consecutive dots #109590

@lscorcia

Description

@lscorcia

Description

According to RFC5322/RFC2822, email addresses with multiple consecutive dots are invalid, e.g. test..address@example.com or address@test..example.com should be rejected when parsing email addresses.

Quoted from https://serverfault.com/questions/395766/are-two-periods-allowed-in-the-local-part-of-an-email-address:

RFC 2822 seems to object to this in section 3.4.1:

The locally interpreted string is either a quoted-string or a dot-atom. If the string can be represented as a dot-atom (that is, it contains no characters other than atext characters or "." surrounded by atext characters), then the dot-atom form SHOULD be used and the quoted-string form SHOULD NOT be used. Comments and folding white space SHOULD NOT be used around the "@" in the addr-spec.

Furthermore, in that same section, it references this:

addr-spec = local-part "@" domain
local-part = dot-atom / quoted-string / obs-local-part

Reproduction Steps

public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(new System.Net.Mail.MailAddress("test..address@example.it"));
        Console.WriteLine(new System.Net.Mail.MailAddress("address@test..example.it"));
    }
}

Expected behavior

Invalid addresses should be rejected by the MailAddress class.

Actual behavior

Currently the System.Net.Mail.MailAddress class happily accepts such malformed addresses.

Regression?

Tested on .net 4.7.2, .net 6 and 8, behavior is the same so I'd say not a regression.

Known Workarounds

Manual validation or using any other tool to validate addresses before passing them to MailAddress. For example, MimeKit throws an exception with both two lines:

Console.WriteLine(MailboxAddress.Parse("test..address@example.it"));
Console.WriteLine(MailboxAddress.Parse("address@test..example.it"));

Configuration

Tested on .net 4.7.2, .net 6 and .net 8.

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Netbughelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions