public void TestModifyBodyWithExistingAttachments() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string swedish = "abc.zip"; string attachmentName = swedish + ".zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, swedish); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; downloadedMessage.Body = "Test"; downloadedMessage.Save(); }
public void TestBodyStructureWithNonLatinCharacter() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string attachmentName = "本本本.zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, "tjena moss"); hMailServer.Message message = new hMailServer.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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); IMAPSimulator oSimulator = new IMAPSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.Fetch("1 BODYSTRUCTURE"); oSimulator.Disconnect(); // utf-8 representation of 本本本.zip: Assert.IsTrue(result.Contains("=?utf-8?B?5pys5pys5pys?=.zip")); }
public void TestSwedishAndChineseCombination() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string swedishAndChinese = "ÅÄÖ汉语"; string attachmentName = swedishAndChinese + ".zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, swedishAndChinese); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreNotEqual(0, downloadedMessage.Attachments.Count); hMailServer.Attachment attachment = downloadedMessage.Attachments[0]; Assert.AreEqual(attachmentName, attachment.Filename); Assert.AreEqual(swedishAndChinese + Environment.NewLine, downloadedMessage.Body); }
public void TestMailCreationUnicodeAndAttachment() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string filename = Path.Combine(Path.GetTempPath(), "dummy.txt"); File.WriteAllText(filename, "tjena moss"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Charset = "utf-8"; message.Attachments.Add(filename); // may cause an assert. message.HTMLBody = "Test of message... 日本語"; message.Body = "Test of message... 日本語"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: multipart/mixed; charset=\"utf-8\"")); File.Delete(filename); }
public void TestSaveMessageInExistingIMAPFolder() { hMailServer.Settings settings = SingletonProvider <Utilities> .Instance.GetApp().Settings; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Check that the message does not exist POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 0); // Send a message to the account. hMailServer.IMAPFolder folder = oAccount1.IMAPFolders.get_ItemByName("INBOX"); hMailServer.Message oMessage = folder.Messages.Add(); Assert.AreEqual(0, oMessage.State); oMessage.Body = "Välkommen till verkligheten"; oMessage.Subject = "Hej"; oMessage.Save(); Assert.AreEqual(2, oMessage.State); Assert.IsFalse(oMessage.Filename.Contains(settings.PublicFolderDiskName)); Assert.IsTrue(oMessage.Filename.Contains(_domain.Name)); // Check that the message exists string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("Hej")); }
public void TestEncodingOfStringIncludingSpace() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); string messageText = POP3Simulator.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. Assert.IsFalse(subject.Contains(" ")); break; } } }
public void TestAddBodyAfterAttachment() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string filename = Path.Combine(Path.GetTempPath(), "dummy.txt"); File.WriteAllText(filename, "tjena moss"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Attachments.Add(filename); message.Body = "Hello"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: multipart/mixed;")); Assert.IsTrue(messageText.Contains("Hello")); Assert.IsTrue(messageText.Contains("dummy.txt")); File.Delete(filename); }
public void TestReplaceFullPathInPublicFolderWithPartialPath() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.IMAPFolders publicFolders = _settings.PublicFolders; hMailServer.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}", Utilities.Escape(fileName), message.ID); SingletonProvider <Utilities> .Instance.GetApp().Database.ExecuteSQL(sql); // Now try to insert the message. Assert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, 0)); _application.Reinitialize(); string newMessgaeFilename = _settings.PublicFolders[0].Messages[0].Filename; Assert.AreNotEqual(fileName, newMessgaeFilename); Assert.IsTrue(File.Exists(newMessgaeFilename)); }
public void TestJapaneseAttachments() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string attachmentName = "本本本.zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, "tjena moss"); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreNotEqual(0, downloadedMessage.Attachments.Count); hMailServer.Attachment attachment = downloadedMessage.Attachments[0]; Assert.AreEqual(attachmentName, attachment.Filename); }
public void SingleLatinCharacterRecipient() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("Ö", account.Address); message.Charset = "utf-8"; message.Body = "Test body."; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageText.Contains("To: \"=?utf-8?B?w5Y=?=\" <*****@*****.**>")); }
private void SendMessage(string subject, string body, string to, string cc) { hMailServer.Message message = new hMailServer.Message(); message.Charset = "UTF-8"; message.AddRecipient("test", "meta'*****@*****.**"); message.From = "Test"; message.FromAddress = "meta'*****@*****.**"; message.Subject = subject; message.set_HeaderValue("To", to); message.set_HeaderValue("cc", cc); message.Body = body; message.Save(); }
public void TestMailCreationUnicodeBodyAndHtml() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Charset = "utf-8"; message.Body = "Test of message... 日本語"; message.HTMLBody = "Test of message... 日本語"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageText.Contains("Content-Type: text/html; charset=\"utf-8\"")); Assert.IsTrue(messageText.Contains("Content-Type: text/plain; charset=\"utf-8\"")); }
public void TestMailCreationHTML() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.HTMLBody = "Hello"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: text/html; charset=\"utf-8\"")); Assert.IsTrue(header.Contains("Content-Transfer-Encoding: quoted-printable")); Assert.IsTrue(messageText.Contains("Hello")); }
public void NonLatinCharactersInRecipientNameResultsInBoxesInThunderbird() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); //message.AddRecipient("Тестов Тест ТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостеронович", account.Address); message.AddRecipient("ТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероно", account.Address); message.Subject = "Test"; message.Charset = "utf-8"; message.Body = "Test body."; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); // Important: // RFC 2047: http://www.faqs.org/rfcs/rfc2047.html // The notation of RFC 822 is used, with the exception that white space // characters MUST NOT appear between components of an 'encoded-word'. // // Also, there should be a space separating the encoded word with the following // non-encoded word. string match = "To: \"=?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\" <*****@*****.**>"; Assert.IsTrue(messageText.Contains(match)); }
public void TestDanishSubject() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string croatianAndDanish = "ʒʥʨPiskefløde"; hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = "Test"; message.FromAddress = account.Address; message.Subject = croatianAndDanish; message.Body = "hej"; message.Save(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreEqual(croatianAndDanish, downloadedMessage.Subject); }
public void NonLatinCharactersInRecipientNameResultsInBoxesInThunderbird() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); //message.AddRecipient("Тестов Тест ТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостероновичТестостеронович", account.Address); message.AddRecipient("ТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероноТестовТестТестостероно", account.Address); message.Subject = "Test"; message.Charset = "utf-8"; message.Body = "Test body."; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); // Important: // RFC 2047: http://www.faqs.org/rfcs/rfc2047.html // The notation of RFC 822 is used, with the exception that white space // characters MUST NOT appear between components of an 'encoded-word'. // // Also, there should be a space separating the encoded word with the following // non-encoded word. string match = "To: \"=?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n"+ " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\r\n" + " =?utf-8?B?0KLQtdGB0YLQvtCy0KLQtdGB0YLQotC10YHRgtC+0YHRgtC10YDQvtC90L4=?=\" <*****@*****.**>"; Assert.IsTrue(messageText.Contains(match)); }
public void TestMailCreationHTMLAndPlainTextReverse() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Body = "PlainTextBody"; message.HTMLBody = "HTMLBody"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: multipart/alternative")); Assert.IsFalse(header.Contains("Content-Transfer-Encoding: quoted-printable")); Assert.IsTrue(messageText.Contains("PlainTextBody")); Assert.IsTrue(messageText.Contains("HTMLBody")); }
public void TestEncodeWord() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string croatianAndDanish = "ʒʥʨPiskefløde"; hMailServer.Message message = new hMailServer.Message(); message.Subject = croatianAndDanish; message.AddRecipient("", account.Address); message.Save(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); hMailServer.Message apiMessage = account.Messages[0]; Assert.AreEqual(apiMessage.Subject, croatianAndDanish); string fileContents = File.ReadAllText(apiMessage.Filename); Assert.IsFalse(fileContents.Contains(croatianAndDanish)); }
public void TestMultipleLanguages() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string manyLanguages = "中文åäöん文t͡ɬɪŋ"; hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = manyLanguages; message.FromAddress = account.Address; message.Subject = manyLanguages; message.Body = manyLanguages; message.Save(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreEqual(manyLanguages, downloadedMessage.Subject); Assert.AreEqual(manyLanguages, downloadedMessage.From); Assert.AreEqual(manyLanguages + Environment.NewLine, downloadedMessage.Body); }
public void TestSendMessage() { hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. hMailServer.Message oMessage = new hMailServer.Message(); Assert.AreEqual(0, oMessage.State); oMessage.AddRecipient("Martin", oAccount1.Address); oMessage.Body = "Välkommen till verkligheten"; oMessage.Subject = "Hej"; oMessage.Save(); Assert.AreEqual(1, oMessage.State); // Check that the message exists string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("Hej")); }
public void TestMostlyLatinCharacters() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("Test Recipient: Тест", account.Address); message.Subject = "Test Subject: Тест"; message.Charset = "utf-8"; message.Body = "Test body."; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); // Important: // RFC 2047: http://www.faqs.org/rfcs/rfc2047.html // The notation of RFC 822 is used, with the exception that white space // characters MUST NOT appear between components of an 'encoded-word'. // // Also, there should be a space separating the encoded word with the following // non-encoded word. Assert.IsTrue(messageText.Contains("To: \"=?utf-8?B?VGVzdCBSZWNpcGllbnQ6INCi0LXRgdGC?=\" <*****@*****.**>")); }
public void TestSaveMessageInPublicIMAPFolder() { hMailServer.Settings settings = SingletonProvider <Utilities> .Instance.GetApp().Settings; hMailServer.IMAPFolders publicFolders = settings.PublicFolders; hMailServer.IMAPFolder testFolder = publicFolders.Add("TestFolder"); testFolder.Save(); // Send a message to the account. hMailServer.Message oMessage = testFolder.Messages.Add(); Assert.AreEqual(0, oMessage.State); oMessage.Body = "Välkommen till verkligheten"; oMessage.Subject = "Hej"; oMessage.Save(); Assert.AreEqual(2, oMessage.State); Assert.IsTrue(oMessage.Filename.Contains(settings.PublicFolderDiskName)); Assert.IsFalse(oMessage.Filename.Contains(_domain.Name)); }
public void TestAddBodyAfterAttachment() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string filename = Path.Combine(Path.GetTempPath(), "dummy.txt"); File.WriteAllText(filename, "tjena moss"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Attachments.Add(filename); message.Body = "Hello"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: multipart/mixed;")); Assert.IsTrue(messageText.Contains("Hello")); Assert.IsTrue(messageText.Contains("dummy.txt")); File.Delete(filename); }
public void TestMailCreationUnicodeAndAttachment() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string filename = Path.Combine(Path.GetTempPath(), "dummy.txt"); File.WriteAllText(filename, "tjena moss"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Charset = "utf-8"; message.Attachments.Add(filename); // may cause an assert. message.HTMLBody = "Test of message... 日本語"; message.Body = "Test of message... 日本語"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: multipart/mixed; charset=\"utf-8\"")); File.Delete(filename); }
public void TestEncodingOfStringIncludingSpace() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); string messageText = POP3Simulator.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. Assert.IsFalse(subject.Contains(" ")); break; } } }
public void TestEncodeWord() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string croatianAndDanish = "ʒʥʨPiskefløde"; hMailServer.Message message = new hMailServer.Message(); message.Subject = croatianAndDanish; message.AddRecipient("", account.Address); message.Save(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); hMailServer.Message apiMessage = account.Messages[0]; Assert.AreEqual(apiMessage.Subject, croatianAndDanish); string fileContents = File.ReadAllText(apiMessage.Filename); Assert.IsFalse(fileContents.Contains(croatianAndDanish)); }
public void TestDanishSubject() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string croatianAndDanish = "ʒʥʨPiskefløde"; hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = "Test"; message.FromAddress = account.Address; message.Subject = croatianAndDanish; message.Body = "hej"; message.Save(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreEqual(croatianAndDanish, downloadedMessage.Subject); }
public void Save() { _object.Save(); }
public void TestMailCreationUnicodeBodyAndHtml() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Charset = "utf-8"; message.Body = "Test of message... 日本語"; message.HTMLBody = "Test of message... 日本語"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageText.Contains("Content-Type: text/html; charset=\"utf-8\"")); Assert.IsTrue(messageText.Contains("Content-Type: text/plain; charset=\"utf-8\"")); }
public void TestSwedishAndChineseCombination() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string swedishAndChinese = "ÅÄÖ汉语"; string attachmentName = swedishAndChinese + ".zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, swedishAndChinese); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreNotEqual(0, downloadedMessage.Attachments.Count); hMailServer.Attachment attachment = downloadedMessage.Attachments[0]; Assert.AreEqual(attachmentName, attachment.Filename); Assert.AreEqual(swedishAndChinese + Environment.NewLine, downloadedMessage.Body); }
public void TestCopyMessage() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Utilities utilities = app.Utilities; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Create a new folder. hMailServer.IMAPFolder folder = account.IMAPFolders.get_ItemByName("INBOX"); folder.Save(); hMailServer.IMAPFolder someOtherFolder = account.IMAPFolders.Add("SomeOtherFolder"); for (int i = 0; i < 3; i++) { hMailServer.Message message = folder.Messages.Add(); message.set_Flag(hMailServer.eMessageFlag.eMFSeen, true); message.Save(); message.Copy(someOtherFolder.ID); } SMTPClientSimulator.StaticSend("*****@*****.**", account.Address, "Test", "Test"); // Copy back to inbox. for (int i = 0; i < 3; i++) { hMailServer.Message message = someOtherFolder.Messages[i]; message.Copy(folder.ID); } POP3Simulator.AssertMessageCount(account.Address, "test", 7); IMAPSimulator sim = new IMAPSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("Inbox"); string response = sim.Fetch("1:7 UID"); string[] lines = Microsoft.VisualBasic.Strings.Split(response, Environment.NewLine, -1, Microsoft.VisualBasic.CompareMethod.Text); List <string> uids = new List <string>(); foreach (string line in lines) { int paraPos = line.IndexOf("("); int paraEndPos = line.IndexOf(")"); if (paraPos < 0 || paraEndPos < 0) { continue; } string paraContent = line.Substring(paraPos + 1, paraEndPos - paraPos - 1); if (!uids.Contains(paraContent)) { uids.Add(paraContent); } } Assert.AreEqual(7, uids.Count); // Make sure the UIDS are sorted properly by creating a copy, sort the copy // and then compare to original. List <string> copy = new List <string>(); copy.InsertRange(0, uids); copy.Sort(); Assert.AreEqual(copy, uids); }
public void TestJapaneseAttachments() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string attachmentName = "本本本.zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, "tjena moss"); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreNotEqual(0, downloadedMessage.Attachments.Count); hMailServer.Attachment attachment = downloadedMessage.Attachments[0]; Assert.AreEqual(attachmentName, attachment.Filename); }
public void TestModifyBodyWithExistingAttachments() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string swedish = "abc.zip"; string attachmentName = swedish + ".zip"; string filename = Path.Combine(Path.GetTempPath(), attachmentName); File.WriteAllText(filename, swedish); hMailServer.Message 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(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; downloadedMessage.Body = "Test"; downloadedMessage.Save(); }
public void TestMostlyLatinCharacters() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("Test Recipient: Тест", account.Address); message.Subject = "Test Subject: Тест"; message.Charset = "utf-8"; message.Body = "Test body."; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); // Important: // RFC 2047: http://www.faqs.org/rfcs/rfc2047.html // The notation of RFC 822 is used, with the exception that white space // characters MUST NOT appear between components of an 'encoded-word'. // // Also, there should be a space separating the encoded word with the following // non-encoded word. Assert.IsTrue(messageText.Contains("To: \"=?utf-8?B?VGVzdCBSZWNpcGllbnQ6INCi0LXRgdGC?=\" <*****@*****.**>")); }
public void TestMultipleLanguages() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); string manyLanguages = "中文åäöん文t͡ɬɪŋ"; hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = manyLanguages; message.FromAddress = account.Address; message.Subject = manyLanguages; message.Body = manyLanguages; message.Save(); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreEqual(manyLanguages, downloadedMessage.Subject); Assert.AreEqual(manyLanguages, downloadedMessage.From); Assert.AreEqual(manyLanguages + Environment.NewLine, downloadedMessage.Body); }
public void TestMailCreationHTMLAndPlainTextReverse() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Body = "PlainTextBody"; message.HTMLBody = "HTMLBody"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: multipart/alternative")); Assert.IsFalse(header.Contains("Content-Transfer-Encoding: quoted-printable")); Assert.IsTrue(messageText.Contains("PlainTextBody")); Assert.IsTrue(messageText.Contains("HTMLBody")); }
public void SingleLatinCharacterRecipient() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("Ö", account.Address); message.Charset = "utf-8"; message.Body = "Test body."; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageText.Contains("To: \"=?utf-8?B?w5Y=?=\" <*****@*****.**>")); }
public void TestMailCreationPlainText() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Message message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Body = "Hello"; message.Save(); string messageText = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: text/plain; charset=\"utf-8\"")); Assert.IsTrue(header.Contains("Content-Transfer-Encoding: quoted-printable")); Assert.IsTrue(messageText.Contains("Hello")); }