bugfixes
[org.ibex.mail.git] / src / org / ibex / mail / target / FileBasedMailbox.java
index fef694e..6f3198a 100644 (file)
@@ -87,9 +87,15 @@ public class FileBasedMailbox extends Mailbox.Default {
     public synchronized void add(Message message) { add(message, Mailbox.Flag.RECENT); }
     public synchronized void add(Message message, int flags) {
         try {
-            // FIXME: set flags
             int num = new File(path).list(filter).length;
-            File target = new File(path + slash + uidNext(true) + ".");
+           String name = path + slash + uidNext(true) + "." +
+                ((flags & Mailbox.Flag.DELETED) == Mailbox.Flag.DELETED ? "x" : "") +
+                ((flags & Mailbox.Flag.DRAFT) == Mailbox.Flag.DRAFT ? "d" : "") +
+                ((flags & Mailbox.Flag.RECENT) == Mailbox.Flag.RECENT ? "r" : "") +
+                ((flags & Mailbox.Flag.ANSWERED) == Mailbox.Flag.ANSWERED ? "a" : "") +
+                ((flags & Mailbox.Flag.FLAGGED) == Mailbox.Flag.FLAGGED ? "f" : "") +
+                ((flags & Mailbox.Flag.SEEN) == Mailbox.Flag.SEEN ? "s" : "");
+            File target = new File(name);
             File f = new File(target.getCanonicalPath() + "-");
             FileOutputStream fo = new FileOutputStream(f);
             message.dump(fo);
@@ -105,6 +111,7 @@ public class FileBasedMailbox extends Mailbox.Default {
         public Iterator() { names = new File(path).list(filter); }
 
         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 LineReader(new InputStreamReader(new FileInputStream(file))));