use of org.apache.jsieve.StringListArgument in project zm-mailbox by Zimbra.
the class FileInto method validateArguments.
@Override
protected void validateArguments(Arguments arguments, SieveContext context) throws SieveException {
List<Argument> args = arguments.getArgumentList();
if (args.size() < 1 || args.size() > 2) {
throw new SyntaxException("Exactly 1 or 2 arguments permitted. Found " + args.size());
}
Argument argument;
String copyArg;
if (args.size() == 1) {
// folder list argument
argument = (Argument) args.get(0);
} else {
copyArg = ((Argument) args.get(0)).getValue().toString();
// if arguments size is 2; first argument should be :copy
if (!Copy.COPY.equalsIgnoreCase(copyArg)) {
throw new SyntaxException("Error in sieve fileinto. Expecting argument :copy");
}
// folder list argument
argument = (Argument) args.get(1);
}
// folder list argument should be a String list
if (!(argument instanceof StringListArgument)) {
throw new SyntaxException("Expecting a string-list");
}
// folder list argument should contain exactly one folder name
if (1 != ((StringListArgument) argument).getList().size()) {
throw new SyntaxException("Expecting exactly one argument");
}
}
use of org.apache.jsieve.StringListArgument 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.StringListArgument in project zm-mailbox by Zimbra.
the class ValidNotifyMethodTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
List<String> notificationUris = null;
/*
* Usage: valid_notify_method <notification-uris: string-list>
*/
ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
if (argumentsIter.hasNext()) {
Argument argument = argumentsIter.next();
if (argument instanceof StringListArgument) {
notificationUris = ((StringListArgument) argument).getList();
}
}
if (null == notificationUris) {
throw context.getCoordinate().syntaxException("Expecting a StringList of notification-uris");
}
return test(notificationUris);
}
Aggregations