Example #1
3
        public void TestSearchOR()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

             ;
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             if (oSimulator.Search("OR SINCE 28-May-2001 ON 28-May-2001 ALL") != "1")
             {
            throw new Exception("ERROR - Search or flag failed");
             }

             if (oSimulator.Search("OR SINCE 28-May-2012 ON 28-May-2012 ALL") != "")
             {
            throw new Exception("ERROR - Search or flag failed");
             }

             string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToUpper();
             if (oSimulator.Search("OR SINCE 28-May-2017 ON " + formattedToday + " ALL") != "1")
             {
            throw new Exception("ERROR - Search or flag failed");
             }

             string formatted2001 = new DateTime(2001,01,01).ToString("dd-MMM-yyyy").ToUpper();
             if (oSimulator.Search("OR SINCE 28-May-2008 ON " + formatted2001 + " ALL") != "1")
             {
            throw new Exception("ERROR - Search or flag failed");
             }
        }
Example #2
0
        public void TestRenameRootPublicFolder()
        {
            hMailServer.IMAPFolders folders = _application.Settings.PublicFolders;
            hMailServer.IMAPFolder  folder  = folders.Add("ShareA");
            folder.Save();

            hMailServer.IMAPFolderPermission permission = folder.Permissions.Add();
            permission.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeAnyone;
            permission.set_Permission(hMailServer.eACLPermission.ePermissionLookup, true);
            permission.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
            permission.set_Permission(hMailServer.eACLPermission.ePermissionDeleteMailbox, true);
            permission.Save();

            hMailServer.IMAPFolder folder2 = folders.Add("ShareB");
            folder2.Save();

            hMailServer.IMAPFolderPermission permission2 = folder2.Permissions.Add();
            permission2.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeAnyone;
            permission2.set_Permission(hMailServer.eACLPermission.ePermissionLookup, true);
            permission2.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
            permission2.set_Permission(hMailServer.eACLPermission.ePermissionDeleteMailbox, true);
            permission2.Save();

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

            IMAPSimulator simulator1 = new IMAPSimulator();

            simulator1.ConnectAndLogon(account.Address, "test");
            Assert.IsTrue(simulator1.SelectFolder("#Public.ShareA"));
            Assert.IsTrue(simulator1.SelectFolder("#Public.ShareB"));
            Assert.IsTrue(simulator1.RenameFolder("#Public.ShareA", "#Public.ShareB.ShareA"));
            Assert.IsFalse(simulator1.SelectFolder("#Public.ShareA"));
            Assert.IsTrue(simulator1.SelectFolder("#Public.ShareB"));
            Assert.IsTrue(simulator1.SelectFolder("#Public.ShareB.ShareA"));
        }
Example #3
0
        public void TestCreateLongFolder()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.LogonWithLiteral(oAccount.Address, "test");

            string folderName = "";

            for (int i = 0; i < 255; i++)
            {
                folderName = folderName + "A";
            }

            string result = oSimulator.Send("A01 CREATE " + folderName);

            Assert.IsTrue(result.Contains("A01 OK"));
            Assert.IsTrue(oSimulator.SelectFolder(folderName));

            folderName = "";
            for (int i = 0; i < 256; i++)
            {
                folderName = folderName + "A";
            }

            result = oSimulator.Send("A01 CREATE " + folderName);
            Assert.IsTrue(result.Contains("A01 NO"));
            Assert.IsFalse(oSimulator.SelectFolder(folderName));

            oSimulator.Disconnect();
        }
Example #4
0
        public void TestIMAPServer()
        {
            Utilities.DeleteCurrentDefaultLog();

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

            for (int i = 0; i < 30; i++)
            {
                try
                {
                    IMAPSimulator imapSim = new IMAPSimulator(true, 14300);
                    imapSim.ConnectAndLogon(account.Address, "test");
                    Assert.IsTrue(imapSim.SelectFolder("Inbox"), "SelectInbox");
                    imapSim.CreateFolder("Test");
                    Assert.IsTrue(imapSim.SelectFolder("Test"), "SelectTest");
                    Assert.IsTrue(imapSim.Logout(), "Logout");

                    imapSim.Disconnect();
                    break;
                }
                catch (Exception)
                {
                    if (i == 29)
                    {
                        throw;
                    }
                }
            }
        }
Example #5
0
        public void TestExpunge()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1);

            IMAPSimulator simulator = new IMAPSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.SelectFolder("Inbox");
            Assert.IsTrue(simulator.SetFlagOnMessage(1, true, @"\Deleted"));

            IMAPSimulator secondSimulator = new IMAPSimulator();

            secondSimulator.ConnectAndLogon(oAccount.Address, "test");
            string result = secondSimulator.ExamineFolder("INBOX");

            Assert.IsTrue(result.Contains("1 EXISTS"), result);
            Assert.IsFalse(secondSimulator.Expunge());

            simulator.SelectFolder("INBOX");
            Assert.IsTrue(simulator.Expunge());

            simulator.Close();
            secondSimulator.Close();
        }
Example #6
0
        public void TestSortReverseArrival()
        {
            hMailServer.Domain  oDomain  = _application.Domains[0];
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

            // The two messages needs to be sent a second apart, so we actually need to pause a bit here.

            System.Threading.Thread.Sleep(1000);
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            Assert.AreEqual("1 2", oSimulator.Sort("(ARRIVAL) UTF-8 ALL"));
            Assert.AreEqual("2 1", oSimulator.Sort("(REVERSE ARRIVAL) UTF-8 ALL"));
        }
        public void TestRetrievalOfMessageInDeletedFolderUsingIMAP()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text;

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

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody");

            hMailServer.IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");;

            Utilities.AssertMessageExistsInFolder(inbox, 1);

            hMailServer.Message message = inbox.Messages[0];

            DirectoryInfo dir    = new DirectoryInfo(Path.GetFullPath(message.Filename));
            DirectoryInfo parent = dir.Parent.Parent.Parent;

            parent.Delete(true);

            IMAPSimulator sim = new IMAPSimulator();

            sim.ConnectAndLogon(account.Address, "test");
            sim.SelectFolder("INBOX");
            string result = sim.Fetch("1 BODY[1]");

            Assert.IsTrue(result.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename)));
            Utilities.AssertReportedError();
        }
Example #8
0
        public void TestPOP3TransactionSafety()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"));
            POP3Simulator.AssertMessageCount(account.Address, "test", 1);

            POP3Simulator sim = new POP3Simulator();

            sim.ConnectAndLogon(account.Address, "test");

            // Now delete the message using an IMAP client.
            IMAPSimulator imapSimulator = new IMAPSimulator();

            Assert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(imapSimulator.SelectFolder("INBOX"));
            Assert.IsTrue(imapSimulator.SetDeletedFlag(1));
            Assert.IsTrue(imapSimulator.Expunge());
            Assert.AreEqual(0, imapSimulator.GetMessageCount("Inbox"));

            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"));
            IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1);

            // This deletion should not have any effect, since the POP3 connection is referencing an old message.
            sim.DELE(1);
            sim.QUIT();

            Assert.AreEqual(1, imapSimulator.GetMessageCount("Inbox"));
        }
Example #9
0
        public void TestFetchEnvelopeWithDateContainingQuote()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string message = "From: Someone <*****@*****.**>" + Environment.NewLine +
                             "To: Someoen <*****@*****.**>" + Environment.NewLine +
                             "Date: Wed, 22 Apr 2009 11:05:09 \"GMT\"" + Environment.NewLine +
                             "Subject: Something" + Environment.NewLine +
                             Environment.NewLine +
                             "Hello" + Environment.NewLine;

            SMTPClientSimulator smtpSimulator = new SMTPClientSimulator();

            smtpSimulator.SendRaw(account.Address, account.Address, message);

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

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(account.Address, "test");
            oSimulator.SelectFolder("INBOX");
            string result = oSimulator.Fetch("1 ENVELOPE");

            oSimulator.Disconnect();

            Assert.IsTrue(result.Contains("Wed, 22 Apr 2009 11:05:09 GMT"));
        }
Example #10
0
        public void TestSubjectSearchMultipleMatches()
        {
            hMailServer.Domain  oDomain  = _application.Domains[0];
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            oSMTP.Send("*****@*****.**", "*****@*****.**", "TestA", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 3);

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            Assert.AreEqual("1 3", oSimulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test1\""));
            Assert.AreEqual("2", oSimulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"TestA\""));
            Assert.AreEqual("3 1", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test1\""));
            Assert.AreEqual("2", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"TestA\""));
            Assert.AreEqual("3 1", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT) \"Test1\""));
            Assert.AreEqual("2", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT) \"TestA\""));
        }
Example #11
0
        public void TestSearchON()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            ;
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            string formattedTomorrow = (DateTime.Now + new TimeSpan(1, 0, 0, 0)).ToString("dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToUpper();
            string formattedToday    = DateTime.Now.ToString("dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToUpper();

            if (oSimulator.Search("ON " + formattedTomorrow) != "")
            {
                throw new Exception("ERROR - Search or flag failed");
            }

            if (oSimulator.Search("ON " + formattedToday) != "1")
            {
                throw new Exception("ERROR - Search or flag failed");
            }
        }
Example #12
0
        public void TestSearchORWithLiterals3()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            ;
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");

            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            string result = oSimulator.Send("A01 SEARCH ALL OR (HEADER SUBJECT {5}");

            result = oSimulator.Send("Test5) (HEADER SUBJECT {5}");
            result = oSimulator.Send("Test2)");
            Assert.IsTrue(result.StartsWith("* SEARCH 2"));
        }
Example #13
0
        public void TestSearchORWithParenthesisSubjectNested()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            ;
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            if (oSimulator.Search("ALL (OR (HEADER SUBJECT \"Test1\") (HEADER SUBJECT \"Test2\"))") != "1 2")
            {
                throw new Exception("ERROR - Search or flag failed");
            }
        }
Example #14
0
        public void TestNestedOrSearch()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            ;
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search");

            IMAPSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1);

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            oSimulator.SelectFolder("INBOX");

            string result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008");

            Assert.IsTrue(result.StartsWith("* SEARCH 1"), result);

            result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR SMALLER 1 LARGER 10000");
            Assert.IsTrue(result.StartsWith("* SEARCH\r\n"), result);

            result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SMALLER 1 LARGER 10000 SMALLER 10000");
            Assert.IsTrue(result.StartsWith("* SEARCH 1\r\n"), result);
        }
Example #15
0
        public void TestSearchUTF8TEXT()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string body = Utilities.GetResource("Messages.MessageContainingGreekSubject.txt");

            SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body);

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

            IMAPSimulator oSimulator = new IMAPSimulator();

            Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            string result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK");

            Assert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT 標準語");
            Assert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK標準語");
            Assert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣKWHAT標準語");
            Assert.AreEqual("", result);
        }
Example #16
0
        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"));
        }
Example #17
0
        public void TestSortReverseSize()
        {
            hMailServer.Domain  oDomain  = _application.Domains[0];
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            StringBuilder longBodyString = new StringBuilder();

            longBodyString.Append('A', 10000);

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", longBodyString.ToString());
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "Test body");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            Assert.AreEqual("2 1", oSimulator.Sort("(SIZE) UTF-8 ALL"));
            Assert.AreEqual("1 2", oSimulator.Sort("(REVERSE SIZE) UTF-8 ALL"));
        }
Example #18
0
        public void TestDateSortOrder()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("Inbox"));

             string response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 22:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 13:00:00 +0000");
             Assert.IsTrue(response.Contains("* 1 EXISTS"), response);

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 21:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 14:00:00 +0000");
             Assert.IsTrue(response.Contains("* 2 EXISTS"), response);

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 20:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 12:00:00 +0000");
             Assert.IsTrue(response.Contains("* 3 EXISTS"), response);

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {37}", "Date: Wed, 15 Dec 2010 11:00:00 +0000");
             Assert.IsTrue(response.Contains("* 4 EXISTS"), response);

             string sortDateResponse = oSimulator.SendSingleCommand("A10 SORT (DATE) US-ASCII ALL");

             Assert.IsTrue(sortDateResponse.Contains(" 4 3 1 2"));
             oSimulator.Disconnect();
        }
Example #19
0
        public void TestDateSortOrder()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.LogonWithLiteral("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("Inbox"));

            string response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 22:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 13:00:00 +0000");

            Assert.IsTrue(response.Contains("* 1 EXISTS"), response);

            response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 21:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 14:00:00 +0000");
            Assert.IsTrue(response.Contains("* 2 EXISTS"), response);

            response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 20:00:00 +0200\" {37}", "Date: Wed, 15 Dec 2010 12:00:00 +0000");
            Assert.IsTrue(response.Contains("* 3 EXISTS"), response);

            response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {37}", "Date: Wed, 15 Dec 2010 11:00:00 +0000");
            Assert.IsTrue(response.Contains("* 4 EXISTS"), response);

            string sortDateResponse = oSimulator.SendSingleCommand("A10 SORT (DATE) US-ASCII ALL");

            Assert.IsTrue(sortDateResponse.Contains(" 4 3 1 2"));
            oSimulator.Disconnect();
        }
Example #20
0
        public void TestChangeSeenFlag()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1);

            IMAPSimulator simulator = new IMAPSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.ExamineFolder("Inbox");
            string flags      = simulator.GetFlags(1);
            string body       = simulator.Fetch("1 RFC822");
            string flagsAfter = simulator.GetFlags(1);

            simulator.Close();
            simulator.Disconnect();

            Assert.AreEqual(flags, flagsAfter);

            IMAPSimulator secondSimulator = new IMAPSimulator();

            secondSimulator.ConnectAndLogon(oAccount.Address, "test");
            secondSimulator.SelectFolder("Inbox");
            string secondFlags      = secondSimulator.GetFlags(1);
            string secondBody       = secondSimulator.Fetch("1 RFC822");
            string secondFlagsAfter = secondSimulator.GetFlags(1);

            secondSimulator.Close();
            secondSimulator.Disconnect();

            Assert.AreNotEqual(secondFlags, secondFlagsAfter);
        }
Example #21
0
        public void TestChangeRecentFlag()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1);

            IMAPSimulator simulator = new IMAPSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            string result = simulator.ExamineFolder("Inbox");

            Assert.IsTrue(result.Contains("* 1 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();

            simulator = new IMAPSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            Assert.IsTrue(simulator.SelectFolder("Inbox", out result));
            Assert.IsTrue(result.Contains("* 1 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();

            simulator = new IMAPSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            result = simulator.ExamineFolder("Inbox");
            Assert.IsTrue(result.Contains("* 0 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();
        }
Example #22
0
        public void TestDateSortOrderNonexistantDate()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("Inbox"));

             string response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 22:00:00 +0200\" {4}", "ABCD");
             Assert.IsTrue(response.Contains("* 1 EXISTS"), response);

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 21:00:00 +0200\" {4}", "ABCD");
             Assert.IsTrue(response.Contains("* 2 EXISTS"), response);

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"22-Feb-2008 20:00:00 +0200\" {4}", "ABCD");
             Assert.IsTrue(response.Contains("* 3 EXISTS"), response);

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {4}", "ABCD");
             Assert.IsTrue(response.Contains("* 4 EXISTS"), response);

             /*
              * RFC 5256 "2.2. Sent Date" chapter. If the sent date cannot be determined (a Date: header is missing or cannot be parsed),
              * the INTERNALDATE for that message is used as the sent date.
              */

             string sortDateResponse = oSimulator.SendSingleCommand("A10 SORT (DATE) US-ASCII ALL");
             string sortArivalDateResponse = oSimulator.SendSingleCommand("A10 SORT (ARRIVAL) US-ASCII ALL");

             Assert.IsTrue(sortArivalDateResponse.Contains(" 3 2 1 4"));
             Assert.AreEqual(sortDateResponse, sortArivalDateResponse);
             oSimulator.Disconnect();
        }
Example #23
0
        public void TestSortSubjectSearch()
        {
            hMailServer.Domain  oDomain  = _application.Domains[0];
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "aa", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            oSMTP.Send("*****@*****.**", "*****@*****.**", "bb", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT bb"));
            Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT bb)"));
            Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT bb)"));

            Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT cc"));
            Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT cc)"));
            Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT cc)"));

            Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT bb HEADER SUBJECT cc"));
            Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT bb) (HEADER SUBJECT cc)"));
            Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT bb HEADER SUBJECT cc)"));
        }
Example #24
0
        public void TestFetchHeaderFieldsNot()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string message = "From: Someone <*****@*****.**>" + Environment.NewLine +
                             "To: Someoen <*****@*****.**>" + Environment.NewLine +
                             "Date: Wed, 22 Apr 2009 11:05:09 \"GMT\"" + Environment.NewLine +
                             "Subject: Something" + Environment.NewLine +
                             Environment.NewLine +
                             "Hello" + Environment.NewLine;

            SMTPClientSimulator smtpSimulator = new SMTPClientSimulator();

            Assert.IsTrue(smtpSimulator.SendRaw(account.Address, account.Address, message));

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

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(account.Address, "test");
            oSimulator.SelectFolder("INBOX");
            string result = oSimulator.Fetch("1 BODY.PEEK[HEADER.FIELDS.NOT (Subject From)]");

            oSimulator.Disconnect();


            Assert.IsTrue(result.Contains("Received:"), result);
            Assert.IsFalse(result.Contains("Subject:"), result);
            Assert.IsFalse(result.Contains("From:"), result);
            // The feedback should end with an empty header line.
            Assert.IsTrue(result.Contains("\r\n\r\n)"), result);
        }
Example #25
0
        public void TestFetch()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1");
            IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1);

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2");
            IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2);

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody3");
            IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3);


            IMAPSimulator sim = new IMAPSimulator();

            sim.ConnectAndLogon(account.Address, "test");
            sim.SelectFolder("INBOX");
            string result = sim.Fetch("1 BODY[1]");

            Assert.IsTrue(result.Contains("SampleBody1"), result);
            result = sim.Fetch("2 BODY[1]");
            Assert.IsTrue(result.Contains("SampleBody2"), result);
            result = sim.Fetch("3 BODY[1]");
            Assert.IsTrue(result.Contains("SampleBody3"), result);
        }
Example #26
0
        public void FolderMarkedAsReadOnlyWhenUserHasReadOnlyRights()
        {
            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.IMAPFolderPermission permission = folder.Permissions.Add();
             permission.PermissionAccountID = account1.ID;
             permission.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeUser;
             permission.set_Permission(hMailServer.eACLPermission.ePermissionLookup, true);
             permission.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
             permission.Save();

             string selectResult = string.Empty;

             IMAPSimulator oSimulator1 = new IMAPSimulator();
             oSimulator1.Connect();
             oSimulator1.LogonWithLiteral(account1.Address, "test");
             oSimulator1.SelectFolder("#Public.Share1", out selectResult);
             oSimulator1.Disconnect();

             Assert.IsTrue(selectResult.Contains("[READ-ONLY]"), selectResult);
             Assert.IsFalse(selectResult.Contains("[READ-WRITE]"), selectResult);
        }
Example #27
0
        public void TestNestedOrSearch()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

              ;
              hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              // Send a message to this account.
              SMTPClientSimulator oSMTP = new SMTPClientSimulator();
              oSMTP.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search");

              IMAPSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1);

              IMAPSimulator oSimulator = new IMAPSimulator();
              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.Logon("*****@*****.**", "test");
              oSimulator.SelectFolder("INBOX");

              string result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008");
              Assert.IsTrue(result.StartsWith("* SEARCH 1"), result);

              result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR SMALLER 1 LARGER 10000");
              Assert.IsTrue(result.StartsWith("* SEARCH\r\n"), result);

              result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SMALLER 1 LARGER 10000 SMALLER 10000");
              Assert.IsTrue(result.StartsWith("* SEARCH 1\r\n"), result);
        }
Example #28
0
        public void TestRenameSubFolderToMatchingName()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator = new IMAPSimulator();

            Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(oSimulator.CreateFolder("Folder1"));
            Assert.IsTrue(oSimulator.SelectFolder("Folder1"));

            string result = string.Empty;

            Assert.IsFalse(oSimulator.RenameFolder("Folder1", "Folder1.Sub1", out result));
            Assert.IsTrue(result.Contains("A folder cannot be moved into one of its subfolders."));
            Assert.IsTrue(oSimulator.SelectFolder("Folder1"));

            result = string.Empty;
            Assert.IsTrue(oSimulator.RenameFolder("Folder1", "Folder1Test", out result));
            Assert.IsTrue(oSimulator.SelectFolder("Folder1Test"));

            oSimulator.Disconnect();
        }
Example #29
0
        public void TestCreateFolderWithSlash()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              string folderName = "ABC\\123";

              IMAPSimulator oSimulator = new IMAPSimulator();
              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.Logon(oAccount.Address, "test");
              Assert.IsTrue(oSimulator.CreateFolder(folderName));
              Assert.IsTrue(oSimulator.List().Contains(folderName));
              Assert.IsTrue(oSimulator.SelectFolder(folderName));
              oSimulator.Disconnect();
        }
Example #30
0
        public void TestCreateFolderWithSlash()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string folderName = "ABC\\123";

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(oAccount.Address, "test");
            Assert.IsTrue(oSimulator.CreateFolder(folderName));
            Assert.IsTrue(oSimulator.List().Contains(folderName));
            Assert.IsTrue(oSimulator.SelectFolder(folderName));
            oSimulator.Disconnect();
        }
Example #31
0
        public void TestSearchUID()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

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

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            for (int i = 0; i < 3; i++)
            {
                oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            }

            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 3);

            // There should be 3 UID's, 1,2,3 or similar. No skips in the middle fo them.
            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            string result = oSimulator.SendSingleCommand("* UID SEARCH UID 1:*");

            // Potentially, the response is multiline. (UID RESPONSE and an OK line). We only want the first line...
            result = result.Substring(0, result.IndexOf("\r\n"));

            string [] tokens = Microsoft.VisualBasic.Strings.Split(result, " ", -1, Microsoft.VisualBasic.CompareMethod.Text);

            List <int> uids = new List <int>();

            foreach (string token in tokens)
            {
                int temp;
                if (Int32.TryParse(token, out temp))
                {
                    uids.Add(temp);
                }
            }

            Assert.AreEqual(3, uids.Count, result);

            Assert.AreEqual(1, uids[0]);
            Assert.AreEqual(2, uids[1]);
            Assert.AreEqual(3, uids[2]);
        }
Example #32
0
        public void TestSearchInvalidCharset()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody");

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

            IMAPSimulator oSimulator = new IMAPSimulator();

            Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            string result = oSimulator.SendSingleCommand("A01 SEARCH CHARSET NONEXISTANT ALL SUBJECT MySubject");

            Assert.AreEqual("A01 NO [BADCHARSET]\r\n", result);
        }
Example #33
0
        public void TestFolderCaseInLIST()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string folderName = "ABC.def.GHI";

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(oAccount.Address, "test");
            Assert.IsTrue(oSimulator.CreateFolder(folderName));
            Assert.IsFalse(oSimulator.List("ABC.DEF.*").Contains("ABC.def.GHI"));
            Assert.IsTrue(oSimulator.List("ABC.DEF.*").Contains("ABC.DEF.GHI"));
            Assert.IsFalse(oSimulator.List("ABC.def.*").Contains("ABC.DEF"));
            Assert.IsTrue(oSimulator.List("ABC.def.*").Contains("ABC.def.GHI"));
            Assert.IsTrue(oSimulator.SelectFolder(folderName));
            oSimulator.Disconnect();
        }
Example #34
0
        public void Test()
        {
            IMAPSimulator sim = new IMAPSimulator();

            sim.ConnectAndLogon("*****@*****.**", "test");
            sim.SelectFolder("Inbox");

            Stopwatch watch = new Stopwatch();

            watch.Start();
            string result = sim.SendSingleCommand("A282 SORT (SIZE) UTF-8");

            watch.Stop();

            long sortSizeTime = watch.ElapsedMilliseconds;

            watch.Reset();

            watch.Start();
            result = sim.SendSingleCommand("A282 SORT (FROM) UTF-8");
            watch.Stop();

            long sortFromTime = watch.ElapsedMilliseconds;

            watch.Reset();

            watch.Start();
            result = sim.SendSingleCommand("A282 SORT (FROM) UTF-8 1:15");
            watch.Stop();

            long sortFromTimeLimit15 = watch.ElapsedMilliseconds;

            watch.Reset();

            watch.Start();
            result = sim.SendSingleCommand("A282 SORT (DATE) UTF-8");
            watch.Stop();

            long sortDateTime = watch.ElapsedMilliseconds;

            watch.Reset();

            System.Threading.Thread.Sleep(1);
        }
Example #35
0
        public void TestRenameLongFolder()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.LogonWithLiteral(oAccount.Address, "test");
            Assert.IsTrue(oSimulator.CreateFolder("1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25"));
            Assert.IsTrue(oSimulator.CreateFolder("A"));

            Assert.IsFalse(oSimulator.RenameFolder("1", "A.1"));
            Assert.IsTrue(oSimulator.RenameFolder("1.2.3", "A.1"));
            Assert.IsTrue(oSimulator.SelectFolder("A.1.4"));


            oSimulator.Disconnect();
        }
Example #36
0
        public void TestSearchSpecficUID()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            for (int i = 0; i < 5; i++)
            {
                oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            }

            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 5);

            hMailServer.Messages messages = oAccount.IMAPFolders.get_ItemByName("Inbox").Messages;

            int second = messages[1].UID;
            int third  = messages[2].UID;
            int fourth = messages[3].UID;


            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            string result = oSimulator.SendSingleCommand(string.Format("a01 SORT (REVERSE DATE) UTF-8 ALL UID {0},{1}", second, third));

            Assert.IsTrue(result.StartsWith("* SORT 3 2"));

            result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0},{1}", third, second));
            Assert.IsTrue(result.StartsWith("* SORT 2 3"));

            result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0}:{1}", second, fourth));
            Assert.IsTrue(result.StartsWith("* SORT 2 3 4"));

            result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0}:*", second));
            Assert.IsTrue(result.StartsWith("* SORT 2 3 4 5"));
        }
Example #37
0
        public void TestAppendFolderNameInOctet()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             oSimulator.SelectFolder("INBOX");
             oSimulator.CreateFolder("MONK");
             oSimulator.SendRaw("A01 APPEND {4}\r\n");
             string result = oSimulator.Receive();
             Assert.IsTrue(result.StartsWith("+ Ready for additional command text."));

             oSimulator.SendRaw("MONK (\\Seen) \"20-Jan-2009 12:59:50 +0100\" {5}\r\n");
             result = oSimulator.Receive();
             Assert.IsTrue(result.StartsWith("+ Ready for literal data"));

             oSimulator.SendRaw("WOOOT\r\n");
             result = oSimulator.Receive();

             Assert.AreEqual("A01 OK APPEND completed\r\n", result);
        }
Example #38
0
        public void TestSubjectSearchValueWithParanthesis()
        {
            hMailServer.Domain oDomain = _application.Domains[0];
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send("*****@*****.**", "*****@*****.**", "Te(st1", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
             oSMTP.Send("*****@*****.**", "*****@*****.**", "Te)st2", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             Assert.AreEqual("1", oSimulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"Te(st1\""));
             Assert.AreEqual("2", oSimulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"Te)st2\""));
        }
Example #39
0
        public void TestRenameToSubFolder()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral(oAccount.Address, "test");
             Assert.IsTrue(oSimulator.CreateFolder("1.2.3.4.5"));
             Assert.IsTrue(oSimulator.CreateFolder("A"));
             Assert.IsTrue(oSimulator.RenameFolder("1", "A.1"));
             Assert.IsTrue(oSimulator.SelectFolder("A.1"));
             Assert.IsTrue(oSimulator.SelectFolder("A.1.2.3.4.5"));
             Assert.IsTrue(oSimulator.RenameFolder("A.1", "1"));
             Assert.IsFalse(oSimulator.SelectFolder("A.1"));
             Assert.IsFalse(oSimulator.SelectFolder("A.1.2.3.4.5"));
             Assert.IsTrue(oSimulator.SelectFolder("1"));
             Assert.IsTrue(oSimulator.SelectFolder("1.2.3.4.5"));

             oSimulator.Disconnect();
        }
Example #40
0
        public void TestRenameSubFolderToMatchingName()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              IMAPSimulator oSimulator = new IMAPSimulator();
              Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
              Assert.IsTrue(oSimulator.CreateFolder("Folder1"));
              Assert.IsTrue(oSimulator.SelectFolder("Folder1"));

              string result = string.Empty;
              Assert.IsFalse(oSimulator.RenameFolder("Folder1", "Folder1.Sub1", out result));
              Assert.IsTrue(result.Contains("A folder cannot be moved into one of its subfolders."));
              Assert.IsTrue(oSimulator.SelectFolder("Folder1"));

              result = string.Empty;
              Assert.IsTrue(oSimulator.RenameFolder("Folder1", "Folder1Test", out result));
              Assert.IsTrue(oSimulator.SelectFolder("Folder1Test"));

              oSimulator.Disconnect();
        }
Example #41
0
        public void TestRenameRootPublicFolder()
        {
            hMailServer.IMAPFolders folders = _application.Settings.PublicFolders;
             hMailServer.IMAPFolder folder = folders.Add("ShareA");
             folder.Save();

             hMailServer.IMAPFolderPermission permission = folder.Permissions.Add();
             permission.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeAnyone;
             permission.set_Permission(hMailServer.eACLPermission.ePermissionLookup, true);
             permission.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
             permission.set_Permission(hMailServer.eACLPermission.ePermissionDeleteMailbox, true);
             permission.Save();

             hMailServer.IMAPFolder folder2 = folders.Add("ShareB");
             folder2.Save();

             hMailServer.IMAPFolderPermission permission2 = folder2.Permissions.Add();
             permission2.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeAnyone;
             permission2.set_Permission(hMailServer.eACLPermission.ePermissionLookup, true);
             permission2.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
             permission2.set_Permission(hMailServer.eACLPermission.ePermissionDeleteMailbox, true);
             permission2.Save();

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

             IMAPSimulator simulator1 = new IMAPSimulator();
             simulator1.ConnectAndLogon(account.Address, "test");
             Assert.IsTrue(simulator1.SelectFolder("#Public.ShareA"));
             Assert.IsTrue(simulator1.SelectFolder("#Public.ShareB"));
             Assert.IsTrue(simulator1.RenameFolder("#Public.ShareA", "#Public.ShareB.ShareA"));
             Assert.IsFalse(simulator1.SelectFolder("#Public.ShareA"));
             Assert.IsTrue(simulator1.SelectFolder("#Public.ShareB"));
             Assert.IsTrue(simulator1.SelectFolder("#Public.ShareB.ShareA"));
        }
Example #42
0
        public void TestRenameLongFolder()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral(oAccount.Address, "test");
             Assert.IsTrue(oSimulator.CreateFolder("1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25"));
             Assert.IsTrue(oSimulator.CreateFolder("A"));

             Assert.IsFalse(oSimulator.RenameFolder("1", "A.1"));
             Assert.IsTrue(oSimulator.RenameFolder("1.2.3", "A.1"));
             Assert.IsTrue(oSimulator.SelectFolder("A.1.4"));

             oSimulator.Disconnect();
        }
Example #43
0
        public void TestSearchUTF8TEXT()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             string body = Utilities.GetResource("Messages.MessageContainingGreekSubject.txt");
             SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body);

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

             IMAPSimulator oSimulator = new IMAPSimulator();
             Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             string result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK");
             Assert.AreEqual("1", result);

             result = oSimulator.Search("CHARSET UTF-8 ALL TEXT 標準語");
             Assert.AreEqual("1", result);

             result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK標準語");
             Assert.AreEqual("1", result);

             result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣKWHAT標準語");
             Assert.AreEqual("", result);
        }
Example #44
0
        public void TestSortReverseSize()
        {
            hMailServer.Domain oDomain = _application.Domains[0];
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             StringBuilder longBodyString = new StringBuilder();
             longBodyString.Append('A', 10000);

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", longBodyString.ToString());
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

             oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "Test body");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             Assert.AreEqual("2 1", oSimulator.Sort("(SIZE) UTF-8 ALL"));
             Assert.AreEqual("1 2", oSimulator.Sort("(REVERSE SIZE) UTF-8 ALL"));
        }
Example #45
0
        public void TestSortDeletedOrAnswered()
        {
            hMailServer.Domain oDomain = _application.Domains[0];
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send("*****@*****.**", "*****@*****.**", "aa", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
             oSMTP.Send("*****@*****.**", "*****@*****.**", "bb", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

             IMAPSimulator oSimulator = new IMAPSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             Assert.AreEqual("", oSimulator.Sort("(DATE) UTF-8 ALL OR ANSWERED DELETED"));
        }
        public void TestRetrievalOfMessageInDeletedFolderUsingIMAP()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();
             string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text;

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

             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody");

             hMailServer.IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); ;

             Utilities.AssertMessageExistsInFolder(inbox, 1);

             hMailServer.Message message = inbox.Messages[0];

             DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(message.Filename));
             DirectoryInfo parent = dir.Parent.Parent.Parent;
             parent.Delete(true);

             IMAPSimulator sim = new IMAPSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             sim.SelectFolder("INBOX");
             string result = sim.Fetch("1 BODY[1]");

             Assert.IsTrue(result.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename)));
             Utilities.AssertReportedError();
        }
Example #47
0
        public void TestSearchInvalidCharset()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             SMTPClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody");

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

             IMAPSimulator oSimulator = new IMAPSimulator();
             Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             string result = oSimulator.SendSingleCommand("A01 SEARCH CHARSET NONEXISTANT ALL SUBJECT MySubject");
             Assert.AreEqual("A01 NO [BADCHARSET]\r\n", result);
        }
Example #48
0
        public void TestSearchORWithParenthesisSubjectNested()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

              ;
              hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              // Send a message to this account.
              SMTPClientSimulator oSMTP = new SMTPClientSimulator();
              oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
              IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
              oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
              IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

              IMAPSimulator oSimulator = new IMAPSimulator();

              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.Logon("*****@*****.**", "test");
              Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

              if (oSimulator.Search("ALL (OR (HEADER SUBJECT \"Test1\") (HEADER SUBJECT \"Test2\"))") != "1 2")
              {
              throw new Exception("ERROR - Search or flag failed");
              }
        }
Example #49
0
        public void TestSearch()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "se'*****@*****.**", "test");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send(oAccount.Address, oAccount.Address, "Search test", "This is a test of IMAP Search");

             IMAPSimulator.AssertMessageCount(oAccount.Address, "test", "INBOX", 1);

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(oAccount.Address, "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             oSimulator.SetFlagOnFirstMessage(true, "\\ANSWERED");
             if (oSimulator.Search("ANSWERED") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\ANSWERED");
             if (oSimulator.Search("ANSWERED") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\DELETED");
             if (oSimulator.Search("DELETED") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\DELETED");
             if (oSimulator.Search("DELETED") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\DRAFT");
             if (oSimulator.Search("DRAFT") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\DRAFT");
             if (oSimulator.Search("DRAFT") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\FLAGGED");
             if (oSimulator.Search("FLAGGED  ") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\FLAGGED");
             if (oSimulator.Search("FLAGGED") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\SEEN");
             if (oSimulator.Search("SEEN") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\SEEN");
             if (oSimulator.Search("SEEN") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\ANSWERED");
             if (oSimulator.Search("UNANSWERED") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\ANSWERED");
             if (oSimulator.Search("UNANSWERED") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\DELETED");
             if (oSimulator.Search("UNDELETED") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\DELETED");
             if (oSimulator.Search("UNDELETED") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\DRAFT");
             if (oSimulator.Search("UNDRAFT") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\DRAFT");
             if (oSimulator.Search("UNDRAFT") != "1")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(true, "\\FLAGGED");
             if (oSimulator.Search("UNFLAGGED") != "")
            throw new Exception("ERROR - Search or flag failed");

             oSimulator.SetFlagOnFirstMessage(false, "\\FLAGGED");
             if (oSimulator.Search("UNFLAGGED") != "1")
            throw new Exception("ERROR - Search or flag failed");

             // SEARCH using LARGER & SMALLER
             if (oSimulator.Search("SMALLER 10") != "")
            throw new Exception("ERROR - Search or flag failed");

             if (oSimulator.Search("SMALLER 10000") != "1")
            throw new Exception("ERROR - Search or flag failed");

             if (oSimulator.Search("LARGER 10") != "1")
            throw new Exception("ERROR - Search or flag failed");

             if (oSimulator.Search("LARGER 10000") != "")
            throw new Exception("ERROR - Search or flag failed");
        }
Example #50
0
        public void TestSearchRange()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

              ;
              hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              // Send a message to this account.
              SMTPClientSimulator oSMTP = new SMTPClientSimulator();
              for (int i = 0; i <5 ; i++)
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");

              IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 5);

              IMAPSimulator oSimulator = new IMAPSimulator();
              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.Logon("*****@*****.**", "test");
              Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

              string result = oSimulator.SendSingleCommand("a01 search 2:4");
              Assert.IsTrue(result.StartsWith("* SEARCH 2 3 4"));

              result = oSimulator.SendSingleCommand("a01 search 3,2");
              Assert.IsTrue(result.StartsWith("* SEARCH 2 3"));

              result = oSimulator.SendSingleCommand("a01 search 3:*");
              Assert.IsTrue(result.StartsWith("* SEARCH 3 4 5"));

              result = oSimulator.SendSingleCommand("a01 search 3,1,3");
              Assert.IsTrue(result.StartsWith("* SEARCH 1 3"));

              result = oSimulator.SendSingleCommand("a01 search 1:*");
              Assert.IsTrue(result.StartsWith("* SEARCH 1 2 3 4 5"));
        }
Example #51
0
        public void TestSearchUID()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

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

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             for (int i = 0; i < 3; i++)
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 3);

             // There should be 3 UID's, 1,2,3 or similar. No skips in the middle fo them.
             IMAPSimulator oSimulator = new IMAPSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             string result = oSimulator.SendSingleCommand("* UID SEARCH UID 1:*");

             // Potentially, the response is multiline. (UID RESPONSE and an OK line). We only want the first line...
             result = result.Substring(0, result.IndexOf("\r\n"));

             string [] tokens = Microsoft.VisualBasic.Strings.Split(result, " ", -1, Microsoft.VisualBasic.CompareMethod.Text);

             List<int> uids = new List<int>();
             foreach (string token in tokens)
             {
            int temp;
            if (Int32.TryParse(token, out temp))
            {
               uids.Add(temp);
            }
             }

             Assert.AreEqual(3, uids.Count, result);

             Assert.AreEqual(1, uids[0]);
             Assert.AreEqual(2, uids[1]);
             Assert.AreEqual(3, uids[2]);
        }
Example #52
0
        public void TestCreateLongFolder()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral(oAccount.Address, "test");

             string folderName = "";
             for (int i = 0; i < 255; i++)
            folderName = folderName + "A";

             string result = oSimulator.Send("A01 CREATE " + folderName);
             Assert.IsTrue(result.Contains("A01 OK"));
             Assert.IsTrue(oSimulator.SelectFolder(folderName));

             folderName = "";
             for (int i = 0; i < 256; i++)
            folderName = folderName + "A";

             result = oSimulator.Send("A01 CREATE " + folderName);
             Assert.IsTrue(result.Contains("A01 NO"));
             Assert.IsFalse(oSimulator.SelectFolder(folderName));

             oSimulator.Disconnect();
        }
Example #53
0
        public void TestSortSubjectSearch()
        {
            hMailServer.Domain oDomain = _application.Domains[0];
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send("*****@*****.**", "*****@*****.**", "aa", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
             oSMTP.Send("*****@*****.**", "*****@*****.**", "bb", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

             IMAPSimulator oSimulator = new IMAPSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT bb"));
             Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT bb)"));
             Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT bb)"));

             Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT cc"));
             Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT cc)"));
             Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT cc)"));

             Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT bb HEADER SUBJECT cc"));
             Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT bb) (HEADER SUBJECT cc)"));
             Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT bb HEADER SUBJECT cc)"));
        }
Example #54
0
        public void TestBasics()
        {
            // Fetch the default domain

             // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Add a rule to this account.
             SingletonProvider<Utilities>.Instance.AddSpamRule(oAccount);
             SingletonProvider<Utilities>.Instance.AddCorporateRule(oAccount);
             SingletonProvider<Utilities>.Instance.AddExactMatchRule(oAccount);

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "**SPAM** INBOX->SPAM", "Detta ska hamna i mappen Inbox\\Spam");

             // Corporate folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "**CORPORATE** INBOX->CORPORATE", "Detta ska hamna i mappen Inbox\\Corporate");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "CORPORATE EXACT MATCH", "Detta ska hamna i mappen Inbox\\Corporate");

             // Inbox folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "**CORPORATE EXACT MATCH**", "Detta ska hamna i mappen Inbox");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Detta ska hamna i mappen Inbox");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Detta ska hamna i mappen Inbox");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Detta ska hamna i mappen Inbox");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox.Spam", 1);
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox.Corporate", 2);
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 4);

             // Test move to imap with mail with multiple recipients.

             hMailServer.Account oAccount1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             hMailServer.Account oAccount2 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             SingletonProvider<Utilities>.Instance.AddSpamRule(oAccount1);

             // Send email to both recipients
             List<string> lstRecipients = new List<string>();
             lstRecipients.Add("*****@*****.**");
             lstRecipients.Add("*****@*****.**");

             string sBody = "Test of sending same email to multiple accounts.";

             oSMTP.Send(oAccount1.Address, lstRecipients, "**SPAM** INBOX->SPAM", sBody);

             IMAPSimulator.AssertMessageCount(oAccount1.Address, "test", "Inbox.Spam", 1);
             IMAPSimulator.AssertMessageCount(oAccount2.Address, "test", "Inbox", 1);

             IMAPSimulator sim = new IMAPSimulator();
             sim.ConnectAndLogon(oAccount2.Address, "test");
             Assert.IsFalse(sim.SelectFolder("Inbox.Spam"));
        }
Example #55
0
        public void TestSortReverseArrival()
        {
            hMailServer.Domain oDomain = _application.Domains[0];
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);

             // The two messages needs to be sent a second apart, so we actually need to pause a bit here.

             System.Threading.Thread.Sleep(1000);
             oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             Assert.AreEqual("1 2", oSimulator.Sort("(ARRIVAL) UTF-8 ALL"));
             Assert.AreEqual("2 1", oSimulator.Sort("(REVERSE ARRIVAL) UTF-8 ALL"));
        }
Example #56
0
        public void TestSearchUSASCII()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             SMTPClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody");

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

             IMAPSimulator oSimulator = new IMAPSimulator();
             Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             string result = oSimulator.Search("CHARSET US-ASCII ALL SUBJECT MySubject");
             Assert.AreEqual("1", result);

             result = oSimulator.Search("CHARSET US-ASCII ALL SUBJECT MySubjact");
             Assert.AreEqual("", result);
        }
Example #57
0
        public void TestIdle()
        {
            _settings.IMAPIdleEnabled = true;

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

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(account.Address, "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             oSimulator.StartIdle();

             if (oSimulator.GetPendingDataExists())
            throw new Exception("Unexpected data exists");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             oSMTP.Send(account.Address, account.Address, "IDLE Test", "This is a test of IDLE");

             string data;
             Assert.IsTrue(oSimulator.EndIdle(false, out data));
        }
Example #58
0
        public void TestSearchSpecficUID()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Send a message to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             for (int i = 0; i < 5; i++)
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 5);

             hMailServer.Messages messages = oAccount.IMAPFolders.get_ItemByName("Inbox").Messages;

             int second = messages[1].UID;
             int third = messages[2].UID;
             int fourth = messages[3].UID;

             IMAPSimulator oSimulator = new IMAPSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

             string result = oSimulator.SendSingleCommand(string.Format("a01 SORT (REVERSE DATE) UTF-8 ALL UID {0},{1}", second, third));
             Assert.IsTrue(result.StartsWith("* SORT 3 2"));

             result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0},{1}", third, second));
             Assert.IsTrue(result.StartsWith("* SORT 2 3"));

             result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0}:{1}", second, fourth));
             Assert.IsTrue(result.StartsWith("* SORT 2 3 4"));

             result = oSimulator.SendSingleCommand(string.Format("a01 SORT (DATE) UTF-8 ALL UID {0}:*", second));
             Assert.IsTrue(result.StartsWith("* SORT 2 3 4 5"));
        }
Example #59
0
        public void TestSearchWithLiterals()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

              ;
              hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              // Send a message to this account.
              SMTPClientSimulator oSMTP = new SMTPClientSimulator();
              oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
              IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
              oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
              IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

              IMAPSimulator oSimulator = new IMAPSimulator();

              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.Logon("*****@*****.**", "test");

              Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

              string result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test1");
              Assert.IsTrue(result.StartsWith("* SEARCH 1\r\n"));

              result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test2");
              Assert.IsTrue(result.StartsWith("* SEARCH 2\r\n"));
        }
Example #60
0
        public void TestFolderCaseInLSUB()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              string folderName = "ABC.def.GHI";

              IMAPSimulator oSimulator = new IMAPSimulator();
              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.Logon(oAccount.Address, "test");
              Assert.IsTrue(oSimulator.CreateFolder(folderName));
              Assert.IsTrue(oSimulator.Subscribe(folderName));
              Assert.IsFalse(oSimulator.LSUB("ABC.DEF.*").Contains("ABC.def.GHI"));
              Assert.IsTrue(oSimulator.LSUB("ABC.DEF.*").Contains("ABC.DEF.GHI"));
              Assert.IsFalse(oSimulator.LSUB("ABC.def.*").Contains("ABC.DEF"));
              Assert.IsTrue(oSimulator.LSUB("ABC.def.*").Contains("ABC.def.GHI"));
              Assert.IsTrue(oSimulator.SelectFolder(folderName));
              oSimulator.Disconnect();
        }