Skip to content

Commit

Permalink
Added work-around for mailers that don't use a ';' between Content-Ty…
Browse files Browse the repository at this point in the history
…pe/Content-Disposition parameters

Fixes issue #595
  • Loading branch information
jstedfast committed Jul 30, 2020
1 parent 7368395 commit 5850645
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 8 additions & 5 deletions MimeKit/ParameterList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -973,13 +973,16 @@ internal static bool TryParse (ParserOptions options, byte[] text, ref int index
break;

if (text[index] != (byte) ';') {
if (throwOnError)
throw new ParseException (string.Format (CultureInfo.InvariantCulture, "Invalid parameter list token at offset {0}", index), index, index);
if (options.ParameterComplianceMode == RfcComplianceMode.Strict) {
if (throwOnError)
throw new ParseException (string.Format (CultureInfo.InvariantCulture, "Invalid parameter list token at offset {0}", index), index, index);

return false;
return false;
}
} else {
// Skip over ';'
index++;
}

index++;
} while (true);

paramList = new ParameterList ();
Expand Down
13 changes: 12 additions & 1 deletion UnitTests/ContentTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ public void TestContentTypeWithEmptyParameter ()
AssertParse (text, expected);
}

// Tests the work-around for issue #595
[Test]
public void TestContentTypeWithoutSemicolonBetweenParameters ()
{
const string text = "application/x-pkcs7-mime;\n name=\"smime.p7m\"\n smime-type=enveloped-data";
var expected = new ContentType ("application", "x-pkcs7-mime") { Name = "smime.p7m" };
expected.Parameters.Add ("smime-type", "enveloped-data");

AssertParse (text, expected, true);
}

[Test]
public void TestContentTypeAndContentTrafserEncodingOnOneLine ()
{
Expand All @@ -260,7 +271,7 @@ public void TestContentTypeAndContentTrafserEncodingOnOneLine ()

// TryParse should "fail", but still produce a usable ContentType.
// Parse will throw ParseException.
AssertParse (text, expected, false, 35, 35);
AssertParse (text, expected, false, 35, 60);
}

[Test]
Expand Down

0 comments on commit 5850645

Please sign in to comment.