2011-10-07 [colin] 3.7.10cvs21
[claws.git] / src / plugins / dillo_viewer / dillo_viewer.c
index 105a799cfdcd0d888b77ec011c67bff498c87b0f..41d2f3072ee34daca8c76d3d3d4fc7bb82d7ab9b 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Sylpheed-Claws Team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2011 the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#if GTK_CHECK_VERSION(3, 0, 0)
+#include <gtk/gtkx.h>
+#endif
 #include <gdk/gdkx.h>
 
-#include "common/sylpheed.h"
+#include "common/claws.h"
 #include "common/version.h"
 #include "plugin.h"
 #include "utils.h"
 #include "mimeview.h"
+#include "addr_compl.h"
 
 #include "dillo_prefs.h"
 
+#define PLUGIN_NAME (_("Dillo HTML Viewer"))
+
 typedef struct _DilloViewer DilloViewer;
 
 struct _DilloViewer
@@ -57,7 +63,11 @@ static GtkWidget *dillo_get_widget(MimeViewer *_viewer)
        return GTK_WIDGET(viewer->widget);
 }
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
+static gboolean socket_destroy_cb(GtkObject *object, gpointer data)
+#else
 static gboolean socket_destroy_cb(GtkObject *object, gpointer data)
+#endif
 {
        DilloViewer *viewer = (DilloViewer *) data;
        debug_print("Destroyed dillo socket %p\n", viewer->socket);
@@ -65,6 +75,73 @@ static gboolean socket_destroy_cb(GtkObject *object, gpointer data)
        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)
@@ -74,7 +151,7 @@ static void dillo_show_mimepart(MimeViewer *_viewer,
        debug_print("dillo_show_mimepart\n");
 
        if (viewer->filename != NULL) {
-               g_unlink(viewer->filename);
+               claws_unlink(viewer->filename);
                g_free(viewer->filename);
        }
 
@@ -95,7 +172,7 @@ static void dillo_show_mimepart(MimeViewer *_viewer,
                                 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);
@@ -123,8 +200,12 @@ static void dillo_destroy_viewer(MimeViewer *_viewer)
 
        debug_print("dillo_destroy_viewer\n");
 
-       gtk_widget_unref(GTK_WIDGET(viewer->widget));
-       g_unlink(viewer->filename);
+       if (viewer->socket) {
+               gtk_widget_destroy(viewer->socket);
+       }
+
+       g_object_unref(GTK_WIDGET(viewer->widget));
+       claws_unlink(viewer->filename);
        g_free(viewer->filename);
        g_free(viewer);
 }
@@ -141,10 +222,11 @@ static MimeViewer *dillo_viewer_create(void)
        viewer->mimeviewer.show_mimepart = dillo_show_mimepart;
        viewer->mimeviewer.clear_viewer = dillo_clear_viewer;
        viewer->mimeviewer.destroy_viewer = dillo_destroy_viewer;       
+       viewer->mimeviewer.get_selection = NULL;
        viewer->widget = gtk_event_box_new();
 
        gtk_widget_show(viewer->widget);
-       gtk_widget_ref(viewer->widget);
+       g_object_ref(viewer->widget);
 
        viewer->filename = NULL;
 
@@ -159,20 +241,21 @@ static MimeViewerFactory dillo_viewer_factory =
        content_types,  
        0,
 
-       dillo_viewer_create
+       dillo_viewer_create,
 };
 
 gint plugin_init(gchar **error)
 {
-       if ((sylpheed_get_version() > VERSION_NUMERIC)) {
-               *error = g_strdup("Your version of Sylpheed-Claws is newer than the version the Dillo plugin was built with");
-               return -1;
-       }
+       gchar *dillo_path = NULL;
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
+                               VERSION_NUMERIC, PLUGIN_NAME, error))
+               return -1;
 
-       if ((sylpheed_get_version() < MAKE_NUMERIC_VERSION(0, 9, 3, 86))) {
-               *error = g_strdup("Your vesion of Sylpheed-Claws is too old for the Dillo plugin");
+       if ((dillo_path = g_find_program_in_path("dillo")) == NULL) {
+               *error = g_strdup(_("Can't find the dillo executable in PATH. Is it installed?"));
                return -1;
        }
+       g_free(dillo_path);
 
         dillo_prefs_init();
 
@@ -181,25 +264,46 @@ gint plugin_init(gchar **error)
        return 0;       
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        mimeview_unregister_viewer_factory(&dillo_viewer_factory);
 
         dillo_prefs_done();
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
 {
-       return _("Dillo HTML Viewer");
+       return PLUGIN_NAME;
 }
 
 const gchar *plugin_desc(void)
 {
        return _("This plugin renders HTML mail using the Dillo "
-               "web browser.");
+               "web browser.\n"
+               "\n"
+               "Options can be found in /Configuration/Preferences/Plugins/Dillo Browser");
 }
 
 const gchar *plugin_type(void)
 {
        return "GTK2";
 }
+
+const gchar *plugin_licence(void)
+{
+       return "GPL3+";
+}
+
+const gchar *plugin_version(void)
+{
+       return VERSION;
+}
+
+struct PluginFeature *plugin_provides(void)
+{
+       static struct PluginFeature features[] = 
+               { {PLUGIN_MIMEVIEWER, "text/html"},
+                 {PLUGIN_NOTHING, NULL}};
+       return features;
+}