use of com.zimbra.cs.service.mail.ModifyFilterRules in project zm-mailbox by Zimbra.
the class ValueComparisonTest method testAddressTestValueComparisonCaseSensitivity.
/**
* Tests rule creation through ModifyFilterRulesRequest for address test having caseSensitive attribute with
* value comparison
* @throws Exception
*/
@Test
public void testAddressTestValueComparisonCaseSensitivity() 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_VALUE_COMPARISON, "eq");
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 :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 testEnvelopeTestStringComparisonCaseSensitivity.
/**
* Tests rule creation through ModifyFilterRulesRequest for envelope test having caseSensitive attribute with
* string comparison
* @throws Exception
*/
@Test
public void testEnvelopeTestStringComparisonCaseSensitivity() 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_STRING_COMPARISON, "contains");
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 :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 testHeaderTestStringComparisonCaseSensitivity.
/**
* Tests rule creation through ModifyFilterRulesRequest for header test having caseSensitive attribute with
* string comparison
* @throws Exception
*/
@Test
public void testHeaderTestStringComparisonCaseSensitivity() 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_STRING_COMPARISON, "contains");
headerTest.addAttribute(MailConstants.A_CASE_SENSITIVE, "true");
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 :contains :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 testAddressTestValueComparisonComparator.
/**
* Tests rule creation through ModifyFilterRulesRequest for address test having value comparison with
* valueComparisonComparator
* @throws Exception
*/
@Test
public void testAddressTestValueComparisonComparator() 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_VALUE_COMPARISON, "eq");
addressTest.addAttribute(MailConstants.A_VALUE_COMPARISON_COMPARATOR, "i;octet");
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 :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 testHeaderTestValueComparisonCaseSensitivity.
/**
* Tests rule creation through ModifyFilterRulesRequest for header test having caseSensitive attribute with
* value comparison
* @throws Exception
*/
@Test
public void testHeaderTestValueComparisonCaseSensitivity() 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_CASE_SENSITIVE, "true");
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());
}
Aggregations