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.filter.plugins;
17:
18: import org.columba.core.filter.AbstractFilter;
19: import org.columba.core.filter.FilterCriteria;
20: import org.columba.core.filter.IFilterCriteria;
21: import org.columba.core.folder.api.IFolder;
22: import org.columba.mail.folder.IMailbox;
23:
24: /**
25: * Filter for account's uid.
26: *
27: * @author redsolo
28: */
29: public class AccountFilter extends AbstractFilter {
30: int criteriaCondition;
31:
32: int criteriaAccountUid;
33:
34: /**
35: * @param f
36: * the filter criteria
37: */
38: public AccountFilter() {
39: super ();
40: }
41:
42: /** {@inheritDoc} */
43: public boolean process(IFolder folder, Object uid) throws Exception {
44: boolean result = false;
45:
46: Integer messageAccountUid = (Integer) ((IMailbox) folder)
47: .getAttribute(uid, "columba.accountuid");
48:
49: if ((messageAccountUid != null) && (criteriaAccountUid != -1)) {
50: int id = messageAccountUid.intValue();
51:
52: if ((criteriaCondition == FilterCriteria.IS)
53: && (criteriaAccountUid == id)) {
54: result = true;
55: } else if ((criteriaCondition == FilterCriteria.IS_NOT)
56: && (criteriaAccountUid != id)) {
57: result = true;
58: }
59: }
60:
61: return result;
62: }
63:
64: /**
65: * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
66: */
67: public void setUp(IFilterCriteria f) {
68: criteriaCondition = f.getCriteria();
69: String uidString = f.getPatternString();
70: criteriaAccountUid = -1;
71: try {
72: criteriaAccountUid = Integer.parseInt(uidString);
73: } catch (NumberFormatException e) {
74: criteriaAccountUid = -1;
75: }
76:
77: }
78: }
|