public void TestSURBLCorrectNegative() { hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SURBL. hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message without a SURBL url: -> http://www.youtube.com/ <-")); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Non-spam message detected as spam"); } oSURBLServer.Active = false; oSURBLServer.Save(); }
public void TestOneFailOnePass() { hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _settings.AntiSpam.SpamMarkThreshold = 1; _settings.AntiSpam.SpamDeleteThreshold = 100; _settings.AntiSpam.AddHeaderReason = true; _settings.AntiSpam.AddHeaderSpam = true; _settings.AntiSpam.PrependSubject = true; _settings.AntiSpam.PrependSubjectText = "ThisIsSpam"; _settings.AntiSpam.CheckHostInHelo = true; _settings.AntiSpam.CheckHostInHeloScore = 5; // Enable SURBL. hMailServer.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: 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("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", "This is a test message.")); string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:")); Assert.IsFalse(message.Contains("X-hMailServer-Reason-2:")); }
public void TestEnabled() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.WhiteListAddresses obAddresses = _antiSpam.WhiteListAddresses; hMailServer.WhiteListAddress obAddress = obAddresses.Add(); obAddress.EmailAddress = "*****@*****.**"; obAddress.LowerIPAddress = "0.0.0.0"; obAddress.UpperIPAddress = "255.255.255.255"; obAddress.Description = "Test"; obAddress.Save(); // Enable SURBL. hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); obAddresses.DeleteByDBID(obAddress.ID); // Check that it's detected as spam again. Assert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1); }
public void TestSpamProtectionPostTransmission() { _application.Settings.AntiSpam.SpamMarkThreshold = 1; _application.Settings.AntiSpam.SpamDeleteThreshold = 100; _application.Settings.AntiSpam.AddHeaderReason = true; _application.Settings.AntiSpam.AddHeaderSpam = true; _application.Settings.AntiSpam.PrependSubject = true; _application.Settings.AntiSpam.PrependSubjectText = "ThisIsSpam"; hMailServer.SURBLServer oSURBLServer = _application.Settings.AntiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); List <string> messages = new List <string>(); string message = "Received: from example.com (example.com [1.2.3.4]) by mail.host.edu\r\n" + "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "http://surbl-org-permanent-test-point.com/"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.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(); string downloadedMessage = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains("X-hMailServer-Spam: YES")); }
public void TestSURBLCombinedWithSignature() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; _domain.SignatureEnabled = true; _domain.SignaturePlainText = "MyDomainSignature"; _domain.AddSignaturesToLocalMail = true; _domain.Save(); hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SURBL. hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match", "This is a test message without a SURBL url."); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Length == 0 || sMessageContents.Contains("X-hMailServer-Spam") || sMessageContents.Contains("X-hMailServer-Reason") || sMessageContents.Contains("ThisIsSpam")) { throw new Exception("Non-Spam message detected as spam"); } Assert.IsTrue(sMessageContents.Contains(_domain.SignaturePlainText)); oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam") || !sMessageContents.Contains("X-hMailServer-Reason") || !sMessageContents.Contains("ThisIsSpam")) { throw new Exception("Spam message not detected as spam"); } Assert.IsTrue(sMessageContents.Contains(_domain.SignaturePlainText)); }
public void TestSpamMultipleHits() { hMailServer.Account oAccount1 = SingletonProvider <Utilities> .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. hMailServer.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: SMTPClientSimulator oSMTP = 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. Assert.IsFalse(oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", 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("Running spam test"); int iLast = liveLog.LastIndexOf("Running spam test"); Assert.AreNotSame(-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); }
private void ConfirmSURBLServers() { hMailServer.SURBLServer black = _application.Settings.AntiSpam.SURBLServers.get_ItemByDNSHost("127.0.0.1"); Assert.IsTrue(black.Active); Assert.AreEqual("Test", black.RejectMessage); Assert.AreEqual(4, black.Score); black = _application.Settings.AntiSpam.SURBLServers.get_ItemByDNSHost("127.0.0.2"); Assert.IsTrue(black.Active); Assert.AreEqual("Test2", black.RejectMessage); Assert.AreEqual(5, black.Score); }
public void TestMaxSizeNoLimit() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; _antiSpam.MaximumMessageSize = 0; // Enable SURBL. hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); StringBuilder sb = new StringBuilder(); int iterations = ((40 * 1024) / 100) + 1; for (int i = 0; i < iterations; i++) { sb.Append("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); } Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-\r\n" + sb.ToString())); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam") || !sMessageContents.Contains("X-hMailServer-Reason") || !sMessageContents.Contains("ThisIsSpam")) { throw new Exception("Spam message not detected as spam."); } oSURBLServer.Active = false; oSURBLServer.Save(); }
private void SetupSURBLServers() { hMailServer.SURBLServer black = _application.Settings.AntiSpam.SURBLServers.Add(); black.Active = true; black.DNSHost = "127.0.0.1"; black.RejectMessage = "Test"; black.Score = 4; black.Save(); black = _application.Settings.AntiSpam.SURBLServers.Add(); black.Active = true; black.DNSHost = "127.0.0.2"; black.RejectMessage = "Test2"; black.Score = 5; black.Save(); }
protected override void LoadList() { listObjects.Items.Clear(); hMailServer.SURBLServers surblServers = GetSurblServers(); for (int i = 0; i < surblServers.Count; i++) { hMailServer.SURBLServer surblServer = surblServers[i]; ListViewItem item = listObjects.Items.Add(surblServer.DNSHost); item.SubItems.Add(EnumStrings.GetYesNoString(surblServer.Active)); item.Tag = surblServer.ID; Marshal.ReleaseComObject(surblServer); } Marshal.ReleaseComObject(surblServers); }
public ucSURBLServer(int serverID) { InitializeComponent(); if (serverID > 0) { hMailServer.SURBLServers surblServers = APICreator.SURBLServers; _representedObject = surblServers.get_ItemByDBID(serverID); Marshal.ReleaseComObject(surblServers); } DirtyChecker.SubscribeToChange(this, OnContentChanged); new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); checkEnabled.Checked = true; EnableDisable(); }
public void TestSURBLServer() { hMailServer.Settings oSettings = SingletonProvider <Utilities> .Instance.GetApp().Settings; hMailServer.SURBLServer surblServer = oSettings.AntiSpam.SURBLServers.Add(); surblServer.DNSHost = "somehost.com"; surblServer.RejectMessage = "somerejectmessage"; surblServer.Score = 5; surblServer.Save(); if (surblServer.ID == 0) { throw new Exception("SURBL server not saved properly"); } oSettings.AntiSpam.SURBLServers.DeleteByDBID(surblServer.ID); }
public bool SaveData() { bool newObject = false; if (_representedObject == null) { hMailServer.SURBLServers surblServers = APICreator.SURBLServers; _representedObject = surblServers.Add(); newObject = true; Marshal.ReleaseComObject(surblServers); } _representedObject.Active = checkEnabled.Checked; _representedObject.DNSHost = textDNSHost.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(null); // Set the object to clean. DirtyChecker.SetClean(this); if (newObject) { SearchNodeText crit = new SearchNodeText(_representedObject.DNSHost); mainForm.SelectNode(crit); } return(true); }
public void TestSURBLWithWrappedURL() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SURBL. hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", "Wrapped URL - <a href=3D\"http://surbl-org-perma=\r\nnent-test-point.com\">Test</a>"); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; oSURBLServer.Save(); }
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:")); }
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 bool SaveData() { bool newObject = false; if (_representedObject == null) { hMailServer.SURBLServers surblServers = APICreator.SURBLServers; _representedObject = surblServers.Add(); newObject = true; Marshal.ReleaseComObject(surblServers); } _representedObject.Active = checkEnabled.Checked; _representedObject.DNSHost = textDNSHost.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(null); // Set the object to clean. DirtyChecker.SetClean(this); if (newObject) { SearchNodeText crit = new SearchNodeText(_representedObject.DNSHost); mainForm.SelectNode(crit); } return true; }