2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 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 void mimeview_button_pressed (GtkWidget *widget,
88 GdkEventButton *event,
90 static void 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;
140 gchar *titles[] = {_("MIME Type"), _("Size"), _("Name")};
144 debug_print(_("Creating MIME view...\n"));
145 mimeview = g_new0(MimeView, 1);
147 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
148 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
149 GTK_POLICY_AUTOMATIC,
151 gtk_widget_set_usize(scrolledwin, -1, 80);
153 ctree = gtk_sctree_new_with_titles(N_MIMEVIEW_COLS, 0, titles);
154 gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
155 gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_NONE);
156 gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_SIZE,
158 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_MIMETYPE, 240);
159 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_SIZE, 64);
160 for (i = 0; i < N_MIMEVIEW_COLS; i++)
161 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
163 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
165 gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
166 GTK_SIGNAL_FUNC(mimeview_selected), mimeview);
167 gtk_signal_connect(GTK_OBJECT(ctree), "button_press_event",
168 GTK_SIGNAL_FUNC(mimeview_button_pressed), mimeview);
169 gtk_signal_connect(GTK_OBJECT(ctree), "key_press_event",
170 GTK_SIGNAL_FUNC(mimeview_key_pressed), mimeview);
171 gtk_signal_connect(GTK_OBJECT (ctree),"start_drag",
172 GTK_SIGNAL_FUNC (mimeview_start_drag), mimeview);
173 gtk_signal_connect(GTK_OBJECT(ctree), "drag_data_get",
174 GTK_SIGNAL_FUNC(mimeview_drag_data_get), mimeview);
176 vbox = gtk_vbox_new(FALSE, 0);
178 paned = gtk_vpaned_new();
179 gtk_paned_add1(GTK_PANED(paned), scrolledwin);
180 gtk_paned_add2(GTK_PANED(paned), vbox);
181 gtk_widget_show_all(paned);
183 n_entries = sizeof(mimeview_popup_entries) /
184 sizeof(mimeview_popup_entries[0]);
185 popupmenu = menu_create_items(mimeview_popup_entries, n_entries,
186 "<MimeView>", &popupfactory, mimeview);
188 mimeview->paned = paned;
189 mimeview->scrolledwin = scrolledwin;
190 mimeview->ctree = ctree;
191 mimeview->vbox = vbox;
192 mimeview->popupmenu = popupmenu;
193 mimeview->popupfactory = popupfactory;
198 void mimeview_init(MimeView *mimeview)
203 * Check whether the message is OpenPGP signed
206 static gboolean mimeview_is_signed(MimeView *mimeview)
210 debug_print("mimeview_is signed of %p\n", mimeview);
212 if (!mimeview) return FALSE;
213 if (!mimeview->opened) return FALSE;
215 debug_print("mimeview_is_signed: open\n" );
217 if (!mimeview->file) return FALSE;
219 debug_print("mimeview_is_signed: file\n" );
221 partinfo = gtk_ctree_node_get_row_data
222 (GTK_CTREE(mimeview->ctree), mimeview->opened);
223 g_return_val_if_fail(partinfo != NULL, FALSE);
225 /* walk the tree and see whether there is a signature somewhere */
227 if (rfc2015_has_signature(partinfo))
229 if (pgptext_has_signature(partinfo))
231 } while ((partinfo = partinfo->parent) != NULL);
233 debug_print("mimeview_is_signed: FALSE\n" );
238 static void set_unchecked_signature(MimeInfo *mimeinfo)
240 MimeInfo *sig_partinfo;
242 sig_partinfo = rfc2015_find_signature(mimeinfo);
243 if (sig_partinfo == NULL) return;
245 g_free(sig_partinfo->sigstatus);
246 sig_partinfo->sigstatus =
247 g_strdup(_("Select \"Check signature\" to check"));
249 g_free(sig_partinfo->sigstatus_full);
250 sig_partinfo->sigstatus_full = NULL;
252 #endif /* USE_GPGME */
254 void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
257 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
262 mimeview_clear(mimeview);
264 g_return_if_fail(file != NULL);
265 g_return_if_fail(mimeinfo != NULL);
267 mimeview->mimeinfo = mimeinfo;
269 if ((fp = fopen(file, "r")) == NULL) {
270 FILE_OP_ERROR(file, "fopen");
273 mimeview->file = g_strdup(file);
275 /* skip MIME part headers */
276 if (mimeinfo->mime_type == MIME_MULTIPART) {
277 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
279 while (fgets(buf, sizeof(buf), fp) != NULL)
280 if (buf[0] == '\r' || buf[0] == '\n') break;
283 procmime_scan_multipart_message(mimeinfo, fp);
285 if (prefs_common.auto_check_signatures)
286 rfc2015_check_signature(mimeinfo, fp);
288 set_unchecked_signature(mimeinfo);
292 gtk_signal_handler_block_by_func(GTK_OBJECT(ctree), mimeview_selected,
295 mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
297 gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
298 mimeview_selected, mimeview);
300 /* search first text part */
301 for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
302 node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
305 partinfo = gtk_ctree_node_get_row_data(ctree, node);
306 if (partinfo && partinfo->mime_type == MIME_TEXT)
310 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
313 gtk_ctree_select(ctree, node);
314 gtkut_ctree_set_focus_row(ctree, node);
315 gtk_widget_grab_focus(mimeview->ctree);
319 void mimeview_destroy(MimeView *mimeview)
321 procmime_mimeinfo_free_all(mimeview->mimeinfo);
322 g_free(mimeview->file);
326 static void mimeview_set_multipart_tree(MimeView *mimeview,
328 GtkCTreeNode *parent)
330 g_return_if_fail(mimeinfo != NULL);
332 if (!mimeinfo->main && mimeinfo->parent)
333 parent = mimeview_append_part(mimeview, mimeinfo, parent);
335 if (mimeinfo->sub && mimeinfo->sub->children)
336 mimeview_set_multipart_tree(mimeview, mimeinfo->sub, parent);
338 if (mimeinfo->children) {
341 child = mimeinfo->children;
343 mimeview_set_multipart_tree(mimeview, child, parent);
349 static gchar *get_part_name(MimeInfo *partinfo)
352 if (partinfo->sigstatus)
353 return partinfo->sigstatus;
357 return partinfo->name;
358 else if (partinfo->filename)
359 return partinfo->filename;
364 static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
366 GtkCTreeNode *parent)
368 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
370 gchar *str[N_MIMEVIEW_COLS];
373 partinfo->content_type ? partinfo->content_type : "";
374 str[COL_SIZE] = to_human_readable(partinfo->size);
375 str[COL_NAME] = get_part_name(partinfo);
377 node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
378 NULL, NULL, NULL, NULL,
380 gtk_ctree_node_set_row_data(ctree, node, partinfo);
385 static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
393 if (!partinfo) return;
396 for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent)
398 fname = pi ? pi->plaintextfile : mimeview->file;
400 fname = mimeview->file;
401 #endif /* USE_GPGME */
404 if ((fp = fopen(fname, "r")) == NULL) {
405 FILE_OP_ERROR(fname, "fopen");
409 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0) {
410 FILE_OP_ERROR(mimeview->file, "fseek");
415 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
416 textview_show_part(mimeview->textview, partinfo, fp);
421 static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo)
425 if (!partinfo) return;
427 filename = procmime_get_tmp_file_name(partinfo);
429 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
431 (_("Can't get the part of multipart message."));
433 mimeview_change_view_type(mimeview, MIMEVIEW_IMAGE);
434 imageview_show_image(mimeview->imageview, partinfo, filename);
441 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
443 TextView *textview = mimeview->textview;
444 ImageView *imageview = mimeview->imageview;
446 if (mimeview->type == type) return;
450 gtk_container_remove(GTK_CONTAINER(mimeview->vbox),
451 GTK_WIDGET_PTR(textview));
452 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
453 GTK_WIDGET_PTR(imageview));
456 gtk_container_remove(GTK_CONTAINER(mimeview->vbox),
457 GTK_WIDGET_PTR(imageview));
458 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
459 GTK_WIDGET_PTR(textview));
465 mimeview->type = type;
468 static void mimeview_clear(MimeView *mimeview)
470 GtkCList *clist = GTK_CLIST(mimeview->ctree);
472 procmime_mimeinfo_free_all(mimeview->mimeinfo);
473 mimeview->mimeinfo = NULL;
475 gtk_clist_clear(clist);
476 textview_clear(mimeview->textview);
478 mimeview->opened = NULL;
480 g_free(mimeview->file);
481 mimeview->file = NULL;
484 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
489 if (mimeview->opened == node) return;
490 mimeview->opened = node;
491 gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
493 partinfo = gtk_ctree_node_get_row_data(ctree, node);
494 if (!partinfo) return;
496 /* ungrab the mouse event */
497 if (GTK_WIDGET_HAS_GRAB(ctree)) {
498 gtk_grab_remove(GTK_WIDGET(ctree));
499 if (gdk_pointer_is_grabbed())
500 gdk_pointer_ungrab(GDK_CURRENT_TIME);
503 switch (partinfo->mime_type) {
506 case MIME_TEXT_ENRICHED:
507 case MIME_MESSAGE_RFC822:
509 mimeview_show_message_part(mimeview, partinfo);
511 #if (HAVE_GDK_PIXBUF || HAVE_GDK_IMLIB)
513 mimeview_show_image_part(mimeview, partinfo);
517 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
519 if (g_strcasecmp(partinfo->content_type,
520 "application/pgp-signature") == 0)
521 textview_show_signature_part(mimeview->textview,
525 textview_show_mime_part(mimeview->textview, partinfo);
530 static void mimeview_start_drag (GtkWidget *widget, gint button,
531 GdkEvent *event, MimeView *mimeview)
534 GdkDragContext *context;
538 g_return_if_fail(mimeview != NULL);
539 ctree = GTK_CTREE(mimeview->ctree);
540 partinfo = gtk_ctree_node_get_row_data(ctree, mimeview->opened);
541 if (partinfo->filename == NULL && partinfo->name == NULL) return;
543 list = gtk_target_list_new(mimeview_mime_types, 1);
544 context = gtk_drag_begin(widget, list,
545 GDK_ACTION_COPY, button, event);
546 gtk_drag_set_icon_default(context);
549 static void mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
552 GtkCList *clist = GTK_CLIST(widget);
558 if (event->button == 2 || event->button == 3) {
559 if (!gtk_clist_get_selection_info(clist, event->x, event->y,
562 gtk_clist_unselect_all(clist);
563 gtk_clist_select_row(clist, row, column);
564 gtkut_clist_set_focus_row(clist, row);
567 if (event->button == 2 ||
568 (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
569 /* call external program for image, audio or html */
570 mimeview_launch(mimeview);
571 } else if (event->button == 3) {
572 partinfo = gtk_ctree_node_get_row_data
573 (GTK_CTREE(mimeview->ctree), mimeview->opened);
574 if (partinfo && (partinfo->mime_type == MIME_TEXT ||
575 partinfo->mime_type == MIME_TEXT_HTML ||
576 partinfo->mime_type == MIME_TEXT_ENRICHED ||
577 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
578 partinfo->mime_type == MIME_IMAGE ||
579 partinfo->mime_type == MIME_MULTIPART))
580 menu_set_sensitive(mimeview->popupfactory,
581 "/Display as text", FALSE);
583 menu_set_sensitive(mimeview->popupfactory,
584 "/Display as text", TRUE);
586 partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
587 menu_set_sensitive(mimeview->popupfactory,
590 menu_set_sensitive(mimeview->popupfactory,
593 menu_set_sensitive(mimeview->popupfactory,
595 mimeview_is_signed(mimeview));
598 gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
599 NULL, NULL, NULL, NULL,
600 event->button, event->time);
604 #define BREAK_ON_MODIFIER_KEY() \
605 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
607 static void mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
610 SummaryView *summaryview;
611 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
615 if (!mimeview->opened) return;
617 switch (event->keyval) {
619 if (textview_scroll_page(mimeview->textview, FALSE)) return;
621 node = GTK_CTREE_NODE_NEXT(mimeview->opened);
623 gtk_sctree_unselect_all(GTK_SCTREE(ctree));
624 gtk_sctree_select(GTK_SCTREE(ctree), node);
629 textview_scroll_page(mimeview->textview, TRUE);
632 textview_scroll_one_line(mimeview->textview,
633 (event->state & GDK_MOD1_MASK) != 0);
637 BREAK_ON_MODIFIER_KEY();
638 if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break;
640 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
641 GTK_SCROLL_STEP_FORWARD, 0.0);
645 BREAK_ON_MODIFIER_KEY();
646 if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break;
648 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
649 GTK_SCROLL_STEP_BACKWARD, 0.0);
652 BREAK_ON_MODIFIER_KEY();
653 mimeview_save_as(mimeview);
656 BREAK_ON_MODIFIER_KEY();
657 mimeview_display_as_text(mimeview);
660 BREAK_ON_MODIFIER_KEY();
661 mimeview_launch(mimeview);
667 if (!mimeview->messageview->mainwin) return;
668 summaryview = mimeview->messageview->mainwin->summaryview;
669 summary_pass_key_press_event(summaryview, event);
672 static void mimeview_drag_data_get(GtkWidget *widget,
673 GdkDragContext *drag_context,
674 GtkSelectionData *selection_data,
679 gchar *filename, *uriname;
682 if (!mimeview->opened) return;
683 if (!mimeview->file) return;
685 partinfo = gtk_ctree_node_get_row_data
686 (GTK_CTREE(mimeview->ctree), mimeview->opened);
687 if (!partinfo) return;
688 if (!partinfo->filename && !partinfo->name) return;
690 filename = partinfo->filename ? partinfo->filename : partinfo->name;
691 filename = g_basename(filename);
692 if (*filename == '\0') return;
694 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
697 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
699 (_("Can't save the part of multipart message."));
701 uriname = g_strconcat("file:/", filename, NULL);
702 gtk_selection_data_set(selection_data, selection_data->target, 8,
703 uriname, strlen(uriname));
709 static void mimeview_display_as_text(MimeView *mimeview)
713 if (!mimeview->opened) return;
715 partinfo = gtk_ctree_node_get_row_data
716 (GTK_CTREE(mimeview->ctree), mimeview->opened);
717 mimeview_show_message_part(mimeview, partinfo);
720 static void mimeview_save_as(MimeView *mimeview)
725 if (!mimeview->opened) return;
726 if (!mimeview->file) return;
728 partinfo = gtk_ctree_node_get_row_data
729 (GTK_CTREE(mimeview->ctree), mimeview->opened);
730 g_return_if_fail(partinfo != NULL);
732 filename = filesel_select_file
734 partinfo->filename ? partinfo->filename : partinfo->name);
735 if (!filename) return;
736 if (is_file_exist(filename)) {
739 aval = alertpanel(_("Overwrite"),
740 _("Overwrite existing file?"),
741 _("OK"), _("Cancel"), NULL);
742 if (G_ALERTDEFAULT != aval) return;
745 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
747 (_("Can't save the part of multipart message."));
750 static void mimeview_launch(MimeView *mimeview)
755 if (!mimeview->opened) return;
756 if (!mimeview->file) return;
758 partinfo = gtk_ctree_node_get_row_data
759 (GTK_CTREE(mimeview->ctree), mimeview->opened);
760 g_return_if_fail(partinfo != NULL);
762 filename = procmime_get_tmp_file_name(partinfo);
764 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
766 (_("Can't save the part of multipart message."));
768 mimeview_view_file(filename, partinfo, NULL);
773 static void mimeview_open_with(MimeView *mimeview)
779 if (!mimeview->opened) return;
780 if (!mimeview->file) return;
782 partinfo = gtk_ctree_node_get_row_data
783 (GTK_CTREE(mimeview->ctree), mimeview->opened);
784 g_return_if_fail(partinfo != NULL);
786 filename = procmime_get_tmp_file_name(partinfo);
788 if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
790 (_("Can't save the part of multipart message."));
795 if (!prefs_common.mime_open_cmd_history)
796 prefs_common.mime_open_cmd_history =
797 add_history(NULL, prefs_common.mime_open_cmd);
799 cmd = input_dialog_combo
801 _("Enter the command line to open file:\n"
802 "(`%s' will be replaced with file name)"),
803 prefs_common.mime_open_cmd,
804 prefs_common.mime_open_cmd_history);
806 mimeview_view_file(filename, partinfo, cmd);
807 g_free(prefs_common.mime_open_cmd);
808 prefs_common.mime_open_cmd = cmd;
809 prefs_common.mime_open_cmd_history =
810 add_history(prefs_common.mime_open_cmd_history, cmd);
816 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
817 const gchar *cmdline)
819 static gchar *default_image_cmdline = "display '%s'";
820 static gchar *default_audio_cmdline = "play '%s'";
821 static gchar *default_html_cmdline =
822 "netscape -remote 'openURL(%s,raise)'";
823 static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
827 const gchar *def_cmd;
833 } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) {
835 } else if (MIME_IMAGE == partinfo->mime_type) {
836 cmd = prefs_common.mime_image_viewer;
837 def_cmd = default_image_cmdline;
838 } else if (MIME_AUDIO == partinfo->mime_type) {
839 cmd = prefs_common.mime_audio_player;
840 def_cmd = default_audio_cmdline;
841 } else if (MIME_TEXT_HTML == partinfo->mime_type) {
842 cmd = prefs_common.uri_cmd;
843 def_cmd = default_html_cmdline;
845 g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
846 partinfo->content_type, "%s");
851 if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
853 g_snprintf(buf, sizeof(buf), cmd, filename);
856 g_warning(_("MIME viewer command line is invalid: `%s'"), cmd);
858 g_snprintf(buf, sizeof(buf), def_cmd, filename);
863 execute_command_line(buf, TRUE);
867 static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
873 partinfo = gtk_ctree_node_get_row_data(ctree, node);
874 g_return_if_fail(partinfo != NULL);
876 part_name = get_part_name(partinfo);
877 gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
880 static void mimeview_update_names(MimeView *mimeview)
882 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
884 gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
887 static void mimeview_update_signature_info(MimeView *mimeview)
891 if (!mimeview) return;
892 if (!mimeview->opened) return;
894 partinfo = gtk_ctree_node_get_row_data
895 (GTK_CTREE(mimeview->ctree), mimeview->opened);
896 if (!partinfo) return;
898 if (g_strcasecmp(partinfo->content_type,
899 "application/pgp-signature") == 0) {
900 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
901 textview_show_signature_part(mimeview->textview, partinfo);
905 static void mimeview_check_signature(MimeView *mimeview)
911 g_return_if_fail (mimeview_is_signed(mimeview));
913 mimeinfo = gtk_ctree_node_get_row_data
914 (GTK_CTREE(mimeview->ctree), mimeview->opened);
915 g_return_if_fail(mimeinfo != NULL);
916 g_return_if_fail(mimeview->file != NULL);
918 while (mimeinfo->parent)
919 mimeinfo = mimeinfo->parent;
921 if ((fp = fopen(mimeview->file, "r")) == NULL) {
922 FILE_OP_ERROR(mimeview->file, "fopen");
927 if (mimeinfo->mime_type == MIME_MULTIPART) {
928 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
929 FILE_OP_ERROR(mimeview->file, "fseek");
930 while (fgets(buf, sizeof(buf), fp) != NULL)
931 if (buf[0] == '\r' || buf[0] == '\n') break;
934 procmime_scan_multipart_message(mimeinfo, fp);
935 rfc2015_check_signature(mimeinfo, fp);
938 mimeview_update_names(mimeview);
939 mimeview_update_signature_info(mimeview);
941 #endif /* USE_GPGME */