From a906df4c56f4f3659fcad3b1adaf6408142b50d6 Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 16 Aug 2004 01:59:36 +0000 Subject: [PATCH] added Mbox parser darcs-hash:20040816015936-5007d-c438d48b9b652018285a240f41df6937b9f84652.gz --- src/org/ibex/mail/protocol/Mbox.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/org/ibex/mail/protocol/Mbox.java diff --git a/src/org/ibex/mail/protocol/Mbox.java b/src/org/ibex/mail/protocol/Mbox.java new file mode 100644 index 0000000..e0e02d5 --- /dev/null +++ b/src/org/ibex/mail/protocol/Mbox.java @@ -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()]); + } +} -- 1.7.10.4