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: package org.columba.mail.mailchecking;
17:
18: import java.util.Enumeration;
19:
20: import javax.swing.tree.DefaultMutableTreeNode;
21:
22: import org.columba.core.command.CommandProcessor;
23: import org.columba.mail.command.MailFolderCommandReference;
24: import org.columba.mail.config.AccountItem;
25: import org.columba.mail.folder.imap.CheckForNewMessagesCommand;
26: import org.columba.mail.folder.imap.IMAPFolder;
27: import org.columba.mail.folder.imap.IMAPRootFolder;
28: import org.columba.mail.gui.tree.FolderTreeModel;
29:
30: /**
31: * IMAP mail checking item.
32: *
33: * @author fdietz
34: */
35: public class IMAPMailCheckingAction extends AbstractMailCheckingAction {
36: private int accountUid;
37:
38: /**
39: * Constructor
40: *
41: * @param item
42: * account item
43: */
44: public IMAPMailCheckingAction(AccountItem accountItem) {
45: super (accountItem);
46:
47: // account ID
48: accountUid = accountItem.getUid();
49: }
50:
51: /**
52: * @see org.columba.mail.mailchecking.AbstractMailCheckingAction#check()
53: */
54: public void check() {
55: setEnabled(false);
56: IMAPRootFolder imapRootFolder = (IMAPRootFolder) FolderTreeModel
57: .getInstance().getImapFolder(accountUid);
58:
59: Enumeration children = imapRootFolder.breadthFirstEnumeration();
60:
61: while (children.hasMoreElements()) {
62: DefaultMutableTreeNode child = (DefaultMutableTreeNode) children
63: .nextElement();
64: if (child instanceof IMAPFolder) {
65: IMAPFolder folder = (IMAPFolder) child;
66:
67: if (folder.getName().equalsIgnoreCase("INBOX")
68: || folder.getConfiguration()
69: .getBooleanWithDefault("activeSync",
70: false)) {
71: MailFolderCommandReference r = new MailFolderCommandReference(
72: folder);
73: CommandProcessor.getInstance().addOp(
74: new CheckForNewMessagesCommand(this , r));
75: }
76: }
77:
78: }
79:
80: }
81:
82: /**
83: * @see org.columba.mail.mailchecking.AbstractMailCheckingAction#isCheckAll()
84: */
85: public boolean isCheckAll() {
86: IMAPRootFolder imapRootFolder = (IMAPRootFolder) FolderTreeModel
87: .getInstance().getImapFolder(accountUid);
88: return !imapRootFolder.getAccountItem().getImapItem()
89: .getBooleanWithDefault("exclude_from_checkall", false);
90: }
91: }
|