classpathx-javamail
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Classpathx-javamail] [PATCH/FIXED] 3 buglets in current javamail code


From: Adam Heath
Subject: [Classpathx-javamail] [PATCH/FIXED] 3 buglets in current javamail code
Date: Fri, 7 Jun 2002 21:14:52 -0500 (CDT)

Index: source/gnu/mail/handler/MultipartAlternative.java
===================================================================
RCS file: 
/cvsroot/classpathx/mail/source/gnu/mail/handler/MultipartAlternative.java,v
retrieving revision 1.1
diff -u -r1.1 MultipartAlternative.java
--- source/gnu/mail/handler/MultipartAlternative.java   29 Mar 2002 21:27:46 
-0000      1.1
+++ source/gnu/mail/handler/MultipartAlternative.java   8 Jun 2002 02:01:35 
-0000
@@ -24,7 +24,7 @@
  * type.
  */
 public final class MultipartAlternative
-  extends Application
+  extends Multipart
 {

   /**
Index: source/gnu/mail/handler/MultipartMixed.java
===================================================================
RCS file: /cvsroot/classpathx/mail/source/gnu/mail/handler/MultipartMixed.java,v
retrieving revision 1.1
diff -u -r1.1 MultipartMixed.java
--- source/gnu/mail/handler/MultipartMixed.java 29 Mar 2002 21:27:46 -0000      
1.1
+++ source/gnu/mail/handler/MultipartMixed.java 8 Jun 2002 02:01:35 -0000
@@ -24,7 +24,7 @@
  * type.
  */
 public final class MultipartMixed
-  extends Application
+  extends Multipart
 {

   /**

The patch pretty much speaks for itself.  Without it, any email that has
multipart content throws an exception.

The details are as follows:

Application only handles objects that are byte[].  Since this class isn't, a
NullPointerException gets thrown, because the object can't be cast to a byte
array.


Index: source/gnu/mail/util/RFC2822OutputStream.java
===================================================================
RCS file: 
/cvsroot/classpathx/mail/source/gnu/mail/util/RFC2822OutputStream.java,v
retrieving revision 1.2
diff -u -r1.2 RFC2822OutputStream.java
--- source/gnu/mail/util/RFC2822OutputStream.java       9 May 2002 12:42:02 
-0000       1.2
+++ source/gnu/mail/util/RFC2822OutputStream.java       8 Jun 2002 02:01:35 
-0000
@@ -107,10 +107,10 @@
     len += off;
     for (int i=off; i<len; i++)
     {
+      count++;
       if (b[i]==CR || b[i]==LF)
       {
         out.write(b, d, i-d);
-        out.write(LF);
         d = i;
         count = 0;
       }
@@ -124,7 +124,6 @@
           count = 0;
         }
       }
-      count++;
     }
     if (count>0)
       out.write(b, d, count);

This patch fixes 2 bugs.

First, is the off-by-one bug.  Incrementing count at the end of the loop, will
ALWAYS cause the condition outside the loop to pass.

Consider data, that ends with a new line:

* We loop over data, and find the last new line.
* Reset the count to 0.
* Then, we increment count.
* Since the end of data was reached, the loop terminates.
* Since count is 1 at this point, we attempt to output from d to count.
* However, d is pointed to the end of the block, and with count == 1, it'll
  try to read one byte past the end of the buffer.
* ArrayIndexOutOfBounds gets thrown.

The other bug fixed with this patch is a doubling of line feeds.

When the input contains a CR, we output the current buffer contents, then a
LF.  The current buffer contents contain the current char(CR, at position i).

The problem occurs when we then go to the next char.

If the input is already in CRLF mode, the next char will be a LF.  So, the
first out.write() will output this char, and then we output a second one.

Since the code has constructed a CRLFOutputStream -> RFC2822OutputStream ->
CRLFOutputStream, the last CRLFOutputStream will see the lone LF, and convert
it to a CRLF, causing the doubling.

==

With the above fixes, I can actually swap out BOTH activation and mail classes
from sun, with classpathx, and everything works.  This is much better then
when I last tried last summer/fall.

Keep up the good work.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]