[balsa/html-filter] HTML filter bug fixes and clarifications



commit b393a6d650327cc084895023fed7358ba6db04cb
Author: Albrecht Dreß <albrecht dress netcologne de>
Date:   Sat Nov 6 21:23:40 2021 +0100

    HTML filter bug fixes and clarifications
    
    Fix bugs reported by @peterb in #62#note_1304251:
    
    - do not show the info bar re. loading external content if the sender
    preference in the database is set
    - rename functions, parameters, etc. to indicate that external contents
    is loaded, not only images
    - fix user messages
    
    Signed-off-by: Albrecht Dreß <albrecht dress netcologne de>

 libbalsa/html-pref-db.c       | 23 +++++++++++++----------
 libbalsa/html-pref-db.h       | 12 ++++++------
 libbalsa/html.c               | 28 ++++++++++++++--------------
 src/balsa-mime-widget-text.c  | 12 ++++++------
 src/balsa-print-object-html.c |  2 +-
 src/balsa-print-object.h      |  2 +-
 src/print-gtk.c               | 17 +++++++++--------
 7 files changed, 50 insertions(+), 46 deletions(-)
---
diff --git a/libbalsa/html-pref-db.c b/libbalsa/html-pref-db.c
index 70d8fdda1..7e0bbbee4 100644
--- a/libbalsa/html-pref-db.c
+++ b/libbalsa/html-pref-db.c
@@ -39,11 +39,13 @@
 enum {
        PREFS_ADDRESS_COLUMN = 0,
        PREFS_PREFER_HTML_COLUMN,
-       PREFS_LOAD_IMAGES_COLUMN,
+       PREFS_LOAD_EXT_CONTENT,
        PREFS_DB_VIEW_COLUMNS
 };
 
 
+/* Note: the database column prefer_load_img actually indicates if any external content shall be loaded.  
The naming is kept for
+ * backward compatibility from previous versions where only loading external images automatically could be 
configured. */
 #define DB_SCHEMA                                                              \
        "PRAGMA auto_vacuum = 1;"                                       \
        "CREATE TABLE html_prefs("                                      \
@@ -95,7 +97,7 @@ libbalsa_html_get_prefer_html(InternetAddressList *from)
 
 
 gboolean
-libbalsa_html_get_load_images(InternetAddressList *from)
+libbalsa_html_get_load_content(InternetAddressList *from)
 {
        return pref_db_get(from, 2);
 }
@@ -109,7 +111,7 @@ libbalsa_html_prefer_set_prefer_html(InternetAddressList *from, gboolean state)
 
 
 void
-libbalsa_html_prefer_set_load_images(InternetAddressList *from, gboolean state)
+libbalsa_html_prefer_set_load_content(InternetAddressList *from, gboolean state)
 {
        pref_db_set_ial(from, 2, state);
 }
@@ -150,7 +152,7 @@ libbalsa_html_pref_dialog_run(GtkWindow *parent)
        model = gtk_list_store_new(PREFS_DB_VIEW_COLUMNS,
                G_TYPE_STRING,                  /* address */
                G_TYPE_BOOLEAN,                 /* prefer html over plain text */
-               G_TYPE_BOOLEAN);                /* auto-load images */
+               G_TYPE_BOOLEAN);                /* auto-load external content */
 
        tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
 
@@ -174,7 +176,7 @@ libbalsa_html_pref_dialog_run(GtkWindow *parent)
                gtk_list_store_set(model, &iter,
                        PREFS_ADDRESS_COLUMN, sqlite3_column_text(query[4], 0),
                        PREFS_PREFER_HTML_COLUMN, sqlite3_column_int(query[4], 1),
-                       PREFS_LOAD_IMAGES_COLUMN, sqlite3_column_int(query[4], 2),
+                       PREFS_LOAD_EXT_CONTENT, sqlite3_column_int(query[4], 2),
                        -1);
                sqlite_res = sqlite3_step(query[4]);
        }
@@ -197,9 +199,10 @@ libbalsa_html_pref_dialog_run(GtkWindow *parent)
        gtk_widget_show_all(vbox);
 
        renderer = gtk_cell_renderer_toggle_new();
-       g_object_set_data(G_OBJECT(renderer), "dbcol", GINT_TO_POINTER(PREFS_LOAD_IMAGES_COLUMN));
+       g_object_set_data(G_OBJECT(renderer), "dbcol", GINT_TO_POINTER(PREFS_LOAD_EXT_CONTENT));
        g_signal_connect(renderer, "toggled", G_CALLBACK(on_prefs_button_toggled), model);
-       column = gtk_tree_view_column_new_with_attributes(_("Auto-load images"), renderer, "active", 
PREFS_LOAD_IMAGES_COLUMN, NULL);
+       column = gtk_tree_view_column_new_with_attributes(_("Auto-load external content"), renderer, 
"active", PREFS_LOAD_EXT_CONTENT,
+               NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
        gtk_tree_view_column_set_resizable(column, TRUE);
        gtk_widget_show_all(vbox);
@@ -283,7 +286,7 @@ pref_db_check(void)
 /** \brief Get the HTML preferences setting for a sender
  *
  * \param from From: address list, may be NULL or empty
- * \param col 1 prefer HTML, 2 auto-load images
+ * \param col 1 prefer HTML, 2 auto-load external content
  * \return the requested setting, FALSE on error, empty address list or missing entry
  */
 static gboolean
@@ -328,7 +331,7 @@ pref_db_get(InternetAddressList *from, int col)
 /** \brief Set the HTML preferences setting for a sender
  *
  * \param from From: address list, must not be NULL
- * \param pref_idx 1 prefer HTML, 2 auto-load images
+ * \param pref_idx 1 prefer HTML, 2 auto-load external content
  */
 static void
 pref_db_set_ial(InternetAddressList *from, int pref_idx, gboolean value)
@@ -350,7 +353,7 @@ pref_db_set_ial(InternetAddressList *from, int pref_idx, gboolean value)
 /** \brief Set the HTML preferences setting for a sender
  *
  * \param sender From: mailbox, must not be NULL
- * \param pref_idx 1 prefer HTML, 2 auto-load images
+ * \param pref_idx 1 prefer HTML, 2 auto-load external content
  * \return TRUE if the operation was successful
  */
 static gboolean
diff --git a/libbalsa/html-pref-db.h b/libbalsa/html-pref-db.h
index 4f3f90e2a..c22391429 100644
--- a/libbalsa/html-pref-db.h
+++ b/libbalsa/html-pref-db.h
@@ -39,12 +39,12 @@
  */
 gboolean libbalsa_html_get_prefer_html(InternetAddressList *from);
 
-/** \brief Check if images in HTML messages from a sender shall be loaded automatically
+/** \brief Check if external content in HTML messages from a sender shall be loaded automatically
  *
  * \param from From: address list, may be NULL or empty
- * \return TRUE if images in HTML messages shall be loaded without confirmation
+ * \return TRUE if external content in HTML messages shall be loaded without confirmation
  */
-gboolean libbalsa_html_get_load_images(InternetAddressList *from);
+gboolean libbalsa_html_get_load_content(InternetAddressList *from);
 
 /** \brief Remember if HTML is preferred for messages from a sender
  *
@@ -55,13 +55,13 @@ gboolean libbalsa_html_get_load_images(InternetAddressList *from);
 void libbalsa_html_prefer_set_prefer_html(InternetAddressList *from,
                                           gboolean             state);
 
-/** \brief Remember if images in HTML messages from a sender shall be loaded automatically
+/** \brief Remember if external content in HTML messages from a sender shall be loaded automatically
  *
  * \param from From: address list, must not be NULL
- * \param state TRUE if images in HTML messages shall be loaded without confirmation
+ * \param state TRUE if external content in HTML messages shall be loaded without confirmation
  * \note The function is a no-op if the InternetAddressList does not contain an InternetAddressMailbox as 
1st element.
  */
-void libbalsa_html_prefer_set_load_images(InternetAddressList *from,
+void libbalsa_html_prefer_set_load_content(InternetAddressList *from,
                                           gboolean             state);
 
 /** \brief Show the dialogue for managing the HTML preferences database
diff --git a/libbalsa/html.c b/libbalsa/html.c
index 42532561e..4ed0f6b30 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -391,7 +391,7 @@ lbh_load_external_resources(WebKitWebView *web_view, gboolean load_resources)
 
 
 /*
- * Show the GtkInfoBar for asking about downloading images
+ * Show the GtkInfoBar for asking about downloading external content
  *
  * First two signal callbacks
  */
@@ -437,12 +437,12 @@ lbh_info_bar(LibBalsaWebKitInfo * info)
     GtkWidget *label;
     GtkWidget *content_area;
     static const gchar text[] =
-                 N_("This message part references contents on one or more external servers. "
-                       "To protect your privacy, Balsa has not downloaded them. You may choose "
-                       "to download them if you trust the sender of the message.");
+                 N_("This message part references content on one or more external servers. "
+                       "To protect your privacy, Balsa has not downloaded it. You may choose "
+                       "to download it if you trust the sender of the message.");
 
     info_bar_widget =
-        gtk_info_bar_new_with_buttons(_("_Download external contents"),
+        gtk_info_bar_new_with_buttons(_("_Download external content"),
                                      GTK_RESPONSE_OK,
                                      _("_Close"), GTK_RESPONSE_CLOSE,
                                      NULL);
@@ -690,7 +690,7 @@ lbh_get_web_view_context(void)
 static WebKitWebView *
 lbh_web_view_new(LibBalsaWebKitInfo *info,
                                 gint                            width,
-                                gboolean            auto_load_images)
+                                gboolean            auto_load_ext_content)
 {
        WebKitWebView *view;
        WebKitSettings *settings;
@@ -710,8 +710,8 @@ lbh_web_view_new(LibBalsaWebKitInfo *info,
        webkit_settings_set_enable_java(settings, FALSE);
        webkit_settings_set_enable_hyperlink_auditing(settings, TRUE);
        webkit_settings_set_auto_load_images(settings,
-               auto_load_images || (g_atomic_int_get(&html_filter_found) != 0));
-       lbh_load_external_resources(view, auto_load_images);
+               auto_load_ext_content || (g_atomic_int_get(&html_filter_found) != 0));
+       lbh_load_external_resources(view, auto_load_ext_content);
 
        g_signal_connect(view, "web-process-terminated", G_CALLBACK(lbh_web_process_terminated_cb), info);
     g_signal_connect(view, "decide-policy", G_CALLBACK(lbh_decide_policy_cb), info);
@@ -747,13 +747,13 @@ dump_snapshot(GObject      *source_object,
  *
  * \param body HTML message body part
  * \param width rendering width in Cairo units (1/72")
- * \param load_external_images whether external images referenced by the HTML shall be loaded
+ * \param load_external_content whether external content referenced by the HTML shall be loaded
  * \return a cairo surface on success, or NULL on error
  */
 cairo_surface_t *
 libbalsa_html_print_bitmap(LibBalsaMessageBody *body,
                                                   gdouble                              width,
-                                                  gboolean                     load_external_images)
+                                                  gboolean                     load_external_content)
 {
        gint render_width;
     gchar *text;
@@ -780,7 +780,7 @@ libbalsa_html_print_bitmap(LibBalsaMessageBody *body,
        render_width = (gint) (width * HTML_PRINT_DPI / 72.0);
        g_debug("%s: request Cairo width %g, render width %d", __func__, width, render_width);
     gtk_window_set_default_size(GTK_WINDOW(offline_window), render_width, LBH_NATURAL_SIZE);
-    view = lbh_web_view_new(info, render_width, load_external_images || (have_src_cid && !have_src_oth));
+    view = lbh_web_view_new(info, render_width, load_external_content || (have_src_cid && !have_src_oth));
     webkit_web_view_set_zoom_level(view, HTML_PRINT_ZOOM);                     /* heuristic setting, any way 
to calculate it? */
     gtk_container_add(GTK_CONTAINER(offline_window), GTK_WIDGET(view));
     gtk_widget_show_all(offline_window);
@@ -829,7 +829,7 @@ GtkWidget *
 libbalsa_html_new(LibBalsaMessageBody * body,
                   LibBalsaHtmlCallback  hover_cb,
                   LibBalsaHtmlCallback  clicked_cb,
-                  gboolean              auto_load_images)
+                  gboolean              auto_load_ext_content)
 {
     gchar *text;
     gssize len;
@@ -851,7 +851,7 @@ libbalsa_html_new(LibBalsaMessageBody * body,
     have_src_oth = g_regex_match_simple(SRC_REGEX, text, G_REGEX_CASELESS, 0);
 
     info->web_view = lbh_web_view_new(info, LBH_NATURAL_SIZE,
-       auto_load_images || (have_src_cid && !have_src_oth));
+       auto_load_ext_content || (have_src_cid && !have_src_oth));
 
     g_signal_connect(info->web_view, "mouse-target-changed",
                      G_CALLBACK(lbh_mouse_target_changed_cb), info);
@@ -862,7 +862,7 @@ libbalsa_html_new(LibBalsaMessageBody * body,
     gtk_box_pack_end(GTK_BOX(vbox), GTK_WIDGET(info->web_view), TRUE, TRUE, 0);
 
     /* Simple check for possible resource requests: */
-    if (have_src_oth) {
+    if (have_src_oth && !auto_load_ext_content) {
         info->info_bar = lbh_info_bar(info);
         gtk_box_pack_start(GTK_BOX(vbox), info->info_bar, FALSE, FALSE, 0);
         g_debug("%s shows info_bar", __func__);
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 9a5a81987..7c9e83aea 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1112,10 +1112,10 @@ bmwt_html_prefer_html_changed(GtkCheckMenuItem *checkmenuitem,
 }
 
 static void
-bmwt_html_load_images_changed(GtkCheckMenuItem *checkmenuitem,
+bmwt_html_load_external_content_changed(GtkCheckMenuItem *checkmenuitem,
                               gpointer          user_data)
 {
-       libbalsa_html_prefer_set_load_images(INTERNET_ADDRESS_LIST(user_data),
+       libbalsa_html_prefer_set_load_content(INTERNET_ADDRESS_LIST(user_data),
                gtk_check_menu_item_get_active(checkmenuitem));
 }
 
@@ -1187,11 +1187,11 @@ bmwt_html_populate_popup_menu(BalsaMessage * bm,
     g_signal_connect(menuitem, "toggled", G_CALLBACK(bmwt_html_prefer_html_changed), from);
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
-    menuitem = gtk_check_menu_item_new_with_label(_("Load images for this sender"));
+    menuitem = gtk_check_menu_item_new_with_label(_("Load external content for this sender"));
     gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
-        libbalsa_html_get_load_images(from));
+        libbalsa_html_get_load_content(from));
     gtk_widget_set_sensitive(menuitem, from != NULL);
-    g_signal_connect(menuitem, "toggled", G_CALLBACK(bmwt_html_load_images_changed), from);
+    g_signal_connect(menuitem, "toggled", G_CALLBACK(bmwt_html_load_external_content_changed), from);
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
     gtk_widget_show_all(GTK_WIDGET(menu));
@@ -1276,7 +1276,7 @@ bm_widget_new_html(BalsaMessage * bm, LibBalsaMessageBody * mime_body)
         libbalsa_html_new(mime_body,
                          (LibBalsaHtmlCallback) bm_widget_on_url,
                          (LibBalsaHtmlCallback) handle_url,
-                         libbalsa_html_get_load_images(from));
+                         libbalsa_html_get_load_content(from));
     gtk_container_add(GTK_CONTAINER(mwt), widget);
 
     g_object_set_data(G_OBJECT(widget), "mime-body", mime_body);
diff --git a/src/balsa-print-object-html.c b/src/balsa-print-object-html.c
index f51dde5a5..d51496c4d 100644
--- a/src/balsa-print-object-html.c
+++ b/src/balsa-print-object-html.c
@@ -92,7 +92,7 @@ balsa_print_object_html(GList                                 *list,
     c_use_width = psetup->c_width - 2.0 * psetup->curr_depth * C_LABEL_SEP;
 
     /* render the HTML part into a surface, fall back to default if this fails */
-    html_surface = libbalsa_html_print_bitmap(body, c_use_width, psetup->html_load_images);
+    html_surface = libbalsa_html_print_bitmap(body, c_use_width, psetup->html_load_ext_content);
     if (html_surface == NULL) {
        return balsa_print_object_default(list, context, body, psetup);
     }
diff --git a/src/balsa-print-object.h b/src/balsa-print-object.h
index f43eda597..2681b623b 100644
--- a/src/balsa-print-object.h
+++ b/src/balsa-print-object.h
@@ -49,7 +49,7 @@ typedef struct {
     /* note: the following two fields are relevant only if HTML support is enabled;
      * don't hide them for code simplicity even if HTML support is disabled */
     gboolean print_alt_html;   /* print text/html in multipart/alternative */
-    gboolean html_load_images; /* load external images when printing text/html */
+    gboolean html_load_ext_content;    /* load external content when printing text/html */
 } BalsaPrintSetup;
 
 
diff --git a/src/print-gtk.c b/src/print-gtk.c
index fb3bcbe2e..9e6602941 100644
--- a/src/print-gtk.c
+++ b/src/print-gtk.c
@@ -51,9 +51,9 @@ typedef struct {
     GtkWidget *margin_right;
 #ifdef HAVE_HTML_WIDGET
     GtkWidget *html_print;
-    GtkWidget *html_load_imgs;
+    GtkWidget *html_load_ext_content;
     gboolean prefer_text;
-    gboolean load_images;
+    gboolean load_ext_content;
     BalsaPrintSetup *setup;
 #endif
 } BalsaPrintPrefs;
@@ -613,9 +613,10 @@ message_prefs_widget(GtkPrintOperation * operation,
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_prefs->html_print), print_prefs->prefer_text);
     gtk_grid_attach(GTK_GRID(grid), print_prefs->html_print, 1, 0, 1, 1);
 
-    print_prefs->html_load_imgs = gtk_check_button_new_with_mnemonic(_("Download images from remote servers 
(may be dangerous)"));
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_prefs->html_load_imgs), print_prefs->load_images);
-    gtk_grid_attach(GTK_GRID(grid), print_prefs->html_load_imgs, 1, 1, 1, 1);
+    print_prefs->html_load_ext_content =
+       gtk_check_button_new_with_mnemonic(_("Download content from remote servers (may be dangerous)"));
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_prefs->html_load_ext_content), 
print_prefs->load_ext_content);
+    gtk_grid_attach(GTK_GRID(grid), print_prefs->html_load_ext_content, 1, 1, 1, 1);
 
     /* phantom alignment */
     dummy = gtk_label_new(" ");
@@ -708,8 +709,8 @@ message_prefs_apply(GtkPrintOperation * operation, GtkWidget * widget,
 #ifdef HAVE_HTML_WIDGET
     print_prefs->setup->print_alt_html =
        !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(print_prefs->html_print));
-    print_prefs->setup->html_load_images =
-       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(print_prefs->html_load_imgs));
+    print_prefs->setup->html_load_ext_content =
+       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(print_prefs->html_load_ext_content));
 #endif
 }
 
@@ -768,7 +769,7 @@ message_print(LibBalsaMessage * msg, GtkWindow * parent)
     print_prefs.setup = &print_data->setup;
     from = libbalsa_message_get_headers(msg)->from;
     print_prefs.prefer_text = balsa_app.display_alt_plain && !libbalsa_html_get_prefer_html(from);
-    print_prefs.load_images = libbalsa_html_get_load_images(from);
+    print_prefs.load_ext_content = libbalsa_html_get_load_content(from);
 #endif
 
     g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), print_data);


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