Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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"));
        }
Ejemplo n.º 3
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);
            }
             }
        }
Ejemplo n.º 4
0
        public void TestReinitialize()
        {
            string @messageText =
            "From: [email protected]\r\n" +
            "\r\n" +
            "WhatTest\r\n";

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

             // Create another message on disk and import it.
             string domainPath = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com");
             string accountPath = Path.Combine(domainPath, "test");
             Directory.CreateDirectory(accountPath);
             string fileName = Path.Combine(accountPath, "something.eml");
             File.WriteAllText(fileName, messageText);
             Assert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID));

             // Since the cache isn't refreshed, the message has not yet appeared.
             Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);

             // Reinitialize the server. Should, among other things, clear the cache.
             _application.Reinitialize();

             // Now the message should have appeared.
             Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2);

             var sim = new Pop3ClientSimulator();
             sim.ConnectAndLogon(account.Address, "test");
             messageText = sim.RETR(2);
             sim.QUIT();

             Assert.IsTrue(messageText.Contains("WhatTest"), messageText);
        }