import java.text.*;
// FIXME: appallingly inefficient
-public class FileSystem {
+public class FileSystem extends Target {
private static final String STORAGE_ROOT =
System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
}
}
+ public void accept(Message m) throws IOException { add(m); }
public FileSystem slash(String name) throws IOException {
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 Message[] query(int maxResults) {
throw new Error(this.getClass().getName() + " does not support the query() method"); }
+ public static class Mailbox extends FileSystem {
+ 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 FileSystem slash(String name) throws IOException {
+ throw new Error(this.getClass().getName() + " does not support the slash() method"); }
+ public synchronized int add(Message message) throws IOException {
+ 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 FileSystem {
private String path;