major simplifications to Iterator api
[org.ibex.mail.git] / src / org / ibex / mail / target / FileBasedMailbox.java
index 0a8c013..7af0194 100644 (file)
@@ -68,7 +68,15 @@ public class FileBasedMailbox extends Mailbox.Default {
         // acquire lock
         File lockfile = new File(this.path.getAbsolutePath() + slash + ".lock");
         lock = new RandomAccessFile(lockfile, "rw").getChannel().tryLock();
-        if (lock == null) throw new IOException("unable to lock FileBasedMailbox");
+        /*
+        if (lock == null) {
+            Log.warn(this, "warning: blocking waiting for a lock on " + path);
+            lock = new RandomAccessFile(lockfile, "rw").getChannel().lock();
+            if (lock == null) throw new IOException("unable to lock FileBasedMailbox: " + path);
+        }
+        lockfile.deleteOnExit();
+        */
+
         uidValidity = (int)(lockfile.lastModified() & 0xffffffff);
         uidNext = 0;
         String[] files = path.list();
@@ -104,7 +112,6 @@ public class FileBasedMailbox extends Mailbox.Default {
     };
 
     public Mailbox.Iterator  iterator()           { return new Iterator(); }
-    public synchronized void add(Message message) { add(message, Mailbox.Flag.RECENT); }
     public String[] children() {
         Vec vec = new Vec();
         String[] list = sort(path.list());
@@ -117,7 +124,7 @@ public class FileBasedMailbox extends Mailbox.Default {
 
     public int uidValidity() { return uidValidity; }
     public int uidNext() {  return uidNext; }
-    public synchronized void add(Message message, int flags) {
+    public synchronized void insert(Message message, int flags) {
         try {
             String name, fullname; File target, f;
             for(int i = uidNext; ; i++) {
@@ -126,7 +133,7 @@ public class FileBasedMailbox extends Mailbox.Default {
                 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());
+                Log.error(this, "aieeee!!!! target of insert() already exists: " + target.getAbsolutePath());
             }
             Stream stream = new Stream(new FileOutputStream(f));
             message.getStream().transcribe(stream);