コード例 #1
0
ファイル: API.cs プロジェクト: radtek/hMailServer
        public void TestSaveMessageInExistingIMAPFolder()
        {
            hMailServer.Settings settings = SingletonProvider <Utilities> .Instance.GetApp().Settings;

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

            // Check that the message does not exist
            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 0);

            // Send a message to the account.
            hMailServer.IMAPFolder folder = oAccount1.IMAPFolders.get_ItemByName("INBOX");

            hMailServer.Message oMessage = folder.Messages.Add();

            Assert.AreEqual(0, oMessage.State);

            oMessage.Body    = "Välkommen till verkligheten";
            oMessage.Subject = "Hej";
            oMessage.Save();

            Assert.AreEqual(2, oMessage.State);
            Assert.IsFalse(oMessage.Filename.Contains(settings.PublicFolderDiskName));
            Assert.IsTrue(oMessage.Filename.Contains(_domain.Name));

            // Check that the message exists
            string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            Assert.IsNotEmpty(message);
            Assert.Less(0, message.IndexOf("Hej"));
        }
コード例 #2
0
        public void TestMoveMessageWithAccountLevelRule()
        {
            hMailServer.Account testAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "Test'*****@*****.**", "test");

            // First deliver two messages to the inbox.
            SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");
            POP3Simulator.AssertMessageCount(testAccount.Address, "test", 1);
            hMailServer.IMAPFolder inboxFolder = testAccount.IMAPFolders[0];
            Assert.AreEqual(1, inboxFolder.CurrentUID);
            Assert.AreEqual(1, inboxFolder.Messages[0].UID);

            SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");
            POP3Simulator.AssertMessageCount(testAccount.Address, "test", 2);
            Assert.AreEqual(2, inboxFolder.CurrentUID);
            Assert.AreEqual(2, inboxFolder.Messages[1].UID);

            CreateMoveRule(testAccount.Rules, "TestFolder");

            // This message will be moved into the test folder.
            SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");

            // Wait for the message to arrive.
            Utilities.AssertFolderExists(testAccount.IMAPFolders, "TestFolder");

            hMailServer.IMAPFolder testFolder = testAccount.IMAPFolders.get_ItemByName("TestFolder");

            // Since the message is placed in a new folder, it should receive a unique UID.
            Utilities.AssertMessageExistsInFolder(testFolder, 1);
            Assert.AreEqual(1, testFolder.CurrentUID);
            Assert.AreEqual(1, testFolder.Messages[0].UID);
        }
コード例 #3
0
        public void TestBasicIncrementsWithDeletion()
        {
            hMailServer.Account testAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "Test'*****@*****.**", "test");

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

            hMailServer.IMAPFolder inboxFolder = testAccount.IMAPFolders[0];

            Assert.AreEqual(1, inboxFolder.CurrentUID);
            Assert.AreEqual(1, inboxFolder.Messages[0].UID);
            POP3Simulator.AssertGetFirstMessageText(testAccount.Address, "test");

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

            Assert.AreEqual(2, inboxFolder.CurrentUID);
            Assert.AreEqual(2, inboxFolder.Messages[0].UID);
            POP3Simulator.AssertGetFirstMessageText(testAccount.Address, "test");


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

            Assert.AreEqual(3, inboxFolder.CurrentUID);
            Assert.AreEqual(3, inboxFolder.Messages[0].UID);
        }
コード例 #4
0
ファイル: API.Message.cs プロジェクト: radtek/hMailServer
        public void TestUpdateSubjectOnMessageWithNoMessageWideCharacterSet()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine +
                            " oMessage.Subject = \"[ov]\" + oMessage.Subject " + Environment.NewLine +
                            " oMessage.Save() " + Environment.NewLine +
                            "End Sub" + Environment.NewLine + Environment.NewLine;

            hMailServer.Scripting scripting = _settings.Scripting;
            System.IO.File.WriteAllText(scripting.CurrentScriptFile, script);
            scripting.Enabled = true;
            scripting.Reload();
            Assert.IsEmpty(scripting.CheckSyntax());

            string body = @"From: <*****@*****.**>" + Environment.NewLine +
                          "Subject: =?windows-1251?B?yuDr7Pvq7uLzIMji4O3zIC0g7/Do7OXwICLy5fXt6Pfl8eru4+4g8OX4?=" + Environment.NewLine +
                          "   =?windows-1251?B?5e3o/yIgW0Z3ZDog0tAg4uXw8ejoIDEuMl0=?=" + Environment.NewLine +
                          Environment.NewLine +
                          "Hej!" + Environment.NewLine;



            SMTPClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", body);

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

            Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1);

            string subject = account.IMAPFolders[0].Messages[0].Subject;
        }
コード例 #5
0
ファイル: API.cs プロジェクト: radtek/hMailServer
        public void TestLiveLog()
        {
            hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp();

            hMailServer.Utilities utilities = app.Utilities;

            hMailServer.Logging logging = app.Settings.Logging;

            logging.EnableLiveLogging(true);

            // Add an account and send a message to it.
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            string liveLog = logging.LiveLog;

            Assert.IsTrue(liveLog.Length > 0, liveLog);

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

            logging.EnableLiveLogging(true);

            liveLog = logging.LiveLog;
            Assert.IsFalse(liveLog.Contains("SMTPDeliverer - Message"));
        }
コード例 #6
0
        public void TestSpamProtectionPreTransmissionHELOPassFirst()
        {
            _application.Settings.AntiSpam.SpamMarkThreshold   = 1;
            _application.Settings.AntiSpam.SpamDeleteThreshold = 100;
            _application.Settings.AntiSpam.AddHeaderReason     = true;
            _application.Settings.AntiSpam.AddHeaderSpam       = true;
            _application.Settings.AntiSpam.PrependSubject      = true;
            _application.Settings.AntiSpam.PrependSubjectText  = "ThisIsSpam";

            _application.Settings.AntiSpam.CheckHostInHelo      = true;
            _application.Settings.AntiSpam.CheckHostInHeloScore = 105;

            hMailServer.IncomingRelay incomingRelay = _application.Settings.IncomingRelays.Add();
            incomingRelay.LowerIP = "1.2.1.2";
            incomingRelay.UpperIP = "1.2.1.3";
            incomingRelay.Name    = "Test";
            incomingRelay.Save();

            List <string> messages = new List <string>();

            string message = "Received: from example.com (example.com [1.2.1.2]) by mail.host.edu\r\n" +
                             "Received: from mail.hmailserver.com (mail.hmailserver.com [" + Utilities.GethMailServerCOMIPaddress() + "]) by mail.host.edu\r\n" +
                             "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Should be blocked by SPF.";

            messages.Add(message);

            int        port       = 1110;
            POP3Server pop3Server = new POP3Server(1, port, messages);

            pop3Server.StartListen();

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

            hMailServer.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.DaysToKeepMessages    = 0;
            fa.UseAntiSpam           = true;
            fa.Save();

            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

            POP3Simulator.AssertMessageCount(account.Address, "test", 1);
        }
コード例 #7
0
        public void TestSearchUTF8TEXT()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string body = Utilities.GetResource("Messages.MessageContainingGreekSubject.txt");

            SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body);

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

            IMAPSimulator oSimulator = new IMAPSimulator();

            Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(oSimulator.SelectFolder("INBOX"));

            string result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK");

            Assert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT 標準語");
            Assert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK標準語");
            Assert.AreEqual("1", result);

            result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣKWHAT標準語");
            Assert.AreEqual("", result);
        }
コード例 #8
0
ファイル: API.Utilities.cs プロジェクト: radtek/hMailServer
        public void TestImportOfMessageIntoOtherFolder()
        {
            string @messageText =
                "From: [email protected]\r\n" +
                "\r\n" +
                "Test\r\n";

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

            account.IMAPFolders.Add("Woho");

            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.ImportMessageFromFileToIMAPFolder(fileName, account.ID, "Woho"));

            POP3Simulator.AssertMessageCount("*****@*****.**", "test", 0);
            IMAPSimulator sim = new IMAPSimulator();

            sim.ConnectAndLogon("*****@*****.**", "test");
            Assert.AreEqual(1, sim.GetMessageCount("Woho"));
            sim.Disconnect();
        }
コード例 #9
0
ファイル: AccountServices.cs プロジェクト: radtek/hMailServer
        public void TestAutoReplyCombinedWithForwarding()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            hMailServer.Account oAccount2 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            hMailServer.Account oAccount3 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            oAccount2.VacationMessageIsOn = true;
            oAccount2.VacationMessage     = "I'm on vacation";
            oAccount2.VacationSubject     = "Out of office!";

            oAccount2.ForwardAddress      = oAccount3.Address;
            oAccount2.ForwardEnabled      = true;
            oAccount2.ForwardKeepOriginal = true;
            oAccount2.Save();

            // Send a message...
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body");

            SingletonProvider <Utilities> .Instance.GetApp().SubmitEMail();

            Utilities.AssertRecipientsInDeliveryQueue(0);

            // Wait for the auto-reply.
            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1);
            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 1);
            POP3Simulator.AssertMessageCount(oAccount3.Address, "test", 1);
        }
コード例 #10
0
ファイル: AccountServices.cs プロジェクト: radtek/hMailServer
        public void TestForwardingAndDelete()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            // Set up account 1 to forward to account2.
            oAccount1.ForwardEnabled      = true;
            oAccount1.ForwardAddress      = "*****@*****.**";
            oAccount1.ForwardKeepOriginal = false;
            oAccount1.Save();

            // Send 2 messages to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "POP3 test message");
            Utilities.AssertRecipientsInDeliveryQueue(0);
            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 1);

            string domainDir = Path.Combine(_settings.Directories.DataDirectory, "test.com");
            string userDir   = Path.Combine(domainDir, "Forward1");

            string[] dirs = Directory.GetDirectories(userDir);
            foreach (string dir in dirs)
            {
                string[] files = Directory.GetFiles(dir);

                Assert.AreEqual(0, files.Length);
            }
        }
コード例 #11
0
ファイル: AccountServices.cs プロジェクト: radtek/hMailServer
        public void TestForwarding()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            // Set up account 1 to forward to account2.
            oAccount1.ForwardEnabled      = true;
            oAccount1.ForwardAddress      = "*****@*****.**";
            oAccount1.ForwardKeepOriginal = true;
            oAccount1.Save();

            // Send 2 messages to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            for (int i = 0; i < 2; i++)
            {
                oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "POP3 test message");
            }

            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 2);

            // Tell hMailServer to deliver now, so that the forward takes effect.
            SingletonProvider <Utilities> .Instance.GetApp().SubmitEMail();

            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 2);
        }
コード例 #12
0
        public void TestAntiVirusDisabled()
        {
            List <string> messages = new List <string>();

            string messageText = "From: [email protected]\r\n" +
                                 "To: [email protected]\r\n" +
                                 "Subject: Test\r\n" +
                                 "\r\n" +
                                 "Should be blocked by SPF.";

            messages.Add(messageText);

            int        port       = 1110;
            POP3Server pop3Server = new POP3Server(1, port, messages);

            pop3Server.StartListen();

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

            hMailServer.FetchAccount fa = CreateFetchAccount(account, port, false, false);

            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

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

            hMailServer.Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0];
            Assert.IsFalse(message.get_Flag(hMailServer.eMessageFlag.eMFVirusScan));
        }
コード例 #13
0
ファイル: IMAP.Examine.cs プロジェクト: radtek/hMailServer
        public void TestExpunge()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1);

            IMAPSimulator simulator = new IMAPSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.SelectFolder("Inbox");
            Assert.IsTrue(simulator.SetFlagOnMessage(1, true, @"\Deleted"));

            IMAPSimulator secondSimulator = new IMAPSimulator();

            secondSimulator.ConnectAndLogon(oAccount.Address, "test");
            string result = secondSimulator.ExamineFolder("INBOX");

            Assert.IsTrue(result.Contains("1 EXISTS"), result);
            Assert.IsFalse(secondSimulator.Expunge());

            simulator.SelectFolder("INBOX");
            Assert.IsTrue(simulator.Expunge());

            simulator.Close();
            secondSimulator.Close();
        }
コード例 #14
0
ファイル: IMAP.Fetch.cs プロジェクト: radtek/hMailServer
        public void TestFetchHeaderFieldsNot()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string message = "From: Someone <*****@*****.**>" + Environment.NewLine +
                             "To: Someoen <*****@*****.**>" + Environment.NewLine +
                             "Date: Wed, 22 Apr 2009 11:05:09 \"GMT\"" + Environment.NewLine +
                             "Subject: Something" + Environment.NewLine +
                             Environment.NewLine +
                             "Hello" + Environment.NewLine;

            SMTPClientSimulator smtpSimulator = new SMTPClientSimulator();

            Assert.IsTrue(smtpSimulator.SendRaw(account.Address, account.Address, message));

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

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(account.Address, "test");
            oSimulator.SelectFolder("INBOX");
            string result = oSimulator.Fetch("1 BODY.PEEK[HEADER.FIELDS.NOT (Subject From)]");

            oSimulator.Disconnect();


            Assert.IsTrue(result.Contains("Received:"), result);
            Assert.IsFalse(result.Contains("Subject:"), result);
            Assert.IsFalse(result.Contains("From:"), result);
            // The feedback should end with an empty header line.
            Assert.IsTrue(result.Contains("\r\n\r\n)"), result);
        }
コード例 #15
0
ファイル: Delivery.cs プロジェクト: radtek/hMailServer
        public void TestMirrorMultipleRecipients()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

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

            _settings.MirrorEMailAddress   = "*****@*****.**";
            _settings.AddDeliveredToHeader = true;

            // Send 5 messages to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", new List <string>()
            {
                oAccount1.Address, oAccount2.Address, oAccount3.Address
            }, "INBOX", "Mirror test message");

            POP3Simulator.AssertMessageCount(mirrorAccount.Address, "test", 1);

            string message = POP3Simulator.AssertGetFirstMessageText(mirrorAccount.Address, "test");

            Assert.IsTrue(message.Contains("Delivered-To: [email protected],[email protected],[email protected]"));

            Utilities.AssertRecipientsInDeliveryQueue(0);
        }
コード例 #16
0
ファイル: Delivery.cs プロジェクト: radtek/hMailServer
        public void TestMirrorMultipleRecipientsOver255Chars()
        {
            // Create a test account
            // Fetch the default domain
            List <string> recipients = new List <string>();

            for (int i = 0; i < 20; i++)
            {
                string address = string.Format("mirror{0}@test.com", i);
                SingletonProvider <Utilities> .Instance.AddAccount(_domain, address, "test");

                recipients.Add(address);
            }

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

            _settings.MirrorEMailAddress   = "*****@*****.**";
            _settings.AddDeliveredToHeader = true;

            // Send 5 messages to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", recipients, "INBOX", "Mirror test message");

            POP3Simulator.AssertMessageCount(mirrorAccount.Address, "test", 1);

            string message = POP3Simulator.AssertGetFirstMessageText(mirrorAccount.Address, "test");

            Assert.IsTrue(message.Contains("Delivered-To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],mirror14@test\r\n"));

            Utilities.AssertRecipientsInDeliveryQueue(0);
        }
コード例 #17
0
        public void MultiThread()
        {
            hMailServer.Account account =
                SingletonProvider <Utilities> .Instance.AddAccount(_domain.Accounts, "*****@*****.**", "test");

            int threadCount = 5;

            _threadedMessageCount = 100;
            int totalMessageCount = threadCount * _threadedMessageCount;

            List <Thread> threads = new List <Thread>();

            for (int thread = 0; thread < threadCount; thread++)
            {
                Thread t = new Thread(new ThreadStart(SendMessageThread));

                threads.Add(t);

                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

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

            for (int i = 0; i < totalMessageCount; i++)
            {
                string content = POP3Simulator.AssertGetFirstMessageText(account.Address, "test");

                Assert.IsTrue(content.Contains("X-Spam-Status"), content);
            }
        }
コード例 #18
0
ファイル: Delivery.cs プロジェクト: radtek/hMailServer
        public void TestMirror()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            _settings.MirrorEMailAddress   = "*****@*****.**";
            _settings.AddDeliveredToHeader = true;

            // Send 5 messages to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            for (int i = 0; i < 5; i++)
            {
                oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Mirror test message");
            }

            // Check using POP3 that 5 messages exists.
            POP3Simulator.AssertMessageCount("*****@*****.**", "test", 5);

            string message = POP3Simulator.AssertGetFirstMessageText(oAccount2.Address, "test");

            Assert.IsTrue(message.Contains("Delivered-To: [email protected]"));
        }
コード例 #19
0
        public void TestMissingMXRecord()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            // Create a test account
            // Fetch the default domain
            ;
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Disallow incorrect line endings.

            _antiSpam.SpamDeleteThreshold = 1;
            _antiSpam.UseMXChecks         = true;
            _antiSpam.UseMXChecksScore    = 2;

            // Send a messages to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            if (!oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "This is a test message."))
            {
                throw new Exception("ERROR - Was not able to send correct email.");
            }

            if (oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", "This is a test message."))
            {
                throw new Exception("ERROR - Was not able to send incorrect email.");
            }

            _antiSpam.UseMXChecks = false;

            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1);
        }
コード例 #20
0
        public void TestEnabled()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            hMailServer.WhiteListAddresses obAddresses = _antiSpam.WhiteListAddresses;
            hMailServer.WhiteListAddress   obAddress   = obAddresses.Add();

            obAddress.EmailAddress   = "*****@*****.**";
            obAddress.LowerIPAddress = "0.0.0.0";
            obAddress.UpperIPAddress = "255.255.255.255";
            obAddress.Description    = "Test";
            obAddress.Save();

            // Enable SURBL.
            hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];
            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account.
            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"));

            obAddresses.DeleteByDBID(obAddress.ID);

            // Check that it's detected as spam again.
            Assert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"));

            POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1);
        }
コード例 #21
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"));
        }
コード例 #22
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."));
        }
コード例 #23
0
ファイル: IMAP.Examine.cs プロジェクト: radtek/hMailServer
        public void TestChangeRecentFlag()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1);

            IMAPSimulator simulator = new IMAPSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            string result = simulator.ExamineFolder("Inbox");

            Assert.IsTrue(result.Contains("* 1 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();

            simulator = new IMAPSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            Assert.IsTrue(simulator.SelectFolder("Inbox", out result));
            Assert.IsTrue(result.Contains("* 1 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();

            simulator = new IMAPSimulator();
            simulator.ConnectAndLogon(oAccount.Address, "test");
            result = simulator.ExamineFolder("Inbox");
            Assert.IsTrue(result.Contains("* 0 RECENT"), result);
            simulator.Close();
            simulator.Disconnect();
        }
コード例 #24
0
ファイル: SSL.cs プロジェクト: radtek/hMailServer
        public void TestPOP3Server()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SMTPClientSimulator smtpSim = new SMTPClientSimulator();

            Assert.IsTrue(smtpSim.Send("*****@*****.**", account.Address, "Test", "MyBody"));

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    POP3Simulator.AssertMessageCount(account.Address, "test", 1);
                    POP3Simulator pop3Sim = new POP3Simulator(true, 11000);
                    string        text    = pop3Sim.GetFirstMessageText(account.Address, "test");

                    Assert.IsTrue(text.Contains("MyBody"));

                    break;
                }
                catch (AssertionException)
                {
                    throw;
                }
                catch (Exception)
                {
                    if (i == 9)
                    {
                        throw;
                    }
                }
            }
        }
コード例 #25
0
ファイル: AccountServices.cs プロジェクト: radtek/hMailServer
        public void TestAutoReplySubject()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            hMailServer.Account oAccount2 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            oAccount2.VacationMessageIsOn = true;
            oAccount2.VacationMessage     = "I'm on vacation";
            oAccount2.VacationSubject     = "Auto-Reply: %SUBJECT%";
            oAccount2.Save();

            // Send 1 message to this account
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body");

            // Wait a second to be sure that the message
            // are delivered.

            // Check using POP3 that 2 messages exists.
            POP3Simulator oPOP3 = new POP3Simulator();

            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1);
            string s = oPOP3.GetFirstMessageText(oAccount1.Address, "test");

            if (s.IndexOf("Subject: Auto-Reply: Test message") < 0)
            {
                throw new Exception("ERROR - Auto reply subject not set properly.");
            }
        }
コード例 #26
0
ファイル: IMAP.Examine.cs プロジェクト: radtek/hMailServer
        public void TestChangeSeenFlag()
        {
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1);

            IMAPSimulator simulator = new IMAPSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.ExamineFolder("Inbox");
            string flags      = simulator.GetFlags(1);
            string body       = simulator.Fetch("1 RFC822");
            string flagsAfter = simulator.GetFlags(1);

            simulator.Close();
            simulator.Disconnect();

            Assert.AreEqual(flags, flagsAfter);

            IMAPSimulator secondSimulator = new IMAPSimulator();

            secondSimulator.ConnectAndLogon(oAccount.Address, "test");
            secondSimulator.SelectFolder("Inbox");
            string secondFlags      = secondSimulator.GetFlags(1);
            string secondBody       = secondSimulator.Fetch("1 RFC822");
            string secondFlagsAfter = secondSimulator.GetFlags(1);

            secondSimulator.Close();
            secondSimulator.Disconnect();

            Assert.AreNotEqual(secondFlags, secondFlagsAfter);
        }
コード例 #27
0
ファイル: IMAP.Fetch.cs プロジェクト: radtek/hMailServer
        public void TestFetchEnvelopeWithDateContainingQuote()
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            string message = "From: Someone <*****@*****.**>" + Environment.NewLine +
                             "To: Someoen <*****@*****.**>" + Environment.NewLine +
                             "Date: Wed, 22 Apr 2009 11:05:09 \"GMT\"" + Environment.NewLine +
                             "Subject: Something" + Environment.NewLine +
                             Environment.NewLine +
                             "Hello" + Environment.NewLine;

            SMTPClientSimulator smtpSimulator = new SMTPClientSimulator();

            smtpSimulator.SendRaw(account.Address, account.Address, message);

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

            IMAPSimulator oSimulator      = new IMAPSimulator();
            string        sWelcomeMessage = oSimulator.Connect();

            oSimulator.Logon(account.Address, "test");
            oSimulator.SelectFolder("INBOX");
            string result = oSimulator.Fetch("1 ENVELOPE");

            oSimulator.Disconnect();

            Assert.IsTrue(result.Contains("Wed, 22 Apr 2009 11:05:09 GMT"));
        }
コード例 #28
0
        public void TestSpamProtectionNoTagging()
        {
            Utilities.AssertSpamAssassinIsRunning();

            _application.Settings.AntiSpam.SpamMarkThreshold   = 5;
            _application.Settings.AntiSpam.SpamDeleteThreshold = 9999;
            _application.Settings.AntiSpam.MaximumMessageSize  = 1024 * 1024;
            _application.Settings.AntiSpam.AddHeaderReason     = false;
            _application.Settings.AntiSpam.AddHeaderSpam       = false;
            _application.Settings.AntiSpam.PrependSubject      = false;
            _application.Settings.AntiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SpamAssassin
            _application.Settings.AntiSpam.SpamAssassinEnabled    = true;
            _application.Settings.AntiSpam.SpamAssassinHost       = "localhost";
            _application.Settings.AntiSpam.SpamAssassinPort       = 783;
            _application.Settings.AntiSpam.SpamAssassinMergeScore = true;
            _application.Settings.AntiSpam.SpamAssassinScore      = 5;

            List <string> messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";

            messages.Add(message);

            int        port       = 1110;
            POP3Server pop3Server = new POP3Server(1, port, messages);

            pop3Server.StartListen();

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

            hMailServer.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.DaysToKeepMessages    = -1;
            fa.UseAntiSpam           = true;

            fa.Save();
            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

            POP3Simulator.AssertMessageCount(account.Address, "test", 1);
        }
コード例 #29
0
        public void TestLongSMTPDataSessionIncludingNewline()
        {
            long memoryUsage = Shared.GetCurrentMemoryUsage();

            _application.Settings.MaxMessageSize = 0;

            TCPSocket socket = new TCPSocket();

            socket.Connect(25);
            socket.Receive();

            socket.Send("HELO test.com\r\n");
            socket.Receive();

            // Build a large string...
            StringBuilder sb = new StringBuilder();

            sb.Append("A01");
            for (int i = 0; i < 10000; i++)
            {
                sb.Append("01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890\r\n");
            }
            int length = sb.Length;

            sb.Append(Environment.NewLine);

            socket.Send("MAIL FROM: [email protected]\r\n");
            socket.Receive();
            socket.Send("RCPT TO: [email protected]\r\n");
            socket.Receive();
            socket.Send("DATA\r\n");
            socket.Receive();

            for (int i = 0; i < 100; i++)
            {
                Shared.AssertLowMemoryUsage(memoryUsage + 30);

                try
                {
                    socket.Send(sb.ToString());
                }
                catch (Exception)
                {
                    return;
                }
            }

            socket.Send("\r\n.\r\n");
            string result = socket.Receive();

            Assert.IsTrue(result.StartsWith("250"));

            socket.Send("QUIT\r\n");
            result = socket.Receive();
            socket.Disconnect();

            POP3Simulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1);
        }
コード例 #30
0
        public void TestDeliverToExternalMimeRecipientsDisabled()
        {
            List <string> messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int        port       = 1110;
            POP3Server pop3Server = new POP3Server(1, port, messages);

            pop3Server.StartListen();

            Dictionary <string, int> deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

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

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

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

            _domain.Postmaster = catchallAccount.Address;
            _domain.Save();

            hMailServer.FetchAccount fa = account1.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 = true;
            fa.Save();

            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

            string downloadedMessage1 = POP3Simulator.AssertGetFirstMessageText(account2.Address, "test");

            POP3Simulator.AssertMessageCount(account1.Address, "test", 0);
            Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

            POP3Simulator.AssertMessageCount(account2.Address, "test", 0);
            POP3Simulator.AssertMessageCount(catchallAccount.Address, "test", 0);
        }