2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkscrolledwindow.h>
29 #include <gtk/gtkctree.h>
30 #include <gtk/gtkvbox.h>
31 #include <gtk/gtkvpaned.h>
32 #include <gtk/gtktext.h>
33 #include <gtk/gtksignal.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkdnd.h>
36 #include <gtk/gtkselection.h>
45 #include "summaryview.h"
48 #include "alertpanel.h"
49 #include "inputdialog.h"
52 #include "prefs_common.h"
63 #define N_MIMEVIEW_COLS 3
65 static void mimeview_set_multipart_tree (MimeView *mimeview,
67 GtkCTreeNode *parent);
68 static GtkCTreeNode *mimeview_append_part (MimeView *mimeview,
70 GtkCTreeNode *parent);
71 static void mimeview_show_message_part (MimeView *mimeview,
73 static void mimeview_show_image_part (MimeView *mimeview,
75 static void mimeview_change_view_type (MimeView *mimeview,
77 static void mimeview_clear (MimeView *mimeview);
79 static void mimeview_selected (GtkCTree *ctree,
83 static void mimeview_start_drag (GtkWidget *widget,
87 static gint mimeview_button_pressed (GtkWidget *widget,
88 GdkEventButton *event,
90 static gint mimeview_key_pressed (GtkWidget *widget,
94 static void mimeview_drag_data_get (GtkWidget *widget,
95 GdkDragContext *drag_context,
96 GtkSelectionData *selection_data,
101 static void mimeview_display_as_text (MimeView *mimeview);
102 static void mimeview_save_as (MimeView *mimeview);
103 static void mimeview_launch (MimeView *mimeview);
104 static void mimeview_open_with (MimeView *mimeview);
105 static void mimeview_view_file (const gchar *filename,
107 const gchar *cmdline);
109 static void mimeview_check_signature (MimeView *mimeview);
112 static GtkItemFactoryEntry mimeview_popup_entries[] =
114 {N_("/_Open"), NULL, mimeview_launch, 0, NULL},
115 {N_("/Open _with..."), NULL, mimeview_open_with, 0, NULL},
116 {N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
117 {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL}
120 {N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL}
124 static GtkTargetEntry mimeview_mime_types[] =
126 {"text/uri-list", 0, 0}
129 MimeView *mimeview_create(void)
134 GtkWidget *scrolledwin;
137 GtkWidget *popupmenu;
138 GtkItemFactory *popupfactory;
139 gchar *titles[N_MIMEVIEW_COLS];
143 debug_print(_("Creating MIME view...\n"));
144 mimeview = g_new0(MimeView, 1);
146 titles[COL_MIMETYPE] = _("MIME Type");
147 titles[COL_SIZE] = _("Size");
148 titles[COL_NAME] = _("Name");
150 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
151 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
152 GTK_POLICY_AUTOMATIC,
154 gtk_widget_set_usize(scrolledwin, -1, 80);
156 ctree = gtk_sctree_new_with_titles(N_MIMEVIEW_COLS, 0, titles);
157 gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
158 gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_NONE);
159 gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_SIZE,
161 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_MIMETYPE, 240);
162 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_SIZE, 64);
163 for (i = 0; i < N_MIMEVIEW_COLS; i++)
164 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
166 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
168 gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
169 GTK_SIGNAL_FUNC(mimeview_selected), mimeview);
170 gtk_signal_connect(GTK_OBJECT(ctree), "button_press_event",
171 GTK_SIGNAL_FUNC(mimeview_button_pressed), mimeview);
172 gtk_signal_connect(GTK_OBJECT(ctree), "key_press_event",
173 GTK_SIGNAL_FUNC(mimeview_key_pressed), mimeview);
174 gtk_signal_connect(GTK_OBJECT (ctree),"start_drag",
175 GTK_SIGNAL_FUNC (mimeview_start_drag), mimeview);
176 gtk_signal_connect(GTK_OBJECT(ctree), "drag_data_get",
177 GTK_SIGNAL_FUNC(mimeview_drag_data_get), mimeview);
179 vbox = gtk_vbox_new(FALSE, 0);
181 paned = gtk_vpaned_new();
182 gtk_paned_add1(GTK_PANED(paned), scrolledwin);
183 gtk_paned_add2(GTK_PANED(paned), vbox);
184 gtk_widget_show_all(paned);
186 n_entries = sizeof(mimeview_popup_entries) /
187 sizeof(mimeview_popup_entries[0]);
188 popupmenu = menu_create_items(mimeview_popup_entries, n_entries,
189 "<MimeView>", &popupfactory, mimeview);
191 mimeview->paned = paned;
192 mimeview->scrolledwin = scrolledwin;
193 mimeview->ctree = ctree;
194 mimeview->vbox = vbox;
195 mimeview->popupmenu = popupmenu;
196 mimeview->popupfactory = popupfactory;
201 void mimeview_init(MimeView *mimeview)
206 * Check whether the message is OpenPGP signed
209 static gboolean mimeview_is_signed(MimeView *mimeview)
213 debug_print("mimeview_is signed of %p\n", mimeview);
215 if (!mimeview) return FALSE;
216 if (!mimeview->opened) return FALSE;
218 debug_print("mimeview_is_signed: open\n" );
220 if (!mimeview->file) return FALSE;
222 debug_print("mimeview_is_signed: file\n" );
224 partinfo = gtk_ctree_node_get_row_data
225 (GTK_CTREE(mimeview->ctree), mimeview->opened);
226 g_return_val_if_fail(partinfo != NULL, FALSE);
228 /* walk the tree and see whether there is a signature somewhere */
230 if (rfc2015_has_signature(partinfo))
232 if (pgptext_has_signature(partinfo))
234 } while ((partinfo = partinfo->parent) != NULL);
236 debug_print("mimeview_is_signed: FALSE\n" );
241 static void set_unchecked_signature(MimeInfo *mimeinfo)
243 MimeInfo *sig_partinfo;
245 sig_partinfo = rfc2015_find_signature(mimeinfo);
246 if (sig_partinfo == NULL) return;
248 g_free(sig_partinfo->sigstatus);
249 sig_partinfo->sigstatus =
250 g_strdup(_("Select \"Check signature\" to check"));
252 g_free(sig_partinfo->sigstatus_full);
253 sig_partinfo->sigstatus_full = NULL;
255 #endif /* USE_GPGME */
257 void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
260 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
265 mimeview_clear(mimeview);
267 g_return_if_fail(file != NULL);
268 g_return_if_fail(mimeinfo != NULL);
270 mimeview->mimeinfo = mimeinfo;
272 if ((fp = fopen(file, "r")) == NULL) {
273 FILE_OP_ERROR(file, "fopen");
276 mimeview->file = g_strdup(file);
278 /* skip MIME part headers */
279 if (mimeinfo->mime_type == MIME_MULTIPART) {
280 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
282 while (fgets(buf, sizeof(buf), fp) != NULL)
283 if (buf[0] == '\r' || buf[0] == '\n') break;
286 procmime_scan_multipart_message(mimeinfo, fp);
288 if (prefs_common.auto_check_signatures)
289 rfc2015_check_signature(mimeinfo, fp);
291 set_unchecked_signature(mimeinfo);
295 gtk_signal_handler_block_by_func(GTK_OBJECT(ctree), mimeview_selected,
298 mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
300 gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
301 mimeview_selected, mimeview);
303 /* search first text part */
304 for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
305 node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
308 partinfo = gtk_ctree_node_get_row_data(ctree, node);
310 (partinfo->mime_type == MIME_TEXT ||
311 partinfo->mime_type == MIME_TEXT_HTML))
315 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
318 gtk_ctree_select(ctree, node);
319 gtkut_ctree_set_focus_row(ctree, node);
320 gtk_widget_grab_focus(mimeview->ctree);
324 void mimeview_destroy(MimeView *mimeview)
326 procmime_mimeinfo_free_all(mimeview->mimeinfo);
327 g_free(mimeview->file);
331 static void mimeview_set_multipart_tree(MimeView *mimeview,
333 GtkCTreeNode *parent)
335 GtkCTreeNode *current = parent;
337 g_return_if_fail(mimeinfo != NULL);
339 if (!mimeinfo->sub && mimeinfo->parent)
340 current = mimeview_append_part(mimeview, mimeinfo, parent);
343 mimeview_set_multipart_tree(mimeview, mimeinfo->sub, current);
345 if (mimeinfo->children)
346 mimeview_set_multipart_tree(mimeview, mimeinfo->children, current);
349 mimeview_set_multipart_tree(mimeview, mimeinfo->next, parent);
352 static gchar *get_part_name(MimeInfo *partinfo)
355 if (partinfo->sigstatus)
356 return partinfo->sigstatus;
360 return partinfo->name;
361 else if (partinfo->filename)
362 return partinfo->filename;
367 static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
369 GtkCTreeNode *parent)
371 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
373 gchar *str[N_MIMEVIEW_COLS];
376 partinfo->content_type ? partinfo->content_type : "";
377 str[COL_SIZE] = to_human_readable(partinfo->size);
378 str[COL_NAME] = get_part_name(partinfo);
380 node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
381 NULL, NULL, NULL, NULL,
383 gtk_ctree_node_set_row_data(ctree, node, partinfo);
388 static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
396 if (!partinfo) return;
399 for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent)
401 fname = pi ? pi->plaintextfile : mimeview->file;
403 fname = mimeview->file;
404 #endif /* USE_GPGME */
407 if ((fp = fopen(fname, "r")) == NULL) {
408 FILE_OP_ERROR(fname, "fopen");
412 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0) {
413 FILE_OP_ERROR(mimeview->file, "fseek");
418 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
419 textview_show_part(mimeview->textview, partinfo, fp);
424 static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo)
428 if (!partinfo) return;
430 filename = procmime_get_tmp_file_name(partinfo);
432 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
434 (_("Can't get the part of multipart message."));
436 mimeview_change_view_type(mimeview, MIMEVIEW_IMAGE);
437 /* Workaround for the GTK+ bug with handling scroll adjustments
439 imageview_clear(mimeview->imageview);
440 imageview_show_image(mimeview->imageview, partinfo, filename);
447 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
449 TextView *textview = mimeview->textview;
450 ImageView *imageview = mimeview->imageview;
452 if (mimeview->type == type) return;
456 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
457 GTK_WIDGET_PTR(textview));
458 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
459 GTK_WIDGET_PTR(imageview));
462 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
463 GTK_WIDGET_PTR(imageview));
464 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
465 GTK_WIDGET_PTR(textview));
471 mimeview->type = type;
474 static void mimeview_clear(MimeView *mimeview)
476 GtkCList *clist = GTK_CLIST(mimeview->ctree);
478 procmime_mimeinfo_free_all(mimeview->mimeinfo);
479 mimeview->mimeinfo = NULL;
481 gtk_clist_clear(clist);
482 textview_clear(mimeview->textview);
483 imageview_clear(mimeview->imageview);
485 mimeview->opened = NULL;
487 g_free(mimeview->file);
488 mimeview->file = NULL;
491 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
496 if (mimeview->opened == node) return;
497 mimeview->opened = node;
498 gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
500 partinfo = gtk_ctree_node_get_row_data(ctree, node);
501 if (!partinfo) return;
503 /* ungrab the mouse event */
504 if (GTK_WIDGET_HAS_GRAB(ctree)) {
505 gtk_grab_remove(GTK_WIDGET(ctree));
506 if (gdk_pointer_is_grabbed())
507 gdk_pointer_ungrab(GDK_CURRENT_TIME);
510 switch (partinfo->mime_type) {
513 case MIME_TEXT_ENRICHED:
514 case MIME_MESSAGE_RFC822:
516 mimeview_show_message_part(mimeview, partinfo);
518 #if (HAVE_GDK_PIXBUF || HAVE_GDK_IMLIB)
520 mimeview_show_image_part(mimeview, partinfo);
524 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
526 if (g_strcasecmp(partinfo->content_type,
527 "application/pgp-signature") == 0)
528 textview_show_signature_part(mimeview->textview,
532 textview_show_mime_part(mimeview->textview, partinfo);
537 static void mimeview_start_drag (GtkWidget *widget, gint button,
538 GdkEvent *event, MimeView *mimeview)
541 GdkDragContext *context;
545 g_return_if_fail(mimeview != NULL);
546 ctree = GTK_CTREE(mimeview->ctree);
547 partinfo = gtk_ctree_node_get_row_data(ctree, mimeview->opened);
548 if (partinfo->filename == NULL && partinfo->name == NULL) return;
550 list = gtk_target_list_new(mimeview_mime_types, 1);
551 context = gtk_drag_begin(widget, list,
552 GDK_ACTION_COPY, button, event);
553 gtk_drag_set_icon_default(context);
556 static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
559 GtkCList *clist = GTK_CLIST(widget);
563 if (!event) return FALSE;
565 if (event->button == 2 || event->button == 3) {
566 if (!gtk_clist_get_selection_info(clist, event->x, event->y,
569 gtk_clist_unselect_all(clist);
570 gtk_clist_select_row(clist, row, column);
571 gtkut_clist_set_focus_row(clist, row);
574 if (event->button == 2 ||
575 (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
576 /* call external program for image, audio or html */
577 mimeview_launch(mimeview);
578 } else if (event->button == 3) {
579 partinfo = gtk_ctree_node_get_row_data
580 (GTK_CTREE(mimeview->ctree), mimeview->opened);
581 if (partinfo && (partinfo->mime_type == MIME_TEXT ||
582 partinfo->mime_type == MIME_TEXT_HTML ||
583 partinfo->mime_type == MIME_TEXT_ENRICHED ||
584 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
585 partinfo->mime_type == MIME_IMAGE ||
586 partinfo->mime_type == MIME_MULTIPART))
587 menu_set_sensitive(mimeview->popupfactory,
588 "/Display as text", FALSE);
590 menu_set_sensitive(mimeview->popupfactory,
591 "/Display as text", TRUE);
593 partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
594 menu_set_sensitive(mimeview->popupfactory,
597 menu_set_sensitive(mimeview->popupfactory,
600 menu_set_sensitive(mimeview->popupfactory,
602 mimeview_is_signed(mimeview));
605 gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
606 NULL, NULL, NULL, NULL,
607 event->button, event->time);
613 void mimeview_pass_key_press_event(MimeView *mimeview, GdkEventKey *event)
615 mimeview_key_pressed(mimeview->ctree, event, mimeview);
618 #define BREAK_ON_MODIFIER_KEY() \
619 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
621 #define KEY_PRESS_EVENT_STOP() \
622 if (gtk_signal_n_emissions_by_name \
623 (GTK_OBJECT(ctree), "key_press_event") > 0) { \
624 gtk_signal_emit_stop_by_name(GTK_OBJECT(ctree), \
625 "key_press_event"); \
628 static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
631 SummaryView *summaryview;
632 GtkCTree *ctree = GTK_CTREE(widget);
635 if (!event) return FALSE;
636 if (!mimeview->opened) return FALSE;
638 switch (event->keyval) {
640 if (textview_scroll_page(mimeview->textview, FALSE))
643 node = GTK_CTREE_NODE_NEXT(mimeview->opened);
645 gtk_sctree_unselect_all(GTK_SCTREE(ctree));
646 gtk_sctree_select(GTK_SCTREE(ctree), node);
651 textview_scroll_page(mimeview->textview, TRUE);
654 textview_scroll_one_line(mimeview->textview,
655 (event->state & GDK_MOD1_MASK) != 0);
659 BREAK_ON_MODIFIER_KEY();
660 if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break;
661 KEY_PRESS_EVENT_STOP();
663 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
664 GTK_SCROLL_STEP_FORWARD, 0.0);
668 BREAK_ON_MODIFIER_KEY();
669 if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break;
670 KEY_PRESS_EVENT_STOP();
672 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
673 GTK_SCROLL_STEP_BACKWARD, 0.0);
676 BREAK_ON_MODIFIER_KEY();
677 KEY_PRESS_EVENT_STOP();
678 mimeview_save_as(mimeview);
681 BREAK_ON_MODIFIER_KEY();
682 KEY_PRESS_EVENT_STOP();
683 mimeview_display_as_text(mimeview);
686 BREAK_ON_MODIFIER_KEY();
687 KEY_PRESS_EVENT_STOP();
688 mimeview_launch(mimeview);
693 if (!mimeview->messageview->mainwin) return FALSE;
694 summaryview = mimeview->messageview->mainwin->summaryview;
695 summary_pass_key_press_event(summaryview, event);
699 static void mimeview_drag_data_get(GtkWidget *widget,
700 GdkDragContext *drag_context,
701 GtkSelectionData *selection_data,
706 gchar *filename, *uriname;
709 if (!mimeview->opened) return;
710 if (!mimeview->file) return;
712 partinfo = gtk_ctree_node_get_row_data
713 (GTK_CTREE(mimeview->ctree), mimeview->opened);
714 if (!partinfo) return;
715 if (!partinfo->filename && !partinfo->name) return;
717 filename = partinfo->filename ? partinfo->filename : partinfo->name;
718 filename = g_basename(filename);
719 if (*filename == '\0') return;
721 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
724 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
726 (_("Can't save the part of multipart message."));
728 uriname = g_strconcat("file:/", filename, NULL);
729 gtk_selection_data_set(selection_data, selection_data->target, 8,
730 uriname, strlen(uriname));
736 static void mimeview_display_as_text(MimeView *mimeview)
740 if (!mimeview->opened) return;
742 partinfo = gtk_ctree_node_get_row_data
743 (GTK_CTREE(mimeview->ctree), mimeview->opened);
744 mimeview_show_message_part(mimeview, partinfo);
747 static void mimeview_save_as(MimeView *mimeview)
750 gchar *defname = NULL;
753 if (!mimeview->opened) return;
754 if (!mimeview->file) return;
756 partinfo = gtk_ctree_node_get_row_data
757 (GTK_CTREE(mimeview->ctree), mimeview->opened);
758 g_return_if_fail(partinfo != NULL);
760 if (partinfo->filename)
761 defname = partinfo->filename;
762 else if (partinfo->name) {
763 Xstrdup_a(defname, partinfo->name, return);
764 subst_for_filename(defname);
767 filename = filesel_select_file(_("Save as"), defname);
768 if (!filename) return;
769 if (is_file_exist(filename)) {
772 aval = alertpanel(_("Overwrite"),
773 _("Overwrite existing file?"),
774 _("OK"), _("Cancel"), NULL);
775 if (G_ALERTDEFAULT != aval) return;
778 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
780 (_("Can't save the part of multipart message."));
783 static void mimeview_launch(MimeView *mimeview)
788 if (!mimeview->opened) return;
789 if (!mimeview->file) return;
791 partinfo = gtk_ctree_node_get_row_data
792 (GTK_CTREE(mimeview->ctree), mimeview->opened);
793 g_return_if_fail(partinfo != NULL);
795 filename = procmime_get_tmp_file_name(partinfo);
797 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
799 (_("Can't save the part of multipart message."));
801 mimeview_view_file(filename, partinfo, NULL);
806 static void mimeview_open_with(MimeView *mimeview)
812 if (!mimeview->opened) return;
813 if (!mimeview->file) return;
815 partinfo = gtk_ctree_node_get_row_data
816 (GTK_CTREE(mimeview->ctree), mimeview->opened);
817 g_return_if_fail(partinfo != NULL);
819 filename = procmime_get_tmp_file_name(partinfo);
821 if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
823 (_("Can't save the part of multipart message."));
828 if (!prefs_common.mime_open_cmd_history)
829 prefs_common.mime_open_cmd_history =
830 add_history(NULL, prefs_common.mime_open_cmd);
832 cmd = input_dialog_combo
834 _("Enter the command line to open file:\n"
835 "(`%s' will be replaced with file name)"),
836 prefs_common.mime_open_cmd,
837 prefs_common.mime_open_cmd_history);
839 mimeview_view_file(filename, partinfo, cmd);
840 g_free(prefs_common.mime_open_cmd);
841 prefs_common.mime_open_cmd = cmd;
842 prefs_common.mime_open_cmd_history =
843 add_history(prefs_common.mime_open_cmd_history, cmd);
849 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
850 const gchar *cmdline)
852 static gchar *default_image_cmdline = "display '%s'";
853 static gchar *default_audio_cmdline = "play '%s'";
854 static gchar *default_html_cmdline =
855 "netscape -remote 'openURL(%s,raise)'";
856 static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
860 const gchar *def_cmd;
866 } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) {
868 } else if (MIME_IMAGE == partinfo->mime_type) {
869 cmd = prefs_common.mime_image_viewer;
870 def_cmd = default_image_cmdline;
871 } else if (MIME_AUDIO == partinfo->mime_type) {
872 cmd = prefs_common.mime_audio_player;
873 def_cmd = default_audio_cmdline;
874 } else if (MIME_TEXT_HTML == partinfo->mime_type) {
875 cmd = prefs_common.uri_cmd;
876 def_cmd = default_html_cmdline;
878 g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
879 partinfo->content_type, "%s");
884 if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
886 g_snprintf(buf, sizeof(buf), cmd, filename);
889 g_warning(_("MIME viewer command line is invalid: `%s'"), cmd);
891 g_snprintf(buf, sizeof(buf), def_cmd, filename);
896 execute_command_line(buf, TRUE);
900 static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
906 partinfo = gtk_ctree_node_get_row_data(ctree, node);
907 g_return_if_fail(partinfo != NULL);
909 part_name = get_part_name(partinfo);
910 gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
913 static void mimeview_update_names(MimeView *mimeview)
915 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
917 gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
920 static void mimeview_update_signature_info(MimeView *mimeview)
924 if (!mimeview) return;
925 if (!mimeview->opened) return;
927 partinfo = gtk_ctree_node_get_row_data
928 (GTK_CTREE(mimeview->ctree), mimeview->opened);
929 if (!partinfo) return;
931 if (g_strcasecmp(partinfo->content_type,
932 "application/pgp-signature") == 0) {
933 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
934 textview_show_signature_part(mimeview->textview, partinfo);
938 static void mimeview_check_signature(MimeView *mimeview)
944 g_return_if_fail (mimeview_is_signed(mimeview));
946 mimeinfo = gtk_ctree_node_get_row_data
947 (GTK_CTREE(mimeview->ctree), mimeview->opened);
948 g_return_if_fail(mimeinfo != NULL);
949 g_return_if_fail(mimeview->file != NULL);
951 while (mimeinfo->parent)
952 mimeinfo = mimeinfo->parent;
954 if ((fp = fopen(mimeview->file, "r")) == NULL) {
955 FILE_OP_ERROR(mimeview->file, "fopen");
960 if (mimeinfo->mime_type == MIME_MULTIPART) {
961 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
962 FILE_OP_ERROR(mimeview->file, "fseek");
963 while (fgets(buf, sizeof(buf), fp) != NULL)
964 if (buf[0] == '\r' || buf[0] == '\n') break;
967 procmime_scan_multipart_message(mimeinfo, fp);
968 rfc2015_check_signature(mimeinfo, fp);
971 mimeview_update_names(mimeview);
972 mimeview_update_signature_info(mimeview);
974 #endif /* USE_GPGME */