Search in sources :

Example 21 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 : StringListArgument(org.apache.jsieve.StringListArgument) Argument(org.apache.jsieve.Argument) SyntaxException(org.apache.jsieve.exception.SyntaxException) StringListArgument(org.apache.jsieve.StringListArgument)

Example 22 with StringListArgument

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);
}
Also used : Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) TagArgument(org.apache.jsieve.TagArgument) ServiceException(com.zimbra.common.service.ServiceException) SyntaxException(org.apache.jsieve.exception.SyntaxException) TagArgument(org.apache.jsieve.TagArgument) StringListArgument(org.apache.jsieve.StringListArgument) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 23 with StringListArgument

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

Aggregations

Argument (org.apache.jsieve.Argument)23 StringListArgument (org.apache.jsieve.StringListArgument)23 SyntaxException (org.apache.jsieve.exception.SyntaxException)17 TagArgument (org.apache.jsieve.TagArgument)14 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)7 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 ImmutableSet (com.google.common.collect.ImmutableSet)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1