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 ba...@apache.org on 2006/03/03 12:23:20 UTC

svn commit: r382763 - in /james/server/trunk/src/java/org/apache/james: core/MimeMessageUtil.java transport/mailets/AbstractRedirect.java

Author: bago
Date: Fri Mar  3 03:23:17 2006
New Revision: 382763

URL: http://svn.apache.org/viewcvs?rev=382763&view=rev
Log:
Refactored AbstractRedirect to use the same writeMessage used by the MimeMessageWrapper (the code was identical)

Modified:
    james/server/trunk/src/java/org/apache/james/core/MimeMessageUtil.java
    james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java

Modified: james/server/trunk/src/java/org/apache/james/core/MimeMessageUtil.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/core/MimeMessageUtil.java?rev=382763&r1=382762&r2=382763&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/MimeMessageUtil.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/MimeMessageUtil.java Fri Mar  3 03:23:17 2006
@@ -19,6 +19,7 @@
 import org.apache.james.util.InternetPrintWriter;
 import org.apache.james.util.io.IOUtil;
 
+import javax.activation.UnsupportedDataTypeException;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeUtility;
@@ -77,27 +78,13 @@
         hos.println();
         hos.flush();
 
-        InputStream bis;
-        OutputStream bos;
         // Write the body to the output stream
+        writeMessageTo(message, bodyOs);
+    }
 
-        /*
-        try {
-            bis = message.getRawInputStream();
-            bos = bodyOs;
-        } catch(javax.mail.MessagingException me) {
-            // we may get a "No content" exception
-            // if that happens, try it the hard way
-
-            // Why, you ask?  In JavaMail v1.3, when you initially
-            // create a message using MimeMessage APIs, there is no
-            // raw content available.  getInputStream() works, but
-            // getRawInputStream() throws an exception.
-
-            bos = MimeUtility.encode(bodyOs, message.getEncoding());
-            bis = message.getInputStream();
-        }
-        */
+    public static void writeMessageTo(MimeMessage message, OutputStream bodyOs) throws IOException, UnsupportedDataTypeException, MessagingException {
+        OutputStream bos;
+        InputStream bis;
 
         try {
             // Get the message as a stream.  This will encode
@@ -106,7 +93,7 @@
             // raw stream, but see
             bos = MimeUtility.encode(bodyOs, message.getEncoding());
             bis = message.getInputStream();
-        } catch(javax.activation.UnsupportedDataTypeException udte) {
+        } catch(UnsupportedDataTypeException udte) {
             /* If we get an UnsupportedDataTypeException try using
              * the raw input stream as a "best attempt" at rendering
              * a message.

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java?rev=382763&r1=382762&r2=382763&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java Fri Mar  3 03:23:17 2006
@@ -41,6 +41,7 @@
 import org.apache.mailet.RFC2822Headers;
 import org.apache.mailet.dates.RFC822DateFormat;
 import org.apache.james.core.MailImpl;
+import org.apache.james.core.MimeMessageUtil;
 
 import org.apache.mailet.GenericMailet;
 import org.apache.mailet.Mail;
@@ -1175,76 +1176,9 @@
      * Message's body
      */
     private String getMessageBody(MimeMessage message) throws Exception {
-        java.io.InputStream bis = null;
-        java.io.OutputStream bos = null;
         java.io.ByteArrayOutputStream bodyOs = new java.io.ByteArrayOutputStream();
-
-        try {
-            try {
-                // Get the message as a stream.  This will encode
-                // objects as necessary, and we have some overhead from
-                // decoding and re-encoding the stream.  I'd prefer the
-                // raw stream, but see the WARNING below.
-                bos = javax.mail.internet.MimeUtility.encode(bodyOs, message.getEncoding());
-                bis = message.getInputStream();
-            } catch(javax.activation.UnsupportedDataTypeException udte) {
-                /* If we get an UnsupportedDataTypeException try using
-                 * the raw input stream as a "best attempt" at rendering
-                 * a message.
-                 *
-                 * WARNING: JavaMail v1.3 getRawInputStream() returns
-                 * INVALID (unchanged) content for a changed message.
-                 * getInputStream() works properly, but in this case
-                 * has failed due to a missing DataHandler.
-                 *
-                 * MimeMessage.getRawInputStream() may throw a "no
-                 * content" MessagingException.  In JavaMail v1.3, when
-                 * you initially create a message using MimeMessage
-                 * APIs, there is no raw content available.
-                 * getInputStream() works, but getRawInputStream()
-                 * throws an exception.  If we catch that exception,
-                 * throw the UDTE.  It should mean that someone has
-                 * locally constructed a message part for which JavaMail
-                 * doesn't have a DataHandler.
-                 */
-    
-                try {
-                    bis = message.getRawInputStream();
-                    bos = bodyOs;
-                } catch(javax.mail.MessagingException _) {
-                    throw udte;
-                }
-            }
-            catch(javax.mail.MessagingException me) {
-                /* This could be another kind of MessagingException
-                 * thrown by MimeMessage.getInputStream(), such as a
-                 * javax.mail.internet.ParseException.
-                 *
-                 * The ParseException is precisely one of the reasons
-                 * why the getRawInputStream() method exists, so that we
-                 * can continue to stream the content, even if we cannot
-                 * handle it.  Again, if we get an exception, we throw
-                 * the one that caused us to call getRawInputStream().
-                 */
-                try {
-                    bis = message.getRawInputStream();
-                    bos = bodyOs;
-                } catch(javax.mail.MessagingException _) {
-                    throw me;
-                }
-            }
-
-            byte[] block = new byte[1024];
-            int read = 0;
-            while ((read = bis.read(block)) > -1) {
-                bos.write(block, 0, read);
-            }
-            bos.flush();
-            return bodyOs.toString();
-        }
-        finally {
-            bis.close();
-        }
+        MimeMessageUtil.writeMessageTo(message,bodyOs);
+        return bodyOs.toString();
     }
 
     /**



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