From 987ed9e8d4dfe41f118b6bc3f1558fbc5955519c Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 23 Oct 2004 22:54:12 +0000 Subject: [PATCH] more fixes for dumb mistakes darcs-hash:20041023225412-5007d-e88b93c9654ae656b8eb059d9b3e276e5bed5019.gz --- src/org/ibex/mail/target/FileBasedMailbox.java | 47 ++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/org/ibex/mail/target/FileBasedMailbox.java b/src/org/ibex/mail/target/FileBasedMailbox.java index b2e7e85..ca4e0da 100644 --- a/src/org/ibex/mail/target/FileBasedMailbox.java +++ b/src/org/ibex/mail/target/FileBasedMailbox.java @@ -78,18 +78,7 @@ public class FileBasedMailbox extends Mailbox.Default { } }.start(); } - public static class Drop implements Transaction { - int uid; - public Drop(int uid) { this.uid = uid; } - public void executeOn(Object o, Date now) { - Cache c = (Cache)o; - Entry e = c.get(uid); - c.byname.remove(e.name); - c.linear.remove(e); - c.byuid.remove(uid); - } - } - + public synchronized int size() { return linear.size(); } public synchronized int uidNext(boolean increment) { return increment ? uidNext++ : uidNext; } public synchronized Entry get(int uid) { return byuid.get(uid); } @@ -125,7 +114,6 @@ public class FileBasedMailbox extends Mailbox.Default { public int uid() { return uid; } public boolean seen() { return seen; } public void seen(Cache cache, boolean seen) { - this.seen = seen; String base = cache.dir.getParent() + slash + name; File target = new File(base); if (!target.exists()) target = new File(base + "s"); @@ -201,13 +189,14 @@ public class FileBasedMailbox extends Mailbox.Default { Log.info(path, message.summary()); try { String name; String fullname; File target; File f; - do { + while(true) { name = cache.uidNext(true) + "."; fullname = path.getAbsolutePath() + slash + name; target = new File(fullname); f = new File(target.getCanonicalPath() + "-"); + if (!f.exists() && !target.exists()) break; Log.error(this, "aieeee!!!! target of add() already exists: " + target.getAbsolutePath()); - } while (f.exists() || target.exists()); + } FileOutputStream fo = new FileOutputStream(f); Stream stream = new Stream(fo); if (message.envelope != null) { @@ -232,19 +221,31 @@ public class FileBasedMailbox extends Mailbox.Default { public int num() { return cur+1; } // EUDORA insists that message numbers start at 1, not 0 public int uid() { return done() ? -1 : entry().uid(); } public Message cur() { return done() ? null : entry().message(cache); } - public void seen(boolean seen) { prevayler.execute(new Seen(uid(), seen)); } - public void delete() { if (!done()) prevayler.execute(new Delete(uid())); } + public void seen(boolean seen) { + entry().seen((Cache)prevayler.prevalentSystem(), seen); + prevayler.execute(new Seen(uid(), seen)); + } + public void delete() { + entry().delete((Cache)prevayler.prevalentSystem()); + prevayler.execute(new Drop(entry().uid())); + } } - private static class Delete implements Transaction { - private int uid; - public Delete(int uid) { this.uid = uid; } - public void executeOn(Object c, Date d) { ((Cache)c).get(uid).delete((Cache)c); } - } private static class Seen implements Transaction { private int uid; private boolean seen; public Seen(int uid, boolean seen) { this.uid = uid; this.seen = seen; } - public void executeOn(Object c, Date d) { ((Cache)c).get(uid).seen((Cache)c, seen); } + public void executeOn(Object c, Date d) { ((Cache)c).get(uid).seen = seen; } + } + public static class Drop implements Transaction { + int uid; + public Drop(int uid) { this.uid = uid; } + public void executeOn(Object o, Date now) { + Cache c = (Cache)o; + Cache.Entry e = c.get(uid); + c.byname.remove(e.name); + c.linear.remove(e); + c.byuid.remove(uid); + } } } -- 1.7.10.4