KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > shutdown > ClearRecentFlagPlugin


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.shutdown;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.io.UnsupportedEncodingException JavaDoc;
22 import java.util.Enumeration JavaDoc;
23
24 import org.columba.core.filter.Filter;
25 import org.columba.core.xml.XmlIO;
26 import org.columba.mail.folder.AbstractMessageFolder;
27 import org.columba.mail.folder.IMailFolder;
28 import org.columba.mail.folder.command.MarkMessageCommand;
29 import org.columba.mail.gui.tree.FolderTreeModel;
30
31 public class ClearRecentFlagPlugin implements Runnable JavaDoc {
32
33     private static final String JavaDoc FILTER_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><filter enabled=\"true\"><rules condition=\"matchall\"><criteria criteria=\"is\" type=\"Flags\" pattern=\"Recent\"></criteria></rules></filter>";
34
35     private static Filter RECENT_FILTER;
36
37     static {
38         try {
39             XmlIO io = new XmlIO();
40             io.load(new ByteArrayInputStream JavaDoc(FILTER_XML.getBytes("UTF-8")));
41
42             RECENT_FILTER = new Filter(io.getRoot().getElement(0));
43         } catch (UnsupportedEncodingException JavaDoc e) {
44             // TODO Auto-generated catch block
45
e.printStackTrace();
46         }
47
48     }
49
50     public void run() {
51         IMailFolder rootFolder = (IMailFolder) FolderTreeModel.getInstance()
52                 .getRoot();
53         clearRecent(rootFolder);
54     }
55
56     protected void clearRecent(IMailFolder parentFolder) {
57         IMailFolder child;
58
59         for (Enumeration JavaDoc e = parentFolder.children(); e.hasMoreElements();) {
60             child = (IMailFolder) e.nextElement();
61
62             if (child instanceof AbstractMessageFolder) {
63                 AbstractMessageFolder folder = (AbstractMessageFolder) child;
64                 if (folder.getMessageFolderInfo().getRecent() > 0) {
65
66                     try {
67                         Object JavaDoc uids[] = folder.searchMessages(RECENT_FILTER);
68                         folder.markMessage(uids,
69                                 MarkMessageCommand.MARK_AS_NOTRECENT);
70
71                         folder.save();
72                     } catch (Exception JavaDoc e1) {
73                     }
74                 }
75             }
76             clearRecent(child);
77         }
78     }
79
80 }
81
Popular Tags