1 /************************************************************************
2 * Copyright (c) 2000-2006 The Apache Software Foundation. *
3 * All rights reserved. *
4 * ------------------------------------------------------------------- *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you *
6 * may not use this file except in compliance with the License. You *
7 * may obtain a copy of the License at: *
8 * *
9 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * *
11 * Unless required by applicable law or agreed to in writing, software *
12 * distributed under the License is distributed on an "AS IS" BASIS, *
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14 * implied. See the License for the specific language governing *
15 * permissions and limitations under the License. *
16 ***********************************************************************/
17
18 package org.apache.james.transport.matchers;
19
20 import org.apache.mailet.GenericMatcher;
21 import org.apache.mailet.Mail;
22
23 import javax.mail.MessagingException;
24 import javax.mail.internet.MimeMessage;
25 import java.util.Collection;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 public class HasHabeasWarrantMark extends GenericMatcher
66 {
67 public static final String[][] warrantMark =
68 {
69 { "X-Habeas-SWE-1", "winter into spring" },
70 { "X-Habeas-SWE-2", "brightly anticipated" },
71 { "X-Habeas-SWE-3", "like Habeas SWE (tm)" },
72 { "X-Habeas-SWE-4", "Copyright 2002 Habeas (tm)" },
73 { "X-Habeas-SWE-5", "Sender Warranted Email (SWE) (tm). The sender of this" },
74 { "X-Habeas-SWE-6", "email in exchange for a license for this Habeas" },
75 { "X-Habeas-SWE-7", "warrant mark warrants that this is a Habeas Compliant" },
76 { "X-Habeas-SWE-8", "Message (HCM) and not spam. Please report use of this" },
77 { "X-Habeas-SWE-9", "mark in spam to <http://www.habeas.com/report/>." },
78 };
79
80 public Collection match(Mail mail) throws MessagingException
81 {
82 MimeMessage message = mail.getMessage();
83
84
85 for (int i = 0; i < warrantMark.length; i++) try
86 {
87 String headerName = warrantMark[i][0];
88 String requiredValue = warrantMark[i][1];
89 String headerValue = message.getHeader(headerName, null);
90
91
92
93
94
95
96
97 if (!(requiredValue.equals(headerValue))) return null;
98 }
99 catch (Exception e)
100 {
101 log(e.toString());
102 return null;
103 }
104
105
106 return mail.getRecipients();
107 }
108
109
110
111
112
113
114
115
116
117
118 public String getMatcherInfo()
119 {
120 return "Habeas Warrant Mark Matcher (see http://www.habeas.com for details).";
121 }
122 }
123