public void TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal() { var messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); // Add a route so we can connect to localhost. //Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, 250, false); //route.TreatSecurityAsLocalDomain = false; //route.Save(); Account userAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account recipientAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account catchallAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); FetchAccount fa = userAccount.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 = true; fa.EnableRouteRecipients = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage1 = POP3ClientSimulator.AssertGetFirstMessageText(recipientAccount1.Address, "test"); CustomAssert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); TestSetup.AssertRecipientsInDeliveryQueue(0, false); } }
public void TestAntiVirusEnabled() { var messages = new List <string>(); string messageText = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Should be blocked by SPF."; messages.Add(messageText); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = CreateFetchAccount(account, port, false, true); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; CustomAssert.IsTrue(message.get_Flag(eMessageFlag.eMFVirusScan)); } }
public void TestAntiVirusEnabled() { List<string> messages = new List<string>(); string messageText = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Should be blocked by SPF."; messages.Add(messageText); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.FetchAccount fa = CreateFetchAccount(account, port, false, true); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; Assert.IsTrue(message.get_Flag(hMailServer.eMessageFlag.eMFVirusScan)); }
public void TestAntiVirusDisabled() { List <string> messages = new List <string>(); string messageText = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Should be blocked by SPF."; messages.Add(messageText); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.FetchAccount fa = CreateFetchAccount(account, port, false, false); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; Assert.IsFalse(message.get_Flag(hMailServer.eMessageFlag.eMFVirusScan)); }
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); }
public void TestSpamProtectionNoTagging() { Utilities.AssertSpamAssassinIsRunning(); _application.Settings.AntiSpam.SpamMarkThreshold = 5; _application.Settings.AntiSpam.SpamDeleteThreshold = 9999; _application.Settings.AntiSpam.MaximumMessageSize = 1024 * 1024; _application.Settings.AntiSpam.AddHeaderReason = false; _application.Settings.AntiSpam.AddHeaderSpam = false; _application.Settings.AntiSpam.PrependSubject = false; _application.Settings.AntiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SpamAssassin _application.Settings.AntiSpam.SpamAssassinEnabled = true; _application.Settings.AntiSpam.SpamAssassinHost = "localhost"; _application.Settings.AntiSpam.SpamAssassinPort = 783; _application.Settings.AntiSpam.SpamAssassinMergeScore = true; _application.Settings.AntiSpam.SpamAssassinScore = 5; List <string> messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; 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(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); }
public void TestDeliverToMIMERecipients() { var messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: \"Test\" <*****@*****.**>, \"Test 2\" <*****@*****.**>\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account account2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account account3 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account catchallAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); FetchAccount fa = account1.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 = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage1 = POP3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); string downloadedMessage2 = POP3ClientSimulator.AssertGetFirstMessageText(account3.Address, "test"); POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); POP3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0); CustomAssert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); CustomAssert.IsTrue(downloadedMessage2.Contains(message), downloadedMessage2); } }
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 TestDeliverToExternalMimeRecipientsDisabled() { List <string> messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account2 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account catchallAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); hMailServer.FetchAccount fa = account1.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 = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage1 = POP3Simulator.AssertGetFirstMessageText(account2.Address, "test"); POP3Simulator.AssertMessageCount(account1.Address, "test", 0); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); POP3Simulator.AssertMessageCount(account2.Address, "test", 0); POP3Simulator.AssertMessageCount(catchallAccount.Address, "test", 0); }
public void TestSpamProtectionDisabled() { _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.UseSPF = true; _application.Settings.AntiSpam.UseSPFScore = 5; var messages = new List <string>(); string message = "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 = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); 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 = false; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsFalse(downloadedMessage.Contains("X-hMailServer-Spam: YES")); } }
public void TestSpamProtectionPreTransmissionHELODelete() { _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; var messages = new List <string>(); string message = "Received: from openspf.org (openspf.org [1.2.1.1]) 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 = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); 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(); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 0); } }
public void TestFetchMessageWithInvalidFromAddress() { string message = string.Format("From: A\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"); var messages = new List <string>() { message }; int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); LockHelper.WaitForUnlock(fa); fa.Delete(); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var log = TestSetup.ReadCurrentDefaultLog(); CustomAssert.IsTrue(log.Contains("Delivering message from <Empty> to [email protected].")); } }
public void TestDeleteMutliple() { var messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); messages.Add(message); messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); CustomAssert.AreEqual(3, pop3Server.DeletedMessages.Count); } }
public void TestServerNotSupportingUIDL() { var 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" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.SupportsUIDL = false; pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); RetryHelper.TryAction(TimeSpan.FromSeconds(10), () => { string error = TestSetup.ReadCurrentDefaultLog(); CustomAssert.IsTrue(error.Contains("-ERR unhandled command")); CustomAssert.IsTrue(error.Contains("Completed retrieval of messages from external account.")); }); } }
public void TestBasicExternalAccount() { var 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" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsTrue(downloadedMessage.Contains(message)); } }
public void TestDelete() { List <string> messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(message)); Assert.AreEqual(1, pop3Server.DeletedMessages.Count); }
public void POP3ServerSupportingStartTLS_StartTLSOptional() { var messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSSTARTTLSRequired)) { pop3Server.SetCertificate(SslSetup.GetCertificate()); pop3Server.StartListen(); TestSetup.DeleteCurrentDefaultLog(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = "******"; fa.Password = "******"; fa.ConnectionSecurity = eConnectionSecurity.eCSSTARTTLSOptional; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1); fa.Delete(); } }
public void TestServerNotSupportingUIDL() { 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" + "Hello!"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.SupportsUIDL = false; 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string error = Utilities.ReadAndDeleteErrorLog(); Assert.IsTrue(error.Contains("-ERR unhandled command")); }
private void DownloadFromExternalAccount(Account account, FetchAccount fa) { if (!_backupMessages) { return; } // Download messages from the external account. var messages = new List <string>(); messages.Add("Subject: Message 1\r\n"); messages.Add("Subject: Message 2\r\n"); messages.Add("Subject: Message 3\r\n"); using (var pop3Server = new POP3Server(1, fa.Port, messages)) { pop3Server.StartListen(); fa.DownloadNow(); pop3Server.WaitForCompletion(); } TestSetup.AssertRecipientsInDeliveryQueue(0); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 5); }
public void POP3ServerNOTSupportingStartTLS_StartTLSRequired() { var messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSNone)) { pop3Server.SetCertificate(SslSetup.GetCertificate()); pop3Server.StartListen(); TestSetup.DeleteCurrentDefaultLog(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = "******"; fa.Password = "******"; fa.ConnectionSecurity = eConnectionSecurity.eCSSTARTTLSRequired; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); string expectedMessage = string.Format( "The download of messages from external account {0} failed. The external aAccount is configured to use STARTTLS connection security, but the POP3 server does not support it.", fa.Name); string contentSoFar = ""; for (int i = 0; i <= 10; i++) { if (i == 5) { CustomAssert.Fail("No connection: " + contentSoFar); } contentSoFar = TestSetup.ReadCurrentDefaultLog(); if (contentSoFar.Contains(expectedMessage)) { break; } Thread.Sleep(1000); } pop3Server.WaitForCompletion(); fa.Delete(); } }
public void TestPOP3Client() { List<string> messages = new List<string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; 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 = GetUsername(); fa.Password = GetPassword(); fa.UseSSL = false; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(message)); EnsureNoPassword(); }
public void TestOnExternalAccountDownload() { TestSetup.DeleteCurrentDefaultLog(); var messages = new List <string>(); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 1\r\n" + "\r\n" + "Message 1!"); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 2\r\n" + "\r\n" + "Message 2!"); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 3\r\n" + "\r\n" + "Message 3!"); // The second message should be deleted after 5 days. string script = "Sub OnExternalAccountDownload(oFetchAccount, oMessage, sRemoteUID)" + Environment.NewLine + " EventLog.Write(\"UID: \" & sRemoteUID) " + Environment.NewLine + " EventLog.Write(\"FetchAccount: \" & oFetchAccount.Name) " + Environment.NewLine + " If Not oMessage Is Nothing Then " + Environment.NewLine + " EventLog.Write(\"From: \" & oMessage.FromAddress) " + Environment.NewLine + " EventLog.Write(\"Filename: \" & oMessage.FileName) " + Environment.NewLine + " Else " + Environment.NewLine + " EventLog.Write(\"Message details missing\") " + Environment.NewLine + " End If" + Environment.NewLine + " if sRemoteUID = \"UniqueID-" + messages[1].GetHashCode() + "\" Then " + Environment.NewLine + " Result.Value = 2 " + Environment.NewLine + " Result.Parameter = 5 " + Environment.NewLine + " End If " + Environment.NewLine + " End Sub"; Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; TestSetup.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa; int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "TestFA"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = false; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.DaysToKeepMessages = -1; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); string eventLogFile = _settings.Logging.CurrentEventLog; string logContents = TestSetup.ReadExistingTextFile(eventLogFile); CustomAssert.IsTrue(logContents.Contains("FetchAccount: " + fa.Name)); CustomAssert.IsTrue(logContents.Contains("From: [email protected]")); CustomAssert.IsTrue(logContents.Contains("From: [email protected]")); CustomAssert.IsTrue(logContents.Contains("From: [email protected]")); string appLogContent = TestSetup.ReadCurrentDefaultLog(); CustomAssert.IsTrue(pop3Server.DeletedMessages.Contains(1)); CustomAssert.IsFalse(pop3Server.DeletedMessages.Contains(2)); CustomAssert.IsTrue(pop3Server.DeletedMessages.Contains(3)); CustomAssert.IsTrue(pop3Server.RetrievedMessages.Contains(1)); CustomAssert.IsTrue(pop3Server.RetrievedMessages.Contains(2)); CustomAssert.IsTrue(pop3Server.RetrievedMessages.Contains(3)); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); } using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.StartListen(); // Download again... fa.DownloadNow(); pop3Server.WaitForCompletion(); // Make sure that no messages are deleted. CustomAssert.AreEqual(0, pop3Server.DeletedMessages.Count); CustomAssert.AreEqual(0, pop3Server.RetrievedMessages.Count); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); } }
public void TestOnExternalAccountDownload() { Utilities.DeleteCurrentDefaultLog(); List<string> messages = new List<string>(); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 1\r\n" + "\r\n" + "Message 1!"); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 2\r\n" + "\r\n" + "Message 2!"); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 3\r\n" + "\r\n" + "Message 3!"); // First set up a script hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp(); // The second message should be deleted after 5 days. string script = "Sub OnExternalAccountDownload(oFetchAccount, oMessage, sRemoteUID)" + Environment.NewLine + " EventLog.Write(\"UID: \" & sRemoteUID) " + Environment.NewLine + " EventLog.Write(\"FetchAccount: \" & oFetchAccount.Name) " + Environment.NewLine + " If Not oMessage Is Nothing Then " + Environment.NewLine + " EventLog.Write(\"From: \" & oMessage.FromAddress) " + Environment.NewLine + " EventLog.Write(\"Filename: \" & oMessage.FileName) " + Environment.NewLine + " Else " + Environment.NewLine + " EventLog.Write(\"Message details missing\") " + Environment.NewLine + " End If" + Environment.NewLine + " if sRemoteUID = \"UniqueID-" + messages[1].GetHashCode() + "\" Then " + Environment.NewLine + " Result.Value = 2 " + Environment.NewLine + " Result.Parameter = 5 " + Environment.NewLine + " End If " + Environment.NewLine + " End Sub"; hMailServer.Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); int port = 43132; 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 = "TestFA"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = false; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.DaysToKeepMessages = -1; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); string eventLogFile = _settings.Logging.CurrentEventLog; string logContents = Utilities.ReadExistingTextFile(eventLogFile); Assert.IsTrue(logContents.Contains("FetchAccount: " + fa.Name)); Assert.IsTrue(logContents.Contains("From: [email protected]")); Assert.IsTrue(logContents.Contains("From: [email protected]")); Assert.IsTrue(logContents.Contains("From: [email protected]")); string appLogContent = Utilities.ReadCurrentDefaultLog(); Assert.IsTrue(pop3Server.DeletedMessages.Contains(1)); Assert.IsFalse(pop3Server.DeletedMessages.Contains(2)); Assert.IsTrue(pop3Server.DeletedMessages.Contains(3)); Assert.IsTrue(pop3Server.RetrievedMessages.Contains(1)); Assert.IsTrue(pop3Server.RetrievedMessages.Contains(2)); Assert.IsTrue(pop3Server.RetrievedMessages.Contains(3)); POP3Simulator.AssertMessageCount(account.Address, "test", 3); pop3Server.StartListen(); // Download again... fa.DownloadNow(); pop3Server.WaitForCompletion(); // Make sure that no messages are deleted. Assert.AreEqual(0, pop3Server.DeletedMessages.Count); Assert.AreEqual(0, pop3Server.RetrievedMessages.Count); POP3Simulator.AssertMessageCount(account.Address, "test", 3); }
public void TestDeliverToExternalMimeRecipientsEnabled() { List <string> messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator smtpServer = new SMTPServerSimulator(1, 250); smtpServer.AddRecipientResult(deliveryResults); smtpServer.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatSecurityAsLocalDomain = true; route.Save(); hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account2 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account catchallAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); hMailServer.FetchAccount fa = account1.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 = true; fa.EnableRouteRecipients = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage1 = POP3Simulator.AssertGetFirstMessageText(account2.Address, "test"); POP3Simulator.AssertMessageCount(account1.Address, "test", 0); POP3Simulator.AssertMessageCount(catchallAccount.Address, "test", 0); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); // Make sure the exernal recipient has received his copy. smtpServer.WaitForCompletion(); string messageData = smtpServer.MessageData; Assert.IsTrue(messageData.Contains(messageData), messageData); Utilities.AssertRecipientsInDeliveryQueue(0, false); }
public void TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal() { List<string> messages = new List<string>(); string message = "From: [email protected]\r\n" + "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, 250, false); route.TreatSecurityAsLocalDomain = false; route.Save(); hMailServer.Account userAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account recipientAccount1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account catchallAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); hMailServer.FetchAccount fa = userAccount.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 = true; fa.EnableRouteRecipients = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage1 = POP3Simulator.AssertGetFirstMessageText(recipientAccount1.Address, "test"); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); Utilities.AssertRecipientsInDeliveryQueue(0, false); }
public void TestFetchMessagesWithVeryLongHeader() { var messages = new List <string>(); var toHeaderBuilder = new StringBuilder(); for (int i = 0; i < 10000; i++) { if (i > 0) { toHeaderBuilder.Append("; "); } toHeaderBuilder.AppendFormat("to-{0}@example.com", i); } for (int i = 0; i < 5; i++) { string message = string.Format("To: {1}\r\n" + "X-Dummy: {0}\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!", i, toHeaderBuilder); messages.Add(message); } int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(1, port, messages)) { pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); LockHelper.WaitForUnlock(fa); fa.Delete(); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 5); string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); for (int i = 0; i < 5; i++) { if (downloadedMessage.Contains(messages[i])) { return; } } CustomAssert.Fail("Downloaded messages did not match uploaded messages."); } }
public void TestDeliverToMIMERecipients() { List<string> messages = new List<string>(); string message = "From: [email protected]\r\n" + "To: \"Test\" <*****@*****.**>, \"Test 2\" <*****@*****.**>\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account2 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account3 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account catchallAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); hMailServer.FetchAccount fa = account1.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 = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage1 = POP3Simulator.AssertGetFirstMessageText(account2.Address, "test"); string downloadedMessage2 = POP3Simulator.AssertGetFirstMessageText(account3.Address, "test"); POP3Simulator.AssertMessageCount(account1.Address, "test", 0); POP3Simulator.AssertMessageCount(catchallAccount.Address, "test", 0); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); Assert.IsTrue(downloadedMessage2.Contains(message), downloadedMessage2); }
public void TestServerNotSupportingUIDL() { 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" + "Hello!"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.SupportsUIDL = false; 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string error = Utilities.ReadAndDeleteErrorLog(); Assert.IsTrue(error.Contains("-ERR unhandled command")); }
public void TestSpamProtectionNoTagging() { Utilities.AssertSpamAssassinIsRunning(); _application.Settings.AntiSpam.SpamMarkThreshold = 5; _application.Settings.AntiSpam.SpamDeleteThreshold = 9999; _application.Settings.AntiSpam.MaximumMessageSize = 1024 * 1024; _application.Settings.AntiSpam.AddHeaderReason = false; _application.Settings.AntiSpam.AddHeaderSpam = false; _application.Settings.AntiSpam.PrependSubject = false; _application.Settings.AntiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SpamAssassin _application.Settings.AntiSpam.SpamAssassinEnabled = true; _application.Settings.AntiSpam.SpamAssassinHost = "localhost"; _application.Settings.AntiSpam.SpamAssassinPort = 783; _application.Settings.AntiSpam.SpamAssassinMergeScore = true; _application.Settings.AntiSpam.SpamAssassinScore = 5; List<string> messages = new List<string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; 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(); POP3Simulator.AssertMessageCount(account.Address, "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 TestSpamProtectionPreTransmissionSPFPass() { _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.UseSPF = true; _application.Settings.AntiSpam.UseSPFScore = 105; List<string> messages = new List<string>(); string message = "Received: from openspf.org (openspf.org [72.81.252.18]) 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); }
public void POP3ServerNotSupportingSSL() { var messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new POP3Server(2, port, messages)) { pop3Server.DisconnectImmediate = true; pop3Server.StartListen(); TestSetup.DeleteCurrentDefaultLog(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = true; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); string contentSoFar = ""; for (int i = 0; i <= 10; i++) { if (i == 5) { CustomAssert.Fail("No connection: " + contentSoFar); } contentSoFar = TestSetup.ReadCurrentDefaultLog(); if (contentSoFar.Contains("TCPConnection - TLS/SSL handshake failed.")) { break; } Thread.Sleep(1000); } TestSetup.DeleteCurrentDefaultLog(); // try again. fa.DownloadNow(); contentSoFar = ""; for (int i = 0; i <= 10; i++) { if (i == 5) { CustomAssert.Fail("No connection: " + contentSoFar); } contentSoFar = TestSetup.ReadCurrentDefaultLog(); if (contentSoFar.Contains("TCPConnection - TLS/SSL handshake failed.")) { break; } Thread.Sleep(1000); } pop3Server.WaitForCompletion(); fa.Delete(); } }
public void TestBasicExternalAccountSSLEvenThoughNotSupported() { List <string> messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = 1111; POP3Server pop3Server = new POP3Server(2, port, messages); pop3Server.DisconnectImmediate = true; pop3Server.StartListen(); Utilities.DeleteCurrentDefaultLog(); 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 = true; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); string contentSoFar = ""; for (int i = 0; i <= 10; i++) { if (i == 5) { Assert.Fail("No connection: " + contentSoFar); } contentSoFar = Utilities.ReadCurrentDefaultLog(); if (contentSoFar.Contains("SSL handshake with client failed.")) { break; } Thread.Sleep(1000); } Utilities.DeleteCurrentDefaultLog(); // try again. fa.DownloadNow(); contentSoFar = ""; for (int i = 0; i <= 10; i++) { if (i == 5) { Assert.Fail("No connection: " + contentSoFar); } contentSoFar = Utilities.ReadCurrentDefaultLog(); if (contentSoFar.Contains("SSL handshake with client failed.")) { break; } Thread.Sleep(1000); } pop3Server.WaitForCompletion(); fa.Delete(); }
public void TestBasicExternalAccountSSLEvenThoughNotSupported() { List<string> messages = new List<string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = 1111; POP3Server pop3Server = new POP3Server(2, port, messages); pop3Server.DisconnectImmediate = true; pop3Server.StartListen(); Utilities.DeleteCurrentDefaultLog(); 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 = true; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); string contentSoFar = ""; for (int i = 0; i <= 10; i++) { if (i == 5) Assert.Fail("No connection: " + contentSoFar); contentSoFar = Utilities.ReadCurrentDefaultLog(); if (contentSoFar.Contains("SSL handshake with client failed.")) break; Thread.Sleep(1000); } Utilities.DeleteCurrentDefaultLog(); // try again. fa.DownloadNow(); contentSoFar = ""; for (int i = 0; i <= 10; i++) { if (i == 5) Assert.Fail("No connection: " +contentSoFar); contentSoFar = Utilities.ReadCurrentDefaultLog(); if (contentSoFar.Contains("SSL handshake with client failed.")) break; Thread.Sleep(1000); } pop3Server.WaitForCompletion(); fa.Delete(); }
public void TestDeleteMutliple() { List<string> messages = new List<string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); messages.Add(message); 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.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3Simulator.AssertMessageCount(account.Address, "test", 3); Assert.AreEqual(3, pop3Server.DeletedMessages.Count); }