From 71abff2a33c5f7c156d7b443cd770829022cdbdc Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 9 Nov 2015 14:31:57 -0500 Subject: [PATCH] Fixed logic for trimming trailing blank lines for the DKIM relaxed body algorithm Fixes issue #187 --- MimeKit/Cryptography/DkimRelaxedBodyFilter.cs | 2 +- UnitTests/DkimRelaxedBodyFilterTests.cs | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/MimeKit/Cryptography/DkimRelaxedBodyFilter.cs b/MimeKit/Cryptography/DkimRelaxedBodyFilter.cs index 61caa13ecd..69fc080003 100644 --- a/MimeKit/Cryptography/DkimRelaxedBodyFilter.cs +++ b/MimeKit/Cryptography/DkimRelaxedBodyFilter.cs @@ -89,7 +89,7 @@ unsafe int Filter (byte* inbuf, int length, byte* outbuf) if ((*inptr).IsBlank ()) { LastWasNewLine = false; - IsEmptyLine = false; + //IsEmptyLine = false; lwsp = true; } else { if (lwsp) { diff --git a/UnitTests/DkimRelaxedBodyFilterTests.cs b/UnitTests/DkimRelaxedBodyFilterTests.cs index 2851b94189..b16a67bf1f 100644 --- a/UnitTests/DkimRelaxedBodyFilterTests.cs +++ b/UnitTests/DkimRelaxedBodyFilterTests.cs @@ -41,11 +41,29 @@ namespace UnitTests { [TestFixture] public class DkimRelaxedBodyFilterTests { + // Disabled because it conflicts with TestTrimmingEmptyLines() +// [Test] +// public void TestWhiteSpaceBeforeNewLine () +// { +// const string text = "This is a test of the relaxed body filter \n \n"; +// const string expected = "This is a test of the relaxed body filter\n\n"; +// var input = Encoding.ASCII.GetBytes (text); +// var filter = new DkimRelaxedBodyFilter (); +// int outputIndex, outputLength; +// byte[] output; +// string actual; +// +// output = filter.Flush (input, 0, input.Length, out outputIndex, out outputLength); +// actual = Encoding.ASCII.GetString (output, outputIndex, outputLength); +// +// Assert.AreEqual (expected, actual); +// } + [Test] - public void TestWhiteSpaceBeforeNewLine () + public void TestTrimmingEmptyLines () { - const string text = "This is a test of the relaxed body filter \n \n"; - const string expected = "This is a test of the relaxed body filter\n\n"; + const string text = "Hello!\r\n \r\n\r\n"; + const string expected = "Hello!\r\n"; var input = Encoding.ASCII.GetBytes (text); var filter = new DkimRelaxedBodyFilter (); int outputIndex, outputLength;