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 2001/08/11 20:25:03 UTC

cvs commit: jakarta-james/src/java/org/apache/james/smtpserver SMTPInputStream.java SMTPHandler.java

serge       01/08/11 11:25:03

  Modified:    src/java/org/apache/james/smtpserver SMTPHandler.java
  Added:       src/java/org/apache/james/smtpserver SMTPInputStream.java
  Log:
  Added code to undo the dot-stuffing that happens during SMTP transport.
  
  Revision  Changes    Path
  1.7       +6 -2      jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java
  
  Index: SMTPHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SMTPHandler.java	2001/08/01 04:00:31	1.6
  +++ SMTPHandler.java	2001/08/11 18:25:03	1.7
  @@ -43,8 +43,8 @@
    * @author Jason Borden <jb...@javasense.com>
    * @author Matthew Pangaro <ma...@lokitech.com>
    *
  - * This is $Revision: 1.6 $
  - * Committed on $Date: 2001/08/01 04:00:31 $ by: $Author: serge $
  + * This is $Revision: 1.7 $
  + * Committed on $Date: 2001/08/11 18:25:03 $ by: $Author: serge $
    */
   public class SMTPHandler
       extends BaseConnectionHandler
  @@ -486,6 +486,10 @@
                       }
                       msgIn = new SizeLimitedInputStream(msgIn, maxmessagesize);
                   }
  +                //Removes the dot stuffing
  +                msgIn = new SMTPInputStream(msgIn);
  +
  +                //Parse out the message headers
                   MailHeaders headers = new MailHeaders(msgIn);
   
                   // if headers do not contains minimum REQUIRED headers fields,
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/smtpserver/SMTPInputStream.java
  
  Index: SMTPInputStream.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.smtpserver;
  
  import java.io.*;
  
  /**
   * Removes the dot-stuffing happing during the SMTP DATA transport
   *
   * @author Serge Knystautas <se...@lokitech.com>
   */
  public class SMTPInputStream extends FilterInputStream {
      protected int last[] = new int[2];
  
      public SMTPInputStream(InputStream in) {
          super(in);
          last[0] = -1;
          last[1] = -1;
      }
  
      /**
       * Read through the stream, checking for '\r\n.'
       */
      public int read() throws IOException {
          int b = in.read();
          if (b == '.' && last[0] == '\r' && last[1] == '\n') {
              //skip this '.' because it should have been stuffed
              b = in.read();
          }
          last[0] = last[1];
          last[1] = b;
          return b;
      }
  
      /**
       * Read through the stream, checking for '\r\n.'
       */
      public int read(byte[] b, int off, int len) throws IOException {
          if (b == null) {
              throw new NullPointerException();
          } else if ((off < 0) || (off > b.length) || (len < 0) ||
                 ((off + len) > b.length) || ((off + len) < 0)) {
              throw new IndexOutOfBoundsException();
          } else if (len == 0) {
              return 0;
          }
  
          int c = read();
          if (c == -1) {
              return -1;
          }
          b[off] = (byte)c;
  
          int i = 1;
  
          for (; i < len ; i++) {
              c = read();
              if (c == -1) {
                  break;
              }
              if (b != null) {
                  b[off + i] = (byte)c;
              }
          }
  
          return i;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org