private void OnEndOfHeadersHandler(ReceiveMessageEventSource source, EndOfHeadersEventArgs e)
 {
     Logger.Debug("[GenericTransportAgent] SmtpReceiveAgent - OnEndOfHeaders fired...");
     foreach (var x in Configuration.Config.SmtpReceiveAgentConfig.OnEndOfHeaders)
     {
         try
         {
             x.Execute(new EmailItem(e.MailItem));
         }
         catch (Exception ex)
         {
             Logger.Error(ex, @"Error executing ""OnEndOfHeaders""");
         }
     }
 }
        /// <summary>
        /// This method is called if the sender address provided by the
        /// mail from command was null.
        ///
        /// Because at this point individual recipients cannot be rejected,
        /// if any recipient should be rejected, all recipients will be rejected.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="eodArgs">The arguments passed to the event.</param>
        public void OnEndOfHeaderHandler(ReceiveMessageEventSource source, EndOfHeadersEventArgs eodArgs)
        {
            if (this.testOnEndOfHeaders)
            {
                // Reset the flag.
                this.testOnEndOfHeaders = false;

                // Get the sender address from the message header.
                Header fromAddress = eodArgs.Headers.FindFirst(HeaderId.From);
                if (fromAddress != null)
                {
                    this.senderAddress = new RoutingAddress(fromAddress.Value);
                }
                else
                {
                    // No sender address, reject the message.
                    source.RejectMessage(DelayResponseMessage);
                    return;
                }

                // Determine whether any of the recipients should be rejected, and if so, reject them all.
                bool rejectAll = false;
                foreach (EnvelopeRecipient currentRecipient in eodArgs.MailItem.Recipients)
                {
                    if (!this.ShouldBypassFilter(this.senderAddress, currentRecipient.Address, this.server) &&
                        !this.VerifyTriplet(this.senderIP, this.senderAddress, currentRecipient.Address))
                    {
                        rejectAll = true;
                    }
                }

                if (rejectAll)
                {
                    source.RejectMessage(DelayResponseMessage);
                }
            }
        }
 void OnEndOfHeadersHandler(ReceiveMessageEventSource source, EndOfHeadersEventArgs e)
 {
     Logger.Debug("[GenericTransportAgent] SmtpReceiveAgent - OnEndOfHeaders fired...");
     _config.SmtpReceiveAgentConfig.OnEndOfHeaders.ToList().ForEach(x => { try { x.Execute(new EmailItem(e.MailItem)); } catch (Exception ex) { Logger.Error(ex, @"Error executing ""OnEndOfHeaders"""); } });
 }
Ejemplo n.º 4
0
        public void OnEndOfHeaderHandler(ReceiveMessageEventSource source, EndOfHeadersEventArgs eodArgs)
        {
            if (this.testOnEndOfHeaders)
            {
                RoutingAddress senderAddress;
                // Reset the flag.
                this.testOnEndOfHeaders = false;

                // Get the sender address from the message header.
                Header fromAddress = eodArgs.Headers.FindFirst(HeaderId.From);
                if (fromAddress != null)
                {
                    senderAddress = new RoutingAddress(fromAddress.Value);
                }
                else
                {
                    this.logLine("FROM=, TO=Multiple, REMOTE=" + eodArgs.SmtpSession.RemoteEndPoint.Address.ToString() + ", STATE=Greylist, REASON=No from address.", 2);                
                    // No sender address, reject the message.
                    source.RejectMessage(DelayResponseMessage);
                    return;
                }

                // Determine whether any of the recipients should be rejected, and if so, reject them all.
                bool rejectAll = false;
                foreach (EnvelopeRecipient currentRecipient in eodArgs.MailItem.Recipients)
                {
                    if (this.ShouldBypassFilter(senderAddress, currentRecipient.Address, eodArgs.SmtpSession.RemoteEndPoint.Address))
                    {
                        continue;
                    }
                    if (!this.VerifyTriplet(eodArgs.SmtpSession.RemoteEndPoint.Address, senderAddress, currentRecipient.Address))
                    {
                        this.logLine("FROM="+senderAddress.ToString()+", TO="+currentRecipient.Address.ToString()+", REMOTE=" + eodArgs.SmtpSession.RemoteEndPoint.Address.ToString() + ", STATE=Greylist, REASON=Triplet verify failed.", 2);  
                        rejectAll = true;
                    }
                }

                if (rejectAll)
                {
                    this.logLine("FROM=" + senderAddress.ToString() + ", TO=MANY, REMOTE=" + eodArgs.SmtpSession.RemoteEndPoint.Address.ToString() + ", STATE=Greylist, REASON=One or more recipients failed Triplet verification.", 2);                
                    source.RejectMessage(DelayResponseMessage);
                    return;
                }
                this.logLine("FROM=" + senderAddress.ToString() + ", TO=MANY, REMOTE=" + eodArgs.SmtpSession.RemoteEndPoint.Address.ToString() + ", STATE=Accept, REASON=Triplets Match.", 2);                
                    
            }
        }
Ejemplo n.º 5
0
        public void OnEndOfHeadersHandler(ReceiveMessageEventSource source, EndOfHeadersEventArgs args)
        {
            string        messageId       = String.Empty;
            string        rejectReason    = String.Empty;
            List <Header> headersToRemove = new List <Header>();

            // Compare the message's headers with the rules.
            foreach (Header header in args.Headers)
            {
                if (header.HeaderId == HeaderId.MessageId)
                {
                    messageId = header.Value;
                }

                foreach (XHeaderRule rule in XHeaderAgent.rules)
                {
                    if (String.Equals(rule.Name, header.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        switch (rule.Action)
                        {
                        case Action.Reject:
                            rejectReason = header.Name;
                            break;

                        case Action.Remove:
                            headersToRemove.Add(header);
                            break;
                        }
                    }
                }
            }

            // Begin preparing a debug message.
            StringBuilder builder = new StringBuilder();

            builder.Append("XHeaderAgent: Message-Id \"");
            builder.Append(messageId);
            builder.Append("\", ");

            // Take action.
            if (!String.IsNullOrEmpty(rejectReason))
            {
                builder.Append("Rejected");
                builder.Append("Contains forbidden X-header");
                builder.Append(rejectReason);

                source.RejectMessage(SmtpResponse.InvalidContent);
                source.Disconnect();
            }
            else if (0 != headersToRemove.Count)
            {
                builder.Append("Removed headers");
                foreach (Header header in headersToRemove)
                {
                    builder.Append(" ");
                    builder.Append(header.Name);
                    args.Headers.RemoveChild(header);
                }
            }
            else
            {
                builder.Append("No action");
            }

            // Write the debug message.
            Debug.WriteLine(builder.ToString());

            return;
        }
Ejemplo n.º 6
0
 void OnEndOfHeadersHandler(ReceiveMessageEventSource source, EndOfHeadersEventArgs e)
 {
     Logger.Debug("[GenericExchangeTransportagent] [SmtpReceiveAgent] OnEndOfHeaders fired...");
     _config.SmtpReceiveAgentConfig.OnEndOfHeaders.ToList().ForEach(x => { try { x.Execute(new EmailItem(e.MailItem)); } catch (Exception ex) { Logger.Error(ex, @"Error executing ""OnEndOfHeaders"""); } });
 }