Summary description for IMAPSimulator.
Exemplo n.º 1
0
        public void TestBatchOfCommands()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

               IMAPSimulator oSimulator = new IMAPSimulator();
               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();
        }
Exemplo n.º 2
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.
                Utilities.AssertRecipientsInDeliveryQueue(0);
            }

            IMAPSimulator oIMAP = new IMAPSimulator();

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

            Assert.Fail(error);
        }
Exemplo n.º 3
0
        public void TestLongCommand()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

              StringBuilder sb = new StringBuilder();

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

              string result = oSimulator.Send("A01 " + sb.ToString());
              Assert.IsTrue(result.Length == 0 || result.StartsWith("A01"));
        }
Exemplo n.º 4
0
        public void TestLongCommand()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(account.Address, "test");

            StringBuilder sb = new StringBuilder();

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

            string result = oSimulator.Send("A01 " + sb.ToString());

            Assert.IsTrue(result.Length == 0 || result.StartsWith("A01"));
        }
Exemplo n.º 5
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.
                Utilities.AssertRecipientsInDeliveryQueue(0);
            }

            IMAPSimulator oIMAP = new IMAPSimulator();
            Assert.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();
            Assert.Fail(error);
        }
Exemplo n.º 6
0
        public void Test()
        {
            IMAPSimulator sim = new IMAPSimulator();
             sim.ConnectAndLogon("*****@*****.**", "test");
             sim.SelectFolder("Inbox");

             Stopwatch watch = new Stopwatch();

             watch.Start();
             string result = sim.SendSingleCommand("A282 SORT (SIZE) UTF-8");
             watch.Stop();

             long sortSizeTime = watch.ElapsedMilliseconds;
             watch.Reset();

             watch.Start();
             result = sim.SendSingleCommand("A282 SORT (FROM) UTF-8");
             watch.Stop();

             long sortFromTime = watch.ElapsedMilliseconds;
             watch.Reset();

             watch.Start();
             result = sim.SendSingleCommand("A282 SORT (FROM) UTF-8 1:15");
             watch.Stop();

             long sortFromTimeLimit15 = watch.ElapsedMilliseconds;
             watch.Reset();

             watch.Start();
             result = sim.SendSingleCommand("A282 SORT (DATE) UTF-8");
             watch.Stop();

             long sortDateTime = watch.ElapsedMilliseconds;
             watch.Reset();

             System.Threading.Thread.Sleep(1);
        }
Exemplo n.º 7
0
        public void TestBatchOfCommands()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            IMAPSimulator oSimulator      = new IMAPSimulator();
            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();
        }
Exemplo n.º 8
0
 private static IMAPSimulator ConnectAndLogon()
 {
     IMAPSimulator sim = new IMAPSimulator();
     sim.ConnectAndLogon("*****@*****.**", "test");
     return sim;
 }
Exemplo n.º 9
0
        private void SetupAccountObject(hMailServer.Domain domain)
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(domain, "*****@*****.**", "test");

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

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

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

            IMAPSimulator sim = new IMAPSimulator();

            Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(sim.SelectFolder("Inbox"));
            Assert.IsTrue(sim.SetDeletedFlag(2));
            Assert.IsTrue(sim.Expunge());
            sim.Disconnect();

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

            account.Active              = true;
            account.ADDomain            = "AD";
            account.AdminLevel          = hMailServer.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
            hMailServer.FetchAccount fa = account.FetchAccounts.Add();
            fa.DaysToKeepMessages  = 5;
            fa.Enabled             = true;
            fa.MinutesBetweenFetch = 10;
            fa.Name                  = "test";
            fa.Port                  = 1110;
            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);

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

            hMailServer.RuleAction action = rule.Actions.Add();
            action.Type           = hMailServer.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();
        }
Exemplo n.º 10
0
        public void TestSaveMessageWithScriptAndMoveMessageWithGlobalRule()
        {
            _settings.Scripting.Enabled = true;

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

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

             // First deliver two messages to the inbox.
             SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");
             POP3Simulator.AssertMessageCount(testAccount.Address, "test", 1);
             hMailServer.IMAPFolder inboxFolder = testAccount.IMAPFolders[0];
             Assert.AreEqual(1, inboxFolder.CurrentUID);
             Assert.AreEqual(1, inboxFolder.Messages[0].UID);
             Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 2"));

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

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

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

             // Wait for the message to arrive.
             Utilities.AssertFolderExists(testAccount.IMAPFolders, "TestFolder");

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

             hMailServer.IMAPFolder testFolder = testAccount.IMAPFolders.get_ItemByName("TestFolder");

             // Since the message is placed in a new folder, it should receive a unique UID.
             Assert.IsTrue(sim.Status("TestFolder", "UIDNEXT").Contains("UIDNEXT 2"));
             Assert.AreEqual(1, testFolder.Messages.Count);
             Assert.AreEqual(1, testFolder.CurrentUID);
             Assert.AreEqual(1, testFolder.Messages[0].UID);
        }
Exemplo n.º 11
0
        public void TestPortOpening()
        {
            hMailServer.Application oApp = SingletonProvider<Utilities>.Instance.GetApp();

             oApp.Settings.TCPIPPorts.SetDefault();

             SMTPClientSimulator pSMTPSimulator = new SMTPClientSimulator();
             POP3Simulator pPOP3Simulator = new POP3Simulator();
             IMAPSimulator pIMAPSimulator = new IMAPSimulator();

             oApp.Stop();

             hMailServer.TCPIPPorts oPorts = oApp.Settings.TCPIPPorts;
             for (int i = 0; i < oPorts.Count; i++)
             {
            hMailServer.TCPIPPort oTestPort = oPorts[i];
            if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
               oTestPort.PortNumber = 14300;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
               oTestPort.PortNumber = 11000;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
               oTestPort.PortNumber = 2500;

            oTestPort.Save();
             }

             oApp.Start();

             Assert.IsTrue(pSMTPSimulator.TestConnect(2500));
             Assert.IsTrue(pSMTPSimulator.TestConnect(11000));
             Assert.IsTrue(pSMTPSimulator.TestConnect(14300));

             oApp.Stop();

             hMailServer.TCPIPPort oPort = oApp.Settings.TCPIPPorts.Add();
             oPort.Protocol = hMailServer.eSessionType.eSTSMTP;
             oPort.PortNumber = 25000;
             oPort.Save();

             oApp.Start();

             // Try to connect to the new port
             Assert.IsTrue(pSMTPSimulator.TestConnect(25000));

             oApp.Stop();

              // Delete the port again
             oApp.Settings.TCPIPPorts.DeleteByDBID(oPort.ID);

             // Change back the ports
             for (int i = 0; i < oPorts.Count; i++)
             {
            hMailServer.TCPIPPort oTestPort = oPorts[i];
            if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
               oTestPort.PortNumber = 143;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
               oTestPort.PortNumber = 25;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
               oTestPort.PortNumber = 110;

            oTestPort.Save();
             }

             oApp.Start();

             Assert.IsTrue(pSMTPSimulator.TestConnect(25));
             Assert.IsTrue(pPOP3Simulator.TestConnect(110));
             Assert.IsTrue(pPOP3Simulator.TestConnect(143));
        }
Exemplo n.º 12
0
        public void TestPortOpening()
        {
            hMailServer.Application oApp = SingletonProvider <Utilities> .Instance.GetApp();

            oApp.Settings.TCPIPPorts.SetDefault();

            SMTPClientSimulator pSMTPSimulator = new SMTPClientSimulator();
            POP3Simulator       pPOP3Simulator = new POP3Simulator();
            IMAPSimulator       pIMAPSimulator = new IMAPSimulator();

            oApp.Stop();

            hMailServer.TCPIPPorts oPorts = oApp.Settings.TCPIPPorts;
            for (int i = 0; i < oPorts.Count; i++)
            {
                hMailServer.TCPIPPort oTestPort = oPorts[i];
                if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
                {
                    oTestPort.PortNumber = 14300;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
                {
                    oTestPort.PortNumber = 11000;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
                {
                    oTestPort.PortNumber = 2500;
                }

                oTestPort.Save();
            }

            oApp.Start();

            Assert.IsTrue(pSMTPSimulator.TestConnect(2500));
            Assert.IsTrue(pSMTPSimulator.TestConnect(11000));
            Assert.IsTrue(pSMTPSimulator.TestConnect(14300));

            oApp.Stop();

            hMailServer.TCPIPPort oPort = oApp.Settings.TCPIPPorts.Add();
            oPort.Protocol   = hMailServer.eSessionType.eSTSMTP;
            oPort.PortNumber = 25000;
            oPort.Save();

            oApp.Start();

            // Try to connect to the new port
            Assert.IsTrue(pSMTPSimulator.TestConnect(25000));

            oApp.Stop();

            // Delete the port again
            oApp.Settings.TCPIPPorts.DeleteByDBID(oPort.ID);

            // Change back the ports
            for (int i = 0; i < oPorts.Count; i++)
            {
                hMailServer.TCPIPPort oTestPort = oPorts[i];
                if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
                {
                    oTestPort.PortNumber = 143;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
                {
                    oTestPort.PortNumber = 25;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
                {
                    oTestPort.PortNumber = 110;
                }

                oTestPort.Save();
            }

            oApp.Start();

            Assert.IsTrue(pSMTPSimulator.TestConnect(25));
            Assert.IsTrue(pPOP3Simulator.TestConnect(110));
            Assert.IsTrue(pPOP3Simulator.TestConnect(143));
        }