[geary] Fix format=flowed when sending Base64 encoded text/plain. Bug 753528.



commit da96e96c70249b5a2d4a1f093df28dbfae11e1eb
Author: Michael James Gratton <mike vee net>
Date:   Thu Jun 30 17:35:16 2016 +1000

    Fix format=flowed when sending Base64 encoded text/plain. Bug 753528.
    
    Sending a message with a text/plain body containing many wide chars will
    usually result in it being encoded as Base64. This was breaking
    format=flowed since Geary was doing the LF=>CRLF conversion only when
    serialisaing for transmission, so the LF's in the unencoded text were not
    getting converted to CRLF, and hence all the line breaks were interpreted
    as hard breaks under F=F.
    
    * src/engine/rfc822/rfc822-message.vala (Message.from_composed_email):
      When setting the RFC822 message body/body part from the composed
      message, apply a CRLF filter first iff it will be encoded with Base64.

 src/engine/rfc822/rfc822-message.vala |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index 02cb40d..856716a 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -145,17 +145,27 @@ public class Geary.RFC822.Message : BaseObject {
         // Body: text format (optional)
         GMime.Part? body_text = null;
         if (email.body_text != null) {
-            GMime.StreamMem stream = new GMime.StreamMem.with_buffer(email.body_text.data);
-            GMime.DataWrapper content = new GMime.DataWrapper.with_stream(stream,
-                GMime.ContentEncoding.DEFAULT);
-            
+            GMime.Stream stream = new GMime.StreamMem.with_buffer(email.body_text.data);
+            GMime.ContentEncoding encoding = Geary.RFC822.Utils.get_best_content_encoding(
+                stream, GMime.EncodingConstraint.7BIT
+            );
+            if (encoding == GMime.ContentEncoding.BASE64) {
+                // Base64-encoded text needs to have CR's added after
+                // LF's before encoding, otherwise it breaks
+                // format=flowed. See bug 753528.
+                GMime.StreamFilter filter_stream = new GMime.StreamFilter(stream);
+                filter_stream.add(new GMime.FilterCRLF(true, false));
+                stream = filter_stream;
+            }
+            GMime.DataWrapper content = new GMime.DataWrapper.with_stream(
+                stream, GMime.ContentEncoding.DEFAULT
+            );
             body_text = new GMime.Part();
             body_text.set_content_type(new GMime.ContentType.from_string("text/plain; charset=utf-8; 
format=flowed"));
             body_text.set_content_object(content);
-            body_text.set_content_encoding(Geary.RFC822.Utils.get_best_content_encoding(stream,
-                GMime.EncodingConstraint.7BIT));
+            body_text.set_content_encoding(encoding);
         }
-        
+
         // Body: HTML format (also optional)
         GMime.Part? body_html = null;
         if (email.body_html != null) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]