Search in sources :

Example 1 with ReplaceheaderAction

use of com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction 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 2 with ReplaceheaderAction

use of com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction 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 3 with ReplaceheaderAction

use of com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction in project zm-mailbox by Zimbra.

the class ModifyFilterRulesAdminTest method testSoapToSieveReplaceheaderAction2.

// headerName and headerValue only
// default comparator and matchType
@Test
public void testSoapToSieveReplaceheaderAction2() throws ServiceException, Exception {
    List<String> values = new ArrayList<String>();
    values.add("Test value");
    EditheaderTest test = new EditheaderTest(null, null, null, null, null, "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}\" :comparator \"i;ascii-casemap\" :is \"X-Test-Header\" \"Test value\";\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 4 with ReplaceheaderAction

use of com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction in project zm-mailbox by Zimbra.

the class ModifyFilterRulesAdminTest method testSoapToSieveReplaceheaderAction3.

// headerName and multiple headerValues
// default comparator and matchType
@Test
public void testSoapToSieveReplaceheaderAction3() throws ServiceException, Exception {
    List<String> values = new ArrayList<String>();
    values.add("Value1");
    values.add("Value2");
    values.add("Value3");
    EditheaderTest test = new EditheaderTest(null, null, null, null, null, "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}\" :comparator \"i;ascii-casemap\" :is \"X-Test-Header\" [ \"Value1\", \"Value2\", \"Value3\" ];\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 5 with ReplaceheaderAction

use of com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction in project zm-mailbox by Zimbra.

the class ModifyFilterRulesAdminTest method testSoapToSieveReplaceheaderAction6.

// headerName, multiple headerValues, comparator, value, relationalComparator
@Test
public void testSoapToSieveReplaceheaderAction6() 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)

Aggregations

EditheaderTest (com.zimbra.soap.mail.type.EditheaderTest)7 ReplaceheaderAction (com.zimbra.soap.mail.type.FilterAction.ReplaceheaderAction)7 FilterRule (com.zimbra.soap.mail.type.FilterRule)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7