Exemplo n.º 1
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)"));
        }
Exemplo n.º 2
0
        public void TestMetaDataSortSubjectSwedish()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

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

            // disable...
            SendMessage("Test Ä", "Body", "", "");
            IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1);

            SendMessage("Test Ö", "Body", "", "");
            IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2);

            SendMessage("Test Å", "Body", "", "");
            IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3);

            AssertAllMessagesIndexed();

            IMAPSimulator sim = new IMAPSimulator(account.Address, "test", "Inbox");

            string result = sim.Sort("(SUBJECT) UTF-8 ALL");

            Assert.AreEqual("3 1 2", result);

            // Disable the indexing functionality
            _indexing.Enabled = false;
            _indexing.Clear();

            // Make sure the sort order is the same.
            string resultAfter = sim.Sort("(SUBJECT) UTF-8 ALL");

            Assert.AreEqual(result, resultAfter);
        }
Exemplo n.º 3
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"));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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");
            }
        }
Exemplo n.º 6
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\""));
        }
Exemplo n.º 7
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");
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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"));
        }
Exemplo n.º 10
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"));
        }
Exemplo n.º 11
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"));
        }
Exemplo n.º 12
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]);
        }
Exemplo n.º 13
0
        public void TestFetchCharsetInQuotesWithoutQuotesWithSpace()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SMTPClientSimulator.StaticSendRaw(account.Address, account.Address,
                                              "From: [email protected]\r\n" +
                                              "Content-Type: text/plain; charset = iso-8859-1 \r\n" +
                                              "\r\n" +
                                              "Test\r\n");

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

            IMAPSimulator sim    = new IMAPSimulator(account.Address, "test", "Inbox");
            string        result = sim.Fetch("1 BODYSTRUCTURE");

            sim.Disconnect();

            Assert.IsTrue(result.Contains("(\"CHARSET\" \"iso-8859-1\")"), result);
        }
Exemplo n.º 14
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"));
        }
Exemplo n.º 15
0
        public void TestAliases()
        {
            // Fetch default domain

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

            // Add aliases
            SingletonProvider <Utilities> .Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**");

            SingletonProvider <Utilities> .Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**");

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            // Spam folder
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1");
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 2", "Mail 2");
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 3", "Mail 3");

            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 3);
        }
Exemplo n.º 16
0
        public void SizeAfterSend()
        {
            hMailServer.Domain domain = SingletonProvider <Utilities> .Instance.AddTestDomain();

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

            // Send a message
            for (int i = 0; i < 30; i++)
            {
                SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test message", "123456789012345678901234567890123456789012345678901234567890");
            }

            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 30);

            var size = account.Size;

            if (size == 0)
            {
                throw new Exception("Account is empty");
            }
        }
Exemplo n.º 17
0
        public void SizeIncreasedWhenMessageReceived()
        {
            hMailServer.Domain domain = SingletonProvider <Utilities> .Instance.AddTestDomain();

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

            string body = Utilities.CreateLargeDummyMailBody();

            // Send a message
            SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test message", body);
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);

            float sizeBefore = account.Size;

            SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test message", body);
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 2);

            float sizeAfter = account.Size;

            Assert.Greater(sizeAfter, sizeBefore);
        }
Exemplo n.º 18
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"));
        }
Exemplo n.º 19
0
        public void TestFetchInvalid()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1");
            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2");
            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("0 BODY[1]");

            Assert.IsTrue(result.StartsWith("A01 OK FETCH completed"));
            result = sim.Fetch("-1 BODY[1]");
            Assert.IsTrue(result.StartsWith("A01 BAD"));
            result = sim.Fetch("-100 BODY[1]");
            Assert.IsTrue(result.StartsWith("A01 BAD"));
        }
Exemplo n.º 20
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"));
        }
Exemplo n.º 21
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");
            }
        }