Ejemplo n.º 1
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();
             CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             sim.Disconnect();

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

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

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

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

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

             string logText = TestSetup.ReadCurrentDefaultLog();
             CustomAssert.IsTrue(logText.Contains("Blocked either by IP range or by connection limit."), logText);
        }
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
0
        public void TestChangeFlags()
        {
            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");
             CustomAssert.IsFalse(simulator.SetFlagOnMessage(1, true, @"\Deleted"));
        }
Ejemplo n.º 8
0
        public void TestEmptyPassword()
        {
            Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "");

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

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

             var simSMTP = new SMTPClientSimulator();
             CustomAssert.IsFalse(simSMTP.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "", out message));
             CustomAssert.AreEqual("535 Authentication failed. Restarting authentication process.\r\n", message);
        }
Ejemplo n.º 9
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.
                TestSetup.AssertRecipientsInDeliveryQueue(0);
            }

            var oIMAP = new IMAPClientSimulator();

            CustomAssert.IsTrue(oIMAP.ConnectAndLogon(accountName, accountPassword));

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

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

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

                if (currentCount > expectedCount)
                {
                    break;
                }

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

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

            oIMAP.Disconnect();

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

            CustomAssert.Fail(error);
        }
Ejemplo n.º 10
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.
            TestSetup.AssertRecipientsInDeliveryQueue(0);
             }

             var oIMAP = new IMAPClientSimulator();
             CustomAssert.IsTrue(oIMAP.ConnectAndLogon(accountName, accountPassword));

             if (expectedCount != 0)
            oIMAP.AssertFolderExists(folderName);

             int currentCount = 0;
             int timeout = 1000; // 1000 * 25 = 25 seconds.
             while (timeout > 0)
             {
            currentCount = oIMAP.GetMessageCount(folderName);

            if (currentCount > expectedCount)
               break;

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

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

             oIMAP.Disconnect();

             string error = "Wrong number of messages in mailbox " + folderName + " in account " + accountName +
                        " Actual: " + currentCount.ToString() + " Expected: " + expectedCount.ToString();
             CustomAssert.Fail(error);
        }
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 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.º 13
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);
             CustomAssert.IsFalse(response.Contains("INBOX"));
             CustomAssert.IsFalse(response.Contains("SomeOtherFolder"));
             CustomAssert.IsTrue(response.Contains("* LIST (\\HasChildren) \".\" \"Main.Sub1\""));
             CustomAssert.IsTrue(response.Contains("* LIST (\\HasChildren) \".\" \"Main.Sub1.Sub2\""));
             CustomAssert.IsTrue(response.Contains("* LIST (\\HasNoChildren) \".\" \"Main.Sub1.Sub2.Sub3\""));

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

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

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

             oSimulator.Disconnect();
        }
Ejemplo n.º 14
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);
             CustomAssert.IsFalse(response.Contains("\"INBOX.MyApp\""));
             CustomAssert.IsFalse(response.Contains("\"INBOX.SomeOtherFolder\""));
             CustomAssert.IsTrue(response.Contains("* LIST (\\HasNoChildren) \".\" \"INBOX.MyApp.SubFolder1\""));
             CustomAssert.IsTrue(response.Contains("* LIST (\\HasNoChildren) \".\" \"INBOX.MyApp.SubFolder2\""));

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

             SMTPClientSimulator.StaticSend(account.Address, account.Address, "TestSubject", "TestBody");

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

             var simulator1 = new IMAPClientSimulator();
             var simulator2 = new IMAPClientSimulator();

             simulator1.ConnectAndLogon(account.Address, "test");
             simulator2.ConnectAndLogon(account.Address, "test");

             simulator1.SelectFolder("Inbox");
             simulator2.SelectFolder("Inbox");

             string result = simulator2.NOOP() + simulator2.NOOP();
             CustomAssert.IsFalse(result.Contains("Deleted"));
             CustomAssert.IsFalse(result.Contains("Seen"));

             simulator1.SetDeletedFlag(1);
             simulator1.SetSeenFlag(1);

             result = simulator2.NOOP() + simulator2.NOOP();
             CustomAssert.IsTrue(result.Contains("Deleted"));
             CustomAssert.IsTrue(result.Contains("Seen"));

             simulator1.Disconnect();
             simulator2.Disconnect();
        }
Ejemplo n.º 16
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.º 17
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.º 18
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.º 19
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.º 20
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.º 21
0
        public void TestDeleteSubFolderCheckAPI()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();

             IMAPFolders publicFolders = _settings.PublicFolders;

             CustomAssert.AreEqual(0, publicFolders.Count);

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

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

             CustomAssert.AreEqual(1, publicFolders.Count);

             IMAPFolders mySubFolders = folder.SubFolders;
             CustomAssert.AreEqual(0, mySubFolders.Count);

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

             var oSimulator1 = new IMAPClientSimulator();
             oSimulator1.ConnectAndLogon("*****@*****.**", "test");
             CustomAssert.IsTrue(oSimulator1.CreateFolder("#public.Share1.MySub"));
             CustomAssert.AreEqual(1, mySubFolders.Count);

             permission.set_Permission(eACLPermission.ePermissionDeleteMailbox, true);
             permission.Save();

             CustomAssert.IsTrue(oSimulator1.DeleteFolder("#public.Share1.MySub"));
             CustomAssert.IsFalse(oSimulator1.SelectFolder("#public.Share1.MySub"));

             CustomAssert.AreEqual(0, mySubFolders.Count);
             CustomAssert.AreEqual(1, publicFolders.Count);

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

             CustomAssert.IsTrue(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();
             CustomAssert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             CustomAssert.IsTrue(imapSimulator.SetDeletedFlag(1));
             CustomAssert.IsTrue(imapSimulator.Expunge());
             CustomAssert.AreEqual(0, imapSimulator.GetMessageCount("Inbox"));

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

             CustomAssert.AreEqual(1, imapSimulator.GetMessageCount("Inbox"));
        }
Ejemplo n.º 23
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.º 24
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 oSimulator = new IMAPClientSimulator();
             oSimulator.ConnectAndLogon(account.Address, "test");
             string result = oSimulator.Send("A01 NAMESPACE");
             string correctNamespaceSetting = "* NAMESPACE ((\"\" \"\\\\\")) NIL ((\"" + publicFolderName +
                                          "\" \"\\\\\"))";
             CustomAssert.IsTrue(result.Contains(correctNamespaceSetting), result);
             oSimulator.Disconnect();

             settings.IMAPHierarchyDelimiter = ".";

             oSimulator = new IMAPClientSimulator();
             oSimulator.ConnectAndLogon(account.Address, "test");

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

             settings.IMAPHierarchyDelimiter = "/";

             oSimulator = new IMAPClientSimulator();
             oSimulator.ConnectAndLogon(account.Address, "test");

             result = oSimulator.Send("A01 NAMESPACE");
             correctNamespaceSetting = "* NAMESPACE ((\"\" \"/\")) NIL ((\"" + publicFolderName + "\" \"/\"))";
             CustomAssert.IsTrue(result.Contains(correctNamespaceSetting), result);
             oSimulator.Disconnect();
        }
Ejemplo n.º 25
0
        public void TestExpunge()
        {
            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.SelectFolder("Inbox");
             CustomAssert.IsTrue(simulator.SetFlagOnMessage(1, true, @"\Deleted"));

             var secondSimulator = new IMAPClientSimulator();
             secondSimulator.ConnectAndLogon(oAccount.Address, "test");
             string result = secondSimulator.ExamineFolder("INBOX");
             CustomAssert.IsTrue(result.Contains("1 EXISTS"), result);
             CustomAssert.IsFalse(secondSimulator.Expunge());

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

             simulator.Close();
             secondSimulator.Close();
        }
Ejemplo n.º 26
0
        private void SetupAccountObject(Domain domain)
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(domain, "*****@*****.**", "test");

             // Make sure the inbox contains two messages which should be backed up.
             CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1 Subject",
                                                      "Message 1 Body"));
             POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1);

             CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 2 Subject",
                                                      "Message 2 Body"));
             POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2);

             CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 3 Subject",
                                                      "Message 3 Body"));
             POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3);

             var sim = new IMAPClientSimulator();
             CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(sim.SelectFolder("Inbox"));
             CustomAssert.IsTrue(sim.SetDeletedFlag(2));
             CustomAssert.IsTrue(sim.Expunge());
             sim.Disconnect();

             _folderCreationTime = account.IMAPFolders.get_ItemByName("INBOX").CreationTime;

             account.Active = true;
             account.ADDomain = "AD";
             account.AdminLevel = eAdminLevel.hAdminLevelDomainAdmin;
             account.ADUsername = "******";
             account.ForwardAddress = "FA";
             account.ForwardEnabled = false;
             account.ForwardKeepOriginal = true;
             account.IsAD = false;
             account.MaxSize = 1250;
             account.PersonFirstName = "First";
             account.PersonLastName = "Last";
             account.SignatureEnabled = true;
             account.SignatureHTML = "HTML";
             account.SignaturePlainText = "PLAIN";
             account.VacationMessage = "VAC";
             account.VacationMessageExpires = true;
             account.VacationMessageExpiresDate = "2020-01-01";
             account.VacationMessageIsOn = true;
             account.VacationSubject = "SUBJ";
             account.Password = "******";
             account.Save();

             // Set up fetch account
             FetchAccount fa = account.FetchAccounts.Add();
             fa.DaysToKeepMessages = 5;
             fa.Enabled = true;
             fa.MinutesBetweenFetch = 10;
             fa.Name = "test";
             fa.Port = _fetchAccountPort;
             fa.ProcessMIMEDate = true;
             fa.ProcessMIMERecipients = true;
             fa.ServerAddress = "127.0.0.1";
             fa.Username = "******";
             fa.UseSSL = false;
             fa.UseAntiSpam = true;
             fa.UseAntiVirus = true;
             fa.Save();

             DownloadFromExternalAccount(account, fa);

             Rule rule = account.Rules.Add();
             rule.Name = "MyRule";
             RuleCriteria criteria = rule.Criterias.Add();
             criteria.MatchType = eRuleMatchType.eMTGreaterThan;
             criteria.PredefinedField = eRulePredefinedField.eFTMessageSize;
             criteria.MatchValue = "0";
             criteria.Save();

             RuleAction action = rule.Actions.Add();
             action.Type = eRuleActionType.eRAForwardEmail;
             action.To = "*****@*****.**";
             action.Body = "Test";
             action.Filename = "File";
             action.FromAddress = "T";
             action.FromName = "N";
             action.HeaderName = "H";
             action.IMAPFolder = "Folder";
             action.ScriptFunction = "Script";
             action.Subject = "Subj";
             action.Value = "Value";
             action.Save();

             rule.Save();
        }
Ejemplo n.º 27
0
 private static IMAPClientSimulator ConnectAndLogon()
 {
     IMAPClientSimulator sim = new IMAPClientSimulator();
      sim.ConnectAndLogon("*****@*****.**", "test");
      return sim;
 }
Ejemplo n.º 28
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();
             CustomAssert.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();
             CustomAssert.IsFalse(result.Contains(folder.Name));
             simulator1.Disconnect();
        }
Ejemplo n.º 29
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");

             TestSetup.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]");

             CustomAssert.IsTrue(result.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename)));
             TestSetup.AssertReportedError();
        }
Ejemplo n.º 30
0
 public void TestIMAPServerNormal()
 {
     var sim = new IMAPClientSimulator();
      sim.ConnectAndLogon(GetUsername(), GetPassword());
      EnsureNoPassword();
 }
Ejemplo n.º 31
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();

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

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