KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > spam > command > LearnMessageAsSpamCommand


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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) throws Exception JavaDoc {
46
47         // get array of source references
48
IMailFolderCommandReference r = (IMailFolderCommandReference) getReference();
49
50         // get array of message UIDs
51
Object JavaDoc[] uids = r.getUids();
52
53         // get source folder
54
IMailbox srcFolder = (IMailbox) r.getSourceFolder();
55
56         // register for status events
57
((StatusObservableImpl) srcFolder.getObservable()).setWorker(worker);
58
59         // update status message
60
if (uids.length > 1) {
61             // TODO (@author fdietz): i18n
62
worker.setDisplayText("Training messages...");
63             worker.setProgressBarMaximum(uids.length);
64         }
65
66         for (int j = 0; j < uids.length; j++) {
67             if (worker.cancelled()) {
68                 break;
69             }
70
71             try {
72
73                 // train message as spam
74
SpamController.getInstance().trainMessageAsSpam(srcFolder,
75                         uids[j]);
76
77                 if (uids.length > 1) {
78                     worker.setProgressBarValue(j);
79                 }
80             } catch (Exception JavaDoc e) {
81                 if (Logging.DEBUG) {
82                     e.printStackTrace();
83                 }
84             }
85         }
86
87     }
88 }
Popular Tags