Example #1
0
        protected virtual MessageEnvelope ProcessEnvelope(ISmtpMessage message, MessageEnvelope envelope)
        {
            //
            // OUTGOING:
            //  Non-Encrypted messages from within the domain are treated as OUTGOING.
            //  Encrypted messages from within the domain are OPTIONALLY treated as Incoming
            //    - Only if InternalRelay is enabled
            // INCOMING:
            //  All messages sent by sources OUTSIDE the domain are ALWAYS treated as INCOMING
            //
            // The following boolean logic is the way it is to make it *easy to read*
            //
            bool isSenderInDomain = this.SecurityAgent.Domains.IsManaged(envelope.Sender);
            bool isOutgoing;

            if (isSenderInDomain)
            {
                isOutgoing = true;
                if (SMIMEStandard.IsEncrypted(envelope.Message))
                {
                    if (!m_settings.AllowInternalRelay)
                    {
                        throw new SmtpAgentException(SmtpAgentError.InternalRelayDisabled);
                    }
                    isOutgoing = false;
                }
            }
            else
            {
                isOutgoing = false;
            }

            if (isOutgoing)
            {
                envelope = this.ProcessOutgoing(message, envelope);
            }
            else
            {
                envelope = this.ProcessIncoming(message, envelope);
            }

            if (envelope == null)
            {
                throw new SmtpAgentException(SmtpAgentError.InvalidEnvelopeFromAgent);
            }

            return(envelope);
        }
Example #2
0
        public void TestWithMessageObjects()
        {
            var message = MimeSerializer.Default.Deserialize <Message>(m_tester.ReadMessageText("simple.eml"));

            var outgoing = new OutgoingMessage(message);

            outgoing = m_tester.AgentA.ProcessOutgoing(outgoing);

            Assert.True(outgoing.Message.HasHeader(MailStandard.Headers.Date));

            Assert.True(SMIMEStandard.IsEncrypted(outgoing.Message));
            VerifyTrusted(outgoing.Recipients, m_tester.AgentA.MinTrustRequirement);
            Assert.True(outgoing.RejectedRecipients.Count == 0);

            var incoming = new IncomingMessage(outgoing.Message);

            incoming = m_tester.AgentB.ProcessIncoming(incoming);

            Assert.False(SMIMEStandard.IsEncrypted(incoming.Message));
            Assert.False(WrappedMessage.IsWrapped(incoming.Message));

            VerifyTrusted(incoming.Recipients, m_tester.AgentB.MinTrustRequirement);
            Assert.True(outgoing.RejectedRecipients.Count == 0);
        }