From: adam Date: Mon, 14 Jun 2004 02:02:08 +0000 (+0000) Subject: basically works completely with mozilla imap X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=b4567fd5118ec9bf588873f8ef72712e43b915e7;p=org.ibex.mail.git basically works completely with mozilla imap darcs-hash:20040614020208-5007d-7ecc50b94fd9decb4b466b907c74b1ba373733e3.gz --- diff --git a/src/org/ibex/mail/protocol/IMAP.java b/src/org/ibex/mail/protocol/IMAP.java index 24a56c4..8a2319c 100644 --- a/src/org/ibex/mail/protocol/IMAP.java +++ b/src/org/ibex/mail/protocol/IMAP.java @@ -50,13 +50,13 @@ public class IMAP { public int count(String mailbox); public int uidNext(String mailbox); public int uidValidity(String mailbox); + public int[] search(Query q, boolean uid); public void rename(String from, String to); public void select(String mailbox, boolean examineOnly); public static interface Client { public void expunge(int uid); public void list(char separator, String mailbox); - public void lsub(char separator, String mailbox); public void fetch(int uidnum, int flags, int size, Message m); // m may be null or incomplete } @@ -108,6 +108,7 @@ public class IMAP { public void list(String start, String ref, Client client) { if (ref.length() == 0 && start.length() == 0) { client.list(sep, ""); return; } while (start.endsWith(""+sep)) start = start.substring(0, start.length() - 1); + if (ref.endsWith("%")) ref = ref + sep; String[] children = (start.length() == 0 ? root : getMailbox(start, false)).children(); for(int i=0; i 0 ? sep+"" : "") + s; @@ -116,7 +117,7 @@ public class IMAP { if (s.length() == 0) client.list(sep, kid); } else switch(pre.charAt(0)) { case sep: if (s.length() == 0) list(kid, pre.substring(1), client); break; - case '%': client.list(sep, kid); pre=pre.substring(1); list(kid, pre, client); break; + case '%': client.list(sep, kid); pre = pre.substring(1); s = ""; continue; case '*': client.list(sep, kid); list(kid, pre, client); pre = pre.substring(1); break; default: if (s.length()==0) break; if (s.charAt(0) != pre.charAt(0)) break; @@ -164,6 +165,14 @@ public class IMAP { public void setFlags(Query q, int f, boolean uid, Client c) { doFlags(q, f, c, uid, 0); } public void addFlags(Query q, int f, boolean uid, Client c) { doFlags(q, f, c, uid, 1); } public void removeFlags(Query q, int f, boolean uid, Client c) { doFlags(q, f, c, uid, -1); } + public int[] search(Query q, boolean uid) { + Vec vec = new Vec(); + for(Mailbox.Iterator it = selected.iterator(q); it.next(); ) + vec.addElement(new Integer(uid ? it.uid() : it.num())); + int[] ret = new int[vec.size()]; + for(int i=0; i0) r.append(" "); + if (r.length() > initlen) r.append(" "); String s = t[i].s.toUpperCase(); - r.append(s); + if (!uid || !s.equals("UID")) r.append(s.equals("BODY.PEEK")?"BODY":s); if (s.equals("BODYSTRUCTURE")) { spec|=BODYSTRUCTURE;if(e){r.append(" ");r.append(Printer.bodystructure(m));} } else if (s.equals("ENVELOPE")) { spec|=ENVELOPE; if(e){r.append(" "); r.append(Printer.envelope(m));} } else if (s.equals("FLAGS")) { spec|=FLAGS; if(e){r.append(" "); r.append(Printer.flags(flags));} @@ -323,12 +335,18 @@ public class IMAP { } else if (s.equals("RFC822.TEXT")) { spec|=RFC822TEXT; if(e){r.append(" ");r.append(Printer.qq(m.body));} } else if (s.equals("RFC822.HEADER")) { spec|=RFC822HEADER; if(e){r.append(" ");r.append(Printer.qq(m.allHeaders));} } else if (s.equals("RFC822.SIZE")) { spec|=RFC822SIZE; if(e){r.append(" "); r.append(m.rfc822size());} + } else if (s.equals("UID")) { + spec|=UID; + if (e && !uid) { r.append(" "); r.append(uidnum); } + /*FIXME: UID in nonuid fetch*/ } else if (s.equals("BODY.PEEK") || s.equals("BODY")) { if (s.equalsIgnoreCase("BODY.PEEK")) spec |= PEEK; String payload = ""; if (i')); + String s3 = t[i].s.substring(1, t[i].s.indexOf('>')); int dot = s3.indexOf('.'); start = dot == -1 ? Integer.parseInt(s3) : Integer.parseInt(s3.substring(0, s3.indexOf('.'))); end = dot == -1 ? -1 : Integer.parseInt(s3.substring(s3.indexOf('.') + 1)); @@ -364,6 +391,8 @@ public class IMAP { } } if (e) { + // FIXME hack + if (uid) r.append(" UID " + uidnum); r.append(")"); star(r.toString()); } else { @@ -397,6 +426,7 @@ public class IMAP { private static final int FETCH = 22; static { commands.put("FETCH", new Integer(FETCH)); } private static final int APPEND = 23; static { commands.put("APPEND", new Integer(APPEND)); } private static final int STORE = 24; static { commands.put("STORE", new Integer(STORE)); } + private static final int SEARCH = 25; static { commands.put("SEARCH", new Integer(SEARCH)); } } public static class Parser { @@ -410,7 +440,15 @@ public class IMAP { this.pw = new PrintWriter(new OutputStreamWriter(conn.getOutputStream())); this.r = new PushbackReader(new InputStreamReader(this.is)); } - protected void println(String s) { pw.println(s); pw.flush(); } + protected void println(String s) { + pw.println(s); + pw.flush(); + if (log.length() > 0) { + System.err.println("\033[31;1m"+log+"\033[33;0m"); + log = ""; + } + System.err.println("\033[33;1m"+s+"\033[33;0m"); + } protected void flush() { pw.flush(); } Query query() { String s = null; @@ -429,6 +467,7 @@ public class IMAP { if (s.startsWith("UN")) { not = true; s = s.substring(2); } if (s.equals("ANSWERED")) q = Query.answered(); else if (s.equals("DELETED")) q = Query.deleted(); + else if (s.equals("ALL")) q = Query.all(); else if (s.equals("DRAFT")) q = Query.draft(); else if (s.equals("FLAGGED")) q = Query.flagged(); else if (s.equals("RECENT")) q = Query.recent(); @@ -548,9 +587,14 @@ public class IMAP { } } + String log = ""; public char getc() throws IOException { int ret = r.read(); if (ret == -1) throw new EOFException(); + if (ret == '\n') { + System.err.println("\033[31;1m"+log+"\033[33;0m"); + log = ""; + } else if (ret != '\r') log += (char)ret; return (char)ret; } public char peekc() throws IOException { @@ -640,7 +684,7 @@ public class IMAP { return ret.toString(); } static String flags(Mailbox.Iterator it) { - return + return (it.deleted() ? "\\Deleted " : "") + (it.seen() ? "\\Seen " : "") + (it.flagged() ? "\\Flagged " : "") + @@ -649,13 +693,15 @@ public class IMAP { (it.recent() ? "\\Recent " : ""); } static String flags(int flags) { - return + String ret = "(" + (((flags & Mailbox.Flag.DELETED) == Mailbox.Flag.DELETED) ? "\\Deleted " : "") + (((flags & Mailbox.Flag.SEEN) == Mailbox.Flag.SEEN) ? "\\Seen " : "") + (((flags & Mailbox.Flag.FLAGGED) == Mailbox.Flag.FLAGGED) ? "\\Flagged " : "") + (((flags & Mailbox.Flag.DRAFT) == Mailbox.Flag.DRAFT) ? "\\Draft " : "") + (((flags & Mailbox.Flag.ANSWERED) == Mailbox.Flag.ANSWERED)? "\\Answered " : "") + (((flags & Mailbox.Flag.RECENT) == Mailbox.Flag.RECENT) ? "\\Recent " : ""); + if (ret.endsWith(" ")) ret = ret.substring(0, ret.length() - 1); + return ret + ")"; } static String bodystructure(Message m) { // FIXME @@ -691,6 +737,14 @@ public class IMAP { return ret.toString(); } + private static String join(int[] nums) { + StringBuffer ret = new StringBuffer(); + for(int i=0; i