Summary description for POP3Simulator.
示例#1
0
        public static string AssertGetFirstMessageText(string accountName, string accountPassword)
        {
            // Wait for the message to appear.
            POP3Simulator pop3 = new POP3Simulator();

            for (int i = 0; i < 5000; i++)
            {
                if (pop3.GetMessageCount(accountName, accountPassword) > 0)
                {
                    break;
                }

                Thread.Sleep(20);
            }

            // Download it.
            string text = pop3.GetFirstMessageText(accountName, accountPassword);

            if (text.Length == 0)
            {
                Assert.Fail("Message was found but contents could not be received");
            }

            return(text);
        }
示例#2
0
        public static void AssertMessageCount(string accountName, string accountPassword, int expectedCount)
        {
            if (expectedCount == 0)
             {
            // just in case.
            Utilities.AssertRecipientsInDeliveryQueue(0);
             }

             int timeout = 100;
             int actualCount = 0;
             while (timeout > 0)
             {

            POP3Simulator oPOP3 = new POP3Simulator();

            actualCount = oPOP3.GetMessageCount(accountName, accountPassword);
            if (actualCount == expectedCount)
               return;

            if (actualCount > expectedCount)
               Assert.Fail(string.Format("Actual count exceeds expected count. Account name: {2}, Actual: {0}, Expected: {1}.", actualCount, expectedCount, accountName));

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

             Assert.Fail(string.Format("Wrong number of messages in inbox for {0}. Actual: {1}, Expected: {2}",
            accountName, actualCount, expectedCount));
        }
示例#3
0
        public static void AssertMessageCount(string accountName, string accountPassword, int expectedCount)
        {
            if (expectedCount == 0)
            {
                // just in case.
                Utilities.AssertRecipientsInDeliveryQueue(0);
            }

            int timeout     = 100;
            int actualCount = 0;

            while (timeout > 0)
            {
                POP3Simulator oPOP3 = new POP3Simulator();

                actualCount = oPOP3.GetMessageCount(accountName, accountPassword);
                if (actualCount == expectedCount)
                {
                    return;
                }

                if (actualCount > expectedCount)
                {
                    Assert.Fail(string.Format("Actual count exceeds expected count. Account name: {2}, Actual: {0}, Expected: {1}.", actualCount, expectedCount, accountName));
                }

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

            Assert.Fail(string.Format("Wrong number of messages in inbox for {0}. Actual: {1}, Expected: {2}",
                                      accountName, actualCount, expectedCount));
        }
示例#4
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            // Determine message count
            POP3Simulator pop3sim = new POP3Simulator();
            int count = pop3sim.GetMessageCount("*****@*****.**", "test");

            // Fetch them..
            pop3sim.ConnectAndLogon("*****@*****.**","test");

            for (int i = 1; i <= count; i++)
            {
                pop3sim.RETR(i);
            }

            for (int i = 1; i <= count; i++)
            {
                pop3sim.DELE(i);
            }

            pop3sim.QUIT();

            System.Threading.Thread.Sleep(1000 * 60 * 60);

            stopwatch.Stop();

            Console.WriteLine("Passed time: " + stopwatch.Elapsed.TotalSeconds.ToString());
        }
示例#5
0
        public static string AssertGetFirstMessageText(string accountName, string accountPassword)
        {
            // Wait for the message to appear.
             POP3Simulator pop3 = new POP3Simulator();
             for (int i = 0; i < 5000; i++)
             {
            if (pop3.GetMessageCount(accountName, accountPassword) > 0)
               break;

            Thread.Sleep(20);
             }

             // Download it.
             string text = pop3.GetFirstMessageText(accountName, accountPassword);

             if (text.Length == 0)
            Assert.Fail("Message was found but contents could not be received");

             return text;
        }
示例#6
0
        private void DownloadFromExternalAccount(hMailServer.Account account, hMailServer.FetchAccount fa)
        {
            if (!_backupMessages)
            {
                return;
            }

            // Download messages from the external account.
            List <string> messages = new List <string>();

            messages.Add("Subject: Message 1\r\n");
            messages.Add("Subject: Message 2\r\n");
            messages.Add("Subject: Message 3\r\n");

            int        port       = 1110;
            POP3Server pop3Server = new POP3Server(1, port, messages);

            pop3Server.StartListen();
            fa.DownloadNow();
            pop3Server.WaitForCompletion();

            Utilities.AssertRecipientsInDeliveryQueue(0);
            POP3Simulator.AssertMessageCount(account.Address, "test", 5);
        }
示例#7
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();
        }
示例#8
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));
        }
示例#9
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));
        }