Пример #1
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 smtpClientSimulator = new SmtpClientSimulator();
             smtpClientSimulator.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");
             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);
        }
Пример #2
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 imapClientSimulator = new ImapClientSimulator();
             imapClientSimulator.Connect();
             imapClientSimulator.LogonWithLiteral(account1.Address, "test");
             imapClientSimulator.SelectFolder("#Public.Share1", out selectResult);
             imapClientSimulator.Disconnect();

             Assert.IsTrue(selectResult.Contains("[READ-ONLY]"), selectResult);
             Assert.IsFalse(selectResult.Contains("[READ-WRITE]"), selectResult);
        }
Пример #3
0
        public void ConfirmFileAddedToCorrectAccountFolder()
        {
            TestSetup testSetup = SingletonProvider<TestSetup>.Instance;
             Account oAccount = testSetup.AddAccount(_domain, "*****@*****.**", "test");
             var oSimulator = new ImapClientSimulator();

             // Confirm that the public folder is empty before we start our test.
             string publicDir = GetPublicDirectory();
             CustomAsserts.AssertFilesInDirectory(publicDir, 0);

             // Add a message to the inbox.
             oSimulator.Connect();
             oSimulator.LogonWithLiteral("*****@*****.**", "test");
             oSimulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {4}", "ABCD");

             // Confirm it exists in the IMAP folder.
             Assert.AreEqual(1, oSimulator.GetMessageCount("INBOX"));
             oSimulator.Disconnect();

             // The public directory should still be empty - the message was added to the user account.
             CustomAsserts.AssertFilesInDirectory(publicDir, 0);

             // There should be a single file in the users directory.
             CustomAsserts.AssertFilesInUserDirectory(oAccount, 1);
        }
Пример #4
0
        public void IfInReplyToFieldContainsQuoteThenFetchHeadersShouldEncodeIt()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             string message = "From: Someone <*****@*****.**>" + Environment.NewLine +
                          "To: Someoen <*****@*****.**>" + Environment.NewLine +
                          "In-Reply-To: ShouldBeEncodedDueToQuote\"" + Environment.NewLine +
                          "Subject: Something" + Environment.NewLine +
                          Environment.NewLine +
                          "Hello" + Environment.NewLine;

             var smtpSimulator = new SmtpClientSimulator();
             smtpSimulator.SendRaw(account.Address, account.Address, message);

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

             var oSimulator = new ImapClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(account.Address, "test");
             oSimulator.SelectFolder("INBOX");
             string result = oSimulator.Fetch("1 ENVELOPE");
             oSimulator.Disconnect();

             Assert.IsFalse(result.Contains("ShouldBeEncodedDueToQuote"));
        }
Пример #5
0
        public void TestBatchOfCommands()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new ImapClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(account.Address, "test");

             string commandSequence = "";
             for (int i = 0; i < 200; i++)
             {
            commandSequence += "A" + i.ToString() + " SELECT INBOX\r\n";
             }
             commandSequence = commandSequence.TrimEnd("\r\n".ToCharArray());

             string result = oSimulator.Send(commandSequence);
             Assert.IsFalse(result.StartsWith("* BYE"));

             oSimulator.Disconnect();

             sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(account.Address, "test");
             commandSequence = "";
             for (int i = 0; i < 500; i++)
             {
            commandSequence += "A" + i.ToString() + " SELECT INBOX\r\n";
             }
             commandSequence = commandSequence.TrimEnd("\r\n".ToCharArray());

             result = oSimulator.Send(commandSequence);
             Assert.IsFalse(result.StartsWith("* BYE Excessive number of buffered commands"));
             oSimulator.Disconnect();
        }
Пример #6
0
        public void TestMetaDataSortCC()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();
             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "meta'*****@*****.**", "test");

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

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

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

             AssertAllMessagesIndexed();

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

             string result = sim.Sort("(CC) 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("(CC) UTF-8 ALL");

             Assert.AreEqual(result, resultAfter);
        }
Пример #7
0
        public void TestDateSortOrder()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             var oSimulator = new ImapClientSimulator();

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

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

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

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

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

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

             Assert.IsTrue(sortDateResponse.Contains(" 4 3 1 2"));
             oSimulator.Disconnect();
        }
Пример #8
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);
        }
Пример #9
0
        public void ExamineFolderRequiresReadPermission()
        {
            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.Save();

             string selectResult = string.Empty;

             var imapClientSimulator = new ImapClientSimulator();
             imapClientSimulator.Connect();
             imapClientSimulator.LogonWithLiteral(account1.Address, "test");
             string examineResult = imapClientSimulator.ExamineFolder("#Public.Share1");
             imapClientSimulator.Disconnect();

             Assert.IsTrue(examineResult.Contains("ACL: Read permission denied (Required for EXAMINE command)."),
                       examineResult);
        }
Пример #10
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);
        }
Пример #11
0
        public void RequestingSameHeaderFieldMultipleTimesShouldReturnItOnce()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

             var smtpSimulator = new SmtpClientSimulator();
             smtpSimulator.SendRaw(account.Address, account.Address, message);

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

             var oSimulator = new ImapClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(account.Address, "test");
             oSimulator.SelectFolder("INBOX");
             string result = oSimulator.Fetch("1 BODY.PEEK[HEADER.FIELDS (Subject Subject)]");
             oSimulator.Disconnect();

             Assert.AreEqual(1, StringExtensions.Occurences(result, "SubjectText"));
        }
Пример #12
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();
        }
Пример #13
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;
            }
             }
        }
Пример #14
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);
             }

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

             Assert.AreEqual(copy, uids);
        }
Пример #15
0
 public void TestIMAPServerLiteral()
 {
     var sim = new ImapClientSimulator();
      sim.Connect();
      Assert.IsTrue(sim.Send("a01 login " + GetUsername() + " {4}").StartsWith("+"));
      sim.Send(GetPassword());
      EnsureNoPassword();
 }
Пример #16
0
        public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse()
        {
            var imapSimulator = new ImapClientSimulator(false, 143);
             imapSimulator.Connect();
             var data = imapSimulator.GetCapabilities();

             Assert.IsFalse(data.Contains("STARTTLS"));
        }
Пример #17
0
        public void IfStlsRequiredLogonShouldFailIfNoStls()
        {
            var imapSimulator = new ImapClientSimulator(false, 14303);
             imapSimulator.Connect();

             string errorMessage;
             Assert.IsFalse(imapSimulator.Logon(_account.Address, "test", out errorMessage));

             Assert.IsTrue(errorMessage.Contains("A01 BAD STARTTLS is required."));
        }
Пример #18
0
        public void IfStlsRequiredLogonShouldSucceedIfStls()
        {
            var imapSimulator = new ImapClientSimulator(false, 14303);
             imapSimulator.Connect();
             imapSimulator.SendSingleCommand("A01 STARTTLS");
             imapSimulator.Handshake();

             // command is sent over TLS.
             imapSimulator.GetCapabilities();

             Assert.IsTrue(imapSimulator.Logon(_account.Address, "test"));
        }
Пример #19
0
        public void TestCreateFolderWithHash()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new ImapClientSimulator();

             oSimulator.Connect();
             oSimulator.Logon(oAccount.Address, "test");
             Assert.IsFalse(oSimulator.CreateFolder("#Test"));
             Assert.IsTrue(oSimulator.CreateFolder("Test.#Testar"));
             oSimulator.Disconnect();
        }
Пример #20
0
        public void TestAppendBadLiteral()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new ImapClientSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral("*****@*****.**", "test");
             oSimulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {TEST}", "ABCD");
             Assert.AreEqual(0, oSimulator.GetMessageCount("INBOX"));
             oSimulator.Disconnect();
        }
Пример #21
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"));
        }
Пример #22
0
        public void TestParseMultipartNoBody()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             string body = TestSetup.GetResource("Messages.MultipartMessageWithNoMainBodyText.txt");
             SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, body);

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

             var imapSim = new ImapClientSimulator("*****@*****.**", "test", "INBOX");
             string result = imapSim.Fetch("1 (BODY.PEEK[HEADER] BODY.PEEK[TEXT])");

             imapSim.Logout();
        }
Пример #23
0
        public void IfStlsOptionalButSslRequiredByIpRangeForAuthThenAuthShouldFail()
        {
            var range = SingletonProvider<TestSetup>.Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");
             range.RequireSSLTLSForAuth = true;
             range.Save();

             var imapSimulator = new ImapClientSimulator(false, 14302);
             imapSimulator.Connect();

             string errorMessage;
             Assert.IsFalse(imapSimulator.Logon(_account.Address, "test", out errorMessage));
             Assert.IsTrue(errorMessage.Contains("A01 BAD A SSL/TLS-connection is required for authentication."));
        }
Пример #24
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");
             Assert.IsTrue(oSimulator.CreateFolder(folderName));
             Assert.IsTrue(oSimulator.List().Contains(folderName));
             Assert.IsTrue(oSimulator.SelectFolder(folderName));
             oSimulator.Disconnect();
        }
Пример #25
0
        public void TestCreateDeepFolder()
        {
            Account oAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new ImapClientSimulator();

             oSimulator.Connect();
             oSimulator.LogonWithLiteral(oAccount.Address, "test");
             string result =
            oSimulator.Send("A01 CREATE 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.26");
             Assert.IsTrue(result.Contains("A01 NO"));

             oSimulator.Disconnect();
        }
        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());
        }
Пример #27
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);
        }
Пример #28
0
        public static void AssertMessageCount(string accountName, string accountPassword, string folderName,
                                              int expectedCount)
        {
            if (expectedCount == 0)
            {
                // make sure that we aren't currently delivering messages.
                CustomAsserts.AssertRecipientsInDeliveryQueue(0);
            }

            var imap = new ImapClientSimulator();

            Assert.IsTrue(imap.ConnectAndLogon(accountName, accountPassword));

            if (expectedCount != 0)
            {
                imap.AssertFolderExists(folderName);
            }

            int currentCount = 0;
            int timeout      = 1000; // 1000 * 25 = 25 seconds.

            while (timeout > 0)
            {
                currentCount = imap.GetMessageCount(folderName);

                if (currentCount > expectedCount)
                {
                    break;
                }

                if (currentCount == expectedCount)
                {
                    imap.Disconnect();
                    return;
                }

                timeout--;
                Thread.Sleep(25);
            }

            imap.Disconnect();

            string error = "Wrong number of messages in mailbox " + folderName + " in account " + accountName +
                           " Actual: " + currentCount.ToString() + " Expected: " + expectedCount.ToString();

            Assert.Fail(error);
        }
Пример #29
0
        public void TestFetchCharsetInQuotesWithoutSpace()
        {
            Account account = SingletonProvider<TestSetup>.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");

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

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

             Assert.IsTrue(result.Contains("(\"CHARSET\" \"iso-8859-1\")"), result);
        }
Пример #30
0
        public void TestLongCommand()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var oSimulator = new ImapClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(account.Address, "test");

             var sb = new StringBuilder();

             for (int i = 0; i < 240000; i++)
             {
            sb.Append("A");
             }

             string result = oSimulator.Send("A01 " + sb);
             Assert.IsTrue(result.Length == 0 || result.StartsWith("A01"));
        }
Пример #31
0
        public void TestHierarchyDelimiterListResponse()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();
             Settings settings = _settings;
             settings.IMAPHierarchyDelimiter = "\\";

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

             string folderName = "Test\\Test";

             var oSimulator = new ImapClientSimulator();
             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.Logon(account.Address, "test");
             Assert.IsTrue(oSimulator.CreateFolder(folderName));
             string listResponse = oSimulator.List();
             Assert.IsTrue(listResponse.Contains("\"Test\\Test\""));
             Assert.IsTrue(listResponse.Contains("\"Test\""));
             oSimulator.Disconnect();
        }
Пример #32
0
        public static bool ValidatePassword(string username, string password)
        {
            var client = new ImapClientSimulator();

            return(client.ConnectAndLogon(username, password));
        }