major simplifications to Iterator api
[org.ibex.mail.git] / src / org / ibex / mail / target / FileBasedMailbox.java
index 4fc5176..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);
@@ -152,7 +159,8 @@ public class FileBasedMailbox extends Mailbox.Default {
         public boolean next() { cur++; return !done(); }
         public boolean seen() { return false; }
         public boolean recent() { return false; }
-        public int num() { return cur+1; }  // EUDORA insists that message numbers start at 1, not 0
+        public int nntpNumber() { return cur+1; }  // FIXME: lame
+        public int imapNumber() { return cur+1; }  // EUDORA insists that message numbers start at 1, not 0
         public int uid() { return done() ? -1 : Integer.parseInt(files[cur].substring(0, files[cur].length()-1)); }
         public void delete() { File f = file(); if (f != null && f.exists()) f.delete(); }
         public void seen(boolean seen) { }
@@ -218,7 +226,7 @@ public class FileBasedMailbox extends Mailbox.Default {
                 s[0] = (m.from==null?"":m.from.toString(true));
                 s[1] = m.subject;
                 s[2] = (m.date + "").trim().replaceAll(" "," ");
-                s[3] = it.num() + "";
+                s[3] = it.imapNumber() + "";
                 msgs.addElement(s);
             }
             String[][] messages;
@@ -253,7 +261,7 @@ public class FileBasedMailbox extends Mailbox.Default {
                 int target = Integer.parseInt(request.getParameter("msgnum"));
                 Mailbox.Iterator it = mbox.iterator();
                 while(it.next())
-                    if (it.num() == target)
+                    if (it.imapNumber() == target)
                         break;
                 if (it.cur() != null) {
                     pw.println("    <table width=100% border=0 cellspacing=0 style='border: 1px black solid; background-color:#F0F0E0;'>");