public void TestUpdateSubjectOnMessageWithNoMessageWideCharacterSet() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine + " oMessage.Subject = \"[ov]\" + oMessage.Subject " + Environment.NewLine + " oMessage.Save() " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; Scripting scripting = _settings.Scripting; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); CustomAssert.IsEmpty(scripting.CheckSyntax()); string body = @"From: <*****@*****.**>" + Environment.NewLine + "Subject: =?windows-1251?B?yuDr7Pvq7uLzIMji4O3zIC0g7/Do7OXwICLy5fXt6Pfl8eru4+4g8OX4?=" + Environment.NewLine + " =?windows-1251?B?5e3o/yIgW0Z3ZDog0tAg4uXw8ejoIDEuMl0=?=" + Environment.NewLine + Environment.NewLine + "Hej!" + Environment.NewLine; SMTPClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", body); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); TestSetup.AssertFolderMessageCount(account.IMAPFolders[0], 1); string subject = account.IMAPFolders[0].Messages[0].Subject; }
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 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 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 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 TestBodyStructureWithNonLatinCharacter() { 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 Message(); message.Charset = "utf-8"; 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); var oSimulator = new IMAPClientSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.Fetch("1 BODYSTRUCTURE"); oSimulator.Disconnect(); // utf-8 representation of 本本本.zip: CustomAssert.IsTrue(result.Contains("=?utf-8?B?5pys5pys5pys?=.zip")); }
public void TestFetchBody() { 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 Message(); message.Charset = "utf-8"; 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); var oSimulator = new IMAPClientSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string bodyStructureResponse = oSimulator.Fetch("1 BODYSTRUCTURE"); string bodyResponse = oSimulator.Fetch("1 BODY"); oSimulator.Disconnect(); CustomAssert.IsTrue(bodyStructureResponse.Contains("BOUNDARY")); CustomAssert.IsFalse(bodyResponse.Contains("BOUNDARY")); }
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 TestModifyBodyWithExistingAttachments() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string swedish = "abc.zip"; string attachmentName = swedish + ".zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, swedish); var message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.Attachments.Add(filename); message.From = swedish; message.FromAddress = account.Address; message.Subject = swedish; message.Body = ""; message.Save(); TestSetup.AssertFolderMessageCount(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; downloadedMessage.Body = "Test"; downloadedMessage.Save(); }
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 TestEncodingOfStringIncludingSpace() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = "Test"; message.FromAddress = account.Address; message.Subject = "test mit encoding und deutc ü..."; message.Body = "Test"; message.Save(); TestSetup.AssertFolderMessageCount(account.IMAPFolders[0], 1); string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); string[] lines = messageText.Split(Environment.NewLine.ToCharArray()); foreach (string line in lines) { if (line.ToLower().StartsWith("subject: ")) { string subject = line.Substring("subject: ".Length + 1); // encoded part should not contain space. CustomAssert.IsFalse(subject.Contains(" ")); break; } } }
public void TestSaveMessageWithScriptAndMoveMessageWithGlobalRule() { _settings.Scripting.Enabled = true; Account testAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "Test'*****@*****.**", "test"); var sim = new IMAPClientSimulator(); CustomAssert.IsTrue(sim.ConnectAndLogon(testAccount.Address, "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); CustomAssert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 2")); 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); CustomAssert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3")); CreateMessageModificationRule(_application.Rules); 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); // Inbox UID should not have changed since nothing has been added to the inbox. CustomAssert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3")); // Since the message is placed in a new folder, it should receive a unique UID. string status = sim.Status("TestFolder", "UIDNEXT"); CustomAssert.IsTrue(status.Contains("UIDNEXT 2"), status); CustomAssert.AreEqual(1, testFolder.CurrentUID); CustomAssert.AreEqual(1, testFolder.Messages[0].UID); }
public void TestDanishSubject() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string croatianAndDanish = "ʒʥʨPiskefløde"; var message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = "Test"; message.FromAddress = account.Address; message.Subject = croatianAndDanish; message.Body = "hej"; message.Save(); TestSetup.AssertFolderMessageCount(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; CustomAssert.AreEqual(croatianAndDanish, downloadedMessage.Subject); }
public void TestReplaceFullPathWithPartialPath() { 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]; // Now nothing should happen. CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(message.Filename, account.ID)); // 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 '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); CustomAssert.IsTrue(File.Exists(fileName)); // Now the file should be moved to the correct path. CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); CustomAssert.IsFalse(File.Exists(fileName)); // Now nothing should happen because the file is no longer there. CustomAssert.IsFalse(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); string content = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); CustomAssert.IsTrue(content.Contains("Test message")); }
public void TestOnErrorJScript() { Application app = SingletonProvider <TestSetup> .Instance.GetApp(); Scripting scripting = app.Settings.Scripting; scripting.Language = "JScript"; string script = "function OnError(iSeverity, iError, sSource, sDescription) {" + Environment.NewLine + " EventLog.Write('Severity: ' + iSeverity) " + Environment.NewLine + " EventLog.Write('Error: ' + iError) " + Environment.NewLine + " EventLog.Write('Source: ' + sSource) " + Environment.NewLine + " EventLog.Write('Description: ' + sDescription) " + Environment.NewLine + "}" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); string deletedMessageText = app.Settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); TestSetup.AssertFolderMessageCount(inbox, 1); hMailServer.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(); string eventLogText = TestSetup.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog); CustomAssert.IsTrue(eventLogText.Contains("Description: Message retrieval failed")); }
public void TestMultipleLanguages() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string manyLanguages = "中文åäöん文t͡ɬɪŋ"; var message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = manyLanguages; message.FromAddress = account.Address; message.Subject = manyLanguages; message.Body = manyLanguages; message.Save(); TestSetup.AssertFolderMessageCount(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; CustomAssert.AreEqual(manyLanguages, downloadedMessage.Subject); CustomAssert.AreEqual(manyLanguages, downloadedMessage.From); CustomAssert.AreEqual(manyLanguages + Environment.NewLine, downloadedMessage.Body); }
public void TestRenameAccountOrDomainWithMessagesWithFullPath() { 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); 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}", TestSetup.Escape(fileName), message.ID); SingletonProvider <TestSetup> .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; } CustomAssert.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; } CustomAssert.IsTrue(thrown); // Saving domain is OK, unless its address is changed. _domain.Name = "test.com"; _domain.Save(); }