Пример #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;
        }
Пример #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);
                }
            }
        }
Пример #3
0
  /// <summary>
  /// Initializes a DSN to the specified recipient.
  /// </summary>
  /// <param name="to">The DSN recipient.</param>
  /// <param name="from">Postmaster</param>
  /// <param name="notification">The dsn to send.</param>
  public DSNMessage(string to, string from, DSN notification)
      : base(to, from)
  {
      if (notification == null)
      {
          throw new ArgumentNullException("notification");
      }
      
      this.SetParts(notification);
 }
Пример #4
0
        /// <summary>
        /// Initializes a DSN to the specified recipient.
        /// </summary>
        /// <param name="to">The DSN recipient.</param>
        /// <param name="from">Postmaster</param>
        /// <param name="notification">The dsn to send.</param>
        public DSNMessage(string to, string from, DSN notification)
            : base(to, from)
        {
            if (notification == null)
            {
                throw new ArgumentNullException("notification");
            }

            this.SetParts(notification);
        }
Пример #5
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;
 }
Пример #6
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);
        }
Пример #7
0
        DSN CreateFailedStatusNotification(int recipients)
        {
            ReportingMtaName = "reporting_mta_name";
            var perMessage = new DSNPerMessage(ReportingMtaName, OriginalID);

            var perRecipients = new List<DSNPerRecipient>();
            for (int i = 1; i <= recipients; i++)
            {
                perRecipients.Add(new DSNPerRecipient(DSNStandard.DSNAction.Failed, DSNStandard.DSNStatus.Permanent
                                                      , DSNStandard.DSNStatus.UNDEFINED_STATUS,
                                                      new MailAddress(String.Format("User{0}@kryptiq.com", i))));
                
            }
            
            var dsn = new DSN(perMessage, perRecipients);

            return dsn;
        }
Пример #8
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));
        }
Пример #9
0
 /// <summary>
 /// Initializes a DSN to the specified recipient.
 /// </summary>
 /// <param name="to">The DSN recipient.</param>
 /// <param name="notification">The notification to send.</param>
 public DSNMessage(string to, DSN notification)
     : this(to, null, notification)
 {
 }
Пример #10
0
 /// <summary>
 /// Initializes a DSN to the specified recipient.
 /// </summary>
 /// <param name="to">The DSN recipient.</param>
 /// <param name="notification">The notification to send.</param>
 public DSNMessage(string to, DSN notification)
     : this(to, null, notification)
 {
 }
Пример #11
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);
        }
        /// <summary>
        /// Generate external notification messages for failed final destination delivery
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="recipients">sending failure status for these message recipients</param>
        /// <returns>An DSNmessage</returns>
        public DSNMessage ProduceFailure(IncomingMessage envelope, DirectAddressCollection recipients)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException("envelope");
            }

            if (string.IsNullOrEmpty(m_settings.ProductName))
            {
                throw new ArgumentException("reportingAgentName:AgentSettings:ProductName");  
            }

            DSNPerMessage perMessage = new DSNPerMessage(envelope.Sender.Host, envelope.Message.IDValue);

            //
            // Un-Deliverable recipients
            //
            List<DSNPerRecipient> dsnPerRecipients = envelope.CreatePerRecipientStatus(recipients.AsMailAddresses()
                , m_settings.Text, m_settings.AlwaysAck, DSNStandard.DSNAction.Failed, DSNStandard.DSNStatus.Permanent
                , DSNStandard.DSNStatus.DELIVERY_OTHER).ToList();
            

            DSN dsn = new DSN(perMessage, dsnPerRecipients);

            //Configure and/or dynamic plus refactor
            //TODO: Split messages by domain.  See envelope.Recipients[0] below.
            return envelope.Message.CreateStatusMessage(new MailAddress("Postmaster@" + envelope.Recipients[0].Host), dsn);

        }
        /// <summary>
        /// Generate internal notification messages (if any) for this outgoing message
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="recipients">sending failure status for these message recipients</param>
        /// <returns>An DSNmessage</returns>
        public DSNMessage ProduceFailure(OutgoingMessage envelope, DirectAddressCollection recipients)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException("envelope");
            }

            if (string.IsNullOrEmpty(m_settings.ProductName))
            {
                throw new ArgumentException("reportingAgentName:AgentSettings:ProductName");
            }

            DSNPerMessage perMessage = new DSNPerMessage(envelope.Sender.Host, envelope.Message.IDValue);

            //
            // Un-Secured recipients
            //
            List<DSNPerRecipient> dsnPerRecipients = envelope.CreatePerRecipientStatus(recipients.UnResolvedCertificates().AsMailAddresses()
                , m_settings.Text, m_settings.AlwaysAck, DSNStandard.DSNAction.Failed, DSNStandard.DSNStatus.Permanent
                , DSNStandard.DSNStatus.UNSECURED_STATUS).ToList();
            //
            // Un-Trusted recipients
            //
            dsnPerRecipients.AddRange(envelope.CreatePerRecipientStatus(recipients.ResolvedCertificates().AsMailAddresses()
                , m_settings.Text, m_settings.AlwaysAck, DSNStandard.DSNAction.Failed, DSNStandard.DSNStatus.Permanent
                , DSNStandard.DSNStatus.UNTRUSTED_STATUS).ToList());

            DSN dsn = new DSN(perMessage, dsnPerRecipients);

            //Configure and/or dynamic plus refactor
            return envelope.Message.CreateStatusMessage(new MailAddress("Postmaster@" + envelope.Sender.Host), dsn);

        }
Пример #14
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));
        }
Пример #15
0
        /// <summary>
        /// Verify Disposition-Type MDN notification 
        /// </summary>
        void VerifyDSNHeaders(MimeEntity notificationEntity, DSN notification)
        {
            HeaderCollection fields = DSNParser.ParseDSNFields(notificationEntity);
            Assert.NotEmpty(fields);
            //
            // perMessage
            //
            Assert.True(fields.HasHeader(DSNStandard.Fields.ReportingMTA, "dns;" + ReportingMtaName));
            Assert.True(fields.HasHeader(DSNStandard.Fields.OriginalMessageID, OriginalID));

            //
            // perRecipient
            //
            Assert.True(fields.HasHeader(DSNStandard.Fields.FinalRecipient, 
                                         "rfc822;" + notification.PerRecipient.First().FinalRecipient.Address));
            Assert.True(fields.HasHeader(DSNStandard.Fields.Action, "failed"));
            Assert.True(fields.HasHeader(DSNStandard.Fields.Status, "5.0.0"));
            
        }
Пример #16
0
        private void VerifyEqual(DSN dsnExpected, DSN dsnActual)
        {
            Assert.Equal(dsnExpected.PerMessage.ReportingMtaName, dsnActual.PerMessage.ReportingMtaName);
            Assert.Equal(dsnExpected.PerMessage.OriginalMessageId, dsnActual.PerMessage.OriginalMessageId);

            Assert.Equal(dsnExpected.PerRecipient.Count(), dsnActual.PerRecipient.Count());

            Assert.Equal(dsnExpected.PerRecipient.First().FinalRecipient, dsnActual.PerRecipient.First().FinalRecipient);
            Assert.Equal(dsnExpected.PerRecipient.First().Action, dsnActual.PerRecipient.First().Action);
            Assert.Equal(dsnExpected.PerRecipient.First().Status, dsnActual.PerRecipient.First().Status);
        }
Пример #17
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);
        }