Exemplo n.º 1
0
        public void TestMostlyLatinCharacters()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var message = new hMailServer.Message();

            message.AddRecipient("Test Recipient: Тест", account.Address);
            message.Subject = "Test Subject: Тест";
            message.Charset = "utf-8";
            message.Body    = "Test body.";
            message.Save();

            string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            // Important:
            //   RFC 2047: http://www.faqs.org/rfcs/rfc2047.html
            //   The notation of RFC 822 is used, with the exception that white space
            //   characters MUST NOT appear between components of an 'encoded-word'.
            //
            //   Also, there should be a space separating the encoded word with the following
            //   non-encoded word.
            Assert.IsTrue(messageText.Contains("To: \"=?utf-8?B?VGVzdCBSZWNpcGllbnQ6INCi0LXRgdGC?=\" <*****@*****.**>"));
        }
Exemplo n.º 2
0
        public void TestImportDuplicateMessage()
        {
            string @messageText =
                "From: [email protected]\r\n" +
                "\r\n" +
                "Test\r\n";

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

            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));
            Assert.IsFalse(_application.Utilities.ImportMessageFromFile(fileName, account.ID));

            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1);
        }
Exemplo n.º 3
0
        public void TestDomainMaxMessageSizeLimit()
        {
            _domain.MaxMessageSize = 0;
            _domain.Save();

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

            var message = new StringBuilder();

            for (int i = 0; i < 10000; i++)
            {
                message.Append("ABCDEFGH");
            }

            SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "TestSubject",
                                           message.ToString());
            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "secret1", 1);
            _domain.MaxMessageSize = 50;
            _domain.Save();

            CustomAsserts.Throws <DeliveryFailedException>(() => SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "TestSubject",
                                                                                                message.ToString()));
        }
Exemplo n.º 4
0
        public void TestTOPSpecificPartial()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            for (int i = 1; i <= 10; i++)
            {
                SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test",
                                               "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n");
            }

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

            var sim = new Pop3ClientSimulator();

            sim.ConnectAndLogon(account.Address, "test");
            string result = sim.TOP(4, 2);

            Assert.IsTrue(result.Contains("Received"));
            Assert.IsTrue(result.Contains("Line1"));
            Assert.IsTrue(result.Contains("Line2"));
            Assert.IsFalse(result.Contains("Line3"));
            Assert.IsFalse(result.Contains("Line4"));
        }
Exemplo n.º 5
0
        public void TestMessageScoreNotMerged()
        {
            // Send a messages to this account.
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send(account.Address, account.Address, "SA test",
                                     "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X.");

            string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            int scoreStart = sMessageContents.IndexOf("X-hMailServer-Reason-Score");

            Assert.AreNotEqual(0, scoreStart);

            scoreStart = sMessageContents.IndexOf(":", scoreStart) + 2;
            int    scoreEnd    = sMessageContents.IndexOf("\r\n", scoreStart);
            int    scoreLength = scoreEnd - scoreStart;
            string score       = sMessageContents.Substring(scoreStart, scoreLength);

            double scoreValue = Convert.ToDouble(score);

            Assert.Less(scoreValue, 10);
        }
Exemplo n.º 6
0
        public void TestValidSignatureSHA256()
        {
            _antiSpam.DKIMVerificationEnabled      = true;
            _antiSpam.DKIMVerificationFailureScore = 100;

            string messageText = @"Return-Path: <*****@*****.**>" + "\r\n" +
                                 "X-Original-To: [email protected]" + "\r\n" +
                                 "Delivered-To: [email protected]" + "\r\n" +
                                 "Received: from voicemail.cis.att.net (unknown [12.34.200.188])" + "\r\n" +
                                 "	by mx2.messiah.edu (Postfix) with ESMTP id 02F12E15D8"+ "\r\n" +
                                 "	for <*****@*****.**>; Wed,  3 May 2006 15:06:32 -0400 (EDT)"+ "\r\n" +
                                 "Received: from  (localhost[127.0.0.1]) by voicemail.cis.att.net (vm2) with SMTP" +
                                 "\r\n" +
                                 "          id <2006050319071918800spa0re>; Wed, 3 May 2006 19:07:19 +0000" + "\r\n" +
                                 "DKIM-Signature: a=rsa-sha256;  c=relaxed; d=vmt2.cis.att.net; t=1146680862; " + "\r\n" +
                                 " h=Date : From : MIME-Version : To : Subject : Content-Type : Content-Transfer-Encoding; bh=HryPFX2R6r7JPsX1Z7+yReZddQR2PjvCvdXgaxW5QYU=; s=shan; " +
                                 "\r\n" +
                                 " b=QXd8h2UbBO7fIPz/Iy3wNwbVU6dih6ozokPXqAvI6p9iG5SqFahyTXwqZeltC4az3Sjay7Vx+b5e" +
                                 "\r\n" +
                                 " 1s2rQuhT4SKD47gJYs4kw0JgV2WLanF3oR1hWD0tL0vuDeUgH6kr" + "\r\n" +
                                 "Date: Wed, 15 Feb 2006 17:32:54 -0500" + "\r\n" +
                                 "From: Tony Hansen <*****@*****.**>" + "\r\n" +
                                 "MIME-Version: 1.0" + "\r\n" +
                                 "To: [email protected], [email protected], [email protected]" +
                                 "\r\n" +
                                 "Subject: this is a test message minimum.ietf-01.sha256-relaxed" + "\r\n" +
                                 "Content-Type: text/plain; charset=ISO-8859-1" + "\r\n" +
                                 "Content-Transfer-Encoding: 7bit" + "\r\n" +
                                 "Message-Id: <*****@*****.**>" + "\r\n" +
                                 "" + "\r\n" +
                                 "The quick brown fox jumped over the lazy dog." + "\r\n";

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

            SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText);
            string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
        }
Exemplo n.º 7
0
        public void TestValidSignatureSHA1()
        {
            _antiSpam.DKIMVerificationEnabled      = true;
            _antiSpam.DKIMVerificationFailureScore = 100;

            string messageText = @"DKIM-Signature: v=1; a=rsa-sha1; c=simple; d=messiah.edu; h=from:to" + "\r\n" +
                                 "	:subject:date; s=test3; [email protected]; bh=OW2otvzd7V2TO8"+ "\r\n" +
                                 "	w056SjbYRFCa0=; b=Vfr9HgUlyVf1ZaRVMV8VJNSDXn7f1j2N/rFM4PPmYIC2GD"+ "\r\n" +
                                 "	pSelCRrdA979Buuu/Mmx9FTWoZJBL+s5tafFM8bw=="+ "\r\n" +
                                 "Received: from x.y.test" + "\r\n" +
                                 "   by example.net" + "\r\n" +
                                 "   via TCP" + "\r\n" +
                                 "   with ESMTP" + "\r\n" +
                                 "   id ABC12345" + "\r\n" +
                                 "   for <*****@*****.**>;  21 Nov 1997 10:05:43 -0600" + "\r\n" +
                                 "Received: from machine.example by x.y.test; 21 Nov 1997 10:01:22 -0600" + "\r\n" +
                                 "From: Jason Long <*****@*****.**>" + "\r\n" +
                                 "To: Nobody <*****@*****.**>" + "\r\n" +
                                 "Subject: dkim test (i= uses quoted-printable)" + "\r\n" +
                                 "Date: Wed, 9 Apr 2008 09:11:00 -0500" + "\r\n" +
                                 "" + "\r\n" +
                                 "Should pass." + "\r\n" +
                                 "" + "\r\n" +
                                 "This is a test" + "\r\n" +
                                 "  More lines here" + "\r\n" +
                                 "" + "\r\n" +
                                 "Blah  blah  blah" + "\r\n" +
                                 "" + "\r\n" +
                                 "" + "\r\n" +
                                 "" + "\r\n" +
                                 "" + "\r\n";

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

            SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText);
            string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
        }
Exemplo n.º 8
0
        public void TestPOP3LogonFailure()
        {
            _settings.AutoBanOnLogonFailure         = true;
            _settings.MaxInvalidLogonAttempts       = 3;
            _settings.MaxInvalidLogonAttemptsWithin = 5;
            _settings.AutoBanMinutes = 3;

            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "te'*****@*****.**", "test");

            var sim = new Pop3ClientSimulator(TestSetup.GetLocalIpAddress(), false, 110);

            Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
            sim.Disconnect();

            // confirm that we can retrieve welcome message.
            Assert.IsTrue(sim.GetWelcomeMessage().StartsWith("+OK"));

            string errorMessage;

            // fail to log on 3 times.
            for (int i = 0; i < 3; i++)
            {
                Assert.IsFalse(sim.ConnectAndLogon(account.Address, "testA", out errorMessage));
                sim.Disconnect();

                if (i == 2)
                {
                    Assert.IsTrue(errorMessage.Contains("Too many invalid logon attempts."));
                }
            }

            Assert.IsTrue(sim.GetWelcomeMessage().Length == 0);

            string logText = LogHandler.ReadCurrentDefaultLog();

            Assert.IsTrue(logText.Contains("Blocked either by IP range or by connection limit."), logText);
        }
Exemplo n.º 9
0
        public void TestErrorOnMailFrom()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

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

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.MailFromResult = 561;
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can conenct to localhost.
                TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

                Assert.IsTrue(bounceMessage.Contains("MAIL FROM:<*****@*****.**>"));
                Assert.IsTrue(bounceMessage.Contains("Remote server replied: 561"));
            }
        }
Exemplo n.º 10
0
        public void TestOneFailOnePass()
        {
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            _settings.AntiSpam.SpamMarkThreshold   = 1;
            _settings.AntiSpam.SpamDeleteThreshold = 100;

            _settings.AntiSpam.AddHeaderReason    = true;
            _settings.AntiSpam.AddHeaderSpam      = true;
            _settings.AntiSpam.PrependSubject     = true;
            _settings.AntiSpam.PrependSubjectText = "ThisIsSpam";

            _settings.AntiSpam.CheckHostInHelo      = true;
            _settings.AntiSpam.CheckHostInHeloScore = 5;

            // Enable SURBL.
            SURBLServer oSURBLServer = _settings.AntiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account, containing both incorrect MX records an SURBL-hits.
            // We should only detect one of these two:
            var smtpClientSimulator = new SmtpClientSimulator();

            // Should not be possible to send this email since it's results in a spam
            // score over the delete threshold.
            smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "INBOX",
                                     "This is a test message.");

            string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:"));
            Assert.IsFalse(message.Contains("X-hMailServer-Reason-2:"));
        }
Exemplo n.º 11
0
      public void TestSearchUTF8TEXT()
      {
         Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
         string body = TestSetup.GetResource("Messages.MessageContainingGreekSubject.txt");
         SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, body);

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

         var oSimulator = new ImapClientSimulator();
         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);
      }
Exemplo n.º 12
0
      public void TestSearchLargeBody()
      {
         Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
         var body = new StringBuilder();
         body.AppendLine("From: [email protected]");
         body.AppendLine("Subject: Test");
         body.AppendLine();
         for (int i = 0; i < 20000; i++) // One megabye body.
            body.AppendLine("12345678901234567890123456789012345678901234567890");
         body.AppendLine("TestString");
         body.AppendLine();

         SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, body.ToString());

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

         var oSimulator = new ImapClientSimulator();
         Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test"));
         Assert.IsTrue(oSimulator.SelectFolder("INBOX"));
         string result = oSimulator.Search("CHARSET UTF-8 ALL TEXT InvalidText");
         Assert.AreEqual("", result);

         result = oSimulator.Search("CHARSET UTF-8 ALL TEXT TestStringA");
         Assert.AreEqual("", result);

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

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

         result = oSimulator.Search("UNDELETED BODY \"TestString\"");
         Assert.AreEqual("1", result);

         oSimulator.Close();
      }
Exemplo n.º 13
0
        public void TestImportOfMessageIntoInbox2()
        {
            string @messageText =
                "From: [email protected]\r\n" +
                "\r\n" +
                "Test\r\n";

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

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

            string text = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test");

            Assert.IsTrue(text.Contains(messageText));
        }
Exemplo n.º 14
0
        public void TestMaxSizeLimitation()
        {
            Account senderAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            recipientAccount.MaxSize = 1;
            recipientAccount.Save();

            // Make sure that no bounce is sent.
            SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", "Test");
            Pop3ClientSimulator.AssertGetFirstMessageText(recipientAccount.Address, "test");

            // Build a 2MB string.
            var builder = new StringBuilder();

            for (int i = 0; i < 11000; i++)
            {
                builder.Append(
                    "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n");
            }
            string text = builder.ToString();

            SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", text);

            // Make sure the recipient did not receive it.
            CustomAsserts.AssertRecipientsInDeliveryQueue(0);
            Pop3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 0);
            CustomAsserts.AssertFilesInUserDirectory(recipientAccount, 0);

            // Make sure it bounced.
            string content = Pop3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test");

            Assert.IsTrue(content.Contains("Inbox is full"));
        }
Exemplo n.º 15
0
        public void TestAutoReplySubject()
        {
            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain,
                                                                                   TestSetup.UniqueString() + "@test.com",
                                                                                   "test");

            Account oAccount2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain,
                                                                                   TestSetup.UniqueString() + "@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
            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.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.
            var pop3ClientSimulator = new Pop3ClientSimulator();

            Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1);
            string s = pop3ClientSimulator.GetFirstMessageText(oAccount1.Address, "test");

            if (s.IndexOf("Subject: Auto-Reply: Test message") < 0)
            {
                throw new Exception("ERROR - Auto reply subject not set properly.");
            }
        }
Exemplo n.º 16
0
        private void DownloadFromExternalAccount(Account account, FetchAccount fa)
        {
            if (!_backupMessages)
            {
                return;
            }

            // Download messages from the external account.
            var messages = new List <string>();

            messages.Add("Subject: Message 1\r\n");
            messages.Add("Subject: Message 2\r\n");
            messages.Add("Subject: Message 3\r\n");

            using (var pop3Server = new Pop3ServerSimulator(1, fa.Port, messages))
            {
                pop3Server.StartListen();
                fa.DownloadNow();
                pop3Server.WaitForCompletion();
            }

            CustomAsserts.AssertRecipientsInDeliveryQueue(0);
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 5);
        }
Exemplo n.º 17
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();

            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.º 18
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;

            IncomingRelay incomingRelay = _application.Settings.IncomingRelays.Add();

            incomingRelay.LowerIP = "1.2.1.2";
            incomingRelay.UpperIP = "1.2.1.3";
            incomingRelay.Name    = "Test";
            incomingRelay.Save();

            var 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 [" +
                             TestSetup.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 = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

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

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

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);
            }
        }
Exemplo n.º 19
0
        public void TestSpamProtectionPostTransmission()
        {
            _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";


            SURBLServer oSURBLServer = _application.Settings.AntiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            var messages = new List <string>();

            string message = "Received: from example.com (example.com [1.2.3.4]) by mail.host.edu\r\n" +
                             "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "http://surbl-org-permanent-test-point.com/";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

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

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

                string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

                Assert.IsTrue(downloadedMessage.Contains("X-hMailServer-Spam: YES"));
            }
        }
Exemplo n.º 20
0
        public void TestSpamProtectionNoTagging()
        {
            CustomAsserts.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;

            var 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 = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

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

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

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1);
            }
        }
Exemplo n.º 21
0
        public void TestDeliverToExternalMimeRecipientsEnabled()
        {
            var 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 = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

                var deliveryResults = new Dictionary <string, int>();
                deliveryResults["*****@*****.**"] = 250;

                int smtpServerPort = TestSetup.GetNextFreePort();
                using (var smtpServer = new SmtpServerSimulator(1, smtpServerPort))
                {
                    smtpServer.AddRecipientResult(deliveryResults);
                    smtpServer.StartListen();

                    // Add a route so we can connect to localhost.
                    Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);
                    route.TreatSecurityAsLocalDomain = true;
                    route.Save();

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

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

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

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

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

                    fa.DownloadNow();

                    pop3Server.WaitForCompletion();

                    fa.Delete();

                    string downloadedMessage1 = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test");
                    Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0);
                    Pop3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0);
                    Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

                    // Make sure the exernal recipient has received his copy.
                    smtpServer.WaitForCompletion();
                    string messageData = smtpServer.MessageData;
                    Assert.IsTrue(messageData.Contains(messageData), messageData);

                    CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);
                }
            }
        }
Exemplo n.º 22
0
        public void TestFetchMessagesWithVeryLongHeader()
        {
            var messages = new List <string>();

            var toHeaderBuilder = new StringBuilder();

            for (int i = 0; i < 10000; i++)
            {
                if (i > 0)
                {
                    toHeaderBuilder.Append("; ");
                }

                toHeaderBuilder.AppendFormat("to-{0}@example.com", i);
            }

            for (int i = 0; i < 5; i++)
            {
                string message = string.Format("To: {1}\r\n" +
                                               "X-Dummy: {0}\r\n" +
                                               "Subject: Test\r\n" +
                                               "\r\n" +
                                               "Hello!", i, toHeaderBuilder);

                messages.Add(message);
            }

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer;
                pop3Server.StartListen();

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

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

                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                LockHelper.WaitForUnlock(fa);

                fa.Delete();

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 5);
                string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");



                for (int i = 0; i < 5; i++)
                {
                    if (downloadedMessage.Contains(messages[i]))
                    {
                        return;
                    }
                }

                Assert.Fail("Downloaded messages did not match uploaded messages.");
            }
        }
Exemplo n.º 23
0
        private void SetupAccountObject(Domain domain)
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(domain, "*****@*****.**", "test");

            // Make sure the inbox contains two messages which should be backed up.
            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 1 Subject",
                                           "Message 1 Body");

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

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 2 Subject",
                                           "Message 2 Body");
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2);

            SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 3 Subject",
                                           "Message 3 Body");
            Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3);

            var sim = new ImapClientSimulator();

            Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
            Assert.IsTrue(sim.SelectFolder("Inbox"));
            Assert.IsTrue(sim.SetDeletedFlag(2));
            Assert.IsTrue(sim.Expunge());
            sim.Disconnect();

            _folderCreationTime = account.IMAPFolders.get_ItemByName("INBOX").CreationTime;

            account.Active              = true;
            account.ADDomain            = "AD";
            account.AdminLevel          = eAdminLevel.hAdminLevelDomainAdmin;
            account.ADUsername          = "******";
            account.ForwardAddress      = "FA";
            account.ForwardEnabled      = false;
            account.ForwardKeepOriginal = true;
            account.IsAD                       = false;
            account.MaxSize                    = 1250;
            account.PersonFirstName            = "First";
            account.PersonLastName             = "Last";
            account.SignatureEnabled           = true;
            account.SignatureHTML              = "HTML";
            account.SignaturePlainText         = "PLAIN";
            account.VacationMessage            = "VAC";
            account.VacationMessageExpires     = true;
            account.VacationMessageExpiresDate = "2020-01-01";
            account.VacationMessageIsOn        = true;
            account.VacationSubject            = "SUBJ";
            account.Password                   = "******";
            account.Save();

            // Set up fetch account
            FetchAccount fa = account.FetchAccounts.Add();

            fa.DaysToKeepMessages  = 5;
            fa.Enabled             = true;
            fa.MinutesBetweenFetch = 10;
            fa.Name                  = "test";
            fa.Port                  = _fetchAccountPort;
            fa.ProcessMIMEDate       = true;
            fa.ProcessMIMERecipients = true;
            fa.ServerAddress         = "127.0.0.1";
            fa.Username              = "******";
            fa.UseSSL                = false;
            fa.UseAntiSpam           = true;
            fa.UseAntiVirus          = true;
            fa.Save();

            DownloadFromExternalAccount(account, fa);

            Rule rule = account.Rules.Add();

            rule.Name = "MyRule";
            RuleCriteria criteria = rule.Criterias.Add();

            criteria.MatchType       = eRuleMatchType.eMTGreaterThan;
            criteria.PredefinedField = eRulePredefinedField.eFTMessageSize;
            criteria.MatchValue      = "0";
            criteria.Save();

            RuleAction action = rule.Actions.Add();

            action.Type           = eRuleActionType.eRAForwardEmail;
            action.To             = "*****@*****.**";
            action.Body           = "Test";
            action.Filename       = "File";
            action.FromAddress    = "T";
            action.FromName       = "N";
            action.HeaderName     = "H";
            action.IMAPFolder     = "Folder";
            action.ScriptFunction = "Script";
            action.Subject        = "Subj";
            action.Value          = "Value";
            action.Save();

            rule.Save();
        }
Exemplo n.º 24
0
        public void TestWhitelistAllIPv6Addresses()
        {
            var addresses = GetAllLocalAddresses(System.Net.Sockets.AddressFamily.InterNetworkV6);

            if (addresses.Length == 0)
            {
                Assert.Inconclusive("IPv6 not available.");
            }

            var firstAddress = addresses[0];

            // Enable this port
            var tcpIpPort = _application.Settings.TCPIPPorts.Add();

            tcpIpPort.Address    = firstAddress;
            tcpIpPort.Protocol   = eSessionType.eSTSMTP;
            tcpIpPort.PortNumber = 25;
            tcpIpPort.Save();

            // Add an IP range for ALL ipv6 source port.
            foreach (var address in addresses)
            {
                var ipRange = _application.Settings.SecurityRanges.Add();
                ipRange.Name = "IPv6Range" + address;
                ipRange.AllowDeliveryFromLocalToLocal   = true;
                ipRange.AllowDeliveryFromLocalToRemote  = true;
                ipRange.AllowDeliveryFromRemoteToLocal  = true;
                ipRange.AllowDeliveryFromRemoteToRemote = true;
                ipRange.AllowSMTPConnections            = true;
                ipRange.RequireAuthForDeliveryToLocal   = false;
                ipRange.EnableSpamProtection            = true;
                ipRange.LowerIP = address;
                ipRange.UpperIP = address;
                ipRange.Save();
            }

            _application.Stop();
            _application.Start();

            // Enable SURBL.
            SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Make sure we are now blacklisted.
            var smtpClient = new SmtpClientSimulator(false, 25, IPAddress.Parse(firstAddress));

            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody));

            // White list all IPv6 addresses
            var obAddress = _antiSpam.WhiteListAddresses.Add();

            obAddress.EmailAddress   = "*";
            obAddress.LowerIPAddress = "::";
            obAddress.UpperIPAddress = "ffff::ffff";
            obAddress.Description    = "Test";
            obAddress.Save();

            // Make sure we can now send again.
            smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody);

            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1);
        }
Exemplo n.º 25
0
        public void TestPortOpening()
        {
            Application oApp = SingletonProvider <TestSetup> .Instance.GetApp();

            oApp.Settings.TCPIPPorts.SetDefault();

            var pSMTPSimulator = new TcpConnection();
            var pPOP3Simulator = new Pop3ClientSimulator();
            var pIMAPSimulator = new ImapClientSimulator();

            oApp.Stop();

            TCPIPPorts oPorts = oApp.Settings.TCPIPPorts;

            for (int i = 0; i < oPorts.Count; i++)
            {
                TCPIPPort oTestPort = oPorts[i];
                if (oTestPort.Protocol == eSessionType.eSTIMAP)
                {
                    oTestPort.PortNumber = 14300;
                }
                else if (oTestPort.Protocol == eSessionType.eSTSMTP)
                {
                    oTestPort.PortNumber = 11000;
                }
                else if (oTestPort.Protocol == eSessionType.eSTPOP3)
                {
                    oTestPort.PortNumber = 2500;
                }

                oTestPort.Save();
            }

            oApp.Start();

            Assert.IsTrue(pSMTPSimulator.TestConnect(2500));
            Assert.IsTrue(pSMTPSimulator.TestConnect(11000));
            Assert.IsTrue(pSMTPSimulator.TestConnect(14300));

            oApp.Stop();

            TCPIPPort oPort = oApp.Settings.TCPIPPorts.Add();

            oPort.Protocol   = eSessionType.eSTSMTP;
            oPort.PortNumber = 25000;
            oPort.Save();

            oApp.Start();

            // Try to connect to the new port
            Assert.IsTrue(pSMTPSimulator.TestConnect(25000));

            oApp.Stop();

            // Delete the port again
            oApp.Settings.TCPIPPorts.DeleteByDBID(oPort.ID);

            // Change back the ports
            for (int i = 0; i < oPorts.Count; i++)
            {
                TCPIPPort oTestPort = oPorts[i];
                if (oTestPort.Protocol == eSessionType.eSTIMAP)
                {
                    oTestPort.PortNumber = 143;
                }
                else if (oTestPort.Protocol == eSessionType.eSTSMTP)
                {
                    oTestPort.PortNumber = 25;
                }
                else if (oTestPort.Protocol == eSessionType.eSTPOP3)
                {
                    oTestPort.PortNumber = 110;
                }

                oTestPort.Save();
            }

            oApp.Start();

            Assert.IsTrue(pSMTPSimulator.TestConnect(25));
            Assert.IsTrue(pPOP3Simulator.TestConnect(110));
            Assert.IsTrue(pPOP3Simulator.TestConnect(143));
        }
Exemplo n.º 26
0
        public void TestOnExternalAccountDownload()
        {
            LogHandler.DeleteCurrentDefaultLog();


            var messages = new List <string>();

            messages.Add("From: [email protected]\r\n" +
                         "To: [email protected]\r\n" +
                         "Subject: Message 1\r\n" +
                         "\r\n" +
                         "Message 1!");

            messages.Add("From: [email protected]\r\n" +
                         "To: [email protected]\r\n" +
                         "Subject: Message 2\r\n" +
                         "\r\n" +
                         "Message 2!");

            messages.Add("From: [email protected]\r\n" +
                         "To: [email protected]\r\n" +
                         "Subject: Message 3\r\n" +
                         "\r\n" +
                         "Message 3!");


            // The second message should be deleted after 5 days.
            string script = "Sub OnExternalAccountDownload(oFetchAccount, message, sRemoteUID)" + Environment.NewLine +
                            " EventLog.Write(\"UID: \" & sRemoteUID) " + Environment.NewLine +
                            " EventLog.Write(\"FetchAccount: \" & oFetchAccount.Name) " + Environment.NewLine +
                            " If Not message Is Nothing Then " + Environment.NewLine +
                            "   EventLog.Write(\"From: \" & message.FromAddress) " + Environment.NewLine +
                            "   EventLog.Write(\"Filename: \" & message.FileName) " + Environment.NewLine +
                            " Else " + Environment.NewLine +
                            "   EventLog.Write(\"Message details missing\") " + Environment.NewLine +
                            " End If" + Environment.NewLine +
                            " if sRemoteUID = \"UniqueID-" + messages[1].GetHashCode() + "\" Then " +
                            Environment.NewLine +
                            "   Result.Value = 2  " + Environment.NewLine +
                            "   Result.Parameter = 5  " + Environment.NewLine +
                            " End If " + Environment.NewLine +
                            " End Sub";

            Scripting scripting = _settings.Scripting;
            string    file      = scripting.CurrentScriptFile;

            File.WriteAllText(file, script);
            scripting.Enabled = true;
            scripting.Reload();

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

            FetchAccount fa;

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();


                fa = account.FetchAccounts.Add();

                fa.Enabled             = true;
                fa.MinutesBetweenFetch = 10;
                fa.Name                  = "TestFA";
                fa.Username              = "******";
                fa.Password              = "******";
                fa.UseSSL                = false;
                fa.ServerAddress         = "localhost";
                fa.Port                  = port;
                fa.ProcessMIMERecipients = false;
                fa.DaysToKeepMessages    = -1;
                fa.Save();
                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                string eventLogFile = _settings.Logging.CurrentEventLog;
                string logContents  = TestSetup.ReadExistingTextFile(eventLogFile);

                Assert.IsTrue(logContents.Contains("FetchAccount: " + fa.Name));

                Assert.IsTrue(logContents.Contains("From: [email protected]"));
                Assert.IsTrue(logContents.Contains("From: [email protected]"));
                Assert.IsTrue(logContents.Contains("From: [email protected]"));

                string appLogContent = LogHandler.ReadCurrentDefaultLog();

                Assert.IsTrue(pop3Server.DeletedMessages.Contains(1));
                Assert.IsFalse(pop3Server.DeletedMessages.Contains(2));
                Assert.IsTrue(pop3Server.DeletedMessages.Contains(3));

                Assert.IsTrue(pop3Server.RetrievedMessages.Contains(1));
                Assert.IsTrue(pop3Server.RetrievedMessages.Contains(2));
                Assert.IsTrue(pop3Server.RetrievedMessages.Contains(3));

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3);
            }

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

                // Download again...
                fa.DownloadNow();

                pop3Server.WaitForCompletion();

                // Make sure that no messages are deleted.
                Assert.AreEqual(0, pop3Server.DeletedMessages.Count);
                Assert.AreEqual(0, pop3Server.RetrievedMessages.Count);

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3);
            }
        }
Exemplo n.º 27
0
        public void TestDomainSignature()
        {
            var pop3ClientSimulator = new Pop3ClientSimulator();

            _domain.SignatureEnabled         = true;
            _domain.AddSignaturesToLocalMail = true;

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

            account1.SignatureEnabled   = true;
            account1.SignaturePlainText = "PlainTextSignature";
            account1.Save();


            var smtpClientSimulator = new SmtpClientSimulator();

            smtpClientSimulator.Send(account1.Address, account1.Address, "Test of signature, 1", "Test of signature - Body");

            string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");

            if (sMessageContents.IndexOf("PlainTextSignature") <= 0)
            {
                throw new Exception("Did not find signature");
            }


            _domain.SignatureEnabled   = true;
            _domain.SignaturePlainText = "DomainSignature";
            _domain.SignatureMethod    = eDomainSignatureMethod.eSMAppendToAccountSignature;
            _domain.Save();
            smtpClientSimulator.Send(account1.Address, account1.Address, "Test of signature, 1", "Test of signature - Body");

            sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
            if (sMessageContents.IndexOf("PlainTextSignature") <= 0 ||
                sMessageContents.IndexOf("DomainSignature") <= 0)
            {
                throw new Exception("Did not find signature");
            }


            _domain.SignatureEnabled   = true;
            _domain.SignaturePlainText = "DomainSignature";
            _domain.SignatureMethod    = eDomainSignatureMethod.eSMOverwriteAccountSignature;
            _domain.Save();
            smtpClientSimulator.Send(account1.Address, account1.Address, "Test of signature, 1", "Test of signature - Body");

            sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
            if (sMessageContents.IndexOf("PlainTextSignature") >= 0 ||
                sMessageContents.IndexOf("DomainSignature") <= 0)
            {
                throw new Exception("Did not find signature");
            }


            _domain.SignatureEnabled   = true;
            _domain.SignaturePlainText = "DomainSignature";
            _domain.SignatureMethod    = eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount;
            _domain.Save();
            smtpClientSimulator.Send(account1.Address, account1.Address, "Test of signature, 1", "Test of signature - Body");

            sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
            if (sMessageContents.IndexOf("DomainSignature") >= 0)
            {
                throw new Exception("Found incorrect signature.");
            }


            _domain.SignatureEnabled   = true;
            _domain.SignaturePlainText = "DomainSignature";
            _domain.SignatureMethod    = eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount;
            _domain.Save();
            account1.SignaturePlainText = "";
            account1.Save();

            smtpClientSimulator.Send(account1.Address, account1.Address, "Test of signature, 1", "Test of signature - Body");

            sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
            if (sMessageContents.IndexOf("DomainSignature") <= 0)
            {
                throw new Exception("Found incorrect signature.");
            }


            _domain.AddSignaturesToLocalMail = false;
            _domain.Save();
            account1.SignaturePlainText = "PlainTextSignature";
            account1.Save();
            smtpClientSimulator.Send(account1.Address, account1.Address, "Test of signature, 1", "Test of signature - Body");

            sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
            if (sMessageContents.IndexOf("PlainTextSignature") > 0)
            {
                throw new Exception("Found incorrect signature.");
            }

            _domain.AddSignaturesToLocalMail = true;
            _domain.Save();

            smtpClientSimulator.Send(account1.Address, account1.Address, "Test of signature, 1", "Test of signature - Body");

            sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");
            if (sMessageContents.IndexOf("PlainTextSignature") <= 0)
            {
                throw new Exception("Found incorrect signature.");
            }
        }
Exemplo n.º 28
0
        public void Send100MBMessage()
        {
            long memoryUsage = Shared.GetCurrentMemoryUsage();

            _application.Settings.MaxMessageSize = 0;

            TcpConnection socket = new TcpConnection();

            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 = 1; i <= 100; i++)
            {
                Shared.AssertLowMemoryUsage(memoryUsage + 30);

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

                if ((i % 10) == 0)
                {
                    TestTracer.WriteTraceInfo("{0}/{1}", i, 1000);
                }
            }

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

            Pop3ClientSimulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1);
        }
Exemplo n.º 29
0
        public void TestOverlappingBoundaryNames()
        {
            string content = "Return-Path: <*****@*****.**>\r\n" +
                             "From: \"test\" <*****@*****.**>\r\n" +
                             "To: \"Test\" <*****@*****.**>\r\n" +
                             "Subject: rtest\r\n" +
                             "Date: Thu, 22 Jan 2009 13:20:32 +0100\r\n" +
                             "MIME-Version: 1.0\r\n" +
                             "Content-Type: multipart/mixed;\r\n" +
                             "    boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670\"\r\n" +
                             "\r\n" +
                             "This is a multi-part message in MIME format.\r\n" +
                             "\r\n" +
                             "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" +
                             "Content-Type: multipart/alternative;\r\n" +
                             "    boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670.ALT\"\r\n" +
                             "\r\n" +
                             "\r\n" +
                             "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" +
                             "Content-Type: text/plain;\r\n" +
                             "    charset=\"iso-8859-1\"\r\n" +
                             "Content-Transfer-Encoding: quoted-printable\r\n" +
                             "\r\n" +
                             "test\r\n" +
                             "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" +
                             "Content-Type: text/html;\r\n" +
                             "    charset=\"iso-8859-1\"\r\n" +
                             "Content-Transfer-Encoding: quoted-printable\r\n" +
                             "\r\n" +
                             "<a>test</a>\r\n" +
                             "\r\n" +
                             "------=_NextPart_000_000D_01C97C94.33D5E670.ALT--\r\n" +
                             "\r\n" +
                             "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" +
                             "Content-Type: application/octet-stream;\r\n" +
                             "    name=\"test.vbs\"\r\n" +
                             "Content-Transfer-Encoding: 7bit\r\n" +
                             "Content-Disposition: attachment;\r\n" +
                             "    filename=\"test.vbs\"\r\n" +
                             "\r\n" +
                             "s = \"abc\"\r\n" +
                             "\r\n" +
                             "msgbox mid(s,1,100000)\r\n" +
                             "------=_NextPart_000_000D_01C97C94.33D5E670--\r\n" +
                             "\r\n" +
                             "";


            // Add an account
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            Rule rule = account.Rules.Add();

            rule.Name   = "Criteria test";
            rule.Active = true;

            RuleCriteria ruleCriteria = rule.Criterias.Add();

            ruleCriteria.UsePredefined = false;
            ruleCriteria.HeaderField   = "Subject";
            ruleCriteria.MatchType     = eRuleMatchType.eMTContains;
            ruleCriteria.MatchValue    = "rtest";
            ruleCriteria.Save();

            // Add action
            RuleAction ruleAction = rule.Actions.Add();

            ruleAction.Type       = eRuleActionType.eRASetHeaderValue;
            ruleAction.HeaderName = "SomeHeader";
            ruleAction.Value      = "SomeValue";
            ruleAction.Save();

            // Save the rule in the database
            rule.Save();

            var smtpClientSimulator = new SmtpClientSimulator();

            // Spam folder
            smtpClientSimulator.SendRaw("*****@*****.**", "*****@*****.**", content);

            string sContents = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test");

            Assert.IsTrue(sContents.IndexOf("SomeHeader: SomeValue") > 0);
            Assert.IsTrue(sContents.IndexOf("------=_NextPart_000_000D_01C97C94.33D5E670.ALT--") > 0);
        }
Exemplo n.º 30
0
        public void TestForwardingCombinedWithAccountRule()
        {
            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain,
                                                                                   TestSetup.UniqueString() + "@test.com",
                                                                                   "test");

            Account oAccount2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain,
                                                                                   TestSetup.UniqueString() + "@test.com",
                                                                                   "test");

            Account oAccount3 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain,
                                                                                   TestSetup.UniqueString() + "@test.com",
                                                                                   "test");

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

            var smtpClientSimulator = new SmtpClientSimulator();

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

            // Make sure that that a forward is made if no rule is set up.
            Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1);
            _application.SubmitEMail();
            Pop3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 1);

            // Start over again.
            oAccount2.DeleteMessages();
            oAccount3.DeleteMessages();

            // Set up a rule to trash the message.
            Rule oRule = oAccount2.Rules.Add();

            oRule.Name   = "Criteria test";
            oRule.Active = true;

            RuleCriteria oRuleCriteria = oRule.Criterias.Add();

            oRuleCriteria.UsePredefined   = true;
            oRuleCriteria.PredefinedField = eRulePredefinedField.eFTMessageSize;
            oRuleCriteria.MatchType       = eRuleMatchType.eMTGreaterThan;
            oRuleCriteria.MatchValue      = "0";
            oRuleCriteria.Save();

            // Add action
            RuleAction oRuleAction = oRule.Actions.Add();

            oRuleAction.Type = eRuleActionType.eRADeleteEmail;
            oRuleAction.Save();

            // Save the rule in the database
            oRule.Save();

            // Make sure that that a forward is made if no rule is set up.
            smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body");
            Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 0);
            _application.SubmitEMail();
            Pop3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 0);
        }