bogus
[org.ibex.mail.git] / src / org / ibex / mail / target / FileBasedMailbox.java
index f348f4c..d1e0a5e 100644 (file)
@@ -2,7 +2,6 @@ package org.ibex.mail.target;
 import org.ibex.mail.*;
 import org.ibex.util.*;
 import org.ibex.io.*;
-import org.ibex.net.*;
 import java.io.*;
 import java.net.*;
 import java.util.*;
@@ -75,6 +74,7 @@ public class FileBasedMailbox extends Mailbox.Default {
             }
             BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(uidNext)));
             int ret = Integer.parseInt(br.readLine());
+            br.close();
             if (inc) {
                 File tmp = new File(uidNext + "-");
                 PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tmp)));
@@ -99,12 +99,14 @@ public class FileBasedMailbox extends Mailbox.Default {
                 ((flags & Mailbox.Flag.ANSWERED) == Mailbox.Flag.ANSWERED ? "a" : "") +
                 ((flags & Mailbox.Flag.FLAGGED) == Mailbox.Flag.FLAGGED ? "f" : "") +
                 ((flags & Mailbox.Flag.SEEN) == Mailbox.Flag.SEEN ? "s" : "");
+            Log.info(this, "    with chosen filename " + name);
             File target = new File(name);
             File f = new File(target.getCanonicalPath() + "-");
             FileOutputStream fo = new FileOutputStream(f);
             message.dump(new Stream(fo));
             fo.close();
             f.renameTo(target);
+            Log.info(this, "    done writing.");
         } catch (IOException e) { throw new MailException.IOException(e); }
     }
 
@@ -114,11 +116,15 @@ public class FileBasedMailbox extends Mailbox.Default {
         private boolean seen = false, deleted = false, draft = false, flagged = false, answered = false, recent = false;
         public Iterator() { names = new File(path).list(filter); }
 
+        public Message head() { return cur(); }
         public Message cur() {
            if (cur >= names.length) return null;
             try {
                 File file = new File(path + File.separatorChar + names[cur]);
-                return new Message(null, null, new Stream(new FileInputStream(file)));
+                FileInputStream fis = new FileInputStream(file);
+                Message ret = new Message(null, null, new Stream(fis));
+                fis.close();
+                return ret;
             } catch (IOException e) { throw new MailException.IOException(e);
             } catch (Message.Malformed e) { throw new MailException(e.getMessage()); }
         }