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
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
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
87 for (int i = 0; i < warrantMark.length; i++) try
88 {
89 String headerName = warrantMark[i][0];
90 String requiredValue = warrantMark[i][1];
91 String headerValue = message.getHeader(headerName, null);
92
93
94
95
96
97
98
99 if (!(requiredValue.equals(headerValue))) return null;
100 }
101 catch (Exception e)
102 {
103 log(e.toString());
104 return null;
105 }
106
107
108 return mail.getRecipients();
109 }
110
111
112
113
114
115
116
117
118
119
120 public String getMatcherInfo()
121 {
122 return "Habeas Warrant Mark Matcher (see http://www.habeas.com for details).";
123 }
124 }
125