Exemple #1
0
        public void TestDisabled()
        {
            _settings.AutoBanOnLogonFailure = false;
             _settings.MaxInvalidLogonAttempts = 3;
             _settings.MaxInvalidLogonAttemptsWithin = 5;
             _settings.AutoBanMinutes = 3;

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

             var sim = new Pop3ClientSimulator();
             Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             sim.Disconnect();

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

             string errorMessage;
             // fail to log on 3 times.
             for (int i = 0; i < 5; i++)
             {
            Assert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage));
            sim.Disconnect();
             }

             Assert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK"));

             string logText = LogHandler.ReadCurrentDefaultLog();
             Assert.IsFalse(logText.Contains("Blocked either by IP range or by connection limit."), logText);
        }
        public static void AssertMessageCount(string accountName, string accountPassword, int expectedCount)
        {
            if (expectedCount == 0)
             {
            // just in case.
            CustomAsserts.AssertRecipientsInDeliveryQueue(0);
             }

             int timeout = 100;
             int actualCount = 0;
             while (timeout > 0)
             {
            var pop3ClientSimulator = new Pop3ClientSimulator();

            actualCount = pop3ClientSimulator.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));
        }
        public void IfStlsRequiredLogonShouldFailIfNoStls()
        {
            var pop3Simulator = new Pop3ClientSimulator(false, 11003);
             pop3Simulator.Connect();
             string banner;
             pop3Simulator.ReceiveBanner(out banner);

             // run over TLS.
             var result = pop3Simulator.User("*****@*****.**");
             Assert.IsTrue(result.StartsWith("-ERR STLS is required."));
        }
        public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse()
        {
            var pop3Simulator = new Pop3ClientSimulator(false, 110);
             pop3Simulator.Connect();
             string banner;

             pop3Simulator.ReceiveBanner(out banner);

             var data = pop3Simulator.CAPA();

             Assert.IsFalse(data.Contains("STLS"));
        }
        public void IfStlsRequiredLogonShouldSucceedIfStls()
        {
            var pop3Simulator = new Pop3ClientSimulator(false, 11003);
             pop3Simulator.Connect();
             string banner;
             pop3Simulator.ReceiveBanner(out banner);
             pop3Simulator.STLS();
             pop3Simulator.Handshake();

             // run over TLS.
             var result = pop3Simulator.User("*****@*****.**");
             Assert.IsTrue(result.StartsWith("+OK"));
        }
        public void IfStlsOptionalButSslRequiredByIpRangeForAuthThenAuthShouldFail()
        {
            var range = SingletonProvider<TestSetup>.Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");
             range.RequireSSLTLSForAuth = true;
             range.Save();

             var pop3Simulator = new Pop3ClientSimulator(false, 11002);
             pop3Simulator.Connect();
             string banner;
             pop3Simulator.ReceiveBanner(out banner);

             // run over TLS.
             var result = pop3Simulator.User("*****@*****.**");
             Assert.IsTrue(result.StartsWith("-ERR A SSL/TLS-connection is required for authentication."));
        }
Exemple #7
0
        public void TestImproperDisconnect()
        {
            CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, 0);

             var application = SingletonProvider<TestSetup>.Instance.GetApp();

             var account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             int iCount = application.Status.get_SessionCount(eSessionType.eSTPOP3);

             var pop3ClientSimulator = new Pop3ClientSimulator();
             pop3ClientSimulator.ConnectAndLogon(account.Address, "test");
             CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, iCount + 1);
             pop3ClientSimulator.Disconnect(); // Disconnect without sending quit

             CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, iCount);
        }
Exemple #8
0
        public void TestEmptyPassword()
        {
            Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "");

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

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

             var simSMTP = new SmtpClientSimulator();
             CustomAsserts.Throws<AuthenticationException>(() => simSMTP.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "", out message));
             Assert.AreEqual("535 Authentication failed. Restarting authentication process.\r\n", message);
        }
        public static string AssertGetFirstMessageText(string accountName, string accountPassword)
        {
            // Wait for the message to appear.
             var pop3 = new Pop3ClientSimulator();
             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;
        }
        public static void AssertMessageCount(string accountName, string accountPassword, int expectedCount)
        {
            if (expectedCount == 0)
            {
                // just in case.
                CustomAsserts.AssertRecipientsInDeliveryQueue(0);
            }

            int timeout     = 100;
            int actualCount = 0;

            while (timeout > 0)
            {
                var pop3ClientSimulator = new Pop3ClientSimulator();

                actualCount = pop3ClientSimulator.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));
        }
        public void TestSMTPServer()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             int i = 0;
             for (i = 0; i < 10; i++)
             {
            try
            {
               var smtpSim = new SmtpClientSimulator(true, 25001);
               smtpSim.Send("*****@*****.**", account.Address, "Test", "MyBody");

               break;
            }
            catch (Exception)
            {
               if (i == 9)
                  throw;
            }
             }

             Pop3ClientSimulator.AssertMessageCount(account.Address, "test", i + 1);
             var pop3Sim = new Pop3ClientSimulator(false, 110);
             string text = pop3Sim.GetFirstMessageText(account.Address, "test");
             Assert.IsTrue(text.Contains("MyBody"));
        }
Exemple #12
0
        public void TestDomainSignature()
        {
            var pop3ClientSimulator = new Pop3ClientSimulator();

             _domain.SignatureEnabled = true;
             _domain.AddSignaturesToLocalMail = true;

             Account oAccount1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**",
                                                                              "test");
             oAccount1.SignatureEnabled = true;
             oAccount1.SignaturePlainText = "PlainTextSignature";
             oAccount1.Save();

             var smtpClientSimulator = new SmtpClientSimulator();
             smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body");

             string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageContents.IndexOf("PlainTextSignature") <= 0)
            throw new Exception("Did not find signature");

             _domain.SignatureEnabled = true;
             _domain.SignaturePlainText = "DomainSignature";
             _domain.SignatureMethod = eDomainSignatureMethod.eSMAppendToAccountSignature;
             _domain.Save();
             smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body");

             sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageContents.IndexOf("PlainTextSignature") <= 0 ||
             sMessageContents.IndexOf("DomainSignature") <= 0)
            throw new Exception("Did not find signature");

             _domain.SignatureEnabled = true;
             _domain.SignaturePlainText = "DomainSignature";
             _domain.SignatureMethod = eDomainSignatureMethod.eSMOverwriteAccountSignature;
             _domain.Save();
             smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body");

             sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageContents.IndexOf("PlainTextSignature") >= 0 ||
             sMessageContents.IndexOf("DomainSignature") <= 0)
            throw new Exception("Did not find signature");

             _domain.SignatureEnabled = true;
             _domain.SignaturePlainText = "DomainSignature";
             _domain.SignatureMethod = eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount;
             _domain.Save();
             smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body");

             sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageContents.IndexOf("DomainSignature") >= 0)
            throw new Exception("Found incorrect signature.");

             _domain.SignatureEnabled = true;
             _domain.SignaturePlainText = "DomainSignature";
             _domain.SignatureMethod = eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount;
             _domain.Save();
             oAccount1.SignaturePlainText = "";
             oAccount1.Save();

             smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body");

             sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageContents.IndexOf("DomainSignature") <= 0)
            throw new Exception("Found incorrect signature.");

             _domain.AddSignaturesToLocalMail = false;
             _domain.Save();
             oAccount1.SignaturePlainText = "PlainTextSignature";
             oAccount1.Save();
             smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body");

             sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageContents.IndexOf("PlainTextSignature") > 0)
            throw new Exception("Found incorrect signature.");

             _domain.AddSignaturesToLocalMail = true;
             _domain.Save();

             smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body");

             sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageContents.IndexOf("PlainTextSignature") <= 0)
            throw new Exception("Found incorrect signature.");
        }
        public void TestAutoReply()
        {
            // Create a test account
             // Fetch the default domain
             Account oAccount1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain,
                                                                              TestSetup.UniqueString() + "@test.com",
                                                                              "test");
             Account oAccount2 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain,
                                                                              TestSetup.UniqueString() + "@test.com",
                                                                              "test");

             oAccount2.VacationMessageIsOn = true;
             oAccount2.VacationMessage = "I'm on vacation";
             oAccount2.VacationSubject = "Out of office!";
             oAccount2.Save();

             // Send 2 messages to this account.
             var smtpClientSimulator = new SmtpClientSimulator();
             smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body");

             var pop3ClientSimulator = new Pop3ClientSimulator();
             Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1);
             Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1);
             string s = pop3ClientSimulator.GetFirstMessageText(oAccount1.Address, "test");
             if (s.IndexOf("Out of office!") < 0)
            throw new Exception("ERROR - Auto reply subject not set properly.");

             oAccount2.VacationMessageIsOn = false;
             oAccount2.Save();

             oAccount2.VacationSubject = "";
             oAccount2.VacationMessageIsOn = true;
             oAccount2.Save();

             // Send another
             smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body");

             Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 2);
             Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1);

             s = pop3ClientSimulator.GetFirstMessageText(oAccount1.Address, "test");
             if (s.ToLower().IndexOf("re: test message") < 0)
            throw new Exception("ERROR - Auto reply subject not set properly.");

             Assert.IsTrue(s.Contains("Auto-Submitted: auto-replied"));

             oAccount2.VacationMessageIsOn = false;
             oAccount2.Save();
        }
        public void TestAutoReplySubject()
        {
            // Create a test account
             // Fetch the default domain
             Account oAccount1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain,
                                                                              TestSetup.UniqueString() + "@test.com",
                                                                              "test");
             Account oAccount2 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain,
                                                                              TestSetup.UniqueString() + "@test.com",
                                                                              "test");

             oAccount2.VacationMessageIsOn = true;
             oAccount2.VacationMessage = "I'm on vacation";
             oAccount2.VacationSubject = "Auto-Reply: %SUBJECT%";
             oAccount2.Save();

             // Send 1 message to this account
             var smtpClientSimulator = new SmtpClientSimulator();
             smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body");

             // Wait a second to be sure that the message
             // are delivered.

             // Check using POP3 that 2 messages exists.
             var pop3ClientSimulator = new Pop3ClientSimulator();

             Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1);
             string s = pop3ClientSimulator.GetFirstMessageText(oAccount1.Address, "test");
             if (s.IndexOf("Subject: Auto-Reply: Test message") < 0)
            throw new Exception("ERROR - Auto reply subject not set properly.");
        }
Exemple #15
0
        public void TestUIDLSpecific()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1");
             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2");
             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3");

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

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             string result = sim.UIDL(2);

             Assert.IsTrue(result.Contains("OK 2"));

             result = sim.UIDL(3);
             Assert.IsTrue(result.Contains("OK 3"));
        }
Exemple #16
0
        public void TestPOP3TransactionSafety()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody");
             Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");

             // Now delete the message using an IMAP client.
             var imapSimulator = new ImapClientSimulator();
             Assert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test"));
             Assert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             Assert.IsTrue(imapSimulator.SetDeletedFlag(1));
             Assert.IsTrue(imapSimulator.Expunge());
             Assert.AreEqual(0, imapSimulator.GetMessageCount("Inbox"));

             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody");
             ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1);

             // This deletion should not have any effect, since the POP3 connection is referencing an old message.
             sim.DELE(1);
             sim.QUIT();

             Assert.AreEqual(1, imapSimulator.GetMessageCount("Inbox"));
        }
Exemple #17
0
        public void TestTOPSpecificPartial()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             for (int i = 1; i <= 10; i++)
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test",
                                           "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n");

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

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             string result = sim.TOP(4, 2);

             Assert.IsTrue(result.Contains("Received"));
             Assert.IsTrue(result.Contains("Line1"));
             Assert.IsTrue(result.Contains("Line2"));
             Assert.IsFalse(result.Contains("Line3"));
             Assert.IsFalse(result.Contains("Line4"));
        }
Exemple #18
0
        public void TestLogonMailboxWithDeletedMessage()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             for (int i = 1; i <= 3; i++)
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test",
                                           "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n");

             // Mark the second message as deleted using IMAP.
             Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3);

             var sim = new ImapClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             sim.SelectFolder("INBOX");
             sim.SetDeletedFlag(2);
             sim.Disconnect();

             // Now list messages and confirm that all are listed.

             var pop3Client = new Pop3ClientSimulator();
             pop3Client.ConnectAndLogon(account.Address, "test");
             string listResponse = pop3Client.LIST();
             string uidlResponse = pop3Client.UIDL();

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

             Assert.IsTrue(uidlResponse.Contains("\r\n1"));
             Assert.IsTrue(uidlResponse.Contains("\r\n2"));
             Assert.IsTrue(uidlResponse.Contains("\r\n3"));
             Assert.IsTrue(uidlResponse.Contains("\r\n.\r\n"));
             Assert.IsTrue(uidlResponse.Contains("3 messages"));
        }
Exemple #19
0
        public void TestSendToMultipleAccounts()
        {
            Application application = SingletonProvider<TestSetup>.Instance.GetApp();
             Account oAccount1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             Account oAccount2 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             Account oAccount3 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             var smtpClientSimulator = new SmtpClientSimulator();

             var lstRecipients = new List<string>();
             lstRecipients.Add("*****@*****.**");
             lstRecipients.Add("*****@*****.**");
             lstRecipients.Add("*****@*****.**");

             string sBody = "Test of sending same email to multiple accounts.";

             smtpClientSimulator.Send(oAccount1.Address, lstRecipients, "Multi test", sBody);

             var pop3ClientSimulator = new Pop3ClientSimulator();

             string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");
             if (sMessageData.IndexOf(sBody) < 0)
            throw new Exception("E-mail not found");

             sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test");
             if (sMessageData.IndexOf(sBody) < 0)
            throw new Exception("E-mail not found");

             sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount3.Address, "test");
             if (sMessageData.IndexOf(sBody) < 0)
            throw new Exception("E-mail not found");
        }
 public void TestPOP3Server()
 {
     var sim = new Pop3ClientSimulator();
      sim.ConnectAndLogon(GetUsername(), GetPassword());
      EnsureNoPassword();
 }
Exemple #21
0
        public void TestAttachmentEncoding()
        {
            string[] testFiles = GetTestFiles();

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

             foreach (string testFile in testFiles)
             {
            Trace.WriteLine(testFile);

            string fileHash = GetFileHash(testFile);

            var mail = new MailMessage();
            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add("*****@*****.**");
            mail.Subject = "Test";
            mail.Attachments.Add(new Attachment(testFile));

            SendMessage(mail);

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

            var sim = new Pop3ClientSimulator();
            sim.ConnectAndLogon("*****@*****.**", "test");
            string fileContent = sim.RETR(1);
            sim.DELE(1);
            sim.QUIT();

            var message = new Message();

            try
            {
               File.WriteAllText(message.Filename, fileContent);
               message.RefreshContent();

               message.Attachments[0].SaveAs(message.Filename);
               string fileHashAfter = GetFileHash(message.Filename);

               Assert.AreEqual(fileHash, fileHashAfter);
            }
            finally
            {
               File.Delete(message.Filename);
            }
             }
        }
Exemple #22
0
        public void WelcomeMessage()
        {
            SingletonProvider<TestSetup>.Instance.GetApp().Settings.WelcomePOP3 = "HOWDYHO POP3";

             var oSimulator = new Pop3ClientSimulator();

             string sWelcomeMessage = oSimulator.GetWelcomeMessage();

             if (sWelcomeMessage != "+OK HOWDYHO POP3\r\n")
            throw new Exception("ERROR - Wrong welcome message.");
        }
Exemple #23
0
        public void TestUIDLWithDeleted()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             for (int i = 1; i <= 10; i++)
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString());

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

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             sim.DELE(2);
             sim.DELE(4);
             string result = sim.UIDL();

             Assert.IsTrue(result.Contains("8 messages"));
             Assert.IsTrue(result.Contains("\r\n1"));
             Assert.IsTrue(result.Contains("\r\n3"));
             Assert.IsTrue(result.Contains("\r\n5"));
             Assert.IsTrue(result.Contains("\r\n."));
        }
Exemple #24
0
        public void TestNotificationOnPOP3Deletion()
        {
            _settings.IMAPIdleEnabled = true;

             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2);

             var imapSimulator = new ImapClientSimulator();
             string sWelcomeMessage = imapSimulator.Connect();
             Assert.IsTrue(imapSimulator.Logon("*****@*****.**", "test"));
             Assert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             Assert.IsTrue(imapSimulator.StartIdle());

             var sim = new Pop3ClientSimulator();
             Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             Assert.IsTrue(sim.DELE(1));
             sim.QUIT();

             // After a delete, the following should be sent tot he IMAP client:
             //  - EXPUNGE
             //  - EXISTS
             //  - RECENT
             Assert.IsTrue(imapSimulator.AssertPendingDataExists(), "No pending data exist");

             var deadline = DateTime.Now.AddSeconds(10);
             var message = new StringBuilder();

             while (DateTime.Now < deadline)
             {
            if (imapSimulator.GetPendingDataExists())
               message.Append(imapSimulator.Receive());

            var str = message.ToString();

            if (str.Contains("* 1 EXPUNGE") &&
                str.Contains("EXISTS") &&
                str.Contains("RECENT"))
            {
               return;
            }
             }

             var receivedText = message.ToString();
             Assert.IsTrue(receivedText.Contains("* 1 EXPUNGE"), receivedText);
             Assert.IsTrue(receivedText.Contains("EXISTS"), receivedText);
             Assert.IsTrue(receivedText.Contains("RECENT"), receivedText);
        }
Exemple #25
0
        public void TestIPRangeName()
        {
            _settings.AutoBanOnLogonFailure = true;
             _settings.MaxInvalidLogonAttempts = 3;
             _settings.MaxInvalidLogonAttemptsWithin = 5;
             _settings.AutoBanMinutes = 3;

             Assert.AreEqual(2, _settings.SecurityRanges.Count);

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

             var sim = new Pop3ClientSimulator();
             Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             sim.Disconnect();

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

             string errorMessage;
             // fail to log on 3 times.
             for (int i = 0; i < 3; i++)
             {
            Assert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage));
            sim.Disconnect();

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

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

             Assert.AreEqual(3, _settings.SecurityRanges.Count);
             Assert.AreEqual("Auto-ban: [email protected]", _settings.SecurityRanges[2].Name);
        }
        public void StlsCommandShouldSwithToTls()
        {
            var pop3Simulator = new Pop3ClientSimulator(false, 11002);
             pop3Simulator.Connect();
             string banner;
             pop3Simulator.ReceiveBanner(out banner);
             pop3Simulator.STLS();
             pop3Simulator.Handshake();

             // run over TLS.
             pop3Simulator.HELP();
        }
Exemple #27
0
        public void TestTOPSpecificEntire()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             for (int i = 1; i <= 10; i++)
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString());

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

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             string result = sim.TOP(1, 0);

             Assert.IsTrue(result.Contains("Received"));
             Assert.IsTrue(result.Contains("Subject"));
        }
Exemple #28
0
        public void TestDELEInvalid()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             for (int i = 1; i <= 10; i++)
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString());

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

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             Assert.IsFalse(sim.DELE(0));
             Assert.IsFalse(sim.DELE(-1));
             Assert.IsFalse(sim.DELE(1000));
             Assert.IsTrue(sim.DELE(5));
        }
Exemple #29
0
        public void TestUIDLInvalid()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             for (int i = 1; i <= 10; i++)
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString());

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

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             string result = sim.UIDL(0);
             Assert.IsTrue(result.Contains("No such message"));
             result = sim.UIDL(-1);
             Assert.IsTrue(result.Contains("No such message"));
             result = sim.UIDL(100);
             Assert.IsTrue(result.Contains("No such message"));
        }
Exemple #30
0
        public void TestPortOpening()
        {
            Application oApp = SingletonProvider<TestSetup>.Instance.GetApp();

             oApp.Settings.TCPIPPorts.SetDefault();

             var pSMTPSimulator = new TcpConnection();
             var pPOP3Simulator = new Pop3ClientSimulator();
             var pIMAPSimulator = new ImapClientSimulator();

             oApp.Stop();

             TCPIPPorts oPorts = oApp.Settings.TCPIPPorts;
             for (int i = 0; i < oPorts.Count; i++)
             {
            TCPIPPort oTestPort = oPorts[i];
            if (oTestPort.Protocol == eSessionType.eSTIMAP)
               oTestPort.PortNumber = 14300;
            else if (oTestPort.Protocol == eSessionType.eSTSMTP)
               oTestPort.PortNumber = 11000;
            else if (oTestPort.Protocol == 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();

             TCPIPPort oPort = oApp.Settings.TCPIPPorts.Add();
             oPort.Protocol = 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++)
             {
            TCPIPPort oTestPort = oPorts[i];
            if (oTestPort.Protocol == eSessionType.eSTIMAP)
               oTestPort.PortNumber = 143;
            else if (oTestPort.Protocol == eSessionType.eSTSMTP)
               oTestPort.PortNumber = 25;
            else if (oTestPort.Protocol == eSessionType.eSTPOP3)
               oTestPort.PortNumber = 110;

            oTestPort.Save();
             }

             oApp.Start();

             Assert.IsTrue(pSMTPSimulator.TestConnect(25));
             Assert.IsTrue(pPOP3Simulator.TestConnect(110));
             Assert.IsTrue(pPOP3Simulator.TestConnect(143));
        }
Exemple #31
0
        public void TestTopDotOnOtherwiseEmptyLineShouldBeEscaped()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test",
                                          "Line1\r\nLine2\r\n..\r\nLine4\r\n..A\r\n.B\r\nLine6\r\n");

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

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             string result = sim.TOP(1, 100);

             Assert.IsTrue(result.Contains("Line1\r\nLine2\r\n..\r\nLine4\r\n..A\r\nB\r\nLine6\r\n"), result);
        }