001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo
013: // Stich.
014: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
015: //
016: //All Rights Reserved.
017:
018: package org.columba.mail.spam;
019:
020: import java.util.logging.Logger;
021:
022: import org.columba.api.plugin.IExtension;
023: import org.columba.api.plugin.IExtensionHandler;
024: import org.columba.api.plugin.PluginException;
025: import org.columba.api.plugin.PluginHandlerNotFoundException;
026: import org.columba.core.logging.Logging;
027: import org.columba.core.plugin.PluginManager;
028: import org.columba.mail.folder.IMailbox;
029: import org.columba.mail.plugin.IExtensionHandlerKeys;
030:
031: /**
032: * High-level wrapper for the spam filter.
033: * <p>
034: * Class should be used by Columba, to add ham or spam messages to the training
035: * database. And to score messages using this training set.
036: * <p>
037: *
038: * @author fdietz
039: */
040: public class SpamController implements ISpamPlugin {
041:
042: /** JDK 1.4+ logging framework logger, used for logging. */
043: private static final Logger LOG = Logger
044: .getLogger("org.columba.core.gui.htmlviewer");
045:
046: /**
047: * singleton pattern instance of this class
048: */
049: private static SpamController instance;
050:
051: private ISpamPlugin spamPlugin;
052:
053: /**
054: * private constructor
055: */
056: private SpamController() {
057:
058: try {
059: IExtensionHandler handler = PluginManager
060: .getInstance()
061: .getExtensionHandler(
062: IExtensionHandlerKeys.ORG_COLUMBA_MAIL_SPAM);
063:
064: IExtension extension = handler.getExtension("SpamAssassin");
065:
066: spamPlugin = (ISpamPlugin) extension
067: .instanciateExtension(null);
068:
069: } catch (PluginHandlerNotFoundException e) {
070: LOG.severe(e.getMessage());
071: if (Logging.DEBUG)
072: e.printStackTrace();
073:
074: } catch (PluginException e) {
075: LOG.severe(e.getMessage());
076: if (Logging.DEBUG)
077: e.printStackTrace();
078: }
079: }
080:
081: /**
082: * Get instance of class.
083: *
084: * @return spam controller
085: */
086: public static SpamController getInstance() {
087: if (instance == null)
088: instance = new SpamController();
089:
090: return instance;
091: }
092:
093: public boolean scoreMessage(IMailbox mailbox, Object uid)
094: throws Exception {
095:
096: return spamPlugin.scoreMessage(mailbox, uid);
097: }
098:
099: public void trainMessageAsSpam(IMailbox mailbox, Object uid)
100: throws Exception {
101: spamPlugin.trainMessageAsSpam(mailbox, uid);
102: }
103:
104: public void trainMessageAsHam(IMailbox mailbox, Object uid)
105: throws Exception {
106: spamPlugin.trainMessageAsHam(mailbox, uid);
107: }
108:
109: /**
110: * Save frequency DB to file.
111: */
112: public void save() {
113: spamPlugin.save();
114: }
115:
116: public void load() {
117: spamPlugin.load();
118: }
119: }
|