public void TestMultipleHostsLimitMXHosts() { _settings.MaxNumberOfMXHosts = 1; // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. Route route = SMTPClientTests.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test")); // Wait for the client to disconnect. server.WaitForCompletion(); string log = TestSetup.ReadCurrentDefaultLog(); CustomAssert.IsTrue(log.Contains("Truncating MX server list.")); } }
public void TestReplaceInvalidPathWithCorrectPath() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); IMAPFolder folder = account.IMAPFolders.get_ItemByName("Inbox"); TestSetup.AssertFolderMessageCount(folder, 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("Inbox").Messages[0]; string filename = message.Filename; // Now nothing should happen here. CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(filename, account.ID)); CustomAssert.IsTrue(File.Exists(filename)); string sql = string.Format("update hm_messages set messagefilename = '{0}' where messageid = {1}", TestSetup.Escape(message.Filename), message.ID); SingletonProvider <TestSetup> .Instance.GetApp().Database.ExecuteSQL(sql); // Now the path should be replaced. CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(message.Filename, account.ID)); // Now nothing should happen. CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(message.Filename, account.ID)); CustomAssert.IsTrue(File.Exists(message.Filename)); string content = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsTrue(content.Contains("Test message")); }
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 TestDeletionOfMessageInDeletedFolder() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); TestSetup.AssertFolderMessageCount(inbox, 1); Messages messages = inbox.Messages; Message message = messages[0]; var dir = new DirectoryInfo(Path.GetFullPath(message.Filename)); DirectoryInfo parent = dir.Parent.Parent.Parent; parent.Delete(true); DateTime timeBeforeDelete = DateTime.Now; messages.DeleteByDBID(message.ID); TimeSpan executionTime = DateTime.Now - timeBeforeDelete; CustomAssert.Greater(1500, executionTime.TotalMilliseconds); }
public void TestPOP3TransactionSafety() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody")); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var sim = new POP3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); // Now delete the message using an IMAP client. var imapSimulator = new IMAPClientSimulator(); CustomAssert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test")); CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX")); CustomAssert.IsTrue(imapSimulator.SetDeletedFlag(1)); CustomAssert.IsTrue(imapSimulator.Expunge()); CustomAssert.AreEqual(0, imapSimulator.GetMessageCount("Inbox")); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody")); IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); // This deletion should not have any effect, since the POP3 connection is referencing an old message. sim.DELE(1); sim.QUIT(); CustomAssert.AreEqual(1, imapSimulator.GetMessageCount("Inbox")); }
public void TestOnDeliveryFailedVBScript() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); // First set up a script string script = "Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)" + Environment.NewLine + " EventLog.Write(\"File: \" & oMessage.FileName) " + Environment.NewLine + " EventLog.Write(\"Recipient: \" & sRecipient) " + Environment.NewLine + " EventLog.Write(\"Error: \" & sErrorMessage) " + Environment.NewLine + " End Sub"; Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; TestSetup.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Add an account and send a message to it. Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(oAccount1.Address, "*****@*****.**", "Test", "SampleBody"); // Make sure that the message is deliverd and bounced. TestSetup.AssertRecipientsInDeliveryQueue(0); string eventLogText = TestSetup.ReadExistingTextFile(TestSetup.GetEventLogFileName()); CustomAssert.IsTrue(eventLogText.Contains("File: ")); CustomAssert.IsTrue(eventLogText.Contains("Recipient: [email protected]")); CustomAssert.IsTrue(eventLogText.Contains("No mail servers appear to exists")); }
public void TestFetch() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1"); IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2"); IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody3"); IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); var sim = new IMAPClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("INBOX"); string result = sim.Fetch("1 BODY[1]"); CustomAssert.IsTrue(result.Contains("SampleBody1"), result); result = sim.Fetch("2 BODY[1]"); CustomAssert.IsTrue(result.Contains("SampleBody2"), result); result = sim.Fetch("3 BODY[1]"); CustomAssert.IsTrue(result.Contains("SampleBody3"), result); }
public void TestMoveMessageWithAccountLevelRule() { hMailServer.Account testAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "Test'*****@*****.**", "test"); // First deliver two messages to the inbox. SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3Simulator.AssertMessageCount(testAccount.Address, "test", 1); hMailServer.IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3Simulator.AssertMessageCount(testAccount.Address, "test", 2); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[1].UID); CreateMoveRule(testAccount.Rules, "TestFolder"); // This message will be moved into the test folder. SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); // Wait for the message to arrive. Utilities.AssertFolderExists(testAccount.IMAPFolders, "TestFolder"); hMailServer.IMAPFolder testFolder = testAccount.IMAPFolders.get_ItemByName("TestFolder"); // Since the message is placed in a new folder, it should receive a unique UID. Utilities.AssertMessageExistsInFolder(testFolder, 1); Assert.AreEqual(1, testFolder.CurrentUID); Assert.AreEqual(1, testFolder.Messages[0].UID); }
public void TestLiveLog() { Application app = SingletonProvider <TestSetup> .Instance.GetApp(); Utilities utilities = app.Utilities; Logging logging = app.Settings.Logging; logging.EnableLiveLogging(true); // Add an account and send a message to it. Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); string liveLog = logging.LiveLog; CustomAssert.IsTrue(liveLog.Length > 0, liveLog); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2); logging.EnableLiveLogging(true); liveLog = logging.LiveLog; CustomAssert.IsFalse(liveLog.Contains("SMTPDeliverer - Message")); }
public void TestBasicIncrements() { Account testAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "Test'*****@*****.**", "test"); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; CustomAssert.AreEqual(1, inboxFolder.CurrentUID); CustomAssert.AreEqual(1, inboxFolder.Messages[0].UID); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); CustomAssert.AreEqual(2, inboxFolder.CurrentUID); CustomAssert.AreEqual(2, inboxFolder.Messages[1].UID); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 3); CustomAssert.AreEqual(3, inboxFolder.CurrentUID); CustomAssert.AreEqual(3, inboxFolder.Messages[2].UID); }
public void TestBasicIncrementsWithDeletion() { hMailServer.Account testAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "Test'*****@*****.**", "test"); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3Simulator.AssertMessageCount(testAccount.Address, "test", 1); hMailServer.IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); POP3Simulator.AssertGetFirstMessageText(testAccount.Address, "test"); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3Simulator.AssertMessageCount(testAccount.Address, "test", 1); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[0].UID); POP3Simulator.AssertGetFirstMessageText(testAccount.Address, "test"); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3Simulator.AssertMessageCount(testAccount.Address, "test", 1); Assert.AreEqual(3, inboxFolder.CurrentUID); Assert.AreEqual(3, inboxFolder.Messages[0].UID); }
public void TestMoveMessageWithGlobalRule() { Account testAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "Test'*****@*****.**", "test"); // First deliver two messages to the inbox. SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; CustomAssert.AreEqual(1, inboxFolder.CurrentUID); CustomAssert.AreEqual(1, inboxFolder.Messages[0].UID); SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); CustomAssert.AreEqual(2, inboxFolder.CurrentUID); CustomAssert.AreEqual(2, inboxFolder.Messages[1].UID); CreateMoveRule(_application.Rules, "TestFolder"); // This message will be moved into the test folder. SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); // Wait for the message to arrive. TestSetup.AssertFolderExists(testAccount.IMAPFolders, "TestFolder"); IMAPFolder testFolder = testAccount.IMAPFolders.get_ItemByName("TestFolder"); TestSetup.AssertFolderMessageCount(testFolder, 1); // Since the message is placed in a new folder, it should receive a unique UID. CustomAssert.AreEqual(1, testFolder.Messages.Count); CustomAssert.AreEqual(1, testFolder.CurrentUID); CustomAssert.AreEqual(1, testFolder.Messages[0].UID); }
public void TestRenameAccountOrDomainWithMessagesWithFullPath() { var account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); hMailServer.IMAPFolder folder = account.IMAPFolders.get_ItemByName("Inbox"); Utilities.AssertMessageExistsInFolder(folder, 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("Inbox").Messages[0]; // Move the message file to another folder. string domainPath = Path.Combine(_application.Settings.Directories.DataDirectory, _domain.Name); string accountPath = Path.Combine(domainPath, "test"); string fileName = Path.Combine(accountPath, "randomMail.eml"); File.Move(message.Filename, fileName); // Update the database with the full path. string sql = string.Format("update hm_messages set messagefilename = '{0}' where messageid = {1}", Utilities.Escape(fileName), message.ID); SingletonProvider <Utilities> .Instance.GetApp().Database.ExecuteSQL(sql); // Now try to change the name of the domain or account. Should fail. account.Address = "*****@*****.**"; bool thrown = false; try { account.Save(); } catch (Exception) { thrown = true; } Assert.IsTrue(thrown); // Saving account is OK, unless its address is changed. account.Address = "*****@*****.**"; account.Save(); thrown = false; _domain.Name = "example.com"; try { _domain.Save(); } catch (Exception) { thrown = true; } Assert.IsTrue(thrown); // Saving domain is OK, unless its address is changed. _domain.Name = "test.com"; _domain.Save(); }
public void TestSendToAddressWithQuote() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "us'*****@*****.**", "test"); SMTPClientSimulator.StaticSend("*****@*****.**", "us'*****@*****.**", "Test", "Test"); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); }
public void TestDeliverToMyselfOnLocalPort() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // Add a route so we can conenct to localhost. AddRoutePointingAtLocalhost(1, 25, false); // Send message to this route. SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "subject", "body"); for (int i = 0; i < 40; i++) { string s = _status.UndeliveredMessages; if (s.Contains("\t\[email protected]")) { break; } Thread.Sleep(250); } // Wait for the bounce message to be delivered. Utilities.AssertRecipientsInDeliveryQueue(0, true); string message = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsTrue(message.Contains("this would mean connecting to myself.")); }
private void SendMessageThread() { for (int message = 0; message < _threadedMessageCount; message++) { SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "test", "test"); } }
public void TestOnDeliverMessageJScript() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); Scripting scripting = _settings.Scripting; scripting.Language = "JScript"; // First set up a script string script = @"function OnDeliverMessage(oMessage) { oMessage.HeaderValue('X-SpamResult') = 'TEST2'; oMessage.Save(); }"; string file = scripting.CurrentScriptFile; TestSetup.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Add an account and send a message to it. Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); // Check that the message exists string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); CustomAssert.IsNotEmpty(message); CustomAssert.Less(0, message.IndexOf("X-SpamResult: TEST2")); }
public void TestRetrievalOfMessageInDeletedFolder() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); hMailServer.IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");; Utilities.AssertMessageExistsInFolder(inbox, 1); hMailServer.Message message = inbox.Messages[0]; DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(message.Filename)); DirectoryInfo parent = dir.Parent.Parent.Parent; parent.Delete(true); string text = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); Utilities.AssertReportedError(); }
public void TestOnDeliveryStartVBScript() { Application app = SingletonProvider <TestSetup> .Instance.GetApp(); Scripting scripting = app.Settings.Scripting; string script = "Sub OnDeliveryStart(oMessage) " + Environment.NewLine + " EventLog.Write(\"Delivering message: \" & oMessage.FileName) " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); // Wait for the message to be delivered. POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); string eventLogText = TestSetup.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog); CustomAssert.IsTrue(eventLogText.Contains("Delivering message")); }
public void TestExpunge() { Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test")); POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); var simulator = new IMAPClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); simulator.SelectFolder("Inbox"); CustomAssert.IsTrue(simulator.SetFlagOnMessage(1, true, @"\Deleted")); var secondSimulator = new IMAPClientSimulator(); secondSimulator.ConnectAndLogon(oAccount.Address, "test"); string result = secondSimulator.ExamineFolder("INBOX"); CustomAssert.IsTrue(result.Contains("1 EXISTS"), result); CustomAssert.IsFalse(secondSimulator.Expunge()); simulator.SelectFolder("INBOX"); CustomAssert.IsTrue(simulator.Expunge()); simulator.Close(); secondSimulator.Close(); }
public void TestRetrievalOfDeletedMessage() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); TestSetup.AssertFolderMessageCount(inbox, 1); Message message = inbox.Messages[0]; File.Delete(message.Filename); string text = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); TestSetup.AssertReportedError("Message retrieval failed because message file"); }
public void TestChangeRecentFlag() { Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test")); POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); var simulator = new IMAPClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); string result = simulator.ExamineFolder("Inbox"); CustomAssert.IsTrue(result.Contains("* 1 RECENT"), result); simulator.Close(); simulator.Disconnect(); simulator = new IMAPClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); CustomAssert.IsTrue(simulator.SelectFolder("Inbox", out result)); CustomAssert.IsTrue(result.Contains("* 1 RECENT"), result); simulator.Close(); simulator.Disconnect(); simulator = new IMAPClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); result = simulator.ExamineFolder("Inbox"); CustomAssert.IsTrue(result.Contains("* 0 RECENT"), result); simulator.Close(); simulator.Disconnect(); }
public void TestRetrievalOfMessageInDeletedFolderUsingIMAP() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); TestSetup.AssertFolderMessageCount(inbox, 1); Message message = inbox.Messages[0]; var dir = new DirectoryInfo(Path.GetFullPath(message.Filename)); DirectoryInfo parent = dir.Parent.Parent.Parent; parent.Delete(true); var sim = new IMAPClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("INBOX"); string result = sim.Fetch("1 BODY[1]"); CustomAssert.IsTrue(result.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); TestSetup.AssertReportedError("Message retrieval failed because message file"); }
public void TestChangeSeenFlag() { Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test")); POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); var simulator = new IMAPClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); simulator.ExamineFolder("Inbox"); string flags = simulator.GetFlags(1); string body = simulator.Fetch("1 RFC822"); string flagsAfter = simulator.GetFlags(1); simulator.Close(); simulator.Disconnect(); CustomAssert.AreEqual(flags, flagsAfter); var secondSimulator = new IMAPClientSimulator(); secondSimulator.ConnectAndLogon(oAccount.Address, "test"); secondSimulator.SelectFolder("Inbox"); string secondFlags = secondSimulator.GetFlags(1); string secondBody = secondSimulator.Fetch("1 RFC822"); string secondFlagsAfter = secondSimulator.GetFlags(1); secondSimulator.Close(); secondSimulator.Disconnect(); CustomAssert.AreNotEqual(secondFlags, secondFlagsAfter); }
public void TestRETR() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); var sim = new POP3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.RETR(1); CustomAssert.IsTrue(result.Contains("TestBody1"), result); result = sim.RETR(2); CustomAssert.IsTrue(result.Contains("TestBody2"), result); result = sim.RETR(3); CustomAssert.IsTrue(result.Contains("TestBody3"), result); CustomAssert.IsFalse(result.Contains(".\r\n.")); }
public void TestWildcardStar() { WhiteListAddresses obAddresses = _antiSpam.WhiteListAddresses; WhiteListAddress obAddress = obAddresses.Add(); obAddress.EmailAddress = "white*@microsoft.com"; obAddress.LowerIPAddress = "0.0.0.0"; obAddress.UpperIPAddress = "255.255.255.255"; obAddress.Description = "Test"; obAddress.Save(); // Enable SURBL. SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); CustomAssert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); CustomAssert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 2); }
public void TestSURBLCorrectNegative() { Account oAccount1 = SingletonProvider <TestSetup> .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. SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message without a SURBL url: -> http://www.youtube.com/ <-")); string sMessageContents = POP3ClientSimulator.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 TestDeliverToServerNotSupportingEHLO() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); var deliveryResults = new Dictionary <string, int>() { { "*****@*****.**", 250 } }; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.ServerSupportsEhlo = false; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); // Send message to this route. if (!SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message")) { CustomAssert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); TestSetup.AssertRecipientsInDeliveryQueue(0, false); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
public void TestDistributionListPointingAtItself() { // Add distribution list var oRecipients = new List <string>(); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); }
public void TestBounceMessageSyntax() { Account senderAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account recipientAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); recipientAccount.MaxSize = 1; recipientAccount.Save(); // Build a 2MB string. var builder = new StringBuilder(); for (int i = 0; i < 11000; i++) { builder.Append( "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); } string text = builder.ToString(); SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "", text); // Make sure the recipient did not receive it. TestSetup.AssertRecipientsInDeliveryQueue(0); // Check the syntax in the bounce message. string content = POP3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); // The bounce message should contain the MIME-version. CustomAssert.IsTrue(content.Contains("MIME-Version: 1.0")); // Lines may not end with space if they are QP-encoded. CustomAssert.IsTrue(content.Contains(" Subject:=20")); }