Search in sources :

Example 26 with Argument

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

Aggregations

Argument (org.apache.jsieve.Argument)26 StringListArgument (org.apache.jsieve.StringListArgument)25 SyntaxException (org.apache.jsieve.exception.SyntaxException)20 TagArgument (org.apache.jsieve.TagArgument)17 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)8 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