01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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;
21: import java.io.UnsupportedEncodingException;
22: import java.util.Enumeration;
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 {
32:
33: private static final String 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(FILTER_XML
41: .getBytes("UTF-8")));
42:
43: RECENT_FILTER = new Filter(io.getRoot().getElement(0));
44: } catch (UnsupportedEncodingException e) {
45: // TODO Auto-generated catch block
46: e.printStackTrace();
47: }
48:
49: }
50:
51: public void run() {
52: IMailFolder rootFolder = (IMailFolder) FolderTreeModel
53: .getInstance().getRoot();
54: clearRecent(rootFolder);
55: }
56:
57: protected void clearRecent(IMailFolder parentFolder) {
58: IMailFolder child;
59:
60: for (Enumeration e = parentFolder.children(); e
61: .hasMoreElements();) {
62: child = (IMailFolder) e.nextElement();
63:
64: if (child instanceof AbstractMessageFolder) {
65: AbstractMessageFolder folder = (AbstractMessageFolder) child;
66: if (folder.getMessageFolderInfo().getRecent() > 0) {
67:
68: try {
69: Object uids[] = folder
70: .searchMessages(RECENT_FILTER);
71: folder.markMessage(uids,
72: MarkMessageCommand.MARK_AS_NOTRECENT);
73:
74: folder.save();
75: } catch (Exception e1) {
76: }
77: }
78: }
79: clearRecent(child);
80: }
81: }
82:
83: }
|