1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package javax.mail.search;
21
22 import javax.mail.Message;
23 import javax.mail.MessagingException;
24
25
26
27
28 public final class HeaderTerm extends StringTerm {
29 protected String headerName;
30
31 public HeaderTerm(String header, String pattern) {
32 super(pattern);
33 this.headerName = header;
34 }
35
36 public String getHeaderName() {
37 return headerName;
38 }
39
40 public boolean match(Message message) {
41 try {
42 String values[] = message.getHeader(headerName);
43 if (values != null) {
44 for (int i = 0; i < values.length; i++) {
45 String value = values[i];
46 if (match(value)) {
47 return true;
48 }
49 }
50 }
51 return false;
52 } catch (MessagingException e) {
53 return false;
54 }
55 }
56
57 public boolean equals(Object other) {
58 if (other == this) return true;
59 if (other instanceof HeaderTerm == false) return false;
60
61 return headerName.equalsIgnoreCase(((HeaderTerm) other).headerName) && super.equals(other);
62 }
63
64 public int hashCode() {
65 return headerName.toLowerCase().hashCode() + super.hashCode();
66 }
67 }