Search in sources :

Example 26 with EditheaderTest

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));
}
Also used : FilterRule(com.zimbra.soap.mail.type.FilterRule) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) FilterAction(com.zimbra.soap.mail.type.FilterAction) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) Test(org.junit.Test)

Example 27 with EditheaderTest

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));
}
Also used : FilterRule(com.zimbra.soap.mail.type.FilterRule) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) FilterAction(com.zimbra.soap.mail.type.FilterAction) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) Test(org.junit.Test)

Example 28 with EditheaderTest

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());
}
Also used : FilterRule(com.zimbra.soap.mail.type.FilterRule) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) FilterAction(com.zimbra.soap.mail.type.FilterAction) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) Test(org.junit.Test)

Example 29 with EditheaderTest

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));
}
Also used : FilterRule(com.zimbra.soap.mail.type.FilterRule) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) FilterAction(com.zimbra.soap.mail.type.FilterAction) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) Test(org.junit.Test)

Example 30 with EditheaderTest

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));
}
Also used : FilterRule(com.zimbra.soap.mail.type.FilterRule) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) FilterAction(com.zimbra.soap.mail.type.FilterAction) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) Test(org.junit.Test)

Aggregations

EditheaderTest (com.zimbra.soap.mail.type.EditheaderTest)33 FilterRule (com.zimbra.soap.mail.type.FilterRule)30 Test (org.junit.Test)30 FilterAction (com.zimbra.soap.mail.type.FilterAction)19 ArrayList (java.util.ArrayList)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 DeleteheaderAction (com.zimbra.soap.mail.type.FilterAction.DeleteheaderAction)7 ReplaceheaderAction (com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction)7 List (java.util.List)1