Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            // Determine message count
            POP3Simulator pop3sim = new POP3Simulator();
            int           count   = pop3sim.GetMessageCount("*****@*****.**", "test");

            // Fetch them..
            pop3sim.ConnectAndLogon("*****@*****.**", "test");

            for (int i = 1; i <= count; i++)
            {
                pop3sim.RETR(i);
            }

            for (int i = 1; i <= count; i++)
            {
                pop3sim.DELE(i);
            }

            pop3sim.QUIT();

            System.Threading.Thread.Sleep(1000 * 60 * 60);

            stopwatch.Stop();

            Console.WriteLine("Passed time: " + stopwatch.Elapsed.TotalSeconds.ToString());
        }
Exemplo n.º 2
0
        public void TestPOP3TransactionSafety()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"));
            POP3Simulator.AssertMessageCount(account.Address, "test", 1);

            POP3Simulator sim = new POP3Simulator();

            sim.ConnectAndLogon(account.Address, "test");

            // Now delete the message using an IMAP client.
            IMAPSimulator imapSimulator = new IMAPSimulator();

            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"));

            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"));
            IMAPSimulator.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"));
        }
Exemplo n.º 3
0
        public void TestDELEInvalid()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

            POP3Simulator sim = new POP3Simulator();

            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));
        }
Exemplo n.º 4
0
        public void TestAttachmentEncoding()
        {
            var testFiles = GetTestFiles();

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

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


                string fileHash = Utilities.GetFileHash(testFile);

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

                SmtpClient client = new SmtpClient("localhost", 25);
                client.Send(mail);

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

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


                hMailServer.Message message = new hMailServer.Message();

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

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

                    Assert.AreEqual(fileHash, fileHashAfter);
                }
                finally
                {
                    File.Delete(message.Filename);
                }
            }
        }
Exemplo n.º 5
0
        public void TestUIDLWithDeleted()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

            POP3Simulator sim = new POP3Simulator();

            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."));
        }
Exemplo n.º 6
0
        public void TestNotificationOnPOP3Deletion()
        {
            _settings.IMAPIdleEnabled = true;

             hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             POP3Simulator.AssertMessageCount(account.Address, "test", 2);

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

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

             Assert.IsTrue(imapSimulator.AssertPendingDataExists());
             string data = imapSimulator.Receive();
             Assert.IsTrue(data.Contains("* 1 EXPUNGE"));
             Assert.IsFalse(imapSimulator.GetPendingDataExists());
        }