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);
}
}
}
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);
}
}
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;
}
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;
}
}
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();
}
Aggregations