Search in sources :

Example 1 with NumberArgument

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

the class EditHeaderExtension method setupEditHeaderData.

// Utility methods
/**
     * This method sets values provided with replaceheader or deleteheader in <b>EditHeaderExtension</b> object.
     * @param arguments
     * @param ac
     * @throws SyntaxException
     * @throws OperationException
     */
public void setupEditHeaderData(Arguments arguments, AbstractCommand ac) throws SyntaxException, OperationException {
    // set up class variables
    Iterator<Argument> itr = arguments.getArgumentList().iterator();
    while (itr.hasNext()) {
        Argument arg = itr.next();
        if (arg instanceof TagArgument) {
            TagArgument tag = (TagArgument) arg;
            if (tag.is(INDEX)) {
                if (itr.hasNext()) {
                    arg = itr.next();
                    if (arg instanceof NumberArgument) {
                        this.index = ((NumberArgument) arg).getInteger();
                    } else {
                        throw new SyntaxException("Invalid index provided with replaceheader : " + arg);
                    }
                }
            } else if (tag.is(LAST)) {
                this.last = true;
            } else if (tag.is(NEW_NAME)) {
                if (itr.hasNext()) {
                    arg = itr.next();
                    if (arg instanceof StringListArgument) {
                        StringListArgument sla = (StringListArgument) arg;
                        String origNewName = sla.getList().get(0);
                        if (StringUtil.isNullOrEmpty(origNewName)) {
                            throw new SyntaxException("New name must be present with :newname in replaceheader : " + arg);
                        }
                        this.newName = origNewName;
                    } else {
                        throw new SyntaxException("New name not provided with :newname in replaceheader : " + arg);
                    }
                }
            } else if (tag.is(NEW_VALUE)) {
                if (itr.hasNext()) {
                    arg = itr.next();
                    if (arg instanceof StringListArgument) {
                        StringListArgument sla = (StringListArgument) arg;
                        this.newValue = sla.getList().get(0);
                    } else {
                        throw new SyntaxException("New value not provided with :newValue in replaceheader : " + arg);
                    }
                }
            } else if (tag.is(COUNT)) {
                if (this.valueTag) {
                    throw new SyntaxException(":count and :value both can not be used with replaceheader");
                }
                this.countTag = true;
                if (itr.hasNext()) {
                    arg = itr.next();
                    if (arg instanceof StringListArgument) {
                        StringListArgument sla = (StringListArgument) arg;
                        this.relationalComparator = sla.getList().get(0);
                    } else {
                        throw new SyntaxException("Relational comparator not provided with :count in replaceheader : " + arg);
                    }
                }
            } else if (tag.is(VALUE)) {
                if (this.countTag) {
                    throw new SyntaxException(":count and :value both can not be used with replaceheader");
                }
                this.valueTag = true;
                if (itr.hasNext()) {
                    arg = itr.next();
                    if (arg instanceof StringListArgument) {
                        StringListArgument sla = (StringListArgument) arg;
                        this.relationalComparator = sla.getList().get(0);
                    } else {
                        throw new SyntaxException("Relational comparator not provided with :value in replaceheader : " + arg);
                    }
                }
            } else if (tag.is(ComparatorTags.COMPARATOR_TAG)) {
                if (itr.hasNext()) {
                    arg = itr.next();
                    if (arg instanceof StringListArgument) {
                        StringListArgument sla = (StringListArgument) arg;
                        this.comparator = sla.getList().get(0);
                    } else {
                        throw new SyntaxException("Comparator not provided with :comparator in replaceheader : " + arg);
                    }
                }
            } else if (tag.is(MatchTypeTags.CONTAINS_TAG)) {
                this.contains = true;
            } else if (tag.is(MatchTypeTags.IS_TAG)) {
                this.is = true;
            } else if (tag.is(MatchTypeTags.MATCHES_TAG)) {
                this.matches = true;
            } else {
                throw new SyntaxException("Invalid tag argument provided with replaceheader.");
            }
        } else if (arg instanceof StringListArgument) {
            if (ac instanceof ReplaceHeader) {
                StringListArgument sla = (StringListArgument) arg;
                this.key = sla.getList().get(0);
                if (itr.hasNext()) {
                    arg = itr.next();
                    sla = (StringListArgument) arg;
                    this.valueList = sla.getList();
                }
            } else if (ac instanceof DeleteHeader) {
                StringListArgument sla = (StringListArgument) arg;
                this.key = sla.getList().get(0);
                if (itr.hasNext()) {
                    arg = itr.next();
                    sla = (StringListArgument) arg;
                    this.valueList = sla.getList();
                } else {
                    ZimbraLog.filter.info("Value for " + this.key + " is not provided in deleteheader. So all headers with this key will be deleted.");
                }
            } else {
                throw new OperationException("Invalid instance of AbstractCommand is obtained.");
            }
        } else {
            ZimbraLog.filter.info("Unknown argument provided: " + arg.getValue());
        }
    }
    if (!(isIs() || isContains() || isMatches() || isCountTag() || isValueTag())) {
        this.is = true;
    }
}
Also used : NumberArgument(org.apache.jsieve.NumberArgument) Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) TagArgument(org.apache.jsieve.TagArgument) NumberArgument(org.apache.jsieve.NumberArgument) SyntaxException(org.apache.jsieve.exception.SyntaxException) TagArgument(org.apache.jsieve.TagArgument) StringListArgument(org.apache.jsieve.StringListArgument) OperationException(org.apache.jsieve.exception.OperationException)

Example 2 with NumberArgument

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

the class Notify method executeBasic.

@Override
protected Object executeBasic(MailAdapter mail, Arguments arguments, Block block, SieveContext context) throws SieveException {
    List<Argument> args = arguments.getArgumentList();
    if (args.size() < 3)
        throw new SyntaxException("Missing arguments");
    Argument nextArg = args.get(0);
    if (!(nextArg instanceof StringListArgument))
        throw new SyntaxException("Expected string");
    List<String> list = ((StringListArgument) nextArg).getList();
    if (list.size() != 1)
        throw new SyntaxException("Expected exactly one email address");
    String emailAddr = list.get(0);
    nextArg = args.get(1);
    if (!(nextArg instanceof StringListArgument))
        throw new SyntaxException("Expected string");
    list = ((StringListArgument) nextArg).getList();
    if (list.size() != 1)
        throw new SyntaxException("Expected exactly one subject");
    String subjectTemplate = list.get(0);
    nextArg = args.get(2);
    if (!(nextArg instanceof StringListArgument))
        throw new SyntaxException("Expected string");
    list = ((StringListArgument) nextArg).getList();
    if (list.size() != 1)
        throw new SyntaxException("Expected exactly one body");
    String bodyTemplate = list.get(0);
    int maxBodyBytes = -1;
    List<String> origHeaders = null;
    if (args.size() == 4) {
        nextArg = args.get(3);
        if (nextArg instanceof NumberArgument)
            maxBodyBytes = ((NumberArgument) nextArg).getInteger();
        else if (nextArg instanceof StringListArgument)
            origHeaders = ((StringListArgument) nextArg).getList();
        else
            throw new SyntaxException("Invalid argument");
    }
    if (args.size() == 5) {
        nextArg = args.get(3);
        if (!(nextArg instanceof NumberArgument))
            throw new SyntaxException("Expected int");
        maxBodyBytes = ((NumberArgument) nextArg).getInteger();
        nextArg = args.get(4);
        if (!(nextArg instanceof StringListArgument))
            throw new SyntaxException("Expected string list");
        origHeaders = ((StringListArgument) nextArg).getList();
    }
    mail.addAction(new ActionNotify(emailAddr, subjectTemplate, bodyTemplate, maxBodyBytes, origHeaders));
    return null;
}
Also used : NumberArgument(org.apache.jsieve.NumberArgument) Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) NumberArgument(org.apache.jsieve.NumberArgument) SyntaxException(org.apache.jsieve.exception.SyntaxException) StringListArgument(org.apache.jsieve.StringListArgument)

Aggregations

Argument (org.apache.jsieve.Argument)2 NumberArgument (org.apache.jsieve.NumberArgument)2 StringListArgument (org.apache.jsieve.StringListArgument)2 SyntaxException (org.apache.jsieve.exception.SyntaxException)2 TagArgument (org.apache.jsieve.TagArgument)1 OperationException (org.apache.jsieve.exception.OperationException)1