001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.transport.matchers;
019:
020: import org.apache.mailet.GenericMatcher;
021: import org.apache.mailet.Mail;
022:
023: import javax.mail.MessagingException;
024: import javax.mail.internet.MimeMessage;
025: import java.util.Collection;
026:
027: /*
028: * This matcher tests for the Hebeas Warrant Mark.
029: * For details see: http://www.hebeas.com
030: *
031: * Usage: Place this matcher
032: *
033: * <mailet match="HasHabeasWarrantMark" class="ToProcessor">
034: * <processor> transport </processor>
035: * </mailet>
036: *
037: * in the root processs before the DNSRBL block lists (the InSpammerBlacklist matcher).
038: *
039: * Because the Habeas Warrant Mark is copyright material, I have asked for and
040: * received the following explicit statement from Habeas:
041: *
042: * -----------------------------------
043: * From: Lindsey Pettit [mailto:support@habeas.com]
044: * Sent: Sunday, September 29, 2002 5:51
045: * To: Noel J. Bergman
046: * Subject: RE: Habeas and Apache James
047: *
048: * Dear Noel,
049: *
050: * > I guess that since your Warrant Mark is copyright, I should ask for
051: * > something from you to explicitly authorize that Hebeas will permit
052: * > this code to be included and distributed as part of Apache James
053: * > under the Apache Software License. As we have established, the use
054: * > of the Habeas Warrant Mark for filtering is not restricted, but I
055: * > would like something to confirm that, so that Apache will be happy.
056: *
057: * I can hereby confirm to you that there is no license necessary in
058: * order to use the Habeas mark for filtering. That said, however, we
059: * do insist that it not ever be used as a basis for rejecting email which
060: * bears the Habeas mark.
061: * -----------------------------------
062: *
063: */
064:
065: public class HasHabeasWarrantMark extends GenericMatcher {
066: public static final String[][] warrantMark = {
067: { "X-Habeas-SWE-1", "winter into spring" },
068: { "X-Habeas-SWE-2", "brightly anticipated" },
069: { "X-Habeas-SWE-3", "like Habeas SWE (tm)" },
070: { "X-Habeas-SWE-4", "Copyright 2002 Habeas (tm)" },
071: { "X-Habeas-SWE-5",
072: "Sender Warranted Email (SWE) (tm). The sender of this" },
073: { "X-Habeas-SWE-6",
074: "email in exchange for a license for this Habeas" },
075: { "X-Habeas-SWE-7",
076: "warrant mark warrants that this is a Habeas Compliant" },
077: { "X-Habeas-SWE-8",
078: "Message (HCM) and not spam. Please report use of this" },
079: { "X-Habeas-SWE-9",
080: "mark in spam to <http://www.habeas.com/report/>." }, };
081:
082: public Collection match(Mail mail) throws MessagingException {
083: MimeMessage message = mail.getMessage();
084:
085: //Loop through all the patterns
086: for (int i = 0; i < warrantMark.length; i++)
087: try {
088: String headerName = warrantMark[i][0]; //Get the header name
089: String requiredValue = warrantMark[i][1]; //Get the required value
090: String headerValue = message
091: .getHeader(headerName, null); //Get the header value(s)
092:
093: // We want an exact match, so only test the first value.
094: // If there are multiple values, the header may be
095: // (illegally) forged. I'll leave it as an exercise to
096: // others if they want to detect and report potentially
097: // forged headers.
098:
099: if (!(requiredValue.equals(headerValue)))
100: return null;
101: } catch (Exception e) {
102: log(e.toString());
103: return null; //if we get an exception, don't validate the mark
104: }
105:
106: // If we get here, all headers are present and match.
107: return mail.getRecipients();
108: }
109:
110: /*
111: * Returns information about the matcher, such as author, version, and copyright.
112: * <p>
113: * The string that this method returns should be plain text and not markup
114: * of any kind (such as HTML, XML, etc.).
115: *
116: * @return a String containing matcher information
117: */
118:
119: public String getMatcherInfo() {
120: return "Habeas Warrant Mark Matcher (see http://www.habeas.com for details).";
121: }
122: }
|