Example #1
0
        public static void WaitForUnlock(FetchAccount fetchAccount)
        {
            // 10 seconds
             for (int i = 0; i < 100; i++)
             {
            if (!fetchAccount.IsLocked)
               return;

            Thread.Sleep(100);
             }

             string defaultLog = TestSetup.ReadCurrentDefaultLog();
             Assert.Fail("Fetch account was not unlocked. Log follows:\r\n" + defaultLog);
        }
Example #2
0
        public static void WaitForUnlock(FetchAccount fetchAccount)
        {
            var timeoutTime = DateTime.Now.Add(TimeSpan.FromSeconds(30));

             while (DateTime.Now < timeoutTime)
             {
            if (!fetchAccount.IsLocked)
               return;

            Thread.Sleep(100);
             }

             string defaultLog = LogHandler.ReadCurrentDefaultLog();
             Assert.Fail(string.Format("At {0}, fetch account was not unlocked.", DateTime.Now));
        }
Example #3
0
        public void TestBasicExternalAccount()
        {
            var messages = new List <string>();

            string message = "Received: from example.com (example.com [1.2.3.4]) by mail.host.edu\r\n" +
                             "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.Save();

                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                fa.Delete();

                string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

                Assert.IsTrue(downloadedMessage.Contains(message));
            }
        }
Example #4
0
        public void TestServerNotSupportingUIDL()
        {
            var messages = new List <string>();

            string message = "Received: from example.com (example.com [1.2.3.4]) by mail.host.edu\r\n" +
                             "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new POP3Server(1, port, messages))
            {
                pop3Server.SupportsUIDL = false;
                pop3Server.StartListen();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.Save();
                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                fa.Delete();

                string error = TestSetup.ReadAndDeleteErrorLog();

                CustomAssert.IsTrue(error.Contains("-ERR unhandled command"));
            }
        }
Example #5
0
        public static void WaitForUnlock(FetchAccount fetchAccount)
        {
            var timeoutTime = DateTime.Now.Add(TimeSpan.FromSeconds(30));

            while (DateTime.Now < timeoutTime)
            {
                if (!fetchAccount.IsLocked)
                {
                    return;
                }

                Thread.Sleep(100);
            }

            string defaultLog = LogHandler.ReadCurrentDefaultLog();

            Assert.Fail(string.Format("At {0}, fetch account was not unlocked.", DateTime.Now));
        }
        public void POP3ServerSupportingStartTLS_StartTLSOptional()
        {
            var messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSSTARTTLSRequired))
            {
                pop3Server.SetCertificate(SslSetup.GetCertificate());
                pop3Server.StartListen();

                TestSetup.DeleteCurrentDefaultLog();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.ConnectionSecurity    = eConnectionSecurity.eCSSTARTTLSOptional;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.Save();

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

                POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1);

                fa.Delete();
            }
        }
Example #7
0
        private static FetchAccount CreateFetchAccount(Account account, int port, bool antiSpam, bool antiVirus)
        {
            FetchAccount fa = account.FetchAccounts.Add();

            fa.Enabled             = true;
            fa.MinutesBetweenFetch = 10;
            fa.Name                  = "Test";
            fa.Username              = "******";
            fa.Password              = "******";
            fa.UseSSL                = false;
            fa.ServerAddress         = "localhost";
            fa.Port                  = port;
            fa.ProcessMIMERecipients = false;
            fa.DaysToKeepMessages    = -1;
            fa.UseAntiSpam           = antiSpam;
            fa.UseAntiVirus          = antiVirus;
            fa.Save();
            return(fa);
        }
Example #8
0
        public void TestFetchFromInvalidHostName()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            FetchAccount fa = account.FetchAccounts.Add();

            fa.Enabled             = true;
            fa.MinutesBetweenFetch = 10;
            fa.Name                  = "Test";
            fa.Username              = "******";
            fa.Password              = "******";
            fa.UseSSL                = false;
            fa.ServerAddress         = "nonexistant.example.com";
            fa.Port                  = 110;
            fa.ProcessMIMERecipients = false;
            fa.Save();

            fa.DownloadNow();

            TestSetup.AssertReportedError("The IP address for external account Test could not be resolved. Aborting fetch.");

            fa.Delete();
        }
Example #9
0
        private void DownloadFromExternalAccount(Account account, FetchAccount fa)
        {
            if (!_backupMessages)
            {
                return;
            }

            // Download messages from the external account.
            var 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");

            using (var pop3Server = new Pop3ServerSimulator(1, fa.Port, messages))
            {
                pop3Server.StartListen();
                fa.DownloadNow();
                pop3Server.WaitForCompletion();
            }

            CustomAsserts.AssertRecipientsInDeliveryQueue(0);
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 5);
        }
Example #10
0
        public void TestSpamProtectionPreTransmissionHELOPassFirst()
        {
            _application.Settings.AntiSpam.SpamMarkThreshold   = 1;
            _application.Settings.AntiSpam.SpamDeleteThreshold = 100;
            _application.Settings.AntiSpam.AddHeaderReason     = true;
            _application.Settings.AntiSpam.AddHeaderSpam       = true;
            _application.Settings.AntiSpam.PrependSubject      = true;
            _application.Settings.AntiSpam.PrependSubjectText  = "ThisIsSpam";

            _application.Settings.AntiSpam.CheckHostInHelo      = true;
            _application.Settings.AntiSpam.CheckHostInHeloScore = 105;

            IncomingRelay incomingRelay = _application.Settings.IncomingRelays.Add();

            incomingRelay.LowerIP = "1.2.1.2";
            incomingRelay.UpperIP = "1.2.1.3";
            incomingRelay.Name    = "Test";
            incomingRelay.Save();

            var messages = new List <string>();

            string message = "Received: from example.com (example.com [1.2.1.2]) by mail.host.edu\r\n" +
                             "Received: from mail.hmailserver.com (mail.hmailserver.com [" +
                             TestSetup.GethMailServerCOMIPaddress() + "]) by mail.host.edu\r\n" +
                             "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Should be blocked by SPF.";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.DaysToKeepMessages    = 0;
                fa.UseAntiSpam           = true;
                fa.Save();

                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                fa.Delete();

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);
            }
        }
Example #11
0
        public void TestSpamProtectionNoTagging()
        {
            CustomAsserts.AssertSpamAssassinIsRunning();

            _application.Settings.AntiSpam.SpamMarkThreshold   = 5;
            _application.Settings.AntiSpam.SpamDeleteThreshold = 9999;
            _application.Settings.AntiSpam.MaximumMessageSize  = 1024 * 1024;
            _application.Settings.AntiSpam.AddHeaderReason     = false;
            _application.Settings.AntiSpam.AddHeaderSpam       = false;
            _application.Settings.AntiSpam.PrependSubject      = false;
            _application.Settings.AntiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SpamAssassin
            _application.Settings.AntiSpam.SpamAssassinEnabled    = true;
            _application.Settings.AntiSpam.SpamAssassinHost       = "localhost";
            _application.Settings.AntiSpam.SpamAssassinPort       = 783;
            _application.Settings.AntiSpam.SpamAssassinMergeScore = true;
            _application.Settings.AntiSpam.SpamAssassinScore      = 5;

            var messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.DaysToKeepMessages    = -1;
                fa.UseAntiSpam           = true;

                fa.Save();
                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                fa.Delete();

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);
            }
        }
Example #12
0
        public void TestSpamProtectionPostTransmission()
        {
            _application.Settings.AntiSpam.SpamMarkThreshold   = 1;
            _application.Settings.AntiSpam.SpamDeleteThreshold = 100;
            _application.Settings.AntiSpam.AddHeaderReason     = true;
            _application.Settings.AntiSpam.AddHeaderSpam       = true;
            _application.Settings.AntiSpam.PrependSubject      = true;
            _application.Settings.AntiSpam.PrependSubjectText  = "ThisIsSpam";


            SURBLServer oSURBLServer = _application.Settings.AntiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            var messages = new List <string>();

            string message = "Received: from example.com (example.com [1.2.3.4]) by mail.host.edu\r\n" +
                             "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "http://surbl-org-permanent-test-point.com/";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.DaysToKeepMessages    = -1;
                fa.UseAntiSpam           = true;

                fa.Save();
                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                fa.Delete();

                string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

                Assert.IsTrue(downloadedMessage.Contains("X-hMailServer-Spam: YES"));
            }
        }
        public void POP3ServerNOTSupportingStartTLS_StartTLSRequired()
        {
            var messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSNone))
            {
                pop3Server.SetCertificate(SslSetup.GetCertificate());
                pop3Server.StartListen();

                TestSetup.DeleteCurrentDefaultLog();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.ConnectionSecurity    = eConnectionSecurity.eCSSTARTTLSRequired;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.Save();

                fa.DownloadNow();

                string expectedMessage =
                    string.Format(
                        "The download of messages from external account {0} failed. The external aAccount is configured to use STARTTLS connection security, but the POP3 server does not support it.", fa.Name);

                string contentSoFar = "";

                for (int i = 0; i <= 10; i++)
                {
                    if (i == 5)
                    {
                        CustomAssert.Fail("No connection: " + contentSoFar);
                    }

                    contentSoFar = TestSetup.ReadCurrentDefaultLog();
                    if (contentSoFar.Contains(expectedMessage))
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }

                pop3Server.WaitForCompletion();

                fa.Delete();
            }
        }
Example #14
0
        public void TestDeliverToExternalMimeRecipientsEnabled()
        {
            var messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

                var deliveryResults = new Dictionary <string, int>();
                deliveryResults["*****@*****.**"] = 250;

                int smtpServerPort = TestSetup.GetNextFreePort();
                using (var smtpServer = new SmtpServerSimulator(1, smtpServerPort))
                {
                    smtpServer.AddRecipientResult(deliveryResults);
                    smtpServer.StartListen();

                    // Add a route so we can connect to localhost.
                    Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);
                    route.TreatSecurityAsLocalDomain = true;
                    route.Save();

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

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

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

                    _domain.Postmaster = catchallAccount.Address;
                    _domain.Save();

                    FetchAccount fa = account1.FetchAccounts.Add();

                    fa.Enabled             = true;
                    fa.MinutesBetweenFetch = 10;
                    fa.Name                  = "Test";
                    fa.Username              = "******";
                    fa.Password              = "******";
                    fa.UseSSL                = false;
                    fa.ServerAddress         = "localhost";
                    fa.Port                  = port;
                    fa.ProcessMIMERecipients = true;
                    fa.EnableRouteRecipients = true;
                    fa.Save();

                    fa.DownloadNow();

                    pop3Server.WaitForCompletion();

                    fa.Delete();

                    string downloadedMessage1 = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test");
                    Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0);
                    Pop3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0);
                    Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

                    // Make sure the exernal recipient has received his copy.
                    smtpServer.WaitForCompletion();
                    string messageData = smtpServer.MessageData;
                    Assert.IsTrue(messageData.Contains(messageData), messageData);

                    CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);
                }
            }
        }
        public void POP3ServerNotSupportingSSL()
        {
            var messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new POP3Server(2, port, messages))
            {
                pop3Server.DisconnectImmediate = true;
                pop3Server.StartListen();

                TestSetup.DeleteCurrentDefaultLog();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = true;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.Save();

                fa.DownloadNow();
                string contentSoFar = "";
                for (int i = 0; i <= 10; i++)
                {
                    if (i == 5)
                    {
                        CustomAssert.Fail("No connection: " + contentSoFar);
                    }

                    contentSoFar = TestSetup.ReadCurrentDefaultLog();
                    if (contentSoFar.Contains("TCPConnection - TLS/SSL handshake failed."))
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }

                TestSetup.DeleteCurrentDefaultLog();

                // try again.
                fa.DownloadNow();

                contentSoFar = "";

                for (int i = 0; i <= 10; i++)
                {
                    if (i == 5)
                    {
                        CustomAssert.Fail("No connection: " + contentSoFar);
                    }

                    contentSoFar = TestSetup.ReadCurrentDefaultLog();
                    if (contentSoFar.Contains("TCPConnection - TLS/SSL handshake failed."))
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }

                pop3Server.WaitForCompletion();

                fa.Delete();
            }
        }
Example #16
0
        public void TestFetchMessagesWithVeryLongHeader()
        {
            var messages = new List <string>();

            var toHeaderBuilder = new StringBuilder();

            for (int i = 0; i < 10000; i++)
            {
                if (i > 0)
                {
                    toHeaderBuilder.Append("; ");
                }

                toHeaderBuilder.AppendFormat("to-{0}@example.com", i);
            }

            for (int i = 0; i < 5; i++)
            {
                string message = string.Format("To: {1}\r\n" +
                                               "X-Dummy: {0}\r\n" +
                                               "Subject: Test\r\n" +
                                               "\r\n" +
                                               "Hello!", i, toHeaderBuilder);

                messages.Add(message);
            }

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer;
                pop3Server.StartListen();

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

                FetchAccount fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "Test";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.Save();

                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                LockHelper.WaitForUnlock(fa);

                fa.Delete();

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 5);
                string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");



                for (int i = 0; i < 5; i++)
                {
                    if (downloadedMessage.Contains(messages[i]))
                    {
                        return;
                    }
                }

                Assert.Fail("Downloaded messages did not match uploaded messages.");
            }
        }
Example #17
0
        private void DownloadFromExternalAccount(Account account, FetchAccount fa)
        {
            if (!_backupMessages)
            return;

             // Download messages from the external account.
             var 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");

             using (var pop3Server = new POP3Server(1, fa.Port, messages))
             {
            pop3Server.StartListen();
            fa.DownloadNow();
            pop3Server.WaitForCompletion();
             }

             TestSetup.AssertRecipientsInDeliveryQueue(0);
             POP3Simulator.AssertMessageCount(account.Address, "test", 5);
        }
Example #18
0
        private void ConfirmAccountObject()
        {
            Account account = _application.Domains[0].Accounts.get_ItemByAddress("*****@*****.**");


            Assert.IsTrue(account.Active);
            Assert.AreEqual("AD", account.ADDomain);
            Assert.AreEqual(eAdminLevel.hAdminLevelDomainAdmin, account.AdminLevel);
            Assert.AreEqual("AU", account.ADUsername);
            Assert.AreEqual("FA", account.ForwardAddress);
            Assert.IsFalse(account.ForwardEnabled);
            Assert.IsTrue(account.ForwardKeepOriginal);
            Assert.IsFalse(account.IsAD);
            Assert.AreEqual(1250, account.MaxSize);
            Assert.AreEqual("First", account.PersonFirstName);
            Assert.AreEqual("Last", account.PersonLastName);
            Assert.IsTrue(account.SignatureEnabled);
            Assert.AreEqual("HTML", account.SignatureHTML);
            Assert.AreEqual("PLAIN", account.SignaturePlainText);
            Assert.AreEqual("VAC", account.VacationMessage);
            Assert.IsTrue(account.VacationMessageExpires);
            Assert.AreEqual("2020-01-01", account.VacationMessageExpiresDate.Substring(0, 10));
            Assert.IsTrue(account.VacationMessageIsOn);
            Assert.AreEqual("SUBJ", account.VacationSubject);

            // Confirm fetch account
            FetchAccount fa = account.FetchAccounts.get_Item(0);

            Assert.AreEqual(5, fa.DaysToKeepMessages);
            Assert.IsTrue(fa.Enabled);
            Assert.AreEqual(10, fa.MinutesBetweenFetch);
            Assert.AreEqual("test", fa.Name);
            Assert.AreEqual(_fetchAccountPort, fa.Port);
            Assert.AreEqual(true, fa.ProcessMIMEDate);
            Assert.IsTrue(fa.ProcessMIMERecipients);
            Assert.AreEqual("test", fa.Username);
            Assert.IsFalse(fa.UseSSL);
            Assert.AreEqual("127.0.0.1", fa.ServerAddress);
            Assert.IsTrue(fa.UseAntiSpam);
            Assert.IsTrue(fa.UseAntiVirus);

            // Make sur no additional mail is downloaded. We have already downloaded it.
            DownloadFromExternalAccount(account, fa);

            Rule rule = account.Rules[0];

            Assert.AreEqual("MyRule", rule.Name);

            RuleCriteria criteria = rule.Criterias[0];

            Assert.AreEqual(eRuleMatchType.eMTGreaterThan, criteria.MatchType);
            Assert.AreEqual(eRulePredefinedField.eFTMessageSize, criteria.PredefinedField);
            Assert.AreEqual("0", criteria.MatchValue);

            RuleAction action = rule.Actions[0];

            Assert.AreEqual(eRuleActionType.eRAForwardEmail, action.Type);
            Assert.AreEqual("*****@*****.**", action.To);
            Assert.AreEqual("Test", action.Body);
            Assert.AreEqual("File", action.Filename);
            Assert.AreEqual("T", action.FromAddress);
            Assert.AreEqual("N", action.FromName);
            Assert.AreEqual("H", action.HeaderName);
            Assert.AreEqual("Folder", action.IMAPFolder);
            Assert.AreEqual("Script", action.ScriptFunction);
            Assert.AreEqual("Subj", action.Subject);
            Assert.AreEqual("Value", action.Value);

            IMAPFolder inbox = account.IMAPFolders.get_ItemByName("INBOX");

            Messages messages = inbox.Messages;

            if (_backupMessages)
            {
                Assert.AreEqual(6, inbox.CurrentUID);
                Assert.AreEqual(_folderCreationTime, inbox.CreationTime);

                Assert.AreEqual(5, messages.Count);
                Assert.AreEqual("Message 1 Subject", messages[0].Subject);
                Assert.IsTrue(messages[1].Body.Contains("Message 3 Body"));

                Assert.AreEqual(1, messages[0].UID);
                Assert.AreEqual(3, messages[1].UID);
            }
            else
            {
                Assert.AreEqual(0, messages.Count);
            }
        }
Example #19
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.
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 1 Subject",
                                           "Message 1 Body");

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

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 2 Subject",
                                           "Message 2 Body");
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2);

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 3 Subject",
                                           "Message 3 Body");
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3);

            var sim = new ImapClientSimulator();

            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          = 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();
        }