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 se...@apache.org on 2002/02/27 05:47:41 UTC

cvs commit: jakarta-james/src/java/org/apache/james/util ExtraDotOutputStream.java

serge       02/02/26 20:47:41

  Added:       src/java/org/apache/james/util ExtraDotOutputStream.java
  Log:
  Added dot-stuffing when retrieving a message in POP3.  Thanks to Stephan Schiessling <s...@rapi.com>
  
  Revision  Changes    Path
  1.1                  jakarta-james/src/java/org/apache/james/util/ExtraDotOutputStream.java
  
  Index: ExtraDotOutputStream.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.util;
  
  import java.io.FilterOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  
  /**
   * Adds extra dot if dot occurs in message body at beginning of line (according to RFC1939)
   * Compare also org.apache.james.smtpserver.SMTPInputStream
   *
   * @author Stephan Schiessling <s...@rapi.com>
   */
  public class ExtraDotOutputStream extends FilterOutputStream {
  
      /**
       * Counter for number of last (0A or 0D).
       */
      protected int countLast0A0D;
  
      public ExtraDotOutputStream(OutputStream out) {
          super(out);
          countLast0A0D = 2; // we already assume a CRLF at beginning (otherwise TOP would not work correctly !)
      }
  
      public void write(int b) throws IOException {
          out.write(b);
          if (b == '.') {
              if (countLast0A0D > 1) {
                  // add extra dot
                  out.write('.');
              }
              countLast0A0D = 0;
          } else {
              if (b == '\r' || b == '\n') {
                  countLast0A0D++;
              } else {
                  countLast0A0D = 0;
              }
          }
      }
  
  }
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>