[geary/mjog/771-html-not-wrapped-on-send: 3/3] Geary.RFC822.Message: Always re-determine the encoding for body parts



commit 2eb597fec13d5015f5f42a758447dfa7ba511c00
Author: Michael Gratton <mike vee net>
Date:   Sun Mar 29 16:29:30 2020 +1100

    Geary.RFC822.Message: Always re-determine the encoding for body parts
    
    When attaching body parts to a message from a composed email, don't
    re-use the transfer encoding used from the plain part for the HTML part,
    since the latter may be different if e.g. the HTML contains no line
    breaks and hence is a single long line.
    
    See #771

 src/engine/rfc822/rfc822-message.vala | 26 ++++++++++++--------------
 test/engine/rfc822-message-test.vala  | 15 +++++++++------
 2 files changed, 21 insertions(+), 20 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index b7df6725..4ef341c8 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -210,10 +210,12 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
 
         Gee.List<GMime.Object> body_parts = new Gee.LinkedList<GMime.Object>();
 
-        // Share the body charset and encoding between plain and HTML
-        // parts, so we don't need to work it out twice.
+        // Share the body charset between plain and HTML parts, so we
+        // don't need to work it out twice. This doesn't work for the
+        // content encoding however since the HTML encoding may need
+        // to be different, e.g. if it contains lines longer than
+        // allowed by RFC822/SMTP.
         string? body_charset = null;
-        GMime.ContentEncoding? body_encoding = null;
 
         // Body: text format (optional)
         if (email.body_text != null) {
@@ -222,7 +224,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
                 body_text = yield body_data_to_part(
                     email.body_text.data,
                     null,
-                    null,
                     "text/plain",
                     true,
                     cancellable
@@ -234,7 +235,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
                 body_charset = body_text.get_content_type().get_parameter(
                     "charset"
                 );
-                body_encoding = body_text.get_content_encoding();
                 body_parts.add(body_text);
             }
         }
@@ -324,7 +324,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
                 body_html = yield body_data_to_part(
                     email.body_html.data,
                     body_charset,
-                    body_encoding,
                     "text/html",
                     false,
                     cancellable
@@ -1146,7 +1145,6 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
      */
     private async GMime.Part body_data_to_part(uint8[] content,
                                                string? charset,
-                                               GMime.ContentEncoding? encoding,
                                                string content_type,
                                                bool is_flowed,
                                                GLib.Cancellable? cancellable)
@@ -1157,13 +1155,13 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
         }
         GMime.StreamFilter filter_stream = new GMime.StreamFilter(content_stream);
         filter_stream.add(new GMime.FilterCharset(UTF8_CHARSET, charset));
-        if (encoding == null) {
-            encoding = yield Utils.get_best_encoding(
-                filter_stream,
-                GMime.EncodingConstraint.7BIT,
-                cancellable
-            );
-        }
+
+        GMime.ContentEncoding encoding = yield Utils.get_best_encoding(
+            filter_stream,
+            GMime.EncodingConstraint.7BIT,
+            cancellable
+        );
+
         if (is_flowed && encoding == GMime.ContentEncoding.BASE64) {
             // Base64-encoded text needs to have CR's added after LF's
             // before encoding, otherwise it breaks format=flowed. See
diff --git a/test/engine/rfc822-message-test.vala b/test/engine/rfc822-message-test.vala
index c99865f9..2f1ab3f9 100644
--- a/test/engine/rfc822-message-test.vala
+++ b/test/engine/rfc822-message-test.vala
@@ -236,7 +236,6 @@ This is the second line.
         Geary.RFC822.Message message = message_from_composed_email.end(async_result());
 
         string message_data = message.get_network_buffer(true).to_string();
-        print("\n'%s'\n", message_data);
         assert_true(message_data.has_suffix("..newline\r\n..\r\n"));
     }
 
@@ -251,10 +250,14 @@ This is the second line.
             new GLib.DateTime.now_local(),
             new Geary.RFC822.MailboxAddresses.single(from)
         ).set_to(new Geary.RFC822.MailboxAddresses.single(to));
-        composed.body_text = """
-long long long long long long long long long long long long long long long long long
-""";
-        composed.body_html = "<p>%s<p>".printf(composed.body_text);
+
+        GLib.StringBuilder buf = new GLib.StringBuilder();
+        for (int i = 0; i < 2000; i++) {
+            buf.append("long ");
+        }
+
+        //composed.body_text = buf.str;
+        composed.body_html = "<p>%s<p>".printf(buf.str);
 
         this.message_from_composed_email.begin(
             composed,
@@ -264,7 +267,7 @@ long long long long long long long long long long long long long long long long
 
         string message_data = message.get_network_buffer(true).to_string();
         foreach (var line in message_data.split("\n")) {
-            assert_true(line.length < 80, line);
+            assert_true(line.length < 1000, line);
         }
     }
 


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