made newMessage a static method and Message() private
[org.ibex.mail.git] / src / org / ibex / mail / protocol / Mbox.java
1 package org.ibex.mail.protocol;
2 import org.ibex.io.*;
3 import org.ibex.crypto.*;
4 import org.ibex.jinetd.Listener;
5 import org.ibex.jinetd.Worker;
6 import org.ibex.mail.*;
7 import org.ibex.util.*;
8 import org.ibex.mail.target.*;
9 import java.util.*;
10 import java.net.*;
11 import java.text.*;
12 import java.io.*;
13
14 public class Mbox {
15     public static Message[] parse(Stream stream) {
16         StringBuffer buf = null;
17         Vec vec = new Vec();
18         for(String s = stream.readln(); ; s = stream.readln()) {
19             if (s == null || s.startsWith("From ")) {
20                 try {
21                     if (buf != null) vec.addElement(Message.newMessage(new Stream(buf.toString())));
22                 } catch (Exception e) { Log.warn(Mbox.class, e); }
23                 if (s == null) break;
24                 buf = new StringBuffer();
25             } else if (buf != null) {
26                 if (buf.length() == 0 && s.length() == 0) continue;   // skip blank line after From
27                 buf.append(s);
28                 buf.append("\r\n");
29             }
30         }
31         return (Message[])vec.copyInto(new Message[vec.size()]);
32     }
33 }