Search in sources :

Example 6 with GetFilterRules

use of com.zimbra.cs.service.mail.GetFilterRules in project zm-mailbox by Zimbra.

the class GetFilterRulesTest method testNestedIfAllofAnyof.

@Test
public void testNestedIfAllofAnyof() {
    try {
        // - nested if
        // - no 'allof' and 'anyof' test for the outer if block
        // - 'anyof' test for the inner if block
        String filterScript = "require \"fileinto\";" + "if header :comparator \"i;ascii-casemap\" :matches \"Subject\" \"*\" {" + "  if anyof (header :matches \"From\" \"*\"," + "            header :matches \"To\"   \"*\") {" + "    fileinto \"nested-if-block\";" + "  }" + "}";
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        account.setMailSieveScript(filterScript);
        Element request = new Element.XMLElement(MailConstants.GET_FILTER_RULES_REQUEST);
        Element response = new GetFilterRules().handle(request, ServiceTestUtil.getRequestContext(account));
        String expectedSoapResponse = "<GetFilterRulesResponse xmlns=\"urn:zimbraMail\">" + "<filterRules>" + "<filterRule active=\"1\">" + "<filterTests>" + "<headerTest stringComparison=\"matches\" header=\"Subject\" index=\"0\" value=\"*\"/>" + "</filterTests>" + "<nestedRule>" + "<filterTests condition=\"anyof\">" + "<headerTest stringComparison=\"matches\" header=\"From\" index=\"0\" value=\"*\"/>" + "<headerTest stringComparison=\"matches\" header=\"To\"   index=\"1\" value=\"*\"/>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"nested-if-block\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</nestedRule>" + "</filterRule>" + "</filterRules>" + "</GetFilterRulesResponse>";
        XMLDiffChecker.assertXMLEquals(expectedSoapResponse, response.prettyPrint());
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GetFilterRules(com.zimbra.cs.service.mail.GetFilterRules) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 7 with GetFilterRules

use of com.zimbra.cs.service.mail.GetFilterRules in project zm-mailbox by Zimbra.

the class GetFilterRulesTest method testWithoutIfBlock5.

@Test
public void testWithoutIfBlock5() {
    try {
        // - combination of nested if without allof/anyof, and no if block
        String filterScript = "require \"fileinto\";" + "fileinto \"no-if-block1\";" + "if header :comparator \"i;ascii-casemap\" :matches \"Subject\" \"*\" {" + "  if header :matches \"From\" \"*\" {" + "    fileinto \"nested-if-block\";" + "  }" + "}" + "fileinto \"no-if-block2\";";
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        account.setMailSieveScript(filterScript);
        Element request = new Element.XMLElement(MailConstants.GET_FILTER_RULES_REQUEST);
        Element response = new GetFilterRules().handle(request, ServiceTestUtil.getRequestContext(account));
        String expectedSoapResponse = "<GetFilterRulesResponse xmlns=\"urn:zimbraMail\">" + "<filterRules>" + "<filterRule active=\"1\">" + "<filterTests>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"no-if-block1\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</filterRule>" + "<filterRule active=\"1\">" + "<filterTests>" + "<headerTest stringComparison=\"matches\" header=\"Subject\" index=\"0\" value=\"*\"/>" + "</filterTests>" + "<nestedRule>" + "<filterTests>" + "<headerTest stringComparison=\"matches\" header=\"From\" index=\"0\" value=\"*\"/>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"nested-if-block\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</nestedRule>" + "</filterRule>" + "<filterRule active=\"1\">" + "<filterTests>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"no-if-block2\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</filterRule>" + "</filterRules>" + "</GetFilterRulesResponse>";
        XMLDiffChecker.assertXMLEquals(expectedSoapResponse, response.prettyPrint());
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GetFilterRules(com.zimbra.cs.service.mail.GetFilterRules) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 8 with GetFilterRules

use of com.zimbra.cs.service.mail.GetFilterRules in project zm-mailbox by Zimbra.

the class GetFilterRulesTest method testWithoutIfBlock1.

@Test
public void testWithoutIfBlock1() {
    try {
        // - no if block
        String filterScript = "require \"fileinto\";" + "fileinto \"no-if-block\";";
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        account.setMailSieveScript(filterScript);
        Element request = new Element.XMLElement(MailConstants.GET_FILTER_RULES_REQUEST);
        Element response = new GetFilterRules().handle(request, ServiceTestUtil.getRequestContext(account));
        String expectedSoapResponse = "<GetFilterRulesResponse xmlns=\"urn:zimbraMail\">" + "<filterRules>" + "<filterRule active=\"1\">" + "<filterTests>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"no-if-block\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</filterRule>" + "</filterRules>" + "</GetFilterRulesResponse>";
        XMLDiffChecker.assertXMLEquals(expectedSoapResponse, response.prettyPrint());
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GetFilterRules(com.zimbra.cs.service.mail.GetFilterRules) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 9 with GetFilterRules

use of com.zimbra.cs.service.mail.GetFilterRules in project zm-mailbox by Zimbra.

the class GetFilterRulesTest method testWithoutIfBlock2.

@Test
public void testWithoutIfBlock2() {
    try {
        // - multiple no if block
        String filterScript = "require \"fileinto\";" + "fileinto \"no-if-block1\";" + "fileinto \"no-if-block2\";";
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        account.setMailSieveScript(filterScript);
        Element request = new Element.XMLElement(MailConstants.GET_FILTER_RULES_REQUEST);
        Element response = new GetFilterRules().handle(request, ServiceTestUtil.getRequestContext(account));
        String expectedSoapResponse = "<GetFilterRulesResponse xmlns=\"urn:zimbraMail\">" + "<filterRules>" + "<filterRule active=\"1\">" + "<filterTests>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"no-if-block1\" index=\"0\" copy=\"0\"/>" + "<actionFileInto folderPath=\"no-if-block2\" index=\"1\" copy=\"0\"/>" + "</filterActions>" + "</filterRule>" + "</filterRules>" + "</GetFilterRulesResponse>";
        XMLDiffChecker.assertXMLEquals(expectedSoapResponse, response.prettyPrint());
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GetFilterRules(com.zimbra.cs.service.mail.GetFilterRules) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 10 with GetFilterRules

use of com.zimbra.cs.service.mail.GetFilterRules in project zm-mailbox by Zimbra.

the class GetFilterRulesTest method testWithoutIfBlock4.

@Test
public void testWithoutIfBlock4() {
    try {
        // - nested if without allof/anyof, then no if block
        String filterScript = "require \"fileinto\";" + "if header :comparator \"i;ascii-casemap\" :matches \"Subject\" \"*\" {" + "  if header :matches \"From\" \"*\" {" + "    fileinto \"nested-if-block\";" + "  }" + "}" + "fileinto \"no-if-block\";";
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        account.setMailSieveScript(filterScript);
        Element request = new Element.XMLElement(MailConstants.GET_FILTER_RULES_REQUEST);
        Element response = new GetFilterRules().handle(request, ServiceTestUtil.getRequestContext(account));
        String expectedSoapResponse = "<GetFilterRulesResponse xmlns=\"urn:zimbraMail\">" + "<filterRules>" + "<filterRule active=\"1\">" + "<filterTests>" + "<headerTest stringComparison=\"matches\" header=\"Subject\" index=\"0\" value=\"*\"/>" + "</filterTests>" + "<nestedRule>" + "<filterTests>" + "<headerTest stringComparison=\"matches\" header=\"From\" index=\"0\" value=\"*\"/>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"nested-if-block\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</nestedRule>" + "</filterRule>" + "<filterRule active=\"1\">" + "<filterTests>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"no-if-block\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</filterRule>" + "</filterRules>" + "</GetFilterRulesResponse>";
        XMLDiffChecker.assertXMLEquals(expectedSoapResponse, response.prettyPrint());
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GetFilterRules(com.zimbra.cs.service.mail.GetFilterRules) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Aggregations

Element (com.zimbra.common.soap.Element)12 Account (com.zimbra.cs.account.Account)12 GetFilterRules (com.zimbra.cs.service.mail.GetFilterRules)12 Test (org.junit.Test)12 ServiceException (com.zimbra.common.service.ServiceException)3