private boolean auth(String user, String pass) { /* FEATURE */ return user.equals("megacz") && pass.equals("pass"); }
- // FEATURE: manage subscriptions
- public void lsub(Mailbox m, String s) {
- star("LSUB () \".\" INBOX");
- }
-
- // FIXME
- public void list(Mailbox m, String s) {
- //star("LIST () \".\" INBOX");
- star("LIST () \".\" users.megacz.imap");
+ public void lsub(String start, String ref) { list(start, ref); } // FEATURE: manage subscriptions
+ public void list(String start, String ref) {
+ if (ref.length() == 0) { star("LIST () \".\" \"\""); return; }
+ if (start.startsWith(".")) return;
+ String[] children = (start.length() == 0 ? root : getMailbox(start, false)).children();
+ for(int i=0; i<children.length; i++) {
+ String s = children[i], pre = ref;
+ boolean stop = true;
+ while(true) {
+ int percent = pre.indexOf('%'), star = pre.indexOf('*'), dot = pre.indexOf('.');
+ if (s.length() == 0 && pre.length() == 0) {
+ star("LIST () \".\" \""+(start + (start.length() > 0 ? "." : "") + children[i])+"\"");
+ break;
+ } else if (pre.length() == 0) {
+ break;
+ } else if (percent != 0 && star != 0 && dot != 0) {
+ if (s.length() == 0 || s.charAt(0) != pre.charAt(0)) break;
+ s = s.substring(1); pre = pre.substring(1);
+ } else if (pre.charAt(0) == '.') {
+ if (s.length() == 0) list(start + (start.length() > 0 ? "." : "") + children[i], pre.substring(1));
+ break;
+ } else if (pre.charAt(0) == '%') {
+ star("LIST () \".\" \""+(start + (start.length() > 0 ? "." : "") + children[i])+"\"");
+ list(start + (start.length() > 0 ? "." : "") + children[i], pre.substring(1));
+ // FIXME this isn't right
+ pre = pre.substring(1);
+ } else if (pre.charAt(0) == '*') {
+ // FIXME need to iterate
+ star("LIST () \".\" \""+(start + (start.length() > 0 ? "." : "") + children[i])+"\"");
+ list(start + (start.length() > 0 ? "." : "") + children[i], pre);
+ pre = pre.substring(1);
+ }
+ }
+ }
+ // FIXME: \Noselect
}
public void copy(final Query q, Mailbox to) { for(Mailbox.Iterator it=selected.iterator(q);it.next();) to.add(it.cur()); }
String command = atom();
if (command.equalsIgnoreCase("UID")) { uid = true; command = atom(); }
if (command.equalsIgnoreCase("AUTHENTICATE")) { login(astring(), astring()); }
- else if (command.equalsIgnoreCase("LIST")) list(mailbox(), mailboxPattern());
- else if (command.equalsIgnoreCase("LSUB")) lsub(mailbox(), mailboxPattern());
+ else if (command.equalsIgnoreCase("LIST")) list(q(), q());
+ else if (command.equalsIgnoreCase("LSUB")) lsub(q(), q());
else if (command.equalsIgnoreCase("SUBSCRIBE")) { /* FIXME */ }
else if (command.equalsIgnoreCase("UNSUBSCRIBE")) { /* FIXME */ }
else if (command.equalsIgnoreCase("CAPABILITY")) { capability(); }
parseFetchRequest(l()), uid);
else if (command.equalsIgnoreCase("STATUS")) status(mailbox(), l());
else throw new Exn.Bad("unrecognized command \"" + command + "\"");
- pw.println(tag + " OK uid " + command + " Completed.");
- System.err.println(tag + " OK uid " + command + " Completed.");
+ pw.println(tag + " OK " + command + " Completed.");
+ System.err.println(tag + " OK " + command + " Completed.");
} catch (Exn.Bad b) { pw.println(tag + " Bad " + b.toString()); System.err.println(tag + " Bad " + b.toString()); b.printStackTrace();
} catch (Exn.No n) { pw.println(tag + " OK " + n.toString()); System.err.println(tag + " OK " + n.toString());
}
public abstract void rename(String newName);
public abstract void destroy();
public abstract Mailbox slash(String name, boolean create);
+ public abstract String[] children();
// Thunks ////////////////////////////////////////////////////////////////////////////
public void rename(String newName) { throw new MailException("not supported"); }
public void destroy() { throw new MailException("not supported"); }
public Mailbox slash(String name, boolean create) { throw new MailException("not supported"); }
+ public String[] children() { return new String[] { }; }
public void move(Query q, Mailbox dest) {
for(Mailbox.Iterator it = iterator(q);it.next();) { dest.add(it.cur()); it.delete(); }
}