public void AddExactMatchRule(Account oAccount) { Rule oRule = oAccount.Rules.Add(); oRule.Name = "TestRule 3"; oRule.Active = true; RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "Subject"; oRuleCriteria.MatchType = eRuleMatchType.eMTEquals; oRuleCriteria.MatchValue = "CORPORATE EXACT MATCH"; oRuleCriteria.Save(); // Add action RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = eRuleActionType.eRAMoveToImapFolder; oRuleAction.IMAPFolder = "INBOX.Corporate"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); }
private void CreateMessageModificationRule(hMailServer.Rules ruleContainer) { Rule rule = ruleContainer.Add(); rule.Name = "Criteria test"; rule.Active = true; RuleCriteria ruleCriteria = rule.Criterias.Add(); ruleCriteria.UsePredefined = true; ruleCriteria.PredefinedField = eRulePredefinedField.eFTMessageSize; ruleCriteria.MatchType = eRuleMatchType.eMTGreaterThan; ruleCriteria.MatchValue = "0"; ruleCriteria.Save(); RuleAction ruleAction = rule.Actions.Add(); ruleAction.Type = eRuleActionType.eRARunScriptFunction; ruleAction.ScriptFunction = "ModifyMessage"; ruleAction.Save(); rule.Save(); File.WriteAllText(_settings.Scripting.CurrentScriptFile, "Sub ModifyMessage(message)" + Environment.NewLine + "message.Subject = \"[Spam] \" + CStr(message.Subject)" + Environment.NewLine + "message.Save" + Environment.NewLine + "End Sub"); _settings.Scripting.Reload(); }
public void AddSpamRule(Account oAccount) { Rule oRule = oAccount.Rules.Add(); oRule.Name = "TestRule 1"; oRule.Active = true; RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "Subject"; oRuleCriteria.MatchType = eRuleMatchType.eMTContains; oRuleCriteria.MatchValue = "**SPAM**"; oRuleCriteria.Save(); // Add action RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = eRuleActionType.eRAMoveToImapFolder; oRuleAction.IMAPFolder = "INBOX.Spam"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); }
public void ConfirmSingleReturnPathAfterRuleForward() { // Create a test account // Fetch the default _domain Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account oAccount2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a rule to trash the message. Rule oRule = oAccount1.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.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"); Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); _application.SubmitEMail(); // Wait for the auto-reply. string text = Pop3ClientSimulator.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]")); }
private void CreateMoveRule(hMailServer.Rules ruleContainer, string foldername) { Rule rule = ruleContainer.Add(); rule.Name = "Criteria test"; rule.Active = true; RuleCriteria ruleCriteria = rule.Criterias.Add(); ruleCriteria.UsePredefined = true; ruleCriteria.PredefinedField = eRulePredefinedField.eFTMessageSize; ruleCriteria.MatchType = eRuleMatchType.eMTGreaterThan; ruleCriteria.MatchValue = "0"; ruleCriteria.Save(); RuleAction ruleAction = rule.Actions.Add(); ruleAction.Type = eRuleActionType.eRAMoveToImapFolder; ruleAction.IMAPFolder = foldername; ruleAction.Save(); rule.Save(); }
private void CreateDeleteAllMailRule() { Rule rule = SingletonProvider <TestSetup> .Instance.GetApp().Rules.Add(); rule.Name = "Global rule test"; rule.Active = true; RuleCriteria ruleCriteria = rule.Criterias.Add(); ruleCriteria.UsePredefined = true; ruleCriteria.PredefinedField = eRulePredefinedField.eFTMessageSize; ruleCriteria.MatchType = eRuleMatchType.eMTGreaterThan; ruleCriteria.MatchValue = "0"; ruleCriteria.Save(); // Add action RuleAction ruleAction = rule.Actions.Add(); ruleAction.Type = eRuleActionType.eRADeleteEmail; ruleAction.Save(); // Save the rule in the database 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 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); }
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(); }
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); }