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 2005/09/05 13:29:12 UTC

svn commit: r278719 - /james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java

Author: bago
Date: Mon Sep  5 04:29:08 2005
New Revision: 278719

URL: http://svn.apache.org/viewcvs?rev=278719&view=rev
Log:
fix for NPE in 8bitmime support (workaround for javamail bug) (JAMES-419)
Thanks to Mirko Montanari for the patch.

Modified:
    james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=278719&r1=278718&r2=278719&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java Mon Sep  5 04:29:08 2005
@@ -508,9 +508,23 @@
                                     log("Error during the conversion to 7 bit.", e);
                                 }
                             }
+                            
+                            /*
+                             * Workaround for a javamail 1.3.2 bug: if
+                             * a message is sent without encoding information
+                             * and the 8bit allow property is set an exception
+                             * is trown during the mail delivery.
+                             */
+                            
+                            try {
+                                setEncodingIfMissing(message);
+                            } catch (IOException e) {
+                                log("Error while adding encoding information to the message", e);
+                            }
                         } else {
                             // If the transport is not the one
-                            // developed by Sun we are not sure of how it handles the 8 bit mime stuff, 
+                            // developed by Sun we are not sure of how it
+                            // handles the 8 bit mime stuff,
                             // so I convert the message to 7bit.
                             try {
                                 convertTo7Bit(message);
@@ -742,6 +756,29 @@
                 // if the part doesn't contain text it will be base64 encoded.
                 part.setHeader("Content-Transfer-Encoding", "base64");
                 part.addHeader("X-MIME-Autoconverted", "from 8bit to base64 by "+getMailetContext().getServerInfo());
+            }
+        }
+    }
+    
+    /**
+     * Adds an encoding information to each text mime part. This is a workaround
+     * for a javamail 1.3.2 bug: if a message is sent without encoding
+     * information a null pointer exception is thrown during the message
+     * delivery.
+     * 
+     * @param part
+     * @throws MessagingException
+     * @throws IOException
+     */
+    private void setEncodingIfMissing(MimePart part) throws MessagingException, IOException {
+        if (part.isMimeType("text/*")) {
+            String enc = part.getEncoding();
+            if (enc == null) part.setHeader("Content-Transfer-Encoding", "7bit");
+        } else if (part.isMimeType("multipart/*")) {
+            MimeMultipart parts = (MimeMultipart) part.getContent();
+            int count = parts.getCount();
+            for (int i = 0; i < count; i++) {
+                setEncodingIfMissing((MimePart)parts.getBodyPart(i));
             }
         }
     }



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