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(); }
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); }
public formRuleAction(hMailServer.Rule rule, hMailServer.RuleAction ruleAction) { InitializeComponent(); _ruleAction = ruleAction; _isAccountLevelRule = rule.AccountID > 0; FillCombo(); LoadProperties(); new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); Strings.Localize(this); }
private void buttonDeleteAction_Click(object sender, EventArgs e) { foreach (ListViewItem item in listActions.SelectedItems) { hMailServer.RuleAction ruleAction = item.Tag as RuleAction; ruleAction.Delete(); } ListRuleActions(); _forcedDirty = true; EnableDisable(); }
private void buttonMoveDown_Click(object sender, EventArgs e) { if (listActions.SelectedItems.Count != 1) { return; } hMailServer.RuleAction action = listActions.SelectedItems[0].Tag as hMailServer.RuleAction; action.MoveDown(); ListRuleActions(); _forcedDirty = true; EnableDisable(); }
private void ListRuleActions() { listActions.Items.Clear(); hMailServer.RuleActions ruleActions = _rule.Actions; for (int i = 0; i < ruleActions.Count; i++) { hMailServer.RuleAction ruleAction = ruleActions[i]; string name = EnumStrings.GetRuleActionString(ruleAction.Type); ListViewItem listViewItem = listActions.Items.Add(name); listViewItem.Tag = ruleAction; } }
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(); } }
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(); } }
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(); }
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]")); }
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(); }
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(); }
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); } }
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(); }
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); }