01: package org.columba.mail.folder.imap;
02:
03: import org.columba.api.command.ICommandReference;
04: import org.columba.api.command.IWorkerStatusController;
05: import org.columba.core.command.Command;
06: import org.columba.core.command.CommandProcessor;
07: import org.columba.mail.command.IMailFolderCommandReference;
08: import org.columba.mail.command.MailFolderCommandReference;
09:
10: public class FetchMessagesCommand extends Command {
11:
12: private int newMessages;
13: private int fetchedMessages;
14: private int offset;
15:
16: public FetchMessagesCommand(ICommandReference reference,
17: int newMessages, int offset, int fetchedMessages) {
18: super (reference);
19:
20: this .newMessages = newMessages;
21: this .fetchedMessages = fetchedMessages;
22: this .offset = offset;
23: }
24:
25: public void execute(IWorkerStatusController worker)
26: throws Exception {
27: // get references
28: IMailFolderCommandReference r = (IMailFolderCommandReference) getReference();
29:
30: IMAPFolder imapFolder = (IMAPFolder) r.getSourceFolder();
31:
32: worker.setProgressBarMaximum(newMessages);
33: worker.setProgressBarValue(fetchedMessages);
34:
35: int fetched = imapFolder.fetchNewMessages(
36: offset + fetchedMessages).size();
37:
38: fetchedMessages += fetched;
39: worker.setProgressBarValue(fetchedMessages);
40:
41: if (worker.cancelled()) {
42: return;
43: }
44:
45: if (fetched > 0 && fetchedMessages < newMessages) {
46: CommandProcessor.getInstance().addOp(
47: new FetchMessagesCommand(
48: new MailFolderCommandReference(imapFolder),
49: newMessages, offset, fetchedMessages));
50: } else {
51: // Trigger any pending Flag syncs
52: imapFolder.fetchDone();
53:
54: }
55: }
56:
57: }
|