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); }
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); }
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); }