Beispiel #1
0
        public void DecorateMessage(TransportMailItem message)
        {
            message.HeloDomain           = ConfigurationProvider.GetDefaultDomainName();
            message.ReceiveConnectorName = "FromLocal";
            message.RefreshMimeSize();
            long       mimeSize = message.MimeSize;
            HeaderList headers  = message.RootPart.Headers;

            if (!(headers.FindFirst(HeaderId.Date) is DateHeader))
            {
                DateHeader newChild = new DateHeader("Date", DateTime.UtcNow.ToLocalTime());
                headers.AppendChild(newChild);
            }
            headers.RemoveAll(HeaderId.Received);
            DateHeader     dateHeader = new DateHeader("Date", DateTime.UtcNow.ToLocalTime());
            string         value      = dateHeader.Value;
            ReceivedHeader newChild2  = new ReceivedHeader(this.SourceServerFqdn, SubmissionItemBase.FormatIPAddress(this.SourceServerNetworkAddress), this.LocalIP.HostName, this.ReceivedHeaderTcpInfo, null, this.mailProtocol, SubmissionItemBase.serverVersion, null, value);

            headers.PrependChild(newChild2);
            message.ExtendedProperties.SetValue <bool>("Microsoft.Exchange.Transport.ElcJournalReport", this.IsElcJournalReport);
            if (this.IsMapiAdminSubmission)
            {
                headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-Mapi-Admin-Submission", string.Empty));
            }
            if (this.IsDlExpansionProhibited)
            {
                headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-DL-Expansion-Prohibited", string.Empty));
            }
            headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-Processed-By-MBTSubmission", string.Empty));
            if (ConfigurationProvider.GetForwardingProhibitedFeatureStatus() && this.IsAltRecipientProhibited)
            {
                headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-Alt-Recipient-Prohibited", string.Empty));
            }
            headers.RemoveAll("X-MS-Exchange-Organization-OriginalSize");
            headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-OriginalSize", mimeSize.ToString(NumberFormatInfo.InvariantInfo)));
            headers.RemoveAll("X-MS-Exchange-Organization-OriginalArrivalTime");
            Header newChild3 = new AsciiTextHeader("X-MS-Exchange-Organization-OriginalArrivalTime", Util.FormatOrganizationalMessageArrivalTime(this.OriginalCreateTime));

            headers.AppendChild(newChild3);
            headers.RemoveAll("X-MS-Exchange-Organization-MessageSource");
            Header newChild4 = new AsciiTextHeader("X-MS-Exchange-Organization-MessageSource", "StoreDriver");

            headers.AppendChild(newChild4);
            headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Transport-FromEntityHeader", RoutingEndpoint.Hosted.ToString()));
            headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-FromEntityHeader", RoutingEndpoint.Hosted.ToString()));
            message.Directionality = MailDirectionality.Originating;
            message.UpdateDirectionalityAndScopeHeaders();
        }
Beispiel #2
0
        private void AddUnparkedHeader(HeaderList headers, Guid messageId)
        {
            headers.RemoveAll("X-MS-Exchange-Calendar-Series-Instance-Unparked");
            Header header = Header.Create("X-MS-Exchange-Calendar-Series-Instance-Unparked");

            header.Value = messageId.ToString();
            headers.AppendChild(header);
        }
Beispiel #3
0
 internal static void SetProperty(HeaderList mimeHeaders, string name, string value)
 {
     mimeHeaders.RemoveAll(name);
     if (!string.IsNullOrEmpty(value))
     {
         mimeHeaders.AppendChild(new TextHeader(name, value));
     }
 }
Beispiel #4
0
        public void TestReplacingHeaders()
        {
            const string ReplacedContentType        = "text/plain; charset=iso-8859-1; name=body.txt";
            const string ReplacedContentDisposition = "inline; filename=body.txt";
            const string ReplacedContentLocation    = "http://www.example.com/location";
            const string ReplacedContentId          = "<content.id.2@localhost>";
            var          headers = new HeaderList();

            headers.Add(HeaderId.ContentId, "<content-id.1@localhost>");
            headers.Add("Content-Location", "http://www.location.com");
            headers.Insert(0, HeaderId.ContentDisposition, "attachment");
            headers.Insert(0, "Content-Type", "text/plain");

            Assert.IsTrue(headers.Contains(HeaderId.ContentType), "Expected the list of headers to contain HeaderId.ContentType.");
            Assert.IsTrue(headers.Contains("Content-Type"), "Expected the list of headers to contain a Content-Type header.");
            Assert.AreEqual(0, headers.LastIndexOf(HeaderId.ContentType), "Expected the Content-Type header to be the first header.");

            headers.Replace("Content-Disposition", ReplacedContentDisposition);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Disposition.");
            Assert.AreEqual(ReplacedContentDisposition, headers["Content-Disposition"], "Content-Disposition has unexpected value after replacing it.");
            Assert.AreEqual(1, headers.IndexOf("Content-Disposition"), "Replaced Content-Disposition not in the expected position.");

            headers.Replace(HeaderId.ContentType, ReplacedContentType);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Type.");
            Assert.AreEqual(ReplacedContentType, headers["Content-Type"], "Content-Type has unexpected value after replacing it.");
            Assert.AreEqual(0, headers.IndexOf("Content-Type"), "Replaced Content-Type not in the expected position.");

            headers.Replace(HeaderId.ContentId, Encoding.UTF8, ReplacedContentId);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Id.");
            Assert.AreEqual(ReplacedContentId, headers["Content-Id"], "Content-Id has unexpected value after replacing it.");
            Assert.AreEqual(2, headers.IndexOf("Content-Id"), "Replaced Content-Id not in the expected position.");

            headers.Replace("Content-Location", Encoding.UTF8, ReplacedContentLocation);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Location.");
            Assert.AreEqual(ReplacedContentLocation, headers["Content-Location"], "Content-Location has unexpected value after replacing it.");
            Assert.AreEqual(3, headers.IndexOf("Content-Location"), "Replaced Content-Location not in the expected position.");

            headers.RemoveAll("Content-Location");
            Assert.AreEqual(3, headers.Count, "Unexpected number of headers after removing Content-Location.");

            headers.Clear();

            headers.Add(HeaderId.Received, "received 1");
            headers.Add(HeaderId.Received, "received 2");
            headers.Add(HeaderId.Received, "received 3");
            headers.Add(HeaderId.ReturnPath, "return-path");

            headers[0] = new Header(HeaderId.ReturnPath, "new return-path");
            Assert.AreEqual("new return-path", headers[HeaderId.ReturnPath]);
            headers[0] = new Header(HeaderId.Received, "new received");
            Assert.AreEqual("new received", headers[HeaderId.Received]);
        }
Beispiel #5
0
		public void TestReplacingHeaders ()
		{
			const string ReplacedContentType = "text/plain; charset=iso-8859-1; name=body.txt";
			const string ReplacedContentDisposition = "inline; filename=body.txt";
			const string ReplacedContentLocation = "http://www.example.com/location";
			const string ReplacedContentId = "<content.id.2@localhost>";
			var headers = new HeaderList ();

			headers.Add (HeaderId.ContentId, "<content-id.1@localhost>");
			headers.Add ("Content-Location", "http://www.location.com");
			headers.Insert (0, HeaderId.ContentDisposition, "attachment");
			headers.Insert (0, "Content-Type", "text/plain");

			Assert.IsTrue (headers.Contains (HeaderId.ContentType), "Expected the list of headers to contain HeaderId.ContentType.");
			Assert.IsTrue (headers.Contains ("Content-Type"), "Expected the list of headers to contain a Content-Type header.");
			Assert.AreEqual (0, headers.LastIndexOf (HeaderId.ContentType), "Expected the Content-Type header to be the first header.");

			headers.Replace ("Content-Disposition", ReplacedContentDisposition);
			Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Disposition.");
			Assert.AreEqual (ReplacedContentDisposition, headers["Content-Disposition"], "Content-Disposition has unexpected value after replacing it.");
			Assert.AreEqual (1, headers.IndexOf ("Content-Disposition"), "Replaced Content-Disposition not in the expected position.");

			headers.Replace (HeaderId.ContentType, ReplacedContentType);
			Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Type.");
			Assert.AreEqual (ReplacedContentType, headers["Content-Type"], "Content-Type has unexpected value after replacing it.");
			Assert.AreEqual (0, headers.IndexOf ("Content-Type"), "Replaced Content-Type not in the expected position.");

			headers.Replace (HeaderId.ContentId, Encoding.UTF8, ReplacedContentId);
			Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Id.");
			Assert.AreEqual (ReplacedContentId, headers["Content-Id"], "Content-Id has unexpected value after replacing it.");
			Assert.AreEqual (2, headers.IndexOf ("Content-Id"), "Replaced Content-Id not in the expected position.");

			headers.Replace ("Content-Location", Encoding.UTF8, ReplacedContentLocation);
			Assert.AreEqual (4, headers.Count, "Unexpected number of headers after replacing Content-Location.");
			Assert.AreEqual (ReplacedContentLocation, headers["Content-Location"], "Content-Location has unexpected value after replacing it.");
			Assert.AreEqual (3, headers.IndexOf ("Content-Location"), "Replaced Content-Location not in the expected position.");

			headers.RemoveAll ("Content-Location");
			Assert.AreEqual (3, headers.Count, "Unexpected number of headers after removing Content-Location.");
		}
Beispiel #6
0
        public void TestArgumentExceptions()
        {
            var    list = new HeaderList();
            Header header;
            string value;

            using (var stream = new MemoryStream()) {
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load(null, "filename.txt"));
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load(ParserOptions.Default, (string)null));

                Assert.Throws <ArgumentNullException> (() => HeaderList.Load(null, stream));
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load(ParserOptions.Default, (Stream)null));

                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync(null, "filename.txt"));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync(ParserOptions.Default, (string)null));

                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync(null, stream));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync(ParserOptions.Default, (Stream)null));
            }

            // Add
            Assert.Throws <ArgumentNullException> (() => list.Add(null));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Add(HeaderId.Unknown, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Add(HeaderId.AdHoc, null));
            Assert.Throws <ArgumentNullException> (() => list.Add(null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Add("field", null));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Add(HeaderId.Unknown, Encoding.UTF8, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Add(HeaderId.AdHoc, null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Add(HeaderId.AdHoc, Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => list.Add(null, Encoding.UTF8, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Add("field", null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Add("field", Encoding.UTF8, null));

            // Contains
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Contains(HeaderId.Unknown));
            Assert.Throws <ArgumentNullException> (() => list.Contains((Header)null));
            Assert.Throws <ArgumentNullException> (() => list.Contains((string)null));

            // CopyTo
            Assert.Throws <ArgumentOutOfRangeException> (() => list.CopyTo(new Header[0], -1));
            Assert.Throws <ArgumentNullException> (() => list.CopyTo(null, 0));

            // IndexOf
            Assert.Throws <ArgumentOutOfRangeException> (() => list.IndexOf(HeaderId.Unknown));
            Assert.Throws <ArgumentNullException> (() => list.IndexOf((Header)null));
            Assert.Throws <ArgumentNullException> (() => list.IndexOf((string)null));

            // Insert
            list.Add("field", "value");
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Insert(-1, new Header(HeaderId.AdHoc, "value")));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Insert(-1, HeaderId.AdHoc, Encoding.UTF8, "value"));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Insert(-1, "field", Encoding.UTF8, "value"));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Insert(-1, HeaderId.AdHoc, "value"));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Insert(-1, "field", "value"));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Insert(0, HeaderId.Unknown, Encoding.UTF8, "value"));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Insert(0, HeaderId.Unknown, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Insert(0, HeaderId.AdHoc, Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => list.Insert(0, HeaderId.AdHoc, null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Insert(0, HeaderId.AdHoc, null));
            Assert.Throws <ArgumentNullException> (() => list.Insert(0, null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Insert(0, "field", null));
            Assert.Throws <ArgumentNullException> (() => list.Insert(0, null));

            // LastIndexOf
            Assert.Throws <ArgumentOutOfRangeException> (() => list.LastIndexOf(HeaderId.Unknown));
            Assert.Throws <ArgumentNullException> (() => list.LastIndexOf((string)null));

            // Remove
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Remove(HeaderId.Unknown));
            Assert.Throws <ArgumentNullException> (() => list.Remove((Header)null));
            Assert.Throws <ArgumentNullException> (() => list.Remove((string)null));

            // RemoveAll
            Assert.Throws <ArgumentOutOfRangeException> (() => list.RemoveAll(HeaderId.Unknown));
            Assert.Throws <ArgumentNullException> (() => list.RemoveAll((string)null));

            // RemoveAt
            Assert.Throws <ArgumentOutOfRangeException> (() => list.RemoveAt(-1));

            // Replace
            Assert.Throws <ArgumentNullException> (() => list.Replace(null));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Replace(HeaderId.Unknown, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Replace(HeaderId.AdHoc, null));
            Assert.Throws <ArgumentNullException> (() => list.Replace(null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Replace("field", null));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.Replace(HeaderId.Unknown, Encoding.UTF8, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Replace(HeaderId.AdHoc, null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Replace(HeaderId.AdHoc, Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => list.Replace(null, Encoding.UTF8, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Replace("field", null, "value"));
            Assert.Throws <ArgumentNullException> (() => list.Replace("field", Encoding.UTF8, null));

            using (var stream = new MemoryStream()) {
                // Load
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load(ParserOptions.Default, (Stream)null));
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load(ParserOptions.Default, (string)null));
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load(null, stream));
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load((Stream)null));
                Assert.Throws <ArgumentNullException> (() => HeaderList.Load((string)null));

                // LoadAsync
                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync(ParserOptions.Default, (Stream)null));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync(ParserOptions.Default, (string)null));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync(null, stream));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync((Stream)null));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await HeaderList.LoadAsync((string)null));

                // WriteTo
                Assert.Throws <ArgumentNullException> (() => list.WriteTo(FormatOptions.Default, null));
                Assert.Throws <ArgumentNullException> (() => list.WriteTo(null, stream));
                Assert.Throws <ArgumentNullException> (() => list.WriteTo(null));

                // WriteToAsync
                Assert.ThrowsAsync <ArgumentNullException> (async() => await list.WriteToAsync(FormatOptions.Default, null));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await list.WriteToAsync(null, stream));
                Assert.ThrowsAsync <ArgumentNullException> (async() => await list.WriteToAsync(null));
            }

            // Indexers
            Assert.Throws <ArgumentOutOfRangeException> (() => list[-1] = new Header(HeaderId.AdHoc, "value"));
            Assert.Throws <ArgumentOutOfRangeException> (() => list[HeaderId.Unknown] = "value");
            Assert.Throws <ArgumentOutOfRangeException> (() => value          = list[HeaderId.Unknown]);
            Assert.Throws <ArgumentOutOfRangeException> (() => header         = list[-1]);
            Assert.Throws <ArgumentNullException> (() => list[HeaderId.AdHoc] = null);
            Assert.Throws <ArgumentNullException> (() => value         = list[null]);
            Assert.Throws <ArgumentNullException> (() => list[null]    = "value");
            Assert.Throws <ArgumentNullException> (() => list["field"] = null);
            Assert.Throws <ArgumentNullException> (() => list[0]       = null);
        }
Beispiel #7
0
		public void TestArgumentExceptions ()
		{
			var list = new HeaderList ();
			Header header;
			string value;

			// Add
			Assert.Throws<ArgumentNullException> (() => list.Add (null));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Add (HeaderId.Unknown, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add (HeaderId.AdHoc, null));
			Assert.Throws<ArgumentNullException> (() => list.Add (null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add ("field", null));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Add (HeaderId.Unknown, Encoding.UTF8, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add (HeaderId.AdHoc, null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add (HeaderId.AdHoc, Encoding.UTF8, null));
			Assert.Throws<ArgumentNullException> (() => list.Add (null, Encoding.UTF8, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add ("field", null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add ("field", Encoding.UTF8, null));

			// Contains
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Contains (HeaderId.Unknown));
			Assert.Throws<ArgumentNullException> (() => list.Contains ((Header) null));
			Assert.Throws<ArgumentNullException> (() => list.Contains ((string) null));

			// CopyTo
			Assert.Throws<ArgumentOutOfRangeException> (() => list.CopyTo (new Header[0], -1));
			Assert.Throws<ArgumentNullException> (() => list.CopyTo (null, 0));

			// IndexOf
			Assert.Throws<ArgumentOutOfRangeException> (() => list.IndexOf (HeaderId.Unknown));
			Assert.Throws<ArgumentNullException> (() => list.IndexOf ((Header) null));
			Assert.Throws<ArgumentNullException> (() => list.IndexOf ((string) null));

			// Insert
			list.Add ("field", "value");
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, new Header (HeaderId.AdHoc, "value")));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, HeaderId.AdHoc, Encoding.UTF8, "value"));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, "field", Encoding.UTF8, "value"));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, HeaderId.AdHoc, "value"));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, "field", "value"));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (0, HeaderId.Unknown, Encoding.UTF8, "value"));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (0, HeaderId.Unknown, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, HeaderId.AdHoc, Encoding.UTF8, null));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, HeaderId.AdHoc, null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, HeaderId.AdHoc, null));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, "field", null));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, null));

			// LastIndexOf
			Assert.Throws<ArgumentOutOfRangeException> (() => list.LastIndexOf (HeaderId.Unknown));
			Assert.Throws<ArgumentNullException> (() => list.LastIndexOf ((string) null));

			// Remove
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Remove (HeaderId.Unknown));
			Assert.Throws<ArgumentNullException> (() => list.Remove ((Header) null));
			Assert.Throws<ArgumentNullException> (() => list.Remove ((string) null));

			// RemoveAll
			Assert.Throws<ArgumentOutOfRangeException> (() => list.RemoveAll (HeaderId.Unknown));
			Assert.Throws<ArgumentNullException> (() => list.RemoveAll ((string) null));

			// RemoveAt
			Assert.Throws<ArgumentOutOfRangeException> (() => list.RemoveAt (-1));

			// Replace
			Assert.Throws<ArgumentNullException> (() => list.Replace (null));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Replace (HeaderId.Unknown, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Replace (HeaderId.AdHoc, null));
			Assert.Throws<ArgumentNullException> (() => list.Replace (null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Replace ("field", null));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Replace (HeaderId.Unknown, Encoding.UTF8, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Replace (HeaderId.AdHoc, null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Replace (HeaderId.AdHoc, Encoding.UTF8, null));
			Assert.Throws<ArgumentNullException> (() => list.Replace (null, Encoding.UTF8, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Replace ("field", null, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Replace ("field", Encoding.UTF8, null));

			using (var stream = new MemoryStream ()) {
				// Load
				Assert.Throws<ArgumentNullException> (() => HeaderList.Load (ParserOptions.Default, (Stream) null));
				Assert.Throws<ArgumentNullException> (() => HeaderList.Load (ParserOptions.Default, (string) null));
				Assert.Throws<ArgumentNullException> (() => HeaderList.Load (null, stream));
				Assert.Throws<ArgumentNullException> (() => HeaderList.Load ((Stream) null));
				Assert.Throws<ArgumentNullException> (() => HeaderList.Load ((string) null));

				// WriteTo
				Assert.Throws<ArgumentNullException> (() => list.WriteTo (FormatOptions.Default, null));
				Assert.Throws<ArgumentNullException> (() => list.WriteTo (null, stream));
				Assert.Throws<ArgumentNullException> (() => list.WriteTo (null));
			}

			// Indexers
			Assert.Throws<ArgumentOutOfRangeException> (() => list[-1] = new Header (HeaderId.AdHoc, "value"));
			Assert.Throws<ArgumentOutOfRangeException> (() => list[HeaderId.Unknown] = "value");
			Assert.Throws<ArgumentOutOfRangeException> (() => value = list[HeaderId.Unknown]);
			Assert.Throws<ArgumentOutOfRangeException> (() => header = list[-1]);
			Assert.Throws<ArgumentNullException> (() => list[HeaderId.AdHoc] = null);
			Assert.Throws<ArgumentNullException> (() => value = list[null]);
			Assert.Throws<ArgumentNullException> (() => list[null] = "value");
			Assert.Throws<ArgumentNullException> (() => list["field"] = null);
			Assert.Throws<ArgumentNullException> (() => list[0] = null);
		}