Search in sources :

Example 16 with SyntaxException

use of org.apache.jsieve.exception.SyntaxException in project zm-mailbox by Zimbra.

the class ReplaceHeaderTest method testNonAsciiHeaderNameWithoutOperation.

@Test
public void testNonAsciiHeaderNameWithoutOperation() {
    EditHeaderExtension ext = new EditHeaderExtension();
    ext.setKey("日本語ヘッダ名");
    try {
        ext.commonValidation(null);
    } catch (SyntaxException e) {
        Assert.assertEquals("EditHeaderExtension:Header name must be printable ASCII only.", e.getMessage());
    }
}
Also used : EditHeaderExtension(com.zimbra.cs.filter.jsieve.EditHeaderExtension) SyntaxException(org.apache.jsieve.exception.SyntaxException) Test(org.junit.Test)

Example 17 with SyntaxException

use of org.apache.jsieve.exception.SyntaxException in project zm-mailbox by Zimbra.

the class ReplaceHeaderTest method testNonAsciiHeaderName.

@Test
public void testNonAsciiHeaderName() {
    EditHeaderExtension ext = new EditHeaderExtension();
    ext.setKey("日本語ヘッダ名");
    try {
        ext.commonValidation("ReplaceHeader");
    } catch (SyntaxException e) {
        Assert.assertEquals("ReplaceHeader:Header name must be printable ASCII only.", e.getMessage());
    }
}
Also used : EditHeaderExtension(com.zimbra.cs.filter.jsieve.EditHeaderExtension) SyntaxException(org.apache.jsieve.exception.SyntaxException) Test(org.junit.Test)

Example 18 with SyntaxException

use of org.apache.jsieve.exception.SyntaxException in project zm-mailbox by Zimbra.

the class SetVariable method validateArguments.

@Override
protected void validateArguments(Arguments arguments, SieveContext context) throws SieveException {
    List<Argument> args = arguments.getArgumentList();
    // RFC 5229
    // ":lower" / ":upper" / ":lowerfirst" / ":upperfirst" /
    // ":quotewildcard" / ":length"
    // set "name" "Ethelbert"
    // set "a" "juMBlEd lETteRS";             => "juMBlEd lETteRS"
    // set :length "b" "${a}";                => "15"
    // set :lower "b" "${a}";                 => "jumbled letters"
    // set :upperfirst "b" "${a}";            => "JuMBlEd lETteRS"
    // set :upperfirst :lower "b" "${a}";     => "Jumbled letters"
    // set :quotewildcard "b" "Rock*";        => "Rock\*"
    // RFC 5435
    // ":encodeurl"
    // set :encodeurl "body_param" "Safe body&evil=evilbody"; => "safe+body%26evil%3Devilbody"
    int varArgCount = 0;
    String key = null;
    String[] operations = new String[OPERATIONS_IDX];
    if (args.size() >= 2) {
        for (Argument arg : arguments.getArgumentList()) {
            if (arg instanceof TagArgument) {
                TagArgument tag = (TagArgument) arg;
                String tagValue = tag.getTag();
                if (!isValidModifier(tagValue)) {
                    throw new SyntaxException("Invalid variable modifier:" + tagValue);
                } else {
                    int index = getIndex(tagValue);
                    if (StringUtil.isNullOrEmpty(operations[index])) {
                        operations[index] = tagValue.toLowerCase();
                    } else {
                        throw new SyntaxException("Cannot use two or more modifiers of the same" + " precedence in a single \"set\" action. Modifiers used: " + tagValue + " and " + operations[index]);
                    }
                }
            } else {
                String argument = ((StringListArgument) arg).getList().get(0);
                ZimbraLog.filter.debug("set variable argument: " + argument);
                if (varArgCount == 0) {
                    key = argument;
                }
                ++varArgCount;
            }
        }
        if (varArgCount != 2) {
            throw new SyntaxException("Exactly 2 arguments permitted. Found " + varArgCount);
        } else {
            if (!(isValidIdentifier(key))) {
                throw new SyntaxException("Variable identifier is invalid, got identifier " + key);
            }
        }
    } else {
        throw new SyntaxException("Minimum 2 arguments are needed. Usage: set :upperfirst \"b\" \"hello\";. Arguments found: " + arguments);
    }
}
Also used : TagArgument(org.apache.jsieve.TagArgument) Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) SyntaxException(org.apache.jsieve.exception.SyntaxException) TagArgument(org.apache.jsieve.TagArgument)

Example 19 with SyntaxException

use of org.apache.jsieve.exception.SyntaxException 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)

Example 20 with SyntaxException

use of org.apache.jsieve.exception.SyntaxException in project zm-mailbox by Zimbra.

the class Reply method validateArguments.

@Override
protected void validateArguments(Arguments arguments, SieveContext context) throws SieveException {
    List<Argument> args = arguments.getArgumentList();
    if (args.size() != 1)
        throw new SyntaxException("Exactly 1 argument permitted. Found " + args.size());
    Argument argument = args.get(0);
    if (!(argument instanceof StringListArgument))
        throw new SyntaxException("Expected text");
    if (((StringListArgument) argument).getList().size() != 1)
        throw new SyntaxException("Expected exactly one text");
}
Also used : StringListArgument(org.apache.jsieve.StringListArgument) Argument(org.apache.jsieve.Argument) SyntaxException(org.apache.jsieve.exception.SyntaxException) StringListArgument(org.apache.jsieve.StringListArgument)

Aggregations

SyntaxException (org.apache.jsieve.exception.SyntaxException)26 Argument (org.apache.jsieve.Argument)20 StringListArgument (org.apache.jsieve.StringListArgument)19 TagArgument (org.apache.jsieve.TagArgument)13 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)8 ServiceException (com.zimbra.common.service.ServiceException)4 DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)4 List (java.util.List)3 Test (org.junit.Test)3 ZimbraSieveException (com.zimbra.cs.filter.ZimbraSieveException)2 EditHeaderExtension (com.zimbra.cs.filter.jsieve.EditHeaderExtension)2 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 TimeZone (java.util.TimeZone)2 NumberArgument (org.apache.jsieve.NumberArgument)2 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 HeaderConstants (com.zimbra.common.soap.HeaderConstants)1 StringUtil (com.zimbra.common.util.StringUtil)1