X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2Ftarget%2FFileSystem.java;h=8be7d8f923eade866e20a8daa764d8de22e1e63f;hb=034d6cb1d6f959c4640a0690b9ba0613e1f0ded4;hp=ab277a2b7ae65ef3a87f51108b37bb2c1548d22a;hpb=a18d27681a90b7630234b278d2e09a1a1040eb8a;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/target/FileSystem.java b/src/org/ibex/mail/target/FileSystem.java index ab277a2..8be7d8f 100644 --- a/src/org/ibex/mail/target/FileSystem.java +++ b/src/org/ibex/mail/target/FileSystem.java @@ -8,7 +8,7 @@ import java.util.*; 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"); @@ -23,6 +23,7 @@ public class FileSystem { } } + 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"); } @@ -35,6 +36,28 @@ public class FileSystem { 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;