X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FIMAP.java;h=9588cb46c9d241c305f3104b15cca7def46136a6;hb=94ad82f9461422b78e0dbe4db58f9a9efdf95064;hp=dc3b8f3af299fc1dffb322f573fda3d48c9ad366;hpb=c0cdaca74524315b01e9973c027e689627d3d58e;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/IMAP.java b/src/org/ibex/mail/IMAP.java index dc3b8f3..9588cb4 100644 --- a/src/org/ibex/mail/IMAP.java +++ b/src/org/ibex/mail/IMAP.java @@ -102,7 +102,7 @@ public class IMAP { Mailbox inbox = null; Mailbox selected = null; - MailboxTree root = null; + MailTree root = null; Mailbox selected() { if (selected == null) throw new Bad("no mailbox selected"); return selected; } final Login auth; final Client client; @@ -115,12 +115,15 @@ public class IMAP { private Mailbox mailbox(String name, boolean create) { return mailbox(name, create, true); } private Mailbox mailbox(String name, boolean create, boolean throwexn) { if (name.equalsIgnoreCase("inbox")) return inbox; - MailboxTree mt = mailboxTree(name, create, throwexn); - return mt==null ? null : mt.getMailbox(); + if (name.equalsIgnoreCase("trash")) name = "trash"; + MailTree mt = mailboxTree(name, create, throwexn); + Mailbox ret = mt==null ? null : mt.getMailbox(); + if (ret==null && throwexn) throw new Server.No("no such mailbox " + name); + return ret; } - private MailboxTree mailboxTree(String name, boolean create) { return mailboxTree(name, create, true); } - private MailboxTree mailboxTree(String name, boolean create, boolean throwexn) { - MailboxTree m = root; + private MailTree mailboxTree(String name, boolean create) { return mailboxTree(name, create, true); } + private MailTree mailboxTree(String name, boolean create, boolean throwexn) { + MailTree m = root; for(StringTokenizer st = new StringTokenizer(name, sep + ""); st.hasMoreTokens();) if ((m = m.slash(st.nextToken(), create)) == null) { if (throwexn) throw new Server.No("no such mailbox " + name); @@ -144,7 +147,7 @@ public class IMAP { for(int i=0; i 0 ? sep+"" : "") + s; if (mailbox(kid, false) == null) continue; - MailboxTree phant = mailboxTree(kid, false, false); + MailTree phant = mailboxTree(kid, false, false); if (phant != null) { boolean phantom = phant.getMailbox()==null; while(true) { @@ -183,11 +186,16 @@ public class IMAP { public void unselect() { selected = null; } public void delete(String m0) { mailboxTree(dirname(m0),false).rmdir(basename(m0)); } + public void rename(String from0, String to) { Mailbox from = mailbox(from0, false); if (from.equals(inbox)) { from.copy(Query.all(), mailbox(to, true)); } else if (to.equalsIgnoreCase("inbox")) { from.copy(Query.all(), mailbox(to, true)); delete(from0); } - else mailboxTree(dirname(from0), false).rename(dirname(from0), mailboxTree(dirname(to), false), basename(to)); + else mailboxTree(dirname(from0), false) + .rename(dirname(from0), + mailboxTree(dirname(to), + true /* required by IMAP */), + basename(to)); } public void create(String m) { mailbox(m, true, false); } @@ -207,8 +215,7 @@ public class IMAP { int ret = 0; Mailbox mb = selected(); if (mb == null) return 0; - for(Mailbox.Iterator it = mb.iterator(); it.next(); ) ret = it.uid(); - return ret; + return mb.maxuid(); } public int unseen(String mailbox) { return mailbox(mailbox, false).count(Query.not(Query.seen())); } public int recent(String mailbox) { return mailbox(mailbox, false).count(Query.recent()); } @@ -222,7 +229,8 @@ public class IMAP { Vec.Int vec = new Vec.Int(); for(Mailbox.Iterator it = selected().iterator(q); it.next();) { vec.addElement(uid ? it.uid() : it.imapNumber()); - it.setFlags(it.getFlags() & ~Mailbox.Flag.RECENT); + if ((it.getFlags() & Mailbox.Flag.RECENT) != 0) + it.setFlags(it.getFlags() & ~Mailbox.Flag.RECENT); } return vec.dump(); } @@ -245,7 +253,8 @@ public class IMAP { public void fetch(Query q, int spec, String[] headers, int start, int end, boolean uid) { for(Mailbox.Iterator it = selected().iterator(q); it.next(); ) { - Message message = ((spec & (BODYSTRUCTURE | ENVELOPE | INTERNALDATE | FIELDS | FIELDSNOT | RFC822 | + Message message = + ((spec & (BODYSTRUCTURE | ENVELOPE | INTERNALDATE | FIELDS | FIELDSNOT | RFC822 | RFC822TEXT | RFC822SIZE | HEADERNOT | HEADER)) != 0) ? it.cur() : null; long size = message == null ? 0 : message.getLength(); client.fetch(it.imapNumber(), it.getFlags(), (int)size, message, it.uid()); @@ -260,7 +269,7 @@ public class IMAP { public static class Listener implements Client { String selectedName = null; Mailbox inbox = null; - MailboxTree root = null; + MailTree root = null; Server api; Parser parser = null; Connection conn = null; @@ -284,7 +293,7 @@ public class IMAP { } else { Account account = (Account)ret; ((MailboxWrapper)api).root = root = account.getMailbox(IMAP.class); - MailboxTree ibt = root.slash("INBOX", false); + MailTree ibt = root.slash("inbox", false); Mailbox ib = ibt==null ? null : ibt.getMailbox(); ((MailboxWrapper)api).inbox = inbox = ib; } @@ -434,8 +443,8 @@ public class IMAP { lastfetch = t; int spec = 0; // spec; see constants for flags + int start = 0, len = 0; String[] headers = null; - int start = -1, end = -1; StringBuffer r = new StringBuffer(); if (e) { r.append(num); r.append(" FETCH ("); } int initlen = r.length(); @@ -499,19 +508,28 @@ public class IMAP { else if (s.equals("HEADER.FIELDS.NOT")) { spec |= FIELDSNOT; payload=Fountain.Util.create(headers(r,t[i].l()[1].sl(),true,m,e)); } else if (s.equals("MIME")) { throw new Server.Bad("MIME not supported"); } else throw new Server.Bad("unknown section type " + s); + if (i')); int dot = s.indexOf('.'); start = dot == -1 ? Integer.parseInt(s) : Integer.parseInt(s.substring(0, s.indexOf('.'))); - end = dot == -1 ? -1 : Integer.parseInt(s.substring(s.indexOf('.') + 1)); + len = dot == -1 ? -1 : Integer.parseInt(s.substring(s.indexOf('.') + 1)); if (e) { - //payload = payload.substring(start, Math.min(end+1,payload.getLength())); r.append("<"+start+">"); - // FIXME - throw new RuntimeException("this had to be disabled"); + if (start == 0 && len == -1) { + } else if (len == -1) { + payload = Fountain.Util.subFountain(payload, start); + } else { + len = (int)Math.min(len, payload.getLength()-start); + payload = Fountain.Util.subFountain(payload, start, len); + } + r.append("]"); + r.append("<"+start+"> "); } + } else { + if (e) r.append("] "); } - if (e) { r.append("] "); r.append(Printer.qq(payload.getStream())); } + if (e) r.append(Printer.qq(payload.getStream())); } } if ((spec & PEEK) == 0 && looked_at_body && e) @@ -520,7 +538,7 @@ public class IMAP { r.append(")"); println("* " + r.toString()); } else { - api.fetch(q, spec, headers, start, end, uid); + api.fetch(q, spec, headers, start, (len==-1?0:len), uid); } }