View Javadoc

1   /*****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.james.transport.matchers;
21  
22  import org.apache.mailet.GenericMatcher;
23  import org.apache.mailet.Mail;
24  
25  import javax.mail.MessagingException;
26  import javax.mail.internet.MimeMessage;
27  import java.util.Collection;
28  
29  /*
30   * This matcher tests for the Hebeas Warrant Mark.
31   * For details see: http://www.hebeas.com
32   *
33   * Usage: Place this matcher
34   *
35   * <mailet match="HasHabeasWarrantMark" class="ToProcessor">
36   *     <processor> transport </processor>
37   * </mailet>
38   *
39   * in the root processs before the DNSRBL block lists (the InSpammerBlacklist matcher).
40   *
41   * Because the Habeas Warrant Mark is copyright material, I have asked for and
42   * received the following explicit statement from Habeas:
43   *
44   * -----------------------------------
45   * From: Lindsey Pettit [mailto:support@habeas.com]
46   * Sent: Sunday, September 29, 2002 5:51
47   * To: Noel J. Bergman
48   * Subject: RE: Habeas and Apache James
49   *
50   * Dear Noel,
51   * 
52   * > I guess that since your Warrant Mark is copyright, I should ask for
53   * > something from you to explicitly authorize that Hebeas will permit
54   * > this code to be included and distributed as part of Apache James
55   * > under the Apache Software License.  As we have established, the use
56   * > of the Habeas Warrant Mark for filtering is not restricted, but I
57   * > would like something to confirm that, so that Apache will be happy.
58   *
59   * I can hereby confirm to you that there is no license necessary in 
60   * order to use the Habeas mark for filtering.  That said, however, we 
61   * do insist that it not ever be used as a basis for rejecting email which 
62   * bears the Habeas mark.
63   * -----------------------------------
64   *
65   */
66  
67  public class HasHabeasWarrantMark extends GenericMatcher
68  {
69      public static final String[][] warrantMark =
70      {
71          { "X-Habeas-SWE-1", "winter into spring" }, 
72          { "X-Habeas-SWE-2", "brightly anticipated" }, 
73          { "X-Habeas-SWE-3", "like Habeas SWE (tm)" }, 
74          { "X-Habeas-SWE-4", "Copyright 2002 Habeas (tm)" }, 
75          { "X-Habeas-SWE-5", "Sender Warranted Email (SWE) (tm). The sender of this" }, 
76          { "X-Habeas-SWE-6", "email in exchange for a license for this Habeas" }, 
77          { "X-Habeas-SWE-7", "warrant mark warrants that this is a Habeas Compliant" }, 
78          { "X-Habeas-SWE-8", "Message (HCM) and not spam. Please report use of this" }, 
79          { "X-Habeas-SWE-9", "mark in spam to <http://www.habeas.com/report/>." }, 
80      };
81  
82      public Collection match(Mail mail) throws MessagingException
83      {
84          MimeMessage message = mail.getMessage();
85  
86          //Loop through all the patterns
87          for (int i = 0; i < warrantMark.length; i++) try
88          {
89              String headerName = warrantMark[i][0];                      //Get the header name
90              String requiredValue = warrantMark[i][1];                   //Get the required value
91              String headerValue = message.getHeader(headerName, null);   //Get the header value(s)
92  
93              // We want an exact match, so only test the first value.
94              // If there are multiple values, the header may be
95              // (illegally) forged.  I'll leave it as an exercise to
96              // others if they want to detect and report potentially
97              // forged headers.
98  
99              if (!(requiredValue.equals(headerValue))) return null;
100         }
101         catch (Exception e)
102         {
103             log(e.toString());
104             return null;            //if we get an exception, don't validate the mark
105         }
106 
107         // If we get here, all headers are present and match.
108         return mail.getRecipients();
109     }
110 
111     /*
112      * Returns information about the matcher, such as author, version, and copyright.
113      * <p>
114      * The string that this method returns should be plain text and not markup
115      * of any kind (such as HTML, XML, etc.).
116      *
117      * @return a String containing matcher information
118      */
119 
120     public String getMatcherInfo()
121     {
122         return "Habeas Warrant Mark Matcher (see http://www.habeas.com for details).";
123     }
124 }
125