Exemplo n.º 1
0
        private void CreateMessageModificationRule(hMailServer.Rules ruleContainer)
        {
            hMailServer.Rule oRule = ruleContainer.Add();
            oRule.Name   = "Criteria test";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined   = true;
            oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
            oRuleCriteria.MatchType       = hMailServer.eRuleMatchType.eMTGreaterThan;
            oRuleCriteria.MatchValue      = "0";
            oRuleCriteria.Save();

            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type           = hMailServer.eRuleActionType.eRARunScriptFunction;
            oRuleAction.ScriptFunction = "ModifyMessage";
            oRuleAction.Save();

            oRule.Save();

            File.WriteAllText(_settings.Scripting.CurrentScriptFile, "Sub ModifyMessage(oMessage)" + Environment.NewLine +
                              "oMessage.Subject = \"[Spam] \" + CStr(oMessage.Subject)" + Environment.NewLine +
                              "oMessage.Save" + Environment.NewLine +
                              "End Sub");

            _settings.Scripting.Reload();
        }
Exemplo n.º 2
0
        public void TestForwardingCombinedWithAccountRule()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

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

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

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            Assert.IsTrue(oSMTP.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.
            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 1);
            _application.SubmitEMail();
            POP3Simulator.AssertMessageCount(oAccount3.Address, "test", 1);

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

            // Set up a rule to trash the message.
            hMailServer.Rule oRule = oAccount2.Rules.Add();
            oRule.Name   = "Criteria test";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined   = true;
            oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
            oRuleCriteria.MatchType       = hMailServer.eRuleMatchType.eMTGreaterThan;
            oRuleCriteria.MatchValue      = "0";
            oRuleCriteria.Save();

            // Add action
            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type = hMailServer.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.
            Assert.IsTrue(oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"));
            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 0);
            _application.SubmitEMail();
            POP3Simulator.AssertMessageCount(oAccount3.Address, "test", 0);
        }
Exemplo n.º 3
0
        private void buttonAddAction_Click(object sender, EventArgs e)
        {
            hMailServer.RuleAction ruleAction = _rule.Actions.Add();

            formRuleAction ruleActionDialog = new formRuleAction(_rule, ruleAction);

            if (ruleActionDialog.ShowDialog() == DialogResult.OK)
            {
                ruleAction.Save();

                ListRuleActions();

                _forcedDirty = true;
                EnableDisable();
            }
        }
Exemplo n.º 4
0
        private void EditSelectedAction()
        {
            if (listActions.SelectedItems.Count == 0)
            {
                return;
            }

            hMailServer.RuleAction ruleAction       = listActions.SelectedItems[0].Tag as hMailServer.RuleAction;
            formRuleAction         ruleActionDialog = new formRuleAction(_rule, ruleAction);

            if (ruleActionDialog.ShowDialog() == DialogResult.OK)
            {
                ruleAction.Save();

                ListRuleActions();

                _forcedDirty = true;
                EnableDisable();
            }
        }
Exemplo n.º 5
0
        private void CreateMoveRule(hMailServer.Rules ruleContainer, string foldername)
        {
            hMailServer.Rule oRule = ruleContainer.Add();
            oRule.Name   = "Criteria test";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined   = true;
            oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
            oRuleCriteria.MatchType       = hMailServer.eRuleMatchType.eMTGreaterThan;
            oRuleCriteria.MatchValue      = "0";
            oRuleCriteria.Save();

            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type       = hMailServer.eRuleActionType.eRAMoveToImapFolder;
            oRuleAction.IMAPFolder = foldername;
            oRuleAction.Save();

            oRule.Save();
        }
Exemplo n.º 6
0
        public void ConfirmSingleReturnPathAfterRuleForward()
        {
            // Create a test account
            // Fetch the default _domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            // Set up a rule to trash the message.
            hMailServer.Rule oRule = oAccount1.Rules.Add();
            oRule.Name   = "Criteria test";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined   = true;
            oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
            oRuleCriteria.MatchType       = hMailServer.eRuleMatchType.eMTGreaterThan;
            oRuleCriteria.MatchValue      = "0";
            oRuleCriteria.Save();

            // Add action
            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type = hMailServer.eRuleActionType.eRAForwardEmail;
            oRuleAction.To   = oAccount2.Address;
            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.StaticSend("*****@*****.**", oAccount1.Address, "Test message", "This is the body");
            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1);
            _application.SubmitEMail();

            // Wait for the auto-reply.
            string text = POP3Simulator.AssertGetFirstMessageText(oAccount2.Address, "test");

            Assert.IsTrue(text.Contains("Return-Path: [email protected]"));
            Assert.IsFalse(text.Contains("Return-Path: [email protected]"));
            Assert.IsFalse(text.Contains("Return-Path: [email protected]"));
        }
Exemplo n.º 7
0
        public void AddExactMatchRule(hMailServer.Account oAccount)
        {
            hMailServer.Rule oRule = oAccount.Rules.Add();
            oRule.Name   = "TestRule 3";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined = false;
            oRuleCriteria.HeaderField   = "Subject";
            oRuleCriteria.MatchType     = hMailServer.eRuleMatchType.eMTEquals;
            oRuleCriteria.MatchValue    = "CORPORATE EXACT MATCH";
            oRuleCriteria.Save();

            // Add action
            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type       = hMailServer.eRuleActionType.eRAMoveToImapFolder;
            oRuleAction.IMAPFolder = "INBOX.Corporate";
            oRuleAction.Save();

            // Save the rule in the database
            oRule.Save();
        }
Exemplo n.º 8
0
        public void AddSpamRule(hMailServer.Account oAccount)
        {
            hMailServer.Rule oRule = oAccount.Rules.Add();
            oRule.Name   = "TestRule 1";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined = false;
            oRuleCriteria.HeaderField   = "Subject";
            oRuleCriteria.MatchType     = hMailServer.eRuleMatchType.eMTContains;
            oRuleCriteria.MatchValue    = "**SPAM**";
            oRuleCriteria.Save();

            // Add action
            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type       = hMailServer.eRuleActionType.eRAMoveToImapFolder;
            oRuleAction.IMAPFolder = "INBOX.Spam";
            oRuleAction.Save();

            // Save the rule in the database
            oRule.Save();
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
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
            hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            hMailServer.Rule oRule = oAccount.Rules.Add();
            oRule.Name   = "Criteria test";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined = false;
            oRuleCriteria.HeaderField   = "Subject";
            oRuleCriteria.MatchType     = hMailServer.eRuleMatchType.eMTContains;
            oRuleCriteria.MatchValue    = "rtest";
            oRuleCriteria.Save();

            // Add action
            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type       = hMailServer.eRuleActionType.eRASetHeaderValue;
            oRuleAction.HeaderName = "SomeHeader";
            oRuleAction.Value      = "SomeValue";
            oRuleAction.Save();

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

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

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

            Assert.IsTrue(sContents.IndexOf("SomeHeader: SomeValue") > 0);
            Assert.IsTrue(sContents.IndexOf("------=_NextPart_000_000D_01C97C94.33D5E670.ALT--") > 0);
        }