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 TestSpamProtectionPreTransmissionHELOPassFirst() { _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"; _application.Settings.AntiSpam.CheckHostInHelo = true; _application.Settings.AntiSpam.CheckHostInHeloScore = 105; hMailServer.IncomingRelay incomingRelay = _application.Settings.IncomingRelays.Add(); incomingRelay.LowerIP = "1.2.1.2"; incomingRelay.UpperIP = "1.2.1.3"; incomingRelay.Name = "Test"; incomingRelay.Save(); List <string> messages = new List <string>(); string message = "Received: from example.com (example.com [1.2.1.2]) by mail.host.edu\r\n" + "Received: from mail.hmailserver.com (mail.hmailserver.com [" + Utilities.GethMailServerCOMIPaddress() + "]) by mail.host.edu\r\n" + "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Should be blocked by SPF."; 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 = 0; fa.UseAntiSpam = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); }
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 SetupIncomingRelay() { hMailServer.IncomingRelay relay = _application.Settings.IncomingRelays.Add(); relay.Name = "Test"; relay.LowerIP = "1.2.3.4"; relay.UpperIP = "4.3.2.1"; relay.Save(); }
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); }
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 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; }