[geary] Remove inline images that are included by Content-ID reference



commit 787d572e2229c06725837ce704a4eaab4a3db968
Author: Robert Schroll <rschroll gmail com>
Date:   Fri Aug 1 16:18:33 2014 -0400

    Remove inline images that are included by Content-ID reference

 .../conversation-viewer/conversation-viewer.vala   |   17 ++++++++++++++---
 src/engine/rfc822/rfc822-message.vala              |    4 ++--
 2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index bbc11fe..4630eeb 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -730,7 +730,7 @@ public class ConversationViewer : Gtk.Box {
     }
     
     private static string? inline_image_replacer(string filename, Geary.Mime.ContentType? content_type,
-        Geary.Mime.ContentDisposition? disposition, Geary.Memory.Buffer buffer) {
+        Geary.Mime.ContentDisposition? disposition, string? content_id, Geary.Memory.Buffer buffer) {
         if (content_type == null || !is_content_type_supported_inline(content_type)) {
             debug("Not displaying %s inline: unsupported Content-Type", content_type.to_string());
             
@@ -772,9 +772,10 @@ public class ConversationViewer : Gtk.Box {
             debug("Unable to load and rotate image %s for display: %s", filename, err.message);
         }
         
-        return "<img alt=\"%s\" class=\"%s %s\" src=\"%s\" />".printf(
+        return "<img alt=\"%s\" class=\"%s %s\" src=\"%s\" %s />".printf(
             filename, DATA_IMAGE_CLASS, REPLACED_IMAGE_CLASS,
-            assemble_data_uri(content_type.get_mime_type(), rotated_image));
+            assemble_data_uri(content_type.get_mime_type(), rotated_image),
+            content_id != null ? @"cid=\"$content_id\"" : "");
     }
     
     // Called by Gdk.PixbufLoader when the image's size has been determined but not loaded yet ...
@@ -1738,6 +1739,16 @@ public class ConversationViewer : Gtk.Box {
                     remote_images = true;
                 }
             }
+            
+            // Remove any inline images that were referenced through Content-ID
+            foreach (string cid in inlined_content_ids) {
+                try {
+                    WebKit.DOM.Element img = container.query_selector(@"[cid='$cid']");
+                    img.parent_element.remove_child(img);
+                } catch (Error error) {
+                    // expected if no such element
+                }
+            }
 
             // Now return the whole message.
             return container.get_inner_html();
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index 001038d..ae06fa3 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -10,7 +10,7 @@ public class Geary.RFC822.Message : BaseObject {
      * to process arbitrary non-text, inline MIME parts.
      */
     public delegate string? InlinePartReplacer(string filename, Mime.ContentType? content_type,
-        Mime.ContentDisposition? disposition, Geary.Memory.Buffer buffer);
+        Mime.ContentDisposition? disposition, string? content_id, Geary.Memory.Buffer buffer);
     
     private const string DEFAULT_ENCODING = "UTF8";
     
@@ -512,7 +512,7 @@ public class Geary.RFC822.Message : BaseObject {
         
         // Hand off to the replacer for processing
         string? replaced_part = replacer(RFC822.Utils.get_clean_attachment_filename(part), content_type,
-            disposition, mime_part_to_memory_buffer(part));
+            disposition, part.get_content_id(), mime_part_to_memory_buffer(part));
         if (replaced_part != null)
             body = replaced_part;
         


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