use of com.zimbra.cs.service.mail.ModifyFilterRules in project zm-mailbox by Zimbra.
the class ValueComparisonTest method testHeaderTestValueComparisonComparator.
/**
* Tests rule creation through ModifyFilterRulesRequest for header test having value comparison with
* valueComparisonComparator
* @throws Exception
*/
@Test
public void testHeaderTestValueComparisonComparator() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
Element rules = request.addNonUniqueElement(MailConstants.E_FILTER_RULES);
Element rule = rules.addNonUniqueElement(MailConstants.E_FILTER_RULE);
rule.addAttribute(MailConstants.A_ACTIVE, true);
rule.addAttribute(MailConstants.A_NAME, "Test1");
Element filteraction = rule.addNonUniqueElement(MailConstants.E_FILTER_ACTIONS);
Element actionInto = filteraction.addNonUniqueElement(MailConstants.E_ACTION_FILE_INTO);
actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
filteraction.addNonUniqueElement(MailConstants.E_ACTION_STOP);
Element filterTests = rule.addNonUniqueElement(MailConstants.E_FILTER_TESTS);
filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element headerTest = filterTests.addNonUniqueElement(MailConstants.E_HEADER_TEST);
headerTest.addAttribute(MailConstants.A_HEADER, "subject");
headerTest.addAttribute(MailConstants.A_VALUE_COMPARISON, "eq");
headerTest.addAttribute(MailConstants.A_VALUE_COMPARISON_COMPARATOR, "i;octet");
headerTest.addAttribute(MailConstants.A_VALUE, "Important");
try {
new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
} catch (ServiceException e) {
fail("This test is expected not to throw exception. ");
}
String expectedScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
expectedScript += "# Test1\n";
expectedScript += "if anyof (header :value \"eq\" :comparator \"i;octet\" [\"subject\"] \"Important\") {\n";
expectedScript += " fileinto \"Junk\";\n";
expectedScript += " stop;\n";
expectedScript += "}\n";
ZimbraLog.filter.info(acct.getMailSieveScript());
ZimbraLog.filter.info(expectedScript);
assertEquals(expectedScript, acct.getMailSieveScript());
}
use of com.zimbra.cs.service.mail.ModifyFilterRules in project zm-mailbox by Zimbra.
the class ValueComparisonTest method testEnvelopeTestValueComparisonComparator.
/**
* Tests rule creation through ModifyFilterRulesRequest for envelope test having value comparison with
* valueComparisonComparator
* @throws Exception
*/
@Test
public void testEnvelopeTestValueComparisonComparator() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
Element rules = request.addNonUniqueElement(MailConstants.E_FILTER_RULES);
Element rule = rules.addNonUniqueElement(MailConstants.E_FILTER_RULE);
rule.addAttribute(MailConstants.A_ACTIVE, true);
rule.addAttribute(MailConstants.A_NAME, "Test1");
Element filteraction = rule.addNonUniqueElement(MailConstants.E_FILTER_ACTIONS);
Element actionInto = filteraction.addNonUniqueElement(MailConstants.E_ACTION_FILE_INTO);
actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
filteraction.addNonUniqueElement(MailConstants.E_ACTION_STOP);
Element filterTests = rule.addNonUniqueElement(MailConstants.E_FILTER_TESTS);
filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element envelopeTest = filterTests.addNonUniqueElement(MailConstants.E_ENVELOPE_TEST);
envelopeTest.addAttribute(MailConstants.A_HEADER, "from");
envelopeTest.addAttribute(MailConstants.A_VALUE_COMPARISON, "eq");
envelopeTest.addAttribute(MailConstants.A_VALUE_COMPARISON_COMPARATOR, "i;octet");
envelopeTest.addAttribute(MailConstants.A_VALUE, "abCD");
try {
new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
} catch (ServiceException e) {
fail("This test is expected not to throw exception. ");
}
String expectedScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
expectedScript += "# Test1\n";
expectedScript += "if anyof (envelope :value \"eq\" :all :comparator \"i;octet\" [\"from\"] \"abCD\") {\n";
expectedScript += " fileinto \"Junk\";\n";
expectedScript += " stop;\n";
expectedScript += "}\n";
ZimbraLog.filter.info(acct.getMailSieveScript());
ZimbraLog.filter.info(expectedScript);
assertEquals(expectedScript, acct.getMailSieveScript());
}
use of com.zimbra.cs.service.mail.ModifyFilterRules in project zm-mailbox by Zimbra.
the class ValueComparisonTest method testAddressTestStringComparisonCaseSensitivity.
/**
* Tests rule creation through ModifyFilterRulesRequest for address test having caseSensitive attribute with
* string comparison
* @throws Exception
*/
@Test
public void testAddressTestStringComparisonCaseSensitivity() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
Element rules = request.addNonUniqueElement(MailConstants.E_FILTER_RULES);
Element rule = rules.addNonUniqueElement(MailConstants.E_FILTER_RULE);
rule.addAttribute(MailConstants.A_ACTIVE, true);
rule.addAttribute(MailConstants.A_NAME, "Test1");
Element filteraction = rule.addNonUniqueElement(MailConstants.E_FILTER_ACTIONS);
Element actionInto = filteraction.addNonUniqueElement(MailConstants.E_ACTION_FILE_INTO);
actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
filteraction.addNonUniqueElement(MailConstants.E_ACTION_STOP);
Element filterTests = rule.addNonUniqueElement(MailConstants.E_FILTER_TESTS);
filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element addressTest = filterTests.addNonUniqueElement(MailConstants.E_ADDRESS_TEST);
addressTest.addAttribute(MailConstants.A_HEADER, "from");
addressTest.addAttribute(MailConstants.A_STRING_COMPARISON, "contains");
addressTest.addAttribute(MailConstants.A_CASE_SENSITIVE, "true");
addressTest.addAttribute(MailConstants.A_VALUE, "abCD");
try {
new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
} catch (ServiceException e) {
fail("This test is expected not to throw exception. ");
}
String expectedScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
expectedScript += "# Test1\n";
expectedScript += "if anyof (address :all :contains :comparator \"i;octet\" [\"from\"] \"abCD\") {\n";
expectedScript += " fileinto \"Junk\";\n";
expectedScript += " stop;\n";
expectedScript += "}\n";
ZimbraLog.filter.info(acct.getMailSieveScript());
ZimbraLog.filter.info(expectedScript);
assertEquals(expectedScript, acct.getMailSieveScript());
}
use of com.zimbra.cs.service.mail.ModifyFilterRules in project zm-mailbox by Zimbra.
the class ValueComparisonTest method testEnvelopeTestValueComparisonCaseSensitivity.
/**
* Tests rule creation through ModifyFilterRulesRequest for envelope test having caseSensitive attribute with
* value comparison
* @throws Exception
*/
@Test
public void testEnvelopeTestValueComparisonCaseSensitivity() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
Element rules = request.addNonUniqueElement(MailConstants.E_FILTER_RULES);
Element rule = rules.addNonUniqueElement(MailConstants.E_FILTER_RULE);
rule.addAttribute(MailConstants.A_ACTIVE, true);
rule.addAttribute(MailConstants.A_NAME, "Test1");
Element filteraction = rule.addNonUniqueElement(MailConstants.E_FILTER_ACTIONS);
Element actionInto = filteraction.addNonUniqueElement(MailConstants.E_ACTION_FILE_INTO);
actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
filteraction.addNonUniqueElement(MailConstants.E_ACTION_STOP);
Element filterTests = rule.addNonUniqueElement(MailConstants.E_FILTER_TESTS);
filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
Element envelopeTest = filterTests.addNonUniqueElement(MailConstants.E_ENVELOPE_TEST);
envelopeTest.addAttribute(MailConstants.A_HEADER, "from");
envelopeTest.addAttribute(MailConstants.A_VALUE_COMPARISON, "eq");
envelopeTest.addAttribute(MailConstants.A_CASE_SENSITIVE, "true");
envelopeTest.addAttribute(MailConstants.A_VALUE, "abCD");
try {
new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
} catch (ServiceException e) {
fail("This test is expected not to throw exception. ");
}
String expectedScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
expectedScript += "# Test1\n";
expectedScript += "if anyof (envelope :value \"eq\" :all :comparator \"i;octet\" [\"from\"] \"abCD\") {\n";
expectedScript += " fileinto \"Junk\";\n";
expectedScript += " stop;\n";
expectedScript += "}\n";
ZimbraLog.filter.info(acct.getMailSieveScript());
ZimbraLog.filter.info(expectedScript);
assertEquals(expectedScript, acct.getMailSieveScript());
}
Aggregations