Пример #1
0
        public new void SetUp()
        {
            Utilities.AssertSpamAssassinIsRunning();

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

            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;
            ;
            account = SingletonProvider <Utilities> .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;
        }
Пример #2
0
        private hMailServer.SURBLServers GetSurblServers()
        {
            hMailServer.AntiSpam     antiSpam     = APICreator.AntiSpamSettings;
            hMailServer.SURBLServers surblServers = antiSpam.SURBLServers;

            Marshal.ReleaseComObject(antiSpam);

            return(surblServers);
        }
Пример #3
0
        private hMailServer.WhiteListAddresses GetWhiteListAddresses()
        {
            hMailServer.AntiSpam           antiSpam  = APICreator.AntiSpamSettings;
            hMailServer.WhiteListAddresses addresses = antiSpam.WhiteListAddresses;

            Marshal.ReleaseComObject(antiSpam);

            return(addresses);
        }
Пример #4
0
        public void ItShouldBePossibleToTestSAConnectionUsingAPI()
        {
            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;

            string resultText;

            Assert.IsTrue(antiSpam.TestSpamAssassinConnection("localhost", 783, out resultText));
            Assert.IsTrue(resultText.Contains("Content analysis details:"));

            Assert.IsFalse(antiSpam.TestSpamAssassinConnection("localhost", 0, out resultText));
        }
Пример #5
0
        private hMailServer.DNSBlackLists GetDNSBlackLists()
        {
            hMailServer.Application   app           = APICreator.Application;
            hMailServer.Settings      settings      = app.Settings;
            hMailServer.AntiSpam      antiSpam      = settings.AntiSpam;
            hMailServer.DNSBlackLists dnsBlackLists = antiSpam.DNSBlackLists;

            Marshal.ReleaseComObject(settings);
            Marshal.ReleaseComObject(antiSpam);

            return(dnsBlackLists);
        }
Пример #6
0
        public new void SetUp()
        {
            _threadedMessageCount = 0;

            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            antiSpam.SpamAssassinEnabled = true;
            antiSpam.SpamAssassinHost    = "localhost";
            antiSpam.SpamAssassinHost    = "192.168.127.128";

            Utilities.AssertSpamAssassinIsRunning();
        }
Пример #7
0
        public void TestDKIMSpecificMessage()
        {
            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            string folderGood = Path.GetFullPath("../../../TestData/DKIM/Good");
            string path       = Path.Combine(Environment.CurrentDirectory, folderGood);

            string file = Path.Combine(path, "a.txt");

            DeleteCurrentLog();
            hMailServer.eDKIMResult result = antiSpam.DKIMVerify(file);
            Assert.AreEqual(hMailServer.eDKIMResult.eDKPass, result, file);
            Assert.IsTrue(VerifyLoadSuccess());
        }
Пример #8
0
        public new void SetUp()
        {
            _antiSpam = _settings.AntiSpam;

             // We should always mark messages as spam.
             _antiSpam.SpamDeleteThreshold = 5;
             _antiSpam.SpamMarkThreshold = 2;

             _antiSpam.AddHeaderReason = true;
             _antiSpam.AddHeaderSpam = true;
             _antiSpam.PrependSubject = true;
             _antiSpam.PrependSubjectText = "ThisIsSpam";

             SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
        }
Пример #9
0
        public new void SetUp()
        {
            _antiSpam = _settings.AntiSpam;

            // We should always mark messages as spam.
            _antiSpam.SpamDeleteThreshold = 5;
            _antiSpam.SpamMarkThreshold   = 2;

            _antiSpam.AddHeaderReason    = true;
            _antiSpam.AddHeaderSpam      = true;
            _antiSpam.PrependSubject     = true;
            _antiSpam.PrependSubjectText = "ThisIsSpam";

            SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");
        }
Пример #10
0
        public void TestDKIMMissingBH()
        {
            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            string folderMissingBH = Path.GetFullPath("../../../TestData/DKIM/Neutral - Missing bodyhash");
            string path            = Path.Combine(Environment.CurrentDirectory, folderMissingBH);

            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                hMailServer.eDKIMResult result = antiSpam.DKIMVerify(file);
                Assert.AreEqual(hMailServer.eDKIMResult.eDKNeutral, result, file);
            }
        }
Пример #11
0
        public void TestDKIMMassTest()
        {
            int verificationCount = 5000;

            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            string folderGood = Path.GetFullPath("../../../TestData/DKIM/Good");
            string goodFile   = Directory.GetFiles(folderGood)[0];

            for (int i = 0; i < verificationCount; i++)
            {
                DeleteCurrentLog();
                hMailServer.eDKIMResult result = antiSpam.DKIMVerify(goodFile);
                Assert.AreEqual(hMailServer.eDKIMResult.eDKPass, result, goodFile);
                Assert.IsTrue(VerifyLoadSuccess());
            }
        }
Пример #12
0
        public void TestDKIMUnsupported()
        {
            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            string folder = Path.GetFullPath("../../../TestData/DKIM/Unsupported");
            string path   = Path.Combine(TestContext.CurrentContext.TestDirectory, folder);

            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                DeleteCurrentLog();
                hMailServer.eDKIMResult result = antiSpam.DKIMVerify(file);
                Assert.AreEqual(hMailServer.eDKIMResult.eDKNeutral, result, file);
                Assert.IsFalse(VerifyLoadSuccess());
            }
        }
Пример #13
0
        public void TestDKIMBadSignature()
        {
            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            string folder = Path.GetFullPath("../../../TestData/DKIM/PermFail");
            string path   = Path.Combine(Environment.CurrentDirectory, folder);

            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                DeleteCurrentLog();
                hMailServer.eDKIMResult result = antiSpam.DKIMVerify(file);
                Assert.AreEqual(hMailServer.eDKIMResult.eDKPermFail, result, file);
                Assert.IsFalse(VerifyLoadSuccess());
            }
        }
Пример #14
0
        public void TestDKIMGood()
        {
            hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam;

            string folderGood = Path.GetFullPath("../../../TestData/DKIM/Good");
            string path       = Path.Combine(TestContext.CurrentContext.TestDirectory, folderGood);

            string[] files = Directory.GetFiles(folderGood);

            foreach (string file in files)
            {
                DeleteCurrentLog();
                Console.WriteLine(string.Format("Testing file {0}...", file));
                hMailServer.eDKIMResult result = antiSpam.DKIMVerify(file);
                Assert.AreEqual(hMailServer.eDKIMResult.eDKPass, result, file);
                Assert.IsTrue(VerifyLoadSuccess());
            }
        }
Пример #15
0
        public bool SaveData()
        {
            bool newObject = false;

            if (_representedObject == null)
            {
                hMailServer.Settings      settings      = APICreator.Application.Settings;
                hMailServer.AntiSpam      antiSpam      = settings.AntiSpam;
                hMailServer.DNSBlackLists dnsBlackLists = antiSpam.DNSBlackLists;

                _representedObject = dnsBlackLists.Add();
                newObject          = true;

                Marshal.ReleaseComObject(settings);
                Marshal.ReleaseComObject(antiSpam);
                Marshal.ReleaseComObject(dnsBlackLists);
            }

            _representedObject.Active = checkEnabled.Checked;

            _representedObject.DNSHost        = textDNSHost.Text;
            _representedObject.ExpectedResult = textExpectedResult.Text;
            _representedObject.RejectMessage  = textRejectionMessage.Text;
            _representedObject.Score          = textSpamScore.Number;

            _representedObject.Save();


            // Refresh the node in the tree if the name has changed.
            IMainForm mainForm = Instances.MainForm;

            mainForm.RefreshCurrentNode(_representedObject.DNSHost);

            // Set the object to clean.
            DirtyChecker.SetClean(this);

            if (newObject)
            {
                SearchNodeText crit = new SearchNodeText(_representedObject.DNSHost);
                mainForm.SelectNode(crit);
            }

            return(true);
        }
Пример #16
0
        public bool SaveData()
        {
            hMailServer.Settings settings         = APICreator.Application.Settings;
            hMailServer.AntiSpam antiSpamSettings = settings.AntiSpam;

            antiSpamSettings.GreyListingEnabled            = checkEnable.Checked;
            antiSpamSettings.GreyListingInitialDelay       = textGreyListingInitialDelay.Number;
            antiSpamSettings.GreyListingInitialDelete      = textGreyListingInitialDelete.Number * 24;
            antiSpamSettings.GreyListingFinalDelete        = textGreyListingFinalDelete.Number * 24;
            antiSpamSettings.BypassGreylistingOnMailFromMX = checkBypassGreyListingOnMailFromMX.Checked;
            antiSpamSettings.BypassGreylistingOnSPFSuccess = checkBypassGreylistingOnSPFSuccess.Checked;

            Marshal.ReleaseComObject(settings);
            Marshal.ReleaseComObject(antiSpamSettings);

            DirtyChecker.SetClean(this);

            return(true);
        }
Пример #17
0
        public void LoadData()
        {
            hMailServer.Settings settings         = APICreator.Application.Settings;
            hMailServer.AntiSpam antiSpamSettings = settings.AntiSpam;

            checkEnable.Checked = antiSpamSettings.GreyListingEnabled;
            textGreyListingInitialDelay.Number  = antiSpamSettings.GreyListingInitialDelay;
            textGreyListingInitialDelete.Number = antiSpamSettings.GreyListingInitialDelete / 24;
            textGreyListingFinalDelete.Number   = antiSpamSettings.GreyListingFinalDelete / 24;

            checkBypassGreylistingOnSPFSuccess.Checked = antiSpamSettings.BypassGreylistingOnSPFSuccess;
            checkBypassGreyListingOnMailFromMX.Checked = antiSpamSettings.BypassGreylistingOnMailFromMX;

            Marshal.ReleaseComObject(settings);
            Marshal.ReleaseComObject(antiSpamSettings);

            ListWhiteListAddresses();

            EnableDisable();
        }
Пример #18
0
        private void buttonAddWhiteAddress_Click(object sender, EventArgs e)
        {
            formWhiteListAddress whiteDlg = new formWhiteListAddress();

            if (whiteDlg.ShowDialog() == DialogResult.OK)
            {
                hMailServer.AntiSpam           antiSpam  = APICreator.AntiSpamSettings;
                hMailServer.WhiteListAddresses addresses = antiSpam.WhiteListAddresses;
                hMailServer.WhiteListAddress   address   = addresses.Add();

                whiteDlg.SaveProperties(address);

                address.Save();

                Marshal.ReleaseComObject(antiSpam);
                Marshal.ReleaseComObject(addresses);
                Marshal.ReleaseComObject(address);

                ListItems();
            }
        }
Пример #19
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            hMailServer.AntiSpam antiSpam = APICreator.AntiSpamSettings;

            string messageText = "";
            bool   testPass    = antiSpam.TestSpamAssassinConnection(textSpamAssassinHost.Text, textSpamAssassinPort.Number, out messageText);

            Marshal.ReleaseComObject(antiSpam);

            if (testPass)
            {
                string tempFile = Path.GetTempFileName();
                File.WriteAllText(tempFile, messageText);
                formMessageViewer viewer = new formMessageViewer(tempFile);
                viewer.ShowDialog();
                File.Delete(tempFile);
            }
            else
            {
                MessageBox.Show(messageText, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #20
0
        public bool SaveData()
        {
            hMailServer.Settings settings = APICreator.Application.Settings;
            hMailServer.AntiSpam antiSpam = settings.AntiSpam;

            antiSpam.SpamMarkThreshold   = textSpamMarkThreshold.Number;
            antiSpam.SpamDeleteThreshold = textSpamDeleteThreshold.Number;
            antiSpam.AddHeaderSpam       = checkAddHeaderSpam.Checked;
            antiSpam.AddHeaderReason     = checkAddHeaderReason.Checked;
            antiSpam.PrependSubject      = checkPrependSubject.Checked;
            antiSpam.PrependSubjectText  = textPrependSubjectText.Text;

            antiSpam.UseSPF               = chkUseSPF.Checked;
            antiSpam.UseSPFScore          = textUseSPFScore.Number;
            antiSpam.CheckHostInHelo      = chkCheckHostInHelo.Checked;
            antiSpam.CheckHostInHeloScore = textCheckHostInHeloScore.Number;
            antiSpam.CheckPTR             = chkCheckPTR.Checked;
            antiSpam.CheckPTRScore        = textCheckPTRScore.Number;
            antiSpam.UseMXChecks          = chkUseMXChecks.Checked;
            antiSpam.UseMXChecksScore     = textUseMXChecksScore.Number;

            antiSpam.SpamAssassinEnabled    = checkSpamAssassinEnabled.Checked;
            antiSpam.SpamAssassinHost       = textSpamAssassinHost.Text;
            antiSpam.SpamAssassinPort       = textSpamAssassinPort.Number;
            antiSpam.SpamAssassinMergeScore = checkSpamAssassinMergeScore.Checked;
            antiSpam.SpamAssassinScore      = textSpamAssassinScore.Number;

            antiSpam.DKIMVerificationEnabled      = checkDKIMVerificationEnabled.Checked;
            antiSpam.DKIMVerificationFailureScore = textDKIMVerificationFailureScore.Number;

            antiSpam.MaximumMessageSize = textMaximumMessageSize.Number;

            DirtyChecker.SetClean(this);

            Marshal.ReleaseComObject(settings);
            Marshal.ReleaseComObject(antiSpam);

            return(true);
        }
Пример #21
0
        public void LoadData()
        {
            hMailServer.Application app = APICreator.Application;

            hMailServer.Settings settings = app.Settings;
            hMailServer.AntiSpam antiSpam = settings.AntiSpam;

            textSpamMarkThreshold.Number   = antiSpam.SpamMarkThreshold;
            textSpamDeleteThreshold.Number = antiSpam.SpamDeleteThreshold;
            checkAddHeaderSpam.Checked     = antiSpam.AddHeaderSpam;
            checkAddHeaderReason.Checked   = antiSpam.AddHeaderReason;
            checkPrependSubject.Checked    = antiSpam.PrependSubject;
            textPrependSubjectText.Text    = antiSpam.PrependSubjectText;

            chkUseSPF.Checked               = antiSpam.UseSPF;
            textUseSPFScore.Number          = antiSpam.UseSPFScore;
            chkCheckHostInHelo.Checked      = antiSpam.CheckHostInHelo;
            textCheckHostInHeloScore.Number = antiSpam.CheckHostInHeloScore;
            chkCheckPTR.Checked             = antiSpam.CheckPTR;
            textCheckPTRScore.Number        = antiSpam.CheckPTRScore;
            chkUseMXChecks.Checked          = antiSpam.UseMXChecks;
            textUseMXChecksScore.Number     = antiSpam.UseMXChecksScore;

            checkSpamAssassinEnabled.Checked    = antiSpam.SpamAssassinEnabled;
            textSpamAssassinHost.Text           = antiSpam.SpamAssassinHost;
            textSpamAssassinPort.Number         = antiSpam.SpamAssassinPort;
            checkSpamAssassinMergeScore.Checked = antiSpam.SpamAssassinMergeScore;
            textSpamAssassinScore.Number        = antiSpam.SpamAssassinScore;

            textMaximumMessageSize.Number = antiSpam.MaximumMessageSize;

            checkDKIMVerificationEnabled.Checked    = antiSpam.DKIMVerificationEnabled;
            textDKIMVerificationFailureScore.Number = antiSpam.DKIMVerificationFailureScore;

            EnableDisable();

            Marshal.ReleaseComObject(settings);
            Marshal.ReleaseComObject(antiSpam);
        }
Пример #22
0
        private void buttonAddWhiteList_Click(object sender, EventArgs e)
        {
            formGreyListingWhiteAddress whiteDlg = new formGreyListingWhiteAddress();

            if (whiteDlg.ShowDialog() == DialogResult.OK)
            {
                hMailServer.Application app              = APICreator.Application;
                hMailServer.Settings    settings         = app.Settings;
                hMailServer.AntiSpam    antiSpamSettings = settings.AntiSpam;
                hMailServer.GreyListingWhiteAddresses greyListingWhiteAddresses = antiSpamSettings.GreyListingWhiteAddresses;
                hMailServer.GreyListingWhiteAddress   whiteAddress = greyListingWhiteAddresses.Add();

                whiteDlg.SaveProperties(whiteAddress);
                whiteAddress.Save();

                Marshal.ReleaseComObject(settings);
                Marshal.ReleaseComObject(antiSpamSettings);
                Marshal.ReleaseComObject(greyListingWhiteAddresses);
                Marshal.ReleaseComObject(whiteAddress);

                ListWhiteListAddresses();
            }
        }
Пример #23
0
        public void TestDeleteThresholdLowerThanMarkThreshold()
        {
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;

            antiSpam.SpamMarkThreshold   = 15;
            antiSpam.SpamDeleteThreshold = 0;

            antiSpam.AddHeaderReason    = true;
            antiSpam.AddHeaderSpam      = true;
            antiSpam.PrependSubject     = true;
            antiSpam.PrependSubjectText = "ThisIsSpam";

            antiSpam.CheckHostInHelo      = true;
            antiSpam.CheckHostInHeloScore = 10;

            // Enable SURBL.
            hMailServer.SURBLServer oSURBLServer = antiSpam.SURBLServers[0];
            oSURBLServer.Active = true;
            oSURBLServer.Score  = 10;
            oSURBLServer.Save();

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

            // Should not be possible to send this email since it's results in a spam
            // score over the delete threshold.
            Assert.IsTrue(oSMTP.Send("*****@*****.**", oAccount1.Address, "INBOX", "Test http://surbl-org-permanent-test-point.com/ Test 2"));

            string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:"));
            Assert.IsTrue(message.Contains("X-hMailServer-Reason-2:"));
        }
Пример #24
0
 public new void SetUp()
 {
     _antiSpam = _settings.AntiSpam;
 }
Пример #25
0
        public new void SetUp()
        {
            _antiSpam = _application.Settings.AntiSpam;

            _antiSpam.SpamDeleteThreshold = 5;
        }
Пример #26
0
 public new void SetUp()
 {
     _antiSpam = _settings.AntiSpam;
 }
Пример #27
0
        public void DisableSpamProtection()
        {
            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;

            if (antiSpam.SpamMarkThreshold != 10000)
            {
                antiSpam.SpamMarkThreshold = 10000;
            }

            if (antiSpam.SpamDeleteThreshold != 10000)
            {
                antiSpam.SpamDeleteThreshold = 10000;
            }

            if (antiSpam.CheckHostInHelo != false)
            {
                antiSpam.CheckHostInHelo = false;
            }

            if (antiSpam.GreyListingEnabled != false)
            {
                antiSpam.GreyListingEnabled = false;
            }

            if (antiSpam.BypassGreylistingOnMailFromMX != false)
            {
                antiSpam.BypassGreylistingOnMailFromMX = false;
            }

            if (antiSpam.SpamAssassinEnabled != false)
            {
                antiSpam.SpamAssassinEnabled = false;
            }

            if (antiSpam.TarpitCount != 0)
            {
                antiSpam.TarpitCount = 0;
            }

            if (antiSpam.TarpitDelay != 0)
            {
                antiSpam.TarpitDelay = 0;
            }

            if (antiSpam.UseMXChecks != false)
            {
                antiSpam.UseMXChecks = false;
            }

            if (antiSpam.UseSPF != false)
            {
                antiSpam.UseSPF = false;
            }

            if (antiSpam.MaximumMessageSize != 1024)
            {
                antiSpam.MaximumMessageSize = 1024;
            }

            if (antiSpam.DKIMVerificationEnabled != false)
            {
                antiSpam.DKIMVerificationEnabled = false;
            }

            antiSpam.WhiteListAddresses.Clear();

            for (int i = 0; i < antiSpam.DNSBlackLists.Count; i++)
            {
                hMailServer.DNSBlackList list = antiSpam.DNSBlackLists[i];
                if (list.Active)
                {
                    list.Active = false;
                    list.Save();
                }
            }

            hMailServer.DNSBlackLists dnsBlackLists = antiSpam.DNSBlackLists;
            while (dnsBlackLists.Count > 0)
            {
                dnsBlackLists.DeleteByDBID(dnsBlackLists[0].ID);
            }

            hMailServer.SURBLServers surblServers = antiSpam.SURBLServers;

            for (int i = surblServers.Count - 1; i >= 0; i--)
            {
                if (surblServers[i].DNSHost != "multi.surbl.org")
                {
                    surblServers.DeleteByDBID(surblServers[i].ID);
                }
                else
                {
                    surblServers[i].Active = false;
                }
            }

            if (surblServers.Count == 0)
            {
                hMailServer.SURBLServer surblServer = surblServers.Add();
                surblServer.Active        = false;
                surblServer.DNSHost       = "multi.surbl.org";
                surblServer.RejectMessage = "Nope";
                surblServer.Score         = 5;
                surblServer.Save();
            }

            hMailServer.IncomingRelays incomingRelays = _settings.IncomingRelays;
            while (incomingRelays.Count > 0)
            {
                incomingRelays.DeleteByDBID(incomingRelays[0].ID);
            }

            antiSpam.ClearGreyListingTriplets();
        }
        public new void SetUp()
        {
            _antiSpam = _application.Settings.AntiSpam;

            _antiSpam.SpamDeleteThreshold = 5;
        }