コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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();
            }
        }