static void TestMdnTimelyAndReliableExtensionField(NotificationMessage message, bool exists) { var mdn = MDNParser.Parse(message); TestMdnTimelyAndReliableExtensionField(mdn, exists); }
/// <summary> /// Takes a message and constructs an MDN for it. /// </summary> /// <param name="message">The message to send notification about.</param> /// <param name="from">MailAddress this notification is from</param> /// <param name="notification">The notification to create.</param> /// <returns>The MDN.</returns> public static NotificationMessage CreateNotificationFor(Message message, MailAddress from, Notification notification) { if (message == null) { throw new ArgumentNullException("message"); } if (from == null) { throw new ArgumentNullException("from"); } if (notification == null) { throw new ArgumentNullException("notification"); } // // Verify that the message is not itself an MDN! // if (message.IsMDN()) { throw new ArgumentException("Message is an MDN"); } string notifyTo = message.GetNotificationDestination(); if (string.IsNullOrEmpty(notifyTo)) { throw new ArgumentException("Invalid Disposition-Notification-To Header"); } string originalMessageID = message.IDValue; if (!string.IsNullOrEmpty(originalMessageID)) { notification.OriginalMessageID = originalMessageID; } if (!notification.HasFinalRecipient) { notification.FinalRecipient = from; } NotificationMessage notificationMessage = new NotificationMessage(notifyTo, from.ToString(), notification); notificationMessage.AssignMessageID(); string originalSubject = message.SubjectValue; if (!string.IsNullOrEmpty(originalSubject)) { notificationMessage.SubjectValue = string.Format("{0}:{1}", notification.Disposition.Notification.AsString(), originalSubject); } notificationMessage.Timestamp(); return notificationMessage; }
void Parse(Notification source, NotificationMessage notificationMessage) { Notification parsed = null; Assert.DoesNotThrow(() => parsed = MDNParser.Parse(source)); Assert.NotNull(parsed.Disposition); VerifyEqual(source, parsed); }