public MailboxWrapper(Login auth, Client c) { this.auth=auth; this.client=c;}
- private Mailbox mailbox(String name, boolean create) {
+ 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;
Mailbox m = root;
for(StringTokenizer st = new StringTokenizer(name, sep + ""); st.hasMoreTokens();)
- if ((m = m.slash(st.nextToken(), create)) == null) throw new Server.No("no such mailbox " + name);
+ if ((m = m.slash(st.nextToken(), create)) == null) {
+ if (throwexn) throw new Server.No("no such mailbox " + name);
+ return null;
+ }
return m;
}
String[] children = (start.length() == 0 ? root : mailbox(start, false)).children();
for(int i=0; i<children.length; i++) {
String s = children[i], pre = ref, kid = start + (start.length() > 0 ? sep+"" : "") + s;
+ if (mailbox(kid, false) == null) continue;
boolean phantom = mailbox(kid, false).phantom();
while(true) {
if (pre.length() == 0) {
Account account = null;
if ((account = auth.login(u,p)) == null) throw new No("Login failed.");
root = account.getMailbox(IMAP.class);
- inbox = mailbox("INBOX", false); // FEATURE: ??
+ inbox = root.slash("INBOX", false);
+ if (inbox == null) inbox = root;
}
public void unselect() { selected = null; }
public void delete(String m0) { delete(mailbox(m0,false)); }
public void delete(Mailbox m) { if (!m.equals(inbox)) m.destroy(false); else throw new Bad("can't delete inbox"); }
- public void create(String m) { mailbox(m, true); }
+ public void create(String m) { mailbox(m, true, false); }
public void append(String m,int f,Date a,String b) { try {
mailbox(m,false).add(new Message(new Stream(b), new Message.Envelope(null,null,a)),f|Mailbox.Flag.RECENT);
} catch (Message.Malformed e) { throw new No(e.getMessage()); } }
case CAPABILITY: println("* CAPABILITY " + Printer.join(" ", api.capability())); break;
case AUTHENTICATE: throw new Server.No("AUTHENTICATE not supported");
case LOGOUT: api.logout(); println("* BYE"); conn.close(); return;
- case LIST: api.list(token().q(), token().q()); break;
+ case LIST: api.list(token().q(), token().astring()); break; /*astring is a hack for EUDORA*/
case LSUB: api.lsub(token().q(), token().q()); break;
case SUBSCRIBE: api.subscribe(token().astring()); break;
case UNSUBSCRIBE: api.unsubscribe(token().astring()); break;
s = list.length == 0 ? "" : list[0].s.toUpperCase();
r.append(s);
if (list.length == 0) { spec |= RFC822TEXT; if(e) payload = m.headers.raw+"\r\n"+m.body; }
- else if (s.equals("")) { spec |= RFC822TEXT; if(e) payload = m.headers.raw+"\r\n"+m.body; }
+ else if (s.equals("") || s.equals("1")) { spec |= RFC822TEXT; if(e) payload = m.headers.raw+"\r\n"+m.body; }
else if (s.equals("TEXT")) { spec |= RFC822TEXT; if(e) payload = m.body; }
else if (s.equals("HEADER")) { spec |= HEADER; if(e) payload = m.headers.raw+"\r\n"; }
else if (s.equals("HEADER.FIELDS")) { spec |= FIELDS; payload=headers(r,t[i].l()[1].sl(),false,m,e); }
public static String addressList(Object a) {
if (a == null) return "NIL";
if (a instanceof Address) return "("+address((Address)a)+")";
+ if (a instanceof String) return "("+address(Address.parse((String)a))+")";
Address[] aa = (Address[])a;
StringBuffer ret = new StringBuffer();
ret.append("(");
return "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" "+m.size()+" "+m.lines+")";
}
static String message(Message m) { return m.toString(); }
- static String date(Date d) { return d.toString(); }
+ static String date(Date d) { return "\""+d.toString()+"\""; }
static String envelope(Message m) {
return
"(" + quotify(m.envelope.arrival.toString()) +