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);
307 (partinfo->mime_type == MIME_TEXT ||
308 partinfo->mime_type == MIME_TEXT_HTML))
312 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
315 gtk_ctree_select(ctree, node);
316 gtkut_ctree_set_focus_row(ctree, node);
317 gtk_widget_grab_focus(mimeview->ctree);
321 void mimeview_destroy(MimeView *mimeview)
323 procmime_mimeinfo_free_all(mimeview->mimeinfo);
324 g_free(mimeview->file);
328 static void mimeview_set_multipart_tree(MimeView *mimeview,
330 GtkCTreeNode *parent)
332 g_return_if_fail(mimeinfo != NULL);
334 if (!mimeinfo->main && mimeinfo->parent)
335 parent = mimeview_append_part(mimeview, mimeinfo, parent);
337 if (mimeinfo->sub && mimeinfo->sub->children)
338 mimeview_set_multipart_tree(mimeview, mimeinfo->sub, parent);
340 if (mimeinfo->children) {
343 child = mimeinfo->children;
345 mimeview_set_multipart_tree(mimeview, child, parent);
351 static gchar *get_part_name(MimeInfo *partinfo)
354 if (partinfo->sigstatus)
355 return partinfo->sigstatus;
359 return partinfo->name;
360 else if (partinfo->filename)
361 return partinfo->filename;
366 static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
368 GtkCTreeNode *parent)
370 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
372 gchar *str[N_MIMEVIEW_COLS];
375 partinfo->content_type ? partinfo->content_type : "";
376 str[COL_SIZE] = to_human_readable(partinfo->size);
377 str[COL_NAME] = get_part_name(partinfo);
379 node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
380 NULL, NULL, NULL, NULL,
382 gtk_ctree_node_set_row_data(ctree, node, partinfo);
387 static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
395 if (!partinfo) return;
398 for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent)
400 fname = pi ? pi->plaintextfile : mimeview->file;
402 fname = mimeview->file;
403 #endif /* USE_GPGME */
406 if ((fp = fopen(fname, "r")) == NULL) {
407 FILE_OP_ERROR(fname, "fopen");
411 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0) {
412 FILE_OP_ERROR(mimeview->file, "fseek");
417 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
418 textview_show_part(mimeview->textview, partinfo, fp);
423 static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo)
427 if (!partinfo) return;
429 filename = procmime_get_tmp_file_name(partinfo);
431 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
433 (_("Can't get the part of multipart message."));
435 mimeview_change_view_type(mimeview, MIMEVIEW_IMAGE);
436 imageview_show_image(mimeview->imageview, partinfo, filename);
443 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
445 TextView *textview = mimeview->textview;
446 ImageView *imageview = mimeview->imageview;
448 if (mimeview->type == type) return;
452 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
453 GTK_WIDGET_PTR(textview));
454 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
455 GTK_WIDGET_PTR(imageview));
458 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
459 GTK_WIDGET_PTR(imageview));
460 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
461 GTK_WIDGET_PTR(textview));
467 mimeview->type = type;
470 static void mimeview_clear(MimeView *mimeview)
472 GtkCList *clist = GTK_CLIST(mimeview->ctree);
474 procmime_mimeinfo_free_all(mimeview->mimeinfo);
475 mimeview->mimeinfo = NULL;
477 gtk_clist_clear(clist);
478 textview_clear(mimeview->textview);
480 mimeview->opened = NULL;
482 g_free(mimeview->file);
483 mimeview->file = NULL;
486 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
491 if (mimeview->opened == node) return;
492 mimeview->opened = node;
493 gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
495 partinfo = gtk_ctree_node_get_row_data(ctree, node);
496 if (!partinfo) return;
498 /* ungrab the mouse event */
499 if (GTK_WIDGET_HAS_GRAB(ctree)) {
500 gtk_grab_remove(GTK_WIDGET(ctree));
501 if (gdk_pointer_is_grabbed())
502 gdk_pointer_ungrab(GDK_CURRENT_TIME);
505 switch (partinfo->mime_type) {
508 case MIME_TEXT_ENRICHED:
509 case MIME_MESSAGE_RFC822:
511 mimeview_show_message_part(mimeview, partinfo);
513 #if (HAVE_GDK_PIXBUF || HAVE_GDK_IMLIB)
515 mimeview_show_image_part(mimeview, partinfo);
519 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
521 if (g_strcasecmp(partinfo->content_type,
522 "application/pgp-signature") == 0)
523 textview_show_signature_part(mimeview->textview,
527 textview_show_mime_part(mimeview->textview, partinfo);
532 static void mimeview_start_drag (GtkWidget *widget, gint button,
533 GdkEvent *event, MimeView *mimeview)
536 GdkDragContext *context;
540 g_return_if_fail(mimeview != NULL);
541 ctree = GTK_CTREE(mimeview->ctree);
542 partinfo = gtk_ctree_node_get_row_data(ctree, mimeview->opened);
543 if (partinfo->filename == NULL && partinfo->name == NULL) return;
545 list = gtk_target_list_new(mimeview_mime_types, 1);
546 context = gtk_drag_begin(widget, list,
547 GDK_ACTION_COPY, button, event);
548 gtk_drag_set_icon_default(context);
551 static void mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
554 GtkCList *clist = GTK_CLIST(widget);
560 if (event->button == 2 || event->button == 3) {
561 if (!gtk_clist_get_selection_info(clist, event->x, event->y,
564 gtk_clist_unselect_all(clist);
565 gtk_clist_select_row(clist, row, column);
566 gtkut_clist_set_focus_row(clist, row);
569 if (event->button == 2 ||
570 (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
571 /* call external program for image, audio or html */
572 mimeview_launch(mimeview);
573 } else if (event->button == 3) {
574 partinfo = gtk_ctree_node_get_row_data
575 (GTK_CTREE(mimeview->ctree), mimeview->opened);
576 if (partinfo && (partinfo->mime_type == MIME_TEXT ||
577 partinfo->mime_type == MIME_TEXT_HTML ||
578 partinfo->mime_type == MIME_TEXT_ENRICHED ||
579 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
580 partinfo->mime_type == MIME_IMAGE ||
581 partinfo->mime_type == MIME_MULTIPART))
582 menu_set_sensitive(mimeview->popupfactory,
583 "/Display as text", FALSE);
585 menu_set_sensitive(mimeview->popupfactory,
586 "/Display as text", TRUE);
588 partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
589 menu_set_sensitive(mimeview->popupfactory,
592 menu_set_sensitive(mimeview->popupfactory,
595 menu_set_sensitive(mimeview->popupfactory,
597 mimeview_is_signed(mimeview));
600 gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
601 NULL, NULL, NULL, NULL,
602 event->button, event->time);
606 #define BREAK_ON_MODIFIER_KEY() \
607 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
609 static void mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
612 SummaryView *summaryview;
613 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
617 if (!mimeview->opened) return;
619 switch (event->keyval) {
621 if (textview_scroll_page(mimeview->textview, FALSE)) return;
623 node = GTK_CTREE_NODE_NEXT(mimeview->opened);
625 gtk_sctree_unselect_all(GTK_SCTREE(ctree));
626 gtk_sctree_select(GTK_SCTREE(ctree), node);
631 textview_scroll_page(mimeview->textview, TRUE);
634 textview_scroll_one_line(mimeview->textview,
635 (event->state & GDK_MOD1_MASK) != 0);
639 BREAK_ON_MODIFIER_KEY();
640 if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break;
642 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
643 GTK_SCROLL_STEP_FORWARD, 0.0);
647 BREAK_ON_MODIFIER_KEY();
648 if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break;
650 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
651 GTK_SCROLL_STEP_BACKWARD, 0.0);
654 BREAK_ON_MODIFIER_KEY();
655 mimeview_save_as(mimeview);
658 BREAK_ON_MODIFIER_KEY();
659 mimeview_display_as_text(mimeview);
662 BREAK_ON_MODIFIER_KEY();
663 mimeview_launch(mimeview);
669 if (!mimeview->messageview->mainwin) return;
670 summaryview = mimeview->messageview->mainwin->summaryview;
671 summary_pass_key_press_event(summaryview, event);
674 static void mimeview_drag_data_get(GtkWidget *widget,
675 GdkDragContext *drag_context,
676 GtkSelectionData *selection_data,
681 gchar *filename, *uriname;
684 if (!mimeview->opened) return;
685 if (!mimeview->file) return;
687 partinfo = gtk_ctree_node_get_row_data
688 (GTK_CTREE(mimeview->ctree), mimeview->opened);
689 if (!partinfo) return;
690 if (!partinfo->filename && !partinfo->name) return;
692 filename = partinfo->filename ? partinfo->filename : partinfo->name;
693 filename = g_basename(filename);
694 if (*filename == '\0') return;
696 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
699 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
701 (_("Can't save the part of multipart message."));
703 uriname = g_strconcat("file:/", filename, NULL);
704 gtk_selection_data_set(selection_data, selection_data->target, 8,
705 uriname, strlen(uriname));
711 static void mimeview_display_as_text(MimeView *mimeview)
715 if (!mimeview->opened) return;
717 partinfo = gtk_ctree_node_get_row_data
718 (GTK_CTREE(mimeview->ctree), mimeview->opened);
719 mimeview_show_message_part(mimeview, partinfo);
722 static void mimeview_save_as(MimeView *mimeview)
727 if (!mimeview->opened) return;
728 if (!mimeview->file) return;
730 partinfo = gtk_ctree_node_get_row_data
731 (GTK_CTREE(mimeview->ctree), mimeview->opened);
732 g_return_if_fail(partinfo != NULL);
734 filename = filesel_select_file
736 partinfo->filename ? partinfo->filename : partinfo->name);
737 if (!filename) return;
738 if (is_file_exist(filename)) {
741 aval = alertpanel(_("Overwrite"),
742 _("Overwrite existing file?"),
743 _("OK"), _("Cancel"), NULL);
744 if (G_ALERTDEFAULT != aval) return;
747 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
749 (_("Can't save the part of multipart message."));
752 static void mimeview_launch(MimeView *mimeview)
757 if (!mimeview->opened) return;
758 if (!mimeview->file) return;
760 partinfo = gtk_ctree_node_get_row_data
761 (GTK_CTREE(mimeview->ctree), mimeview->opened);
762 g_return_if_fail(partinfo != NULL);
764 filename = procmime_get_tmp_file_name(partinfo);
766 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
768 (_("Can't save the part of multipart message."));
770 mimeview_view_file(filename, partinfo, NULL);
775 static void mimeview_open_with(MimeView *mimeview)
781 if (!mimeview->opened) return;
782 if (!mimeview->file) return;
784 partinfo = gtk_ctree_node_get_row_data
785 (GTK_CTREE(mimeview->ctree), mimeview->opened);
786 g_return_if_fail(partinfo != NULL);
788 filename = procmime_get_tmp_file_name(partinfo);
790 if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
792 (_("Can't save the part of multipart message."));
797 if (!prefs_common.mime_open_cmd_history)
798 prefs_common.mime_open_cmd_history =
799 add_history(NULL, prefs_common.mime_open_cmd);
801 cmd = input_dialog_combo
803 _("Enter the command line to open file:\n"
804 "(`%s' will be replaced with file name)"),
805 prefs_common.mime_open_cmd,
806 prefs_common.mime_open_cmd_history);
808 mimeview_view_file(filename, partinfo, cmd);
809 g_free(prefs_common.mime_open_cmd);
810 prefs_common.mime_open_cmd = cmd;
811 prefs_common.mime_open_cmd_history =
812 add_history(prefs_common.mime_open_cmd_history, cmd);
818 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
819 const gchar *cmdline)
821 static gchar *default_image_cmdline = "display '%s'";
822 static gchar *default_audio_cmdline = "play '%s'";
823 static gchar *default_html_cmdline =
824 "netscape -remote 'openURL(%s,raise)'";
825 static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
829 const gchar *def_cmd;
835 } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) {
837 } else if (MIME_IMAGE == partinfo->mime_type) {
838 cmd = prefs_common.mime_image_viewer;
839 def_cmd = default_image_cmdline;
840 } else if (MIME_AUDIO == partinfo->mime_type) {
841 cmd = prefs_common.mime_audio_player;
842 def_cmd = default_audio_cmdline;
843 } else if (MIME_TEXT_HTML == partinfo->mime_type) {
844 cmd = prefs_common.uri_cmd;
845 def_cmd = default_html_cmdline;
847 g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
848 partinfo->content_type, "%s");
853 if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
855 g_snprintf(buf, sizeof(buf), cmd, filename);
858 g_warning(_("MIME viewer command line is invalid: `%s'"), cmd);
860 g_snprintf(buf, sizeof(buf), def_cmd, filename);
865 execute_command_line(buf, TRUE);
869 static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
875 partinfo = gtk_ctree_node_get_row_data(ctree, node);
876 g_return_if_fail(partinfo != NULL);
878 part_name = get_part_name(partinfo);
879 gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
882 static void mimeview_update_names(MimeView *mimeview)
884 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
886 gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
889 static void mimeview_update_signature_info(MimeView *mimeview)
893 if (!mimeview) return;
894 if (!mimeview->opened) return;
896 partinfo = gtk_ctree_node_get_row_data
897 (GTK_CTREE(mimeview->ctree), mimeview->opened);
898 if (!partinfo) return;
900 if (g_strcasecmp(partinfo->content_type,
901 "application/pgp-signature") == 0) {
902 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
903 textview_show_signature_part(mimeview->textview, partinfo);
907 static void mimeview_check_signature(MimeView *mimeview)
913 g_return_if_fail (mimeview_is_signed(mimeview));
915 mimeinfo = gtk_ctree_node_get_row_data
916 (GTK_CTREE(mimeview->ctree), mimeview->opened);
917 g_return_if_fail(mimeinfo != NULL);
918 g_return_if_fail(mimeview->file != NULL);
920 while (mimeinfo->parent)
921 mimeinfo = mimeinfo->parent;
923 if ((fp = fopen(mimeview->file, "r")) == NULL) {
924 FILE_OP_ERROR(mimeview->file, "fopen");
929 if (mimeinfo->mime_type == MIME_MULTIPART) {
930 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
931 FILE_OP_ERROR(mimeview->file, "fseek");
932 while (fgets(buf, sizeof(buf), fp) != NULL)
933 if (buf[0] == '\r' || buf[0] == '\n') break;
936 procmime_scan_multipart_message(mimeinfo, fp);
937 rfc2015_check_signature(mimeinfo, fp);
940 mimeview_update_names(mimeview);
941 mimeview_update_signature_info(mimeview);
943 #endif /* USE_GPGME */