001: /*
002: *
003: * Jsmtpd, Java SMTP daemon
004: * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021: package org.jsmtpd.plugins.filters.SA;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.jsmtpd.core.common.PluginInitException;
026: import org.jsmtpd.core.common.filter.IFilter;
027: import org.jsmtpd.core.mail.Email;
028:
029: /**
030: * SpamAssassin Filter for Jsmtpd
031: * <br>
032: *
033: * The SA filter will always return true, as long
034: * as it only modifies the Email message (the body
035: * of the mail).
036: *
037: * @author Jean-Francois POUX
038: */
039: public class SAFilter implements IFilter {
040:
041: private String spamdHost;
042: private int spamdPort;
043: private Log log = LogFactory.getLog(SAFilter.class);
044: private int socketTimeout = 0;
045: private int skipIfSizeMore = -1;
046:
047: /* (non-Javadoc)
048: * @see jsmtpd.common.filter.IFilter#doFilter(jsmtpd.mail.Email)
049: */
050: public boolean doFilter(Email input) {
051:
052: //most spam are small, if a mail exceed this size, it will pass throught directly as true response
053: if (skipIfSizeMore != -1) {
054: if (input.getSize() > skipIfSizeMore) {
055: log
056: .info("Mail "
057: + input.getDiskName()
058: + " skipped filter, it's size exceds the treshold set");
059: return true;
060: }
061: }
062: SAChat chat = new SAChat(spamdHost, spamdPort, socketTimeout);
063: return (chat.checkMail(input));
064:
065: }
066:
067: /* (non-Javadoc)
068: * @see jsmtpd.common.IGenericPlugin#getPluginName()
069: */
070: public String getPluginName() {
071: return "Jsmtpd-SA SpamAssassin filter";
072: }
073:
074: /* (non-Javadoc)
075: * @see jsmtpd.common.IGenericPlugin#initPlugin()
076: */
077: public void initPlugin() throws PluginInitException {
078: log.debug(getPluginName() + " initialized");
079: }
080:
081: /* (non-Javadoc)
082: * @see jsmtpd.common.IGenericPlugin#shutdownPlugin()
083: */
084: public void shutdownPlugin() {
085: }
086:
087: //Methods for plugin loader
088:
089: public void setSpamdHost(String hostname) {
090: spamdHost = hostname;
091: }
092:
093: public void setSpamdPort(int port) {
094: spamdPort = port;
095: }
096:
097: public void setSocketTimeout(int time) {
098: socketTimeout = time;
099: }
100:
101: public void setSkipIfSizeMore(int skipIfSizeMore) {
102: this.skipIfSizeMore = skipIfSizeMore;
103: }
104: }
|