예제 #1
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));
        }
예제 #2
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);
        }
예제 #3
0
        private void EditSelectedExternalAccount()
        {
            if (listFetchAccounts.SelectedItems.Count < 1)
            {
                return;
            }

            int id = Convert.ToInt32(listFetchAccounts.SelectedItems[0].Tag);

            hMailServer.FetchAccounts fetchAccounts = _representedAccount.FetchAccounts;
            hMailServer.FetchAccount  fetchAccount  = fetchAccounts.get_ItemByDBID(id);

            formExternalAccount externalAccountDialog = new formExternalAccount();

            externalAccountDialog.LoadAccountProperties(fetchAccount);
            if (externalAccountDialog.ShowDialog() == DialogResult.OK)
            {
                externalAccountDialog.SaveAccountProperties(fetchAccount);
                fetchAccount.Save();
            }

            ListExternalAccounts();

            Marshal.ReleaseComObject(fetchAccounts);
            Marshal.ReleaseComObject(fetchAccount);
        }
예제 #4
0
        private void ListExternalAccounts()
        {
            listFetchAccounts.Items.Clear();

            hMailServer.FetchAccounts fetchAccounts = _representedAccount.FetchAccounts;

            for (int i = 0; i < fetchAccounts.Count; i++)
            {
                hMailServer.FetchAccount fetchAccount = fetchAccounts.get_Item(i);

                string name    = fetchAccount.Name;
                string enabled = EnumStrings.GetYesNoString(fetchAccount.Enabled);

                ListViewItem item = listFetchAccounts.Items.Add(name);
                item.SubItems.Add(enabled);

                if (fetchAccount.Enabled)
                {
                    item.SubItems.Add(fetchAccount.NextDownloadTime);
                }

                item.Tag = fetchAccount.ID;

                Marshal.ReleaseComObject(fetchAccount);
            }
        }
예제 #5
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);
        }
예제 #6
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";


            hMailServer.SURBLServer oSURBLServer = _application.Settings.AntiSpam.SURBLServers[0];
            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            List <string> 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       = 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();

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

            Assert.IsTrue(downloadedMessage.Contains("X-hMailServer-Spam: YES"));
        }
예제 #7
0
        public void TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal()
        {
            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();

            // Add a route so we can connect to localhost.
            hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, 250, false);
            route.TreatSecurityAsLocalDomain = false;
            route.Save();

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

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

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

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

            hMailServer.FetchAccount fa = userAccount.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 = POP3Simulator.AssertGetFirstMessageText(recipientAccount1.Address, "test");

            Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

            Utilities.AssertRecipientsInDeliveryQueue(0, false);
        }
예제 #8
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);
        }
예제 #9
0
        public void TestSpamProtectionDisabled()
        {
            _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.UseSPF      = true;
            _application.Settings.AntiSpam.UseSPFScore = 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" +
                             "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    = -1;
            fa.UseAntiSpam           = false;
            fa.Save();

            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

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

            Assert.IsFalse(downloadedMessage.Contains("X-hMailServer-Spam: YES"));
        }
예제 #10
0
        public void TestFetchAccount()
        {
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            hMailServer.FetchAccount oFA = oAccount1.FetchAccounts.Add();
            oFA.Name = "test";
            oFA.Save();

            if (oFA.ID == 0)
            {
                throw new Exception("Fetch account could not be saved");
            }

            oAccount1.FetchAccounts.Delete(0);
        }
예제 #11
0
        public void TestDeleteMutliple()
        {
            List <string> messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

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


            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

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

            Assert.AreEqual(3, pop3Server.DeletedMessages.Count);
        }
예제 #12
0
        private void buttonAddExternalAccount_Click(object sender, EventArgs e)
        {
            formExternalAccount externalAccountDialog = new formExternalAccount();

            if (externalAccountDialog.ShowDialog() == DialogResult.OK)
            {
                hMailServer.FetchAccounts fetchAccounts = _representedAccount.FetchAccounts;
                hMailServer.FetchAccount  fetchAccount  = _representedAccount.FetchAccounts.Add();
                Marshal.ReleaseComObject(fetchAccounts);

                externalAccountDialog.SaveAccountProperties(fetchAccount);
                fetchAccount.Save();

                Marshal.ReleaseComObject(fetchAccount);

                ListExternalAccounts();
            }
        }
예제 #13
0
        public void LoadAccountProperties(hMailServer.FetchAccount fetchAccount)
        {
            _isLoading = true;

            _fetchAccount = fetchAccount;

            checkEnabled.Checked                  = fetchAccount.Enabled;
            textName.Text                         = fetchAccount.Name;
            textMinutesBetweenFetch.Number        = fetchAccount.MinutesBetweenFetch;
            comboServerType.SelectedValue         = fetchAccount.ServerType;
            textServer.Text                       = fetchAccount.ServerAddress;
            textPort.Number                       = fetchAccount.Port;
            textUsername.Text                     = fetchAccount.Username;
            comboConnectionSecurity.SelectedValue = fetchAccount.ConnectionSecurity;


            checkProcessMIMERecipients.Checked = fetchAccount.ProcessMIMERecipients;
            checkProcessMIMEDate.Checked       = fetchAccount.ProcessMIMEDate;

            checkUseAntiSpam.Checked  = fetchAccount.UseAntiSpam;
            checkUseAntiVirus.Checked = fetchAccount.UseAntiVirus;

            checkEnableRouteRecipients.Checked = fetchAccount.EnableRouteRecipients;

            if (fetchAccount.DaysToKeepMessages == -1)
            {
                radioDeleteImmediately.Checked = true;
            }
            else if (fetchAccount.DaysToKeepMessages == 0)
            {
                radioNeverDeleteMessages.Checked = true;
            }
            else
            {
                radioDeleteMessagesAfter.Checked = true;
                textDaysToKeepMessages.Number    = fetchAccount.DaysToKeepMessages;
            }

            buttonDownloadNow.Enabled = true;

            _isLoading = false;

            EnableDisable();
        }
예제 #14
0
        public void TestPOP3Client()
        {
            List <string> messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            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              = GetUsername();
            fa.Password              = GetPassword();
            fa.UseSSL                = false;
            fa.ServerAddress         = "localhost";
            fa.Port                  = port;
            fa.ProcessMIMERecipients = false;
            fa.Save();

            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

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

            Assert.IsTrue(downloadedMessage.Contains(message));

            EnsureNoPassword();
        }
예제 #15
0
        private static hMailServer.FetchAccount CreateFetchAccount(hMailServer.Account account, int port, bool antiSpam, bool antiVirus)
        {
            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           = antiSpam;
            fa.UseAntiVirus          = antiVirus;
            fa.Save();
            return(fa);
        }
예제 #16
0
        public void TestServerNotSupportingUIDL()
        {
            List <string> 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" +
                             "Hello!";

            messages.Add(message);

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

            pop3Server.SupportsUIDL = false;
            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.Save();
            fa.DownloadNow();

            pop3Server.WaitForCompletion();

            fa.Delete();

            string error = Utilities.ReadAndDeleteErrorLog();

            Assert.IsTrue(error.Contains("-ERR unhandled command"));
        }
예제 #17
0
      public void SaveAccountProperties(hMailServer.FetchAccount fetchAccount)
      {
         fetchAccount.DaysToKeepMessages = SettingDaysToKeepMessages;
         fetchAccount.Enabled = checkEnabled.Checked;
         fetchAccount.MinutesBetweenFetch = textMinutesBetweenFetch.Number;
         fetchAccount.Name = textName.Text;
         fetchAccount.Port = textPort.Number;
         fetchAccount.ProcessMIMEDate = checkProcessMIMEDate.Checked;
         fetchAccount.ProcessMIMERecipients = checkProcessMIMERecipients.Checked;
         fetchAccount.ServerAddress = textServer.Text;
         fetchAccount.ServerType = (int) comboServerType.SelectedValue;
         fetchAccount.Username = textUsername.Text;
         fetchAccount.ConnectionSecurity = (eConnectionSecurity) comboConnectionSecurity.SelectedValue;
         fetchAccount.UseAntiSpam = checkUseAntiSpam.Checked;
         fetchAccount.UseAntiVirus = checkUseAntiVirus.Checked;
         fetchAccount.EnableRouteRecipients = checkEnableRouteRecipients.Checked;

         if (textPassword.Dirty)
            fetchAccount.Password = textPassword.Password;

      }
예제 #18
0
        public void LoadAccountProperties(hMailServer.FetchAccount fetchAccount)
        {
            _isLoading = true;

             _fetchAccount = fetchAccount;

             checkEnabled.Checked = fetchAccount.Enabled;
             textName.Text = fetchAccount.Name;
             textMinutesBetweenFetch.Number = fetchAccount.MinutesBetweenFetch;
             comboServerType.SelectedValue = fetchAccount.ServerType;
             textServer.Text = fetchAccount.ServerAddress;
             textPort.Number = fetchAccount.Port;
             textUsername.Text = fetchAccount.Username;
             comboConnectionSecurity.SelectedValue = fetchAccount.ConnectionSecurity;

             checkProcessMIMERecipients.Checked = fetchAccount.ProcessMIMERecipients;
             checkProcessMIMEDate.Checked = fetchAccount.ProcessMIMEDate;

             checkUseAntiSpam.Checked = fetchAccount.UseAntiSpam;
             checkUseAntiVirus.Checked = fetchAccount.UseAntiVirus;

             checkEnableRouteRecipients.Checked = fetchAccount.EnableRouteRecipients;

             if (fetchAccount.DaysToKeepMessages == -1)
            radioDeleteImmediately.Checked = true;
             else if (fetchAccount.DaysToKeepMessages == 0)
            radioNeverDeleteMessages.Checked = true;
             else
             {
            radioDeleteMessagesAfter.Checked = true;
            textDaysToKeepMessages.Number = fetchAccount.DaysToKeepMessages;
             }

             buttonDownloadNow.Enabled = true;

             _isLoading = false;

             EnableDisable();
        }
예제 #19
0
        private void DownloadFromExternalAccount(hMailServer.Account account, hMailServer.FetchAccount fa)
        {
            if (!_backupMessages)
            {
                return;
            }

            // Download messages from the external account.
            List <string> 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");

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

            pop3Server.StartListen();
            fa.DownloadNow();
            pop3Server.WaitForCompletion();

            Utilities.AssertRecipientsInDeliveryQueue(0);
            POP3Simulator.AssertMessageCount(account.Address, "test", 5);
        }
예제 #20
0
        public void TestOnExternalAccountDownload()
        {
            Utilities.DeleteCurrentDefaultLog();


            List <string> 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!");


            // First set up a script
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            // The second message should be deleted after 5 days.
            string script = "Sub OnExternalAccountDownload(oFetchAccount, oMessage, sRemoteUID)" + Environment.NewLine +
                            " EventLog.Write(\"UID: \" & sRemoteUID) " + Environment.NewLine +
                            " EventLog.Write(\"FetchAccount: \" & oFetchAccount.Name) " + Environment.NewLine +
                            " If Not oMessage Is Nothing Then " + Environment.NewLine +
                            "   EventLog.Write(\"From: \" & oMessage.FromAddress) " + Environment.NewLine +
                            "   EventLog.Write(\"Filename: \" & oMessage.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";

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

            Utilities.WriteFile(file, script);
            scripting.Enabled = true;
            scripting.Reload();


            int        port       = 43132;
            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                  = "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  = Utilities.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 = Utilities.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));

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

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

            POP3Simulator.AssertMessageCount(account.Address, "test", 3);
        }
예제 #21
0
        private void ConfirmAccountObject()
        {
            hMailServer.Account account = _application.Domains[0].Accounts.get_ItemByAddress("*****@*****.**");


            Assert.IsTrue(account.Active);
            Assert.AreEqual("AD", account.ADDomain);
            Assert.AreEqual(hMailServer.eAdminLevel.hAdminLevelDomainAdmin, account.AdminLevel);
            Assert.AreEqual("AU", account.ADUsername);
            Assert.AreEqual("FA", account.ForwardAddress);
            Assert.IsFalse(account.ForwardEnabled);
            Assert.IsTrue(account.ForwardKeepOriginal);
            Assert.IsFalse(account.IsAD);
            Assert.AreEqual(1250, account.MaxSize);
            Assert.AreEqual("First", account.PersonFirstName);
            Assert.AreEqual("Last", account.PersonLastName);
            Assert.IsTrue(account.SignatureEnabled);
            Assert.AreEqual("HTML", account.SignatureHTML);
            Assert.AreEqual("PLAIN", account.SignaturePlainText);
            Assert.AreEqual("VAC", account.VacationMessage);
            Assert.IsTrue(account.VacationMessageExpires);
            Assert.AreEqual("2020-01-01", account.VacationMessageExpiresDate.Substring(0, 10));
            Assert.IsTrue(account.VacationMessageIsOn);
            Assert.AreEqual("SUBJ", account.VacationSubject);

            // Confirm fetch account
            hMailServer.FetchAccount fa = account.FetchAccounts.get_Item(0);
            Assert.AreEqual(5, fa.DaysToKeepMessages);
            Assert.IsTrue(fa.Enabled);
            Assert.AreEqual(10, fa.MinutesBetweenFetch);
            Assert.AreEqual("test", fa.Name);
            Assert.AreEqual(1110, fa.Port);
            Assert.AreEqual(true, fa.ProcessMIMEDate);
            Assert.IsTrue(fa.ProcessMIMERecipients);
            Assert.AreEqual("test", fa.Username);
            Assert.IsFalse(fa.UseSSL);
            Assert.AreEqual("127.0.0.1", fa.ServerAddress);
            Assert.IsTrue(fa.UseAntiSpam);
            Assert.IsTrue(fa.UseAntiVirus);

            // Make sur no additional mail is downloaded. We have already downloaded it.
            DownloadFromExternalAccount(account, fa);

            hMailServer.Rule rule = account.Rules[0];
            Assert.AreEqual("MyRule", rule.Name);

            hMailServer.RuleCriteria criteria = rule.Criterias[0];
            Assert.AreEqual(hMailServer.eRuleMatchType.eMTGreaterThan, criteria.MatchType);
            Assert.AreEqual(hMailServer.eRulePredefinedField.eFTMessageSize, criteria.PredefinedField);
            Assert.AreEqual("0", criteria.MatchValue);

            hMailServer.RuleAction action = rule.Actions[0];
            Assert.AreEqual(hMailServer.eRuleActionType.eRAForwardEmail, action.Type);
            Assert.AreEqual("*****@*****.**", action.To);
            Assert.AreEqual("Test", action.Body);
            Assert.AreEqual("File", action.Filename);
            Assert.AreEqual("T", action.FromAddress);
            Assert.AreEqual("N", action.FromName);
            Assert.AreEqual("H", action.HeaderName);
            Assert.AreEqual("Folder", action.IMAPFolder);
            Assert.AreEqual("Script", action.ScriptFunction);
            Assert.AreEqual("Subj", action.Subject);
            Assert.AreEqual("Value", action.Value);

            hMailServer.IMAPFolder inbox = account.IMAPFolders.get_ItemByName("INBOX");

            hMailServer.Messages messages = inbox.Messages;

            if (_backupMessages)
            {
                Assert.AreEqual(6, inbox.CurrentUID);
                Assert.AreEqual(_folderCreationTime, inbox.CreationTime);

                Assert.AreEqual(5, messages.Count);
                Assert.AreEqual("Message 1 Subject", messages[0].Subject);
                Assert.IsTrue(messages[1].Body.Contains("Message 3 Body"));

                Assert.AreEqual(1, messages[0].UID);
                Assert.AreEqual(3, messages[1].UID);
            }
            else
            {
                Assert.AreEqual(0, messages.Count);
            }
        }
예제 #22
0
        private void SetupAccountObject(hMailServer.Domain domain)
        {
            hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(domain, "*****@*****.**", "test");

            // Make sure the inbox contains two messages which should be backed up.
            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1 Subject", "Message 1 Body"));
            POP3Simulator.AssertMessageCount(account.Address, "test", 1);

            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 2 Subject", "Message 2 Body"));
            POP3Simulator.AssertMessageCount(account.Address, "test", 2);

            Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 3 Subject", "Message 3 Body"));
            POP3Simulator.AssertMessageCount(account.Address, "test", 3);

            IMAPSimulator sim = new IMAPSimulator();

            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          = hMailServer.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
            hMailServer.FetchAccount fa = account.FetchAccounts.Add();
            fa.DaysToKeepMessages  = 5;
            fa.Enabled             = true;
            fa.MinutesBetweenFetch = 10;
            fa.Name                  = "test";
            fa.Port                  = 1110;
            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);

            hMailServer.Rule rule = account.Rules.Add();
            rule.Name = "MyRule";
            hMailServer.RuleCriteria criteria = rule.Criterias.Add();
            criteria.MatchType       = hMailServer.eRuleMatchType.eMTGreaterThan;
            criteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
            criteria.MatchValue      = "0";
            criteria.Save();

            hMailServer.RuleAction action = rule.Actions.Add();
            action.Type           = hMailServer.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();
        }
예제 #23
0
        public void TestBasicExternalAccountSSLEvenThoughNotSupported()
        {
            List <string> messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: [email protected]\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int        port       = 1111;
            POP3Server pop3Server = new POP3Server(2, port, messages);

            pop3Server.DisconnectImmediate = true;
            pop3Server.StartListen();

            Utilities.DeleteCurrentDefaultLog();

            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                = true;
            fa.ServerAddress         = "localhost";
            fa.Port                  = port;
            fa.ProcessMIMERecipients = false;
            fa.Save();

            fa.DownloadNow();
            string contentSoFar = "";

            for (int i = 0; i <= 10; i++)
            {
                if (i == 5)
                {
                    Assert.Fail("No connection: " + contentSoFar);
                }

                contentSoFar = Utilities.ReadCurrentDefaultLog();
                if (contentSoFar.Contains("SSL handshake with client failed."))
                {
                    break;
                }

                Thread.Sleep(1000);
            }

            Utilities.DeleteCurrentDefaultLog();

            // try again.
            fa.DownloadNow();

            contentSoFar = "";

            for (int i = 0; i <= 10; i++)
            {
                if (i == 5)
                {
                    Assert.Fail("No connection: " + contentSoFar);
                }

                contentSoFar = Utilities.ReadCurrentDefaultLog();
                if (contentSoFar.Contains("SSL handshake with client failed."))
                {
                    break;
                }

                Thread.Sleep(1000);
            }

            pop3Server.WaitForCompletion();

            fa.Delete();
        }