public void TestSPFViaIncomingRelay() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SPF _antiSpam.UseSPF = true; _antiSpam.UseSPFScore = 5; string message = @"Received: from openspf.org ([76.79.20.184]) by Someone ; Mon, 29 Dec 2008 13:42:55 +0100\r\n" + "Message-ID: <5F90152F-DAC5-43CF-B553-FCF9302F6E0C@WORK>\r\n" + "From: [email protected]\r\n" + "To: [email protected]\r\n" + "\r\n" + "This is a test message.\r\n"; // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); // Add a forwarding relay pointing at localhost, so that the message will appear to be // properly forwarded. hMailServer.IncomingRelays incomingRelays = _settings.IncomingRelays; Assert.AreEqual(0, incomingRelays.Count); hMailServer.IncomingRelay incomingRelay = incomingRelays.Add(); incomingRelay.Name = "Localhost"; incomingRelay.LowerIP = "127.0.0.1"; incomingRelay.UpperIP = "127.0.0.1"; incomingRelay.Save(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); // change so that the forwarding relay no longer covers the IP. incomingRelay.LowerIP = "1.1.1.1"; incomingRelay.UpperIP = "1.1.1.1"; incomingRelay.Save(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); }
protected override void LoadList() { listObjects.Items.Clear(); hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = APICreator.Settings; hMailServer.IncomingRelays IncomingRelays = settings.IncomingRelays; for (int i = 0; i < IncomingRelays.Count; i++) { hMailServer.IncomingRelay IncomingRelay = IncomingRelays[i]; ListViewItem item = listObjects.Items.Add(IncomingRelay.Name); item.SubItems.Add(IncomingRelay.LowerIP); item.SubItems.Add(IncomingRelay.UpperIP); item.Tag = IncomingRelay.ID; Marshal.ReleaseComObject(IncomingRelay); } Marshal.ReleaseComObject(settings); Marshal.ReleaseComObject(IncomingRelays); }
public void TestIncomingRelays() { hMailServer.IncomingRelays incomingRelays = _application.Settings.IncomingRelays; Assert.AreEqual(0, incomingRelays.Count); hMailServer.IncomingRelay incomingRelay = incomingRelays.Add(); incomingRelay.Name = "TestRelay"; incomingRelay.LowerIP = "1.2.1.1"; incomingRelay.UpperIP = "2.1.2.1"; incomingRelay.Save(); // Check that it was saved. Assert.AreNotEqual(0, incomingRelay.ID); // Confirm that settings were saved properly. incomingRelays.Refresh(); hMailServer.IncomingRelay incomingRelay2 = incomingRelays.get_ItemByDBID(incomingRelay.ID); Assert.AreEqual(incomingRelay.ID, incomingRelay2.ID); Assert.AreEqual(incomingRelay.Name, incomingRelay2.Name); Assert.AreEqual(incomingRelay.LowerIP, incomingRelay2.LowerIP); Assert.AreEqual(incomingRelay.UpperIP, incomingRelay2.UpperIP); // Delete it again. incomingRelays.Delete(0); Assert.AreEqual(0, incomingRelays.Count); }
private void ConfirmIncomingRelay() { hMailServer.IncomingRelays relays = _application.Settings.IncomingRelays; Assert.AreEqual(1, relays.Count); hMailServer.IncomingRelay relay = relays[0]; Assert.AreEqual("Test", relay.Name); Assert.AreEqual("1.2.3.4", relay.LowerIP); Assert.AreEqual("4.3.2.1", relay.UpperIP); }
protected override void DeleteItems(List <ListViewItem> items) { hMailServer.Settings settings = APICreator.Settings; hMailServer.IncomingRelays IncomingRelays = settings.IncomingRelays; foreach (var item in items) { int id = Convert.ToInt32(item.Tag); IncomingRelays.DeleteByDBID(id); } Marshal.ReleaseComObject(settings); Marshal.ReleaseComObject(IncomingRelays); }
private void DeleteEnvironment() { while (_application.Domains.Count > 0) { _application.Domains[0].Delete(); } hMailServer.WhiteListAddresses addresses = _application.Settings.AntiSpam.WhiteListAddresses; while (addresses.Count > 0) { addresses[0].Delete(); } hMailServer.Routes routes = _application.Settings.Routes; while (routes.Count > 0) { routes[0].Delete(); } hMailServer.BlockedAttachments attachments = _application.Settings.AntiVirus.BlockedAttachments; while (attachments.Count > 0) { attachments[0].Delete(); } hMailServer.DNSBlackLists blackLists = _application.Settings.AntiSpam.DNSBlackLists; while (blackLists.Count > 0) { blackLists[0].Delete(); } hMailServer.SURBLServers surblServers = _application.Settings.AntiSpam.SURBLServers; while (surblServers.Count > 0) { surblServers[0].Delete(); } hMailServer.SSLCertificates sslCertificates = _application.Settings.SSLCertificates; while (sslCertificates.Count > 0) { sslCertificates[0].Delete(); } hMailServer.IncomingRelays incomingRelays = _application.Settings.IncomingRelays; while (incomingRelays.Count > 0) { incomingRelays[0].Delete(); } }
public void OnDeleteObject(object sender, EventArgs args) { if (!Utility.AskDeleteItem(_incomingRelayTitle)) { return; } hMailServer.Settings settings = APICreator.Settings; hMailServer.IncomingRelays incomingRelays = settings.IncomingRelays; incomingRelays.DeleteByDBID(_incomingRelayID); Marshal.ReleaseComObject(incomingRelays); Marshal.ReleaseComObject(settings); Instances.MainForm.RefreshParentNode(); }
public ucIncomingRelay(int IncomingRelayID) { InitializeComponent(); if (IncomingRelayID > 0) { hMailServer.Settings settings = APICreator.Settings; hMailServer.IncomingRelays IncomingRelays = settings.IncomingRelays; _representedObject = IncomingRelays.get_ItemByDBID(IncomingRelayID); Marshal.ReleaseComObject(IncomingRelays); Marshal.ReleaseComObject(settings); } DirtyChecker.SubscribeToChange(this, OnContentChanged); new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); }
public bool SaveData() { bool newObject = false; if (_representedObject == null) { hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = app.Settings; hMailServer.IncomingRelays IncomingRelays = settings.IncomingRelays; _representedObject = IncomingRelays.Add(); newObject = true; Marshal.ReleaseComObject(settings); Marshal.ReleaseComObject(IncomingRelays); } _representedObject.Name = textName.Text; _representedObject.LowerIP = textLower.Text; _representedObject.UpperIP = textUpper.Text; _representedObject.Save(); // Refresh the node in the tree if the name has changed. IMainForm mainForm = Instances.MainForm; mainForm.RefreshCurrentNode(textName.Text); // Set the object to clean. DirtyChecker.SetClean(this); if (newObject) { SearchNodeText crit = new SearchNodeText(_representedObject.Name); mainForm.SelectNode(crit); } return(true); }
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(); }