Skip to content

Commit

Permalink
Reflect the following changes.
Browse files Browse the repository at this point in the history
----

commit ac26fa6
Author: Jeffrey Stedfast <[email protected]>
Date:   Thu Jan 16 16:44:53 2020 -0500

    Fixed mailbox address parser to be more lenient about []'s in the display-name

    Fixes issue jstedfast#532
  • Loading branch information
aTakuyaKaneko committed Mar 5, 2021
1 parent e6f8c07 commit 3c3cfb0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MimeKit/InternetAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ internal static bool TryParse (ParserOptions options, byte[] text, ref int index
trimLeadingQuote = true;
}
} else {
if (!ParseUtils.SkipWordAndPeriod (text, ref index, endIndex, throwOnError))
if (!ParseUtils.SkipPhraseWordAndPeriod (text, ref index, endIndex, throwOnError))
break;
}

Expand Down
14 changes: 14 additions & 0 deletions MimeKit/Utils/ParseUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ public static bool SkipWordAndPeriod (byte[] text, ref int index, int endIndex,
return false;
}

public static bool SkipPhraseWordAndPeriod (byte[] text, ref int index, int endIndex, bool throwOnError)
{
if (text[index] == (byte) '"')
return SkipQuoted (text, ref index, endIndex, throwOnError);

if (text[index].IsPhraseAtom ())
return SkipPhraseAtom (text, ref index, endIndex);

if (text[index] == (byte) '.')
return SkipPeriod (text, ref index, endIndex);

return false;
}

public static bool IsSentinel (byte c, byte[] sentinels)
{
for (int i = 0; i < sentinels.Length; i++) {
Expand Down
5 changes: 5 additions & 0 deletions UnitTests/InternetAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ static TestCaseData[] LegacyAddressNotCompliantWithRFC()
new TestCaseData ("[email protected]"),
new TestCaseData ("[email protected]"),

// Not compliant with RFC (Square brackets in display name)
new TestCaseData ("[Invalid Sender] <[email protected]>"),
new TestCaseData ("[Invalid Sender] <[email protected]>"),
new TestCaseData ("[Invalid Sender] <[email protected]>"),

// More not compliant with RFC
// Does not correspond now.
//new TestCaseData ("アドレス <aa\"[email protected]>"),
Expand Down
5 changes: 5 additions & 0 deletions UnitTests/MailboxAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,11 @@ static TestCaseData[] LegacyAddressNotCompliantWithRFC ()
new TestCaseData ("[email protected]"),
new TestCaseData ("[email protected]"),

// Not compliant with RFC (Square brackets in display name)
new TestCaseData ("[Invalid Sender] <[email protected]>"),
new TestCaseData ("[Invalid Sender] <[email protected]>"),
new TestCaseData ("[Invalid Sender] <[email protected]>"),

// More not compliant with RFC
// Does not correspond now.
//new TestCaseData ("アドレス <aa\"[email protected]>"),
Expand Down

0 comments on commit 3c3cfb0

Please sign in to comment.