2007-10-28 [colin] 3.0.2cvs105
authorColin Leroy <colin@colino.net>
Sun, 28 Oct 2007 17:02:31 +0000 (17:02 +0000)
committerColin Leroy <colin@colino.net>
Sun, 28 Oct 2007 17:02:31 +0000 (17:02 +0000)
* src/plugins/dillo_viewer/dillo_prefs.c
* src/plugins/dillo_viewer/dillo_prefs.h
* src/plugins/dillo_viewer/dillo_viewer.c
Implement addressbook-based whitelisting for loading
remote images. Fixed missing destroy of the embedded
browser that made a Dillo window pop up on exit, if
an HTML part was displayed.

ChangeLog
PATCHSETS
configure.ac
src/plugins/dillo_viewer/dillo_prefs.c
src/plugins/dillo_viewer/dillo_prefs.h
src/plugins/dillo_viewer/dillo_viewer.c

index 9c45f1e..fa5818f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-10-28 [colin]     3.0.2cvs105
+
+       * src/plugins/dillo_viewer/dillo_prefs.c
+       * src/plugins/dillo_viewer/dillo_prefs.h
+       * src/plugins/dillo_viewer/dillo_viewer.c
+               Implement addressbook-based whitelisting for loading
+               remote images. Fixed missing destroy of the embedded
+               browser that made a Dillo window pop up on exit, if
+               an HTML part was displayed.
+
 2007-10-26 [colin]     3.0.2cvs104
 
        * src/edittags.c
 2007-10-26 [colin]     3.0.2cvs104
 
        * src/edittags.c
index 2f76fe3..b954f32 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.179.2.195 -r 1.179.2.196 src/imap.c;  cvs diff -u -r 1.1.4.19 -r 1.1.4.20 src/etpan/imap-thread.h;  ) > 3.0.2cvs102.patchset
 ( cvs diff -u -r 1.14.2.42 -r 1.14.2.43 src/editaddress.c;  cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/edittags.c;  cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/edittags.h;  cvs diff -u -r 1.274.2.219 -r 1.274.2.220 src/mainwindow.c;  cvs diff -u -r 1.150.2.104 -r 1.150.2.105 src/procmsg.c;  cvs diff -u -r 1.395.2.333 -r 1.395.2.334 src/summaryview.c;  cvs diff -u -r 1.96.2.190 -r 1.96.2.191 src/textview.c;  ) > 3.0.2cvs103.patchset
 ( cvs diff -u -r 1.1.2.9 -r 1.1.2.10 src/edittags.c;  ) > 3.0.2cvs104.patchset
 ( cvs diff -u -r 1.179.2.195 -r 1.179.2.196 src/imap.c;  cvs diff -u -r 1.1.4.19 -r 1.1.4.20 src/etpan/imap-thread.h;  ) > 3.0.2cvs102.patchset
 ( cvs diff -u -r 1.14.2.42 -r 1.14.2.43 src/editaddress.c;  cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/edittags.c;  cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/edittags.h;  cvs diff -u -r 1.274.2.219 -r 1.274.2.220 src/mainwindow.c;  cvs diff -u -r 1.150.2.104 -r 1.150.2.105 src/procmsg.c;  cvs diff -u -r 1.395.2.333 -r 1.395.2.334 src/summaryview.c;  cvs diff -u -r 1.96.2.190 -r 1.96.2.191 src/textview.c;  ) > 3.0.2cvs103.patchset
 ( cvs diff -u -r 1.1.2.9 -r 1.1.2.10 src/edittags.c;  ) > 3.0.2cvs104.patchset
+( cvs diff -u -r 1.5.2.17 -r 1.5.2.18 src/plugins/dillo_viewer/dillo_prefs.c;  cvs diff -u -r 1.2.4.7 -r 1.2.4.8 src/plugins/dillo_viewer/dillo_prefs.h;  cvs diff -u -r 1.12.2.23 -r 1.12.2.24 src/plugins/dillo_viewer/dillo_viewer.c;  ) > 3.0.2cvs105.patchset
index 4d277b6..b563161 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=104
+EXTRA_VERSION=105
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 2f0f23f..381bf22 100644 (file)
@@ -38,6 +38,8 @@
 #include "prefs.h"
 #include "prefs_gtk.h"
 #include "prefswindow.h"
 #include "prefs.h"
 #include "prefs_gtk.h"
 #include "prefswindow.h"
+#include "combobox.h"
+#include "addressbook.h"
 
 #include "dillo_prefs.h"
 
 
 #include "dillo_prefs.h"
 
@@ -50,12 +52,20 @@ typedef struct _DilloBrowserPage DilloBrowserPage;
 struct _DilloBrowserPage {
         PrefsPage page;
         GtkWidget *local;
 struct _DilloBrowserPage {
         PrefsPage page;
         GtkWidget *local;
+       GtkWidget *whitelist_ab;
+       GtkWidget *whitelist_ab_folder_combo;
+       GtkWidget *whitelist_ab_select_btn;
         GtkWidget *full;
 };
 
 static PrefParam param[] = {
         {"local_browse", "TRUE", &dillo_prefs.local, P_BOOL, NULL, NULL, NULL},
         {"full_window", "TRUE", &dillo_prefs.full, P_BOOL, NULL, NULL, NULL},
         GtkWidget *full;
 };
 
 static PrefParam param[] = {
         {"local_browse", "TRUE", &dillo_prefs.local, P_BOOL, NULL, NULL, NULL},
         {"full_window", "TRUE", &dillo_prefs.full, P_BOOL, NULL, NULL, NULL},
+       {"whitelist_ab", "FALSE", &dillo_prefs.whitelist_ab, P_BOOL,
+        NULL, NULL, NULL},
+       {"whitelist_ab_folder", N_("Any"), &dillo_prefs.whitelist_ab_folder, P_STRING,
+        NULL, NULL, NULL},
+
         {0,0,0,0,0,0,0}
 };
 
         {0,0,0,0,0,0,0}
 };
 
@@ -67,6 +77,43 @@ static void create_dillo_prefs_page  (PrefsPage *page,
 static void destroy_dillo_prefs_page   (PrefsPage *page);
 static void save_dillo_prefs           (PrefsPage *page);
 
 static void destroy_dillo_prefs_page   (PrefsPage *page);
 static void save_dillo_prefs           (PrefsPage *page);
 
+static void dillo_whitelist_ab_select_cb(GtkWidget *widget, gpointer data)
+{
+       DilloBrowserPage *page = (DilloBrowserPage *) data;
+       gchar *folderpath = NULL;
+       gboolean ret = FALSE;
+
+       folderpath = (gchar *) gtk_entry_get_text(GTK_ENTRY(GTK_BIN(page->whitelist_ab_folder_combo)->child));
+       ret = addressbook_folder_selection(&folderpath);
+       if ( ret != FALSE && folderpath != NULL)
+               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(page->whitelist_ab_folder_combo)->child), folderpath);
+}
+
+static void local_checkbox_toggled(GtkToggleButton *button,
+                                         gpointer user_data)
+{
+       gboolean active = gtk_toggle_button_get_active(button);
+        DilloBrowserPage *prefs_page = (DilloBrowserPage *) user_data;
+
+       gtk_widget_set_sensitive(prefs_page->whitelist_ab, active);
+       gtk_widget_set_sensitive(prefs_page->whitelist_ab_folder_combo, active && 
+                       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prefs_page->whitelist_ab)));
+       gtk_widget_set_sensitive(prefs_page->whitelist_ab_select_btn, active && 
+                       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prefs_page->whitelist_ab)));
+}
+
+static void whitelist_checkbox_toggled(GtkToggleButton *button,
+                                         gpointer user_data)
+{
+       gboolean active = gtk_toggle_button_get_active(button);
+        DilloBrowserPage *prefs_page = (DilloBrowserPage *) user_data;
+
+       active &= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prefs_page->local));
+
+       gtk_widget_set_sensitive(prefs_page->whitelist_ab_folder_combo, active);
+       gtk_widget_set_sensitive(prefs_page->whitelist_ab_select_btn, active);
+}
+
 void dillo_prefs_init(void)
 {
        static gchar *path[3];
 void dillo_prefs_init(void)
 {
        static gchar *path[3];
@@ -106,6 +153,11 @@ static void create_dillo_prefs_page(PrefsPage *page,
         GtkWidget *label;
        GtkTooltips *local_tooltip;
        GtkTooltips *full_tooltip;
         GtkWidget *label;
        GtkTooltips *local_tooltip;
        GtkTooltips *full_tooltip;
+       GtkWidget *whitelist_ab_checkbtn;
+       GtkWidget *whitelist_ab_folder_combo;
+       GtkWidget *whitelist_ab_select_btn;
+       GtkWidget *hbox_whitelist, *spacer;
+
 
         vbox = gtk_vbox_new(FALSE, 3);
         gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
 
         vbox = gtk_vbox_new(FALSE, 3);
         gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
@@ -113,9 +165,9 @@ static void create_dillo_prefs_page(PrefsPage *page,
         
        local_tooltip = gtk_tooltips_new();
         local_checkbox = gtk_check_button_new_with_label
         
        local_tooltip = gtk_tooltips_new();
         local_checkbox = gtk_check_button_new_with_label
-                               (_("Do not load remote links in mails"));
+                               (_("Load remote links in mails"));
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(local_checkbox),
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(local_checkbox),
-                                     dillo_prefs.local);
+                                     !dillo_prefs.local);
         gtk_box_pack_start(GTK_BOX(vbox), local_checkbox, FALSE, FALSE, 0);
         gtk_widget_show(local_checkbox);
        gtk_tooltips_set_tip(GTK_TOOLTIPS(local_tooltip), local_checkbox,
         gtk_box_pack_start(GTK_BOX(vbox), local_checkbox, FALSE, FALSE, 0);
         gtk_widget_show(local_checkbox);
        gtk_tooltips_set_tip(GTK_TOOLTIPS(local_tooltip), local_checkbox,
@@ -128,6 +180,33 @@ static void create_dillo_prefs_page(PrefsPage *page,
        gtkut_widget_set_small_font_size (label);
         gtk_widget_show(label);
 
        gtkut_widget_set_small_font_size (label);
         gtk_widget_show(label);
 
+       
+       hbox_whitelist = gtk_hbox_new(FALSE, 8);
+       gtk_widget_show(hbox_whitelist);
+       gtk_box_pack_start (GTK_BOX (vbox), hbox_whitelist, FALSE, FALSE, 0);
+       
+       spacer = gtk_hbox_new(FALSE, 0);
+       gtk_widget_set_size_request(spacer, 12, -1);
+       gtk_widget_show(spacer);
+       gtk_box_pack_start(GTK_BOX(hbox_whitelist), spacer, FALSE, FALSE, 0);
+
+       whitelist_ab_checkbtn = gtk_check_button_new_with_label(_("Only for senders found in address book/folder"));
+       gtk_widget_show(whitelist_ab_checkbtn);
+       gtk_box_pack_start(GTK_BOX(hbox_whitelist), whitelist_ab_checkbtn, FALSE, FALSE, 0);
+
+       whitelist_ab_folder_combo = combobox_text_new(TRUE, _("Any"), NULL);
+       gtk_widget_set_size_request(whitelist_ab_folder_combo, 100, -1);
+       gtk_box_pack_start (GTK_BOX (hbox_whitelist), whitelist_ab_folder_combo, TRUE, TRUE, 0);
+
+       whitelist_ab_select_btn = gtk_button_new_with_label(_("Select ..."));
+       gtk_widget_show (whitelist_ab_select_btn);
+       gtk_box_pack_start (GTK_BOX (hbox_whitelist), whitelist_ab_select_btn, FALSE, FALSE, 0);
+
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(whitelist_ab_checkbtn), dillo_prefs.whitelist_ab);
+       if (dillo_prefs.whitelist_ab_folder != NULL)
+               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(whitelist_ab_folder_combo)->child),
+                               dillo_prefs.whitelist_ab_folder);
+
        full_tooltip = gtk_tooltips_new();
         full_checkbox = gtk_check_button_new_with_label
                                (_("Full window mode (hide controls)"));
        full_tooltip = gtk_tooltips_new();
         full_checkbox = gtk_check_button_new_with_label
                                (_("Full window mode (hide controls)"));
@@ -138,9 +217,25 @@ static void create_dillo_prefs_page(PrefsPage *page,
        gtk_tooltips_set_tip(GTK_TOOLTIPS(full_tooltip), full_checkbox,
                             _("Equivalent to Dillo's '--fullwindow' option"),
                             NULL);
        gtk_tooltips_set_tip(GTK_TOOLTIPS(full_tooltip), full_checkbox,
                             _("Equivalent to Dillo's '--fullwindow' option"),
                             NULL);
+
+       g_signal_connect(G_OBJECT(local_checkbox), "toggled",
+                        G_CALLBACK(local_checkbox_toggled),
+                        prefs_page);
+
+       g_signal_connect(G_OBJECT(whitelist_ab_checkbtn), "toggled",
+                        G_CALLBACK(whitelist_checkbox_toggled),
+                        prefs_page);
+
+       gtk_widget_set_sensitive(whitelist_ab_checkbtn, !dillo_prefs.local);
+       gtk_widget_set_sensitive(whitelist_ab_folder_combo, !dillo_prefs.local && dillo_prefs.whitelist_ab);
+       gtk_widget_set_sensitive(whitelist_ab_select_btn, !dillo_prefs.local && dillo_prefs.whitelist_ab);
+
         
         prefs_page->local = local_checkbox;
         prefs_page->full = full_checkbox;
         
         prefs_page->local = local_checkbox;
         prefs_page->full = full_checkbox;
+       prefs_page->whitelist_ab = whitelist_ab_checkbtn;
+       prefs_page->whitelist_ab_folder_combo = whitelist_ab_folder_combo;
+       prefs_page->whitelist_ab_select_btn = whitelist_ab_select_btn;
         prefs_page->page.widget = vbox;
 }
 
         prefs_page->page.widget = vbox;
 }
 
@@ -156,10 +251,15 @@ static void save_dillo_prefs(PrefsPage *page)
         gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                           COMMON_RC, NULL);
         
         gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                           COMMON_RC, NULL);
         
-        dillo_prefs.local = gtk_toggle_button_get_active
+        dillo_prefs.local = !gtk_toggle_button_get_active
                                (GTK_TOGGLE_BUTTON(prefs_page->local));
         dillo_prefs.full = gtk_toggle_button_get_active
                                (GTK_TOGGLE_BUTTON(prefs_page->full));
                                (GTK_TOGGLE_BUTTON(prefs_page->local));
         dillo_prefs.full = gtk_toggle_button_get_active
                                (GTK_TOGGLE_BUTTON(prefs_page->full));
+
+       dillo_prefs.whitelist_ab = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prefs_page->whitelist_ab));
+       g_free(dillo_prefs.whitelist_ab_folder);
+       dillo_prefs.whitelist_ab_folder = gtk_editable_get_chars(
+                               GTK_EDITABLE(GTK_BIN(prefs_page->whitelist_ab_folder_combo)->child), 0, -1);
         
         pref_file = prefs_write_open(rc_file_path);
         g_free(rc_file_path);
         
         pref_file = prefs_write_open(rc_file_path);
         g_free(rc_file_path);
index 45788b5..fff4f3e 100644 (file)
@@ -33,6 +33,8 @@ typedef struct _DilloBrowserPrefs     DilloBrowserPrefs;
 struct _DilloBrowserPrefs
 {
        gboolean local;   /**< local browsing */
 struct _DilloBrowserPrefs
 {
        gboolean local;   /**< local browsing */
+       gboolean whitelist_ab;
+       gchar *whitelist_ab_folder;
        gboolean full;    /**< use full window */
 };
 
        gboolean full;    /**< use full window */
 };
 
index 7ac7a50..f5c2af6 100644 (file)
@@ -33,6 +33,7 @@
 #include "plugin.h"
 #include "utils.h"
 #include "mimeview.h"
 #include "plugin.h"
 #include "utils.h"
 #include "mimeview.h"
+#include "addr_compl.h"
 
 #include "dillo_prefs.h"
 
 
 #include "dillo_prefs.h"
 
@@ -67,6 +68,73 @@ static gboolean socket_destroy_cb(GtkObject *object, gpointer data)
        return FALSE;
 }
 
        return FALSE;
 }
 
+static gboolean found_in_addressbook(const gchar *address)
+{
+       gchar *addr = NULL;
+       gboolean found = FALSE;
+       gint num_addr = 0;
+       
+       if (!address)
+               return FALSE;
+       
+       addr = g_strdup(address);
+       extract_address(addr);
+       num_addr = complete_address(addr);
+       if (num_addr > 1) {
+               /* skip first item (this is the search string itself) */
+               int i = 1;
+               for (; i < num_addr && !found; i++) {
+                       gchar *caddr = get_complete_address(i);
+                       extract_address(caddr);
+                       if (strcasecmp(caddr, addr) == 0)
+                               found = TRUE;
+                       g_free(caddr);
+               }
+       }
+       g_free(addr);
+       return found;
+}
+
+static gboolean load_images(DilloViewer *viewer)
+{
+       MessageView *messageview = ((MimeViewer *)viewer)->mimeview 
+                                       ? ((MimeViewer *)viewer)->mimeview->messageview 
+                                       : NULL;
+       MsgInfo *msginfo = NULL;
+       gchar *ab_folderpath = NULL;
+
+       if (messageview == NULL)
+               return FALSE;
+       
+       msginfo = messageview->msginfo;
+       
+       if (msginfo == NULL)
+               return FALSE;
+
+       /* don't load remote images, period. */
+       if (dillo_prefs.local)
+               return FALSE;
+       
+       /* don't do whitelisting -> load images */
+       if (!dillo_prefs.whitelist_ab)
+               return TRUE;
+
+       if (*dillo_prefs.whitelist_ab_folder != '\0' &&
+           strcasecmp(dillo_prefs.whitelist_ab_folder, _("Any")) != 0)
+               ab_folderpath = dillo_prefs.whitelist_ab_folder;
+
+       start_address_completion(ab_folderpath);
+
+       /* do whitelisting -> check sender */
+       if (found_in_addressbook(msginfo->from)) {
+               end_address_completion();
+               return TRUE;
+       }
+       
+       end_address_completion();
+       return FALSE;
+}
+
 static void dillo_show_mimepart(MimeViewer *_viewer,
                                const gchar *infile,
                                MimeInfo *partinfo)
 static void dillo_show_mimepart(MimeViewer *_viewer,
                                const gchar *infile,
                                MimeInfo *partinfo)
@@ -97,7 +165,7 @@ static void dillo_show_mimepart(MimeViewer *_viewer,
                                 G_CALLBACK(socket_destroy_cb), viewer);
 
                cmd = g_strdup_printf("dillo %s%s-x %d \"%s\"",
                                 G_CALLBACK(socket_destroy_cb), viewer);
 
                cmd = g_strdup_printf("dillo %s%s-x %d \"%s\"",
-                                     (dillo_prefs.local ? "-l " : ""),
+                                     (!load_images(viewer) ? "-l " : ""),
                                      (dillo_prefs.full ? "-f " : ""),
                                      (gint) GDK_WINDOW_XWINDOW(viewer->socket->window),
                                      viewer->filename);
                                      (dillo_prefs.full ? "-f " : ""),
                                      (gint) GDK_WINDOW_XWINDOW(viewer->socket->window),
                                      viewer->filename);
@@ -125,6 +193,10 @@ static void dillo_destroy_viewer(MimeViewer *_viewer)
 
        debug_print("dillo_destroy_viewer\n");
 
 
        debug_print("dillo_destroy_viewer\n");
 
+       if (viewer->socket) {
+               gtk_widget_destroy(viewer->socket);
+       }
+
        gtk_widget_unref(GTK_WIDGET(viewer->widget));
        g_unlink(viewer->filename);
        g_free(viewer->filename);
        gtk_widget_unref(GTK_WIDGET(viewer->widget));
        g_unlink(viewer->filename);
        g_free(viewer->filename);