Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a deliver status notification (DSN) for the given <paramref name="message"/> to the <paramref name="senders"/>.
        /// </summary>
        /// <param name="message">The message for which to send notification</param>
        /// <param name="senders">The message senders to which to send notification</param>
        /// <param name="notificationCreator">A function creating dsn objects from addresses</param>
        /// <returns>An enumerator over dsn messages</returns>
        public static IEnumerable <DSNMessage> CreateNotificationMessages(this Message message, IEnumerable <MailAddress> senders, Func <MailAddress, DSN> notificationCreator)
        {
            if (senders == null)
            {
                throw new ArgumentNullException("senders");
            }
            if (notificationCreator == null)
            {
                throw new ArgumentNullException("notificationCreator");
            }

            if (message.IsDSN())
            {
                yield break;
            }

            foreach (MailAddress sender in senders)
            {
                DSN        dsn           = notificationCreator(sender);
                DSNMessage statusMessage = message.CreateStatusMessage(sender, dsn);
                if (statusMessage != null)
                {
                    yield return(statusMessage);
                }
            }
        }
Ejemplo n.º 3
0
 static DSNMessage CreateNotificationMessage(Mdn mdn, TimeoutSettings settings)
 {
     var perMessage = new DSNPerMessage(settings.ProductName, mdn.MessageId);
     var perRecipient = new DSNPerRecipient(DSNStandard.DSNAction.Failed, DSNStandard.DSNStatus.Permanent
                                            , DSNStandard.DSNStatus.NETWORK_EXPIRED_PROCESSED,
                                            MailParser.ParseMailAddress(mdn.Recipient));
     //
     // The nature of Mdn storage in config store does not result in a list of perRecipients
     // If you would rather send one DSN with muliple recipients then one could write their own Job.
     //
     var notification = new DSN(perMessage, new List<DSNPerRecipient> { perRecipient });
     var sender = new MailAddress(mdn.Sender);
     var notificationMessage = new DSNMessage(sender.Address, new MailAddress("Postmaster@" + sender.Host).Address, notification);
     notificationMessage.AssignMessageID();
     notificationMessage.SubjectValue = string.Format("{0}:{1}", "Rejected", mdn.SubjectValue);
     notificationMessage.Timestamp();
     return notificationMessage;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates an DSN Notification for the given message
        /// </summary>
        /// <param name="from">PostalAddress this notification is from</param>
        /// <param name="message">source message</param>
        /// <param name="dsn">The dsn to created</param>
        /// <returns>Null if no notification should be issued</returns>
        public static DSNMessage CreateNotificationMessage(this Message message, MailAddress from, DSN dsn)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

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

            if (!message.ShouldIssueNotification())
            {
                return(null);
            }

            return(DSNMessage.CreateNotificationFor(message, from, dsn));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates an DSN Notification for the given message
        /// </summary>
        /// <param name="from">PostalAddress this notification is from</param>
        /// <param name="message">source message</param>
        /// <param name="notification"></param>
        /// <returns>Null if no notification should be issued</returns>
        public static DSNMessage CreateStatusMessage(this Message message, MailAddress from, DSN notification)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

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

            if (message.IsDSN())
            {
                return(null);
            }

            return(DSNMessage.CreateNotificationFor(message, from, notification));
        }
Ejemplo n.º 6
0
        /// <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;
        }