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 2008/06/26 18:48:53 UTC

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

Author: bago
Date: Thu Jun 26 09:48:53 2008
New Revision: 671943

URL: http://svn.apache.org/viewvc?rev=671943&view=rev
Log:
RemoteDelivery convertTo7Bit() can corrupt message content. (JAMES-846)
Based on a bugreport+patch provided by Rick McGuire

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

Modified: james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=671943&r1=671942&r2=671943&view=diff
==============================================================================
--- james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java (original)
+++ james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java Thu Jun 26 09:48:53 2008
@@ -916,14 +916,17 @@
                 convertTo7Bit((MimePart)parts.getBodyPart(i));
             }
         } else {
-            if (part.isMimeType("text/*")) {
-                part.setHeader("Content-Transfer-Encoding", "quoted-printable");
-                part.addHeader("X-MIME-Autoconverted", "from 8bit to quoted-printable by "+getMailetContext().getServerInfo());
-            } else {
-                // 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());
-            }
+            // The content may already be in encoded the form (likely with mail created from a
+            // stream).  In that case, just changing the encoding to quoted-printable will mangle 
+            // the result when this is transmitted.  We must first convert the content into its 
+            // native format, set it back, and only THEN set the transfer encoding to force the 
+            // content to be encoded appropriately.
+            
+            // if the part doesn't contain text it will be base64 encoded.
+            String contentTransferEncoding = part.isMimeType("text/*") ? "quoted-printable" : "base64";
+            part.setContent(part.getContent(), part.getContentType()); 
+            part.setHeader("Content-Transfer-Encoding", contentTransferEncoding);
+            part.addHeader("X-MIME-Autoconverted", "from 8bit to "+contentTransferEncoding+" by "+getMailetContext().getServerInfo());
         }
     }
     



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


Re: svn commit: r671943 - /james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java

Posted by Rick McGuire <ri...@gmail.com>.
Stefano Bagnara wrote:
> Rick McGuire ha scritto:
>> Shouldn't you be maintaining the check for the current encoding being 
>> "8bit" before changing this?  This can remove the need for 
>> unnecessary encoding/decoding.  In particular, the MIMEMessage class 
>> when it transmits attempts to determine the most optimal encoding 
>> based on the data.  So, for example, a text part might be using a 
>> base64 encoding because it contains a high percentage of characters 
>> that would be encoded.   Unconditionally forcing this to Q-P bypasses 
>> this optimization.  And if the text is already in Q-P format, then 
>> this will force it to be decoded and reencoded again.
>> Rick
>
> I saw your comment about the "8bit check", but I didn't see that check 
> in the patch you submitted.
>
> Can you check the JIRA issue?
I get to drag out one of my favorite quotes:  "A man with one watch 
always knows what time it is, a man with two is never sure".  The same 
thing applies to builds!  The 8bit test was an improvement I added to 
the build version that was using the geronimo javamail, not the one I 
generated the patch from (sigh).  Anyway, it was a simple change: 

            // only convert if 8bit encoding is indicated
            String encoding = part.getEncoding();
            if (encoding != null && encoding.equals("8bit") {
                // The content may already be in encoded the form 
(likely with mail created from a
                // stream).  In that case, just changing the encoding to 
quoted-printable will mangle
                // the result when this is transmitted.  We must first 
convert the content into its
                // native format, set it back, and only THEN set the 
transfer encoding to force the
                // content to be encoded appropriately.
                if (part.isMimeType("text/*")) {
                    part.setContent(part.getContent(), 
part.getContentType());
                    part.setHeader("Content-Transfer-Encoding", 
"quoted-printable");
                    part.addHeader("X-MIME-Autoconverted", "from 8bit to 
quoted-printable by "+getMailetContext().getServerInfo());
                } else {
                    // if the part doesn't contain text it will be 
base64 encoded.
                    part.setContent(part.getContent(), 
part.getContentType());
                    part.setHeader("Content-Transfer-Encoding", "base64");
                    part.addHeader("X-MIME-Autoconverted", "from 8bit to 
base64 by "+getMailetContext().getServerInfo());
                }
            }


Rick




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


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


Re: svn commit: r671943 - /james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java

Posted by Stefano Bagnara <ap...@bago.org>.
Rick McGuire ha scritto:
> Shouldn't you be maintaining the check for the current encoding being 
> "8bit" before changing this?  This can remove the need for unnecessary 
> encoding/decoding.  In particular, the MIMEMessage class when it 
> transmits attempts to determine the most optimal encoding based on the 
> data.  So, for example, a text part might be using a base64 encoding 
> because it contains a high percentage of characters that would be 
> encoded.   Unconditionally forcing this to Q-P bypasses this 
> optimization.  And if the text is already in Q-P format, then this will 
> force it to be decoded and reencoded again.
> Rick

I saw your comment about the "8bit check", but I didn't see that check 
in the patch you submitted.

Can you check the JIRA issue?

Thank you,
Stefano


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


Re: svn commit: r671943 - /james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java

Posted by Rick McGuire <ri...@gmail.com>.
Shouldn't you be maintaining the check for the current encoding being 
"8bit" before changing this?  This can remove the need for unnecessary 
encoding/decoding.  In particular, the MIMEMessage class when it 
transmits attempts to determine the most optimal encoding based on the 
data.  So, for example, a text part might be using a base64 encoding 
because it contains a high percentage of characters that would be 
encoded.   Unconditionally forcing this to Q-P bypasses this 
optimization.  And if the text is already in Q-P format, then this will 
force it to be decoded and reencoded again. 

Rick


bago@apache.org wrote:
> Author: bago
> Date: Thu Jun 26 09:48:53 2008
> New Revision: 671943
>
> URL: http://svn.apache.org/viewvc?rev=671943&view=rev
> Log:
> RemoteDelivery convertTo7Bit() can corrupt message content. (JAMES-846)
> Based on a bugreport+patch provided by Rick McGuire
>
> Modified:
>     james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
>
> Modified: james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=671943&r1=671942&r2=671943&view=diff
> ==============================================================================
> --- james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java (original)
> +++ james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java Thu Jun 26 09:48:53 2008
> @@ -916,14 +916,17 @@
>                  convertTo7Bit((MimePart)parts.getBodyPart(i));
>              }
>          } else {
> -            if (part.isMimeType("text/*")) {
> -                part.setHeader("Content-Transfer-Encoding", "quoted-printable");
> -                part.addHeader("X-MIME-Autoconverted", "from 8bit to quoted-printable by "+getMailetContext().getServerInfo());
> -            } else {
> -                // 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());
> -            }
> +            // The content may already be in encoded the form (likely with mail created from a
> +            // stream).  In that case, just changing the encoding to quoted-printable will mangle 
> +            // the result when this is transmitted.  We must first convert the content into its 
> +            // native format, set it back, and only THEN set the transfer encoding to force the 
> +            // content to be encoded appropriately.
> +            
> +            // if the part doesn't contain text it will be base64 encoded.
> +            String contentTransferEncoding = part.isMimeType("text/*") ? "quoted-printable" : "base64";
> +            part.setContent(part.getContent(), part.getContentType()); 
> +            part.setHeader("Content-Transfer-Encoding", contentTransferEncoding);
> +            part.addHeader("X-MIME-Autoconverted", "from 8bit to "+contentTransferEncoding+" by "+getMailetContext().getServerInfo());
>          }
>      }
>      
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>
>   


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