public class Message extends JSReflection {
- // FIXME: case-insensitive header hashmap
- public int rfc822size() { return -1; } // FIXME
- public int numLines() { return -1; } // FIXME
- public int messageNum = -1;
+ private static class CaseInsensitiveHash extends Hashtable {
+ public Object get(Object o) {
+ if (o instanceof String) return super.get(((String)o).toLowerCase());
+ return super.get(o);
+ }
+ public Object put(Object k, Object v) {
+ if (k instanceof String) return super.put(((String)k).toLowerCase(), v);
+ else return super.put(k, v);
+ }
+ }
+
+ public int rfc822size() { return allHeaders.length() + 2 /* CRLF */ + body.length(); } // double check this
public final String allHeaders; // pristine headers
public final Hashtable headers; // hash of headers (not including resent's and traces)
public final String body; // entire body
+ public final int lines; // lines in the body
public final Date date;
public final Address to;
w.write(body);
w.flush();
}
-
-
+ /*
+ public static class Persistent {
public boolean deleted = false;
public boolean seen = false;
public boolean flagged = false;
public boolean draft = false;
public boolean answered = false;
public boolean recent = false;
- public int uid = 0;
-
+ public int uid = 0;
+ }
+ */
/*
public static class StoredMessage extends Message {
public int uid;
this.envelopeFrom = envelopeFrom;
this.envelopeTo = envelopeTo;
this.arrival = new Date();
- this.headers = new Hashtable();
+ this.headers = new CaseInsensitiveHash();
String key = null;
StringBuffer all = new StringBuffer();
Date date = null;
traces.copyInto(this.traces = new Trace[traces.size()]);
allHeaders = all.toString();
StringBuffer body = new StringBuffer();
- for(String s = rs.readLine();; s = rs.readLine()) { if (s == null) break; else body.append(s + "\r\n"); }
+ int lines = 0;
+ for(String s = rs.readLine();; s = rs.readLine()) { if (s == null) break; lines++; body.append(s + "\r\n"); }
+ this.lines = lines;
this.body = body.toString();
}
public void status(Mailbox m, Token[] attrs) {
int[] list = m.list();
int recent = 0, unseen = 0;
- for(int i=0; i<list.length; i++) {
- Message message = m.get(list[i]);
- if (!message.seen) unseen++;
- if (message.recent) recent++;
- }
+ for(int i=0; i<list.length; i++) { if (!m.seen(i)) unseen++; if (m.recent(i)) recent++; }
String response = "";
for(int i=0; i<attrs.length; i++) {
String s = attrs[i].atom();
selected = getMailbox(mailbox, false);
star(selected.list().length + " EXISTS");
int recent = 0;
- int[] list = selected.list(); for(int i=0; i<list.length; i++) if (selected.get(list[i]).recent) recent++;
+ int[] list = selected.list(); for(int i=0; i<list.length; i++) if (selected.recent(list[i])) recent++;
star(recent + " RECENT");
//star("OK [UNSEEN 12] Message 12 is first unseen"); FEATURE
star("OK [UIDVALIDITY " + selected.uidvalidity + "] UIDs valid");
int[] messages = selected.list();
for(int i=0; i<messages.length; i++) {
Message m = selected.get(messages[i]);
- if (m.deleted) {
- if (!silent) star(m.uid + " EXPUNGE");
+ if (selected.deleted(messages[i])) {
+ if (!silent) star(selected.uid(m) + " EXPUNGE");
if (!examineOnly) selected.delete(m);
}
}
start = Integer.parseInt(range);
}
if (s.equals("ENVELOPE") || all || full) reply.append("ENVELOPE " + envelope(m) + " ");
- if (s.equals("FLAGS") || full || all || fast) reply.append("FLAGS (" + flags(m) + ") ");
+ if (s.equals("FLAGS") || full || all || fast) reply.append("FLAGS (" + flags(selected, set[j]) + ") ");
if (s.equals("INTERNALDATE") || full || all || fast) reply.append("INTERNALDATE "+quotify(m.arrival)+" ");
if (s.equals("RFC822.SIZE") || full || all || fast) reply.append("RFC822.SIZE " + m.rfc822size() + " ");
if (s.equals("RFC822.HEADER") || s.equals("BODY[HEADER]"))
{ reply.append("BODY[HEADER] {" + m.allHeaders.length() + "}\r\n"); reply.append(m.allHeaders); }
if (s.equals("RFC822")||s.equals("RFC822.TEXT")||s.equals("BODY")||s.equals("BODY[]")||s.equals("TEXT")||full)
{ reply.append("BODY[TEXT] {" + m.body.length() + "}\r\n"); reply.append(m.body); }
- if (s.equals("UID")) reply.append("UID " + m.uid);
+ if (s.equals("UID")) reply.append("UID " + selected.uid(set[j]));
if (s.equals("MIME")) throw new Exn.No("FETCH BODY.MIME not supported");
if (s.startsWith("BODY[HEADER.FIELDS")) throw new Exn.No("partial headers not supported");
if (s.startsWith("BODY[HEADER.FIELDS.NOT")) throw new Exn.No("partial headers not supported");
if (s.equals("BODYSTRUCTURE"))
reply.append("(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" " +
- m.rfc822size()+" "+ m.numLines() +")");
+ m.rfc822size()+" "+ m.lines +")");
}
- star(m.messageNum + " FETCH (" + reply.toString() + ")");
+ star(set[j] + " FETCH (" + reply.toString() + ")");
// FEATURE set seen flag if not BODY.PEEK
}
}
public void store(int[] messages, String what, Token[] flags) {
for(int i=0; i<messages.length; i++) {
Message m = selected.get(messages[i]);
- if (what.charAt(0) == 'F') m.deleted = m.seen = m.flagged = m.draft = m.answered = m.recent = false;
+ if (what.charAt(0) == 'F') {
+ selected.setDeleted(messages[i], false);
+ selected.setSeen(messages[i], false);
+ selected.setFlagged(messages[i], false);
+ selected.setDraft(messages[i], false);
+ selected.setAnswered(messages[i], false);
+ selected.setRecent(messages[i], false);
+ }
for(int j=0; j<flags.length; j++) {
String flag = flags[j].flag();
- if (flag.equals("Deleted")) m.deleted = what.charAt(0) != '-';
- if (flag.equals("Seen")) m.seen = what.charAt(0) != '-';
- if (flag.equals("Flagged")) m.flagged = what.charAt(0) != '-';
- if (flag.equals("Draft")) m.draft = what.charAt(0) != '-';
- if (flag.equals("Answered")) m.answered = what.charAt(0) != '-';
- if (flag.equals("Recent")) m.recent = what.charAt(0) != '-';
+ if (flag.equals("Deleted")) selected.setDeleted(messages[i], what.charAt(0) != '-');
+ if (flag.equals("Seen")) selected.setSeen(messages[i], what.charAt(0) != '-');
+ if (flag.equals("Flagged")) selected.setFlagged(messages[i], what.charAt(0) != '-');
+ if (flag.equals("Draft")) selected.setDraft(messages[i], what.charAt(0) != '-');
+ if (flag.equals("Answered")) selected.setAnswered(messages[i], what.charAt(0) != '-');
+ if (flag.equals("Recent")) selected.setRecent(messages[i], what.charAt(0) != '-');
}
selected.add(m); // re-add
}
ret.append(")");
return ret.toString();
}
- static String flags(Message m) {
+ static String flags(Mailbox s, int i) {
return
- (m.deleted ? "\\Deleted " : "") +
- (m.seen ? "\\Seen " : "") +
- (m.flagged ? "\\Flagged " : "") +
- (m.draft ? "\\Draft " : "") +
- (m.answered ? "\\Answered " : "") +
- (m.recent ? "\\Recent " : "");
+ (s.deleted(i) ? "\\Deleted " : "") +
+ (s.seen(i) ? "\\Seen " : "") +
+ (s.flagged(i) ? "\\Flagged " : "") +
+ (s.draft(i) ? "\\Draft " : "") +
+ (s.answered(i) ? "\\Answered " : "") +
+ (s.recent(i) ? "\\Recent " : "");
}
static String envelope(Message m) {
return
public int uidvalidity;
public int uidnext;
+ public void setDeleted(int i, boolean b) { }
+ public void setSeen(int i, boolean b) { }
+ public void setFlagged(int i, boolean b) { }
+ public void setDraft(int i, boolean b) { }
+ public void setAnswered(int i, boolean b) { }
+ public void setRecent(int i, boolean b) { }
+ public boolean deleted(int i) { return false; }
+ public boolean seen(int i) { return false; }
+ public boolean flagged(int i) { return false; }
+ public boolean draft(int i) { return false; }
+ public boolean answered(int i) { return false; }
+ public boolean recent(int i) { return false; }
+ public int uid(int i) { return -1; }
+ public int uid(Message m) { return -1; }
+
public void moveAllMessagesTo(Mailbox m) throws MailException { throw new Error("moveAllMessagesTo() not implemented"); }
public String getName() throws MailException { throw new Error("Mailbox.getName() not implemented"); }
public void rename(String newName) throws MailException { throw new Error("Mailbox.rename() not implemented"); }