james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject cvs commit: jakarta-james/src/java/org/apache/james/util ExtraDotOutputStream.java
Date Mon, 10 Mar 2003 21:52:02 GMT
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


Mime
View raw message