Exemplo n.º 1
0
 public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
 {
     if (Index != null)
     {
         writer.WriteString("@");
         writer.WriteString(Register.Name);
         writer.WriteString("+");
         writer.WriteString(Index.Name);
     }
     else
     {
         if (DirectAddress != null)
         {
             writer.WriteString("[");
             if (DirectAddress is Constant c)
             {
                 writer.WriteString(c.ToUInt16().ToString("X4"));
             }
             else
             {
                 writer.WriteString(DirectAddress.ToString());
             }
             writer.WriteString("]");
         }
         else
         {
             writer.WriteString($"@{Register.Name}");
         }
     }
 }
Exemplo n.º 2
0
        public void TestAddressTrustAnchors()
        {
            DirectAddress addr = new DirectAddress(new MailAddress("\"Eleanor Roosevelt\" <*****@*****.**>"));

            addr.TrustAnchors = new X509Certificate2Collection(new X509Certificate2());
            Assert.True(addr.HasTrustAnchors);
        }
Exemplo n.º 3
0
        public void TestBasic()
        {
            m_agent.Settings.InternalMessage.EnableRelay = true;
            m_agent.Settings.Notifications.AutoResponse  = true;

            Message msg = Message.Load(string.Format(TestMessage, Guid.NewGuid()));

            msg.RequestNotification();

            OutgoingMessage outgoing = null;
            IncomingMessage incoming = null;

            base.ProcessEndToEnd(m_agent, msg, out outgoing, out incoming);

            int i = 0;

            foreach (NotificationMessage notification in m_producer.Produce(incoming))
            {
                DirectAddress sender = incoming.DomainRecipients[i++];
                Assert.Equal(sender.Address, notification.FromValue, MailStandard.Comparer);
            }

            m_agent.Settings.InternalMessage.PickupFolder = Path.GetTempPath();
            Assert.Null(Record.Exception(() => m_agent.ProcessMessage(this.LoadMessage(outgoing.SerializeMessage()))));
        }
Exemplo n.º 4
0
 protected override void DoRender(MachineInstructionRenderer renderer, MachineInstructionRendererOptions options)
 {
     if (Index != null)
     {
         renderer.WriteString("@");
         renderer.WriteString(Register !.Name);
         renderer.WriteString("+");
         renderer.WriteString(Index.Name);
     }
     else
     {
         if (DirectAddress != null)
         {
             renderer.WriteString("[");
             if (DirectAddress is Constant c)
             {
                 renderer.WriteString(c.ToUInt16().ToString("X4"));
             }
             else
             {
                 renderer.WriteString(DirectAddress.ToString());
             }
             renderer.WriteString("]");
         }
         else
         {
             renderer.WriteString($"@{Register!.Name}");
         }
     }
 }
Exemplo n.º 5
0
        public void TestAddressTrustStatusSuccess()
        {
            DirectAddress addr = new DirectAddress("\"Eleanor Roosevelt\" <*****@*****.**>");

            addr.Status = TrustEnforcementStatus.Success;
            Assert.True(addr.IsTrusted(TrustEnforcementStatus.Success));
        }
Exemplo n.º 6
0
 public void TestAddressTrustStatusFailure()
 {
     DirectAddress addr = new DirectAddress("\"Eleanor Roosevelt\" <*****@*****.**>");
     addr.Status = TrustEnforcementStatus.Failed;
     Assert.False(addr.IsTrusted(TrustEnforcementStatus.Success));
     Assert.False(addr.IsTrusted(TrustEnforcementStatus.Unknown));
 }
Exemplo n.º 7
0
        public void TestAddressTrustStatusFailure()
        {
            DirectAddress addr = new DirectAddress("\"Eleanor Roosevelt\" <*****@*****.**>");

            addr.Status = TrustEnforcementStatus.Failed;
            Assert.False(addr.IsTrusted(TrustEnforcementStatus.Success));
            Assert.False(addr.IsTrusted(TrustEnforcementStatus.Unknown));
        }
Exemplo n.º 8
0
 public void TestBasicAddressCreate()
 {
     DirectAddress addr = new DirectAddress("*****@*****.**");
     Assert.Null(addr.Certificates);
     Assert.False(addr.HasCertificates);
     Assert.Null(addr.TrustAnchors);
     Assert.False(addr.HasTrustAnchors);
     Assert.Equal<TrustEnforcementStatus>(TrustEnforcementStatus.Unknown, addr.Status);
     Assert.False(addr.IsTrusted(TrustEnforcementStatus.Success));
     Assert.Equal<string>("eleanor", addr.User);
     Assert.Equal<string>("roosevelt.com", addr.Host);
 }
Exemplo n.º 9
0
        public void TestBasicAddressCreate()
        {
            DirectAddress addr = new DirectAddress("*****@*****.**");

            Assert.Null(addr.Certificates);
            Assert.False(addr.HasCertificates);
            Assert.Null(addr.TrustAnchors);
            Assert.False(addr.HasTrustAnchors);
            Assert.Equal <TrustEnforcementStatus>(TrustEnforcementStatus.Unknown, addr.Status);
            Assert.False(addr.IsTrusted(TrustEnforcementStatus.Success));
            Assert.Equal <string>("eleanor", addr.User);
            Assert.Equal <string>("roosevelt.com", addr.Host);
        }
Exemplo n.º 10
0
        internal Address GetAddress(DirectAddress address)
        {
            Debug.Assert(m_settings.HasAddressManager);

            using (AddressManagerClient client = CreateAddressManagerClient())
            {
                if (AddressDomainSearchEnabled(m_settings.AddressManager))
                {
                    return(client.GetAddressesOrDomain(address, EntityStatus.Enabled));
                }
                return(client.GetAddress(address, EntityStatus.Enabled));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Ensure that domain recipients are KNOWN - i.e. registered with the Config System
        /// If not, remove them.
        /// </summary>
        /// <param name="message"></param>
        void VerifyDomainRecipientsRegistered(IncomingMessage message)
        {
            message.EnsureRecipientsCategorizedByDomain(this.SecurityAgent.Domains);
            if (!message.HasDomainRecipients)
            {
                throw new AgentException(AgentError.NoRecipients);
            }

            DirectAddressCollection recipients = message.DomainRecipients;

            if (this.Settings.MaxIncomingDomainRecipients > 0 && recipients.Count > this.Settings.MaxIncomingDomainRecipients)
            {
                throw new AgentException(AgentError.MaxDomainRecipients);
            }

            if (!m_settings.HasAddressManager)
            {
                // Address validation is turned off
                return;
            }

            Address[] resolved = m_configService.GetAddresses(recipients);
            if (resolved.IsNullOrEmpty())
            {
                throw new AgentException(AgentError.NoDomainRecipients);
            }

            // Remove any addresses that could not be resolved
            // Yes, this is currently n^2, but given the typical # of addresses, cost should be insignificant
            int i = 0;

            while (i < recipients.Count)
            {
                DirectAddress recipient = recipients[i];
                int           iAddress  = Array.FindIndex <Address>(resolved, x => x.Match(recipient));
                if (iAddress >= 0)
                {
                    ++i; // Found
                    recipient.Tag = resolved[iAddress];
                }
                else
                {
                    recipients.RemoveAt(i);
                }
            }
        }
Exemplo n.º 12
0
        MessageEnvelope CreateEnvelope(CDO.Message message)
        {
            DirectAddressCollection recipientAddresses = null;
            DirectAddress           senderAddress      = null;
            MessageEnvelope         envelope;

            string messageText = message.GetMessageText();

            if (this.ExtractEnvelopeFields(message, ref recipientAddresses, ref senderAddress))
            {
                envelope = new MessageEnvelope(messageText, recipientAddresses, senderAddress);
            }
            else
            {
                envelope = new MessageEnvelope(messageText);
            }

            return(envelope);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        //
        // A CDO Message could be arriving via the SMTP server, or could have been constructed manually
        // The one created by SMTP has envelope information
        // Returns false if no envelope info is available. We have to look within message headers in that case
        //
        bool ExtractEnvelopeFields(CDO.Message message, ref DirectAddressCollection recipientAddresses, ref DirectAddress senderAddress)
        {
            if (!this.HasEnvelope)
            {
                //
                // No envelope
                //
                return(false);
            }

            recipientAddresses = null;
            senderAddress      = null;

            string sender = message.GetEnvelopeSender();

            if (string.IsNullOrEmpty(sender))
            {
                throw new SmtpAgentException(SmtpAgentError.NoSenderInEnvelope);
            }
            //
            // In SMTP Server, the MAIL TO (sender) in the envelope can be empty if the message is from the server postmaster
            // The actual postmaster address is found in the message itself
            //
            if (Health.Direct.SmtpAgent.Extensions.IsSenderLocalPostmaster(sender))
            {
                return(false);
            }
            string recipients = message.GetEnvelopeRecipients();

            if (string.IsNullOrEmpty(recipients))
            {
                throw new SmtpAgentException(SmtpAgentError.NoRecipientsInEnvelope);
            }

            recipientAddresses = DirectAddressCollection.ParseSmtpServerEnvelope(recipients);
            senderAddress      = new DirectAddress(sender);

            return(true);
        }
Exemplo n.º 15
0
        internal Address GetAddress(DirectAddress address)
        {
            Debug.Assert(_settings.HasAddressManager);

            Address managedAddress;

            if (_addressCache != null)
            {
                managedAddress = _addressCache.Get(address.Address);
                if (managedAddress != null)
                {
                    return(managedAddress);
                }
            }

            IAddressManager client = CreateAddressManagerClient();

            using (client as IDisposable)
            {
                if (_enabledDomainSearch)
                {
                    managedAddress = client.GetAddressesOrDomain(address, EntityStatus.Enabled);
                }
                else
                {
                    managedAddress = client.GetAddress(address, EntityStatus.Enabled);
                }
            }


            if (_addressCache != null)
            {
                _addressCache.Put(managedAddress);
            }

            return(managedAddress);
        }
Exemplo n.º 16
0
 static void VerifyTrusted(DirectAddress address, TrustEnforcementStatus minStatus)
 {
     Assert.True(address.IsTrusted(minStatus));
 }
Exemplo n.º 17
0
 public void TestAddressTrustAnchors()
 {
     DirectAddress addr = new DirectAddress(new MailAddress("\"Eleanor Roosevelt\" <*****@*****.**>"));
     addr.TrustAnchors = new X509Certificate2Collection(new X509Certificate2());
     Assert.True(addr.HasTrustAnchors);
 }
Exemplo n.º 18
0
 static void VerifyTrusted(DirectAddress address, TrustEnforcementStatus minStatus)
 {
     Assert.True(address.IsTrusted(minStatus));
 }
Exemplo n.º 19
0
 public void TestAddressTrustStatusSuccess()
 {
     DirectAddress addr = new DirectAddress("\"Eleanor Roosevelt\" <*****@*****.**>");
     addr.Status = TrustEnforcementStatus.Success;
     Assert.True(addr.IsTrusted(TrustEnforcementStatus.Success));
 }