01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
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: ****************************************************************/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 java.net.InetAddress;
25: import java.net.UnknownHostException;
26: import java.util.Collection;
27: import java.util.StringTokenizer;
28:
29: /**
30: * Checks the network IP address of the sending server against a
31: * blacklist of spammers. There are 3 lists that support this...
32: * <ul>
33: * <li><b>blackholes.mail-abuse.org</b>: Rejected - see http://www.mail-abuse.org/rbl/
34: * <li><b>dialups.mail-abuse.org</b>: Dialup - see http://www.mail-abuse.org/dul/
35: * <li><b>relays.mail-abuse.org</b>: Open spam relay - see http://www.mail-abuse.org/rss/
36: * </ul>
37: *
38: * Example:
39: * <mailet match="InSpammerBlacklist=blackholes.mail-abuse.org" class="ToProcessor">
40: * <processor>spam</processor>
41: * </mailet>
42: *
43: */
44: public class InSpammerBlacklist extends GenericMatcher {
45: String network = null;
46:
47: public void init() throws MessagingException {
48: network = getCondition();
49: }
50:
51: public Collection match(Mail mail) {
52: String host = mail.getRemoteAddr();
53: try {
54: //Have to reverse the octets first
55: StringBuffer sb = new StringBuffer();
56: StringTokenizer st = new StringTokenizer(host, " .", false);
57:
58: while (st.hasMoreTokens()) {
59: sb.insert(0, st.nextToken() + ".");
60: }
61:
62: //Add the network prefix for this blacklist
63: sb.append(network);
64:
65: //Try to look it up
66: org.apache.james.dnsserver.DNSServer.getByName(sb
67: .toString());
68:
69: //If we got here, that's bad... it means the host
70: // was found in the blacklist
71: return mail.getRecipients();
72: } catch (UnknownHostException uhe) {
73: //This is good... it's not on the list
74: return null;
75: }
76: }
77: }
|