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/gtknotebook.h>
29 #include <gtk/gtkscrolledwindow.h>
30 #include <gtk/gtkctree.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtkvpaned.h>
33 #include <gtk/gtktext.h>
34 #include <gtk/gtksignal.h>
35 #include <gtk/gtkmenu.h>
36 #include <gtk/gtkdnd.h>
37 #include <gtk/gtkselection.h>
46 #include "summaryview.h"
49 #include "alertpanel.h"
50 #include "inputdialog.h"
53 #include "prefs_common.h"
64 #define N_MIMEVIEW_COLS 3
66 static void mimeview_set_multipart_tree (MimeView *mimeview,
68 GtkCTreeNode *parent);
69 static GtkCTreeNode *mimeview_append_part (MimeView *mimeview,
71 GtkCTreeNode *parent);
72 static void mimeview_show_message_part (MimeView *mimeview,
74 static void mimeview_show_image_part (MimeView *mimeview,
76 static void mimeview_change_view_type (MimeView *mimeview,
78 static void mimeview_clear (MimeView *mimeview);
80 static void mimeview_selected (GtkCTree *ctree,
84 static void mimeview_start_drag (GtkWidget *widget,
88 static gint mimeview_button_pressed (GtkWidget *widget,
89 GdkEventButton *event,
91 static gint mimeview_key_pressed (GtkWidget *widget,
95 static void mimeview_drag_data_get (GtkWidget *widget,
96 GdkDragContext *drag_context,
97 GtkSelectionData *selection_data,
102 static void mimeview_display_as_text (MimeView *mimeview);
103 static void mimeview_save_as (MimeView *mimeview);
104 static void mimeview_launch (MimeView *mimeview);
105 static void mimeview_open_with (MimeView *mimeview);
106 static void mimeview_view_file (const gchar *filename,
108 const gchar *cmdline);
110 static void mimeview_check_signature (MimeView *mimeview);
113 static GtkItemFactoryEntry mimeview_popup_entries[] =
115 {N_("/_Open"), NULL, mimeview_launch, 0, NULL},
116 {N_("/Open _with..."), NULL, mimeview_open_with, 0, NULL},
117 {N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
118 {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL}
121 {N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL}
125 static GtkTargetEntry mimeview_mime_types[] =
127 {"text/uri-list", 0, 0}
130 MimeView *mimeview_create(void)
137 GtkWidget *scrolledwin;
139 GtkWidget *mime_vbox;
140 GtkWidget *popupmenu;
141 GtkItemFactory *popupfactory;
142 gchar *titles[N_MIMEVIEW_COLS];
146 debug_print(_("Creating MIME view...\n"));
147 mimeview = g_new0(MimeView, 1);
149 titles[COL_MIMETYPE] = _("MIME Type");
150 titles[COL_SIZE] = _("Size");
151 titles[COL_NAME] = _("Name");
153 notebook = gtk_notebook_new();
154 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
156 vbox = gtk_vbox_new(FALSE, 0);
157 gtk_container_add(GTK_CONTAINER(notebook), vbox);
158 gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook), vbox,
161 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
162 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
163 GTK_POLICY_AUTOMATIC,
165 gtk_widget_set_usize(scrolledwin, -1, 80);
167 ctree = gtk_sctree_new_with_titles(N_MIMEVIEW_COLS, 0, titles);
168 gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
169 gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_NONE);
170 gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_SIZE,
172 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_MIMETYPE, 240);
173 gtk_clist_set_column_width(GTK_CLIST(ctree), COL_SIZE, 64);
174 for (i = 0; i < N_MIMEVIEW_COLS; i++)
175 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
177 gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
179 gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
180 GTK_SIGNAL_FUNC(mimeview_selected), mimeview);
181 gtk_signal_connect(GTK_OBJECT(ctree), "button_press_event",
182 GTK_SIGNAL_FUNC(mimeview_button_pressed), mimeview);
183 gtk_signal_connect(GTK_OBJECT(ctree), "key_press_event",
184 GTK_SIGNAL_FUNC(mimeview_key_pressed), mimeview);
185 gtk_signal_connect(GTK_OBJECT (ctree),"start_drag",
186 GTK_SIGNAL_FUNC (mimeview_start_drag), mimeview);
187 gtk_signal_connect(GTK_OBJECT(ctree), "drag_data_get",
188 GTK_SIGNAL_FUNC(mimeview_drag_data_get), mimeview);
190 mime_vbox = gtk_vbox_new(FALSE, 0);
192 paned = gtk_vpaned_new();
193 gtk_paned_add1(GTK_PANED(paned), scrolledwin);
194 gtk_paned_add2(GTK_PANED(paned), mime_vbox);
195 gtk_container_add(GTK_CONTAINER(notebook), paned);
196 gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook), paned,
199 gtk_widget_show_all(notebook);
201 n_entries = sizeof(mimeview_popup_entries) /
202 sizeof(mimeview_popup_entries[0]);
203 popupmenu = menu_create_items(mimeview_popup_entries, n_entries,
204 "<MimeView>", &popupfactory, mimeview);
206 mimeview->notebook = notebook;
207 mimeview->vbox = vbox;
208 mimeview->paned = paned;
209 mimeview->scrolledwin = scrolledwin;
210 mimeview->ctree = ctree;
211 mimeview->mime_vbox = mime_vbox;
212 mimeview->popupmenu = popupmenu;
213 mimeview->popupfactory = popupfactory;
219 void mimeview_init(MimeView *mimeview)
224 * Check whether the message is OpenPGP signed
227 static gboolean mimeview_is_signed(MimeView *mimeview)
231 debug_print("mimeview_is signed of %p\n", mimeview);
233 if (!mimeview) return FALSE;
234 if (!mimeview->opened) return FALSE;
236 debug_print("mimeview_is_signed: open\n" );
238 if (!mimeview->file) return FALSE;
240 debug_print("mimeview_is_signed: file\n" );
242 partinfo = gtk_ctree_node_get_row_data
243 (GTK_CTREE(mimeview->ctree), mimeview->opened);
244 g_return_val_if_fail(partinfo != NULL, FALSE);
246 /* walk the tree and see whether there is a signature somewhere */
248 if (rfc2015_has_signature(partinfo))
250 if (pgptext_has_signature(partinfo))
252 } while ((partinfo = partinfo->parent) != NULL);
254 debug_print("mimeview_is_signed: FALSE\n" );
259 static void set_unchecked_signature(MimeInfo *mimeinfo)
261 MimeInfo *sig_partinfo;
263 sig_partinfo = rfc2015_find_signature(mimeinfo);
264 if (sig_partinfo == NULL) return;
266 g_free(sig_partinfo->sigstatus);
267 sig_partinfo->sigstatus =
268 g_strdup(_("Select \"Check signature\" to check"));
270 g_free(sig_partinfo->sigstatus_full);
271 sig_partinfo->sigstatus_full = NULL;
273 #endif /* USE_GPGME */
275 void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
278 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
283 mimeview_clear(mimeview);
284 textview_clear(mimeview->messageview->textview);
286 g_return_if_fail(file != NULL);
287 g_return_if_fail(mimeinfo != NULL);
289 mimeview->mimeinfo = mimeinfo;
291 if ((fp = fopen(file, "r")) == NULL) {
292 FILE_OP_ERROR(file, "fopen");
295 mimeview->file = g_strdup(file);
297 /* skip MIME part headers */
298 if (mimeinfo->mime_type == MIME_MULTIPART) {
299 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
301 while (fgets(buf, sizeof(buf), fp) != NULL)
302 if (buf[0] == '\r' || buf[0] == '\n') break;
305 procmime_scan_multipart_message(mimeinfo, fp);
307 if (prefs_common.auto_check_signatures)
308 rfc2015_check_signature(mimeinfo, fp);
310 set_unchecked_signature(mimeinfo);
313 gtk_signal_handler_block_by_func(GTK_OBJECT(ctree), mimeview_selected,
316 mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
318 gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
319 mimeview_selected, mimeview);
321 /* search first text part */
322 for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
323 node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
326 partinfo = gtk_ctree_node_get_row_data(ctree, node);
328 (partinfo->mime_type == MIME_TEXT ||
329 partinfo->mime_type == MIME_TEXT_HTML)) {
330 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0)
334 (mimeview->messageview->textview,
342 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
345 gtk_ctree_select(ctree, node);
346 gtkut_ctree_set_focus_row(ctree, node);
347 gtk_widget_grab_focus(mimeview->ctree);
351 void mimeview_destroy(MimeView *mimeview)
353 procmime_mimeinfo_free_all(mimeview->mimeinfo);
354 g_free(mimeview->file);
358 static void mimeview_set_multipart_tree(MimeView *mimeview,
360 GtkCTreeNode *parent)
362 GtkCTreeNode *current = parent;
364 g_return_if_fail(mimeinfo != NULL);
366 if (!mimeinfo->sub && mimeinfo->parent)
367 current = mimeview_append_part(mimeview, mimeinfo, parent);
370 mimeview_set_multipart_tree(mimeview, mimeinfo->sub, current);
372 if (mimeinfo->children)
373 mimeview_set_multipart_tree(mimeview, mimeinfo->children, current);
376 mimeview_set_multipart_tree(mimeview, mimeinfo->next, parent);
379 static gchar *get_part_name(MimeInfo *partinfo)
382 if (partinfo->sigstatus)
383 return partinfo->sigstatus;
387 return partinfo->name;
388 else if (partinfo->filename)
389 return partinfo->filename;
394 static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
396 GtkCTreeNode *parent)
398 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
400 gchar *str[N_MIMEVIEW_COLS];
403 partinfo->content_type ? partinfo->content_type : "";
404 str[COL_SIZE] = to_human_readable(partinfo->size);
405 str[COL_NAME] = get_part_name(partinfo);
407 node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
408 NULL, NULL, NULL, NULL,
410 gtk_ctree_node_set_row_data(ctree, node, partinfo);
415 static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
423 if (!partinfo) return;
426 for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent)
428 fname = pi ? pi->plaintextfile : mimeview->file;
430 fname = mimeview->file;
431 #endif /* USE_GPGME */
434 if ((fp = fopen(fname, "r")) == NULL) {
435 FILE_OP_ERROR(fname, "fopen");
439 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0) {
440 FILE_OP_ERROR(mimeview->file, "fseek");
445 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
446 textview_show_part(mimeview->textview, partinfo, fp);
451 static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo)
455 if (!partinfo) return;
457 filename = procmime_get_tmp_file_name(partinfo);
459 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
461 (_("Can't get the part of multipart message."));
463 mimeview_change_view_type(mimeview, MIMEVIEW_IMAGE);
464 /* Workaround for the GTK+ bug with handling scroll adjustments
466 imageview_clear(mimeview->imageview);
467 imageview_show_image(mimeview->imageview, partinfo, filename);
474 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
476 TextView *textview = mimeview->textview;
477 ImageView *imageview = mimeview->imageview;
480 if (mimeview->type == type) return;
482 children = gtk_container_children(GTK_CONTAINER(mimeview->mime_vbox));
484 gtkut_container_remove(GTK_CONTAINER(mimeview->mime_vbox),
485 GTK_WIDGET(children->data));
486 g_list_free(children);
491 gtk_container_add(GTK_CONTAINER(mimeview->mime_vbox),
492 GTK_WIDGET_PTR(imageview));
495 gtk_container_add(GTK_CONTAINER(mimeview->mime_vbox),
496 GTK_WIDGET_PTR(textview));
502 mimeview->type = type;
505 static void mimeview_clear(MimeView *mimeview)
507 GtkCList *clist = GTK_CLIST(mimeview->ctree);
509 procmime_mimeinfo_free_all(mimeview->mimeinfo);
510 mimeview->mimeinfo = NULL;
512 gtk_clist_clear(clist);
513 textview_clear(mimeview->textview);
514 imageview_clear(mimeview->imageview);
516 mimeview->opened = NULL;
518 g_free(mimeview->file);
519 mimeview->file = NULL;
521 /* gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 0); */
524 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
529 if (mimeview->opened == node) return;
530 mimeview->opened = node;
531 gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
533 partinfo = gtk_ctree_node_get_row_data(ctree, node);
534 if (!partinfo) return;
536 /* ungrab the mouse event */
537 if (GTK_WIDGET_HAS_GRAB(ctree)) {
538 gtk_grab_remove(GTK_WIDGET(ctree));
539 if (gdk_pointer_is_grabbed())
540 gdk_pointer_ungrab(GDK_CURRENT_TIME);
543 switch (partinfo->mime_type) {
546 case MIME_TEXT_ENRICHED:
547 case MIME_MESSAGE_RFC822:
549 mimeview_show_message_part(mimeview, partinfo);
551 #if (HAVE_GDK_PIXBUF || HAVE_GDK_IMLIB)
553 mimeview_show_image_part(mimeview, partinfo);
557 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
559 if (g_strcasecmp(partinfo->content_type,
560 "application/pgp-signature") == 0)
561 textview_show_signature_part(mimeview->textview,
565 textview_show_mime_part(mimeview->textview, partinfo);
570 static void mimeview_start_drag(GtkWidget *widget, gint button,
571 GdkEvent *event, MimeView *mimeview)
574 GdkDragContext *context;
578 g_return_if_fail(mimeview != NULL);
579 ctree = GTK_CTREE(mimeview->ctree);
580 partinfo = gtk_ctree_node_get_row_data(ctree, mimeview->opened);
581 if (partinfo->filename == NULL && partinfo->name == NULL) return;
583 list = gtk_target_list_new(mimeview_mime_types, 1);
584 context = gtk_drag_begin(widget, list,
585 GDK_ACTION_COPY, button, event);
586 gtk_drag_set_icon_default(context);
589 static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
592 GtkCList *clist = GTK_CLIST(widget);
596 if (!event) return FALSE;
598 if (event->button == 2 || event->button == 3) {
599 if (!gtk_clist_get_selection_info(clist, event->x, event->y,
602 gtk_clist_unselect_all(clist);
603 gtk_clist_select_row(clist, row, column);
604 gtkut_clist_set_focus_row(clist, row);
607 if (event->button == 2 ||
608 (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
609 /* call external program for image, audio or html */
610 mimeview_launch(mimeview);
611 } else if (event->button == 3) {
612 partinfo = gtk_ctree_node_get_row_data
613 (GTK_CTREE(mimeview->ctree), mimeview->opened);
614 if (partinfo && (partinfo->mime_type == MIME_TEXT ||
615 partinfo->mime_type == MIME_TEXT_HTML ||
616 partinfo->mime_type == MIME_TEXT_ENRICHED ||
617 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
618 partinfo->mime_type == MIME_IMAGE ||
619 partinfo->mime_type == MIME_MULTIPART))
620 menu_set_sensitive(mimeview->popupfactory,
621 "/Display as text", FALSE);
623 menu_set_sensitive(mimeview->popupfactory,
624 "/Display as text", TRUE);
626 partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
627 menu_set_sensitive(mimeview->popupfactory,
630 menu_set_sensitive(mimeview->popupfactory,
633 menu_set_sensitive(mimeview->popupfactory,
635 mimeview_is_signed(mimeview));
638 gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
639 NULL, NULL, NULL, NULL,
640 event->button, event->time);
646 void mimeview_pass_key_press_event(MimeView *mimeview, GdkEventKey *event)
648 mimeview_key_pressed(mimeview->ctree, event, mimeview);
651 #define BREAK_ON_MODIFIER_KEY() \
652 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
654 #define KEY_PRESS_EVENT_STOP() \
655 if (gtk_signal_n_emissions_by_name \
656 (GTK_OBJECT(ctree), "key_press_event") > 0) { \
657 gtk_signal_emit_stop_by_name(GTK_OBJECT(ctree), \
658 "key_press_event"); \
661 static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
664 SummaryView *summaryview;
665 GtkCTree *ctree = GTK_CTREE(widget);
668 if (!event) return FALSE;
669 if (!mimeview->opened) return FALSE;
671 switch (event->keyval) {
673 if (textview_scroll_page(mimeview->textview, FALSE))
676 node = GTK_CTREE_NODE_NEXT(mimeview->opened);
678 gtk_sctree_unselect_all(GTK_SCTREE(ctree));
679 gtk_sctree_select(GTK_SCTREE(ctree), node);
684 textview_scroll_page(mimeview->textview, TRUE);
687 textview_scroll_one_line(mimeview->textview,
688 (event->state & GDK_MOD1_MASK) != 0);
692 BREAK_ON_MODIFIER_KEY();
693 if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break;
694 KEY_PRESS_EVENT_STOP();
696 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
697 GTK_SCROLL_STEP_FORWARD, 0.0);
701 BREAK_ON_MODIFIER_KEY();
702 if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break;
703 KEY_PRESS_EVENT_STOP();
705 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
706 GTK_SCROLL_STEP_BACKWARD, 0.0);
709 BREAK_ON_MODIFIER_KEY();
710 KEY_PRESS_EVENT_STOP();
711 mimeview_save_as(mimeview);
714 BREAK_ON_MODIFIER_KEY();
715 KEY_PRESS_EVENT_STOP();
716 mimeview_display_as_text(mimeview);
719 BREAK_ON_MODIFIER_KEY();
720 KEY_PRESS_EVENT_STOP();
721 mimeview_launch(mimeview);
726 if (!mimeview->messageview->mainwin) return FALSE;
727 summaryview = mimeview->messageview->mainwin->summaryview;
728 summary_pass_key_press_event(summaryview, event);
732 static void mimeview_drag_data_get(GtkWidget *widget,
733 GdkDragContext *drag_context,
734 GtkSelectionData *selection_data,
739 gchar *filename, *uriname;
742 if (!mimeview->opened) return;
743 if (!mimeview->file) return;
745 partinfo = gtk_ctree_node_get_row_data
746 (GTK_CTREE(mimeview->ctree), mimeview->opened);
747 if (!partinfo) return;
748 if (!partinfo->filename && !partinfo->name) return;
750 filename = partinfo->filename ? partinfo->filename : partinfo->name;
751 filename = g_basename(filename);
752 if (*filename == '\0') return;
754 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
757 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
759 (_("Can't save the part of multipart message."));
761 uriname = g_strconcat("file:/", filename, NULL);
762 gtk_selection_data_set(selection_data, selection_data->target, 8,
763 uriname, strlen(uriname));
769 static void mimeview_display_as_text(MimeView *mimeview)
773 if (!mimeview->opened) return;
775 partinfo = gtk_ctree_node_get_row_data
776 (GTK_CTREE(mimeview->ctree), mimeview->opened);
777 mimeview_show_message_part(mimeview, partinfo);
780 static void mimeview_save_as(MimeView *mimeview)
783 gchar *defname = NULL;
786 if (!mimeview->opened) return;
787 if (!mimeview->file) return;
789 partinfo = gtk_ctree_node_get_row_data
790 (GTK_CTREE(mimeview->ctree), mimeview->opened);
791 g_return_if_fail(partinfo != NULL);
793 if (partinfo->filename)
794 defname = partinfo->filename;
795 else if (partinfo->name) {
796 Xstrdup_a(defname, partinfo->name, return);
797 subst_for_filename(defname);
800 filename = filesel_select_file(_("Save as"), defname);
801 if (!filename) return;
802 if (is_file_exist(filename)) {
805 aval = alertpanel(_("Overwrite"),
806 _("Overwrite existing file?"),
807 _("OK"), _("Cancel"), NULL);
808 if (G_ALERTDEFAULT != aval) return;
811 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
813 (_("Can't save the part of multipart message."));
816 static void mimeview_launch(MimeView *mimeview)
821 if (!mimeview->opened) return;
822 if (!mimeview->file) return;
824 partinfo = gtk_ctree_node_get_row_data
825 (GTK_CTREE(mimeview->ctree), mimeview->opened);
826 g_return_if_fail(partinfo != NULL);
828 filename = procmime_get_tmp_file_name(partinfo);
830 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
832 (_("Can't save the part of multipart message."));
834 mimeview_view_file(filename, partinfo, NULL);
839 static void mimeview_open_with(MimeView *mimeview)
845 if (!mimeview->opened) return;
846 if (!mimeview->file) return;
848 partinfo = gtk_ctree_node_get_row_data
849 (GTK_CTREE(mimeview->ctree), mimeview->opened);
850 g_return_if_fail(partinfo != NULL);
852 filename = procmime_get_tmp_file_name(partinfo);
854 if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
856 (_("Can't save the part of multipart message."));
861 if (!prefs_common.mime_open_cmd_history)
862 prefs_common.mime_open_cmd_history =
863 add_history(NULL, prefs_common.mime_open_cmd);
865 cmd = input_dialog_combo
867 _("Enter the command line to open file:\n"
868 "(`%s' will be replaced with file name)"),
869 prefs_common.mime_open_cmd,
870 prefs_common.mime_open_cmd_history);
872 mimeview_view_file(filename, partinfo, cmd);
873 g_free(prefs_common.mime_open_cmd);
874 prefs_common.mime_open_cmd = cmd;
875 prefs_common.mime_open_cmd_history =
876 add_history(prefs_common.mime_open_cmd_history, cmd);
882 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
883 const gchar *cmdline)
885 static gchar *default_image_cmdline = "display '%s'";
886 static gchar *default_audio_cmdline = "play '%s'";
887 static gchar *default_html_cmdline =
888 "netscape -remote 'openURL(%s,raise)'";
889 static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
893 const gchar *def_cmd;
899 } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) {
901 } else if (MIME_IMAGE == partinfo->mime_type) {
902 cmd = prefs_common.mime_image_viewer;
903 def_cmd = default_image_cmdline;
904 } else if (MIME_AUDIO == partinfo->mime_type) {
905 cmd = prefs_common.mime_audio_player;
906 def_cmd = default_audio_cmdline;
907 } else if (MIME_TEXT_HTML == partinfo->mime_type) {
908 cmd = prefs_common.uri_cmd;
909 def_cmd = default_html_cmdline;
911 g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
912 partinfo->content_type, "%s");
917 if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
919 g_snprintf(buf, sizeof(buf), cmd, filename);
922 g_warning(_("MIME viewer command line is invalid: `%s'"), cmd);
924 g_snprintf(buf, sizeof(buf), def_cmd, filename);
929 execute_command_line(buf, TRUE);
933 static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
939 partinfo = gtk_ctree_node_get_row_data(ctree, node);
940 g_return_if_fail(partinfo != NULL);
942 part_name = get_part_name(partinfo);
943 gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
946 static void mimeview_update_names(MimeView *mimeview)
948 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
950 gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
953 static void mimeview_update_signature_info(MimeView *mimeview)
957 if (!mimeview) return;
958 if (!mimeview->opened) return;
960 partinfo = gtk_ctree_node_get_row_data
961 (GTK_CTREE(mimeview->ctree), mimeview->opened);
962 if (!partinfo) return;
964 if (g_strcasecmp(partinfo->content_type,
965 "application/pgp-signature") == 0) {
966 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
967 textview_show_signature_part(mimeview->textview, partinfo);
971 static void mimeview_check_signature(MimeView *mimeview)
977 g_return_if_fail (mimeview_is_signed(mimeview));
979 mimeinfo = gtk_ctree_node_get_row_data
980 (GTK_CTREE(mimeview->ctree), mimeview->opened);
981 g_return_if_fail(mimeinfo != NULL);
982 g_return_if_fail(mimeview->file != NULL);
984 while (mimeinfo->parent)
985 mimeinfo = mimeinfo->parent;
987 if ((fp = fopen(mimeview->file, "r")) == NULL) {
988 FILE_OP_ERROR(mimeview->file, "fopen");
993 if (mimeinfo->mime_type == MIME_MULTIPART) {
994 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
995 FILE_OP_ERROR(mimeview->file, "fseek");
996 while (fgets(buf, sizeof(buf), fp) != NULL)
997 if (buf[0] == '\r' || buf[0] == '\n') break;
1000 procmime_scan_multipart_message(mimeinfo, fp);
1001 rfc2015_check_signature(mimeinfo, fp);
1004 mimeview_update_names(mimeview);
1005 mimeview_update_signature_info(mimeview);
1007 #endif /* USE_GPGME */