- 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"); }
-
- /** 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;
- public Transcript(String path) throws MailException { new File(this.path = path).mkdirs(); }
- private static String lastTime = null;
- private static int lastCounter = 0;
-
- /** returns a message identifier */
- public synchronized int add(Message message) throws MailException {
- try {
- File today = new File(path + File.separatorChar + (new SimpleDateFormat("yy-MMM-dd").format(new Date())));
- today.mkdirs();
-
- String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
- synchronized (Transcript.class) {
- if (lastTime != null && lastTime.equals(time)) {
- time += "." + (++lastCounter);
- } else {
- lastTime = time;
- }
- }
-
- File target = new File(today.getPath() + File.separatorChar + time + ".txt");
- OutputStream os = new FileOutputStream(target);
- message.dump(os);
- os.close();
- return -1;
- } catch (IOException e) { throw new MailException.IOException(e); }
- }
- }
-
- public static class FileBased extends Mailbox {
- private String path;
- private FileBased(String path) throws MailException { new File(this.path = path).mkdirs(); }
- public Mailbox slash(String name, boolean create) throws MailException {
- // FIXME: create
- return new FileBased(path + "/" + name);
- }
-
- public int[] list() {
- String[] names = new File(path).list();
- int[] ret = new int[names.length];
- for(int i=0, j=0; j<ret.length; i++, j++) {
- try {
- ret[j] = Integer.parseInt(names[i].substring(0, names[i].length() - 1));
- } catch (NumberFormatException nfe) {
- Log.warn(FileBased.class, "NumberFormatException: " + names[i].substring(0, names[i].length() - 1));
- j--;
- int[] newret = new int[ret.length - 1];
- System.arraycopy(ret, 0, newret, 0, newret.length);
- ret = newret;
- }
- }
- return ret;
- }
-
- /** returns a message identifier */
- public synchronized int add(Message message) throws MailException {
- try {
- int[] all = list();
- int max = 0;
- for(int i=0; i<all.length; i++) max = Math.max(max, all[i]);
- int target = max++;
- File f = new File(path + File.separatorChar + max + ".-");
- FileOutputStream fo = new FileOutputStream(f);
- message.dump(fo);
- fo.close();
- f.renameTo(new File(path + File.separatorChar + max + "."));
- return target;
- } catch (IOException e) { throw new MailException.IOException(e); }
- }