Search in sources :

Example 6 with EditheaderTest

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));
}
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 7 with EditheaderTest

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));
}
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 8 with EditheaderTest

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());
}
Also used : ArrayList(java.util.ArrayList) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) ReplaceheaderAction(com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction) FilterRule(com.zimbra.soap.mail.type.FilterRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) Test(org.junit.Test)

Example 9 with EditheaderTest

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());
}
Also used : ArrayList(java.util.ArrayList) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) ReplaceheaderAction(com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction) FilterRule(com.zimbra.soap.mail.type.FilterRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) Test(org.junit.Test)

Example 10 with EditheaderTest

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());
}
Also used : ArrayList(java.util.ArrayList) DeleteheaderAction(com.zimbra.soap.mail.type.FilterAction.DeleteheaderAction) EditheaderTest(com.zimbra.soap.mail.type.EditheaderTest) FilterRule(com.zimbra.soap.mail.type.FilterRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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