/// <summary> /// Takes a message and constructs an DSN for it. /// </summary> /// <param name="message">The message to send notification about.</param> /// <param name="from">MailAddress this notification is from</param> /// <param name="dsn">The dsn to create.</param> /// <returns>The DSN.</returns> public static DSNMessage CreateNotificationFor(Message message, MailAddress from, DSN dsn) { if (message == null) { throw new ArgumentNullException("message"); } if (from == null) { throw new ArgumentNullException("from"); } if (dsn == null) { throw new ArgumentNullException("dsn"); } // // Verify that the message is not itself an MDN! // if (message.IsMDN()) { throw new ArgumentException("Message is an MDN"); } string notifyTo = message.From.Value; DSNMessage statusMessage = new DSNMessage(notifyTo, from.ToString(), dsn); statusMessage.AssignMessageID(); statusMessage.SubjectValue = string.Format("{0}:{1}", "Rejected", message.SubjectValue); statusMessage.Timestamp(); return statusMessage; }
/// <summary> /// Extract MDN Notifications from a message /// </summary> /// <param name="message"><see cref="Health.Direct.Common.Mail.Message"/></param> /// <returns><see cref="Notification"/>object</returns> public static Notification Parse(Message message) { if (message == null) { throw new ArgumentNullException("message"); } if (!message.IsMDN()) { throw new MDNException(MDNError.NotMDN); } if (!message.IsMultiPart) { throw new MDNException(MDNError.InvalidMDNBody); } return Parse(message.GetParts()); }
/// <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; }