geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsny...@apache.org
Subject svn commit: r387976 - in /geronimo/specs/trunk/geronimo-spec-javamail/src: main/java/javax/mail/internet/ main/java/org/apache/geronimo/mail/util/ test/java/javax/mail/internet/
Date Thu, 23 Mar 2006 00:16:09 GMT
Author: bsnyder
Date: Wed Mar 22 16:16:06 2006
New Revision: 387976

URL: http://svn.apache.org/viewcvs?rev=387976&view=rev
Log:
Committed patch for GERONIMO-1760.

Added:
    geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeTest.java
Modified:
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMultipart.java
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64DecoderStream.java
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64EncoderStream.java

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java?rev=387976&r1=387975&r2=387976&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeBodyPart.java
Wed Mar 22 16:16:06 2006
@@ -399,7 +399,9 @@
         out.write('\r');
         out.write('\n');
         // we need to process this using the transfer encoding type
-        getDataHandler().writeTo(MimeUtility.encode(out, getEncoding()));
+        OutputStream encodingStream = MimeUtility.encode(out, getEncoding()); 
+        getDataHandler().writeTo(encodingStream);
+        encodingStream.flush();
     }
 
     public String[] getHeader(String name) throws MessagingException {

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMultipart.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMultipart.java?rev=387976&r1=387975&r2=387976&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMultipart.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMultipart.java
Wed Mar 22 16:16:06 2006
@@ -264,12 +264,11 @@
             if (boundaryIndex == boundary.length) { // boundary found
                 boundaryFound = true;
                 // read the end of line character
-                if (inStream.read() == 45) {
-                    //check whether end of stream
+                if (inStream.read() == 45 && value == 45) {
                     //Last mime boundary should have a succeeding "--"
-                    if (!((value = inStream.read()) == 45) && value != -1) {
-                        inStream.unread(value);
-                    }
+                    //as we are on it, read the terminating CRLF
+                    inStream.read();
+                    inStream.read();
                 }
                 return -1;
             }

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64DecoderStream.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64DecoderStream.java?rev=387976&r1=387975&r2=387976&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64DecoderStream.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64DecoderStream.java
Wed Mar 22 16:16:06 2006
@@ -127,7 +127,7 @@
 
             // now copy some of the data from the decoded buffer to the target buffer
             int copyCount = Math.min(decodedCount, length);
-            System.arraycopy(data, offset, decodedChars, decodedIndex, copyCount);
+            System.arraycopy(decodedChars, decodedIndex, data, offset, copyCount);
             decodedIndex += copyCount;
             decodedCount -= copyCount;
             offset += copyCount;

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64EncoderStream.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64EncoderStream.java?rev=387976&r1=387975&r2=387976&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64EncoderStream.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/Base64EncoderStream.java
Wed Mar 22 16:16:06 2006
@@ -134,6 +134,18 @@
             }
         }
     }
+    
+    public void close() throws IOException {
+        flush();
+        out.close();
+    }
+    
+    public void flush() throws IOException {
+        if (bufferedBytes > 0) {
+            encoder.encode(buffer, 0, bufferedBytes, out);
+            bufferedBytes = 0;
+        }
+    }
 
 
     /**

Added: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeTest.java?rev=387976&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeTest.java
(added)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeTest.java
Wed Mar 22 16:16:06 2006
@@ -0,0 +1,121 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package javax.mail.internet;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.mail.Session;
+
+import junit.framework.TestCase;
+
+public class MimeTest extends TestCase {
+
+    public void testWriteRead() throws Exception {
+        Session session = Session.getDefaultInstance(new Properties(), null);
+        MimeMessage mime = new MimeMessage(session);
+        MimeMultipart parts = new MimeMultipart("related; type=\"text/xml\"; start=\"<xml>\"");
+        MimeBodyPart xmlPart = new MimeBodyPart();
+        xmlPart.setContentID("<xml>");
+        xmlPart.setDataHandler(new DataHandler(new ByteArrayDataSource("<hello/>".getBytes(),
"text/xml")));
+        parts.addBodyPart(xmlPart);
+        MimeBodyPart jpegPart = new MimeBodyPart();
+        jpegPart.setContentID("<jpeg>");
+        jpegPart.setDataHandler(new DataHandler(new ByteArrayDataSource(new byte[] { 0, 1,
2, 3, 4, 5 }, "image/jpeg")));
+        parts.addBodyPart(jpegPart);
+        mime.setContent(parts);
+        mime.setHeader("Content-Type", parts.getContentType());
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        mime.writeTo(baos);
+        
+        System.out.println(baos);
+
+        MimeMessage mime2 = new MimeMessage(session, new ByteArrayInputStream(baos.toByteArray()));
+        assertTrue(mime2.getContent() instanceof MimeMultipart);
+        MimeMultipart parts2 = (MimeMultipart) mime2.getContent();
+        assertEquals(mime.getContentType(), mime2.getContentType());
+        assertEquals(parts.getCount(), parts2.getCount());
+        assertTrue(parts2.getBodyPart(0) instanceof MimeBodyPart);
+        assertTrue(parts2.getBodyPart(1) instanceof MimeBodyPart);
+        
+        MimeBodyPart xmlPart2 = (MimeBodyPart) parts2.getBodyPart(0);
+        assertEquals(xmlPart.getContentID(), xmlPart2.getContentID());
+        ByteArrayOutputStream xmlBaos = new ByteArrayOutputStream();
+        copyInputStream(xmlPart.getDataHandler().getInputStream(), xmlBaos);
+        ByteArrayOutputStream xmlBaos2 = new ByteArrayOutputStream(); 
+        copyInputStream(xmlPart2.getDataHandler().getInputStream(), xmlBaos2);
+        assertEquals(xmlBaos.toString(), xmlBaos2.toString());
+        
+        MimeBodyPart jpegPart2 = (MimeBodyPart) parts2.getBodyPart(1);
+        assertEquals(jpegPart.getContentID(), jpegPart2.getContentID());
+        ByteArrayOutputStream jpegBaos = new ByteArrayOutputStream();
+        copyInputStream(jpegPart.getDataHandler().getInputStream(), jpegBaos);
+        ByteArrayOutputStream jpegBaos2 = new ByteArrayOutputStream(); 
+        copyInputStream(jpegPart2.getDataHandler().getInputStream(), jpegBaos2);
+        assertEquals(jpegBaos.toString(), jpegBaos2.toString());
+    }
+    
+    public static class ByteArrayDataSource implements DataSource {
+        private byte[] data;
+        private String type;
+        private String name = "unused";
+        
+        public ByteArrayDataSource(byte[] data, String type) {
+            this.data = data;
+            this.type = type;
+        }
+
+        public InputStream getInputStream() throws IOException {
+            if (data == null) throw new IOException("no data");
+            return new ByteArrayInputStream(data);
+        }
+
+        public OutputStream getOutputStream() throws IOException {
+            throw new IOException("getOutputStream() not supported");
+        }
+
+        public String getContentType() {
+            return type;
+        }
+
+        public String getName() {
+            return name;
+        }
+        
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+    
+    public static void copyInputStream(InputStream in, OutputStream out) throws IOException
{
+        byte[] buffer = new byte[1024];
+        int len;
+        while ((len = in.read(buffer)) >= 0) {
+            out.write(buffer, 0, len);
+        }
+        in.close();
+        out.close();
+    }
+}



Mime
View raw message