Esempio n. 1
0
        public void NonLatinCharactersInRecipientNameResultsInNoSpaces()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var message = new hMailServer.Message();

            message.AddRecipient("Tестов Тест Тестостеронович", account.Address);
            message.Subject = "Test";
            message.Charset = "utf-8";
            message.Body    = "Test body.";
            message.Save();

            string messageText = Pop3ClientSimulator.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?VNC10YHRgtC+0LIg0KLQtdGB0YIg0KLQtdGB0YLQvtGB0YLQtdGA0L7QvdC+?=\r\n =?utf-8?B?0LLQuNGH?=\" <*****@*****.**>"));
        }
Esempio n. 2
0
        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();

            CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1);

            hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0];
            Assert.AreNotEqual(0, downloadedMessage.Attachments.Count);
            Attachment attachment = downloadedMessage.Attachments[0];

            Assert.AreEqual(attachmentName, attachment.Filename);

            Assert.AreEqual(swedishAndChinese + Environment.NewLine, downloadedMessage.Body);
        }
Esempio n. 3
0
        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();

            CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1);

            hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0];

            downloadedMessage.Body = "Test";
            downloadedMessage.Save();
        }
Esempio n. 4
0
        public void TestSaveMessageInExistingIMAPFolder()
        {
            Settings settings = SingletonProvider <TestSetup> .Instance.GetApp().Settings;

            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Check that the message does not exist
            POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 0);

            // Send a message to the account.
            IMAPFolder folder = oAccount1.IMAPFolders.get_ItemByName("INBOX");

            hMailServer.Message oMessage = folder.Messages.Add();

            CustomAssert.AreEqual(0, oMessage.State);

            oMessage.Body    = "Välkommen till verkligheten";
            oMessage.Subject = "Hej";
            oMessage.Save();

            CustomAssert.AreEqual(2, oMessage.State);
            CustomAssert.IsFalse(oMessage.Filename.Contains(settings.PublicFolderDiskName));
            CustomAssert.IsTrue(oMessage.Filename.Contains(_domain.Name));

            // Check that the message exists
            string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            CustomAssert.IsNotEmpty(message);
            CustomAssert.Less(0, message.IndexOf("Hej"));
        }
Esempio n. 5
0
        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();

            CustomAsserts.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.
                    Assert.IsFalse(subject.Contains(" "));

                    break;
                }
            }
        }
Esempio n. 6
0
        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();

            CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1);

            hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0];
            Assert.AreNotEqual(0, downloadedMessage.Attachments.Count);
            Attachment attachment = downloadedMessage.Attachments[0];

            Assert.AreEqual(attachmentName, attachment.Filename);
        }
Esempio n. 7
0
        public void TestImportOfMessageInInvalidSubName()
        {
            string @messageText =
                "From: [email protected]\r\n" +
                "\r\n" +
                "Test\r\n";

            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string domainPath  = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com");
            string accountPath = Path.Combine(domainPath, "test");

            Directory.CreateDirectory(accountPath);

            string guid     = Guid.NewGuid().ToString();
            string guidPath = Path.Combine(accountPath, guid.Substring(1, 2));

            Directory.CreateDirectory(guidPath);

            string fileName = Path.Combine(guidPath, "§§§§.eml");

            File.WriteAllText(fileName, messageText);

            CustomAssert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID));

            hMailServer.Message message = _domain.Accounts[0].IMAPFolders.get_ItemByName("Inbox").Messages[0];
            CustomAssert.IsFalse(fileName.Contains("$$$$.eml"));
        }
Esempio n. 8
0
        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"));
        }
Esempio n. 9
0
        public void TestAddBodyAfterAttachment()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string filename = Path.Combine(Path.GetTempPath(), "dummy.txt");

            File.WriteAllText(filename, "tjena moss");

            var message = new hMailServer.Message();

            message.AddRecipient("", account.Address);
            message.Attachments.Add(filename);
            message.Body = "Hello";
            message.Save();

            string messageText = Pop3ClientSimulator.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);
        }
Esempio n. 10
0
        public void TestMailCreationUnicodeAndAttachment()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string filename = Path.Combine(Path.GetTempPath(), "dummy.txt");

            File.WriteAllText(filename, "tjena moss");

            var 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 = Pop3ClientSimulator.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);
        }
Esempio n. 11
0
        public void TestUnderscoreInBody()
        {
            string body = "underscore_in_body\r\n";

            var message = new hMailServer.Message();

            message.Body = body;
            Assert.AreEqual(body, message.Body);
        }
Esempio n. 12
0
        public void SwedishCharactersInBody()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var message = new hMailServer.Message();

            message.AddRecipient("Ö", account.Address);
            message.Charset = "utf-8";
            message.Body    = "Test ÅÄÖ Test.";

            string body = message.Body;

            Assert.IsTrue(body.Contains("Test ÅÄÖ Test."));
        }
Esempio n. 13
0
        public void SingleLatinCharacterRecipient()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var message = new hMailServer.Message();

            message.AddRecipient("Ö", account.Address);
            message.Charset = "utf-8";
            message.Body    = "Test body.";
            message.Save();

            string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            Assert.IsTrue(messageText.Contains("To: \"=?utf-8?B?w5Y=?=\" <*****@*****.**>"));
        }
Esempio n. 14
0
        public void TestMailCreationUnicodeBodyAndHtml()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var 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 = Pop3ClientSimulator.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\""));
        }
Esempio n. 15
0
        public void TestRetrieveMessageID()
        {
            Application app = SingletonProvider <TestSetup> .Instance.GetApp();

            Utilities utilities = app.Utilities;

            // 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);

            hMailServer.Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0];

            CustomAssert.AreEqual(message.ID, utilities.RetrieveMessageID(message.Filename));
            CustomAssert.AreEqual(0, utilities.RetrieveMessageID(@"C:\some\nonexistant\file"));
        }
Esempio n. 16
0
        public void NonLatinCharactersInRecipientNameResultsInBoxesInThunderbird()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var 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=?=\" <*****@*****.**>";

             CustomAssert.IsTrue(messageText.Contains(match));
        }
Esempio n. 17
0
        public void TestMailCreationPlainText()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var message = new hMailServer.Message();

            message.AddRecipient("", account.Address);
            message.Body = "Hello";
            message.Save();

            string messageText = Pop3ClientSimulator.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"));
        }
Esempio n. 18
0
        public void TestAddTextDuringSendingAttachment()
        {
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to the account.
            var oMessage = new hMailServer.Message();

            Assert.AreEqual(0, oMessage.State);

            Scripting scripting = SingletonProvider <TestSetup> .Instance.GetApp().Settings.Scripting;

            string signature = "MySignature";

            string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine +
                            " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine +
                            " oMessage.Save() " + Environment.NewLine +
                            "End Sub" + Environment.NewLine + Environment.NewLine;

            File.WriteAllText(scripting.CurrentScriptFile, script);
            scripting.Enabled = true;
            scripting.Reload();

            Assembly a = Assembly.GetExecutingAssembly();

            var mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add("*****@*****.**");
            mail.Subject         = "Automatiskt servertest";
            mail.Body            = "Detta är ett automatiskt test av epostservern.";
            mail.BodyEncoding    = Encoding.GetEncoding(1252);
            mail.SubjectEncoding = Encoding.GetEncoding(1252);
            mail.Attachments.Add(new Attachment(a.Location));
            var oClient = new SmtpClient("localhost", 25);

            oClient.Send(mail);

            // Check that the message exists
            string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            Assert.IsNotEmpty(message, message);
            Assert.IsTrue(message.Contains(signature), message);
        }
Esempio n. 19
0
        public void TestDecodeSpecificMessage()
        {
            string message = "Return-Path:" + Environment.NewLine +
                             "Received: from host ([1.2.3.4])" + Environment.NewLine +
                             "X-Facebook: from zuckmail" + Environment.NewLine +
                             "by localhost.localdomain with local (ZuckMail);" + Environment.NewLine +
                             "Date: Wed, 3 Dec 2008 06:14:37 -0800" + Environment.NewLine +
                             "To: [email protected]" + Environment.NewLine +
                             "From: Facebook" + Environment.NewLine +
                             "Reply-to: Facebook" + Environment.NewLine +
                             "Subject: =?UTF-8?Q?V=C3=A4nligen_=C3=A5terst=C3=A4ll_dina_inst=C3=A4llningar_f=C3?=" +
                             Environment.NewLine +
                             "    =?UTF-8?Q?=B6r_meddelanden_via_e-post.?=" + Environment.NewLine +
                             "Message-ID:" + Environment.NewLine +
                             "X-Priority: 3" + Environment.NewLine +
                             "X-Mailer: ZuckMail [version 1.00]" + Environment.NewLine +
                             "Errors-To: [email protected]" + Environment.NewLine +
                             "MIME-Version: 1.0" + Environment.NewLine +
                             "Content-Type: text/plain; charset=\"UTF-8\"" + Environment.NewLine +
                             "Content-Transfer-Encoding: quoted-printable" + Environment.NewLine +
                             "" + Environment.NewLine +
                             "Dina inst=C3=A4llningar f=C3=B6r meddelanden via e-post har tyv=C3=A4rr g=" +
                             Environment.NewLine +
                             "=C3=A5tt f=C3=B6rlorade. Vi beklagar det intr=C3=A4ffade.G=C3=" + Environment.NewLine +
                             "=A5 till http://www.facebook.com/editaccount.php?notifications f=C3=B6r a=" +
                             Environment.NewLine +
                             "tt =C3=A5terst=C3=A4lla dina inst=C3=A4llningar.Tack!Facebook-grupp=" +
                             Environment.NewLine +
                             "en." + Environment.NewLine;

            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSendRaw("*****@*****.**", account.Address, message);

            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);

            hMailServer.Message apiMessage = account.Messages[0];

            Assert.AreEqual("Vänligen återställ dina inställningar för meddelanden via e-post.", apiMessage.Subject);
            Assert.IsTrue(
                apiMessage.Body.StartsWith("Dina inställningar för meddelanden via e-post har tyvärr gått förlorade."));
        }
Esempio n. 20
0
        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();

            CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1);

            hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0];
            Assert.AreEqual(croatianAndDanish, downloadedMessage.Subject);
        }
Esempio n. 21
0
        public void TestEncodeWord()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string croatianAndDanish = "ʒʥʨPiskefløde";
            var    message           = new hMailServer.Message();

            message.Subject = croatianAndDanish;
            message.AddRecipient("", account.Address);
            message.Save();

            Pop3ClientSimulator.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));
        }
Esempio n. 22
0
        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"));
        }
Esempio n. 23
0
        public void TestMailCreationHTMLAndPlainTextReverse()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var message = new hMailServer.Message();

            message.AddRecipient("", account.Address);
            message.Body     = "PlainTextBody";
            message.HTMLBody = "HTMLBody";
            message.Save();

            string messageText = Pop3ClientSimulator.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"));
        }
Esempio n. 24
0
        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"));
        }
Esempio n. 25
0
        public void TestSendMessage()
        {
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to the account.
            var oMessage = new hMailServer.Message();

            CustomAssert.AreEqual(0, oMessage.State);

            oMessage.AddRecipient("Martin", oAccount1.Address);
            oMessage.Body    = "Välkommen till verkligheten";
            oMessage.Subject = "Hej";
            oMessage.Save();

            CustomAssert.AreEqual(1, oMessage.State);

            // Check that the message exists
            string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            CustomAssert.IsNotEmpty(message);
            CustomAssert.Less(0, message.IndexOf("Hej"));
        }
Esempio n. 26
0
        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();

            CustomAsserts.AssertFolderMessageCount(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);
        }
Esempio n. 27
0
        public void TestAddTextDuringSending()
        {
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to the account.
            var oMessage = new hMailServer.Message();

            Assert.AreEqual(0, oMessage.State);

            Scripting scripting = SingletonProvider <TestSetup> .Instance.GetApp().Settings.Scripting;

            string signature = "MySignature";

            string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine +
                            " Call EventLog.Write(\"Subject:\" +oMessage.Subject)" + Environment.NewLine +
                            " Call EventLog.Write(\"Date:\" +oMessage.Date)" + Environment.NewLine +
                            " Call EventLog.Write(\"Body:\" +oMessage.Body)" + Environment.NewLine +
                            " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine +
                            " oMessage.Save() " + Environment.NewLine +
                            "End Sub" + Environment.NewLine + Environment.NewLine;

            File.WriteAllText(scripting.CurrentScriptFile, script);
            scripting.Enabled = true;
            scripting.Reload();
            Assert.IsEmpty(scripting.CheckSyntax());

            // Send the message.
            var recipients = new List <string>();

            recipients.Add("*****@*****.**");
            SmtpClientSimulator.StaticSend("*****@*****.**", recipients, "Hej", "Välkommen till verkligheten");

            // Check that the message exists
            string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            Assert.IsNotEmpty(message);
            Assert.IsTrue(message.Contains(signature));
            Assert.Less(0, message.IndexOf("Hej"));
        }
Esempio n. 28
0
        public void TestSaveMessageInPublicIMAPFolder()
        {
            Settings settings = SingletonProvider <TestSetup> .Instance.GetApp().Settings;

            IMAPFolders publicFolders = settings.PublicFolders;

            IMAPFolder testFolder = publicFolders.Add("TestFolder");

            testFolder.Save();

            // Send a message to the account.
            hMailServer.Message oMessage = testFolder.Messages.Add();

            CustomAssert.AreEqual(0, oMessage.State);

            oMessage.Body    = "Välkommen till verkligheten";
            oMessage.Subject = "Hej";
            oMessage.Save();

            CustomAssert.AreEqual(2, oMessage.State);
            CustomAssert.IsTrue(oMessage.Filename.Contains(settings.PublicFolderDiskName));
            CustomAssert.IsFalse(oMessage.Filename.Contains(_domain.Name));
        }
Esempio n. 29
0
        public void TestMostlyLatinCharacters()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var 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 = Pop3ClientSimulator.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?=\" <*****@*****.**>"));
        }
Esempio n. 30
0
        public void TestAddTextToEmptyBody()
        {
            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to the account.
            string messageText = @"Date: Thu, 03 Jul 2008 22:01:53 +0200\r\n" +
                                 "From: Test <*****@*****.**>\r\n" +
                                 "MIME-Version: 1.0\r\n" +
                                 "To: [email protected]\r\n" +
                                 "Subject: test\r\n" +
                                 "Content-Type: multipart/mixed;\r\n" +
                                 "  boundary=\"------------050908050500020808050006\"\r\n" +
                                 "\r\n" +
                                 "This is a multi-part message in MIME format.\r\n" +
                                 "--------------050908050500020808050006\r\n" +
                                 "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n" +
                                 "Content-Transfer-Encoding: 7bit\r\n" +
                                 "\r\n" +
                                 "Test\r\n" +
                                 "\r\n" +
                                 "--------------050908050500020808050006\r\n" +
                                 "Content-Type: text/plain;\r\n" +
                                 " name=\"AUTOEXEC.BAT\"\r\n" +
                                 "Content-Transfer-Encoding: base64\r\n" +
                                 "Content-Disposition: inline;\r\n" +
                                 " filename=\"AUTOEXEC.BAT\"\r\n" +
                                 "\r\n" +
                                 "\r\n" +
                                 "--------------050908050500020808050006--\r\n";

            SMTPClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", messageText);

            hMailServer.Message message =
                TestSetup.AssertRetrieveFirstMessage(account1.IMAPFolders.get_ItemByName("INBOX"));
            CustomAssert.AreEqual(1, message.Attachments.Count);
            CustomAssert.AreEqual("AUTOEXEC.BAT", message.Attachments[0].Filename);
        }
Esempio n. 31
0
        public void TestAddTextDuringSending()
        {
            Account oAccount1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to the account.
             var oMessage = new hMailServer.Message();
             CustomAssert.AreEqual(0, oMessage.State);

             Scripting scripting = SingletonProvider<TestSetup>.Instance.GetApp().Settings.Scripting;

             string signature = "MySignature";

             string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine +
                         " Call EventLog.Write(\"Subject:\" +oMessage.Subject)" + Environment.NewLine +
                         " Call EventLog.Write(\"Date:\" +oMessage.Date)" + Environment.NewLine +
                         " Call EventLog.Write(\"Body:\" +oMessage.Body)" + Environment.NewLine +
                         " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine +
                         " oMessage.Save() " + Environment.NewLine +
                         "End Sub" + Environment.NewLine + Environment.NewLine;

             File.WriteAllText(scripting.CurrentScriptFile, script);
             scripting.Enabled = true;
             scripting.Reload();
             CustomAssert.IsEmpty(scripting.CheckSyntax());

             // Send the message.
             var recipients = new List<string>();
             recipients.Add("*****@*****.**");
             SMTPClientSimulator.StaticSend("*****@*****.**", recipients, "Hej", "Välkommen till verkligheten");

             // Check that the message exists
             string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");

             CustomAssert.IsNotEmpty(message);
             CustomAssert.IsTrue(message.Contains(signature));
             CustomAssert.Less(0, message.IndexOf("Hej"));
        }
Esempio n. 32
0
        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));
        }
Esempio n. 33
0
        public void TestAddBodyAfterAttachment()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             string filename = Path.Combine(Path.GetTempPath(), "dummy.txt");
             File.WriteAllText(filename, "tjena moss");

             var 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);

             CustomAssert.IsTrue(header.Contains("Content-Type: multipart/mixed;"));
             CustomAssert.IsTrue(messageText.Contains("Hello"));
             CustomAssert.IsTrue(messageText.Contains("dummy.txt"));

             File.Delete(filename);
        }
Esempio n. 34
0
        public void NonLatinCharactersInRecipientNameResultsInNoSpaces()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var message = new hMailServer.Message();
             message.AddRecipient("Tестов Тест Тестостеронович", account.Address);
             message.Subject = "Test";
             message.Charset = "utf-8";
             message.Body = "Test body.";
             message.Save();

             string messageText = Pop3ClientSimulator.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?VNC10YHRgtC+0LIg0KLQtdGB0YIg0KLQtdGB0YLQvtGB0YLQtdGA0L7QvdC+?=\r\n =?utf-8?B?0LLQuNGH?=\" <*****@*****.**>"));
        }
Esempio n. 35
0
        public void TestMostlyLatinCharacters()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var 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.
             CustomAssert.IsTrue(messageText.Contains("To: \"=?utf-8?B?VGVzdCBSZWNpcGllbnQ6INCi0LXRgdGC?=\" <*****@*****.**>"));
        }
Esempio n. 36
0
        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);
        }
Esempio n. 37
0
        public void TestMailCreationHTMLAndPlainTextReverse()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var 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);

             CustomAssert.IsTrue(header.Contains("Content-Type: multipart/alternative"));
             CustomAssert.IsFalse(header.Contains("Content-Transfer-Encoding: quoted-printable"));
             CustomAssert.IsTrue(messageText.Contains("PlainTextBody"));
             CustomAssert.IsTrue(messageText.Contains("HTMLBody"));
        }
Esempio n. 38
0
        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();
        }
Esempio n. 39
0
        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 = 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.
               CustomAssert.IsFalse(subject.Contains(" "));

               break;
            }
             }
        }
Esempio n. 40
0
        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);
        }
Esempio n. 41
0
        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);
        }
Esempio n. 42
0
        public void TestAddTextDuringSendingAttachment()
        {
            Account oAccount1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to the account.
             var oMessage = new hMailServer.Message();
             CustomAssert.AreEqual(0, oMessage.State);

             Scripting scripting = SingletonProvider<TestSetup>.Instance.GetApp().Settings.Scripting;

             string signature = "MySignature";

             string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine +
                         " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine +
                         " oMessage.Save() " + Environment.NewLine +
                         "End Sub" + Environment.NewLine + Environment.NewLine;

             File.WriteAllText(scripting.CurrentScriptFile, script);
             scripting.Enabled = true;
             scripting.Reload();

             Assembly a = Assembly.GetExecutingAssembly();

             var mail = new MailMessage();
             mail.From = new MailAddress("*****@*****.**");
             mail.To.Add("*****@*****.**");
             mail.Subject = "Automatiskt servertest";
             mail.Body = "Detta är ett automatiskt test av epostservern.";
             mail.BodyEncoding = Encoding.GetEncoding(1252);
             mail.SubjectEncoding = Encoding.GetEncoding(1252);
             mail.Attachments.Add(new Attachment(a.Location));
             var oClient = new SmtpClient("localhost", 25);
             oClient.Send(mail);

             // Check that the message exists
             string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");

             CustomAssert.IsNotEmpty(message, message);
             CustomAssert.IsTrue(message.Contains(signature), message);
        }
Esempio n. 43
0
        public void SingleLatinCharacterRecipient()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var 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");

             CustomAssert.IsTrue(messageText.Contains("To: \"=?utf-8?B?w5Y=?=\" <*****@*****.**>"));
        }
Esempio n. 44
0
        public void SwedishCharactersInBody()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var message = new hMailServer.Message();
             message.AddRecipient("Ö", account.Address);
             message.Charset = "utf-8";
             message.Body = "Test ÅÄÖ Test.";

             string body = message.Body;
             CustomAssert.IsTrue(body.Contains("Test ÅÄÖ Test."));
        }
Esempio n. 45
0
        public void TestMailCreationPlainText()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var 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);

             CustomAssert.IsTrue(header.Contains("Content-Type: text/plain; charset=\"utf-8\""));
             CustomAssert.IsTrue(header.Contains("Content-Transfer-Encoding: quoted-printable"));
             CustomAssert.IsTrue(messageText.Contains("Hello"));
        }
Esempio n. 46
0
        public void TestMailCreationUnicodeAndAttachment()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             string filename = Path.Combine(Path.GetTempPath(), "dummy.txt");
             File.WriteAllText(filename, "tjena moss");

             var message = new hMailServer.Message();
             message.AddRecipient("", account.Address);
             message.Charset = "utf-8";
             message.Attachments.Add(filename);
             // may cause an CustomAssert.
             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);

             CustomAssert.IsTrue(header.Contains("Content-Type: multipart/mixed; charset=\"utf-8\""));

             File.Delete(filename);
        }
Esempio n. 47
0
        public void TestMailCreationUnicodeBodyAndHtml()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var 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");

             CustomAssert.IsTrue(messageText.Contains("Content-Type: text/html; charset=\"utf-8\""));
             CustomAssert.IsTrue(messageText.Contains("Content-Type: text/plain; charset=\"utf-8\""));
        }
Esempio n. 48
0
        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);
        }
Esempio n. 49
0
        public void TestEncodeWord()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             string croatianAndDanish = "ʒʥʨPiskefløde";
             var 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];

             CustomAssert.AreEqual(apiMessage.Subject, croatianAndDanish);
             string fileContents = File.ReadAllText(apiMessage.Filename);
             CustomAssert.IsFalse(fileContents.Contains(croatianAndDanish));
        }
Esempio n. 50
0
        public void TestUnderscoreInBody()
        {
            string body = "underscore_in_body\r\n";

             var message = new hMailServer.Message();
             message.Body = body;
             CustomAssert.AreEqual(body, message.Body);
        }
Esempio n. 51
0
        public void TestSendMessage()
        {
            Account oAccount1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to the account.
             var oMessage = new hMailServer.Message();

             CustomAssert.AreEqual(0, oMessage.State);

             oMessage.AddRecipient("Martin", oAccount1.Address);
             oMessage.Body = "Välkommen till verkligheten";
             oMessage.Subject = "Hej";
             oMessage.Save();

             CustomAssert.AreEqual(1, oMessage.State);

             // Check that the message exists
             string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

             CustomAssert.IsNotEmpty(message);
             CustomAssert.Less(0, message.IndexOf("Hej"));
        }