Search in sources :

Example 31 with EditheaderTest

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

the class GetFilterRulesAdminTest method testSieveToSoapDeleteheaderActionWithIndexAndLastWithoutValue.

@Test
public void testSieveToSoapDeleteheaderActionWithIndexAndLastWithoutValue() throws ServiceException {
    RuleManager.clearCachedRules(account);
    String script = "require [\"editheader\"];\n" + "# rule1\n" + "deleteheader :last :index 3 \"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.assertTrue(action.getLast());
    Assert.assertEquals(3, action.getOffset().intValue());
    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 32 with EditheaderTest

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

the class ModifyFilterRulesAdminTest method testSoapToSieveReplaceheaderActionBasic.

/**
 ****************replaceheader********************
 */
@Test
public void testSoapToSieveReplaceheaderActionBasic() throws ServiceException, Exception {
    EditheaderTest test = new EditheaderTest(null, null, null, null, null, "X-Test-Header", null);
    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}\" \"X-Test-Header\";\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 33 with EditheaderTest

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

the class ModifyFilterRulesAdminTest method testSoapToSieveReplaceheaderAction4.

// headerName, multiple headerValues, matchType and comparator
@Test
public void testSoapToSieveReplaceheaderAction4() throws ServiceException, Exception {
    List<String> values = new ArrayList<String>();
    values.add("Value1");
    values.add("Value2");
    values.add("Value3");
    EditheaderTest test = new EditheaderTest("contains", null, null, null, "i;octet", "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;octet\" :contains \"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)

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