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.filter.plugins;
19:
20: import org.columba.core.filter.AbstractFilter;
21: import org.columba.core.filter.FilterCriteria;
22: import org.columba.core.filter.IFilterCriteria;
23: import org.columba.core.folder.api.IFolder;
24: import org.columba.mail.folder.IMailbox;
25: import org.columba.ristretto.message.Flags;
26:
27: /**
28: * Search for a certain flag state.
29: * <p>
30: * Example: Message is read/unread, Marked as Spam/Not Spam
31: *
32: * @author fdietz
33: */
34: public class FlagsFilter extends AbstractFilter {
35:
36: private String pattern;
37:
38: private int condition;
39:
40: /**
41: * Constructor for FlagsFilter.
42: */
43: public FlagsFilter() {
44: super ();
45: }
46:
47: /**
48: * @see org.columba.core.filter.AbstractFilter#process(java.lang.Object,
49: * org.columba.mail.folder.Folder, java.lang.Object,
50: * org.columba.api.command.IWorkerStatusController)
51: */
52: public boolean process(IFolder folder, Object uid) throws Exception {
53: boolean result = false;
54:
55: String headerField = pattern;
56:
57: Flags flags = ((IMailbox) folder).getFlags(uid);
58:
59: if (headerField.equalsIgnoreCase("Answered")) {
60: result = flags.get(Flags.ANSWERED);
61: } else if (headerField.equalsIgnoreCase("Deleted")) {
62: result = flags.get(Flags.DELETED);
63: } else if (headerField.equalsIgnoreCase("Flagged")) {
64: result = flags.get(Flags.FLAGGED);
65: } else if (headerField.equalsIgnoreCase("Recent")) {
66: result = flags.get(Flags.RECENT);
67: } else if (headerField.equalsIgnoreCase("Draft")) {
68: result = flags.get(Flags.DRAFT);
69: } else if (headerField.equalsIgnoreCase("Seen")) {
70: result = flags.get(Flags.SEEN);
71: } else if (headerField.equalsIgnoreCase("Spam")) {
72: result = ((Boolean) ((IMailbox) folder).getAttribute(uid,
73: "columba.spam")).booleanValue();
74: }
75:
76: if (condition == FilterCriteria.IS) {
77: return result;
78: } else {
79: return !result;
80: }
81: }
82:
83: /**
84: * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
85: */
86: public void setUp(IFilterCriteria f) {
87:
88: // string to search
89: pattern = f.getPatternString();
90:
91: condition = f.getCriteria();
92: }
93: }
|