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 ImportanceTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
FilterTest.Importance importance;
if (argumentsIter.hasNext()) {
Argument argument = argumentsIter.next();
if (argument instanceof StringListArgument) {
importance = FilterTest.Importance.valueOf(((StringListArgument) argument).getList().get(0));
} else {
throw new SyntaxException("Expecting a string");
}
} else {
throw new SyntaxException("Unexpected end of arguments");
}
// First check "Importance" header
List<String> headers = Arrays.asList("Importance");
List<String> values = null;
switch(importance) {
case high:
values = Arrays.asList("High");
break;
case low:
values = Arrays.asList("Low");
break;
case normal:
values = Arrays.asList("High", "Low");
}
boolean result1 = match(mail, Sieve.Comparator.iasciicasemap.toString(), MatchTypeTags.IS_TAG, headers, values, context);
// Now check "X-Priority" header
headers = Arrays.asList("X-Priority");
values = null;
switch(importance) {
case high:
values = Arrays.asList("1");
break;
case low:
values = Arrays.asList("5");
break;
case normal:
// normal is when it is neither high importance nor low importance
values = Arrays.asList("1", "5");
}
boolean result2 = match(mail, Sieve.Comparator.iasciicasemap.toString(), MatchTypeTags.IS_TAG, headers, values, context);
// normal is when it is neither high importance nor low importance
return importance == FilterTest.ImportanceTest.Importance.normal ? !(result1 || result2) : result1 || result2;
}
use of org.apache.jsieve.StringListArgument in project zm-mailbox by Zimbra.
the class DummyCustomTag method validateArguments.
@Override
protected void validateArguments(Arguments arguments, SieveContext context) throws SieveException {
@SuppressWarnings("unchecked") List<Argument> args = arguments.getArgumentList();
if (args.size() != 1)
throw new SyntaxException("Exactly 1 argument permitted. Found " + args.size());
Object argument = args.get(0);
if (!(argument instanceof StringListArgument))
throw new SyntaxException("Expecting a string-list");
if (1 != ((StringListArgument) argument).getList().size())
throw new SyntaxException("Expecting exactly one argument");
}
Aggregations