Esempio n. 1
0
        private EventsFileHandler()
        {
            // EventsFileHandler needs to be stopped when MantaMTA is stopping.
            MantaCoreEvents.RegisterStopRequiredInstance(this);

            // Make sure the drop folders exist.
            Directory.CreateDirectory(MtaParameters.BounceDropFolder);
            Directory.CreateDirectory(Path.Combine(MtaParameters.BounceDropFolder, _SubdirectoryForProblemEmails));
            Directory.CreateDirectory(MtaParameters.FeedbackLoopDropFolder);
            Directory.CreateDirectory(Path.Combine(MtaParameters.FeedbackLoopDropFolder, _SubdirectoryForProblemEmails));

            // Setup and start the bounce email file watcher.
            FileSystemWatcher bounceWatcher = new FileSystemWatcher(MtaParameters.BounceDropFolder, "*.eml");

            bounceWatcher.Created            += DoBounceFileProcessing;
            bounceWatcher.EnableRaisingEvents = true;

            // Setup and start the feedback loop email file watcher.
            FileSystemWatcher abuseWatcher = new FileSystemWatcher(MtaParameters.FeedbackLoopDropFolder, "*.eml");

            abuseWatcher.Created            += DoAbuseFileProcessing;
            abuseWatcher.EnableRaisingEvents = true;

            Thread t = new Thread(new ThreadStart(delegate()
            {
                DoBounceFileProcessing(bounceWatcher, new FileSystemEventArgs(WatcherChangeTypes.All, MtaParameters.BounceDropFolder, string.Empty));
                DoAbuseFileProcessing(abuseWatcher, new FileSystemEventArgs(WatcherChangeTypes.All, MtaParameters.FeedbackLoopDropFolder, string.Empty));
            }));

            t.Start();
        }
Esempio n. 2
0
        /// <summary>
        /// Call this method to start the EventHttpForwarder.
        /// </summary>
        public void Start()
        {
            MantaCoreEvents.RegisterStopRequiredInstance(this);
            Thread t = new Thread(new ThreadStart(ForwardEvents));

            t.IsBackground = true;
            t.Start();
        }
Esempio n. 3
0
 /// <summary>
 /// Start the bulk importer.
 /// </summary>
 public void Start()
 {
     _bulkInsertThread = new Thread(new ThreadStart(DoSqlBulkInsertFromRabbitMQ));
     _bulkInsertThread.IsBackground = true;
     _bulkInsertThread.Priority     = ThreadPriority.AboveNormal;
     _bulkInsertThread.Start();
     MantaCoreEvents.RegisterStopRequiredInstance(this);
 }
Esempio n. 4
0
        /// <summary>
        /// Does the actual forwarding of the events.
        /// </summary>
        private void ForwardEvents()
        {
            _IsRunning = true;

            try
            {
                // Keep looping as long as the MTA is running.
                while (!_IsStopping)
                {
                    IList <MantaEvent> events = null;
                    // Get events for forwarding.
                    try
                    {
                        events = EventDB.GetEventsForForwarding(10);
                    }
                    catch (SqlNullValueException)
                    {
                        events = new List <MantaEvent>();
                    }


                    if (events.Count == 0)
                    {
                        // No events to forward sleep for a second and look again.
                        Thread.Sleep(1000);
                        continue;
                    }
                    else
                    {
                        // Found events to forward, create and run Tasks to forward.
                        for (var i = 0; i < events.Count; i++)
                        {
                            ForwardEventAsync(events[i]).Wait();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Something went wrong.
                Logging.Error("EventHttpForwarder encountered an error.", ex);
                MantaCoreEvents.InvokeMantaCoreStopping();
                Environment.Exit(-1);
            }

            _IsRunning = false;
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the MxPatternID that matches the MX Record, Outbound IP Address combo.
        /// </summary>
        /// <param name="record"></param>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        private static int GetMxPatternID(MXRecord record, VirtualMTA ipAddress)
        {
            if (_matchedPatterns == null)
            {
                _matchedPatterns = new ConcurrentDictionary <string, MatchedMxPatternCollection>();
            }

            MatchedMxPatternCollection matchedPatterns = null;

            if (!_matchedPatterns.TryGetValue(record.Host, out matchedPatterns))
            {
                matchedPatterns = new MatchedMxPatternCollection();
                _matchedPatterns.AddOrUpdate(record.Host, matchedPatterns, (string s, MatchedMxPatternCollection p) => matchedPatterns);
            }

            MatchedMxPattern matchedPattern = matchedPatterns.GetMatchedMxPattern(ipAddress);

            if (matchedPattern != null &&
                matchedPattern.MatchedUtc.AddMinutes(MtaParameters.MTA_CACHE_MINUTES) > DateTime.UtcNow)
            {
                // Found a valid cached pattern ID so return it.
                return(matchedPattern.MxPatternID);
            }

            // Loop through all of the patterns
            for (int i = 0; i < _MXPatterns.Count; i++)
            {
                // The current pattern we're working with.
                OutboundMxPattern pattern = _MXPatterns[i];

                // If the pattern applies only to a specified IP address then
                // only check for a match if getting rules for that IP.
                if (pattern.LimitedToOutboundIpAddressID.HasValue &&
                    pattern.LimitedToOutboundIpAddressID.Value != ipAddress.ID)
                {
                    continue;
                }

                if (pattern.Type == OutboundMxPatternType.CommaDelimited)
                {
                    // Pattern is a comma delimited list, so split the values
                    string[] strings = pattern.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    // Loop though the values in the split string array.
                    for (int c = 0; c < strings.Length; c++)
                    {
                        try
                        {
                            // If they are a match return the rules.
                            if (strings[c].Equals(record.Host, StringComparison.OrdinalIgnoreCase))
                            {
                                if (pattern.LimitedToOutboundIpAddressID.HasValue)
                                {
                                    matchedPatterns.Add(pattern.ID, ipAddress);
                                }
                                else
                                {
                                    matchedPatterns.Add(pattern.ID, null);
                                }

                                return(pattern.ID);
                            }
                        }
                        catch (Exception) { }
                    }

                    continue;
                }
                else if (pattern.Type == OutboundMxPatternType.Regex)
                {
                    // Pattern is Regex so just need to do an IsMatch
                    if (Regex.IsMatch(record.Host, pattern.Value, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture))
                    {
                        // Found pattern match.
                        if (pattern.LimitedToOutboundIpAddressID.HasValue)
                        {
                            matchedPatterns.Add(pattern.ID, ipAddress);
                        }
                        else
                        {
                            matchedPatterns.Add(pattern.ID, null);
                        }

                        return(pattern.ID);
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    // Don't know what to do with this pattern so move on to the next.
                    Logging.Error("Unknown OutboundMxPatternType : " + pattern.Type.ToString());
                    continue;
                }
            }

            // Should have been found by default at least, but hasn't.
            Logging.Fatal("No MX Pattern Rules! Default Deleted?");
            MantaCoreEvents.InvokeMantaCoreStopping();
            Environment.Exit(0);
            return(-1);
        }
Esempio n. 6
0
 private MessageSender()
 {
     MantaCoreEvents.RegisterStopRequiredInstance(this);
 }
Esempio n. 7
0
 private QueueManager()
 {
     MantaCoreEvents.RegisterStopRequiredInstance(this);
 }