james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r390042 - in /james/server/trunk/src: java/org/apache/james/core/MimeMessageWrapper.java test/org/apache/james/core/MimeMessageFromStreamTest.java test/org/apache/james/core/MimeMessageTest.java
Date Thu, 30 Mar 2006 09:18:48 GMT
Author: bago
Date: Thu Mar 30 01:18:46 2006
New Revision: 390042

URL: http://svn.apache.org/viewcvs?rev=390042&view=rev
Log:
Fix an NPE in message.getLineCount when there is no Encoding (javamail returns -1 while our
wrapper try to count the lines for small messages) (JAMES-462)

Modified:
    james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java
    james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java
    james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java

Modified: james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java?rev=390042&r1=390041&r2=390042&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java Thu Mar 30 01:18:46
2006
@@ -294,7 +294,12 @@
         //Wrap input stream in LineNumberReader
         //Not sure what encoding to use really...
         try {
-            LineNumberReader counter = new LineNumberReader(new InputStreamReader(in, getEncoding()));
+            LineNumberReader counter;
+            if (getEncoding() != null) {
+                counter = new LineNumberReader(new InputStreamReader(in, getEncoding()));
+            } else {
+                counter = new LineNumberReader(new InputStreamReader(in));
+            }
             //Read through all the data
             char[] block = new char[4096];
             while (counter.read(block) > -1) {

Modified: james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java?rev=390042&r1=390041&r2=390042&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java Thu Mar
30 01:18:46 2006
@@ -40,5 +40,9 @@
         return getMessageFromSources(getMissingEncodingAddHeaderSource());
     }
 
+    protected MimeMessage getMissingEncodingMessage() throws Exception {
+        return getMessageFromSources(getMissingEncodingMessageSource());
+    }
+
 
 }

Modified: james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java?rev=390042&r1=390041&r2=390042&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java Thu Mar 30 01:18:46
2006
@@ -60,7 +60,7 @@
     public void testSimpleMessage() throws Exception {
         assertEquals(getSimpleMessageCleanedSource(), getCleanedMessageSource(getSimpleMessage()));
     }
-
+    
     
     protected MimeMessage getMultipartMessage() throws Exception {
         MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -265,6 +265,42 @@
         System.out.println("-------------------");
     }
     
+
+    protected MimeMessage getMissingEncodingMessage() throws Exception {
+        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        mmCreated.setSubject("test");
+        MimeMultipart mm = new MimeMultipart("alternative");
+        mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header:
test2\r\nContent-Type: text/plain; charset=Cp1252\r\nContent-Transfer-Encoding: quoted-printable\r\n".getBytes())),"second
part =E8=E8".getBytes()));
+        mmCreated.setContent(mm);
+        mmCreated.saveChanges();
+        return mmCreated;
+    }
+    
+
+    protected String getMissingEncodingMessageSource() {
+        return "Subject: test\r\n"
+        +"MIME-Version: 1.0\r\n"
+        +"Content-Type: multipart/alternative; \r\n" 
+        +"\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
+        +"\r\n"
+        +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+        +"X-header: test2\r\n"
+        +"Content-Type: text/plain; charset=Cp1252\r\n"
+        +"Content-Transfer-Encoding: quoted-printable\r\n"
+        +"\r\n"
+        +"second part =E8=E8\r\n"
+        +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
+    }
     
+
+    public void testGetLineCount() throws Exception {
+        MimeMessage mm = getMissingEncodingMessage();
+        try {
+            int count = mm.getLineCount();
+            assertTrue(count == -1 || count == 7);
+        } catch (Exception e) {
+            fail("Unexpected exception in getLineCount");
+        }
+    }
     
 }



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


Mime
View raw message