A message delivery status MIME part.
A message delivery status MIME part is a machine readable notification denoting the delivery status of a message and has a MIME-type of message/delivery-status.
상속: MimePart
		public void TestSerializedContent ()
		{
			const string expected = "Reporting-MTA: dns; mm1\nArrival-Date: Mon, 29 Jul 1996 02:12:50 -0700\n\nFinal-Recipient: RFC822; [email protected]\nAction: failed\nDiagnostic-Code: X-LOCAL; 500 (err.nosuchuser)\n\n";
			var mds = new MessageDeliveryStatus ();
			var recipient = new HeaderList ();
			var status = new HeaderList ();

			status.Add ("Reporting-MTA", "dns; mm1");
			status.Add ("Arrival-Date", DateUtils.FormatDate (new DateTimeOffset (1996, 7, 29, 2, 12, 50, new TimeSpan (-7, 0, 0))));

			recipient.Add ("Final-Recipient", "RFC822; [email protected]");
			recipient.Add ("Action", "failed");
			recipient.Add ("Diagnostic-Code", "X-LOCAL; 500 (err.nosuchuser)");

			mds.StatusGroups.Add (status);
			mds.StatusGroups.Add (recipient);

			Assert.IsTrue (mds.StatusGroups.Contains (status), "Expected the groups to contain the per-message status group.");
			Assert.IsTrue (mds.StatusGroups.Contains (recipient), "Expected the groups to contain the recipient status group.");
			Assert.IsFalse (mds.StatusGroups.IsReadOnly, "The status groups should not be read-only.");

			using (var memory = new MemoryStream ()) {
				mds.ContentObject.DecodeTo (memory);

				var text = Encoding.ASCII.GetString (memory.GetBuffer (), 0, (int) memory.Length).Replace ("\r\n", "\n");
				Assert.AreEqual (expected, text);
			}

			var dummy = new HeaderList ();
			dummy.Add ("Dummy-Header", "dummy value");

			mds.StatusGroups.Add (dummy);

			Assert.IsTrue (mds.StatusGroups.Contains (dummy), "Expected the groups to contain the dummy group.");
			Assert.IsTrue (mds.StatusGroups.Remove (dummy), "Expected removal of the dummy group to be successful.");

			var expectedContent = mds.ContentObject;

			dummy.Add ("Bogus-Header", "bogus value");

			Assert.AreEqual (expectedContent, mds.ContentObject, "The content should not have changed since the dummy group has been removed.");

			mds.StatusGroups.Clear ();

			using (var memory = new MemoryStream ()) {
				mds.ContentObject.DecodeTo (memory);

				var text = Encoding.ASCII.GetString (memory.GetBuffer (), 0, (int) memory.Length).Replace ("\r\n", "\n");

				Assert.AreEqual (string.Empty, text);
			}
		}
예제 #2
0
 /// <summary>
 /// Visit the message/delivery-status MIME entity.
 /// </summary>
 /// <remarks>
 /// Visits the message/delivery-status MIME entity.
 /// </remarks>
 /// <param name="entity">The message/delivery-status MIME entity.</param>
 protected internal virtual void VisitMessageDeliveryStatus(MessageDeliveryStatus entity)
 {
     VisitMimePart(entity);
 }
예제 #3
0
		/// <summary>
		/// Visit the message/delivery-status MIME entity.
		/// </summary>
		/// <remarks>
		/// Visits the message/delivery-status MIME entity.
		/// </remarks>
		/// <param name="entity">The message/delivery-status MIME entity.</param>
		protected internal virtual void VisitMessageDeliveryStatus (MessageDeliveryStatus entity)
		{
			VisitMimePart (entity);
		}
예제 #4
0
        private static BounceDetectResult DetectQmailBounce(MimeMessage message, TextPart textPart)
        {
            if (textPart.ContentType.MimeType != "text/plain")
                return null;

            var text = textPart.Text;

            if (!text.StartsWith("Hi. This is the "))
                return null;

            var match = QmailBounceRegex.Match(text);

            if (!match.Success)
                return null;

            var parts = BreakParagraphRegex.Split(text, 2).ToArray();

            if (parts.Length != 2)
                return null;

            var paragraphs = ParagraphRegex.Split(parts[0]);
            var recipientParagraphs = paragraphs.Skip(1).ToArray();
            var undeliveredMessage = ReadMessage(parts[1]);

            var messageDeliveryStatus = new MessageDeliveryStatus();

            // add per-message status fields.
            messageDeliveryStatus.StatusGroups.Add(
                new HeaderList
                {
                    { "Reporting-MTA", "dns;" + match.Groups[1].Value }
                });

            // add per-recipient status fields.
            var failureParagraphs = recipientParagraphs
                .Select(ParseFailureParagraph)
                .Where(p => p != null)
                .ToArray();

            foreach (var failureParagraph in failureParagraphs)
            {
                messageDeliveryStatus.StatusGroups.Add(
                    new HeaderList
                    {
                        { "Action", "failed" },
                        { "Status", failureParagraph.Status },
                        { "Final-Recipient",  "rfc822;" + failureParagraph.RecipientAddress },
                        { "Diagnostic-Code", "X-QMail;" + LinesRegex.Replace(failureParagraph.Message, " ").Trim() },
                    });
            }

            if (failureParagraphs.Length == 0)
            {
                messageDeliveryStatus.StatusGroups.Add(
                   new HeaderList
                   {
                        { "Action", "failed" },
                        { "Status", "5.3.0" },
                        { "Diagnostic-Code", "X-QMail; No failure paragraphs found" },
                   });
            }

            return new BounceDetectResult(
                message,
                new TextPart("plain", parts[0]),
                messageDeliveryStatus,
                new MessagePart("rfc822", undeliveredMessage));
        }