import java.util.*;
import java.text.*;
-// FIXME: appallingly inefficient
public class Mailbox extends Target {
- private static final String STORAGE_ROOT =
- System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
- public static FileBased root = null;
- public static Transcript transcript = null;
- static {
- try {
- root = new FileBased(STORAGE_ROOT + File.separatorChar);
- transcript = new Transcript(STORAGE_ROOT + File.separatorChar + "transcript");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ // metadata
+ public void set(Message m, String key, String val) { throw new MailException.MetadataNotSupported(); }
+ public String get(Message m, String key) { throw new MailException.MetadataNotSupported(); }
+
+ // flags
+ public final boolean getFlag(Message m, int flags) { return (flags(m) & flag) == flags; }
+ public final void setFlag(Message m, int flag) { flags(m, flags | flag); }
+ public final void clearFlag(Message m, int flag) { flags(m, flags & ~flag); }
+ protected abstract void flags(Message m, int newFlags); // set the flags for a given message
+ protected abstract int flags(Message m); // get the flags for a given message
+ public abstract int uid(Message m); // get the uid for a given message (see IMAP RFC)
+ public abstract int num(Message m); // get the "message number" for a given message (see IMAP RFC)
+ public abstract int uidNext(); // get the next uid to be assigned
+ public abstract int uidValidity(); // get the uid validity identifier (see IMAP RFC)
+
+ // messages
+ public int add(Message message) throws MailException { throw new Error("not implemented"); }
+ public int delete(Message message) throws MailException { throw new Error("not implemented"); }
+ public void query(Query q, Message.Visitor v) throws MailException { throw new Error("not implemented"); }
+ public int count(Query q) throws MailException { throw new Error("not implemented"); }
+ public void move(Query q, Mailbox dest, boolean copy) throws MailException { throw new Error("not implemented"); }
+
+ // submailboxes
+ public void rename(String newName) throws MailException { throw new Error("not implemented"); }
+ public void destroy() throws MailException { throw new Error("not implemented"); }
+ public Mailbox slash(String name, boolean create) throws MailException { throw new Error("not implemented"); }
- 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"); }
- public void destroy() throws MailException { throw new Error("Mailbox.destroy() not implemented"); }
- public void accept(Message m) throws MailException { add(m); }
- public Mailbox slash(String name) throws MailException { return slash(name, false); }
- public Mailbox slash(String name, boolean create) throws MailException {
- throw new Error(this.getClass().getName() + " does not support the slash() method"); }
- public int[] list() { throw new Error(this.getClass().getName() + " does not support the list() method"); }
- public int add(Message message) throws MailException {
- throw new Error(this.getClass().getName() + " does not support the add() method"); }
- public int delete(Message message) throws MailException {
- throw new Error(this.getClass().getName() + " does not support the delete() method"); }
- public Message get(int messagenum) throws MailException {
- throw new Error(this.getClass().getName() + " does not support the get() method"); }
- public Message[] query(int maxResults) {
- throw new Error(this.getClass().getName() + " does not support the query() method"); }
- /*
- public static class Mailbox extends Mailbox {
- String user;
- private static Hashtable cache = new Hashtable();
- public static Mailbox getForUser(String user) {
- Mailbox ret = (Mailbox)cache.get(user);
- if (ret == null) ret = new Mailbox(user);
- return ret;
- }
- Mailbox(String user) { this.user = user; }
- public Mailbox slash(String name) throws MailException {
- throw new Error(this.getClass().getName() + " does not support the slash() method"); }
- public synchronized int add(Message message) throws MailException {
- FileOutputStream fos = new FileOutputStream("/var/mail/" + user, true);
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
- pw.println("From " + message.envelopeFrom);
- pw.flush();
- message.dump(fos);
- fos.close();
- return -1;
- }
- }
- */
/** a fast-write, slow-read place to stash all messages we touch -- in case of a major f*ckup */
public static class Transcript extends Mailbox {
private String path;
}
+
+ String user;
+ private static Hashtable cache = new Hashtable();
+ public static Mailbox getForUser(String user) {
+ Mailbox ret = (Mailbox)cache.get(user);
+ if (ret == null) ret = new Mailbox(user);
+ return ret;
+ }
+ Mailbox(String user) { this.user = user; }
+ public Mailbox slash(String name) throws MailException {
+ throw new Error(this.getClass().getName() + " does not support the slash() method"); }
+ public synchronized int add(Message message) throws MailException {
+ FileOutputStream fos = new FileOutputStream("/var/mail/" + user, true);
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
+ pw.println("From " + message.envelopeFrom);
+ pw.flush();
+ message.dump(fos);
+ fos.close();
+ return -1;
+ }
+
+
+ private static final String STORAGE_ROOT =
+ System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
+ public static FileBased root = null;
+ public static Transcript transcript = null;
+ static {
+ try {
+ root = new FileBased(STORAGE_ROOT + File.separatorChar);
+ transcript = new Transcript(STORAGE_ROOT + File.separatorChar + "transcript");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public final void accept(Message m) throws MailException { add(m); }
}