001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.filter.plugins;
019:
020: import org.columba.core.filter.AbstractFilter;
021: import org.columba.core.filter.FilterCriteria;
022: import org.columba.core.filter.IFilterCriteria;
023: import org.columba.core.folder.api.IFolder;
024: import org.columba.mail.folder.IMailbox;
025:
026: /**
027: * Find messages with certain size.
028: *
029: * @author fdietz
030: */
031: public class SizeFilter extends AbstractFilter {
032:
033: private String pattern;
034:
035: private int condition;
036:
037: /**
038: * Constructor for SizeFilter.
039: */
040: public SizeFilter() {
041: super ();
042: }
043:
044: /**
045: * Transform string to integer representation
046: *
047: * @param p
048: * string containing priority
049: *
050: * @return integer representation of string
051: */
052: protected Integer transformSize(String p) {
053: Integer searchPattern = Integer.valueOf(p);
054:
055: return searchPattern;
056: }
057:
058: /**
059: * @see org.columba.core.filter.AbstractFilter#process(java.lang.Object,
060: * org.columba.mail.folder.Folder, java.lang.Object,
061: * org.columba.api.command.IWorkerStatusController)
062: */
063: public boolean process(IFolder folder, Object uid) throws Exception {
064: boolean result = false;
065:
066: Integer size = transformSize((String) pattern);
067:
068: Integer s = (Integer) ((IMailbox) folder).getAttribute(uid,
069: "columba.size");
070:
071: if (s == null) {
072: return false;
073: }
074:
075: switch (condition) {
076: case FilterCriteria.SIZE_SMALLER:
077:
078: if (size.compareTo(s) > 0) {
079: result = true;
080: }
081:
082: break;
083:
084: case FilterCriteria.SIZE_BIGGER:
085:
086: if (size.compareTo(s) < 0) {
087: result = true;
088: }
089:
090: break;
091: }
092:
093: return result;
094: }
095:
096: /**
097: * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
098: */
099: public void setUp(IFilterCriteria f) {
100:
101: // string to search
102: pattern = f.getPatternString();
103:
104: condition = f.getCriteria();
105: }
106: }
|