Esempio n. 1
0
        public void TestAttachmentEncoding()
        {
            string[] testFiles = GetTestFiles();

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

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

            string fileHash = TestSetup.GetFileHash(testFile);

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

            TestSetup.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 = TestSetup.GetFileHash(message.Filename);

               CustomAssert.AreEqual(fileHash, fileHashAfter);
            }
            finally
            {
               File.Delete(message.Filename);
            }
             }
        }
Esempio n. 2
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");
             CustomAssert.IsFalse(sim.DELE(0));
             CustomAssert.IsFalse(sim.DELE(-1));
             CustomAssert.IsFalse(sim.DELE(1000));
             CustomAssert.IsTrue(sim.DELE(5));
        }
Esempio n. 3
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();

             CustomAssert.IsTrue(result.Contains("8 messages"));
             CustomAssert.IsTrue(result.Contains("\r\n1"));
             CustomAssert.IsTrue(result.Contains("\r\n3"));
             CustomAssert.IsTrue(result.Contains("\r\n5"));
             CustomAssert.IsTrue(result.Contains("\r\n."));
        }
Esempio n. 4
0
        public void TestPOP3TransactionSafety()
        {
            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             CustomAssert.IsTrue(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();
             CustomAssert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             CustomAssert.IsTrue(imapSimulator.SetDeletedFlag(1));
             CustomAssert.IsTrue(imapSimulator.Expunge());
             CustomAssert.AreEqual(0, imapSimulator.GetMessageCount("Inbox"));

             CustomAssert.IsTrue(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();

             CustomAssert.AreEqual(1, imapSimulator.GetMessageCount("Inbox"));
        }
Esempio n. 5
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();
             CustomAssert.IsTrue(imapSimulator.Logon("*****@*****.**", "test"));
             CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             CustomAssert.IsTrue(imapSimulator.StartIdle());

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

             // After a delete, the following should be sent tot he IMAP client:
             //  - EXPUNGE
             //  - EXISTS
             //  - RECENT
             CustomAssert.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();
             CustomAssert.IsTrue(receivedText.Contains("* 1 EXPUNGE"), receivedText);
             CustomAssert.IsTrue(receivedText.Contains("EXISTS"), receivedText);
             CustomAssert.IsTrue(receivedText.Contains("RECENT"), receivedText);
        }