108fefaa5fdf0cb8f240a54a6465e51760f97d31
[org.ibex.mail.git] / src / org / ibex / mail / protocol / Mbox.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.mail.protocol;
6 import org.ibex.io.*;
7 import org.ibex.crypto.*;
8 import org.ibex.jinetd.Listener;
9 import org.ibex.jinetd.Worker;
10 import org.ibex.mail.*;
11 import org.ibex.util.*;
12 import org.ibex.mail.target.*;
13 import java.util.*;
14 import java.net.*;
15 import java.text.*;
16 import java.io.*;
17
18 public class Mbox {
19     public static Message[] parse(Stream stream) {
20         StringBuffer buf = null;
21         Vec vec = new Vec();
22         for(String s = stream.readln(); ; s = stream.readln()) {
23             if (s == null || s.startsWith("From ")) {
24                 try {
25                     if (buf != null) vec.addElement(Message.newMessage(new Fountain.StringFountain(buf.toString())));
26                 } catch (Exception e) { Log.warn(Mbox.class, e); }
27                 if (s == null) break;
28                 buf = new StringBuffer();
29             } else if (buf != null) {
30                 if (buf.length() == 0 && s.length() == 0) continue;   // skip blank line after From
31                 buf.append(s);
32                 buf.append("\r\n");
33             }
34         }
35         return (Message[])vec.copyInto(new Message[vec.size()]);
36     }
37 }