use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionWithCountAndRelationalComparator.
@Test
public void testSieveToSoapDeleteheaderActionWithCountAndRelationalComparator() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\"];\n" + "# rule1\n" + "deleteheader :last :index 3 :count \"ge\" :comparator \"i;ascii-numeric\" \"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.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-numeric", test.getComparator());
Assert.assertNull(test.getMatchType());
Assert.assertEquals("ge", 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("2", values.get(0));
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapReplaceheaderActionBasicWithComparatorAndMatchType.
@Test
public void testSieveToSoapReplaceheaderActionBasicWithComparatorAndMatchType() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\", \"variables\"];\n" + "# rule1\n" + "replaceheader :newname \"X-My-Header2\" :newvalue \"[new] ${1}\" :comparator \"i;octet\" :contains \"X-My-Header\" \"xyz\";";
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;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(1, values.size());
Assert.assertEquals("xyz", values.get(0));
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionBasic.
/**
************deleteheader**************
*/
@Test
public void testSieveToSoapDeleteheaderActionBasic() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\"];\n" + "# rule1\n" + "deleteheader \"X-My-Header\";";
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.assertNull(test.getComparator());
Assert.assertNull(test.getMatchType());
Assert.assertNull(test.getRelationalComparator());
Assert.assertNull(test.getCount());
Assert.assertNull(test.getValue());
Assert.assertEquals("X-My-Header", test.getHeaderName());
Assert.assertNull(test.getHeaderValue());
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapReplaceheaderActionBasicWithIndex.
@Test
public void testSieveToSoapReplaceheaderActionBasicWithIndex() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\", \"variables\"];\n" + "# rule1\n" + "replaceheader :index 4 :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.assertEquals(4, 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 GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionWithValueAndRelationalComparator.
@Test
public void testSieveToSoapDeleteheaderActionWithValueAndRelationalComparator() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\"];\n" + "# rule1\n" + "deleteheader :last :index 3 :value \"ge\" :comparator \"i;ascii-numeric\" \"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.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-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