Search in sources :

Example 6 with FilterRule

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

the class ModifyFilterRulesTest method testBug92309_SetIncomingXMLRules_EmptyAddress.

/**
     * Bug 92309: text "null" was set to To/Cc/From field
     *
     * When the To, Cc, or From field in the message filter rule
     * composing dialogue window is left empty, ZWC automatically
     * put a text "null" to the filed.  This test case tests that
     * the text "null" will not be set if the To/Cc/From field
     * is empty.
     */
@Test
public void testBug92309_SetIncomingXMLRules_EmptyAddress() {
    try {
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        // Construct a filter rule with 'address' test whose value is empty (null)
        FilterRule rule = new FilterRule("testSetIncomingXMLRules_EmptyAddress", true);
        FilterTest.AddressTest test = new FilterTest.AddressTest();
        test.setHeader("to");
        test.setStringComparison("is");
        test.setPart("all");
        test.setValue(null);
        test.setIndex(0);
        FilterTests tests = new FilterTests("anyof");
        tests.addTest(test);
        FilterAction action = new FilterAction.KeepAction();
        action.setIndex(0);
        rule.setFilterTests(tests);
        rule.addFilterAction(action);
        List<FilterRule> filterRuleList = new ArrayList<FilterRule>();
        filterRuleList.add(rule);
        // When the ModifyFilterRulesRequest is submitted from the Web client,
        // eventually this RuleManager.setIncomingXMLRules is called to convert
        // the request in JSON to the SIEVE rule text.
        RuleManager.setIncomingXMLRules(account, filterRuleList);
        // Verify that the saved zimbraMailSieveScript
        String sieve = account.getMailSieveScript();
        int result = sieve.indexOf("address :all :is :comparator \"i;ascii-casemap\" [\"to\"] \"\"");
        Assert.assertNotSame(-1, result);
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) ArrayList(java.util.ArrayList) FilterRule(com.zimbra.soap.mail.type.FilterRule) ServiceException(com.zimbra.common.service.ServiceException) FilterTest(com.zimbra.soap.mail.type.FilterTest) FilterTests(com.zimbra.soap.mail.type.FilterTests) FilterAction(com.zimbra.soap.mail.type.FilterAction) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 7 with FilterRule

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

the class ModifyFilterRulesTest method SetIncomingXMLRulesForEnvelopeCountComparison.

@Test
public void SetIncomingXMLRulesForEnvelopeCountComparison() {
    try {
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        // Construct a filter rule with 'address' test whose value is empty (null)
        FilterRule rule = new FilterRule("testSetIncomingXMLRulesForEnvelope", true);
        FilterTest.EnvelopeTest test = new FilterTest.EnvelopeTest();
        test.setHeader("to");
        test.setCountComparison("eq");
        test.setPart("all");
        test.setValue("1");
        test.setIndex(0);
        FilterTests tests = new FilterTests("anyof");
        tests.addTest(test);
        FilterAction action = new FilterAction.KeepAction();
        action.setIndex(0);
        rule.setFilterTests(tests);
        rule.addFilterAction(action);
        List<FilterRule> filterRuleList = new ArrayList<FilterRule>();
        filterRuleList.add(rule);
        // When the ModifyFilterRulesRequest is submitted from the Web client,
        // eventually this RuleManager.setIncomingXMLRules is called to convert
        // the request in JSON to the SIEVE rule text.
        RuleManager.setIncomingXMLRules(account, filterRuleList);
        // Verify that the saved zimbraMailSieveScript
        String sieve = account.getMailSieveScript();
        int result = sieve.indexOf("envelope :count \"eq\" :all :comparator \"i;ascii-numeric\" [\"to\"] \"1\"");
        Assert.assertNotSame(-1, result);
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) ArrayList(java.util.ArrayList) FilterRule(com.zimbra.soap.mail.type.FilterRule) ServiceException(com.zimbra.common.service.ServiceException) FilterTest(com.zimbra.soap.mail.type.FilterTest) FilterTests(com.zimbra.soap.mail.type.FilterTests) FilterAction(com.zimbra.soap.mail.type.FilterAction) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 8 with FilterRule

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

the class SieveToSoap method visitRule.

@Override
protected void visitRule(Node ruleNode, VisitPhase phase, RuleProperties props) {
    if (phase == VisitPhase.end) {
        return;
    }
    if (!isNestedRule()) {
        currentRule = new FilterRule(getCurrentRuleName(), props.isEnabled);
        setCurrentVariables();
        if (actionVariables != null && !actionVariables.isEmpty()) {
            currentRule.addFilterAction(new FilterVariables(actionVariables));
        }
        if (actionVariables != null && !actionVariables.isEmpty()) {
            currentRule.addFilterAction(new FilterVariables(actionVariables));
        }
        currentRule.setFilterTests(new FilterTests(props.condition.toString()));
        rules.add(currentRule);
        currentRuleIndex++;
        // When start working on the root rule, initialise the pointer to nested rule
        currentNestedRule = null;
    } else {
        // set new Nested Rule instance as child of current one.
        NestedRule nestedRule = new NestedRule(new FilterTests(props.condition.toString()));
        if (currentNestedRule != null) {
            // some nested rule has been already processed
            // set it as child of previous one
            currentNestedRule.setChild(nestedRule);
            setCurrentVariables();
            if (actionVariables != null && !actionVariables.isEmpty()) {
                currentNestedRule.addFilterAction(new FilterVariables(actionVariables));
            }
        } else {
            // first nested rule
            // set it as child of root rule
            currentRule.setChild(nestedRule);
            setCurrentVariables();
            if (actionVariables != null && !actionVariables.isEmpty()) {
                currentRule.addFilterAction(new FilterVariables(actionVariables));
            }
        }
        currentNestedRule = nestedRule;
        actionVariables = null;
    }
}
Also used : FilterTests(com.zimbra.soap.mail.type.FilterTests) NestedRule(com.zimbra.soap.mail.type.NestedRule) FilterRule(com.zimbra.soap.mail.type.FilterRule) FilterVariables(com.zimbra.soap.mail.type.FilterVariables)

Aggregations

FilterRule (com.zimbra.soap.mail.type.FilterRule)8 FilterTests (com.zimbra.soap.mail.type.FilterTests)6 FilterAction (com.zimbra.soap.mail.type.FilterAction)5 FilterTest (com.zimbra.soap.mail.type.FilterTest)5 Test (org.junit.Test)5 Account (com.zimbra.cs.account.Account)4 ServiceException (com.zimbra.common.service.ServiceException)3 ArrayList (java.util.ArrayList)3 Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 GetFilterRulesResponse (com.zimbra.soap.mail.message.GetFilterRulesResponse)1 FilterVariables (com.zimbra.soap.mail.type.FilterVariables)1 NestedRule (com.zimbra.soap.mail.type.NestedRule)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlElement (javax.xml.bind.annotation.XmlElement)1