public void RemoveRecipients()
        {
            MessageEnvelope         envelope = new MessageEnvelope(TestMessage);
            DirectAddressCollection toRemove = new DirectAddressCollection();

            toRemove.Add(new DirectAddress("<*****@*****.**>"));
            toRemove.Add(new DirectAddress("<*****@*****.**>"));
            toRemove.Add(new DirectAddress("<*****@*****.**>"));
            toRemove.Add(new DirectAddress("<*****@*****.**>"));

            Assert.DoesNotThrow(() => envelope.RemoveFromRoutingHeaders(toRemove));

            string outputText = null;

            Assert.DoesNotThrow(() => outputText = envelope.SerializeMessage());

            Message outputMessage = Message.Load(outputText);

            Assert.True(outputMessage.Bcc == null);

            this.CheckHeaderRaw(outputMessage.Cc, 2);
            this.CheckCollection(outputMessage.Cc,
                                 new string[] { "*****@*****.**", "*****@*****.**" },
                                 new string[] { "*****@*****.**>", "*****@*****.**" });

            this.CheckHeaderRaw(outputMessage.To, 1);
            this.CheckCollection(outputMessage.To,
                                 new string[] { "*****@*****.**" },
                                 new string[] { "*****@*****.**" });
        }
Esempio n. 2
0
 public void RemoveRecipients()
 {
     MessageEnvelope envelope = new MessageEnvelope(TestMessage);
     DirectAddressCollection toRemove = new DirectAddressCollection();
     toRemove.Add(new DirectAddress("<*****@*****.**>"));
     toRemove.Add(new DirectAddress("<*****@*****.**>"));
     toRemove.Add(new DirectAddress("<*****@*****.**>"));
     toRemove.Add(new DirectAddress("<*****@*****.**>"));
     
     Assert.DoesNotThrow(() => envelope.RemoveFromRoutingHeaders(toRemove));
     
     string outputText = null;
     Assert.DoesNotThrow(() => outputText = envelope.SerializeMessage());
     
     Message outputMessage = Message.Load(outputText);
     Assert.True(outputMessage.Bcc == null);
     
     this.CheckHeaderRaw(outputMessage.Cc, 2);
     this.CheckCollection(outputMessage.Cc, 
                         new string[] {"*****@*****.**", "*****@*****.**"},
                         new string[] {"*****@*****.**>", "*****@*****.**"});
     
     this.CheckHeaderRaw(outputMessage.To, 1);
     this.CheckCollection(outputMessage.To,
                         new string[] { "*****@*****.**"},
                         new string[] { "*****@*****.**"});
                          
 }
Esempio n. 3
0
        public void TestManInMiddle(string fileName, string injectedWithPersonalKey, string injectedWithOrgKey)
        {
            //
            // Take an encrypted message, add additional recipients
            //
            OutgoingMessage outgoing = m_tester.ProcessOutgoingFile(fileName);
            string          message  = outgoing.SerializeMessage();
            IncomingMessage incoming = new IncomingMessage(message, outgoing.Recipients, outgoing.Sender);

            Assert.DoesNotThrow(() => m_tester.AgentB.ProcessIncoming(incoming));
            //
            // Add additional recipient not in original message
            //
            DirectAddressCollection recipients = new DirectAddressCollection(outgoing.Recipients);

            recipients.Add(new DirectAddress(injectedWithPersonalKey));
            incoming = new IncomingMessage(message, recipients, outgoing.Sender);
            Assert.Throws <AgentException>(() => m_tester.AgentB.ProcessIncoming(incoming));
            //
            // Replace recipient entirely
            //
            recipients.Clear();
            recipients.Add(new DirectAddress(injectedWithPersonalKey));
            incoming = new IncomingMessage(message, recipients, outgoing.Sender);
            Assert.Throws <AgentException>(() => m_tester.AgentB.ProcessIncoming(incoming));
            //
            // Inject recipient with org certs
            //
            recipients.Clear();
            recipients.Add(outgoing.Recipients);
            recipients.Add(new DirectAddress(injectedWithOrgKey));
            incoming = new IncomingMessage(message, recipients, outgoing.Sender);
            Assert.Throws <AgentException>(() => m_tester.AgentB.ProcessIncoming(incoming));
        }
Esempio n. 4
0
        void SendDeliveryStatus(IEnumerable <Route> router, IncomingMessage envelope, DirectAddressCollection routedRecipients)
        {
            if (envelope.Message.IsMDN() || envelope.Message.IsDSN())
            {
                return;
            }

            DirectAddressCollection undeliveredRecipients = new DirectAddressCollection();

            foreach (var route in router)
            {
                if (route.FailedDelivery)
                {
                    foreach (var routedRecipient in routedRecipients)
                    {
                        if (route.AddressType == routedRecipient.Tag as string)
                        {
                            undeliveredRecipients.Add(routedRecipient);
                        }
                    }
                }
            }

            try
            {
                m_notifications.SendFailure(envelope, m_settings.InternalMessage.PickupFolder, undeliveredRecipients);
            }
            catch (Exception ex)
            {
                Logger.Error("While sending un-secured DSN {0}", ex.Message);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Find <c>DirectAddress</c>s without Certificates
        /// </summary>
        /// <param name="addresses"></param>
        /// <returns></returns>
        public static DirectAddressCollection UnResolvedCertificates(this DirectAddressCollection addresses)
        {
            DirectAddressCollection unsecured = new DirectAddressCollection();

            foreach (DirectAddress addr in addresses)
            {
                if (!addr.ResolvedCertificates)
                {
                    unsecured.Add(addr);
                }
            }
            return(unsecured);
        }
Esempio n. 6
0
        DirectAddressCollection BasicCollection()
        {
            string[] addrStrings = new string[] {
                "*****@*****.**",
                "\"Franklin Roosevelt\" <*****@*****.**>",
                "sean+o'*****@*****.**"
            };
            IEnumerable <DirectAddress> addrs = addrStrings.Select(a => new DirectAddress(a));
            DirectAddressCollection     coll  = new DirectAddressCollection();

            coll.Add(addrs);
            coll[0].Status = TrustEnforcementStatus.Failed;
            coll[1].Status = TrustEnforcementStatus.Unknown;
            coll[2].Status = TrustEnforcementStatus.Success;
            return(coll);
        }
Esempio n. 7
0
        void Route(ISmtpMessage message, DirectAddressCollection recipients, DirectAddressCollection routedRecipients)
        {
            Dictionary <string, Route> matchedRoutes = new Dictionary <string, Route>(StringComparer.OrdinalIgnoreCase);
            int i = 0;

            //
            // First, find all routes that match
            // We'll remove recipients that were routed from the recipients list so
            // SMTP server does not itself try to deliver to them
            //
            while (i < recipients.Count)
            {
                DirectAddress recipient = recipients[i];
                Address       address   = recipient.Tag as Address;
                if (address != null)
                {
                    Route route = this[address.Type];
                    if (route != null)
                    {
                        matchedRoutes[address.Type] = route;
                        recipients.RemoveAt(i);
                        if (routedRecipients != null)
                        {
                            recipient.Tag = route.AddressType;  // Reference for failed delivery
                            routedRecipients.Add(recipient);    // Add the routed recipient to the list
                        }
                        continue;
                    }
                }

                ++i;
            }
            if (matchedRoutes.Count == 0)
            {
                return;
            }

            this.Route(message, matchedRoutes.Values);
        }
Esempio n. 8
0
 /// <summary>
 /// Find <c>DirectAddress</c>s without Certificates
 /// </summary>
 /// <param name="addresses"></param>
 /// <returns></returns>
 public static DirectAddressCollection UnResolvedCertificates(this DirectAddressCollection addresses)
 {
     DirectAddressCollection unsecured = new DirectAddressCollection();
     foreach (DirectAddress addr in addresses)
     {
         if ( ! addr.ResolvedCertificates)
         {
             unsecured.Add(addr);
         }
     }
     return unsecured;
 }
Esempio n. 9
0
 /// <summary>
 /// Return a combined collection of all recipients in routing headers (to/cc/bcc)
 /// </summary>
 /// <returns>A collection of recipients</returns>        
 public DirectAddressCollection GetRecipientsInRoutingHeaders()
 {
     DirectAddressCollection addresses = new DirectAddressCollection();
     if (this.To != null)
     {
         addresses.Add(this.To);
     }                
     if (this.Cc != null)
     {
         addresses.Add(this.Cc);
     }
     if (this.Bcc != null)
     {
         addresses.Add(this.Bcc);
     }
     return addresses;
 }
Esempio n. 10
0
        void SendDeliveryStatus(IEnumerable<Route> router, IncomingMessage envelope, DirectAddressCollection routedRecipients)
        {
            if (envelope.Message.IsMDN() || envelope.Message.IsDSN())
            {
                return;
            }
            
            DirectAddressCollection undeliveredRecipients = new DirectAddressCollection();
            
            foreach (var route in router)
            {
               if (route.FailedDelivery)
               {
                   foreach (var routedRecipient in routedRecipients)
                   {
                       if(route.AddressType == routedRecipient.Tag as string)
                       {
                           undeliveredRecipients.Add(routedRecipient);
                       }
                   }
               }
            }

            try
            {
                m_notifications.SendFailure(envelope, m_settings.InternalMessage.PickupFolder, undeliveredRecipients);
            }
            catch (Exception ex)
            {
                Logger.Error("While sending un-secured DSN {0}", ex.Message);
            }
        }
Esempio n. 11
0
 DirectAddressCollection BasicCollection()
 {
     string[] addrStrings = new string[] {
                                             "*****@*****.**",
                                             "\"Franklin Roosevelt\" <*****@*****.**>",
                                             "sean+o'*****@*****.**"};
     IEnumerable<DirectAddress> addrs =  addrStrings.Select(a => new DirectAddress(a));
     DirectAddressCollection coll = new DirectAddressCollection();
     coll.Add(addrs);
     coll[0].Status = TrustEnforcementStatus.Failed;
     coll[1].Status = TrustEnforcementStatus.Unknown;
     coll[2].Status = TrustEnforcementStatus.Success;
     return coll;
 }
Esempio n. 12
0
 public void TestManInMiddle(string fileName, string injectedWithPersonalKey, string injectedWithOrgKey)
 {
     //
     // Take an encrypted message, add additional recipients
     //
     OutgoingMessage outgoing = m_tester.ProcessOutgoingFile(fileName);
     string message = outgoing.SerializeMessage();
     IncomingMessage incoming = new IncomingMessage(message, outgoing.Recipients, outgoing.Sender);
     Assert.DoesNotThrow(() => m_tester.AgentB.ProcessIncoming(incoming));
     //
     // Add additional recipient not in original message
     //
     DirectAddressCollection recipients = new DirectAddressCollection(outgoing.Recipients);
     recipients.Add(new DirectAddress(injectedWithPersonalKey));            
     incoming = new IncomingMessage(message, recipients, outgoing.Sender);
     Assert.Throws<AgentException>(() => m_tester.AgentB.ProcessIncoming(incoming));
     //
     // Replace recipient entirely
     //
     recipients.Clear();
     recipients.Add(new DirectAddress(injectedWithPersonalKey));
     incoming = new IncomingMessage(message, recipients, outgoing.Sender);
     Assert.Throws<AgentException>(() => m_tester.AgentB.ProcessIncoming(incoming));            
     //
     // Inject recipient with org certs
     //
     recipients.Clear();
     recipients.Add(outgoing.Recipients);
     recipients.Add(new DirectAddress(injectedWithOrgKey));
     incoming = new IncomingMessage(message, recipients, outgoing.Sender);
     Assert.Throws<AgentException>(() => m_tester.AgentB.ProcessIncoming(incoming));
 }