Example #1
0
        public void TestFetchMessageWithInvalidFromAddress()
        {
            string message = string.Format("From: A\r\n" +
                                           "To: [email protected]\r\n" +
                                           "Subject: Test\r\n" +
                                           "\r\n" +
                                           "Hello!");

            var messages = new List <string>()
            {
                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", 1);

                var log = LogHandler.ReadCurrentDefaultLog();
                Assert.IsTrue(log.Contains("Delivering message from <Empty> to [email protected]."));
            }
        }
Example #2
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.");
            }
        }