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 spam.
30: *
31: * @author fdietz
32: */
33: public class LearnMessageAsSpamCommand extends Command {
34:
35: /**
36: * @param references
37: */
38: public LearnMessageAsSpamCommand(ICommandReference reference) {
39: super (reference);
40: }
41:
42: /**
43: * @see org.columba.api.command.Command#execute(org.columba.api.command.Worker)
44: */
45: public void execute(IWorkerStatusController worker)
46: throws Exception {
47:
48: // get array of source references
49: IMailFolderCommandReference r = (IMailFolderCommandReference) getReference();
50:
51: // get array of message UIDs
52: Object[] uids = r.getUids();
53:
54: // get source folder
55: IMailbox srcFolder = (IMailbox) r.getSourceFolder();
56:
57: // register for status events
58: ((StatusObservableImpl) srcFolder.getObservable())
59: .setWorker(worker);
60:
61: // update status message
62: if (uids.length > 1) {
63: // TODO (@author fdietz): i18n
64: worker.setDisplayText("Training messages...");
65: worker.setProgressBarMaximum(uids.length);
66: }
67:
68: for (int j = 0; j < uids.length; j++) {
69: if (worker.cancelled()) {
70: break;
71: }
72:
73: try {
74:
75: // train message as spam
76: SpamController.getInstance().trainMessageAsSpam(
77: srcFolder, uids[j]);
78:
79: if (uids.length > 1) {
80: worker.setProgressBarValue(j);
81: }
82: } catch (Exception e) {
83: if (Logging.DEBUG) {
84: e.printStackTrace();
85: }
86: }
87: }
88:
89: }
90: }
|