Exemple #1
0
        public new void SetUp()
        {
            CustomAsserts.AssertSpamAssassinIsRunning();

            // Enable spam assassin
            application = SingletonProvider <TestSetup> .Instance.GetApp();

            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;

            account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Disallow incorrect line endings.
            antiSpam.SpamMarkThreshold   = 1;
            antiSpam.SpamDeleteThreshold = 10000;
            antiSpam.AddHeaderReason     = true;
            antiSpam.AddHeaderSpam       = true;
            antiSpam.PrependSubject      = true;
            antiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SpamAssassin
            antiSpam.SpamAssassinEnabled    = true;
            antiSpam.SpamAssassinHost       = "localhost";
            antiSpam.SpamAssassinPort       = 783;
            antiSpam.SpamAssassinMergeScore = false;
            antiSpam.SpamAssassinScore      = 5;
        }
Exemple #2
0
        public void TestSpamMultipleHits()
        {
            CustomAsserts.AssertSpamAssassinIsRunning();

            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "mult'*****@*****.**", "test");

            _settings.AntiSpam.SpamMarkThreshold   = 1;
            _settings.AntiSpam.SpamDeleteThreshold = 2;

            _settings.AntiSpam.AddHeaderReason    = true;
            _settings.AntiSpam.AddHeaderSpam      = true;
            _settings.AntiSpam.PrependSubject     = true;
            _settings.AntiSpam.PrependSubjectText = "ThisIsSpam";

            // Enable SpamAssassin
            _settings.AntiSpam.SpamAssassinEnabled    = true;
            _settings.AntiSpam.SpamAssassinHost       = "localhost";
            _settings.AntiSpam.SpamAssassinPort       = 783;
            _settings.AntiSpam.SpamAssassinMergeScore = false;
            _settings.AntiSpam.SpamAssassinScore      = 5;


            // Enable SURBL.
            SURBLServer oSURBLServer = _settings.AntiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account, containing both incorrect MX records an SURBL-hits.
            // We should only detect one of these two:
            var smtpClientSimulator = new SmtpClientSimulator();

            _settings.Logging.LogSMTP  = true;
            _settings.Logging.LogDebug = true;
            _settings.Logging.Enabled  = true;
            _settings.Logging.EnableLiveLogging(true);

            // Access the log once to make sure it's cleared.
            string liveLog = _settings.Logging.LiveLog;

            // Should not be possible to send this email since it's results in a spam
            // score over the delete threshold.
            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "INBOX",
                                                                                          "This is a test message. It contains incorrect MX records and a SURBL string: http://surbl-org-permanent-test-point.com/ SpamAssassinString: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"));

            liveLog = _settings.Logging.LiveLog;

            _settings.Logging.EnableLiveLogging(false);

            int iFirst = liveLog.IndexOf("Spam test:");
            int iLast  = liveLog.LastIndexOf("Spam test:");

            Assert.AreNotEqual(-1, iFirst);

            // there should only be one spam test, since any spam match
            // should result in a spam score over the delete threshold.
            Assert.AreEqual(iFirst, iLast);
        }
Exemple #3
0
        public new void SetUp()
        {
            _threadedMessageCount = 0;

            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            antiSpam.SpamAssassinEnabled = true;
            antiSpam.SpamAssassinHost    = "127.0.0.1";
            antiSpam.SpamAssassinPort    = 783;

            CustomAsserts.AssertSpamAssassinIsRunning();

            _account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");
        }
Exemple #4
0
        public void TestSendViaSpamAssassin()
        {
            CustomAsserts.AssertSpamAssassinIsRunning();

            SingletonProvider <TestSetup> .Instance.GetApp().Settings.AntiSpam.SpamAssassinEnabled = true;

            string dataDir =
                Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com");

            string accountDir = Path.Combine(dataDir, "test");

            int memoryUsage    = Shared.GetCurrentMemoryUsage();
            int maxMemoryUsage = memoryUsage + 2;

            const int numberOfMessages = 100;

            var mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add("*****@*****.**");
            mail.Subject         = "Automatic server test";
            mail.Body            = "Automatic server test";
            mail.BodyEncoding    = Encoding.GetEncoding(1252);
            mail.SubjectEncoding = Encoding.GetEncoding(1252);

            for (int i = 1; i <= numberOfMessages; i++)
            {
                var oClient = new SmtpClient("localhost", 25);
                oClient.Send(mail);

                if (i % 5 == 0)
                {
                    Shared.AssertLowMemoryUsage(maxMemoryUsage);
                    TestTracer.WriteTraceInfo("{0}/{1}", i, numberOfMessages);
                }
            }

            WaitForFilesInFolder(accountDir, numberOfMessages);
            _domain.Delete();
        }
Exemple #5
0
        public void TestSpamProtectionNoTagging()
        {
            CustomAsserts.AssertSpamAssassinIsRunning();

            _application.Settings.AntiSpam.SpamMarkThreshold   = 5;
            _application.Settings.AntiSpam.SpamDeleteThreshold = 9999;
            _application.Settings.AntiSpam.MaximumMessageSize  = 1024 * 1024;
            _application.Settings.AntiSpam.AddHeaderReason     = false;
            _application.Settings.AntiSpam.AddHeaderSpam       = false;
            _application.Settings.AntiSpam.PrependSubject      = false;
            _application.Settings.AntiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SpamAssassin
            _application.Settings.AntiSpam.SpamAssassinEnabled    = true;
            _application.Settings.AntiSpam.SpamAssassinHost       = "localhost";
            _application.Settings.AntiSpam.SpamAssassinPort       = 783;
            _application.Settings.AntiSpam.SpamAssassinMergeScore = true;
            _application.Settings.AntiSpam.SpamAssassinScore      = 5;

            var messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

                Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.DaysToKeepMessages    = -1;
                fa.UseAntiSpam           = true;

                fa.Save();
                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                fa.Delete();

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);
            }
        }
Exemple #6
0
 public new void SetUp()
 {
     CustomAsserts.AssertSpamAssassinIsRunning();
 }