[evolution/gnome-3-30] I#288 - Fails to extract downloaded remote images from message preview



commit 49bcb2c5627fe8e8c89ae1d1e0ba0ba5d6bfdea3
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jan 21 16:25:56 2019 +0100

    I#288 - Fails to extract downloaded remote images from message preview
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/288

 src/mail/e-http-request.c                          | 62 +++++++++++++++++++++-
 src/mail/e-http-request.h                          |  3 ++
 src/mail/e-mail-display.c                          |  2 +-
 .../webkit-editor/web-extension/CMakeLists.txt     |  4 +-
 .../web-extension/e-editor-web-extension.c         |  6 ++-
 5 files changed, 72 insertions(+), 5 deletions(-)
---
diff --git a/src/mail/e-http-request.c b/src/mail/e-http-request.c
index 54e9bc1670..7f574d91b2 100644
--- a/src/mail/e-http-request.c
+++ b/src/mail/e-http-request.c
@@ -268,10 +268,12 @@ e_http_request_process_sync (EContentRequest *request,
 
        *out_stream_length = -1;
 
-       /* Use MD5 hash of the URI as a filname of the resourec cache file.
+       /* Use MD5 hash of the URI as a filname of the resource cache file.
         * We were previously using the URI as a filename but the URI is
         * sometimes too long for a filename. */
-       uri_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, use_uri, -1);
+       uri_md5 = e_http_request_util_compute_uri_checksum (use_uri);
+       if (!uri_md5)
+               goto cleanup;
 
        /* Open Evolution's cache */
        user_cache_dir = e_get_user_cache_dir ();
@@ -545,3 +547,59 @@ e_http_request_new (void)
 {
        return g_object_new (E_TYPE_HTTP_REQUEST, NULL);
 }
+
+/* Computes MD5 checksum of the URI with normalized URI query */
+gchar *
+e_http_request_util_compute_uri_checksum (const gchar *in_uri)
+{
+       GString *string;
+       SoupURI *soup_uri;
+       const gchar *soup_query;
+       gchar *md5, *uri;
+
+       g_return_val_if_fail (in_uri != NULL, NULL);
+
+       soup_uri = soup_uri_new (in_uri);
+       g_return_val_if_fail (soup_uri != NULL, NULL);
+
+       string = g_string_new ("");
+
+       soup_query = soup_uri_get_query (soup_uri);
+       if (soup_query) {
+               GHashTable *query;
+               GList *keys, *link;
+
+               query = soup_form_decode (soup_query);
+               keys = g_hash_table_get_keys (query);
+               keys = g_list_sort (keys, (GCompareFunc) g_strcmp0);
+               for (link = keys; link; link = g_list_next (link)) {
+                       const gchar *key, *value;
+
+                       key = link->data;
+                       if (key && *key) {
+                               value = g_hash_table_lookup (query, key);
+                               g_string_append_printf (string, "%s=%s;", key, value ? value : "");
+                       }
+               }
+               g_list_free (keys);
+               g_hash_table_unref (query);
+
+               soup_uri_set_query (soup_uri, NULL);
+       }
+
+       uri = soup_uri_to_string (soup_uri, FALSE);
+       g_string_append (string, uri ? uri : "");
+       g_free (uri);
+
+       /* This is not constructing real URI, only its query parameters in sorted
+          order with the URI part. */
+       if (string->len)
+               md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, string->str, -1);
+       else
+               md5 = NULL;
+
+       g_string_free (string, TRUE);
+       soup_uri_free (soup_uri);
+
+       return md5;
+}
diff --git a/src/mail/e-http-request.h b/src/mail/e-http-request.h
index bdbf009ec8..f4bd64a0c5 100644
--- a/src/mail/e-http-request.h
+++ b/src/mail/e-http-request.h
@@ -58,6 +58,9 @@ GType         e_http_request_get_type         (void) G_GNUC_CONST;
 EContentRequest *
                e_http_request_new              (void);
 
+gchar *                e_http_request_util_compute_uri_checksum
+                                               (const gchar *in_uri);
+
 
 G_END_DECLS
 
diff --git a/src/mail/e-mail-display.c b/src/mail/e-mail-display.c
index 4004d85194..1118239200 100644
--- a/src/mail/e-mail-display.c
+++ b/src/mail/e-mail-display.c
@@ -1668,7 +1668,7 @@ mail_display_image_exists_in_cache (const gchar *image_uri)
        if (!emd_global_http_cache)
                return FALSE;
 
-       hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, image_uri, -1);
+       hash = e_http_request_util_compute_uri_checksum (image_uri);
        filename = camel_data_cache_get_filename (
                emd_global_http_cache, "http", hash);
 
diff --git a/src/modules/webkit-editor/web-extension/CMakeLists.txt 
b/src/modules/webkit-editor/web-extension/CMakeLists.txt
index b2ccdc843e..a7f07ff742 100644
--- a/src/modules/webkit-editor/web-extension/CMakeLists.txt
+++ b/src/modules/webkit-editor/web-extension/CMakeLists.txt
@@ -1,4 +1,6 @@
-set(extra_deps)
+set(extra_deps
+       evolution-mail
+)
 set(sources
        e-composer-dom-functions.c
        e-composer-dom-functions.h
diff --git a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c 
b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
index d799db498e..eed7701c01 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -28,6 +28,10 @@
 
 #include <webkitdom/webkitdom.h>
 
+#define E_UTIL_INCLUDE_WITHOUT_WEBKIT
+#include "mail/e-http-request.h"
+#undef E_UTIL_INCLUDE_WITHOUT_WEBKIT
+
 #include "web-extensions/e-dom-utils.h"
 
 #include "e-editor-page.h"
@@ -2350,7 +2354,7 @@ image_exists_in_cache (const gchar *image_uri)
        if (!emd_global_http_cache)
                return FALSE;
 
-       hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, image_uri, -1);
+       hash = e_http_request_util_compute_uri_checksum (image_uri);
        filename = camel_data_cache_get_filename (
                emd_global_http_cache, "http", hash);
 


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