Example #1
0
        internal string SummarizeEnvelopeHeaders(ISmtpMessage message)
        {
            string mailFrom = message.GetMailFrom();
            string rcptTo   = message.GetRcptTo();

            return(string.Format("MAILFROM={0};RCPTTO={1}", mailFrom, rcptTo));
        }
Example #2
0
 internal void LogEnvelopeHeaders(ISmtpMessage message)
 {
     if (Logger.IsDebugEnabled && message.HasEnvelope)
     {
         Logger.Debug(this.SummarizeEnvelopeHeaders(message));
     }
 }
Example #3
0
 void Route(ISmtpMessage message, IEnumerable <Route> matchedRoutes)
 {
     foreach (Route route in matchedRoutes)
     {
         this.Route(message, route);
     }
 }
Example #4
0
 protected virtual void CopyMessage(ISmtpMessage message, MessageProcessingSettings settings)
 {
     if (settings.HasCopyFolder)
     {
         this.CopyMessage(message, settings.CopyFolder);
     }
 }
Example #5
0
        protected virtual MessageEnvelope ProcessIncoming(ISmtpMessage message, MessageEnvelope envelope)
        {
            envelope = this.SecurityAgent.ProcessIncoming(envelope);
            Logger.Debug("ProcessedIncoming");

            return(envelope);
        }
Example #6
0
        bool IsReceiver(ISmtpMessage smtpMessage, ref ISmtpOnArrival receiver)
        {
            bool fReceive = false;

            // Get the one and only receiver
            //BCLDebug.Assert(m_receiverGuid != Guid.Empty, "m_receiverGuid != Guid.Empty");
            receiver = (ISmtpOnArrival)s_receiverTable[m_mailboxName];
            if (null == receiver)
            {
                throw new Exception(CoreChannel.GetResourceString("Remoting_NoReceiverRegistered"));
            }

            if (receiver == this)
            {
                String mailbox = smtpMessage.To;

                // Only process those messages which are addressed to us
                InternalRemotingServices.RemotingTrace("mailbox " + m_mailboxName + " receiver " + mailbox);
                if ((null != m_mailboxName) &&
                    (-1 != CultureInfo.CurrentCulture.CompareInfo.IndexOf(mailbox, m_mailboxName, CompareOptions.IgnoreCase)))
                {
                    InternalRemotingServices.RemotingTrace("Mailboxes match");
                    fReceive = true;
                }
                else
                {
                    // We don't do anything with messages not addressed to us
                    receiver = null;
                }
            }

            return(fReceive);
        }
Example #7
0
        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);
        }
Example #8
0
        void PostProcessIncoming(ISmtpMessage message, IncomingMessage envelope)
        {
            this.CopyMessage(message, m_settings.Incoming);

            if (envelope.HasDomainRecipients)
            {
                var routedRecipients = new DirectAddressCollection();
                var messageRoute     = m_router.Clone();
                messageRoute.Route(message, envelope, routedRecipients);

                SendNotifications(envelope, routedRecipients);
                SendDeliveryStatus(messageRoute, envelope, routedRecipients);
            }
            //
            // Any recipients that were handled by routes are no longer in the DomainRecipients collection (removed)
            // Smtp Server should continue process any domain recipients whose delivery were NOT handled by routes
            //
            if (m_settings.Incoming.EnableRelay && envelope.HasDomainRecipients)
            {
                this.SendNotifications(envelope, envelope.DomainRecipients);
                //
                // We only want the incoming message sent to trusted domain recipients
                // We are not allowing arbitrary relay
                //
                message.SetRcptTo(envelope.DomainRecipients);
                m_diagnostics.LogEnvelopeHeaders(message);
            }
            else
            {
                //
                // SMTP Server need not proceed with delivery because we already routed the message to all domain recipients
                //
                message.Abort();
            }
        }
Example #9
0
        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
            {
            }
        }
Example #10
0
        public MessageEnvelope ProcessIncoming(ISmtpMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            return(this.ProcessIncoming(message, message.GetEnvelope()));
        }
Example #11
0
        bool ThrowCopyConditional(ISmtpMessage message, string destinationFolder)
        {
            if (string.IsNullOrEmpty(destinationFolder))
            {
                throw new DirectoryNotFoundException(destinationFolder);
            }

            this.UpdateRouteCount(destinationFolder);
            return(true);
        }
Example #12
0
        void ProcessRequest(ISmtpMessage smtpMessage, Smtp.Fields headers,
                            Header[] msgHeaders, String contentType, String seqNum,
                            MemoryStream stm, ref bool fIsOneWay)
        {
            IMessage outMsg = null;

            fIsOneWay = false;

            // Deserialize - Stream to IMessage
            IMessage inMsg = CoreChannel.DeserializeMessage(contentType, stm, true, null, msgHeaders);

            InternalRemotingServices.RemotingTrace("Deserialized message");

            if (inMsg == null)
            {
                throw new Exception(CoreChannel.GetResourceString("Remoting_DeserializeMessage"));
            }

            // Set URI - BUGBUG: temp hack
            String url       = ((IMethodMessage)inMsg).Uri;
            String objectURL = null;

            try
            {
                Parse(url, out objectURL);
            }
            catch (Exception)
            {
                objectURL = url;
            }
            inMsg.Properties["__Uri"] = objectURL;

            // Dispatch Call
            InternalRemotingServices.RemotingTrace("ChannelServices.SyncDispatchMessage - before");
            outMsg = ChannelServices.SyncDispatchMessage(inMsg);
            InternalRemotingServices.RemotingTrace("ChannelServices.SyncDispatchMessage - after");

            // We do not send a reply for one way messages. If the message
            // is not one way and we have a null return message then we
            // throw an exception
            if (null == outMsg)
            {
                MethodBase method = ((IMethodMessage)inMsg).MethodBase;
                fIsOneWay = RemotingServices.IsOneWay(method);
                if (!fIsOneWay)
                {
                    throw new Exception(CoreChannel.GetResourceString("Remoting_DispatchMessage"));
                }
            }
            else
            {
                ReplyMessage(outMsg, smtpMessage, seqNum, headers);
                InternalRemotingServices.RemotingTrace("Reply sent");
            }
        }
Example #13
0
 private void ProcessException(ISmtpMessage smtpMessage, Smtp.Fields headers,
                               String contentType, String seqNum)
 {
     try
     {
     }
     catch (Exception)
     {
         // Fatal error .. ignore
     }
 }
Example #14
0
        // Generate headers for reply message
        void PutHeaders(MailMessage mail, ISmtpMessage inMessage,
                        IMethodMessage replyMsg, String seqNum, int msgLength)
        {
            String sender   = inMessage.To;
            String receiver = inMessage.From;
            String action   = SoapServices.GetSoapActionFromMethodBase(replyMsg.MethodBase);
            String uri      = replyMsg.Uri;

            PutHeaders(mail, sender, receiver, s_defaultReceiverSubject,
                       action, uri, seqNum, msgLength);
        }
Example #15
0
        protected virtual void UpdateMessageText(ISmtpMessage message, MessageEnvelope envelope)
        {
            string messageText = envelope.SerializeMessage();

            if (string.IsNullOrEmpty(messageText))
            {
                throw new SmtpAgentException(SmtpAgentError.EmptyResultFromAgent);
            }

            message.Update(messageText);
        }
Example #16
0
 protected virtual void CopyMessage(ISmtpMessage message, string folderPath)
 {
     try
     {
         string uniqueFileName = Extensions.CreateUniqueFileName();
         message.SaveToFile(Path.Combine(folderPath, uniqueFileName));
     }
     catch (Exception ex)
     {
         Logger.Error("While copying message {0}", ex.ToString());
         Logger.Debug(ex);
     }
 }
Example #17
0
 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());
     }
 }
Example #18
0
        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);
            }
        }
Example #19
0
        bool CopyToFolder(ISmtpMessage message, string folderPath)
        {
            try
            {
                string uniqueFileName = Extensions.CreateUniqueFileName();
                message.SaveToFile(Path.Combine(folderPath, uniqueFileName));
                return(true);
            }
            catch
            {
            }

            return(false);
        }
Example #20
0
        void ProcessResponse(ISmtpMessage smtpMessage, String contentType,
                             String seqNum, MemoryStream stm)
        {
            InternalRemotingServices.RemotingTrace("Received response");

            // Notify the waiting object that its response
            // has arrived
            WaitObject obj = (WaitObject)m_hashTable[seqNum];

            if (null != obj)
            {
                InternalRemotingServices.RemotingTrace("Found an object waiting");

                // First remove the object in a threadsafe manner
                // so that we do not deliver the response twice
                // due to duplicate replies or other errors from
                // Smtp

                lock (obj)
                {
                    if (m_hashTable.Contains(seqNum))
                    {
                        InternalRemotingServices.RemotingTrace("Found an object to notify");
                        m_hashTable.Remove(seqNum);

                        IMethodCallMessage request = (IMethodCallMessage)obj.Request;
                        Header[]           h       = new Header[3];
                        h[0] = new Header("__TypeName", request.TypeName);
                        h[1] = new Header("__MethodName", request.MethodName);
                        h[2] = new Header("__MethodSignature", request.MethodSignature);

                        IMessage response = CoreChannel.DeserializeMessage(contentType, stm, false, request, h);
                        InternalRemotingServices.RemotingTrace("Deserialized message");

                        if (response == null)
                        {
                            throw new Exception(CoreChannel.GetResourceString("Remoting_DeserializeMessage"));
                        }

                        // Notify the object
                        obj.Notify(response);
                    }
                }
            }
            else
            {
                InternalRemotingServices.RemotingTrace("No object waiting");
            }
        }
Example #21
0
 void Route(ISmtpMessage message, Route route)
 {
     try
     {
         if (!route.Process(message))
         {
             route.FailedDelivery = true;
             m_diagnostics.Logger.Error("Routing Error {0}", route.AddressType);
         }
     }
     catch (Exception ex)
     {
         m_diagnostics.Logger.Error("Routing Error {0}, {1}", route.AddressType, ex);
     }
 }
Example #22
0
 /// <summary>
 /// For incoming messages, we only route to DomainRecipients
 /// </summary>
 /// <param name="message">message</param>
 /// <param name="envelope">message envelope</param>
 /// <param name="routedRecipients">(Optional) - if not null, returns a list of recipients who matched routes</param>
 public void Route(ISmtpMessage message, IncomingMessage envelope, DirectAddressCollection routedRecipients)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (envelope == null)
     {
         throw new ArgumentNullException("envelope");
     }
     if (envelope.HasDomainRecipients)
     {
         this.Route(message, envelope.DomainRecipients, routedRecipients);
     }
 }
Example #23
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 #24
0
        protected virtual void RejectMessage(ISmtpMessage message, bool?incoming)
        {
            try
            {
                message.Reject();

                Auditor?.ForEach(a => a.Log(AuditNames.Message.GetRejectedMessage(incoming), a.BuildAuditLogMessage.Build(message)));

                Logger.Debug("Rejected Message");

                this.CopyMessage(message, m_settings.BadMessage);
            }
            catch
            {
            }
        }
Example #25
0
        protected virtual void RejectMessage(ISmtpMessage message, bool?isIncoming)
        {
            try
            {
                message.Reject();

                m_auditor.Log(AuditNames.Message.GetRejectedMessage(isIncoming), this.BuildAuditLogString(message));

                Logger.Debug("Rejected Message");

                this.CopyMessage(message, m_settings.BadMessage);
            }
            catch
            {
            }
        }
Example #26
0
        /// <summary>
        /// Outgoing messages are routed based off envelope.Recipients
        /// </summary>
        public void Route(ISmtpMessage message, OutgoingMessage envelope)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (envelope == null)
            {
                throw new ArgumentNullException("envelope");
            }

            if (envelope.HasRecipients)
            {
                this.Route(message, envelope.Recipients, null);
            }
        }
Example #27
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);
        }
Example #28
0
        // Generates a reply to an incoming Smtp message and sends it
        void ReplyMessage(IMessage replyMsg, ISmtpMessage smtpInMsg,
                          String seqNum, Smtp.Fields headers)
        {
            MemoryStream stm = (MemoryStream)CoreChannel.SerializeMessage(m_mimeType, replyMsg);

            // reset stream to beginning
            stm.Position = 0;
            byte[] byteMessage       = stm.ToArray();
            int    byteMessageLength = byteMessage.Length;
            String reply             = System.Text.Encoding.ASCII.GetString(byteMessage, 0, byteMessage.Length);

            // Create a reply message
            MailMessage smtpOutMsg = new MailMessage();

            // Fill in the headers
            PutHeaders(smtpOutMsg, smtpInMsg, (IMethodMessage)replyMsg, seqNum, reply.Length);

            // Set the body
            smtpOutMsg.Body = reply;

            // Send the message
            SmtpMail.Send(smtpOutMsg);
        }
Example #29
0
        void PostProcessOutgoing(ISmtpMessage message, OutgoingMessage envelope)
        {
            MonitorMdn(envelope);

            SendDeliveryStatus(envelope);

            this.RelayInternal(message, envelope); //Removes recipients in local domains

            if (envelope.HasRecipients)
            {
                this.CopyMessage(message, m_settings.Outgoing);
            }

            if (m_settings.Outgoing.EnableRelay && envelope.HasRecipients)
            {
                message.SetRcptTo(envelope.Recipients);
                m_diagnostics.LogEnvelopeHeaders(message);
            }
            else
            {
                message.Abort();
            }
        }
Example #30
0
        // 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);
        }
Example #31
0
 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());
     }
 }
Example #32
0
 protected virtual void PreProcessMessage(ISmtpMessage message)
 {
     m_diagnostics.LogEnvelopeHeaders(message);
     
     this.CopyMessage(message, m_settings.RawMessage);
 }
Example #33
0
        void PostProcessOutgoing(ISmtpMessage message, OutgoingMessage envelope)
        {
            MonitorMdn(envelope);

            SendDeliveryStatus(envelope);

            this.RelayInternal(message, envelope); //Removes recipients in local domains
            
            if (envelope.HasRecipients)
            {            
                this.CopyMessage(message, m_settings.Outgoing);
            }
            
            if (m_settings.Outgoing.EnableRelay && envelope.HasRecipients)
            {
                message.SetRcptTo(envelope.Recipients);
                m_diagnostics.LogEnvelopeHeaders(message);
            }
            else
            {
                message.Abort();
            }
        }
Example #34
0
 protected virtual void UpdateMessageText(ISmtpMessage message, MessageEnvelope envelope)
 {
     string messageText = envelope.SerializeMessage();            
     if (string.IsNullOrEmpty(messageText))
     {
         throw new SmtpAgentException(SmtpAgentError.EmptyResultFromAgent);
     }
     
     message.Update(messageText);
 }
Example #35
0
        protected virtual void AcceptMessage(ISmtpMessage message, bool incoming)
        {
            message.Accept();

            Auditor.ForEach(a => a.Log(AuditNames.Message.GetAcceptedMessage(incoming), a.BuildAuditLogMessage.Build(message)));
        }
Example #36
0
 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);
     }
 }
Example #37
0
 public MessageEnvelope ProcessIncoming(ISmtpMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     
     return this.ProcessIncoming(message, message.GetEnvelope());
 }
Example #38
0
 bool CopyToFolder(ISmtpMessage message, string folderPath)
 {
     try
     {
         string uniqueFileName = Extensions.CreateUniqueFileName();
         message.SaveToFile(Path.Combine(folderPath, uniqueFileName));
         return true;
     }
     catch
     {
     }
     
     return false;
 }
Example #39
0
        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;
        }
Example #40
0
        public void ProcessMessage(ISmtpMessage message)
        {
            bool? isIncoming = null;
            MessageEnvelope envelope = null;
            try
            {
                this.VerifyInitialized();
                //
                // Preprocessing may involve housekeeping like logging message arrival
                //
                this.PreProcessMessage(message);
                //
                // Let the agent do its thing
                //   
                envelope = message.GetEnvelope();
                envelope = this.ProcessEnvelope(message, envelope);
                if (envelope == null)
                {
                    throw new SmtpAgentException(SmtpAgentError.InvalidEnvelopeFromAgent);
                }
                isIncoming = envelope is IncomingMessage;
                //
                // Capture envelope sender/receiver in the message
                //
                this.UpdateXHeaders(envelope);
                //
                // Replace the contents of the original message with what the agent gave us
                //
                this.UpdateMessageText(message, envelope);
                //
                // We did well...
                //
                this.AcceptMessage(message, isIncoming.Value);
                //
                // We may want want to update logs and do some final post processing
                //
                this.PostProcessMessage(message, envelope);
            }
            catch (FaultException<ConfigStoreFault> ex)
            {
                //
                // Absorb Mdn type errors
                //
                if(IsMdnFault(ex))
                {
                    Logger.Info("Ignored MDN: {0}", ex.ToString());
                }
                else
                {
                    this.RejectMessage(message, isIncoming);
                    Logger.Error("While processing message {0}", ex.ToString());
                    throw;
                }
            }
            catch (Exception ex)
            {
                HandleMessageRejection(message, envelope, isIncoming, ex);

                throw;
            }
        }
Example #41
0
        protected virtual void RejectMessage(ISmtpMessage message, bool? incoming)
        {
            try
            {
                message.Reject();

                Auditor.ForEach(a => a.Log(AuditNames.Message.GetRejectedMessage(incoming), a.BuildAuditLogMessage.Build(message)));
                
                Logger.Debug("Rejected Message");
                
                this.CopyMessage(message, m_settings.BadMessage);
            }
            catch
            {
            }
        }
Example #42
0
        protected virtual void RejectMessage(ISmtpMessage message, bool? isIncoming)
        {
            try
            {
                message.Reject();

                m_auditor.Log(AuditNames.Message.GetRejectedMessage(isIncoming), this.BuildAuditLogString(message));
                
                Logger.Debug("Rejected Message");
                
                this.CopyMessage(message, m_settings.BadMessage);
            }
            catch
            {
            }
        }
Example #43
0
 protected virtual void CopyMessage(ISmtpMessage message, string folderPath)
 {
     try
     {
         string uniqueFileName = Extensions.CreateUniqueFileName();
         message.SaveToFile(Path.Combine(folderPath, uniqueFileName));
     }
     catch (Exception ex)
     {
         Logger.Error("While copying message {0}", ex.ToString());
         Logger.Debug(ex);
     }
 }
Example #44
0
 internal void LogEnvelopeHeaders(ISmtpMessage message)
 {       
     if (Logger.IsDebugEnabled && message.HasEnvelope)
     {     
         Logger.Debug(this.SummarizeEnvelopeHeaders(message));
     }
 }
Example #45
0
 internal string SummarizeEnvelopeHeaders(ISmtpMessage message)
 {
     string mailFrom = message.GetMailFrom();
     string rcptTo = message.GetRcptTo();
     return string.Format("MAILFROM={0};RCPTTO={1}", mailFrom, rcptTo);
 }
Example #46
0
 protected virtual void CopyMessage(ISmtpMessage message, MessageProcessingSettings settings)
 {
     if (settings.HasCopyFolder)
     {
         this.CopyMessage(message, settings.CopyFolder);
     }                
 }
Example #47
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 #48
0
 // 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);
 }
Example #49
0
        void PostProcessIncoming(ISmtpMessage message, IncomingMessage envelope)
        {
            this.CopyMessage(message, m_settings.Incoming);
            
            if (envelope.HasDomainRecipients)
            {
                DirectAddressCollection routedRecipients = new DirectAddressCollection();                
                m_router.Route(message, envelope, routedRecipients); 
                
                this.SendNotifications(envelope, routedRecipients);

                SendDeliveryStatus(m_router, envelope, routedRecipients);
            }
            //
            // Any recipients that were handled by routes are no longer in the DomainRecipients collection (removed)
            // Smtp Server should continue process any domain recipients whose delivery were NOT handled by routes
            //
            if (m_settings.Incoming.EnableRelay && envelope.HasDomainRecipients)
            {
                this.SendNotifications(envelope, envelope.DomainRecipients);
                //
                // We only want the incoming message sent to trusted domain recipients
                // We are not allowing arbitrary relay
                //
                message.SetRcptTo(envelope.DomainRecipients);
                m_diagnostics.LogEnvelopeHeaders(message);
            }
            else
            {
                //
                // SMTP Server need not proceed with delivery because we already routed the message to all domain recipients
                //
                message.Abort();
            }
        }
Example #50
0
        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
            {
            }
        }
Example #51
0
        protected virtual void AcceptMessage(ISmtpMessage message, bool incoming)
        {
            message.Accept();

            m_auditor.Log(AuditNames.Message.GetAcceptedMessage(incoming), this.BuildAuditLogString(message));
        }
Example #52
0
 /// <summary>
 /// Convert <see cref="ISmtpMessage"/> into a audit string.
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public string Build(ISmtpMessage message)
 {
     return string.Format("MAILFROM={0};RCPTTO={1}", message.GetMailFrom(), message.GetRcptTo());
 }
Example #53
0
 public abstract bool Process(ISmtpMessage message);
Example #54
0
        protected virtual MessageEnvelope ProcessIncoming(ISmtpMessage message, MessageEnvelope envelope)
        {            
            envelope = this.SecurityAgent.ProcessIncoming(envelope);
            Logger.Debug("ProcessedIncoming");

            return envelope;
        }
Example #55
0
 static bool ThrowCopy(ISmtpMessage message, string destinationFolder)
 {
     throw new DirectoryNotFoundException(destinationFolder);
 }
Example #56
0
 public override bool Process(ISmtpMessage message)
 {
     return m_loadBalancer.Process(message);
 }