Exemplo n.º 1
0
        public void TestSearchWithLiterals()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

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

            // Send a message to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1);
            oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search");
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2);

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon("*****@*****.**", "test");

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

            string result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test1");

            Assert.IsTrue(result.StartsWith("* SEARCH 1\r\n"));

            result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test2");
            Assert.IsTrue(result.StartsWith("* SEARCH 2\r\n"));
        }
Exemplo n.º 2
0
        public void TestDateSortOrder()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator = new IMAPSimulator();

            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();
        }
Exemplo n.º 3
0
        public void TestDateSortOrder()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             IMAPSimulator oSimulator = new IMAPSimulator();

             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();
        }
Exemplo n.º 4
0
        public void TestDateSortOrderNonexistantDate()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             IMAPSimulator oSimulator = new IMAPSimulator();

             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\" {4}", "ABCD");
             Assert.IsTrue(response.Contains("* 1 EXISTS"), response);

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

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

             response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {4}", "ABCD");
             Assert.IsTrue(response.Contains("* 4 EXISTS"), response);

             /*
              * RFC 5256 "2.2. Sent Date" chapter. If the sent date cannot be determined (a Date: header is missing or cannot be parsed),
              * the INTERNALDATE for that message is used as the sent date.
              */

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

             Assert.IsTrue(sortArivalDateResponse.Contains(" 3 2 1 4"));
             Assert.AreEqual(sortDateResponse, sortArivalDateResponse);
             oSimulator.Disconnect();
        }
Exemplo n.º 5
0
        public void ConfirmFileAddedToCorrectAccountFolder()
        {
            Utilities utilities = SingletonProvider<Utilities>.Instance;
            hMailServer.Account oAccount = utilities.AddAccount(_domain, "*****@*****.**", "test");
            IMAPSimulator oSimulator = new IMAPSimulator();

            // Confirm that the public folder is empty before we start our test.
            string publicDir = utilities.GetPublicDirectory();
            utilities.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.
            utilities.AssertFilesInDirectory(publicDir, 0);

            // There should be a single file in the users directory.
            utilities.AssertFilesInUserDirectory(oAccount, 1);
        }
Exemplo n.º 6
0
        public void ConfirmFileAddedToCorrectAccountFolder()
        {
            Utilities utilities = SingletonProvider <Utilities> .Instance;

            hMailServer.Account oAccount   = utilities.AddAccount(_domain, "*****@*****.**", "test");
            IMAPSimulator       oSimulator = new IMAPSimulator();

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

            utilities.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.
            utilities.AssertFilesInDirectory(publicDir, 0);

            // There should be a single file in the users directory.
            utilities.AssertFilesInUserDirectory(oAccount, 1);
        }
Exemplo n.º 7
0
        public void TestAppendBadLiteral()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral("*****@*****.**", "test");
             oSimulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {TEST}", "ABCD");
             Assert.AreEqual(0, oSimulator.GetMessageCount("INBOX"));
             oSimulator.Disconnect();
        }
Exemplo n.º 8
0
        public void TestAppend()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator = new IMAPSimulator();

            string sWelcomeMessage = oSimulator.Connect();

            oSimulator.LogonWithLiteral("*****@*****.**", "test");
            oSimulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {4}", "ABCD");
            Assert.AreEqual(1, oSimulator.GetMessageCount("INBOX"));
            oSimulator.Disconnect();
        }
Exemplo n.º 9
0
        public void TestDateSortOrderNonexistantDate()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator = new IMAPSimulator();

            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\" {4}", "ABCD");

            Assert.IsTrue(response.Contains("* 1 EXISTS"), response);

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

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

            response = oSimulator.SendSingleCommandWithLiteral("A04 APPEND INBOX \"23-Feb-2008 01:30:23 +0200\" {4}", "ABCD");
            Assert.IsTrue(response.Contains("* 4 EXISTS"), response);

            /*
             * RFC 5256 "2.2. Sent Date" chapter. If the sent date cannot be determined (a Date: header is missing or cannot be parsed),
             * the INTERNALDATE for that message is used as the sent date.
             */

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

            Assert.IsTrue(sortArivalDateResponse.Contains(" 3 2 1 4"));
            Assert.AreEqual(sortDateResponse, sortArivalDateResponse);
            oSimulator.Disconnect();
        }
Exemplo n.º 10
0
        public void ConfirmFileAddedToCorrectPublicFolder()
        {
            Utilities utilities = SingletonProvider <Utilities> .Instance;

            hMailServer.Account oAccount   = utilities.AddAccount(_domain, "*****@*****.**", "test");
            IMAPSimulator       oSimulator = new IMAPSimulator();

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

            utilities.AssertFilesInDirectory(publicDir, 0);

            hMailServer.IMAPFolders folders = _application.Settings.PublicFolders;
            hMailServer.IMAPFolder  folder  = folders.Add("Share");
            folder.Save();

            // Give everyone access to the folder.
            hMailServer.IMAPFolderPermission permission = folder.Permissions.Add();
            permission.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeAnyone;
            permission.set_Permission(hMailServer.eACLPermission.ePermissionLookup, true);
            permission.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
            permission.set_Permission(hMailServer.eACLPermission.ePermissionInsert, true);
            permission.Save();

            // Add the message to the public folder.
            oSimulator.Connect();
            oSimulator.LogonWithLiteral("*****@*****.**", "test");
            oSimulator.SendSingleCommandWithLiteral("A01 APPEND #Public.Share {4}", "ABCD");

            // Confirm that the message exists in the public folder and not in the inbox.
            Assert.AreEqual(1, oSimulator.GetMessageCount("#Public.Share"));
            Assert.AreEqual(0, oSimulator.GetMessageCount("INBOX"));
            oSimulator.Disconnect();


            // The public directory should now contain the message.
            utilities.AssertFilesInDirectory(publicDir, 1);

            // There users directory should still be empty.
            utilities.AssertFilesInUserDirectory(oAccount, 0);
        }
Exemplo n.º 11
0
        public void TestGlobalMaxMessageSizeLimitDisabled()
        {
            var account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test", 0);

            var message = new StringBuilder();

            // ~2 kb string
            for (int i = 0; i < 25; i++)
            {
                message.AppendLine("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
            }

            _settings.MaxMessageSize = 0;

            var    imapSim = new IMAPSimulator("*****@*****.**", "test", "INBOX");
            string result  = imapSim.SendSingleCommandWithLiteral("A01 APPEND INBOX {" + message.Length + "}", message.ToString());

            imapSim.Logout();

            Assert.IsFalse(result.StartsWith("A01 NO Message size exceeds fixed maximum message size."));
        }
Exemplo n.º 12
0
        public void ConfirmFileAddedToCorrectPublicFolder()
        {
            Utilities utilities = SingletonProvider<Utilities>.Instance;
            hMailServer.Account oAccount = utilities.AddAccount(_domain, "*****@*****.**", "test");
            IMAPSimulator oSimulator = new IMAPSimulator();

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

            hMailServer.IMAPFolders folders = _application.Settings.PublicFolders;
            hMailServer.IMAPFolder folder = folders.Add("Share");
            folder.Save();

            // Give everyone access to the folder.
            hMailServer.IMAPFolderPermission permission = folder.Permissions.Add();
            permission.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeAnyone;
            permission.set_Permission(hMailServer.eACLPermission.ePermissionLookup, true);
            permission.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
            permission.set_Permission(hMailServer.eACLPermission.ePermissionInsert, true);
            permission.Save();

            // Add the message to the public folder.
            oSimulator.Connect();
            oSimulator.LogonWithLiteral("*****@*****.**", "test");
            oSimulator.SendSingleCommandWithLiteral("A01 APPEND #Public.Share {4}", "ABCD");

            // Confirm that the message exists in the public folder and not in the inbox.
            Assert.AreEqual(1, oSimulator.GetMessageCount("#Public.Share"));
            Assert.AreEqual(0, oSimulator.GetMessageCount("INBOX"));
            oSimulator.Disconnect();

            // The public directory should now contain the message.
            utilities.AssertFilesInDirectory(publicDir, 1);

            // There users directory should still be empty.
            utilities.AssertFilesInUserDirectory(oAccount, 0);
        }
Exemplo n.º 13
0
        public void TestDomainMaxMessageSizeLimitDisabled()
        {
            var account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test", 0);
               var message = new StringBuilder();

               // ~2 kb string
               for (int i = 0; i < 25; i++)
              message.AppendLine("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");

               _domain.MaxMessageSize = 0; // 1 kb
               _domain.Save();

               var imapSim = new IMAPSimulator("*****@*****.**", "test", "INBOX");
               string result = imapSim.SendSingleCommandWithLiteral("A01 APPEND INBOX {" + message.Length + "}", message.ToString());
               imapSim.Logout();

               Assert.IsFalse(result.StartsWith("A01 NO Message size exceeds fixed maximum message size."));
        }
Exemplo n.º 14
0
        public void TestSearchWithLiterals()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

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

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

              IMAPSimulator oSimulator = new IMAPSimulator();

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

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

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

              result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test2");
              Assert.IsTrue(result.StartsWith("* SEARCH 2\r\n"));
        }
Exemplo n.º 15
0
        public void TestAppendResponseContainsExists()
        {
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             IMAPSimulator oSimulator = new IMAPSimulator();

             string sWelcomeMessage = oSimulator.Connect();
             oSimulator.LogonWithLiteral("*****@*****.**", "test");
             Assert.IsTrue(oSimulator.SelectFolder("Inbox"));
             string response1 = oSimulator.SendSingleCommandWithLiteral("A01 APPEND INBOX {4}", "ABCD");
             Assert.IsTrue(response1.Contains("* 1 EXISTS"), response1);
             Assert.IsTrue(response1.Contains("* 1 RECENT"), response1);
             Assert.AreEqual(1, oSimulator.GetMessageCount("INBOX"));
             oSimulator.Disconnect();
        }
Exemplo n.º 16
0
        public void TestAppendToPublicFolder()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

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

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

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

              IMAPSimulator oSimulator = new IMAPSimulator();

              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.LogonWithLiteral(account.Address, "test");
              oSimulator.SendSingleCommandWithLiteral("A01 APPEND #Public.Share1 {4}", "ABCD");
              Assert.AreEqual(1, oSimulator.GetMessageCount("#Public.Share1"));
              oSimulator.Disconnect();
        }