use of com.zimbra.soap.mail.type.FilterAction in project zm-mailbox by Zimbra.
the class ModifyFilterRulesTest method SetIncomingXMLRulesForEnvelope.
@Test
public void SetIncomingXMLRulesForEnvelope() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
// Construct a filter rule with 'address' test whose value is empty (null)
FilterRule rule = new FilterRule("testSetIncomingXMLRulesForEnvelope", true);
FilterTest.EnvelopeTest test = new FilterTest.EnvelopeTest();
test.setHeader("to");
test.setStringComparison("is");
test.setPart("all");
test.setValue("u1@zimbra.com");
test.setIndex(0);
FilterTests tests = new FilterTests("anyof");
tests.addTest(test);
FilterAction action = new FilterAction.KeepAction();
action.setIndex(0);
rule.setFilterTests(tests);
rule.addFilterAction(action);
List<FilterRule> filterRuleList = new ArrayList<FilterRule>();
filterRuleList.add(rule);
// When the ModifyFilterRulesRequest is submitted from the Web client,
// eventually this RuleManager.setIncomingXMLRules is called to convert
// the request in JSON to the SIEVE rule text.
RuleManager.setIncomingXMLRules(account, filterRuleList);
// Verify that the saved zimbraMailSieveScript
String sieve = account.getMailSieveScript();
int result = sieve.indexOf("envelope :all :is :comparator \"i;ascii-casemap\" [\"to\"] \"u1@zimbra.com\"");
Assert.assertNotSame(-1, result);
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
use of com.zimbra.soap.mail.type.FilterAction in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionBasicWithValue.
@Test
public void testSieveToSoapDeleteheaderActionBasicWithValue() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\"];\n" + "# rule1\n" + // matchType and comparator should be added by default
"deleteheader \"X-My-Header\" \"Test Value\";";
account.setAdminSieveScriptBefore(script);
List<FilterRule> filterRules = RuleManager.getAdminRulesAsXML(account, FilterType.INCOMING, AdminFilterType.BEFORE);
Assert.assertEquals(filterRules.size(), 1);
FilterRule filterRule = filterRules.get(0);
Assert.assertEquals("rule1", filterRule.getName());
Assert.assertTrue(filterRule.isActive());
Assert.assertEquals(1, filterRule.getFilterActions().size());
FilterAction filterAction = filterRule.getFilterActions().get(0);
Assert.assertTrue(filterAction instanceof FilterAction.DeleteheaderAction);
FilterAction.DeleteheaderAction action = (FilterAction.DeleteheaderAction) filterAction;
Assert.assertNull(action.getLast());
Assert.assertNull(action.getOffset());
EditheaderTest test = action.getTest();
Assert.assertEquals("i;ascii-casemap", test.getComparator());
Assert.assertEquals("is", test.getMatchType());
Assert.assertNull(test.getRelationalComparator());
Assert.assertNull(test.getCount());
Assert.assertNull(test.getValue());
Assert.assertEquals("X-My-Header", test.getHeaderName());
List<String> values = test.getHeaderValue();
Assert.assertEquals(1, values.size());
Assert.assertEquals("Test Value", values.get(0));
}
use of com.zimbra.soap.mail.type.FilterAction in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapReplaceheaderActionBasicWithRelationalComparatorAndCount.
@Test
public void testSieveToSoapReplaceheaderActionBasicWithRelationalComparatorAndCount() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\", \"variables\"];\n" + "# rule1\n" + "replaceheader :newname \"X-My-Header2\" :newvalue \"[new] ${1}\" :comparator \"i;ascii-numeric\" :count \"eq\" \"X-My-Header\" \"3\";";
account.setAdminSieveScriptBefore(script);
List<FilterRule> filterRules = RuleManager.getAdminRulesAsXML(account, FilterType.INCOMING, AdminFilterType.BEFORE);
Assert.assertEquals(filterRules.size(), 1);
FilterRule filterRule = filterRules.get(0);
Assert.assertEquals("rule1", filterRule.getName());
Assert.assertTrue(filterRule.isActive());
Assert.assertEquals(1, filterRule.getFilterActions().size());
FilterAction filterAction = filterRule.getFilterActions().get(0);
Assert.assertTrue(filterAction instanceof FilterAction.ReplaceheaderAction);
FilterAction.ReplaceheaderAction action = (FilterAction.ReplaceheaderAction) filterAction;
Assert.assertNull(action.getLast());
Assert.assertNull(action.getOffset());
Assert.assertEquals("X-My-Header2", action.getNewName());
Assert.assertEquals("[new] ${1}", action.getNewValue());
EditheaderTest test = action.getTest();
Assert.assertEquals("i;ascii-numeric", test.getComparator());
Assert.assertNull(test.getMatchType());
Assert.assertEquals("eq", test.getRelationalComparator());
Assert.assertTrue(test.getCount());
Assert.assertNull(test.getValue());
Assert.assertEquals("X-My-Header", test.getHeaderName());
List<String> values = test.getHeaderValue();
Assert.assertEquals(1, values.size());
Assert.assertEquals("3", values.get(0));
}
use of com.zimbra.soap.mail.type.FilterAction in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionWithIndexAndLast.
@Test
public void testSieveToSoapDeleteheaderActionWithIndexAndLast() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\"];\n" + "# rule1\n" + // matchType and comparator should be added by default
"deleteheader :last :index 3 \"X-My-Header\" \"Test Value\";";
account.setAdminSieveScriptBefore(script);
List<FilterRule> filterRules = RuleManager.getAdminRulesAsXML(account, FilterType.INCOMING, AdminFilterType.BEFORE);
Assert.assertEquals(filterRules.size(), 1);
FilterRule filterRule = filterRules.get(0);
Assert.assertEquals("rule1", filterRule.getName());
Assert.assertTrue(filterRule.isActive());
Assert.assertEquals(1, filterRule.getFilterActions().size());
FilterAction filterAction = filterRule.getFilterActions().get(0);
Assert.assertTrue(filterAction instanceof FilterAction.DeleteheaderAction);
FilterAction.DeleteheaderAction action = (FilterAction.DeleteheaderAction) filterAction;
Assert.assertTrue(action.getLast());
Assert.assertEquals(3, action.getOffset().intValue());
EditheaderTest test = action.getTest();
Assert.assertEquals("i;ascii-casemap", test.getComparator());
Assert.assertEquals("is", test.getMatchType());
Assert.assertNull(test.getRelationalComparator());
Assert.assertNull(test.getCount());
Assert.assertNull(test.getValue());
Assert.assertEquals("X-My-Header", test.getHeaderName());
List<String> values = test.getHeaderValue();
Assert.assertEquals(1, values.size());
Assert.assertEquals("Test Value", values.get(0));
}
use of com.zimbra.soap.mail.type.FilterAction in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapReplaceheaderActionBasicWithRelationalComparatorAndValue.
@Test
public void testSieveToSoapReplaceheaderActionBasicWithRelationalComparatorAndValue() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\", \"variables\"];\n" + "# rule1\n" + "replaceheader :newname \"X-My-Header2\" :newvalue \"[new] ${1}\" :comparator \"i;ascii-numeric\" :value \"ge\" \"X-My-Header\" \"2\";";
account.setAdminSieveScriptBefore(script);
List<FilterRule> filterRules = RuleManager.getAdminRulesAsXML(account, FilterType.INCOMING, AdminFilterType.BEFORE);
Assert.assertEquals(filterRules.size(), 1);
FilterRule filterRule = filterRules.get(0);
Assert.assertEquals("rule1", filterRule.getName());
Assert.assertTrue(filterRule.isActive());
Assert.assertEquals(1, filterRule.getFilterActions().size());
FilterAction filterAction = filterRule.getFilterActions().get(0);
Assert.assertTrue(filterAction instanceof FilterAction.ReplaceheaderAction);
FilterAction.ReplaceheaderAction action = (FilterAction.ReplaceheaderAction) filterAction;
Assert.assertNull(action.getLast());
Assert.assertNull(action.getOffset());
Assert.assertEquals("X-My-Header2", action.getNewName());
Assert.assertEquals("[new] ${1}", action.getNewValue());
EditheaderTest test = action.getTest();
Assert.assertEquals("i;ascii-numeric", test.getComparator());
Assert.assertNull(test.getMatchType());
Assert.assertEquals("ge", test.getRelationalComparator());
Assert.assertNull(test.getCount());
Assert.assertTrue(test.getValue());
Assert.assertEquals("X-My-Header", test.getHeaderName());
List<String> values = test.getHeaderValue();
Assert.assertEquals(1, values.size());
Assert.assertEquals("2", values.get(0));
}
Aggregations