예제 #1
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[] { "*****@*****.**"});
                          
 }
예제 #2
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
        protected virtual void RejectMessage(ISmtpMessage message, MessageEnvelope envelope, bool? incoming)
        {
            try
            {
                message.Reject();

                Auditor.ForEach(a => a.Log(AuditNames.Message.GetRejectedMessage(incoming), a.BuildAuditLogMessage.Build(message)));
                
                Logger.Debug("Rejected Message");


                if (!incoming.GetValueOrDefault(false) && envelope.ShouldDeliverFailedStatus(m_settings.Notifications))
                {
                    var outgoingMessage = BuildFailedOutgoingMessage(envelope);
                    SendDeliveryStatus(outgoingMessage);
                }
                else
                {
                    this.CopyMessage(message, m_settings.BadMessage);
                }

            }
            catch
            {
            }
        }
예제 #3
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
 protected virtual void UpdateMessageText(ISmtpMessage message, MessageEnvelope envelope)
 {
     string messageText = envelope.SerializeMessage();            
     if (string.IsNullOrEmpty(messageText))
     {
         throw new SmtpAgentException(SmtpAgentError.EmptyResultFromAgent);
     }
     
     message.Update(messageText);
 }
예제 #4
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
 //---------------------------------------------------
 //
 //  Message Manipulation
 //
 //---------------------------------------------------
 protected virtual void UpdateXHeaders(MessageEnvelope envelope)
 {
     if (envelope is IncomingMessage && envelope.HasDomainRecipients)
     {
         Message message = envelope.Message;
         //
         // Inject the domain recipients & verified sender from the envelope into the message using an x-receiver + x-sender headers
         // These will be useful after the message is serialized and then deserialized for further processing
         //
         message.Headers.SetValue(XHeaders.Receivers, envelope.DomainRecipients.ToString());
         message.Headers.SetValue(XHeaders.Sender, envelope.Sender.ToString());
     }
 }
예제 #5
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
        protected virtual MessageEnvelope ProcessIncoming(ISmtpMessage message, MessageEnvelope envelope)
        {            
            envelope = this.SecurityAgent.ProcessIncoming(envelope);
            Logger.Debug("ProcessedIncoming");

            return envelope;
        }
예제 #6
0
 internal IncomingMessage(MessageEnvelope envelope)
     : base(envelope)
 {
 }
예제 #7
0
        public void TestUntrusted()
        {
            //
            // This should be accepted because the envelope is what we look at
            //
            MessageEnvelope envelope = new MessageEnvelope(BadMessage, 
                                                           DirectAddressCollection.ParseSmtpServerEnvelope("*****@*****.**"),
                                                           new DirectAddress("*****@*****.**")
                );
           
            Assert.DoesNotThrow(() => m_agent.SecurityAgent.ProcessOutgoing(envelope));

            envelope = new MessageEnvelope(string.Format(TestMessage, Guid.NewGuid()),
                                           DirectAddressCollection.ParseSmtpServerEnvelope("*****@*****.**"),
                                           new DirectAddress("*****@*****.**"));

            //
            // This SHOULD throw an exception
            //
            Assert.Throws<OutgoingAgentException>(() => m_agent.SecurityAgent.ProcessOutgoing(envelope));
        }
예제 #8
0
 /// <summary>
 /// Decrypts and verifies trust in a MessageEnvelope instance with signed and encrypted message content.
 /// </summary>
 /// <param name="envelope">
 /// A <see cref="MessageEnvelope"/> instance with signed and encrypted content for decryption and trust verification.
 /// </param>
 /// <returns>
 /// An <see cref="IncomingMessage"/> instance with the trust verified decrypted and verified message. 
 /// </returns>
 public IncomingMessage ProcessIncoming(MessageEnvelope envelope)
 {
     if (envelope == null)
     {
         throw new ArgumentNullException("envelope");
     }
     
     return this.ProcessIncoming(new IncomingMessage(envelope));
 }
예제 #9
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
        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;
        }
예제 #10
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
 private void HandleMessageRejection(ISmtpMessage message, MessageEnvelope envelope, bool? isIncoming, Exception ex)
 {
     if (envelope != null && ex is OutgoingAgentException 
         && ((OutgoingAgentException)ex).Error == AgentError.NoTrustedRecipients)
     {
         this.RejectMessage(message, envelope, isIncoming);
     }
     else
     {
         this.RejectMessage(message, isIncoming);
         Logger.Error("While processing message {0}", ex.ToString());
     }
 }
예제 #11
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;
        }
예제 #12
0
        internal void SummarizeHeaders(StringBuilder builder, MessageEnvelope envelope)
        {
            if (envelope.HasRecipients)
            {
                builder.Append("RECIPIENTS=").AppendLine(envelope.Recipients);
            }
            if (envelope.HasDomainRecipients)
            {
                builder.Append("DOMAIN RECIPIENTS=").AppendLine(envelope.DomainRecipients);
            }
            if (envelope.HasRejectedRecipients)
            {
                builder.Append("REJECTED RECIPIENTS=").AppendLine(envelope.RejectedRecipients);
                builder.Append("NO CERTS=").AppendLine(this.CollectNoCertInformation(envelope.RejectedRecipients));
            }
            if (envelope.HasOtherRecipients)
            {
                builder.Append("OTHER RECIPIENTS=").AppendLine(envelope.OtherRecipients);
            }

            IncomingMessage incoming = envelope as IncomingMessage;
            if (incoming != null)
            {
                CollectSignatures(builder, incoming); 
            }
        }
예제 #13
0
 internal string BuildVerboseErrorMessage(string message, MessageEnvelope envelope, Exception ex)
 {
     StringBuilder builder = new StringBuilder();
     builder.AppendLine(message);
     this.SummarizeHeaders(builder, envelope);
     builder.AppendLine(ex.ToString());
     return builder.ToString();
 }
예제 #14
0
 internal IncomingMessage(MessageEnvelope envelope)
     : base(envelope)
 {
 }
예제 #15
0
 /// <summary>
 /// Create a new OutgoingMessage envelope from the given message envelope
 /// </summary>
 /// <param name="envelope">source envelope</param>        
 public OutgoingMessage(MessageEnvelope envelope)
     : base(envelope)
 {
 }
예제 #16
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
 private OutgoingMessage BuildFailedOutgoingMessage(MessageEnvelope envelope)
 {
     return new OutgoingMessage(
         envelope.Message, 
         envelope.Recipients, //not used but required for validation
         envelope.Recipients, //All are rejected.
         envelope.Sender,
         envelope.ShouldDeliverFailedStatus(m_settings.Notifications));
 }
예제 #17
0
 internal MessageEnvelope(MessageEnvelope envelope)
 {
     m_agent = envelope.m_agent;
     this.RawMessage = envelope.RawMessage;
     m_message = envelope.m_message;
     if (envelope.m_recipients != null)
     {
         m_recipients = new DirectAddressCollection {envelope.m_recipients};
     }
     
     m_sender = envelope.m_sender;
     m_notifyTo = envelope.m_notifyTo;
 }
예제 #18
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
 protected virtual void PostProcessMessage(ISmtpMessage message, MessageEnvelope envelope)
 {
     OutgoingMessage outgoing = envelope as OutgoingMessage;
     if (outgoing != null)
     {
         this.PostProcessOutgoing(message, outgoing);
     }
     else
     {
         this.PostProcessIncoming(message, (IncomingMessage) envelope);
     }
 }
예제 #19
0
 /// <summary>
 /// Encrypts, verifies recipient trust, and signs a MessageEnvelope containing a message to prepare for send.
 /// </summary>
 /// <param name="envelope">
 /// A <see cref="MessageEnvelope"/> instance containing the message to prepare for send.
 /// </param>
 /// <returns>
 /// An <see cref="OutgoingMessage"/> instance containing the encrypted and trust verified message.
 /// </returns>
 public OutgoingMessage ProcessOutgoing(MessageEnvelope envelope)
 {
     if (envelope == null)
     {
         throw new ArgumentNullException("envelope");
     }
     
     OutgoingMessage message = new OutgoingMessage(envelope);
     return this.ProcessOutgoing(message);
 }
예제 #20
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
        protected virtual MessageEnvelope ProcessOutgoing(ISmtpMessage message, MessageEnvelope envelope)
        {
            OutgoingMessage outgoing = new OutgoingMessage(envelope);
            
            if (envelope.Message.IsMDN())
            {
                outgoing.IsMDN = true;
                outgoing.UseIncomingTrustAnchors = this.Settings.Notifications.UseIncomingTrustAnchorsToSend;
            }

            if (envelope.Message.IsDSN())
            {
                outgoing.IsDSN = true;
                outgoing.UseIncomingTrustAnchors = this.Settings.Notifications.UseIncomingTrustAnchorsToSend;
            }
            
            if (envelope.Message.IsTimelyAndReliable())
            {
                outgoing.IsTimelyAndReliable = true;
            }

            outgoing.UsingDeliveryStatus = outgoing.ShouldDeliverFailedStatus(Settings.Notifications);

            envelope = this.SecurityAgent.ProcessOutgoing(outgoing);
            Logger.Debug("ProcessedOutgoing"); 
            return envelope;
        }
예제 #21
0
파일: SmtpAgent.cs 프로젝트: DM-TOR/nhin-d
 // If the message contains trusted internal recipients, drop a copy in the pickup folder, so the message can sent back
 // through the incoming pipeline
 protected void RelayInternal(ISmtpMessage message, MessageEnvelope envelope)
 {
     InternalMessageSettings settings = m_settings.InternalMessage;
     if (!(settings.EnableRelay && settings.HasPickupFolder))
     {
         return;
     }
     if (!envelope.HasDomainRecipients)
     {
         // No internal recipients
         return;
     }
     //
     // We have some trusted domain recipients. Drop a copy of the message into the message pickup folder
     // It will get passed back through the message processing loop and treated as Incoming
     //
     this.CopyMessage(message, settings.PickupFolder);
     //
     // Since we've routed the message ourselves, ensure there is no double delivery by removing them from
     // the recipient list
     //
     envelope.Recipients.Remove(envelope.DomainRecipients);
 }
예제 #22
0
 /// <summary>
 /// Create a new OutgoingMessage envelope from the given message envelope
 /// </summary>
 /// <param name="envelope">source envelope</param>
 public OutgoingMessage(MessageEnvelope envelope)
     : base(envelope)
 {
 }