[geary/wip/765516-gtk-widget-conversation-viewer: 114/119] Fix inline JPEGs being corrupted when converted to data URIs.



commit d6445c84cb6c763dba7d3e1c5f24488691379861
Author: Michael James Gratton <mike vee net>
Date:   Sun Aug 14 11:10:30 2016 +1000

    Fix inline JPEGs being corrupted when converted to data URIs.
    
    * src/engine/rfc822/rfc822-message.vala (mime_part_to_memory_buffer):
      Only do text processing on a part's stream if UTF-8 is requested.

 src/engine/rfc822/rfc822-message.vala |   44 ++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index 4369f6b..65faa1e 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -942,36 +942,40 @@ public class Geary.RFC822.Message : BaseObject {
         GMime.StreamMem stream = new GMime.StreamMem.with_byte_array(byte_array);
         stream.set_owner(false);
         
-        // Convert encoding to UTF-8.
-        GMime.StreamFilter stream_filter = new GMime.StreamFilter(stream);
         if (to_utf8) {
+            // Assume encoded text, convert to unencoded UTF-8
+            GMime.StreamFilter stream_filter = new GMime.StreamFilter(stream);
             string? charset = (content_type != null) ? content_type.params.get_value("charset") : null;
             if (String.is_empty(charset))
                 charset = DEFAULT_ENCODING;
             stream_filter.add(Geary.RFC822.Utils.create_utf8_filter_charset(charset));
-        }
-        
-        bool flowed = (content_type != null) ? content_type.params.has_value_ci("format", "flowed") : false;
-        bool delsp = (content_type != null) ? content_type.params.has_value_ci("DelSp", "yes") : false;
 
-        // Unconditionally remove the CR's in any CRLF sequence, since
-        // they are effectively a wire encoding.
-        stream_filter.add(new GMime.FilterCRLF(false, false));
+            bool flowed = (content_type != null) ? content_type.params.has_value_ci("format", "flowed") : 
false;
+            bool delsp = (content_type != null) ? content_type.params.has_value_ci("DelSp", "yes") : false;
+
+            // Unconditionally remove the CR's in any CRLF sequence, since
+            // they are effectively a wire encoding.
+            stream_filter.add(new GMime.FilterCRLF(false, false));
 
-        if (flowed)
-            stream_filter.add(new Geary.RFC822.FilterFlowed(to_html, delsp));
+            if (flowed)
+                stream_filter.add(new Geary.RFC822.FilterFlowed(to_html, delsp));
 
-        if (to_html) {
-            if (!flowed)
-                stream_filter.add(new Geary.RFC822.FilterPlain());
-            stream_filter.add(new GMime.FilterHTML(
-                GMime.FILTER_HTML_CONVERT_URLS | GMime.FILTER_HTML_CONVERT_ADDRESSES, 0));
-            stream_filter.add(new Geary.RFC822.FilterBlockquotes());
+            if (to_html) {
+                if (!flowed)
+                    stream_filter.add(new Geary.RFC822.FilterPlain());
+                stream_filter.add(new GMime.FilterHTML(
+                    GMime.FILTER_HTML_CONVERT_URLS | GMime.FILTER_HTML_CONVERT_ADDRESSES, 0));
+                stream_filter.add(new Geary.RFC822.FilterBlockquotes());
+            }
+
+            wrapper.write_to_stream(stream_filter);
+            stream_filter.flush();
+        } else {
+            // Keep as binary
+            wrapper.write_to_stream(stream);
+            stream.flush();
         }
 
-        wrapper.write_to_stream(stream_filter);
-        stream_filter.flush();
-        
         return new Geary.Memory.ByteBuffer.from_byte_array(byte_array);
     }
 


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