use of com.zimbra.soap.mail.type.EditheaderTest 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.EditheaderTest 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.EditheaderTest 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.EditheaderTest 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));
}
use of com.zimbra.soap.mail.type.EditheaderTest in project zm-mailbox by Zimbra.
the class GetFilterRulesAdminTest method testSieveToSoapReplaceheaderActionBasicWithNewnameAndNewvaue.
@Test
public void testSieveToSoapReplaceheaderActionBasicWithNewnameAndNewvaue() throws ServiceException {
RuleManager.clearCachedRules(account);
String script = "require [\"editheader\", \"variables\"];\n" + "# rule1\n" + "replaceheader :newname \"X-My-Header2\" :newvalue \"[new] ${1}\" \"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;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("xyz", values.get(0));
}
Aggregations