예제 #1
0
        public void TestRETR()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1");
            POP3Simulator.AssertMessageCount(account.Address, "test", 1);

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2");
            POP3Simulator.AssertMessageCount(account.Address, "test", 2);

            SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3");
            POP3Simulator.AssertMessageCount(account.Address, "test", 3);

            POP3Simulator sim = new POP3Simulator();

            sim.ConnectAndLogon(account.Address, "test");
            string result = sim.RETR(1);

            Assert.IsTrue(result.Contains("TestBody1"), result);
            result = sim.RETR(2);
            Assert.IsTrue(result.Contains("TestBody2"), result);
            result = sim.RETR(3);
            Assert.IsTrue(result.Contains("TestBody3"), result);

            Assert.IsFalse(result.Contains(".\r\n."));
        }
예제 #2
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());
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
파일: API.cs 프로젝트: radtek/hMailServer
        public void TestReinitialize()
        {
            string @messageText =
                "From: [email protected]\r\n" +
                "\r\n" +
                "WhatTest\r\n";

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

            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "First message", "Test message"));
            POP3Simulator.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.
            POP3Simulator.AssertMessageCount(account.Address, "test", 1);

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

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

            POP3Simulator sim = new POP3Simulator();

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

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