total overhaul; were using MIME and MIME.Part now
[org.ibex.mail.git] / src / org / ibex / mail / target / FileBasedMailbox.java
index d1e0a5e..a8e2d53 100644 (file)
@@ -103,7 +103,10 @@ public class FileBasedMailbox extends Mailbox.Default {
             File target = new File(name);
             File f = new File(target.getCanonicalPath() + "-");
             FileOutputStream fo = new FileOutputStream(f);
-            message.dump(new Stream(fo));
+            Stream stream = new Stream(fo);
+            stream.println("X-org.ibex.mail.headers.envelope.From: " + message.envelope.from);
+            stream.println("X-org.ibex.mail.headers.envelope.To: " + message.envelope.to);
+            message.dump(stream);
             fo.close();
             f.renameTo(target);
             Log.info(this, "    done writing.");
@@ -122,7 +125,21 @@ public class FileBasedMailbox extends Mailbox.Default {
             try {
                 File file = new File(path + File.separatorChar + names[cur]);
                 FileInputStream fis = new FileInputStream(file);
-                Message ret = new Message(null, null, new Stream(fis));
+                Stream stream = new Stream(fis);
+                Address envelopeFrom = null;
+                Address envelopeTo = null;
+                for(String s = stream.readln(); s != null; s = stream.readln()) {
+                    if (s.startsWith("X-org.ibex.mail.headers.envelope.From: "))
+                        envelopeFrom = Address.parse(s.substring(38).trim());
+                    else if (s.startsWith("X-org.ibex.mail.headers.envelope.To: "))
+                        envelopeTo = Address.parse(s.substring(36).trim());
+                    else {
+                        stream.unread(s + "\r\n");
+                        break;
+                    }
+                }
+                Message ret = new Message(stream,
+                                          new Message.Envelope(envelopeFrom, envelopeTo, new Date(file.lastModified())));
                 fis.close();
                 return ret;
             } catch (IOException e) { throw new MailException.IOException(e);