1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve.tests;
21
22 import java.util.List;
23
24 import org.apache.jsieve.Argument;
25 import org.apache.jsieve.Arguments;
26 import org.apache.jsieve.SieveContext;
27 import org.apache.jsieve.StringListArgument;
28 import org.apache.jsieve.exception.SieveException;
29 import org.apache.jsieve.mail.MailAdapter;
30
31
32
33
34 public class Exists extends AbstractTest {
35
36
37
38
39 public Exists() {
40 super();
41 }
42
43
44
45
46
47 protected boolean executeBasic(MailAdapter mail, Arguments arguments,
48 SieveContext context) throws SieveException {
49
50 final List<String> argumentList = ((StringListArgument) arguments
51 .getArgumentList().get(0)).getList();
52
53 boolean found = true;
54 for (final String arg:argumentList) {
55 List<String> headers = mail.getMatchingHeader(arg);
56 found = found && !headers.isEmpty();
57 if (!found) {
58 break;
59 }
60 }
61 return found;
62 }
63
64
65
66
67
68 protected void validateArguments(Arguments arguments, SieveContext context)
69 throws SieveException {
70 List<Argument> argumentsList = arguments.getArgumentList();
71 if (1 != argumentsList.size())
72 throw context.getCoordinate().syntaxException(
73 "Expecting exactly one argument");
74
75 if (!(argumentsList.get(0) instanceof StringListArgument))
76 throw context.getCoordinate().syntaxException(
77 "Expecting a StringList");
78
79 if (arguments.hasTests())
80 throw context.getCoordinate().syntaxException(
81 "Found unexpected tests");
82 }
83
84 }