use of org.apache.jsieve.TagArgument in project zm-mailbox by Zimbra.
the class BodyTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
String comparison = null;
boolean caseSensitive = false;
String key = null;
@SuppressWarnings("unchecked") ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
// TODO: handles ":matches" with * and ?
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof TagArgument) {
String tag = ((TagArgument) argument).getTag();
if (tag.equals(CONTAINS))
comparison = tag;
else
throw new SyntaxException("Found unexpected TagArgument: \"" + tag + "\"");
}
}
if (null == comparison)
throw new SyntaxException("Expecting \"" + CONTAINS + "\"");
// Second argument could be :comparator tag or else the value (string)
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof TagArgument) {
String tag = ((TagArgument) argument).getTag();
if (tag.equals(COMPARATOR)) {
if (argumentsIter.hasNext()) {
argument = argumentsIter.next();
if (argument instanceof StringListArgument) {
StringListArgument strList = (StringListArgument) argument;
try {
caseSensitive = Sieve.Comparator.ioctet == Sieve.Comparator.fromString(strList.getList().get(0));
} catch (ServiceException e) {
throw new SyntaxException(e.getMessage());
}
// Move to the last argument
if (argumentsIter.hasNext())
argument = argumentsIter.next();
} else {
throw new SyntaxException("Found unexpected argument after :comparator");
}
} else {
throw new SyntaxException("Unexpected end of arguments");
}
} else {
throw new SyntaxException("Found unexpected TagArgument: \"" + tag + "\"");
}
}
if (argument instanceof StringListArgument) {
StringListArgument strList = (StringListArgument) argument;
key = strList.getList().get(0);
}
}
if (null == key)
throw new SyntaxException("Expecting a string");
// There MUST NOT be any further arguments
if (argumentsIter.hasNext())
throw new SyntaxException("Found unexpected argument(s)");
return mail instanceof ZimbraMailAdapter && test(mail, caseSensitive, key);
}
use of org.apache.jsieve.TagArgument in project zm-mailbox by Zimbra.
the class VariableLog method validateArguments.
@Override
protected void validateArguments(Arguments arguments, SieveContext context) throws SieveException {
if (arguments.getArgumentList().size() > 2) {
throw new SyntaxException("Log: maximum 2 parameters allowed with Log");
}
boolean foundTagArg = false;
int index = 0;
Iterator<Argument> itr = arguments.getArgumentList().iterator();
while (itr.hasNext()) {
Argument arg = itr.next();
index++;
if (arg instanceof TagArgument) {
if (foundTagArg) {
throw new SyntaxException("Log: Multiple log levels are not allowed.");
}
if (index > 1) {
throw new SyntaxException("Log: Log level must be mentioned before log message.");
}
TagArgument tag = (TagArgument) arg;
if (!(tag.is(":" + FilterAction.LogAction.LogLevel.fatal.toString()) || tag.is(":" + FilterAction.LogAction.LogLevel.error.toString()) || tag.is(":" + FilterAction.LogAction.LogLevel.warn.toString()) || tag.is(":" + FilterAction.LogAction.LogLevel.info.toString()) || tag.is(":" + FilterAction.LogAction.LogLevel.debug.toString()) || tag.is(":" + FilterAction.LogAction.LogLevel.trace.toString()))) {
throw new SyntaxException("Log: Invalid log level provided - " + tag.getTag());
}
foundTagArg = true;
}
if (index > 1 && !foundTagArg) {
throw new SyntaxException("Log: Only 1 text message allowed with log statement.");
}
}
ZimbraLog.filter.debug("Log: Validation successfful");
}
Aggregations