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 * This matcher tests for the Hebeas Warrant Mark.
29 * For details see: http://www.hebeas.com
30 *
31 * Usage: Place this matcher
32 *
33 * <mailet match="HasHabeasWarrantMark" class="ToProcessor">
34 * <processor> transport </processor>
35 * </mailet>
36 *
37 * in the root processs before the DNSRBL block lists (the InSpammerBlacklist matcher).
38 *
39 * Because the Habeas Warrant Mark is copyright material, I have asked for and
40 * received the following explicit statement from Habeas:
41 *
42 * -----------------------------------
43 * From: Lindsey Pettit [mailto:support@habeas.com]
44 * Sent: Sunday, September 29, 2002 5:51
45 * To: Noel J. Bergman
46 * Subject: RE: Habeas and Apache James
47 *
48 * Dear Noel,
49 *
50 * > I guess that since your Warrant Mark is copyright, I should ask for
51 * > something from you to explicitly authorize that Hebeas will permit
52 * > this code to be included and distributed as part of Apache James
53 * > under the Apache Software License. As we have established, the use
54 * > of the Habeas Warrant Mark for filtering is not restricted, but I
55 * > would like something to confirm that, so that Apache will be happy.
56 *
57 * I can hereby confirm to you that there is no license necessary in
58 * order to use the Habeas mark for filtering. That said, however, we
59 * do insist that it not ever be used as a basis for rejecting email which
60 * bears the Habeas mark.
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 //Loop through all the patterns
85 for (int i = 0; i < warrantMark.length; i++) try
86 {
87 String headerName = warrantMark[i][0]; //Get the header name
88 String requiredValue = warrantMark[i][1]; //Get the required value
89 String headerValue = message.getHeader(headerName, null); //Get the header value(s)
90
91 // We want an exact match, so only test the first value.
92 // If there are multiple values, the header may be
93 // (illegally) forged. I'll leave it as an exercise to
94 // others if they want to detect and report potentially
95 // forged headers.
96
97 if (!(requiredValue.equals(headerValue))) return null;
98 }
99 catch (Exception e)
100 {
101 log(e.toString());
102 return null; //if we get an exception, don't validate the mark
103 }
104
105 // If we get here, all headers are present and match.
106 return mail.getRecipients();
107 }
108
109 /*
110 * Returns information about the matcher, such as author, version, and copyright.
111 * <p>
112 * The string that this method returns should be plain text and not markup
113 * of any kind (such as HTML, XML, etc.).
114 *
115 * @return a String containing matcher information
116 */
117
118 public String getMatcherInfo()
119 {
120 return "Habeas Warrant Mark Matcher (see http://www.habeas.com for details).";
121 }
122 }
123