Beispiel #1
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);
            }
        }
Beispiel #2
0
        public void TestDispostionTypeDeserializationNoTrim()
        {
            //Notice the leading space at processed
            var message =
                @"MIME-Version:1.0
To:[email protected]
From:[email protected]
Content-Type:multipart/report; boundary=d027c90b736247f6908bb9558cbc5926; report-type=disposition-notification
Subject:processed
Message-ID:0c0918d7-5bfa-48e4-91c0-6bffc7660967
Date:7 Dec 2012 12:50:26 -08:00


--d027c90b736247f6908bb9558cbc5926
Content-Type:text/plain

Synchronicity
--d027c90b736247f6908bb9558cbc5926
Content-Type:message/disposition-notification

Disposition:automatic-action/MDN-sent-automatically; processed
Original-Message-ID:Message In a Bottle
MDN-Gateway:smtp;gateway.example.com
Final-Recipient:rfc822;[email protected]

--d027c90b736247f6908bb9558cbc5926--";
            Message loadedMessage = Message.Load(message);
            var     mdn           = MDNParser.Parse(loadedMessage);

            Assert.Equal("processed", mdn.Disposition.Notification.ToString(), StringComparer.OrdinalIgnoreCase);
        }
Beispiel #3
0
        void Parse(Notification source, NotificationMessage notificationMessage)
        {
            Notification parsed = null;

            Assert.DoesNotThrow(() => parsed = MDNParser.Parse(source));
            Assert.NotNull(parsed.Disposition);
            VerifyEqual(source, parsed);
        }
Beispiel #4
0
        void Parse(Notification source, NotificationMessage notificationMessage)
        {
            Notification parsed = null;

            Assert.Null(Record.Exception(() => parsed = MDNParser.Parse(source)));
            Assert.NotNull(parsed.Disposition);
            VerifyEqual(source, parsed);
        }
Beispiel #5
0
        public void TestDispatchTimelyAndReliableExtension_AssertExtension()
        {
            Message             source              = this.CreateSourceMessage();
            Notification        notification        = this.CreateDispatchedNotification();
            NotificationMessage notificationMessage = source.CreateNotificationMessage(new MailAddress(source.FromValue), notification);

            var mdn = MDNParser.Parse(notificationMessage);

            Assert.NotNull(mdn.SpecialFields[MDNStandard.DispositionOption_TimelyAndReliable]);
        }
Beispiel #6
0
        protected static Mdn BuildMdnQueryFromMdn(CDO.Message message)
        {
            var messageEnvelope = new CDOSmtpMessage(message).GetEnvelope();

            Assert.True(messageEnvelope.Message.IsMDN());
            var    notification      = MDNParser.Parse(messageEnvelope.Message);
            var    originalMessageId = notification.OriginalMessageID;
            string originalSender    = messageEnvelope.Recipients[0].Address;
            string originalRecipient = messageEnvelope.Sender.Address;

            return(new Mdn(originalMessageId, originalRecipient, originalSender));
        }
Beispiel #7
0
        public void TestEndToEnd_GatewayIsDestination_Is_True_And_TimelyAndReliable_Not_Requestd()
        {
            CleanMessages(m_agent.Settings);
            m_agent.Settings.InternalMessage.EnableRelay        = true;
            m_agent.Settings.Outgoing.EnableRelay               = true;
            m_agent.Settings.Notifications.AutoResponse         = true;
            m_agent.Settings.Notifications.AlwaysAck            = true;
            m_agent.Settings.Notifications.GatewayIsDestination = true;

            //
            // Process loopback messages.  Leaves un-encrypted mdns in pickup folder
            // Go ahead and pick them up and Process them as if they where being handled
            // by the SmtpAgent by way of (IIS)SMTP hand off.
            //
            string textMessage    = string.Format(string.Format(TestMessageHsmToSoft, Guid.NewGuid()), Guid.NewGuid());
            var    sendingMessage = LoadMessage(textMessage);

            RunEndToEndTest(sendingMessage, m_agent);

            //
            // grab the clear text mdns and delete others.
            //
            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("disposition-notification"))
                {
                    RunMdnOutBoundProcessingTest(LoadMessage(messageText), m_agent);
                }
            }

            //
            // Now the messages are encrypted and can be handled
            // Processed Mdn's will be recorded by the MdnMonitorService
            //
            foreach (var pickupMessage in PickupMessages())
            {
                string      messageText = File.ReadAllText(pickupMessage);
                CDO.Message message     = LoadMessage(messageText);

                RunMdnInBoundProcessingTest(message, m_agent);
                var envelope = new CDOSmtpMessage(message).GetEnvelope();
                var mdn      = MDNParser.Parse(envelope.Message);

                //
                // Only expect processed MDNs
                //
                Assert.Equal(MDNStandard.NotificationType.Processed, mdn.Disposition.Notification);
                TestMdnTimelyAndReliableExtensionField(mdn, false);
            }

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        internal void UpdateMdn(IncomingMessage message)
        {
            Debug.Assert(m_settings.HasMdnManager);

            using (MdnMonitorClient client = m_settings.MdnMonitor.CreateMdnMonitorClient())
            {
                var notification      = MDNParser.Parse(message.Message);
                var disposition       = notification.Disposition;
                var originalMessageId = notification.OriginalMessageID;
                var originalSender    = message.Recipients.First().Address;
                var originalRecipient = message.Sender.Address;

                client.Update(
                    new Mdn // extract into MdnMonitorParser
                {
                    MessageId = originalMessageId,
                    Recipient = originalRecipient,
                    Sender    = originalSender,
                    Status    = disposition.Notification.ToString()
                });
            }
        }
Beispiel #10
0
        static void TestMdnTimelyAndReliableExtensionField(NotificationMessage message, bool exists)
        {
            var mdn = MDNParser.Parse(message);

            TestMdnTimelyAndReliableExtensionField(mdn, exists);
        }
Beispiel #11
0
        public void TestEndToEnd_GatewayIsDestination_Is_True_And_TimelyAndReliable_Not_Requestd()
        {
            CleanMessages(m_agent.Settings);
            m_agent.Settings.InternalMessage.EnableRelay        = true;
            m_agent.Settings.Outgoing.EnableRelay               = true;
            m_agent.Settings.Notifications.AutoResponse         = true;
            m_agent.Settings.Notifications.AlwaysAck            = true;
            m_agent.Settings.Notifications.GatewayIsDestination = true;
            m_agent.Settings.MdnMonitor     = new ClientSettings();
            m_agent.Settings.MdnMonitor.Url = "http://localhost/ConfigService/MonitorService.svc/Dispositions";

            //
            // Process loopback messages.  Leaves un-encrypted mdns in pickup folder
            // Go ahead and pick them up and Process them as if they where being handled
            // by the SmtpAgent by way of (IIS)SMTP hand off.
            //
            string textMessage    = string.Format(string.Format(TestMessage, Guid.NewGuid()), Guid.NewGuid());
            var    sendingMessage = LoadMessage(textMessage);

            Assert.Null(Record.Exception(() => RunEndToEndTest(sendingMessage)));

            //
            // grab the clear text mdns and delete others.
            //
            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("disposition-notification"))
                {
                    Assert.Null(Record.Exception(() => RunMdnOutBoundProcessingTest(LoadMessage(messageText))));
                }
            }

            //
            // Now the messages are encrypted and can be handled
            // Processed Mdn's will be recorded by the MdnMonitorService
            //
            foreach (var pickupMessage in PickupMessages())
            {
                string      messageText = File.ReadAllText(pickupMessage);
                CDO.Message message     = LoadMessage(messageText);

                Assert.Null(Record.Exception(() => RunMdnInBoundProcessingTest(message)));
                var envelope = new CDOSmtpMessage(message).GetEnvelope();
                var mdn      = MDNParser.Parse(envelope.Message);

                //
                // Only expect processed MDNs
                //
                Assert.Equal(MDNStandard.NotificationType.Processed, mdn.Disposition.Notification);
                TestMdnTimelyAndReliableExtensionField(mdn, false);
            }

            //
            // Test Mdn data is processed
            // Remember above (Settings.Notifications.GatewayIsDestination = true)
            // but message did not request TimelyAndReliable
            //
            var messageEnvelope = new CDOSmtpMessage(sendingMessage).GetEnvelope();

            foreach (var recipient in messageEnvelope.Recipients)
            {
                var queryMdn = new Mdn(messageEnvelope.Message.IDValue
                                       , recipient.Address
                                       , messageEnvelope.Message.FromValue
                                       , MdnStatus.Processed);

                var mdnManager = CreateConfigStore().Mdns;
                var mdn        = mdnManager.Get(queryMdn.MdnIdentifier);
                Assert.NotNull(mdn);
                Assert.Equal("processed", mdn.Status, StringComparer.OrdinalIgnoreCase);
                Assert.Equal(false, mdn.NotifyDispatched);
            }

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }