Ejemplo n.º 1
0
        public void DeletingSingleMessageShouldNotAffectOtherMessages()
        {
            var account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Add 3 messages to the inbox
            var imapClientSimulator = new ImapClientSimulator();

            imapClientSimulator.ConnectAndLogon("*****@*****.**", "test");
            for (int i = 0; i < 3; i++)
            {
                imapClientSimulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {4}", "ABCD");
            }
            imapClientSimulator.Disconnect();

            var messages = account.Messages;

            var firstId  = messages[0].ID;
            var secondId = messages[1].ID;
            var thirdId  = messages[2].ID;

            messages.DeleteByDBID(secondId);

            Assert.AreEqual(2, messages.Count);
            Assert.AreEqual(firstId, messages[0].ID);
            Assert.AreEqual(thirdId, messages[1].ID);

            imapClientSimulator.ConnectAndLogon("*****@*****.**", "test");
            var imapMessageCount = imapClientSimulator.GetMessageCount("Inbox");

            Assert.AreEqual(imapMessageCount, messages.Count);
        }
Ejemplo n.º 2
0
        public void TestFolderDeletion()
        {
            // Create a test account
            // Fetch the default domain
            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPFolder folder = account1.IMAPFolders.Add("TestFolder1");

            folder.Save();

            var simulator1 = new ImapClientSimulator();

            simulator1.ConnectAndLogon(account1.Address, "test");
            string result = simulator1.List();

            Assert.IsTrue(result.Contains(folder.Name));
            simulator1.Disconnect();

            // Delete the folder and confirm it's no longer listed.
            folder.Delete();

            simulator1.ConnectAndLogon(account1.Address, "test");
            result = simulator1.List();
            Assert.IsFalse(result.Contains(folder.Name));
            simulator1.Disconnect();
        }
Ejemplo n.º 3
0
        public void ChangingFlagShouldAffectAllConnections()
        {
            var account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "Test");

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

            var sim1 = new ImapClientSimulator();

            Assert.IsTrue(sim1.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(sim1.SelectFolder("Inbox"));

            var sim2 = new ImapClientSimulator();

            Assert.IsTrue(sim2.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(sim2.SelectFolder("Inbox"));

            sim1.SetFlagOnMessage(1, true, "\\Deleted");

            var flags1 = sim1.GetFlags(1);
            var flags2 = sim2.GetFlags(1);

            Assert.IsTrue(flags2.Contains(@"* 1 FETCH (FLAGS (\Deleted))"), flags2);
            Assert.IsTrue(flags2.Contains(@"* 1 FETCH (FLAGS (\Deleted) UID 1)"), flags2);
        }
Ejemplo n.º 4
0
        public void TestChangeSeenFlag()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            Assert.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();

            Assert.AreNotEqual(secondFlags, secondFlagsAfter);
        }
Ejemplo n.º 5
0
        public void TestChangeRecentFlag()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

            simulator = new ImapClientSimulator();
            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 ImapClientSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            result = simulator.ExamineFolder("Inbox");
            Assert.IsTrue(result.Contains("* 0 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();
        }
Ejemplo n.º 6
0
        public void TestExpunge()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test");
            Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1);

            var simulator = new ImapClientSimulator();

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

            var secondSimulator = new ImapClientSimulator();

            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();
        }
Ejemplo n.º 7
0
        public void TestImportOfMessageIntoOtherFolder()
        {
            string @messageText =
                "From: [email protected]\r\n" +
                "\r\n" +
                "Test\r\n";

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

            account.IMAPFolders.Add("Woho");

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

            Directory.CreateDirectory(accountPath);
            string fileName = Path.Combine(accountPath, "something.eml");

            File.WriteAllText(fileName, messageText);

            Assert.IsTrue(_application.Utilities.ImportMessageFromFileToIMAPFolder(fileName, account.ID, "Woho"));

            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 0);
            var sim = new ImapClientSimulator();

            sim.ConnectAndLogon("*****@*****.**", "test");
            Assert.AreEqual(1, sim.GetMessageCount("Woho"));
            sim.Disconnect();
        }
Ejemplo n.º 8
0
        public void TestIMAPServer()
        {
            LogHandler.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");
                    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;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void TestRetrievalOfMessageInDeletedFolderUsingIMAP()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

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

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

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

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


            CustomAsserts.AssertFolderMessageCount(inbox, 1);

            Message message = inbox.Messages[0];

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

            parent.Delete(true);

            var sim = new ImapClientSimulator();

            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)));
            CustomAsserts.AssertReportedError("Message retrieval failed because message file");
        }
Ejemplo n.º 10
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();

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

            var simulator = new ImapClientSimulator();

            simulator.ConnectAndLogon(account.Address, "test");
            simulator.SelectFolder("INBOX");
            string result = simulator.Fetch("1 BODYSTRUCTURE");

            simulator.Disconnect();

            // utf-8 representation of 本本本.zip:
            Assert.IsTrue(result.Contains("=?utf-8?B?5pys5pys5pys?=.zip"));
        }
Ejemplo n.º 11
0
        public void TestPOP3TransactionSafety()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody");
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);

            var sim = new Pop3ClientSimulator();

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

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

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

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody");
            ImapClientSimulator.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"));
        }
Ejemplo n.º 12
0
        public void TestFetchBody()
        {
            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();

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

            var simulator = new ImapClientSimulator();

            simulator.ConnectAndLogon(account.Address, "test");
            simulator.SelectFolder("INBOX");
            string bodyStructureResponse = simulator.Fetch("1 BODYSTRUCTURE");
            string bodyResponse          = simulator.Fetch("1 BODY");

            simulator.Disconnect();

            Assert.IsTrue(bodyStructureResponse.Contains("BOUNDARY"));
            Assert.IsFalse(bodyResponse.Contains("BOUNDARY"));
        }
Ejemplo n.º 13
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]");

            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);
        }
Ejemplo n.º 14
0
        public void TestIMAPServerNormal()
        {
            var sim = new ImapClientSimulator();

            sim.ConnectAndLogon(GetUsername(), GetPassword());
            EnsureNoPassword();
        }
Ejemplo n.º 15
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();

            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);
        }
Ejemplo n.º 16
0
        private static ImapClientSimulator ConnectAndLogon()
        {
            ImapClientSimulator sim = new ImapClientSimulator();

            sim.ConnectAndLogon("*****@*****.**", "test");
            return(sim);
        }
Ejemplo n.º 17
0
        public void SetupEnvWith50MillionMessages()
        {
            const int accountCount = 1;
            const int folderCount  = 1;
            const int messageCount = 100000;

            var accounts = new List <string>();

            for (int accountIdx = 0; accountIdx < accountCount; accountIdx++)
            {
                var account = string.Format("test-{0}@test.com", accountIdx);
                accounts.Add(account);

                TestTracer.WriteTraceInfo("Setting up {0}...", account);
                SingletonProvider <TestSetup> .Instance.AddAccount(_domain, account, "test");
            }

            var folders = new List <string>();

            for (int folderIdx = 0; folderIdx < folderCount; folderIdx++)
            {
                folders.Add(string.Format("Folder-{0}", folderIdx));
            }

            var parallelOptions = new ParallelOptions();

            parallelOptions.MaxDegreeOfParallelism = 10;

            var watch = new Stopwatch();

            watch.Start();

            Parallel.ForEach(accounts, parallelOptions, account =>
            {
                TestTracer.WriteTraceInfo("Processing messages for {0}...", account);

                var sim = new ImapClientSimulator();
                Assert.IsTrue(sim.ConnectAndLogon(account, "test"));

                foreach (var folder in folders)
                {
                    Assert.IsTrue(sim.CreateFolder(folder));

                    for (int i = 0; i < messageCount; i++)
                    {
                        string f = sim.SendSingleCommandWithLiteral("A01 APPEND " + folder + " {1}", "A");
                        Assert.IsTrue(f.Contains("A01 OK APPEND completed"), f);
                    }
                }

                sim.Disconnect();
            });

            watch.Stop();
            TestTracer.WriteTraceInfo(watch.ElapsedMilliseconds.ToString());
        }
Ejemplo n.º 18
0
        public void TestChangeFlags()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SmtpClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test");
            Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1);

            var simulator = new ImapClientSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.ExamineFolder("Inbox");
            Assert.IsFalse(simulator.SetFlagOnMessage(1, true, @"\Deleted"));
        }
Ejemplo n.º 19
0
        public void TestIMAPLogonFailure()
        {
            _settings.AutoBanOnLogonFailure         = true;
            _settings.MaxInvalidLogonAttempts       = 4;
            _settings.MaxInvalidLogonAttemptsWithin = 5;
            _settings.AutoBanMinutes = 3;

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

            var sim = new ImapClientSimulator();

            Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
            sim.Disconnect();

            // confirm that we can retrieve welcome message.
            Assert.IsTrue(sim.GetWelcomeMessage().StartsWith("* OK"));

            // fail to log on 3 times.
            for (int i = 0; i < 4; i++)
            {
                string errorMessage;

                Assert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage));
                sim.Disconnect();

                if (i == 3)
                {
                    Assert.IsTrue(errorMessage.Contains("Too many invalid logon attempts."));
                }
            }

            Assert.IsTrue(sim.GetWelcomeMessage().Length == 0);

            string logText = LogHandler.ReadCurrentDefaultLog();

            Assert.IsTrue(logText.Contains("Blocked either by IP range or by connection limit."), logText);
        }
Ejemplo n.º 20
0
        public void TestSaveMessageWithScriptAndMoveMessageWithGlobalRule()
        {
            _settings.Scripting.Enabled = true;

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

            var sim = new ImapClientSimulator();

            Assert.IsTrue(sim.ConnectAndLogon(testAccount.Address, "test"));

            // First deliver two messages to the inbox.
            SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");
            Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1);
            IMAPFolder inboxFolder = testAccount.IMAPFolders[0];

            Assert.AreEqual(1, inboxFolder.CurrentUID);
            Assert.AreEqual(1, inboxFolder.Messages[0].UID);
            Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 2"));

            SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");
            Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2);
            Assert.AreEqual(2, inboxFolder.CurrentUID);
            Assert.AreEqual(2, inboxFolder.Messages[1].UID);
            Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3"));

            CreateMessageModificationRule(_application.Rules);
            CreateMoveRule(_application.Rules, "TestFolder");


            // This message will be moved into the test folder.
            SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");

            // Wait for the message to arrive.
            CustomAsserts.AssertFolderExists(testAccount.IMAPFolders, "TestFolder");
            IMAPFolder testFolder = testAccount.IMAPFolders.get_ItemByName("TestFolder");

            CustomAsserts.AssertFolderMessageCount(testFolder, 1);

            // Inbox UID should not have changed since nothing has been added to the inbox.
            Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3"));

            // Since the message is placed in a new folder, it should receive a unique UID.
            string status = sim.Status("TestFolder", "UIDNEXT");

            Assert.IsTrue(status.Contains("UIDNEXT 2"), status);
            Assert.AreEqual(1, testFolder.CurrentUID);
            Assert.AreEqual(1, testFolder.Messages[0].UID);
        }
Ejemplo n.º 21
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();
         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);
      }
Ejemplo n.º 22
0
      public void TestEmptyPassword()
      {
         Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "");

         string message;
         var sim = new Pop3ClientSimulator();
         Assert.IsFalse(sim.ConnectAndLogon(account1.Address, "", out message));


         var simIMAP = new ImapClientSimulator();
         Assert.IsFalse(simIMAP.ConnectAndLogon(account1.Address, "", out message));
         Assert.AreEqual("A01 NO Invalid user name or password.\r\n", message);

         var simSMTP = new SmtpClientSimulator();
         CustomAsserts.Throws<AuthenticationException>(() => simSMTP.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "", out message));
         Assert.AreEqual("535 Authentication failed. Restarting authentication process.\r\n", message);
      }
Ejemplo n.º 23
0
        public void DeletingMultipleMessagesShouldSucceed()
        {
            var account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var imapClientSimulator = new ImapClientSimulator();

            imapClientSimulator.ConnectAndLogon("*****@*****.**", "test");
            for (int i = 0; i < 10; i++)
            {
                imapClientSimulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {4}", "ABCD");
            }
            imapClientSimulator.Disconnect();

            var messages = account.Messages;

            var messagesToDelete = new List <long>();
            var messagesToSave   = new List <long>();

            for (int i = 0; i < 10; i++)
            {
                if (i <= 3)
                {
                    messagesToDelete.Add(messages[i].ID);
                }
                else
                {
                    messagesToSave.Add(messages[i].ID);
                }
            }

            // Delete the 4 messages
            foreach (var messageToDelete in messagesToDelete)
            {
                messages.DeleteByDBID(messageToDelete);
            }

            // Should be 6 remaining
            Assert.AreEqual(6, messages.Count);

            // Validate that the 6 remaining are the expected ones
            foreach (var messageToSave in messagesToSave)
            {
                var message = messages.get_ItemByDBID(messageToSave);
                Assert.IsNotNull(message);
            }
        }
Ejemplo n.º 24
0
        public void TestListWithReference()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var oSimulator = new ImapClientSimulator();

            oSimulator.ConnectAndLogon(oAccount.Address, "test");
            oSimulator.CreateFolder("Main.Sub1.Sub2.Sub3");
            oSimulator.CreateFolder("SomeOtherFolder");

            oSimulator.Subscribe("Main");
            oSimulator.Subscribe("Main.Sub1");
            oSimulator.Subscribe("Main.Sub1.Sub2");
            oSimulator.Subscribe("Main.Sub1.Sub2.Sub3");
            oSimulator.Subscribe("SomeOtherFolder");

            string response = oSimulator.List("Main", "*", true);

            Assert.IsFalse(response.Contains("INBOX"));
            Assert.IsFalse(response.Contains("SomeOtherFolder"));
            Assert.IsTrue(response.Contains("* LIST (\\HasChildren) \".\" \"Main.Sub1\""));
            Assert.IsTrue(response.Contains("* LIST (\\HasChildren) \".\" \"Main.Sub1.Sub2\""));
            Assert.IsTrue(response.Contains("* LIST (\\HasNoChildren) \".\" \"Main.Sub1.Sub2.Sub3\""));

            response = oSimulator.List("Main.Sub1", "*", true);
            Assert.IsFalse(response.Contains("INBOX"));
            Assert.IsFalse(response.Contains("SomeOtherFolder"));
            Assert.IsTrue(response.Contains("* LIST (\\HasChildren) \".\" \"Main.Sub1.Sub2\""));
            Assert.IsTrue(response.Contains("* LIST (\\HasNoChildren) \".\" \"Main.Sub1.Sub2.Sub3\""));

            response = oSimulator.LSUB("Main", "*");
            Assert.IsFalse(response.Contains("INBOX"));
            Assert.IsFalse(response.Contains("SomeOtherFolder"));
            Assert.IsTrue(response.Contains("* LSUB (\\HasChildren) \".\" \"Main.Sub1\""));
            Assert.IsTrue(response.Contains("* LSUB (\\HasChildren) \".\" \"Main.Sub1.Sub2\""));
            Assert.IsTrue(response.Contains("* LSUB (\\HasNoChildren) \".\" \"Main.Sub1.Sub2.Sub3\""));

            response = oSimulator.LSUB("Main.Sub1", "*");
            Assert.IsFalse(response.Contains("INBOX"));
            Assert.IsFalse(response.Contains("SomeOtherFolder"));
            Assert.IsTrue(response.Contains("* LSUB (\\HasChildren) \".\" \"Main.Sub1.Sub2\""));
            Assert.IsTrue(response.Contains("* LSUB (\\HasNoChildren) \".\" \"Main.Sub1.Sub2.Sub3\""));

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

            var oSimulator = new ImapClientSimulator();

            Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(oSimulator.CreateFolder("A.B"));

            string result;

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

            Assert.IsTrue(oSimulator.SelectFolder("A.B"));

            oSimulator.Disconnect();
        }
Ejemplo n.º 26
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();
         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);
      }
Ejemplo n.º 27
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();

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

            Assert.AreEqual("", result);

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

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

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

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

            oSimulator.Close();
        }
Ejemplo n.º 28
0
        public void TestHierarchyDelimiterNamespaceResponse()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            Settings settings = _settings;

            settings.IMAPHierarchyDelimiter = "\\";
            string publicFolderName = _settings.IMAPPublicFolderName;

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

            var simulator = new ImapClientSimulator();

            simulator.ConnectAndLogon(account.Address, "test");
            string result = simulator.Send("A01 NAMESPACE");
            string correctNamespaceSetting = "* NAMESPACE ((\"\" \"\\\\\")) NIL ((\"" + publicFolderName +
                                             "\" \"\\\\\"))";

            Assert.IsTrue(result.Contains(correctNamespaceSetting), result);
            simulator.Disconnect();

            settings.IMAPHierarchyDelimiter = ".";

            simulator = new ImapClientSimulator();
            simulator.ConnectAndLogon(account.Address, "test");

            result = simulator.Send("A01 NAMESPACE");
            correctNamespaceSetting = "* NAMESPACE ((\"\" \".\")) NIL ((\"" + publicFolderName + "\" \".\"))";
            Assert.IsTrue(result.Contains(correctNamespaceSetting), result);
            simulator.Disconnect();

            settings.IMAPHierarchyDelimiter = "/";

            simulator = new ImapClientSimulator();
            simulator.ConnectAndLogon(account.Address, "test");

            result = simulator.Send("A01 NAMESPACE");
            correctNamespaceSetting = "* NAMESPACE ((\"\" \"/\")) NIL ((\"" + publicFolderName + "\" \"/\"))";
            Assert.IsTrue(result.Contains(correctNamespaceSetting), result);
            simulator.Disconnect();
        }
Ejemplo n.º 29
0
        public void TestListWithReferenceTestCase2()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var oSimulator = new ImapClientSimulator();

            oSimulator.ConnectAndLogon(oAccount.Address, "test");
            oSimulator.CreateFolder("INBOX.MyApp.SubFolder1");
            oSimulator.CreateFolder("INBOX.MyApp.SubFolder2");
            oSimulator.CreateFolder("INBOX.SomeOtherFolder");


            string response = oSimulator.List("INBOX.MyApp", "%.%", true);

            Assert.IsFalse(response.Contains("\"INBOX.MyApp\""));
            Assert.IsFalse(response.Contains("\"INBOX.SomeOtherFolder\""));
            Assert.IsTrue(response.Contains("* LIST (\\HasNoChildren) \".\" \"INBOX.MyApp.SubFolder1\""));
            Assert.IsTrue(response.Contains("* LIST (\\HasNoChildren) \".\" \"INBOX.MyApp.SubFolder2\""));

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

            for (int i = 1; i <= 3; i++)
            {
                SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test",
                                               "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n");
            }

            // Mark the second message as deleted using IMAP.
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3);

            var sim = new ImapClientSimulator();

            sim.ConnectAndLogon(account.Address, "test");
            sim.SelectFolder("INBOX");
            sim.SetDeletedFlag(2);
            sim.Disconnect();

            // Now list messages and confirm that all are listed.

            var pop3Client = new Pop3ClientSimulator();

            pop3Client.ConnectAndLogon(account.Address, "test");
            string listResponse = pop3Client.LIST();
            string uidlResponse = pop3Client.UIDL();

            Assert.IsTrue(listResponse.Contains("\r\n1"));
            Assert.IsTrue(listResponse.Contains("\r\n2"));
            Assert.IsTrue(listResponse.Contains("\r\n3"));
            Assert.IsTrue(listResponse.Contains("\r\n.\r\n"));
            Assert.IsTrue(listResponse.Contains("3 messages"));

            Assert.IsTrue(uidlResponse.Contains("\r\n1"));
            Assert.IsTrue(uidlResponse.Contains("\r\n2"));
            Assert.IsTrue(uidlResponse.Contains("\r\n3"));
            Assert.IsTrue(uidlResponse.Contains("\r\n.\r\n"));
            Assert.IsTrue(uidlResponse.Contains("3 messages"));
        }