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.Iterator;
23 import java.util.List;
24
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 Iterator headerNamesIter = ((StringListArgument) arguments
51 .getArgumentList().get(0)).getList().iterator();
52
53 boolean found = true;
54 while (found && headerNamesIter.hasNext()) {
55 List headers = mail.getMatchingHeader((String) headerNamesIter
56 .next());
57 found = found && !headers.isEmpty();
58 }
59 return found;
60 }
61
62
63
64
65
66 protected void validateArguments(Arguments arguments, SieveContext context)
67 throws SieveException {
68 List argumentsList = arguments.getArgumentList();
69 if (1 != argumentsList.size())
70 throw context.getCoordinate().syntaxException(
71 "Expecting exactly one argument");
72
73 if (!(argumentsList.get(0) instanceof StringListArgument))
74 throw context.getCoordinate().syntaxException(
75 "Expecting a StringList");
76
77 if (arguments.hasTests())
78 throw context.getCoordinate().syntaxException(
79 "Found unexpected tests");
80 }
81
82 }