KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jsmtpd > plugins > filters > SA > SAFilter


1 /*
2  *
3  * Jsmtpd, Java SMTP daemon
4  * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  */

21 package org.jsmtpd.plugins.filters.SA;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.jsmtpd.core.common.PluginInitException;
26 import org.jsmtpd.core.common.filter.IFilter;
27 import org.jsmtpd.core.mail.Email;
28
29 /**
30  * SpamAssassin Filter for Jsmtpd
31  * <br>
32  *
33  * The SA filter will always return true, as long
34  * as it only modifies the Email message (the body
35  * of the mail).
36  *
37  * @author Jean-Francois POUX
38  */

39 public class SAFilter implements IFilter {
40
41     private String JavaDoc spamdHost;
42     private int spamdPort;
43     private Log log = LogFactory.getLog(SAFilter.class);
44     private int socketTimeout = 0;
45     private int skipIfSizeMore = -1;
46
47     /* (non-Javadoc)
48      * @see jsmtpd.common.filter.IFilter#doFilter(jsmtpd.mail.Email)
49      */

50     public boolean doFilter(Email input) {
51
52         //most spam are small, if a mail exceed this size, it will pass throught directly as true response
53
if (skipIfSizeMore != -1) {
54             if (input.getSize() > skipIfSizeMore) {
55                 log.info("Mail " + input.getDiskName() + " skipped filter, it's size exceds the treshold set");
56                 return true;
57             }
58         }
59         SAChat chat = new SAChat(spamdHost, spamdPort, socketTimeout);
60         return (chat.checkMail(input));
61
62     }
63
64     /* (non-Javadoc)
65      * @see jsmtpd.common.IGenericPlugin#getPluginName()
66      */

67     public String JavaDoc getPluginName() {
68         return "Jsmtpd-SA SpamAssassin filter";
69     }
70
71     /* (non-Javadoc)
72      * @see jsmtpd.common.IGenericPlugin#initPlugin()
73      */

74     public void initPlugin() throws PluginInitException {
75         log.debug(getPluginName() + " initialized");
76     }
77
78     /* (non-Javadoc)
79      * @see jsmtpd.common.IGenericPlugin#shutdownPlugin()
80      */

81     public void shutdownPlugin() {
82     }
83
84     //Methods for plugin loader
85

86     public void setSpamdHost(String JavaDoc hostname) {
87         spamdHost = hostname;
88     }
89
90     public void setSpamdPort(int port) {
91         spamdPort = port;
92     }
93
94     public void setSocketTimeout(int time) {
95         socketTimeout = time;
96     }
97
98     public void setSkipIfSizeMore(int skipIfSizeMore) {
99         this.skipIfSizeMore = skipIfSizeMore;
100     }
101 }
Popular Tags