Search in sources :

Example 11 with GetFilterRules

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

the class ValueComparisonTest method testGetRuleHeaderTestValueComparisonCaseSensitivity.

/**
 * Tests GetFilterRulesRequest for rule containing header test and caseSensitive attribute with
 * value comparison
 * @throws Exception
 */
@Test
public void testGetRuleHeaderTestValueComparisonCaseSensitivity() 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 (header :value \"eq\" :comparator \"i;octet\" [\"subject\"] \"Important\") {\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" + "<headerTest valueComparison=\"eq\" caseSensitive=\"1\" header=\"subject\" index=\"0\" valueComparisonComparator=\"i;octet\" value=\"Important\"/> \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 12 with GetFilterRules

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

the class ValueComparisonTest method testGetRuleAddressTestValueComparisonCaseSensitivity.

/**
 * Tests GetFilterRulesRequest for rule containing address test and caseSensitive attribute with
 * value comparison
 * @throws Exception
 */
@Test
public void testGetRuleAddressTestValueComparisonCaseSensitivity() 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 (address :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" + "<addressTest 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)

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