X-Git-Url: http://git.megacz.com/?p=org.ibex.mail.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FIMAP.java;h=81f1820fbb444142d5b3d8ddab34e7d5a8ba6ba2;hp=b4abb2477b183956c2dddf898e4cc8c0d484a2df;hb=1975b1d7755c8a92480a8847f9dd3dc476f95ff5;hpb=52c154ee7bf49417e6a6b387ccc3fbab884229b8 diff --git a/src/org/ibex/mail/IMAP.java b/src/org/ibex/mail/IMAP.java index b4abb24..81f1820 100644 --- a/src/org/ibex/mail/IMAP.java +++ b/src/org/ibex/mail/IMAP.java @@ -52,7 +52,7 @@ public class IMAP { public static interface Client { public void expunge(int uid); public void list(char separator, String mailbox, boolean lsub, boolean phantom); - public void fetch(int num, int flags, int size, Message m, int muid); // m may be null or incomplete + public void fetchResponse(int num, int flags, int size, Message m, int muid); // m may be null or incomplete } public static interface Server { @@ -206,9 +206,18 @@ public class IMAP { public void check() { } public void noop() { } public void logout() { } - public void close() { for(Mailbox.Iterator it=selected().iterator(Query.deleted()); it.next();) it.delete(); } + public void close() { + for(Mailbox.Iterator it=selected().iterator(Query.deleted()); it.next();) { + Log.error("imap", "deleting a message due to close(): " + it.cur().summary()); + it.delete(); + } + } public void expunge() { for(Mailbox.Iterator it = selected().iterator(Query.deleted());it.next();) expunge(it); } - public void expunge(Mailbox.Iterator it) { client.expunge(it.uid()); it.delete(); } + public void expunge(Mailbox.Iterator it) { + client.expunge(it.uid()); + Log.error("imap", "deleting a message due to expunge(): " + it.cur().summary()); + it.delete(); + } public void subscribe(String mailbox) { } public void unsubscribe(String mailbox) { } public int maxuid() { @@ -247,12 +256,13 @@ public class IMAP { else if (style == 0) it.setFlags(flags); else if (style == 1) it.setFlags(it.getFlags() | flags); //it.setFlag(Mailbox.Flag.RECENT, recent); - if (!silent) client.fetch(it.imapNumber(), it.getFlags(), -1, null, it.uid()); + if (!silent) client.fetchResponse(it.imapNumber(), it.getFlags(), -1, null, it.uid()); } } public void fetch(Query q, int spec, String[] headers, int start, int end, boolean uid) { for(Mailbox.Iterator it = selected().iterator(q); it.next(); ) { + // FIXME it would be great if we could avoid instantiating the entire message just because RFC822SIZE was requested Message message = ((spec & (BODYSTRUCTURE | RFC822 | RFC822TEXT | RFC822SIZE)) != 0) ? it.cur() @@ -261,7 +271,7 @@ public class IMAP { : null; if (message != null) Log.warn("spec", spec); long size = message == null ? 0 : message.getLength(); - client.fetch(it.imapNumber(), it.getFlags(), (int)size, message, it.uid()); + client.fetchResponse(it.imapNumber(), it.getFlags(), (int)size, message,it.uid()); it.setFlags(it.getFlags() & ~Mailbox.Flag.RECENT); } } @@ -334,10 +344,10 @@ public class IMAP { case EXPUNGE: selected(); api.expunge(); break; case UNSELECT: selected(); api.unselect(); selected = false; break; case CREATE: api.create(token().astring()); break; - case FETCH: selected(); lastuid = uid; fetch((uid - ? Query.uid(token().set(maxn(uid))) - : Query.imapNumber(token().set(maxn(uid)))), - lastfetch=token().lx(), 0, 0, 0, uid, 0); break; + case FETCH: selected(); lastuid = uid; _fetch((uid + ? Query.uid(token().set(maxn(uid))) + : Query.imapNumber(token().set(maxn(uid)))), + lastfetch=token().lx(), 0, 0, 0, uid, 0); break; case COPY: selected(); api.copy(uid ? Query.uid(token().set(maxn(uid))) : Query.imapNumber(token().set(maxn(uid))), token().astring()); break; @@ -422,7 +432,7 @@ public class IMAP { // Callbacks ////////////////////////////////////////////////////////////////////////////// public void expunge(int uid) { println("* " + uid + " EXPUNGE"); } - public void fetch(int n, int f, int size, Message m, int muid) { fetch(m, lastfetch, n, f, size, lastuid, muid); } + public void fetchResponse(int n, int f, int size, Message m, int muid) { _fetch(m, lastfetch, n, f, size, lastuid, muid); } public void list(char sep, String mb, boolean sub, boolean p) { println("* " + (sub?"LSUB":"LIST")+" ("+(p?"\\Noselect":"")+") \""+sep+"\" \""+mb+"\"");} @@ -434,7 +444,7 @@ public class IMAP { * - parse the fetch request in Token[] t and return a fetch spec * - emit a fetch reply for the parsed spec with respect to message m */ - private void fetch(Object o, Parser.Token[] t, int num, int flags, int size, boolean uid, int muid) { + private void _fetch(Object o, Parser.Token[] t, int num, int flags, int size, boolean uid, int muid) { Query q = o == null ? null : o instanceof Query ? (Query)o : null; Message m = o == null ? null : o instanceof Message ? (Message)o : null; boolean e = q == null; @@ -495,7 +505,8 @@ public class IMAP { if (s.equalsIgnoreCase("BODY.PEEK")) spec |= PEEK; looked_at_body = true; if (i >= t.length - 1 || t[i+1].type != Parser.Token.LIST) { - spec |= BODYSTRUCTURE; + // not sure why this was uncommented.... + //spec |= BODYSTRUCTURE; if (e) { r.append(" "); r.append(Printer.bodystructure(m)); } continue; //if (e) { r.append(" "); r.append(Printer.qq(m.getBody().getStream())); } continue; } @@ -664,6 +675,20 @@ public class IMAP { public Token(Parser.Token[] list) { this.s = null; n = 0; l = list; type = LIST; } public Token(int number) { this.s = null; n = number; l = null; type = NUMBER; } + public String toString() { + // FIXME hack + switch(type) { + case NIL: return "NIL"; + case LIST: return "(" + Printer.join(", ", l) + ")"; + case QUOTED: return s; + case NUMBER: return n+""; + case ATOM: return s; + case BAREWORD: return s; + case SET: return ""; + } + return "???"; + } + public String flag() { if (type != ATOM) bad("expected a flag"); return s; } public int n() { if (type != NUMBER) bad("expected number"); return n; } public int nz() { int n = n(); if (n == 0) bad("expected nonzero number"); return n; } @@ -705,6 +730,7 @@ public class IMAP { else if (flag.equals("\\Draft")) ret |= Mailbox.Flag.DRAFT; else if (flag.equals("\\Answered")) ret |= Mailbox.Flag.ANSWERED; else if (flag.equals("\\Recent")) ret |= Mailbox.Flag.RECENT; + else Log.warn(this, "unknown flag: " + flag); } return ret; } @@ -906,5 +932,4 @@ public class IMAP { public static final int PEEK=0x1, BODYSTRUCTURE=0x2, ENVELOPE=0x4, FLAGS=0x8, INTERNALDATE=0x10, FIELDS=0x800, FIELDSNOT=0x1000, RFC822=0x20, RFC822TEXT=0x40, RFC822SIZE=0x80, HEADERNOT=0x100, UID=0x200, HEADER=0x400; - }