2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2023 the Claws Mail Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "claws-features.h"
28 #include <glib/gi18n.h>
33 #include "common/claws.h"
34 #include "common/version.h"
36 #include "file-utils.h"
39 #include "addr_compl.h"
41 #include "dillo_prefs.h"
43 #define PLUGIN_NAME (_("Dillo HTML Viewer"))
45 typedef struct _DilloViewer DilloViewer
;
49 MimeViewer mimeviewer
;
55 static MimeViewerFactory dillo_viewer_factory
;
57 static GtkWidget
*dillo_get_widget(MimeViewer
*_viewer
)
59 DilloViewer
*viewer
= (DilloViewer
*) _viewer
;
61 debug_print("dillo_get_widget\n");
63 return GTK_WIDGET(viewer
->widget
);
66 static gboolean
socket_destroy_cb(GObject
*object
, gpointer data
)
68 DilloViewer
*viewer
= (DilloViewer
*) data
;
69 debug_print("Destroyed dillo socket %p\n", viewer
->socket
);
70 viewer
->socket
= NULL
;
74 static gboolean
load_images(DilloViewer
*viewer
)
76 MessageView
*messageview
= ((MimeViewer
*)viewer
)->mimeview
77 ? ((MimeViewer
*)viewer
)->mimeview
->messageview
79 MsgInfo
*msginfo
= NULL
;
80 gchar
*ab_folderpath
= NULL
;
82 if (messageview
== NULL
)
85 msginfo
= messageview
->msginfo
;
90 /* don't load remote images, period. */
91 if (dillo_prefs
.local
)
94 /* don't do whitelisting -> load images */
95 if (!dillo_prefs
.whitelist_ab
)
98 if (*dillo_prefs
.whitelist_ab_folder
!= '\0' &&
99 strcasecmp(dillo_prefs
.whitelist_ab_folder
, _("Any")) != 0)
100 ab_folderpath
= dillo_prefs
.whitelist_ab_folder
;
102 start_address_completion(ab_folderpath
);
104 /* do whitelisting -> check sender */
105 if (found_in_addressbook(msginfo
->from
)) {
106 end_address_completion();
110 end_address_completion();
114 static void dillo_show_mimepart(MimeViewer
*_viewer
,
118 DilloViewer
*viewer
= (DilloViewer
*) _viewer
;
121 debug_print("dillo_show_mimepart\n");
123 if (viewer
->filename
!= NULL
) {
124 claws_unlink(viewer
->filename
);
125 g_free(viewer
->filename
);
128 #ifdef GDK_WINDOWING_X11
129 if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
130 debug_print("dillo viewer only works on X11\n");
134 debug_print("dillo viewer only works on X11\n");
138 viewer
->filename
= procmime_get_tmp_file_name(partinfo
);
140 if (!(procmime_get_part(viewer
->filename
, partinfo
) < 0)) {
144 gtk_widget_destroy(viewer
->socket
);
145 viewer
->socket
= gtk_socket_new();
146 debug_print("Adding dillo socket %p", viewer
->socket
);
147 gtk_container_add(GTK_CONTAINER(viewer
->widget
),
149 gtk_widget_realize(viewer
->socket
);
150 gtk_widget_show(viewer
->socket
);
151 g_signal_connect(G_OBJECT(viewer
->socket
), "destroy",
152 G_CALLBACK(socket_destroy_cb
), viewer
);
154 gdkwin
= gtk_widget_get_window(viewer
->socket
);
155 cmd
= g_strdup_printf("dillo %s%s-x %d \"%s\"",
156 (!load_images(viewer
) ? "-l " : ""),
157 (dillo_prefs
.full
? "-f " : ""),
158 (gint
) GDK_WINDOW_XID(gdkwin
),
161 execute_command_line(cmd
, TRUE
, NULL
);
166 static void dillo_clear_viewer(MimeViewer
*_viewer
)
168 DilloViewer
*viewer
= (DilloViewer
*) _viewer
;
170 debug_print("dillo_clear_viewer\n");
171 debug_print("Removing dillo socket %p\n", viewer
->socket
);
173 if (viewer
->socket
) {
174 gtk_widget_destroy(viewer
->socket
);
178 static void dillo_destroy_viewer(MimeViewer
*_viewer
)
180 DilloViewer
*viewer
= (DilloViewer
*) _viewer
;
182 debug_print("dillo_destroy_viewer\n");
184 if (viewer
->socket
) {
185 gtk_widget_destroy(viewer
->socket
);
188 g_object_unref(GTK_WIDGET(viewer
->widget
));
189 claws_unlink(viewer
->filename
);
190 g_free(viewer
->filename
);
194 static MimeViewer
*dillo_viewer_create(void)
198 debug_print("dillo_viewer_create\n");
200 viewer
= g_new0(DilloViewer
, 1);
201 viewer
->mimeviewer
.factory
= &dillo_viewer_factory
;
202 viewer
->mimeviewer
.get_widget
= dillo_get_widget
;
203 viewer
->mimeviewer
.show_mimepart
= dillo_show_mimepart
;
204 viewer
->mimeviewer
.clear_viewer
= dillo_clear_viewer
;
205 viewer
->mimeviewer
.destroy_viewer
= dillo_destroy_viewer
;
206 viewer
->mimeviewer
.get_selection
= NULL
;
207 viewer
->widget
= gtk_event_box_new();
209 gtk_widget_show(viewer
->widget
);
210 g_object_ref(viewer
->widget
);
212 viewer
->filename
= NULL
;
214 return (MimeViewer
*) viewer
;
217 static gchar
*content_types
[] =
220 static MimeViewerFactory dillo_viewer_factory
=
228 gint
plugin_init(gchar
**error
)
230 gchar
*dillo_path
= NULL
;
231 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
232 VERSION_NUMERIC
, PLUGIN_NAME
, error
))
235 if ((dillo_path
= g_find_program_in_path("dillo")) == NULL
) {
236 *error
= g_strdup(_("Can't find the dillo executable in PATH. Is it installed?"));
243 mimeview_register_viewer_factory(&dillo_viewer_factory
);
248 gboolean
plugin_done(void)
250 mimeview_unregister_viewer_factory(&dillo_viewer_factory
);
256 const gchar
*plugin_name(void)
261 const gchar
*plugin_desc(void)
263 return _("This plugin renders HTML mail using the Dillo "
266 "Options can be found in /Configuration/Preferences/Plugins/Dillo Browser");
269 const gchar
*plugin_type(void)
274 const gchar
*plugin_licence(void)
279 const gchar
*plugin_version(void)
284 struct PluginFeature
*plugin_provides(void)
286 static struct PluginFeature features
[] =
287 { {PLUGIN_MIMEVIEWER
, "text/html"},
288 {PLUGIN_NOTHING
, NULL
}};