Search in sources :

Example 1 with ASTcommand

use of org.apache.jsieve.parser.generated.ASTcommand in project zm-mailbox by Zimbra.

the class RuleRewriter method traverse.

private void traverse(Node node) {
    int numChildren = node.jjtGetNumChildren();
    int nameIndex = 0;
    for (int i = 0; i < numChildren; i++) {
        Node childNode = node.jjtGetChild(i);
        String name = ((SieveNode) childNode).getName();
        if (childNode instanceof ASTcommand && ("if".equals(name) || "elsif".equals(name) || "disabled_if".equals(name))) {
            String ruleName = "";
            if (mRuleNames != null && nameIndex < mRuleNames.size()) {
                ruleName = mRuleNames.get(nameIndex);
                nameIndex++;
            }
            Element ruleElem = mRoot.addElement(MailConstants.E_RULE).addAttribute(MailConstants.A_NAME, ruleName);
            ruleElem.addAttribute(MailConstants.A_ACTIVE, !"disabled_if".equals(name));
            rule(ruleElem, childNode);
        } else {
            traverse(childNode);
        }
    }
}
Also used : SieveNode(org.apache.jsieve.parser.SieveNode) Node(org.apache.jsieve.parser.generated.Node) SieveNode(org.apache.jsieve.parser.SieveNode) ASTcommand(org.apache.jsieve.parser.generated.ASTcommand) Element(com.zimbra.common.soap.Element) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 2 with ASTcommand

use of org.apache.jsieve.parser.generated.ASTcommand in project zm-mailbox by Zimbra.

the class RuleRewriter method rule.

private void rule(Element elem, Node parent) {
    int numChildren = parent.jjtGetNumChildren();
    for (int i = 0; i < numChildren; i++) {
        Node node = parent.jjtGetChild(i);
        String name = ((SieveNode) node).getName();
        if (node instanceof ASTtest) {
            if ("anyof".equals(name) || "allof".equals(name)) {
                Element condsElem = elem.addElement(MailConstants.E_CONDITION_GROUP).addAttribute(MailConstants.A_OPERATION, name);
                rule(condsElem, node);
            } else if ("not".equals(name)) {
                mStack.push(name);
                rule(elem, node);
            } else {
                if ("exists".equals(name) && !mStack.isEmpty()) {
                    name = mStack.pop() + " " + name;
                }
                Element cElem = elem.addElement(MailConstants.E_CONDITION).addAttribute(MailConstants.A_NAME, name);
                x = 0;
                test(cElem, node);
            }
        } else if (node instanceof ASTcommand) {
            Element actionElem = elem.addElement(MailConstants.E_ACTION).addAttribute(MailConstants.A_NAME, ((SieveNode) node).getName());
            action(actionElem, node);
        } else {
            rule(elem, node);
        }
    }
}
Also used : SieveNode(org.apache.jsieve.parser.SieveNode) Node(org.apache.jsieve.parser.generated.Node) SieveNode(org.apache.jsieve.parser.SieveNode) Element(com.zimbra.common.soap.Element) ASTcommand(org.apache.jsieve.parser.generated.ASTcommand) ASTtest(org.apache.jsieve.parser.generated.ASTtest) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 3 with ASTcommand

use of org.apache.jsieve.parser.generated.ASTcommand in project zm-mailbox by Zimbra.

the class SieveVisitor method accept.

private void accept(Node parent, RuleProperties props) throws ServiceException {
    visitNode(parent, VisitPhase.begin, props);
    int numChildren = parent.jjtGetNumChildren();
    for (int i = 0; i < numChildren; i++) {
        Node node = parent.jjtGetChild(i);
        if (isRuleNode(node)) {
            // New rule tree or Nested if. New RuleProperties is created for each nested if
            RuleProperties newProps = new RuleProperties();
            if ("disabled_if".equalsIgnoreCase(getNodeName(node))) {
                newProps.isEnabled = false;
            }
            visitIfControl(node, VisitPhase.begin, newProps);
            accept(node, newProps);
            visitIfControl(node, VisitPhase.end, newProps);
        } else if (node instanceof ASTtest) {
            acceptTest(node, props);
        } else if (node instanceof ASTcommand) {
            acceptAction(node, props);
        } else {
            accept(node, props);
        }
    }
    visitNode(parent, VisitPhase.end, props);
}
Also used : Node(org.apache.jsieve.parser.generated.Node) SieveNode(org.apache.jsieve.parser.SieveNode) ASTcommand(org.apache.jsieve.parser.generated.ASTcommand) ASTtest(org.apache.jsieve.parser.generated.ASTtest)

Aggregations

SieveNode (org.apache.jsieve.parser.SieveNode)3 ASTcommand (org.apache.jsieve.parser.generated.ASTcommand)3 Node (org.apache.jsieve.parser.generated.Node)3 Element (com.zimbra.common.soap.Element)2 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)2 ASTtest (org.apache.jsieve.parser.generated.ASTtest)2