Search in sources :

Example 26 with StringListArgument

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");
    }
}
Also used : Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) SyntaxException(org.apache.jsieve.exception.SyntaxException) StringListArgument(org.apache.jsieve.StringListArgument)

Example 27 with StringListArgument

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;
}
Also used : Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) FilterTest(com.zimbra.soap.mail.type.FilterTest) SyntaxException(org.apache.jsieve.exception.SyntaxException) StringListArgument(org.apache.jsieve.StringListArgument)

Example 28 with StringListArgument

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");
}
Also used : Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) SyntaxException(org.apache.jsieve.exception.SyntaxException) StringListArgument(org.apache.jsieve.StringListArgument)

Aggregations

StringListArgument (org.apache.jsieve.StringListArgument)28 Argument (org.apache.jsieve.Argument)25 SyntaxException (org.apache.jsieve.exception.SyntaxException)17 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)14 TagArgument (org.apache.jsieve.TagArgument)14 DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)4 ServiceException (com.zimbra.common.service.ServiceException)3 ZimbraSieveException (com.zimbra.cs.filter.ZimbraSieveException)2 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 List (java.util.List)2 TimeZone (java.util.TimeZone)2 NumberArgument (org.apache.jsieve.NumberArgument)2 SieveException (org.apache.jsieve.exception.SieveException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Account (com.zimbra.cs.account.Account)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1