use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapReplaceheaderActionBasicWithLastAndIndex.
@Test
public void testSieveToSoapReplaceheaderActionBasicWithLastAndIndex() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\", \"variables\"];\n" + "# rule1\n" + "replaceheader :last :index 2 :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.assertTrue(action.getLast());
Assert.assertEquals(2, action.getOffset().intValue());
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.EditheaderTest in project zm-mailbox by Zimbra.
the class ModifyFilterRulesAdminTest method testSoapToSieveReplaceheaderAction6.
// headerName, multiple headerValues, comparator, value, relationalComparator
@Test
public void testSoapToSieveReplaceheaderAction6() throws ServiceException, Exception {
List<String> values = new ArrayList<String>();
values.add("2");
EditheaderTest test = new EditheaderTest(null, null, true, "ge", "i;ascii-numeric", "X-Test-Header", values);
ReplaceheaderAction action = new ReplaceheaderAction(null, null, test, null, "[test] ${1}");
FilterRule filterRule = new FilterRule("rule1", true);
filterRule.addFilterAction(action);
List<FilterRule> filterRules = new ArrayList<FilterRule>();
filterRules.add(filterRule);
RuleManager.clearCachedRules(account);
RuleManager.setAdminRulesFromXML(account, filterRules, FilterType.INCOMING, AdminFilterType.BEFORE);
String script = "require [" + SoapToSieve.requireCommon + ", \"editheader\"];\n\n" + "# rule1\n" + "replaceheader :newvalue \"[test] ${1}\" :value \"ge\" :comparator \"i;ascii-numeric\" \"X-Test-Header\" \"2\";\n";
Assert.assertEquals(script, account.getAdminSieveScriptBefore());
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class ModifyFilterRulesAdminTest method testSoapToSieveDeleteheaderAction7.
// headerName, multiple headerValues, comparator, count, relationalComparator
@Test
public void testSoapToSieveDeleteheaderAction7() throws ServiceException, Exception {
List<String> values = new ArrayList<String>();
values.add("2");
EditheaderTest test = new EditheaderTest(null, true, null, "ge", "i;ascii-numeric", "X-Test-Header", values);
DeleteheaderAction action = new DeleteheaderAction(null, null, test);
FilterRule filterRule = new FilterRule("rule1", true);
filterRule.addFilterAction(action);
List<FilterRule> filterRules = new ArrayList<FilterRule>();
filterRules.add(filterRule);
RuleManager.clearCachedRules(account);
RuleManager.setAdminRulesFromXML(account, filterRules, FilterType.INCOMING, AdminFilterType.BEFORE);
String script = "require [" + SoapToSieve.requireCommon + ", \"editheader\"];\n\n" + "# rule1\n" + "deleteheader :count \"ge\" :comparator \"i;ascii-numeric\" \"X-Test-Header\" \"2\";\n";
Assert.assertEquals(script, account.getAdminSieveScriptBefore());
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class ModifyFilterRulesAdminTest method testSoapToSieveDeleteheaderActionBasic.
/**
****************deleteheader********************
*/
@Test
public void testSoapToSieveDeleteheaderActionBasic() throws ServiceException, Exception {
EditheaderTest test = new EditheaderTest(null, null, null, null, null, "X-Test-Header", null);
DeleteheaderAction action = new DeleteheaderAction(null, null, test);
FilterRule filterRule = new FilterRule("rule1", true);
filterRule.addFilterAction(action);
List<FilterRule> filterRules = new ArrayList<FilterRule>();
filterRules.add(filterRule);
RuleManager.clearCachedRules(account);
RuleManager.setAdminRulesFromXML(account, filterRules, FilterType.INCOMING, AdminFilterType.BEFORE);
String script = "require [" + SoapToSieve.requireCommon + ", \"editheader\"];\n\n" + "# rule1\n" + "deleteheader \"X-Test-Header\";\n";
Assert.assertEquals(script, account.getAdminSieveScriptBefore());
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class ModifyFilterRulesAdminTest method testSoapToSieveDeleteheaderAction3.
// headerName and multiple headerValues
// default comparator and matchType
@Test
public void testSoapToSieveDeleteheaderAction3() throws ServiceException, Exception {
List<String> values = new ArrayList<String>();
values.add("Value1");
values.add("Value2");
values.add("Value3");
EditheaderTest test = new EditheaderTest(null, null, null, null, null, "X-Test-Header", values);
DeleteheaderAction action = new DeleteheaderAction(null, null, test);
FilterRule filterRule = new FilterRule("rule1", true);
filterRule.addFilterAction(action);
List<FilterRule> filterRules = new ArrayList<FilterRule>();
filterRules.add(filterRule);
RuleManager.clearCachedRules(account);
RuleManager.setAdminRulesFromXML(account, filterRules, FilterType.INCOMING, AdminFilterType.BEFORE);
String script = "require [" + SoapToSieve.requireCommon + ", \"editheader\"];\n\n" + "# rule1\n" + "deleteheader :comparator \"i;ascii-casemap\" :is \"X-Test-Header\" [ \"Value1\", \"Value2\", \"Value3\" ];\n";
Assert.assertEquals(script, account.getAdminSieveScriptBefore());
}
Aggregations