01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16:
17: package org.columba.mail.spam.command;
18:
19: import org.columba.api.command.ICommandReference;
20: import org.columba.api.command.IWorkerStatusController;
21: import org.columba.core.command.Command;
22: import org.columba.core.command.StatusObservableImpl;
23: import org.columba.core.logging.Logging;
24: import org.columba.mail.command.IMailFolderCommandReference;
25: import org.columba.mail.folder.IMailbox;
26: import org.columba.mail.spam.SpamController;
27:
28: /**
29: * Learn selected messages as ham.
30: *
31: * @author fdietz
32: */
33: public class LearnMessageAsHamCommand extends Command {
34:
35: private static final java.util.logging.Logger LOG = java.util.logging.Logger
36: .getLogger("org.columba.mail.spam.command"); //$NON-NLS-1$
37:
38: /**
39: * @param references
40: */
41: public LearnMessageAsHamCommand(ICommandReference reference) {
42: super (reference);
43: }
44:
45: /**
46: * @see org.columba.api.command.Command#execute(org.columba.api.command.Worker)
47: */
48: public void execute(IWorkerStatusController worker)
49: throws Exception {
50:
51: // get array of source references
52: IMailFolderCommandReference r = (IMailFolderCommandReference) getReference();
53:
54: // get array of message UIDs
55: Object[] uids = r.getUids();
56:
57: // get source folder
58: IMailbox srcFolder = (IMailbox) r.getSourceFolder();
59:
60: // register for status events
61: ((StatusObservableImpl) srcFolder.getObservable())
62: .setWorker(worker);
63:
64: // update status message
65: if (uids.length > 1) {
66: // TODO (@author fdietz): i18n
67: worker.setDisplayText("Training messages...");
68: worker.setProgressBarMaximum(uids.length);
69: }
70:
71: long startTime = System.currentTimeMillis();
72:
73: for (int j = 0; j < uids.length; j++) {
74: if (worker.cancelled()) {
75: break;
76: }
77:
78: try {
79:
80: // train message as ham
81: SpamController.getInstance().trainMessageAsHam(
82: srcFolder, uids[j]);
83:
84: if (uids.length > 1) {
85: worker.setProgressBarValue(j);
86: }
87: } catch (Exception e) {
88: if (Logging.DEBUG) {
89: e.printStackTrace();
90: }
91: }
92: }
93:
94: long endTime = System.currentTimeMillis();
95:
96: LOG.info("took me=" + (endTime - startTime) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
97:
98: }
99: }
|