noel 2003/03/10 13:52:11
Modified: src/java/org/apache/james/util Tag: branch_2_1_fcs
ExtraDotOutputStream.java
Log:
This should be proper RFC 2821 #2.3.7 handling of CR and LF. Put a commented out
test driver in the code to evaluate any use cases.
Revision Changes Path
No revision
No revision
1.2.4.4 +22 -8
jakarta-james/src/java/org/apache/james/util/ExtraDotOutputStream.java
Index: ExtraDotOutputStream.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/util/ExtraDotOutputStream.java,v
retrieving revision 1.2.4.3
retrieving revision 1.2.4.4
diff -u -r1.2.4.3 -r1.2.4.4
--- ExtraDotOutputStream.java 8 Mar 2003 21:54:11 -0000 1.2.4.3
+++ ExtraDotOutputStream.java 10 Mar 2003 21:52:09 -0000 1.2.4.4
@@ -68,6 +68,16 @@
*/
public class ExtraDotOutputStream extends FilterOutputStream {
+ /*
+ static public void main(String[] args) throws IOException
+ {
+ String data = ".This is a test\r\nof the thing.\r\nWe should not have much
trouble.\r\n.doubled?\r\nor not?\n.doubled\nor not?\r\n\r\n\n\n\r\r\r\n";
+
+ OutputStream os = new ExtraDotOutputStream(System.out);
+ os.write(data.getBytes());
+ }
+ */
+
/**
* Counter for number of last (0A or 0D).
*/
@@ -85,36 +95,40 @@
/**
* Writes a byte to the stream, adding dots where appropriate.
+ * Also fixes any naked CR or LF to the RFC 2821 mandated CFLF
+ * pairing.
*
* @param b the byte to write
*
* @throws IOException if an error occurs writing the byte
*/
public void write(int b) throws IOException {
- out.write(b);
-
switch (b) {
case '.':
if (countLast0A0D == 2) {
- // add extra dot
+ // add extra dot (the first of the pair)
out.write('.');
}
countLast0A0D = 0;
break;
case '\r':
+ if (countLast0A0D == 1) out.write('\n'); // two CR in a row, so
insert an LF first
countLast0A0D = 1;
break;
case '\n':
- if (countLast0A0D == 1) {
- countLast0A0D = 2;
- } else {
- countLast0A0D = 0;
- }
+ /* RFC 2821 #2.3.7 mandates that line termination is
+ * CRLF, and that CR and LF must not be transmitted
+ * except in that pairing. If we get a naked LF,
+ * convert to CRLF.
+ */
+ if (countLast0A0D != 1) out.write('\r');
+ countLast0A0D = 2;
break;
default:
// we're no longer at the start of a line
countLast0A0D = 0;
break;
}
+ out.write(b);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]