KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > mailchecking > IMAPMailCheckingAction


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
package org.columba.mail.mailchecking;
17
18 import java.util.Enumeration JavaDoc;
19
20 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
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.getInstance()
57                 .getImapFolder(accountUid);
58         
59         Enumeration JavaDoc children = imapRootFolder.breadthFirstEnumeration();
60         
61         while( children.hasMoreElements()) {
62             DefaultMutableTreeNode JavaDoc child = (DefaultMutableTreeNode JavaDoc)children.nextElement();
63             if( child instanceof IMAPFolder ) {
64                 IMAPFolder folder = (IMAPFolder) child;
65                 
66                 if( folder.getName().equalsIgnoreCase("INBOX") || folder.getConfiguration().getBooleanWithDefault("activeSync", false)) {
67                     MailFolderCommandReference r = new MailFolderCommandReference(folder);
68                     CommandProcessor.getInstance().addOp(new CheckForNewMessagesCommand(this, r));
69                 }
70             }
71             
72         }
73
74     }
75
76     /**
77      * @see org.columba.mail.mailchecking.AbstractMailCheckingAction#isCheckAll()
78      */

79     public boolean isCheckAll() {
80         IMAPRootFolder imapRootFolder = (IMAPRootFolder) FolderTreeModel.getInstance()
81                 .getImapFolder(accountUid);
82         return !imapRootFolder.getAccountItem().getImapItem().getBooleanWithDefault(
83                 "exclude_from_checkall", false);
84     }
85 }
Popular Tags