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());
}
}
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());
}
}
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);
}
}
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");
}
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");
}
Aggregations