use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionWithMultiValue.
@Test
public void testSieveToSoapDeleteheaderActionWithMultiValue() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\"];\n" + "# rule1\n" + "deleteheader :last :index 3 :comparator \"i;octet\" :contains \"X-My-Header\" [\"Value1\", \"Value2\"];";
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;octet", test.getComparator());
Assert.assertEquals("contains", 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(2, values.size());
Assert.assertEquals("Value1", values.get(0));
Assert.assertEquals("Value2", values.get(1));
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionWithIndex.
@Test
public void testSieveToSoapDeleteheaderActionWithIndex() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\"];\n" + "# rule1\n" + // matchType and comparator should be added by default
"deleteheader :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.assertNull(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.EditheaderTest in project zm-mailbox by Zimbra.
the class ModifyFilterRulesAdminTest method testSoapToSieveReplaceheaderAction5.
// headerName, multiple headerValues, comparator, value, relationalComparator
@Test
public void testSoapToSieveReplaceheaderAction5() 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 testSoapToSieveReplaceheaderAction7.
// headerName, multiple headerValues, comparator, count, relationalComparator
@Test
public void testSoapToSieveReplaceheaderAction7() 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);
ReplaceheaderAction action = new ReplaceheaderAction(null, null, test, "X-Test-Header-New", "[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 :newname \"X-Test-Header-New\" :newvalue \"[test] ${1}\" :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 testSoapToSieveDeleteheaderAction6.
// headerName, multiple headerValues, comparator, value, relationalComparator
@Test
public void testSoapToSieveDeleteheaderAction6() 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);
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 :value \"ge\" :comparator \"i;ascii-numeric\" \"X-Test-Header\" \"2\";\n";
Assert.assertEquals(script, account.getAdminSieveScriptBefore());
}
Aggregations