added Mbox parser
authoradam <adam@megacz.com>
Mon, 16 Aug 2004 01:59:36 +0000 (01:59 +0000)
committeradam <adam@megacz.com>
Mon, 16 Aug 2004 01:59:36 +0000 (01:59 +0000)
darcs-hash:20040816015936-5007d-c438d48b9b652018285a240f41df6937b9f84652.gz

src/org/ibex/mail/protocol/Mbox.java [new file with mode: 0644]

diff --git a/src/org/ibex/mail/protocol/Mbox.java b/src/org/ibex/mail/protocol/Mbox.java
new file mode 100644 (file)
index 0000000..e0e02d5
--- /dev/null
@@ -0,0 +1,33 @@
+package org.ibex.mail.protocol;
+import org.ibex.io.*;
+import org.ibex.crypto.*;
+import org.ibex.jinetd.Listener;
+import org.ibex.jinetd.Worker;
+import org.ibex.mail.*;
+import org.ibex.util.*;
+import org.ibex.mail.target.*;
+import java.util.*;
+import java.net.*;
+import java.text.*;
+import java.io.*;
+
+public class Mbox {
+    public static Message[] parse(Stream stream) {
+        StringBuffer buf = null;
+        Vec vec = new Vec();
+        for(String s = stream.readln(); ; s = stream.readln()) {
+            if (s == null || s.startsWith("From ")) {
+                try {
+                    if (buf != null) vec.addElement(new Message(new Stream(buf.toString()), null));
+                } catch (Exception e) { Log.warn(Mbox.class, e); }
+                if (s == null) break;
+                buf = new StringBuffer();
+            } else if (buf != null) {
+                if (buf.length() == 0 && s.length() == 0) continue;   // skip blank line after From
+                buf.append(s);
+                buf.append("\r\n");
+            }
+        }
+        return (Message[])vec.copyInto(new Message[vec.size()]);
+    }
+}