Esempio n. 1
0
		public void TestFrom()
		{
			const string input = "from foobar; Fri, 21 Nov 1997 09:55:06 -0600";
			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("foobar", received.Names["from"]);
		}
Esempio n. 2
0
		public void TestFrom2()
		{
			const string input = "from testing.mail.com; Fri, 21 Nov 1997 09:55:06 -0600";
			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("testing.mail.com", received.Names["from"]);
		}
Esempio n. 3
0
		public void TestBy()
		{
			const string input = "by fep32.mail.com; Fri, 21 Nov 1997 09:55:06 -0600";
			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("fep32.mail.com", received.Names["by"]);
		}
Esempio n. 4
0
		public void TestBy2()
		{
			const string input = "by some.example.openpop.net; Fri, 21 Nov 1997 09:55:06 -0600";
			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("some.example.openpop.net", received.Names["by"]);
		}
Esempio n. 5
0
		public void TestDate()
		{
			const string input = "; Fri, 21 Nov 1997 09:55:06 -0600";
			Received received = new Received(input);

			// -0600 we need to add 6 hours when in UTC
			DateTime expectedOutput = new DateTime(1997, 11, 21, 15, 55, 06, DateTimeKind.Utc);
			DateTime output = received.Date;

			Assert.AreEqual(expectedOutput, output);

			Assert.AreEqual(input, received.Raw);
		}
Esempio n. 6
0
		public void TestDate2()
		{
			const string input = "; Tue, 1 Jul 2003 10:52:37 +0200";
			Received received = new Received(input);

			// +0200 we need to substract 2 hours when in UTC
			DateTime expectedOutput = new DateTime(2003, 7, 1, 8, 52, 37, DateTimeKind.Utc);
			DateTime output = received.Date;

			Assert.AreEqual(expectedOutput, output);

			Assert.AreEqual(input, received.Raw);
		}
Esempio n. 7
0
		public void TestDoubleBy()
		{
			const string input =
				"from x.x.x.x ([x.x.x.x]) " +
				"by abc.def.com " +
				"with emfmta (version 4.8.3.54) " +
				"by TLS " +
				"id 123456789 " +
				"for [email protected];123456789abcdef1; " +
				"Mon, 12 Sep 2011 15:39:23 +0100";

			Received received = null;
			Assert.DoesNotThrow(delegate { received = new Received(input); });

			Assert.NotNull(received);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("x.x.x.x ([x.x.x.x])", received.Names["from"]);
			Assert.AreEqual("abc.def.com", received.Names["by"]);
			Assert.AreEqual("emfmta (version 4.8.3.54)", received.Names["with"]);
			Assert.AreEqual("123456789", received.Names["id"]);
			Assert.AreEqual("[email protected];123456789abcdef1", received.Names["for"]);
			Assert.AreEqual(5, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 9, 12, 14, 39, 23, DateTimeKind.Utc), received.Date);
		}
Esempio n. 8
0
		public void TestDoubleWith()
		{
			const string input =
				"from ([153.2.81.78])\t" +
				"by magma11.ups.com " +
				"with ESMTP " +
				"with TLS " +
				"id 6N259K1.118711799;\t" +
				"Sat, 13 Aug 2011 03:49:33 -0400";

			Received received = null;
			Assert.DoesNotThrow(delegate { received = new Received(input); });

			Assert.NotNull(received);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("([153.2.81.78])", received.Names["from"]);
			Assert.AreEqual("magma11.ups.com", received.Names["by"]);
			Assert.AreEqual("ESMTP", received.Names["with"]);
			Assert.AreEqual("6N259K1.118711799", received.Names["id"]);
			Assert.AreEqual(4, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 8, 13, 7, 49, 33, DateTimeKind.Utc), received.Date);
		}
Esempio n. 9
0
		public void TestNoDate()
		{
			const string input =
				"from 178.88.30.104 " +
				"by rms-us011.v300.gmx.net " +
				"with HTTP";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("178.88.30.104", received.Names["from"]);
			Assert.AreEqual("rms-us011.v300.gmx.net", received.Names["by"]);
			Assert.AreEqual("HTTP", received.Names["with"]);
			Assert.AreEqual(3, received.Names.Keys.Count);
			Assert.AreEqual(DateTime.MinValue, received.Date);
		}
Esempio n. 10
0
		public void TestFromWithExtraInfoWithSemicolonAndExtraDate()
		{
			// This string is properly illegal
			const string input = "from foo (;Tue, 1 Jul 2003 10:52:37 +0200); Fri, 21 Nov 1997 09:55:06 +0000";
			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("foo (;Tue, 1 Jul 2003 10:52:37 +0200)", received.Names["from"]);
			Assert.AreEqual(new DateTime(1997, 11, 21, 9, 55, 06, DateTimeKind.Utc), received.Date);
		}
Esempio n. 11
0
		public void TestFullReceivedLineExessiveWhitespace()
		{
			const string input =
				"from fep26 ([80.160.76.230]) by fep34.mail.dk          (InterMail vM.8.01.04.07 201-2260-137-119-20110503) with ESMTP          id <20110706105008.PZHJ18594.fep34.mail.dk@fep26>          for <*****@*****.**>; Wed, 6 Jul 2011 12:50:08 +0200";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("fep26 ([80.160.76.230])", received.Names["from"]);
			Assert.AreEqual("fep34.mail.dk (InterMail vM.8.01.04.07 201-2260-137-119-20110503)", received.Names["by"]);
			Assert.AreEqual("ESMTP", received.Names["with"]);
			Assert.AreEqual("<20110706105008.PZHJ18594.fep34.mail.dk@fep26>", received.Names["id"]);
			Assert.AreEqual("<*****@*****.**>", received.Names["for"]);
			Assert.AreEqual(5, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 7, 6, 10, 50, 08, DateTimeKind.Utc), received.Date);
		}
Esempio n. 12
0
		public void TestFullReceivedLine4()
		{
			const string input =
				"from fep29 ([80.160.76.233]) " +
				"by fep34.mail.dk (InterMail vM.8.01.04.07 201-2260-137-119-20110503) " +
				"with ESMTP " +
				"id <20110530134858.YAHN18594.fep34.mail.dk@fep29> " +
				"for <*****@*****.**>; " + 
				"Mon, 30 May 2011 15:48:58 +0200";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("fep29 ([80.160.76.233])", received.Names["from"]);
			Assert.AreEqual("fep34.mail.dk (InterMail vM.8.01.04.07 201-2260-137-119-20110503)", received.Names["by"]);
			Assert.AreEqual("ESMTP", received.Names["with"]);
			Assert.AreEqual("<20110530134858.YAHN18594.fep34.mail.dk@fep29>", received.Names["id"]);
			Assert.AreEqual("<*****@*****.**>", received.Names["for"]);
			Assert.AreEqual(5, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 5, 30, 13, 48, 58, DateTimeKind.Utc), received.Date);
		}
Esempio n. 13
0
		public void TestFullReceivedLine3()
		{
			const string input =
				"from ymir.adm.au.dk ([10.60.1.18]) " +
				"by ns2.au.dk (8.13.7+Sun/8.12.5) " +
				"with ESMTP " +
				"id p659boKa018808; " +
				"Tue, 5 Jul 2011 11:38:04 +0200 (MEST)";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("ymir.adm.au.dk ([10.60.1.18])", received.Names["from"]);
			Assert.AreEqual("ns2.au.dk (8.13.7+Sun/8.12.5)", received.Names["by"]);
			Assert.AreEqual("ESMTP", received.Names["with"]);
			Assert.AreEqual("p659boKa018808", received.Names["id"]);
			Assert.AreEqual(4, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 7, 5, 9, 38, 04, DateTimeKind.Utc), received.Date);
		}
Esempio n. 14
0
		public void TestFullReceivedLine2()
		{
			const string input =
				"from smtp.nfit.au.dk ([10.19.9.11]) " +
				"by mbe1i (Cyrus v2.3.16-Invoca-RPM-2.3.16-3) " +
				"with LMTPA;" +
				"Tue, 05 Jul 2011 11:58:11 +0200";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("smtp.nfit.au.dk ([10.19.9.11])", received.Names["from"]);
			Assert.AreEqual("mbe1i (Cyrus v2.3.16-Invoca-RPM-2.3.16-3)", received.Names["by"]);
			Assert.AreEqual("LMTPA", received.Names["with"]);
			Assert.AreEqual(3, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 7, 5, 9, 58, 11, DateTimeKind.Utc), received.Date);
		}
Esempio n. 15
0
		public void TestFullReceivedLine()
		{
			const string input =
				"from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) " +
				"by sfs-ml-3.v29.ch3.sourceforge.com " +
				"with esmtp (Exim 4.76) (envelope-from <*****@*****.**>) " +
				"id 1Qcvg8-0004Kr-17 " +
				"for [email protected]" +
				"; Sat, 02 Jul 2011 08:35:52 +0000";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net)", received.Names["from"]);
			Assert.AreEqual("sfs-ml-3.v29.ch3.sourceforge.com", received.Names["by"]);
			Assert.AreEqual("esmtp (Exim 4.76) (envelope-from <*****@*****.**>)", received.Names["with"]);
			Assert.AreEqual("1Qcvg8-0004Kr-17", received.Names["id"]);
			Assert.AreEqual("*****@*****.**", received.Names["for"]);
			Assert.AreEqual(5, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 7, 2, 8, 35, 52, DateTimeKind.Utc), received.Date);
		}
Esempio n. 16
0
		public void TestFullReceivedLineWithManyComments()
		{
			const string input =
				"from [189.7.13.40] (helo=AlexandrePC) " +
				"by insvr1018.insite.com.br " +
				"with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from <*****@*****.**>) " +
				"id 1QIUsX-0007Ki-6q " +
				"for [email protected]; " +
				"Mon, 30 May 2011 15:48:58 +0200";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("[189.7.13.40] (helo=AlexandrePC)", received.Names["from"]);
			Assert.AreEqual("insvr1018.insite.com.br", received.Names["by"]);
			Assert.AreEqual("esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from <*****@*****.**>)", received.Names["with"]);
			Assert.AreEqual("1QIUsX-0007Ki-6q", received.Names["id"]);
			Assert.AreEqual("*****@*****.**", received.Names["for"]);
			Assert.AreEqual(5, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2011, 5, 30, 13, 48, 58, DateTimeKind.Utc), received.Date);
		}
Esempio n. 17
0
		public void TestFullReceivedLineWithStartingComment()
		{
			const string input =
				"(from apache@localhost) " + 
				"by ip6.nabto.com (8.13.8/8.13.8/Submit) " + 
				"id o937M53u009287; " +
				"Sun, 3 Oct 2010 09:22:05 +0200";

			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.IsFalse(received.Names.ContainsKey("from"));
			Assert.AreEqual("ip6.nabto.com (8.13.8/8.13.8/Submit)", received.Names["by"]);
			Assert.AreEqual("o937M53u009287", received.Names["id"]);
			Assert.AreEqual(2, received.Names.Keys.Count);
			Assert.AreEqual(new DateTime(2010, 10, 3, 7, 22, 05, DateTimeKind.Utc), received.Date);
		}
Esempio n. 18
0
        /// <summary>
        /// Parses a single header and sets member variables according to it.
        /// </summary>
        /// <param name="headerName">The name of the header</param>
        /// <param name="headerValue">The value of the header in unfolded state (only one line)</param>
        /// <exception cref="ArgumentNullException">If <paramref name="headerName"/> or <paramref name="headerValue"/> is <see langword="null"/></exception>
        private void ParseHeader(string headerName, string headerValue)
        {
            if (headerName == null)
            {
                throw new ArgumentNullException("headerName");
            }

            if (headerValue == null)
            {
                throw new ArgumentNullException("headerValue");
            }

            switch (headerName.ToUpperInvariant())
            {
            // See http://tools.ietf.org/html/rfc5322#section-3.6.3
            case "TO":
                To.AddRange(RfcMailAddress.ParseMailAddresses(headerValue));
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.3
            case "CC":
                Cc.AddRange(RfcMailAddress.ParseMailAddresses(headerValue));
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.3
            case "BCC":
                Bcc.AddRange(RfcMailAddress.ParseMailAddresses(headerValue));
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.2
            case "FROM":
                // There is only one MailAddress in the from field
                From = RfcMailAddress.ParseMailAddress(headerValue);
                break;

            // http://tools.ietf.org/html/rfc5322#section-3.6.2
            // The implementation here might be wrong
            case "REPLY-TO":
                // This field may actually be a list of addresses, but no
                // such case has been encountered
                ReplyTo = RfcMailAddress.ParseMailAddress(headerValue);
                break;

            // http://tools.ietf.org/html/rfc5322#section-3.6.2
            case "SENDER":
                Sender = RfcMailAddress.ParseMailAddress(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.5
            // RFC 5322:
            // The "Keywords:" field contains a comma-separated list of one or more
            // words or quoted-strings.
            // The field are intended to have only human-readable content
            // with information about the message
            case "KEYWORDS":
                string[] keywordsTemp = headerValue.Split(',');
                foreach (string keyword in keywordsTemp)
                {
                    // Remove the quotes if there is any
                    Keywords.Add(Utility.RemoveQuotesIfAny(keyword.Trim()));
                }
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.7
            case "RECEIVED":
                // Simply add the value to the list
                Received.Add(new Received(headerValue.Trim()));
                break;

            case "IMPORTANCE":
                Importance = HeaderFieldParser.ParseImportance(headerValue.Trim());
                break;

            // See http://tools.ietf.org/html/rfc3798#section-2.1
            case "DISPOSITION-NOTIFICATION-TO":
                DispositionNotificationTo = RfcMailAddress.ParseMailAddresses(headerValue);
                break;

            case "MIME-VERSION":
                MimeVersion = headerValue.Trim();
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.5
            case "SUBJECT":
                Subject = EncodedWord.Decode(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.7
            case "RETURN-PATH":
                // Return-paths does not include a username, but we
                // may still use the address parser
                ReturnPath = RfcMailAddress.ParseMailAddress(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.4
            // Example Message-ID
            // <*****@*****.**>
            case "MESSAGE-ID":
                MessageId = HeaderFieldParser.ParseId(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.4
            case "IN-REPLY-TO":
                InReplyTo = HeaderFieldParser.ParseMultipleIDs(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.4
            case "REFERENCES":
                References = HeaderFieldParser.ParseMultipleIDs(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc5322#section-3.6.1))
            case "DATE":
                Date     = headerValue.Trim();
                DateSent = Rfc2822DateTime.StringToDate(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc2045#section-6
            // See ContentTransferEncoding class for more details
            case "CONTENT-TRANSFER-ENCODING":
                ContentTransferEncoding = HeaderFieldParser.ParseContentTransferEncoding(headerValue.Trim());
                break;

            // See http://tools.ietf.org/html/rfc2045#section-8
            case "CONTENT-DESCRIPTION":
                // Human description of for example a file. Can be encoded
                ContentDescription = EncodedWord.Decode(headerValue.Trim());
                break;

            // See http://tools.ietf.org/html/rfc2045#section-5.1
            // Example: Content-type: text/plain; charset="us-ascii"
            case "CONTENT-TYPE":
                ContentType = HeaderFieldParser.ParseContentType(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc2183
            case "CONTENT-DISPOSITION":
                ContentDisposition = HeaderFieldParser.ParseContentDisposition(headerValue);
                break;

            // See http://tools.ietf.org/html/rfc2045#section-7
            // Example: <foo4*[email protected]>
            case "CONTENT-ID":
                ContentId = HeaderFieldParser.ParseId(headerValue);
                break;

            default:
                // This is an unknown header

                // Custom headers are allowed. That means headers
                // that are not mentionen in the RFC.
                // Such headers start with the letter "X"
                // We do not have any special parsing of such

                // Add it to unknown headers
                UnknownHeaders.Add(headerName, headerValue);
                break;
            }
        }
Esempio n. 19
0
		public void TestFromWithExtraInfo()
		{
			const string input = "from testing.mail.com ([216.34.181.88:10057] helo=lists.sourceforge.net); Fri, 21 Nov 1997 09:55:06 -0600";
			Received received = new Received(input);

			Assert.AreEqual(input, received.Raw);
			Assert.AreEqual("testing.mail.com ([216.34.181.88:10057] helo=lists.sourceforge.net)", received.Names["from"]);
		}