示例#1
0
        /// <summary>
        /// Parse a disposition header value
        /// </summary>
        /// <param name="value">header value</param>
        /// <returns><see cref="Disposition"/> object</returns>
        public static Disposition ParseDisposition(string value)
        {
            // SplitField checks value for null/empty
            string[] parts = SplitField(value, MDNError.InvalidDisposition);

            string[] dispositionMode         = SplitSubField(parts[0], MDNError.InvalidDisposition);
            MDNStandard.TriggerType trigger  = ParseTriggerType(dispositionMode[0]);
            MDNStandard.SendType    sendType = ParseSendType(dispositionMode[1]);

            string[] dispositionType = SplitSubField(parts[1], 1, MDNError.InvalidDisposition);
            MDNStandard.NotificationType notification = ParseNotificationType(dispositionType[0].Trim());

            Disposition disposition = new Disposition(trigger, sendType, notification);

            if (dispositionType.Length > 1)
            {
                //
                // Modifiers that also need parsing
                //
                string[] modifiers = SplitModifier(dispositionType[1].Trim(), MDNError.InvalidDisposition);
                for (int i = 0; i < modifiers.Length; ++i)
                {
                    if (MailStandard.Equals(modifiers[i], MDNStandard.Modifier_Error))
                    {
                        disposition.IsError = true;
                    }
                }
            }

            return(disposition);
        }
示例#2
0
        internal Notification(MimeEntity explanation, HeaderCollection fields)
        {
            m_explanation = explanation;
            m_fields      = fields;

            m_disposition = MDNParser.ParseDisposition(m_fields.GetValue(MDNStandard.Fields.Disposition));
            //
            // Optional data
            //
            string field = m_fields.GetValue(MDNStandard.Fields.ReportingAgent);

            if (!string.IsNullOrEmpty(field))
            {
                m_reportingAgent = MDNParser.ParseReportingUserAgent(field);
            }
            field = m_fields.GetValue(MDNStandard.Fields.Gateway);
            if (!string.IsNullOrEmpty(field))
            {
                m_gateway = MDNParser.ParseMdnGateway(field);
            }
            field = m_fields.GetValue(MDNStandard.Fields.FinalRecipient);
            if (!string.IsNullOrEmpty(field))
            {
                m_finalRecipient = MDNParser.ParseFinalRecipient(field);
            }
        }
示例#3
0
        public void TestDisposition()
        {
            Disposition disposition = new Disposition(MDNStandard.NotificationType.Processed);
            Assert.True(disposition.ToString() == "automatic-action/MDN-sent-automatically;processed");

            disposition = new Disposition(MDNStandard.NotificationType.Processed, true);
            Assert.True(disposition.ToString() == "automatic-action/MDN-sent-automatically;processed/error");
                        
            disposition = new Disposition(MDNStandard.TriggerType.Automatic, MDNStandard.SendType.UserMediated, MDNStandard.NotificationType.Displayed, true);
            Assert.True(disposition.ToString() == "automatic-action/MDN-sent-manually;displayed/error");
            
            disposition = new Disposition(MDNStandard.TriggerType.UserInitiated, MDNStandard.SendType.UserMediated, MDNStandard.NotificationType.Displayed, true);
            Assert.True(disposition.ToString() == "manual-action/MDN-sent-manually;displayed/error");
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance with the supplied <see cref="Disposition"/>
        /// </summary>
        /// <param name="disposition">The notification disposition for this notification.</param>
        public Notification(Disposition disposition)
            : base(MDNStandard.MediaType.DispositionReport)
        {
            m_explanation             = new MimeEntity();
            m_explanation.ContentType = MimeStandard.MediaType.TextPlain;

            m_notification             = new MimeEntity();
            m_notification.ContentType = MDNStandard.MediaType.DispositionNotification;

            m_fields = new HeaderCollection();

            this.Disposition = disposition;
            if (disposition.Notification == MDNStandard.NotificationType.Dispatched)
            {
                var segment  = new StringSegment(MDNStandard.DispositionOption_TimelyAndReliable + ":");
                var trHeader = new Header(segment);
                m_fields.Add(trHeader);
            }
        }
示例#5
0
 void VerifyEqual(Disposition x, Disposition y)
 {
     Assert.Equal(x.TriggerType, y.TriggerType);
     Assert.Equal(x.SendType, y.SendType);
     Assert.Equal(x.Notification, y.Notification);
     Assert.Equal(x.IsError, y.IsError);
 }        
示例#6
0
        public void TestExtensions_ExtensionsSerialization()
        {
            Disposition expectedDisposition = new Disposition(MDNStandard.NotificationType.Processed);

            Message source = this.CreateSourceMessage();
            Notification notification = this.CreateProcessedNotification();
            notification.SpecialFields = new HeaderCollection()
                                             {
                                                 //Header value of empty fails JoinHeader in DefaultSerializer.  Research this...
                                                 //Constructor with StringSegment does not fail.  
                                                 new Header(new StringSegment("X-Test1:")),
                                                 new Header(new StringSegment("X-Test2:MyValue"))
                                             };
            notification.OriginalRecipient = new MailAddress("*****@*****.**");
            NotificationMessage notificationMessage = source.CreateNotificationMessage(new MailAddress(source.FromValue), notification);

            var path = Path.GetTempFileName();
            try
            {
                notificationMessage.Save(path);
                Message loadedMessage = Message.Load(File.ReadAllText(path));
                Assert.True(loadedMessage.IsMDN());
                Assert.Equal(notificationMessage.ParsedContentType.MediaType, loadedMessage.ParsedContentType.MediaType);
                Assert.Equal(notificationMessage.SubjectValue, loadedMessage.SubjectValue);
                Assert.True(loadedMessage.HasHeader(MimeStandard.VersionHeader));
                Assert.True(loadedMessage.HasHeader(MailStandard.Headers.Date));
                Assert.True(loadedMessage.Headers.Count(x => (MimeStandard.Equals(x.Name, MimeStandard.VersionHeader))) == 1);
               
                var mdn = MDNParser.Parse(loadedMessage);
                VerifyEqual(expectedDisposition, mdn.Disposition);
                Assert.NotNull(mdn.SpecialFields["X-Test1"]);
                Assert.Equal("", mdn.SpecialFields["X-Test1"].ValueRaw);
                Assert.Equal("MyValue", mdn.SpecialFields["X-Test2"].Value);
                Assert.Equal(notification.OriginalRecipient, mdn.OriginalRecipient);
            }
            finally
            {
                File.Delete(path);
            }
        }
示例#7
0
        public void TestSerialization_Dispatched()
        {
            Disposition expectedDisposition = new Disposition(MDNStandard.NotificationType.Dispatched);

            Message source = this.CreateSourceMessage();
            Notification notification = this.CreateDispatchedNotification();
            NotificationMessage notificationMessage = source.CreateNotificationMessage(new MailAddress(source.FromValue), notification);

            var path = Path.GetTempFileName();
            try
            {
                notificationMessage.Save(path);
                Message loadedMessage = Message.Load(File.ReadAllText(path));
                Assert.True(loadedMessage.IsMDN());
                Assert.Equal(notificationMessage.ParsedContentType.MediaType, loadedMessage.ParsedContentType.MediaType);
                Assert.Equal(notificationMessage.SubjectValue, loadedMessage.SubjectValue);
                Assert.True(loadedMessage.HasHeader(MimeStandard.VersionHeader));
                Assert.True(loadedMessage.HasHeader(MailStandard.Headers.Date));
                Assert.True(loadedMessage.Headers.Count(x => (MimeStandard.Equals(x.Name, MimeStandard.VersionHeader))) == 1);
                var mdn = MDNParser.Parse(loadedMessage);
                VerifyEqual(expectedDisposition, mdn.Disposition);
            }
            finally
            {
                File.Delete(path);
            }
        }
示例#8
0
        /// <summary>
        /// Parse a disposition header value
        /// </summary>
        /// <param name="value">header value</param>
        /// <returns><see cref="Disposition"/> object</returns>
        public static Disposition ParseDisposition(string value)
        {
            // SplitField checks value for null/empty
            string[] parts = SplitField(value, MDNError.InvalidDisposition);

            string[] dispositionMode = SplitSubField(parts[0], MDNError.InvalidDisposition);
            MDNStandard.TriggerType trigger = ParseTriggerType(dispositionMode[0]);
            MDNStandard.SendType sendType= ParseSendType(dispositionMode[1]);
            
            string[] dispositionType = SplitSubField(parts[1], 1, MDNError.InvalidDisposition);
            MDNStandard.NotificationType notification = ParseNotificationType(dispositionType[0].Trim());

            Disposition disposition = new Disposition(trigger, sendType, notification);
            if (dispositionType.Length > 1)
            {
                //
                // Modifiers that also need parsing
                //
                string[] modifiers = SplitModifier(dispositionType[1].Trim(), MDNError.InvalidDisposition);
                for (int i = 0; i < modifiers.Length; ++i)
                {
                    if (MailStandard.Equals(modifiers[i], MDNStandard.Modifier_Error))
                    {
                        disposition.IsError = true;
                    }
                }
            }            
            
            return disposition;
        }