示例#1
0
  /** @see org.apache.jsieve.tests.AbstractTest#validateArguments(Arguments, SieveContext) */
  protected void validateArguments(Arguments arguments, SieveContext context)
      throws SieveException {
    List<Argument> argumentsList = arguments.getArgumentList();
    if (1 != argumentsList.size())
      throw context.getCoordinate().syntaxException("Expecting exactly one argument");

    if (!(argumentsList.get(0) instanceof StringListArgument))
      throw context.getCoordinate().syntaxException("Expecting a StringList");

    if (arguments.hasTests())
      throw context.getCoordinate().syntaxException("Found unexpected tests");
  }
示例#2
0
  /**
   * @see org.apache.jsieve.tests.AbstractTest#executeBasic(MailAdapter, Arguments, SieveContext)
   *     <p>From RFC 3028, Section 5.9... <code>
   *    Syntax: size &lt;&quote;:over"&quote; / &quote;:under&quote;&gt; &lt;limit: number&gt;
   * </code>
   */
  protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context)
      throws SyntaxException, SieveMailException {
    String comparator = null;
    Integer size = null;
    ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();

    // First argument MUST be a tag of ":under" or ":over"
    if (argumentsIter.hasNext()) {
      Argument argument = argumentsIter.next();
      if (argument instanceof TagArgument) {
        final String tag = ((TagArgument) argument).getTag();
        if (tag.equals(":under") || tag.equals(":over")) comparator = tag;
        else
          throw context
              .getCoordinate()
              .syntaxException(
                  new StringBuilder("Found unexpected TagArgument: \"").append(tag).append("\""));
      }
    }
    if (null == comparator) throw context.getCoordinate().syntaxException("Expecting a Tag");

    // Second argument MUST be a number
    if (argumentsIter.hasNext()) {
      final Argument argument = argumentsIter.next();
      if (argument instanceof NumberArgument) size = ((NumberArgument) argument).getInteger();
    }
    if (null == size) throw context.getCoordinate().syntaxException("Expecting a Number");

    // There MUST NOT be any further arguments
    if (argumentsIter.hasNext())
      throw context.getCoordinate().syntaxException("Found unexpected argument(s)");

    return test(mail, comparator, size.intValue());
  }
示例#3
0
  /**
   * @see org.apache.jsieve.tests.AbstractTest#executeBasic(MailAdapter, Arguments, SieveContext)
   */
  protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context)
      throws SieveException {

    final List<String> argumentList =
        ((StringListArgument) arguments.getArgumentList().get(0)).getList();

    boolean found = true;
    for (final String arg : argumentList) {
      List<String> headers = mail.getMatchingHeader(arg);
      found = found && !headers.isEmpty();
      if (!found) {
        break;
      }
    }
    return found;
  }