org.mailster.util
Class StreamUtilities

java.lang.Object
  extended by org.mailster.util.StreamUtilities

public class StreamUtilities
extends java.lang.Object

---
Mailster (C) 2007-2009 De Oliveira Edouard

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

See  Mailster Web Site
---

StreamUtilities.java - Various methods to help reading and writing to streams.

Version:
$Revision: 1.7 $, $Date: 2009/01/30 01:32:31 $
Author:
Edouard De Oliveira

Field Summary
private static java.lang.String From_
           
private static org.apache.mina.filter.codec.textline.LineDelimiter lineDelimiter
           
 
Constructor Summary
StreamUtilities()
           
 
Method Summary
static java.util.List<SmtpMessage> readMessageFromMBoxRDFormat(java.io.BufferedReader in, java.nio.charset.Charset charset)
          A reader scans through a mbox file looking for From_ lines.
static void write(java.io.BufferedReader in, AbstractPop3Connection conn)
           
static void write(java.io.BufferedReader in, AbstractPop3Connection conn, int numLines)
           
static void write(java.lang.String s, AbstractPop3Connection conn)
           
static void write(java.lang.String s, AbstractPop3Connection conn, int numLines)
           
static void writeMessageToMBoxRDFormat(StoredSmtpMessage msg, java.io.PrintWriter out)
          Here is how a program appends a message to an mbox file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

From_

private static final java.lang.String From_
See Also:
Constant Field Values

lineDelimiter

private static final org.apache.mina.filter.codec.textline.LineDelimiter lineDelimiter
Constructor Detail

StreamUtilities

public StreamUtilities()
Method Detail

write

public static void write(java.lang.String s,
                         AbstractPop3Connection conn)

write

public static void write(java.lang.String s,
                         AbstractPop3Connection conn,
                         int numLines)

write

public static void write(java.io.BufferedReader in,
                         AbstractPop3Connection conn)
                  throws java.io.IOException
Throws:
java.io.IOException

write

public static void write(java.io.BufferedReader in,
                         AbstractPop3Connection conn,
                         int numLines)
                  throws java.io.IOException
Throws:
java.io.IOException

readMessageFromMBoxRDFormat

public static java.util.List<SmtpMessage> readMessageFromMBoxRDFormat(java.io.BufferedReader in,
                                                                      java.nio.charset.Charset charset)
A reader scans through a mbox file looking for From_ lines. Any From_ line marks the beginning of a message. The reader should not attempt to take advantage of the fact that every From_ line (past the beginning of the file) is preceded by a blank line. Once the reader finds a message, it extracts a (possibly corrupted) envelope sender and delivery date out of the From_ line. It then reads until the next From_ line or end of file, whichever comes first. It strips off the final blank line and deletes the quoting of >From_ lines and >>From_ lines and so on. The result is an RFC 822 message. http://www.qmail.org/qmail-manual-html/man5/mbox.html


writeMessageToMBoxRDFormat

public static void writeMessageToMBoxRDFormat(StoredSmtpMessage msg,
                                              java.io.PrintWriter out)
Here is how a program appends a message to an mbox file. It first creates a From_ line given the message's envelope sender and the current date. If the envelope sender is empty (i.e., if this is a bounce message), the program uses MAILER-DAEMON instead. If the envelope sender contains spaces, tabs, or newlines, the program replaces them with hyphens. The program then copies the message, applying >From quoting to each line. >From quoting ensures that the resulting lines are not From_ lines: the program prepends a > to any From_ line, >From_ line, >>From_ line, >>>From_ line, etc. Finally the program appends a blank line to the message. If the last line of the message was a partial line, it writes two newlines; otherwise it writes one. http://www.qmail.org/qmail-manual-html/man5/mbox.html