You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2003/03/10 22:52:02 UTC
cvs commit: jakarta-james/src/java/org/apache/james/util ExtraDotOutputStream.java
noel 2003/03/10 13:52:02
Modified: src/java/org/apache/james/util 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
1.10 +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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ExtraDotOutputStream.java 8 Mar 2003 21:14:12 -0000 1.9
+++ ExtraDotOutputStream.java 10 Mar 2003 21:52:02 -0000 1.10
@@ -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: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org
RE: cvs commit: jakarta-james/src/java/org/apache/james/util ExtraDotOutputStream.java
Posted by "Noel J. Bergman" <no...@devtech.com>.
> You know we actually have junit tests for this... in fact I think this
> is the only class that has it. :)
We do? Ok, color me blind, but I did a grep for ExtraDot throughout the
entire source base for both HEAD and v2 branches, and only found it in
POP3Handler and the class, itself.
I do agree, as an side, that my silly little main could be replaced with a
JUnit for the class.
--- Noel
---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-james/src/java/org/apache/james/util ExtraDotOutputStream.java
Posted by Serge Knystautas <se...@lokitech.com>.
noel@apache.org wrote:
> + /*
> + 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());
> + }
> + */
> +
You know we actually have junit tests for this... in fact I think this
is the only class that has it. :)
--
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com
---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org