Ejemplo n.º 1
0
        public void TestIMAPServer()
        {
            TestSetup.DeleteCurrentDefaultLog();

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

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

               imapSim.Disconnect();
               break;
            }
            catch (Exception)
            {
               if (i == 29)
                  throw;
            }
             }
        }
Ejemplo n.º 2
0
        public void TestChangeSeenFlag()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

             var simulator = new IMAPClientSimulator();
             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();

             CustomAssert.AreEqual(flags, flagsAfter);

             var secondSimulator = new IMAPClientSimulator();
             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();

             CustomAssert.AreNotEqual(secondFlags, secondFlagsAfter);
        }
Ejemplo n.º 3
0
        public void TestDateSortOrder()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             var oSimulator = new IMAPClientSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral("*****@*****.**", "test");
             CustomAssert.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");
             CustomAssert.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");
             CustomAssert.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");
             CustomAssert.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");
             CustomAssert.IsTrue(response.Contains("* 4 EXISTS"), response);

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

             CustomAssert.IsTrue(sortDateResponse.Contains(" 4 3 1 2"));
             oSimulator.Disconnect();
        }
Ejemplo n.º 4
0
        public void FolderMarkedAsReadOnlyWhenUserHasReadOnlyRights()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

             IMAPFolders publicFolders = _settings.PublicFolders;
             IMAPFolder folder = publicFolders.Add("Share1");
             folder.Save();

             IMAPFolderPermission permission = folder.Permissions.Add();
             permission.PermissionAccountID = account1.ID;
             permission.PermissionType = eACLPermissionType.ePermissionTypeUser;
             permission.set_Permission(eACLPermission.ePermissionLookup, true);
             permission.set_Permission(eACLPermission.ePermissionRead, true);
             permission.Save();

             string selectResult = string.Empty;

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

             CustomAssert.IsTrue(selectResult.Contains("[READ-ONLY]"), selectResult);
             CustomAssert.IsFalse(selectResult.Contains("[READ-WRITE]"), selectResult);
        }
Ejemplo n.º 5
0
        public void TestNestedOrSearch()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

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

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

             var oSimulator = new IMAPClientSimulator();
             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");
             CustomAssert.IsTrue(result.StartsWith("* SEARCH 1"), result);

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

             result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SMALLER 1 LARGER 10000 SMALLER 10000");
             CustomAssert.IsTrue(result.StartsWith("* SEARCH 1\r\n"), result);
        }
Ejemplo n.º 6
0
        public void TestChangeRecentFlag()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

             var simulator = new IMAPClientSimulator();
             simulator.ConnectAndLogon(oAccount.Address, "test");
             string result = simulator.ExamineFolder("Inbox");
             CustomAssert.IsTrue(result.Contains("* 1 RECENT"), result);
             simulator.Close();
             simulator.Disconnect();

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

             simulator = new IMAPClientSimulator();
             simulator.ConnectAndLogon(oAccount.Address, "test");
             result = simulator.ExamineFolder("Inbox");
             CustomAssert.IsTrue(result.Contains("* 0 RECENT"), result);
             simulator.Close();
             simulator.Disconnect();
        }
Ejemplo n.º 7
0
        public void TestBodyStructureWithNonLatinCharacter()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             string attachmentName = "本本本.zip";

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

             var message = new Message();
             message.Charset = "utf-8";
             message.AddRecipient("test", account.Address);
             message.From = "Test";
             message.FromAddress = account.Address;
             message.Body = "hejsan";
             message.Attachments.Add(filename);
             message.Save();

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

             var oSimulator = new IMAPClientSimulator();
             oSimulator.ConnectAndLogon(account.Address, "test");
             oSimulator.SelectFolder("INBOX");
             string result = oSimulator.Fetch("1 BODYSTRUCTURE");
             oSimulator.Disconnect();

             // utf-8 representation of 本本本.zip:
             CustomAssert.IsTrue(result.Contains("=?utf-8?B?5pys5pys5pys?=.zip"));
        }
Ejemplo n.º 8
0
        public void TestAddMessage()
        {
            Application app = SingletonProvider<TestSetup>.Instance.GetApp();
             Utilities utilities = app.Utilities;

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

             // Create a new folder.
             IMAPFolder folder = account.IMAPFolders.get_ItemByName("INBOX");
             folder.Save();

             for (int i = 0; i < 3; i++)
             {
            hMailServer.Message message = folder.Messages.Add();
            message.set_Flag(eMessageFlag.eMFSeen, true);
            message.Save();

            POP3ClientSimulator.AssertMessageCount(account.Address, "test", ((i + 1)*2) - 1);

            SMTPClientSimulator.StaticSend("*****@*****.**", account.Address, "Test", "Test");
            POP3ClientSimulator.AssertMessageCount(account.Address, "test", (i + 1)*2);
             }

             POP3ClientSimulator.AssertMessageCount(account.Address, "test", 6);

             var sim = new IMAPClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             sim.SelectFolder("Inbox");

             string response = sim.Fetch("1:6 UID");

             string[] lines = Strings.Split(response, Environment.NewLine, -1, CompareMethod.Text);

             var uids = new List<string>();

             foreach (string line in lines)
             {
            int paraPos = line.IndexOf("(");
            int paraEndPos = line.IndexOf(")");

            if (paraPos < 0 || paraEndPos < 0)
               continue;

            string paraContent = line.Substring(paraPos + 1, paraEndPos - paraPos - 1);

            if (!uids.Contains(paraContent))
               uids.Add(paraContent);
             }

             CustomAssert.AreEqual(6, uids.Count);

             // Make sure the UIDS are sorted properly by creating a copy, sort the copy
             // and then compare to original.
             var copy = new List<string>();
             copy.InsertRange(0, uids);
             copy.Sort();

             CustomAssert.AreEqual(copy, uids);
        }
Ejemplo n.º 9
0
        public void TestCreateFolderWithSlash()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             const string folderName = "ABC\\123";

             var oSimulator = new IMAPClientSimulator();
             oSimulator.Connect();
             oSimulator.Logon(oAccount.Address, "test");
             CustomAssert.IsTrue(oSimulator.CreateFolder(folderName));
             CustomAssert.IsTrue(oSimulator.List().Contains(folderName));
             CustomAssert.IsTrue(oSimulator.SelectFolder(folderName));
             oSimulator.Disconnect();
        }
Ejemplo n.º 10
0
        public void TestAppendFolderNameInOctet()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new IMAPClientSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             oSimulator.SelectFolder("INBOX");
             oSimulator.CreateFolder("MONK");
             oSimulator.SendRaw("A01 APPEND {4}\r\n");
             string result = oSimulator.Receive();
             CustomAssert.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();
             CustomAssert.IsTrue(result.StartsWith("+ Ready for literal data"));

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

             CustomAssert.AreEqual("A01 OK APPEND completed\r\n", result);
        }
Ejemplo n.º 11
0
        public void TestFetch()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

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

             var sim = new IMAPClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             sim.SelectFolder("INBOX");
             string result = sim.Fetch("1 BODY[1]");
             CustomAssert.IsTrue(result.Contains("SampleBody1"), result);
             result = sim.Fetch("2 BODY[1]");
             CustomAssert.IsTrue(result.Contains("SampleBody2"), result);
             result = sim.Fetch("3 BODY[1]");
             CustomAssert.IsTrue(result.Contains("SampleBody3"), result);
        }
Ejemplo n.º 12
0
        public void TestDateSortOrderNonexistantDate()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             var oSimulator = new IMAPClientSimulator();

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

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

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

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

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {4}",
                                                            "ABCD");
             CustomAssert.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");

             CustomAssert.IsTrue(sortArivalDateResponse.Contains(" 3 2 1 4"));
             CustomAssert.AreEqual(sortDateResponse, sortArivalDateResponse);
             oSimulator.Disconnect();
        }
Ejemplo n.º 13
0
        public void TestSearchUTF8TEXT()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             string body = TestSetup.GetResource("Messages.MessageContainingGreekSubject.txt");
             SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body);

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

             var oSimulator = new IMAPClientSimulator();
             CustomAssert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX"));

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

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

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

             result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣKWHAT標準語");
             CustomAssert.AreEqual("", result);
        }
Ejemplo n.º 14
0
        public void TestRenameSubFolderToMatchingName()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new IMAPClientSimulator();
             CustomAssert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(oSimulator.CreateFolder("Folder1"));
             CustomAssert.IsTrue(oSimulator.SelectFolder("Folder1"));

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

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

             oSimulator.Disconnect();
        }
Ejemplo n.º 15
0
        public void TestRenameToSubFolder()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new IMAPClientSimulator();

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

             oSimulator.Disconnect();
        }
Ejemplo n.º 16
0
        public void TestRenameLongFolder()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new IMAPClientSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral(oAccount.Address, "test");
             CustomAssert.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"));
             CustomAssert.IsTrue(oSimulator.CreateFolder("A"));

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

             oSimulator.Disconnect();
        }
Ejemplo n.º 17
0
        public void TestRenameRootPublicFolder()
        {
            IMAPFolders folders = _application.Settings.PublicFolders;
             IMAPFolder folder = folders.Add("ShareA");
             folder.Save();

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

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

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

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

             var simulator1 = new IMAPClientSimulator();
             simulator1.ConnectAndLogon(account.Address, "test");
             CustomAssert.IsTrue(simulator1.SelectFolder("#Public.ShareA"));
             CustomAssert.IsTrue(simulator1.SelectFolder("#Public.ShareB"));
             CustomAssert.IsTrue(simulator1.RenameFolder("#Public.ShareA", "#Public.ShareB.ShareA"));
             CustomAssert.IsFalse(simulator1.SelectFolder("#Public.ShareA"));
             CustomAssert.IsTrue(simulator1.SelectFolder("#Public.ShareB"));
             CustomAssert.IsTrue(simulator1.SelectFolder("#Public.ShareB.ShareA"));
        }
Ejemplo n.º 18
0
        public void TestBasics()
        {
            // Fetch the default domain

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

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

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

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

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

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

             // Send email to both recipients
             var lstRecipients = new List<string> {"*****@*****.**", "*****@*****.**"};

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

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

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

             var sim = new IMAPClientSimulator();
             sim.ConnectAndLogon(oAccount2.Address, "test");
             CustomAssert.IsFalse(sim.SelectFolder("Inbox.Spam"));
        }
Ejemplo n.º 19
0
        public void TestFolderCaseInLSUB()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             string folderName = "ABC.def.GHI";

             var oSimulator = new IMAPClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(oAccount.Address, "test");
             CustomAssert.IsTrue(oSimulator.CreateFolder(folderName));
             CustomAssert.IsTrue(oSimulator.Subscribe(folderName));
             CustomAssert.IsFalse(oSimulator.LSUB("ABC.DEF.*").Contains("ABC.def.GHI"));
             CustomAssert.IsTrue(oSimulator.LSUB("ABC.DEF.*").Contains("ABC.DEF.GHI"));
             CustomAssert.IsFalse(oSimulator.LSUB("ABC.def.*").Contains("ABC.DEF"));
             CustomAssert.IsTrue(oSimulator.LSUB("ABC.def.*").Contains("ABC.def.GHI"));
             CustomAssert.IsTrue(oSimulator.SelectFolder(folderName));
             oSimulator.Disconnect();
        }
Ejemplo n.º 20
0
        public void TestSearchInvalidCharset()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

             var oSimulator = new IMAPClientSimulator();
             CustomAssert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX"));

             string result = oSimulator.SendSingleCommand("A01 SEARCH CHARSET NONEXISTANT ALL SUBJECT MySubject");
             CustomAssert.AreEqual("A01 NO [BADCHARSET]\r\n", result);
        }
Ejemplo n.º 21
0
        public void TestSearch()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

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

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

             var oSimulator = new IMAPClientSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(oAccount.Address, "test");
             CustomAssert.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");
        }
Ejemplo n.º 22
0
        public void TestSearchLargeBody()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             var body = new StringBuilder();
             body.AppendLine("From: [email protected]");
             body.AppendLine("Subject: Test");
             body.AppendLine();
             for (int i = 0; i < 20000; i++) // One megabye body.
            body.AppendLine("12345678901234567890123456789012345678901234567890");
             body.AppendLine("TestString");
             body.AppendLine();

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

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

             var oSimulator = new IMAPClientSimulator();
             CustomAssert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX"));
             string result = oSimulator.Search("CHARSET UTF-8 ALL TEXT InvalidText");
             CustomAssert.AreEqual("", result);

             result = oSimulator.Search("CHARSET UTF-8 ALL TEXT TestStringA");
             CustomAssert.AreEqual("", result);

             result = oSimulator.Search("CHARSET UTF-8 ALL TEXT TestString");
             CustomAssert.AreEqual("1", result);

             result = oSimulator.Search("CHARSET UTF-8 ALL TEXT TestStr");
             CustomAssert.AreEqual("1", result);

             result = oSimulator.Search("UNDELETED BODY \"TestString\"");
             CustomAssert.AreEqual("1", result);

             oSimulator.Close();
        }
Ejemplo n.º 23
0
        public void TestCreateLongFolder()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new IMAPClientSimulator();

             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);
             CustomAssert.IsTrue(result.Contains("A01 OK"));
             CustomAssert.IsTrue(oSimulator.SelectFolder(folderName));

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

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

             oSimulator.Disconnect();
        }
Ejemplo n.º 24
0
        public void TestSearchUSASCII()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

             var oSimulator = new IMAPClientSimulator();
             CustomAssert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX"));

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

             result = oSimulator.Search("CHARSET US-ASCII ALL SUBJECT MySubjact");
             CustomAssert.AreEqual("", result);
        }
Ejemplo n.º 25
0
        public void TestSearchON()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

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

             var oSimulator = new IMAPClientSimulator();

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

             string formattedTomorrow =
            (DateTime.Now + new TimeSpan(1, 0, 0, 0)).ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture).ToUpper();
             string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", 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");
             }
        }
Ejemplo n.º 26
0
        public void TestSearchRange()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

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

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

             var oSimulator = new IMAPClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX"));

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

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

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

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

             result = oSimulator.SendSingleCommand("a01 search 1:*");
             CustomAssert.IsTrue(result.StartsWith("* SEARCH 1 2 3 4 5"));
        }
Ejemplo n.º 27
0
        public void TestSearchORWithParenthesisSubjectNested()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

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

             var oSimulator = new IMAPClientSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             CustomAssert.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");
             }
        }
Ejemplo n.º 28
0
        public void TestSearchOR()
        {
            SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

             var oSimulator = new IMAPClientSimulator();

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

             CustomAssert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2001 ON 28-May-2001 ALL"));
             CustomAssert.IsNullOrEmpty(oSimulator.Search("OR SINCE 28-May-2020 ON 28-May-2012 ALL"));

             string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture).ToUpper();
             CustomAssert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2017 ON " + formattedToday + " ALL"));

             string formatted2001 = new DateTime(2001, 01, 01).ToString("dd-MMM-yyyy").ToUpper();
             CustomAssert.AreEqual("1", oSimulator.Search("OR SINCE 28-May-2008 ON " + formatted2001 + " ALL"));
        }
Ejemplo n.º 29
0
        public void TestSearchUID()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

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

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

             // There should be 3 UID's, 1,2,3 or similar. No skips in the middle fo them.
             var oSimulator = new IMAPClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon("*****@*****.**", "test");
             CustomAssert.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 = Strings.Split(result, " ", -1, CompareMethod.Text);

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

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

             CustomAssert.AreEqual(1, uids[0]);
             CustomAssert.AreEqual(2, uids[1]);
             CustomAssert.AreEqual(3, uids[2]);
        }
Ejemplo n.º 30
0
        public void TestSearchWithLiterals()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

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

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

             var oSimulator = new IMAPClientSimulator();

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

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

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

             result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test2");
             CustomAssert.IsTrue(result.StartsWith("* SEARCH 2\r\n"));
        }