Search in sources :

Example 1 with GetFilterRules

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

the class ValueComparisonTest method testGetRuleEnvelopeTestValueComparisonCaseSensitivity.

/**
 * Tests GetFilterRulesRequest for rule containing envelope test and caseSensitive attribute with
 * value comparison
 * @throws Exception
 */
@Test
public void testGetRuleEnvelopeTestValueComparisonCaseSensitivity() throws Exception {
    try {
        String filterScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
        filterScript += "if anyof (envelope :value \"eq\" :all :comparator \"i;octet\" [\"from\"] \"abCD\") {\n";
        filterScript += "    fileinto \"Junk\";\n";
        filterScript += "    stop;\n";
        filterScript += "}\n";
        ZimbraLog.filter.info(filterScript);
        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\"> \n" + "<filterRules> \n" + "<filterRule active=\"1\"> \n" + "<filterTests condition=\"anyof\"> \n" + "<envelopeTest valueComparison=\"eq\" caseSensitive=\"1\" part=\"all\" header=\"from\" index=\"0\" valueComparisonComparator=\"i;octet\" value=\"abCD\"/> \n" + "</filterTests> \n" + "<filterActions> \n" + " <actionFileInto folderPath=\"Junk\" index=\"0\" copy=\"0\"/> \n" + "  <actionStop index=\"1\"/> \n" + "</filterActions> \n" + "</filterRule> \n" + "</filterRules> \n" + "</GetFilterRulesResponse>";
        ZimbraLog.filter.info(response.prettyPrint());
        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) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test)

Example 2 with GetFilterRules

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

the class GetFilterRulesTest method testIfWithoutAllof.

@Test
public void testIfWithoutAllof() {
    try {
        // - no 'allof' 'anyof' tests
        String filterScript = "require \"fileinto\";" + "if header :comparator \"i;ascii-casemap\" :matches \"Subject\" \"*\" {" + "  fileinto \"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>" + "<filterActions>" + "<actionFileInto folderPath=\"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 3 with GetFilterRules

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

the class GetFilterRulesTest method testNestedIfWithoutAllof.

@Test
public void testNestedIfWithoutAllof() {
    try {
        // - no 'allof' 'anyof' tests
        // - nested if
        String filterScript = "require \"fileinto\";" + "if header :comparator \"i;ascii-casemap\" :matches \"Subject\" \"*\" {" + "  if header :matches \"From\" \"*\" {" + "    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>" + "<headerTest stringComparison=\"matches\" header=\"From\" index=\"0\" 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 4 with GetFilterRules

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

the class GetFilterRulesTest method testWithoutIfBlock3.

@Test
public void testWithoutIfBlock3() {
    try {
        // - no if block, then nested if without allof/anyof
        String filterScript = "require \"fileinto\";" + "fileinto \"no-if-block\";" + "if header :comparator \"i;ascii-casemap\" :matches \"Subject\" \"*\" {" + "  if header :matches \"From\" \"*\" {" + "    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>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"no-if-block\" 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>" + "</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 5 with GetFilterRules

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

the class GetFilterRulesTest method testIfWithAllofAnyOf.

@Test
public void testIfWithAllofAnyOf() {
    try {
        // - 'allof' and 'anyof' tests
        String filterScript = "require \"fileinto\";" + "if allof (header :comparator \"i;ascii-casemap\" :matches \"Subject\" \"*\") {" + "  fileinto \"if-block1\";" + "}" + "if anyof (header :comparator \"i;ascii-casemap\" :matches \"X-Header\" \"*\") {" + "  fileinto \"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 condition=\"allof\">" + "<headerTest stringComparison=\"matches\" header=\"Subject\" index=\"0\" value=\"*\"/>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"if-block1\" index=\"0\" copy=\"0\"/>" + "</filterActions>" + "</filterRule>" + "<filterRule active=\"1\">" + "<filterTests condition=\"anyof\">" + "<headerTest stringComparison=\"matches\" header=\"X-Header\" index=\"0\" value=\"*\"/>" + "</filterTests>" + "<filterActions>" + "<actionFileInto folderPath=\"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)

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