Search in sources :

Example 1 with SieveNode

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

the class RuleRewriter method action.

private void action(Element elem, Node node) {
    int numChildren = node.jjtGetNumChildren();
    for (int i = 0; i < numChildren; i++) {
        Node childNode = node.jjtGetChild(i);
        if (childNode instanceof ASTstring) {
            String val = ((SieveNode) childNode).getValue().toString();
            if (val.startsWith("text:")) {
                elem.addText(val.substring(5));
            } else {
                // Put quotes around value to maintain backward compatibility
                // with ZCS 5.x.  See bug 39911.
                StringBuilder buf = new StringBuilder();
                if (!val.startsWith("\"")) {
                    buf.append('"');
                }
                buf.append(val);
                if (!val.endsWith("\"")) {
                    buf.append('"');
                }
                elem.addElement(MailConstants.E_FILTER_ARG).setText(buf.toString());
            }
        } else {
            action(elem, childNode);
        }
    }
}
Also used : ASTstring(org.apache.jsieve.parser.generated.ASTstring) Node(org.apache.jsieve.parser.generated.Node) SieveNode(org.apache.jsieve.parser.SieveNode) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 2 with SieveNode

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

the class RuleRewriter method test.

private void test(Element elem, Node node) {
    int numChildren = node.jjtGetNumChildren();
    for (int i = 0; i < numChildren; i++) {
        Node childNode = node.jjtGetChild(i);
        if (childNode instanceof ASTargument) {
            Object val = ((SieveNode) childNode).getValue();
            if (val != null) {
                if (MATCH_TYPES.contains(val.toString())) {
                    if (!mStack.isEmpty())
                        val = mStack.pop() + " " + val;
                    elem.addAttribute(MailConstants.A_OPERATION, val.toString());
                } else {
                    String cname = elem.getAttribute(MailConstants.A_NAME, null);
                    if ("size".equals(cname)) {
                        // special casing size test
                        elem.addAttribute(MailConstants.A_RHS, getSize(val.toString()));
                    } else {
                        elem.addAttribute(MailConstants.A_MODIFIER, val.toString());
                    }
                }
            }
        } else if (childNode instanceof ASTstring_list) {
            List<Object> val = getStringList(childNode);
            String cname = elem.getAttribute(MailConstants.A_NAME, null);
            String param = null;
            if ("date".equals(cname) || "body".equals(cname))
                param = MailConstants.A_RHS;
            else
                param = PARAM_PREFIX + String.valueOf(x++);
            elem.addAttribute(param, toString(val));
        }
        test(elem, childNode);
    }
}
Also used : SieveNode(org.apache.jsieve.parser.SieveNode) ASTstring_list(org.apache.jsieve.parser.generated.ASTstring_list) Node(org.apache.jsieve.parser.generated.Node) SieveNode(org.apache.jsieve.parser.SieveNode) ArrayList(java.util.ArrayList) List(java.util.List) ASTargument(org.apache.jsieve.parser.generated.ASTargument) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 3 with SieveNode

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

the class RuleRewriter method getStringList.

private List<Object> getStringList(Node node) {
    int n = node.jjtGetNumChildren();
    List<Object> a = new ArrayList<Object>(n);
    for (int i = 0; i < n; i++) {
        Node cn = node.jjtGetChild(i);
        a.add(((SieveNode) cn).getValue());
    }
    return a;
}
Also used : Node(org.apache.jsieve.parser.generated.Node) SieveNode(org.apache.jsieve.parser.SieveNode) ArrayList(java.util.ArrayList) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 4 with SieveNode

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

the class FolderRenamer method visitFileIntoAction.

@Override
protected void visitFileIntoAction(Node node, VisitPhase phase, RuleProperties props, String folderPath, boolean copy) throws ServiceException {
    if (phase != SieveVisitor.VisitPhase.begin || folderPath == null) {
        return;
    }
    folderPath = prefixWithSlash(folderPath);
    if (folderPath.startsWith(mOldPath)) {
        String newPath = folderPath.replace(mOldPath, mNewPath);
        SieveNode folderNameNode = (SieveNode) getNode(node, 0, 0, 0, 0);
        String escapedName = FilterUtil.escape(newPath);
        folderNameNode.setValue(escapedName);
        mRenamed = true;
    }
}
Also used : SieveNode(org.apache.jsieve.parser.SieveNode)

Example 5 with SieveNode

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

the class SieveVisitor method getValue.

private String getValue(Node parent, int... indexes) throws ServiceException {
    Node child = getNode(parent, indexes);
    Object value = ((SieveNode) child).getValue();
    if (value == null) {
        return null;
    }
    return value.toString();
}
Also used : SieveNode(org.apache.jsieve.parser.SieveNode) Node(org.apache.jsieve.parser.generated.Node) SieveNode(org.apache.jsieve.parser.SieveNode)

Aggregations

SieveNode (org.apache.jsieve.parser.SieveNode)9 Node (org.apache.jsieve.parser.generated.Node)8 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)5 ArrayList (java.util.ArrayList)4 Element (com.zimbra.common.soap.Element)2 List (java.util.List)2 ASTcommand (org.apache.jsieve.parser.generated.ASTcommand)2 Sieve (com.zimbra.common.filter.Sieve)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 Date (java.util.Date)1 TagArgument (org.apache.jsieve.TagArgument)1 ASTargument (org.apache.jsieve.parser.generated.ASTargument)1 ASTstring (org.apache.jsieve.parser.generated.ASTstring)1 ASTstring_list (org.apache.jsieve.parser.generated.ASTstring_list)1 ASTtest (org.apache.jsieve.parser.generated.ASTtest)1