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 TestSwedishAndChineseCombination() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string swedishAndChinese = "ÅÄÖ汉语"; string attachmentName = swedishAndChinese + ".zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, swedishAndChinese); var message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = "Test"; message.FromAddress = account.Address; message.Body = swedishAndChinese; message.Attachments.Add(filename); message.Save(); TestSetup.AssertFolderMessageCount(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; CustomAssert.AreNotEqual(0, downloadedMessage.Attachments.Count); Attachment attachment = downloadedMessage.Attachments[0]; CustomAssert.AreEqual(attachmentName, attachment.Filename); CustomAssert.AreEqual(swedishAndChinese + Environment.NewLine, downloadedMessage.Body); }
public void TestJapaneseAttachments() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string attachmentName = "本本本.zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, "tjena moss"); var message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = "Test"; message.FromAddress = account.Address; message.Body = "hejsan"; message.Attachments.Add(filename); message.Save(); TestSetup.AssertFolderMessageCount(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; CustomAssert.AreNotEqual(0, downloadedMessage.Attachments.Count); Attachment attachment = downloadedMessage.Attachments[0]; CustomAssert.AreEqual(attachmentName, attachment.Filename); }
public void TestIncomingRelays() { IncomingRelays incomingRelays = _application.Settings.IncomingRelays; CustomAssert.AreEqual(0, incomingRelays.Count); 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. CustomAssert.AreNotEqual(0, incomingRelay.ID); // Confirm that settings were saved properly. incomingRelays.Refresh(); IncomingRelay incomingRelay2 = incomingRelays.get_ItemByDBID(incomingRelay.ID); CustomAssert.AreEqual(incomingRelay.ID, incomingRelay2.ID); CustomAssert.AreEqual(incomingRelay.Name, incomingRelay2.Name); CustomAssert.AreEqual(incomingRelay.LowerIP, incomingRelay2.LowerIP); CustomAssert.AreEqual(incomingRelay.UpperIP, incomingRelay2.UpperIP); // Delete it again. incomingRelays.Delete(0); CustomAssert.AreEqual(0, incomingRelays.Count); }
public void AuthShouldUpdateLastLogonTime() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); DateTime lastLogonTimeBefore = Convert.ToDateTime(account.LastLogonTime); Thread.Sleep(1000); var sock = new TcpConnection(); sock.Connect(25); CustomAssert.IsTrue(sock.Receive().StartsWith("220")); sock.Send("EHLO test.com\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("250")); string base64EncodedUsername = EncodeBase64("*****@*****.**"); sock.Send("AUTH LOGIN " + base64EncodedUsername + "\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("334")); sock.Send(EncodeBase64("test") + "\r\n"); CustomAssert.IsTrue(sock.Receive().StartsWith("235")); DateTime lastLogonTimeAfter = Convert.ToDateTime(SingletonProvider <TestSetup> .Instance.GetApp().Domains[0].Accounts[0].LastLogonTime); CustomAssert.AreNotEqual(lastLogonTimeBefore, lastLogonTimeAfter); }
public void TestSpamMultipleHits() { TestSetup.AssertSpamAssassinIsRunning(); Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "mult'*****@*****.**", "test"); _settings.AntiSpam.SpamMarkThreshold = 1; _settings.AntiSpam.SpamDeleteThreshold = 2; _settings.AntiSpam.AddHeaderReason = true; _settings.AntiSpam.AddHeaderSpam = true; _settings.AntiSpam.PrependSubject = true; _settings.AntiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SpamAssassin _settings.AntiSpam.SpamAssassinEnabled = true; _settings.AntiSpam.SpamAssassinHost = "localhost"; _settings.AntiSpam.SpamAssassinPort = 783; _settings.AntiSpam.SpamAssassinMergeScore = false; _settings.AntiSpam.SpamAssassinScore = 5; // Enable SURBL. SURBLServer oSURBLServer = _settings.AntiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account, containing both incorrect MX records an SURBL-hits. // We should only detect one of these two: var oSMTP = new SMTPClientSimulator(); _settings.Logging.LogSMTP = true; _settings.Logging.LogDebug = true; _settings.Logging.Enabled = true; _settings.Logging.EnableLiveLogging(true); // Access the log once to make sure it's cleared. string liveLog = _settings.Logging.LiveLog; // Should not be possible to send this email since it's results in a spam // score over the delete threshold. CustomAssert.IsFalse(oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", "This is a test message. It contains incorrect MX records and a SURBL string: http://surbl-org-permanent-test-point.com/ SpamAssassinString: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X")); liveLog = _settings.Logging.LiveLog; _settings.Logging.EnableLiveLogging(false); int iFirst = liveLog.IndexOf("Spam test:"); int iLast = liveLog.LastIndexOf("Spam test:"); CustomAssert.AreNotEqual(-1, iFirst); // there should only be one spam test, since any spam match // should result in a spam score over the delete threshold. CustomAssert.AreEqual(iFirst, iLast); }
public void TestTemporaryFailure() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 452; 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. AddRoutePointingAtLocalhost(2, smtpServerPort, false); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message")); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAssert.AreNotEqual(0, _status.UndeliveredMessages.Length); } using (var server = new SMTPServerSimulator(1, smtpServerPort))// Start to listen again. { server.AddRecipientResult(deliveryResults); server.StartListen(); // Deliver the message to the server and then deliver the bounce message. TestSetup.AssertRecipientsInDeliveryQueue(0, true); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAssert.IsFalse(server.Conversation.Contains("\r\nDATA\r\n")); } // Now the message has bounced. string message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); CustomAssert.IsTrue(message.Contains("452 [email protected]")); CustomAssert.IsTrue(message.Contains("Tried 2 time(s)")); }
public void TestLanguages() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); Language oLanguageSwedish = application.GlobalObjects.Languages.get_ItemByName("swedish"); Language oLanguageEnglish = application.GlobalObjects.Languages.get_ItemByName("english"); string sSWE = oLanguageSwedish.get_String("File"); string sENG = oLanguageEnglish.get_String("File"); CustomAssert.AreEqual(sENG, "File"); CustomAssert.AreNotEqual(sSWE, sENG); CustomAssert.AreNotEqual(sSWE, ""); }
public void BlowfishEncryptShouldNotRequireAdminPrivileges() { Application app = SingletonProvider <TestSetup> .Instance.GetApp(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var newApp = new Application(); CustomAssert.IsNotNull(newApp.Authenticate(account.Address, "test")); Utilities utilities = newApp.Utilities; string encryptedResult = utilities.BlowfishEncrypt("Test"); CustomAssert.AreNotEqual("Test", encryptedResult, encryptedResult); string decrypted = utilities.BlowfishDecrypt(encryptedResult); CustomAssert.AreEqual("Test", decrypted, decrypted); }
public void TestScoreMerge() { _settings.AntiSpam.SpamAssassinMergeScore = true; // Send a messages to this account. var oSMTP = new SMTPClientSimulator(); oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-hMailServer-Reason-Score"); CustomAssert.AreNotEqual(-1, scoreStart, sMessageContents); try { scoreStart = sMessageContents.IndexOf(":", scoreStart) + 2; } catch (Exception) { CustomAssert.Fail(sMessageContents); } CustomAssert.AreNotEqual(-1, scoreStart, sMessageContents); int scoreEnd = sMessageContents.IndexOf("\r\n", scoreStart); CustomAssert.AreNotEqual(-1, scoreEnd, sMessageContents); int scoreLength = scoreEnd - scoreStart; string score = sMessageContents.Substring(scoreStart, scoreLength); double scoreValue = Convert.ToDouble(score); CustomAssert.Greater(scoreValue, 100); }
public void TestMessageScoreNotMerged() { // Send a messages to this account. var smtpClientSimulator = new SMTPClientSimulator(); smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-hMailServer-Reason-Score"); CustomAssert.AreNotEqual(0, scoreStart); scoreStart = sMessageContents.IndexOf(":", scoreStart) + 2; int scoreEnd = sMessageContents.IndexOf("\r\n", scoreStart); int scoreLength = scoreEnd - scoreStart; string score = sMessageContents.Substring(scoreStart, scoreLength); double scoreValue = Convert.ToDouble(score); CustomAssert.Less(scoreValue, 10); }
public void TestReplaceFullPathInPublicFolderWithPartialPath() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); IMAPFolders publicFolders = _settings.PublicFolders; IMAPFolder folder = publicFolders.Add("Share1"); folder.Save(); hMailServer.Message message = folder.Messages.Add(); message.Subject = "Test"; message.Save(); // Move the message file to another folder. string publicFolderPath = Path.Combine(_application.Settings.Directories.DataDirectory, "#Public"); string fileName = Path.Combine(publicFolderPath, "randomMail.eml"); File.Move(message.Filename, fileName); // Update the database with the 'invalid' path. string sql = string.Format("update hm_messages set messagefilename = '{0}' where messageid = {1}", TestSetup.Escape(fileName), message.ID); SingletonProvider <TestSetup> .Instance.GetApp().Database.ExecuteSQL(sql); // Now try to insert the message. CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, 0)); _application.Reinitialize(); string newMessgaeFilename = _settings.PublicFolders[0].Messages[0].Filename; CustomAssert.AreNotEqual(fileName, newMessgaeFilename); CustomAssert.IsTrue(File.Exists(newMessgaeFilename)); }
public void TestPartialTemporaryErrorFailure() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 400; 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. AddRoutePointingAtLocalhost(2, smtpServerPort, false); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message")) { CustomAssert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); // Trigger a sending of the bounce message. TestSetup.AssertRecipientsInDeliveryQueue(1); CustomAssert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); CustomAssert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); CustomAssert.AreNotEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } // Attempt to deliver the message again. using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); TestSetup.SendMessagesInQueue(); server.WaitForCompletion(); // TestSetup.AssertRecipientsInDeliveryQueue(0); string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test"); CustomAssert.IsTrue(bounceMessage.Contains("400 [email protected]")); CustomAssert.IsTrue(bounceMessage.Contains("Tried 2 time(s)")); CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**")); CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**")); } }
public void TestMultipleHostsTemporaryFailure() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 499; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. Route route = AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message")) { CustomAssert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); } TestSetup.AssertRecipientsInDeliveryQueue(1); // Check so that only user 3 remains in the queue. CustomAssert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); CustomAssert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); CustomAssert.AreNotEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); using (var server = new SMTPServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResults); server.StartListen(); TestSetup.AssertRecipientsInDeliveryQueue(0, true); server.WaitForCompletion(); string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test"); CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**")); CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**")); CustomAssert.IsTrue(bounceMessage.Contains("*****@*****.**")); CustomAssert.IsTrue(bounceMessage.Contains("499 [email protected]")); CustomAssert.IsTrue(bounceMessage.Contains("Tried 2 time(s)")); } }