From: adam Date: Wed, 9 Jun 2004 01:18:52 +0000 (+0000) Subject: it compiles X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=6196a477ebd6282ccdbfb8a3fa6faad99ab1d45c;p=org.ibex.mail.git it compiles darcs-hash:20040609011852-5007d-e34e7b14dc9abf2a95f22fab225a74eb34a275e6.gz --- diff --git a/src/org/ibex/mail/MailException.java b/src/org/ibex/mail/MailException.java index 4002673..91883da 100644 --- a/src/org/ibex/mail/MailException.java +++ b/src/org/ibex/mail/MailException.java @@ -7,6 +7,7 @@ public class MailException extends RuntimeException { public MailException() { } public MailException(String s) { super(s); } public static class MailboxFull extends MailException { } + public static class MetadataNotSupported extends MailException { public MetadataNotSupported(String s) { super(s); } } public static class Malformed extends MailException { public Malformed(String s) { super(s); } } public static class RelayingDenied extends MailException { } public static class IOException extends MailException { diff --git a/src/org/ibex/mail/Message.java b/src/org/ibex/mail/Message.java index d492ed1..6ad493b 100644 --- a/src/org/ibex/mail/Message.java +++ b/src/org/ibex/mail/Message.java @@ -24,7 +24,9 @@ import java.io.*; */ public class Message extends JSReflection { - public static interface Visitor { public abstract void visit(Message m); } + // FIXME + public Date sent() { return null; } + public Date arrived() { return null; } private static class CaseInsensitiveHash extends Hashtable { public Object get(Object o) { @@ -33,12 +35,13 @@ public class Message extends JSReflection { } public Object put(Object k, Object v) { throw new Error("you cannot write to a CaseInsensitiveHash"); } void add(Object k, Object v) { - if (k instanceof String) return super.put(((String)k).toLowerCase(), v); - else return super.put(k, v); + if (k instanceof String) super.put(((String)k).toLowerCase(), v); + else super.put(k, v); } } public int rfc822size() { return allHeaders.length() + 2 /* CRLF */ + body.length(); } // double check this + public int size() { return allHeaders.length() + 2 /* CRLF */ + body.length(); } // double check this public final String allHeaders; // pristine headers public final Hashtable headers; // hash of headers (not including resent's and traces) @@ -126,7 +129,7 @@ public class Message extends JSReflection { all.append("\r\n"); if (s.length() == 0 || Character.isSpace(s.charAt(0))) { if (key == null) throw new Malformed("Message began with a blank line; no headers"); - headers.add(key, headers.get(key) + s); + headers.put(key, headers.get(key) + s); continue; } if (s.indexOf(':') == -1) throw new Malformed("Header line does not contain colon: " + s); @@ -144,7 +147,7 @@ public class Message extends JSReflection { } else { // just append it to the previous one; valid for Comments/Keywords if (headers.get(key) != null) val = headers.get(key) + " " + val; - headers.add(key, val); + headers.put(key, val); } } diff --git a/src/org/ibex/mail/Query.java b/src/org/ibex/mail/Query.java index bc8495c..300397a 100644 --- a/src/org/ibex/mail/Query.java +++ b/src/org/ibex/mail/Query.java @@ -1,5 +1,6 @@ package org.ibex.mail; import java.util.*; +import org.ibex.mail.target.*; /** * [immutable] This class encapsulates a query against a mailbox. @@ -14,38 +15,41 @@ import java.util.*; */ public class Query { - public static Query not(Query q) { return new Query(NOT, new Query[] { q }, 0, 0, 0, null, null, null, null); } - public static Query and(Query q1, Query q2) { return new Query(AND, new Query[] { q1, q2 }, 0, 0, 0, null, null, null, null); } - public static Query and(Query[] q) { return new Query(AND, q, 0, 0, 0, null, null, null, null); } - public static Query or(Query q1, Query q2) { return new Query(OR, new Query[] { q1, q2 }, 0, 0, 0, null, null, null, null); } - public static Query or(Query[] q) { return new Query(OR, q, 0, 0, 0, null, null, null, null); } - public static Query uid(int min, int max) { return new Query(UID, null, min, max, 0, null, null, null, null); } - public static Query messagenum(int min, int max) { return new Query(MESSAGENUM, null, min, max, 0, null, null, null, null); } - public static Query sent(Date earliest, Date latest) { return new Query(SENT, null,0,0,0,null,null, earliest, latest); } - public static Query arrival(Date earliest, Date latest) { return new Query(ARRIVAL, null,0,0,0,null,null, earliest, latest); } - public static Query header(String name, String val) { return new Query(HEADER, null, 0, 0, 0, name, val, null, null); } - public static Query size(int min, int max) { return new Query(SIZE, null, min, max, 0, null, null, null, null); } - public static Query flags(int flags) { return new Query(FLAGS, null, 0, 0, flags, null, null, null, null); } - public static Query body(String text) { return new Query(BODY, null, 0, 0, 0, null, text, null, null); } - public static Query body(String text) { return new Query(FULL, null, 0, 0, 0, null, text, null, null); } + public static Query not(Query q) { return new Query(NOT, new Query[] { q }, 0, 0, 0, null, null, null, null, null); } + public static Query and(Query q1, Query q2) { return new Query(AND, new Query[] {q1,q2},0,0,0,null, null, null, null, null); } + public static Query and(Query[] q) { return new Query(AND, q, 0, 0, 0, null, null, null, null, null ); } + public static Query or(Query q1, Query q2) { return new Query(OR,new Query[] {q1,q2},0, 0, 0, null, null, null, null, null); } + public static Query or(Query[] q) { return new Query(OR, q, 0, 0, 0, null, null, null, null, null); } + public static Query uid(int min, int max) { return new Query(UID, null, min, max, 0, null, null, null, null, null); } + public static Query messagenum(int min, int max) { return new Query(MESSAGENUM,null,min,max,0,null,null,null,null, null); } + public static Query sent(Date earliest, Date latest) { return new Query(SENT,null,0,0,0,null,null,earliest,latest,null); } + public static Query arrival(Date earliest, Date latest){return new Query(ARRIVAL,null,0,0,0,null,null, earliest,latest,null);} + public static Query header(String name, String val) { return new Query(HEADER, null, 0, 0, 0, name, val, null, null, null);} + public static Query size(int min, int max) { return new Query(SIZE, null, min, max, 0, null, null, null, null, null);} + public static Query flags(int flags) { return new Query(FLAGS, null, 0, 0, flags, null, null, null, null, null);} + public static Query body(String text) { return new Query(BODY, null, 0, 0, 0, null, text, null, null, null);} + public static Query full(String text) { return new Query(FULL, null, 0, 0, 0, null, text, null, null, null);} + public static Query set(int[] set) { return new Query(SET, null, 0 ,0 ,0, null, null, null, null, set);} + public static Query all() { return new Query(ALL, null, 0, 0, 0, null, null, null, null, null); } - private Query(int type, Query[] q, int min, int max, int flags, String key, String text, Date earliest, Date latest) { + 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; - this.earliest = earliest; this.latest = latest; } + this.earliest = earliest; this.latest = latest; this.set = set; } - public static int ALL = 0; - public static int NOT = 1; - public static int AND = 2; - public static int OR = 3; - public static int UID = 4; - public static int MESSAGENUM = 5; - public static int SENT = 6; - public static int ARRIVAL = 7; - public static int HEADER = 8; - public static int SIZE = 9; - public static int FLAGS = 10; - public static int BODY = 11; - public static int FULL = 12; + public static final int ALL = 0; + public static final int NOT = 1; + public static final int AND = 2; + public static final int OR = 3; + public static final int UID = 4; + public static final int MESSAGENUM = 5; + public static final int SENT = 6; + public static final int ARRIVAL = 7; + public static final int HEADER = 8; + public static final int SIZE = 9; + public static final int FLAGS = 10; + public static final int BODY = 11; + public static final int FULL = 12; + public static final int SET = 13; public final int type; public final Query[] q; @@ -56,22 +60,26 @@ public class Query { public final String text; public final Date earliest; public final Date latest; + public final int[] set; - public boolean match(Mailbox mbox, Message m) { + public boolean match(Mailbox.Iterator it) { switch(type) { case ALL: return true; - case NOT: return !q[0].match(mbox, m); - case OR: for(int i=0; i= min && mbox.uid <= max; - case MESSAGENUM: return mbox.messagenum(m) >= min && mbox.messagenum(m) <= max; - case SENT: return (latest == null || m.sent.before(latest)) &&(earliest == null || m.sent.after(earliest)); - case ARRIVAL: return (latest == null || m.arrival.before(latest)) &&(earliest == null || m.arrival.after(earliest)); - case SIZE: return m.size >= min && m.size <= max; - case FLAGS: return mbox.getFlags(flags); - case HEADER: return m.headers.get(key) != null && ((String)m.headers.get(key)).indexOf(text) != -1; - case BODY: return m.body.indexOf(text) != -1; - case FULL: return m.body.indexOf(text) != -1 || m.allHeaders.indexOf(text) != -1; + case NOT: return !q[0].match(it); + case OR: for(int i=0; i= min && it.uid() <= max; + case MESSAGENUM: return it.num() >= min && it.num() <= max; + case SENT: return (latest == null || it.cur().sent().before(latest)) + &&(earliest == null || it.cur().sent().after(earliest)); + case ARRIVAL: return (latest == null || it.cur().arrived().before(latest)) + &&(earliest == null || it.cur().arrived().after(earliest)); + case SIZE: return it.cur().size() >= min && it.cur().size() <= max; + case FLAGS: return it.getFlag(flags); + 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 SET: for(int i=0; i