Author: norman
Date: Sun Aug 27 11:59:27 2006
New Revision: 437436
URL: http://svn.apache.org/viewvc?rev=437436&view=rev
Log:
Add methods to add ham/spam via mboxfile to BayesianAnalyzerManagement and
RemoteManager. See JAMES-590
Added:
james/server/trunk/lib/LICENSE.commons-logging
james/server/trunk/lib/LICENSE.jdom
james/server/trunk/lib/LICENSE.xstream
james/server/trunk/lib/commons-logging.jar (with props)
james/server/trunk/lib/jdom.jar (with props)
james/server/trunk/lib/mstor.LICENSE
james/server/trunk/lib/mstor.jar (with props)
james/server/trunk/lib/xstream.jar (with props)
Modified:
james/server/trunk/build.xml
james/server/trunk/include.properties
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
Modified: james/server/trunk/build.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/build.xml?rev=437436&r1=437435&r2=437436&view=diff
==============================================================================
--- james/server/trunk/build.xml (original)
+++ james/server/trunk/build.xml Sun Aug 27 11:59:27 2006
@@ -85,6 +85,10 @@
<include name="${bcmail.jar}"/>
<include name="${bcmail-workaround.jar}"/>
<include name="${jspf.jar}"/>
+ <include name="${mstor.jar}"/>
+ <include name="${commons-logging.jar}"/>
+ <include name="${jdom.jar}"/>
+ <include name="${xstream.jar}"/>
</fileset>
<pathelement path="${java.class.path}" />
<pathelement path="${build.classes}" />
@@ -510,6 +514,10 @@
<include name="${cornerstone-datasources-impl.jar}"/>
<include name="${concurrent.jar}"/>
<include name="${jspf.jar}"/>
+ <include name="${mstor.jar}"/>
+ <include name="${commons-logging.jar}"/>
+ <include name="${jdom.jar}"/>
+ <include name="${xstream.jar}"/>
</lib>
<zipfileset dir="${conf.dir}" fullpath="conf/sqlResources.xml">
<include name="sqlResources.xml"/>
Modified: james/server/trunk/include.properties
URL:
http://svn.apache.org/viewvc/james/server/trunk/include.properties?rev=437436&r1=437435&r2=437436&view=diff
==============================================================================
--- james/server/trunk/include.properties (original)
+++ james/server/trunk/include.properties Sun Aug 27 11:59:27 2006
@@ -90,4 +90,10 @@
# ----- jSPF -----
jspf.jar=jspf-0.9b2.jar
+# ----- mstor -----
+mstor.jar=mstor.jar
+commons-logging.jar=commons-logging.jar
+jdom.jar=jdom.jar
+xstream.jar=xstream.jar
+
Added: james/server/trunk/lib/LICENSE.commons-logging
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/LICENSE.commons-logging?rev=437436&view=auto
==============================================================================
--- james/server/trunk/lib/LICENSE.commons-logging (added)
+++ james/server/trunk/lib/LICENSE.commons-logging Sun Aug 27 11:59:27 2006
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
Added: james/server/trunk/lib/LICENSE.jdom
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/LICENSE.jdom?rev=437436&view=auto
==============================================================================
--- james/server/trunk/lib/LICENSE.jdom (added)
+++ james/server/trunk/lib/LICENSE.jdom Sun Aug 27 11:59:27 2006
@@ -0,0 +1,56 @@
+/*--
+
+ $Id: LICENSE.txt,v 1.11 2004/02/06 09:32:57 jhunter Exp $
+
+ Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions, and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the disclaimer that follows
+ these conditions in the documentation and/or other materials
+ provided with the distribution.
+
+ 3. The name "JDOM" must not be used to endorse or promote products
+ derived from this software without prior written permission. For
+ written permission, please contact <request_AT_jdom_DOT_org>.
+
+ 4. Products derived from this software may not be called "JDOM", nor
+ may "JDOM" appear in their name, without prior written permission
+ from the JDOM Project Management <request_AT_jdom_DOT_org>.
+
+ In addition, we request (but do not require) that you include in the
+ end-user documentation provided with the redistribution and/or in the
+ software itself an acknowledgement equivalent to the following:
+ "This product includes software developed by the
+ JDOM Project (http://www.jdom.org/)."
+ Alternatively, the acknowledgment may be graphical using the logos
+ available at http://www.jdom.org/images/logos.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ This software consists of voluntary contributions made by many
+ individuals on behalf of the JDOM Project and was originally
+ created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
+ Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
+ on the JDOM Project, please see <http://www.jdom.org/>.
+
+ */
+
Added: james/server/trunk/lib/LICENSE.xstream
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/LICENSE.xstream?rev=437436&view=auto
==============================================================================
--- james/server/trunk/lib/LICENSE.xstream (added)
+++ james/server/trunk/lib/LICENSE.xstream Sun Aug 27 11:59:27 2006
@@ -0,0 +1,27 @@
+(BSD Style License)
+
+Copyright (c) 2003-2004, Joe Walnes
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this
list of
+conditions and the following disclaimer. Redistributions in binary form must
reproduce
+the above copyright notice, this list of conditions and the following
disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+Neither the name of XStream nor the names of its contributors may be used to
endorse
+or promote products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY
+WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
Added: james/server/trunk/lib/commons-logging.jar
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/commons-logging.jar?rev=437436&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/lib/commons-logging.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: james/server/trunk/lib/jdom.jar
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/jdom.jar?rev=437436&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/lib/jdom.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: james/server/trunk/lib/mstor.LICENSE
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/mstor.LICENSE?rev=437436&view=auto
==============================================================================
--- james/server/trunk/lib/mstor.LICENSE (added)
+++ james/server/trunk/lib/mstor.LICENSE Sun Aug 27 11:59:27 2006
@@ -0,0 +1,33 @@
+=================
+ mstor - License
+=================
+
+Copyright (c) 2006, Ben Fortuna
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ o Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+ o Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+ o Neither the name of Ben Fortuna nor the names of any other
contributors
+may be used to endorse or promote products derived from this software
+without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Added: james/server/trunk/lib/mstor.jar
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/mstor.jar?rev=437436&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/lib/mstor.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: james/server/trunk/lib/xstream.jar
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/xstream.jar?rev=437436&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/lib/xstream.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified:
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java?rev=437436&r1=437435&r2=437436&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
(original)
+++
james/server/trunk/src/java/org/apache/james/management/BayesianAnalyzerManagement.java
Sun Aug 27 11:59:27 2006
@@ -27,8 +27,11 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.sql.SQLException;
+import net.fortuna.mstor.data.MboxFile;
+
import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
import org.apache.avalon.excalibur.datasource.DataSourceComponent;
import org.apache.avalon.framework.activity.Initializable;
@@ -42,13 +45,13 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.context.AvalonContextUtilities;
+import org.apache.james.services.BayesianAnalyzerManagementService;
import org.apache.james.util.JDBCBayesianAnalyzer;
/**
* Management for BayesianAnalyzer
*/
-public class BayesianAnalyzerManagement implements
- org.apache.james.services.BayesianAnalyzerManagementService, Serviceable,
Initializable, Contextualizable, Configurable {
+public class BayesianAnalyzerManagement implements
BayesianAnalyzerManagementService, Serviceable, Initializable,
Contextualizable, Configurable {
private final static String HAM = "HAM";
private final static String SPAM = "SPAM";
@@ -123,25 +126,41 @@
}
/**
- * @see
org.apache.james.services.BayesianAnalyzerManagementService#addHam(String)
+ * @see
org.apache.james.services.BayesianAnalyzerManagementService#addHamFromDir(String)
*/
- public int addHam(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException {
+ public int addHamFromDir(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException {
if (repos == null) throw new
BayesianAnalyzerManagementException("RepositoryPath not configured");
- return feedBayesianAnalyzer(dir,HAM);
+ return feedBayesianAnalyzerFromDir(dir,HAM);
}
/**
- * @see
org.apache.james.services.BayesianAnalyzerManagementService#addSpam(String)
+ * @see
org.apache.james.services.BayesianAnalyzerManagementService#addSpamFromDir(String)
*/
- public int addSpam(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException {
+ public int addSpamFromDir(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException {
if (repos == null) throw new
BayesianAnalyzerManagementException("RepositoryPath not configured");
- return feedBayesianAnalyzer(dir,SPAM);
+ return feedBayesianAnalyzerFromDir(dir,SPAM);
+ }
+
+ /**
+ * @see
org.apache.james.services.BayesianAnalyzerManagementService#addHamFromMbox(String)
+ */
+ public int addHamFromMbox(String file) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException {
+ if (repos == null) throw new
BayesianAnalyzerManagementException("RepositoryPath not configured");
+ return feedBayesianAnalyzerFromMbox(file,HAM);
+ }
+
+ /**
+ * @see
org.apache.james.services.BayesianAnalyzerManagementService#addSpamFromMbox(String)
+ */
+ public int addSpamFromMbox(String file) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException {
+ if (repos == null) throw new
BayesianAnalyzerManagementException("RepositoryPath not configured");
+ return feedBayesianAnalyzerFromMbox(file,SPAM);
}
/**
- * Helper method to train the BayesianAnalysis
+ * Helper method to train the BayesianAnalysis from directory which
contain mails
*
* @param dir The directory which contains the emails which should be used
to feed the BayesianAnalysis
* @param type The type to train. HAM or SPAM
@@ -151,7 +170,7 @@
* @throws SQLException
* @throws IllegalArgumentException Get thrown if the directory is not
valid
*/
- private int feedBayesianAnalyzer(String dir, String type) throws
FileNotFoundException, IOException, SQLException, IllegalArgumentException {
+ private int feedBayesianAnalyzerFromDir(String dir, String type) throws
FileNotFoundException, IOException, SQLException, IllegalArgumentException {
//Clear out any existing word/counts etc..
analyzer.clear();
@@ -190,11 +209,58 @@
return count;
}
+
+ /**
+ * Helper method to train the BayesianAnalysis from mbox file
+ *
+ * @param mboxFile The mbox file
+ * @param type The type to train. HAM or SPAM
+ * @return count The count of trained messages
+ * @throws IOException
+ * @throws FileNotFoundException
+ * @throws SQLException
+ * @throws IllegalArgumentException Get thrown if the file is not a valid
mbox file
+ */
+ private int feedBayesianAnalyzerFromMbox(String mboxFile, String type)
throws FileNotFoundException, IOException, SQLException,
IllegalArgumentException {
+ int count = 0;
+
+ //Clear out any existing word/counts etc..
+ analyzer.clear();
+
+ File tmpFile = new File(mboxFile);
+
+ if (MboxFile.isValid(tmpFile) == true ) {
+ MboxFile mbox = new MboxFile(tmpFile,MboxFile.READ_ONLY);
+
+ synchronized(JDBCBayesianAnalyzer.DATABASE_LOCK) {
+ for (int i = 0; i < mbox.getMessageCount(); i++) {
+ if (type.equalsIgnoreCase(HAM)) {
+
+ analyzer.addHam(new BufferedReader(new
InputStreamReader(mbox.getMessageAsStream(i))));
+ count++;
+ } else if (type.equalsIgnoreCase(SPAM)) {
+ analyzer.addSpam(new BufferedReader(new
InputStreamReader(mbox.getMessageAsStream(i))));
+ count++;
+ }
+ }
+
+ //Update storage statistics.
+ if (type.equalsIgnoreCase(HAM)) {
+ analyzer.updateHamTokens(component.getConnection());
+ } else if (type.equalsIgnoreCase(SPAM)) {
+ analyzer.updateSpamTokens(component.getConnection());
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Please provide an valid mbox
file");
+ }
+
+ return count;
+ }
+
private JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer() {
protected void delegatedLog(String logString) {
// no logging
}
- };
-
-
+ };
}
Modified:
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java?rev=437436&r1=437435&r2=437436&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
Sun Aug 27 11:59:27 2006
@@ -576,8 +576,8 @@
out.println("listspool [spoolrepositoryname] list all
mails which reside in the spool and have an error state");
out.println("flushspool [spoolrepositoryname] ([key]) try to
resend the mail assing to the given key. If no key is given all mails get
resend");
out.println("deletespool [spoolrepositoryname] ([key]) delete the
mail assign to the given key. If no key is given all mails get deleted");
- out.println("addham [directory] feed the
BayesianAnalysisFeeder with the content of the directory as HAM. One mail per
file");
- out.println("addspam [directory] feed the
BayesianAnalysisFeeder with the content of the directory as SPAM. One mail per
file");
+ out.println("addham dir/mbox [directory/mbox] feed the
BayesianAnalysisFeeder with the content of the directory or mbox file as HAM");
+ out.println("addspam dir/mbox [directory/mbox] feed the
BayesianAnalysisFeeder with the content of the directory or mbox file as SPAM");
out.println("shutdown kills the
current JVM (convenient when James is run as a daemon)");
out.println("quit close
connection");
out.flush();
@@ -1055,20 +1055,32 @@
*/
private boolean doADDHAM(String argument) {
String exception = null;
-
+ String [] args = null;
+ int count = 0;
+
+ if (argument != null) {
+ args = argument.split(" ");
+ }
+
// check if the command was called correct
- if (argument == null || argument.trim().equals("")) {
- writeLoggedFlushedResponse("Usage: ADDHAM [hamdir]");
+ if (argument == null || argument.trim().equals("") || (args != null &&
args.length != 2)) {
+ writeLoggedFlushedResponse("Usage: ADDHAM DIR/MBOX [dir/mbox]");
return true;
}
try {
// stop watchdog cause feeding can take some time
- theWatchdog.stop();
+ theWatchdog.stop();
- int count =
theConfigData.getBayesianAnalyzerManagement().addHam(argument);
-
+ if (args[0].equalsIgnoreCase("DIR")) {
+ count =
theConfigData.getBayesianAnalyzerManagement().addHamFromDir(args[1]);
+ } else if (args[0].equalsIgnoreCase("MBOX")) {
+ count =
theConfigData.getBayesianAnalyzerManagement().addHamFromMbox(args[1]);
+ } else {
+ writeLoggedFlushedResponse("Usage: ADDHAM DIR/MBOX
[dir/mbox]");
+ return true;
+ }
out.println("Feed the BayesianAnalysis with " + count + " HAM");
out.flush();
@@ -1105,10 +1117,15 @@
*/
private boolean doADDSPAM(String argument) {
String exception = null;
-
+ String [] args = null;
+ int count = 0;
+
+ if (argument != null) {
+ args = argument.split(" ");
+ }
// check if the command was called correct
- if (argument == null || argument.trim().equals("")) {
- writeLoggedFlushedResponse("Usage: ADDSPAM [spamdir]");
+ if (argument == null || argument.trim().equals("") || (args != null &&
args.length != 2)) {
+ writeLoggedFlushedResponse("Usage: ADDSPAM DIR/MBOX [dir/mbox]");
return true;
}
@@ -1117,8 +1134,14 @@
// stop watchdog cause feeding can take some time
theWatchdog.stop();
- int count =
theConfigData.getBayesianAnalyzerManagement().addSpam(argument);
-
+ if (args[0].equalsIgnoreCase("DIR")) {
+ count =
theConfigData.getBayesianAnalyzerManagement().addSpamFromDir(args[1]);
+ } else if (args[0].equalsIgnoreCase("MBOX")) {
+ count =
theConfigData.getBayesianAnalyzerManagement().addSpamFromMbox(args[1]);
+ } else {
+ writeLoggedFlushedResponse("Usage: ADDHAM DIR/MBOX
[dir/mbox]");
+ return true;
+ }
out.println("Feed the BayesianAnalysis with " + count + " SPAM");
out.flush();
Modified:
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java?rev=437436&r1=437435&r2=437436&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
(original)
+++
james/server/trunk/src/java/org/apache/james/services/BayesianAnalyzerManagementService.java
Sun Aug 27 11:59:27 2006
@@ -32,7 +32,7 @@
public static final String ROLE =
"org.apache.james.services.BayesianAnalyzerManagementService";
/**
- * Feed the BayesianAnalyter with spam
+ * Feed the BayesianAnalyter with spam. The given directory contain the
mail files
*
* @param dir The directory in which the spam is located
* @return count The count of added spam
@@ -42,10 +42,10 @@
* @throws SQLException
* @throws BayesianAnalyzerManagementException If the service is not
configured
*/
- public int addSpam(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException;
+ public int addSpamFromDir(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException;
/**
- * Feed the BayesianAnalyzer with ham
+ * Feed the BayesianAnalyzer with ham. The given directory contain the
mail files
*
* @param dir The directory in which the ham is located
* @return count The count of added ham
@@ -55,5 +55,31 @@
* @throws SQLException
* @throws BayesianAnalyzerManagementException If the service is not
configured
*/
- public int addHam(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException;
+ public int addHamFromDir(String dir) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException;
+
+ /**
+ * Feed the BayesianAnalyzer with ham. The given file must be a valid mbox
file
+ *
+ * @param file The mbox file
+ * @return count The count of added ham
+ * @throws FileNotFoundException If the directory not exists
+ * @throws IllegalArgumentException If the provided file is not a valid
mbox file
+ * @throws IOException
+ * @throws SQLException
+ * @throws BayesianAnalyzerManagementException If the service is not
configured
+ */
+ public int addSpamFromMbox(String file) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException;
+
+ /**
+ * Feed the BayesianAnalyzer with ham. The given file must be a valid mbox
file
+ *
+ * @param file The mbox file
+ * @return count The count of added ham
+ * @throws FileNotFoundException If the directory not exists
+ * @throws IllegalArgumentException If the provided file is not a valid
mbox file
+ * @throws IOException
+ * @throws SQLException
+ * @throws BayesianAnalyzerManagementException If the service is not
configured
+ */
+ public int addHamFromMbox(String file) throws FileNotFoundException,
IllegalArgumentException, IOException, SQLException,
BayesianAnalyzerManagementException;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]