+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
package org.ibex.mail;
import java.util.*;
import org.ibex.mail.target.*;
+import org.ibex.util.*;
/**
* [immutable] This class encapsulates a query against a mailbox.
public static Query draft() { return new Query(DRAFT, null, 0, 0, 0, null, null, null, null, null); }
public static Query answered() { return new Query(ANSWERED, null, 0, 0, 0, null, null, null, null, null); }
public static Query recent() { return new Query(RECENT, null, 0, 0, 0, null, null, null, null, null); }
+ public static Query set(boolean uid, int[] set) { return uid ? uid(set) : num(set); }
private Query(int type, Query[] q,int min,int max, int flags, String key, String text, Date earliest, Date latest, int[] set) {
this.type = type; this.q = q; this.min = min; this.max = max; this.flags = flags; this.key = key; this.text = text;
case NOT: return !q[0].match(it);
case OR: for(int i=0; i<q.length; i++) if (q[i].match(it)) return true; return false;
case AND: for(int i=0; i<q.length; i++) if (!q[i].match(it)) return false; return true;
- case UID: if (set != null){for(int i=0; i<set.length; i++) if (set[i] == it.uid()) return true; return false; }
- else return it.uid() >= min && it.uid() <= max;
- case NUM: if (set != null){for(int i=0; i<set.length; i++) if (set[i] == it.uid()) return true; return false; }
+ case UID: if (set != null) {
+ for(int i=0; i<set.length; i+=2)
+ if (set[i] <= it.uid() && set[i+1] >= it.uid()) return true;
+ return false; }
else return it.uid() >= min && it.uid() <= max;
+ case NUM: if (set != null) {
+ for(int i=0; i<set.length; i+=2) if (set[i] <= it.num() && set[i+1] >= it.num()) return true;
+ return false; }
+ else return it.num() >= min && it.num() <= max;
case SENT: return (latest==null||it.cur().date.before(latest)) &&
(earliest==null||it.cur().date.after(earliest));
case ARRIVAL: return (latest == null || it.cur().arrival.before(latest)) &&
(earliest == null || it.cur().arrival.after(earliest));
- case SIZE: return it.cur().rfc822size() >= min && it.cur().rfc822size() <= max;
- case HEADER: return it.cur().headers.get(key) != null && ((String)it.cur().headers.get(key)).indexOf(text) != -1;
- case BODY: return it.cur().body.indexOf(text) != -1;
- case FULL: return it.cur().body.indexOf(text) != -1 || it.cur().allHeaders.indexOf(text) != -1;
+ case HEADER: return it.cur().headers.get(key) != null &&
+ ((String)it.cur().headers.get(key)).toLowerCase().indexOf(text.toLowerCase()) != -1;
case DELETED: return it.deleted();
case SEEN: return it.seen();
case FLAGGED: return it.flagged();
case DRAFT: return it.draft();
case ANSWERED: return it.answered();
case RECENT: return it.recent();
+
+ // FIXME: super inefficient
+ case BODY: throw new RuntimeException("BODY searches are not supported because they are slow");
+ case FULL: throw new RuntimeException("FULL searches are not supported because they are slow");
+ case SIZE: throw new RuntimeException("SIZE searches are not supported because Adam is lame");
+ //return it.cur().size() >= min && it.cur().size() <= max;
+
default: throw new Error("this should not happen");
}
}