public void TestMultipleWhiteSpacesPerLine () { const string text = "This is a test of the relaxed body filter with \t multiple \t spaces\n"; const string expected = "This is a test of the relaxed body filter with multiple spaces\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); }
public void TestTrimmingEmptyLines () { 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; 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); }
public void TestWhiteSpaceBeforeNewLine () { const string text = "text\t \r\n\t \r\ntext\t \r\n"; const string expected = "text\r\n\r\ntext\r\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); }
public void TestNonEmptyBodyEndingWithMultipleNewLines () { const string text = "This is a test of the relaxed body filter with a non-empty body ending with multiple new-lines\n\n\n"; const string expected = "This is a test of the relaxed body filter with a non-empty body ending with multiple new-lines\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); }
byte[] DkimHashBody (FormatOptions options, DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm bodyCanonicalizationAlgorithm, int maxLength) { using (var stream = new DkimHashStream (signatureAlgorithm, maxLength)) { using (var filtered = new FilteredStream (stream)) { DkimBodyFilter dkim; if (bodyCanonicalizationAlgorithm == DkimCanonicalizationAlgorithm.Relaxed) dkim = new DkimRelaxedBodyFilter (); else dkim = new DkimSimpleBodyFilter (); filtered.Add (options.CreateNewLineFilter ()); filtered.Add (dkim); if (Body != null) { try { Body.EnsureNewLine = compliance == RfcComplianceMode.Strict; Body.Headers.Suppress = true; Body.WriteTo (options, filtered, CancellationToken.None); } finally { Body.Headers.Suppress = false; Body.EnsureNewLine = false; } } filtered.Flush (); if (!dkim.LastWasNewLine) stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length); } return stream.GenerateHash (); } }