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 gtk_notebook_set_page(GTK_NOTEBOOK(notebook), 0);
203 n_entries = sizeof(mimeview_popup_entries) /
204 sizeof(mimeview_popup_entries[0]);
205 popupmenu = menu_create_items(mimeview_popup_entries, n_entries,
206 "<MimeView>", &popupfactory, mimeview);
208 mimeview->notebook = notebook;
209 mimeview->vbox = vbox;
210 mimeview->paned = paned;
211 mimeview->scrolledwin = scrolledwin;
212 mimeview->ctree = ctree;
213 mimeview->mime_vbox = mime_vbox;
214 mimeview->popupmenu = popupmenu;
215 mimeview->popupfactory = popupfactory;
221 void mimeview_init(MimeView *mimeview)
226 * Check whether the message is OpenPGP signed
229 static gboolean mimeview_is_signed(MimeView *mimeview)
231 MimeInfo *partinfo = NULL;
232 MsgInfo *msginfo = NULL;
234 debug_print("mimeview_is signed of %p\n", mimeview);
236 if (!mimeview) return FALSE;
237 if (!mimeview->opened) return FALSE;
239 debug_print("mimeview_is_signed: open\n" );
241 if (!mimeview->file) return FALSE;
243 debug_print("mimeview_is_signed: file\n" );
245 partinfo = gtk_ctree_node_get_row_data
246 (GTK_CTREE(mimeview->ctree), mimeview->opened);
247 g_return_val_if_fail(partinfo != NULL, FALSE);
249 /* walk the tree and see whether there is a signature somewhere */
251 if (rfc2015_has_signature(partinfo))
253 if (pgptext_has_signature(msginfo, partinfo))
255 } while ((partinfo = partinfo->parent) != NULL);
257 debug_print("mimeview_is_signed: FALSE\n" );
262 static void set_unchecked_signature(MimeInfo *mimeinfo)
264 MimeInfo *sig_partinfo;
266 sig_partinfo = rfc2015_find_signature(mimeinfo);
267 if (sig_partinfo == NULL) return;
269 g_free(sig_partinfo->sigstatus);
270 sig_partinfo->sigstatus =
271 g_strdup(_("Select \"Check signature\" to check"));
273 g_free(sig_partinfo->sigstatus_full);
274 sig_partinfo->sigstatus_full = NULL;
276 #endif /* USE_GPGME */
278 void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
281 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
286 mimeview_clear(mimeview);
287 textview_clear(mimeview->messageview->textview);
289 g_return_if_fail(file != NULL);
290 g_return_if_fail(mimeinfo != NULL);
292 mimeview->mimeinfo = mimeinfo;
294 if ((fp = fopen(file, "r")) == NULL) {
295 FILE_OP_ERROR(file, "fopen");
298 mimeview->file = g_strdup(file);
300 /* skip MIME part headers */
301 if (mimeinfo->mime_type == MIME_MULTIPART) {
302 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
304 while (fgets(buf, sizeof(buf), fp) != NULL)
305 if (buf[0] == '\r' || buf[0] == '\n') break;
308 procmime_scan_multipart_message(mimeinfo, fp);
310 if (prefs_common.auto_check_signatures)
311 rfc2015_check_signature(mimeinfo, fp);
313 set_unchecked_signature(mimeinfo);
316 gtk_signal_handler_block_by_func(GTK_OBJECT(ctree), mimeview_selected,
319 mimeview_set_multipart_tree(mimeview, mimeinfo, NULL);
321 gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
322 mimeview_selected, mimeview);
324 /* search first text part */
325 for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
326 node != NULL; node = GTK_CTREE_NODE_NEXT(node)) {
329 partinfo = gtk_ctree_node_get_row_data(ctree, node);
331 (partinfo->mime_type == MIME_TEXT ||
332 partinfo->mime_type == MIME_TEXT_HTML))
336 textview_show_message(mimeview->messageview->textview, mimeinfo, file);
339 node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
342 gtk_ctree_select(ctree, node);
343 gtkut_ctree_set_focus_row(ctree, node);
344 gtk_widget_grab_focus(mimeview->ctree);
348 void mimeview_destroy(MimeView *mimeview)
350 procmime_mimeinfo_free_all(mimeview->mimeinfo);
351 g_free(mimeview->file);
355 static void mimeview_set_multipart_tree(MimeView *mimeview,
357 GtkCTreeNode *parent)
359 GtkCTreeNode *current = parent;
361 g_return_if_fail(mimeinfo != NULL);
363 if (!mimeinfo->sub && mimeinfo->parent)
364 current = mimeview_append_part(mimeview, mimeinfo, parent);
367 mimeview_set_multipart_tree(mimeview, mimeinfo->sub, current);
369 if (mimeinfo->children)
370 mimeview_set_multipart_tree(mimeview, mimeinfo->children, current);
373 mimeview_set_multipart_tree(mimeview, mimeinfo->next, parent);
376 static gchar *get_part_name(MimeInfo *partinfo)
379 if (partinfo->sigstatus)
380 return partinfo->sigstatus;
384 return partinfo->name;
385 else if (partinfo->filename)
386 return partinfo->filename;
391 static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
393 GtkCTreeNode *parent)
395 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
397 gchar *str[N_MIMEVIEW_COLS];
400 partinfo->content_type ? partinfo->content_type : "";
401 str[COL_SIZE] = to_human_readable(partinfo->size);
402 str[COL_NAME] = get_part_name(partinfo);
404 node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
405 NULL, NULL, NULL, NULL,
407 gtk_ctree_node_set_row_data(ctree, node, partinfo);
412 static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
420 if (!partinfo) return;
423 for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent)
425 fname = pi ? pi->plaintextfile : mimeview->file;
427 fname = mimeview->file;
428 #endif /* USE_GPGME */
431 if ((fp = fopen(fname, "r")) == NULL) {
432 FILE_OP_ERROR(fname, "fopen");
436 if (fseek(fp, partinfo->fpos, SEEK_SET) < 0) {
437 FILE_OP_ERROR(mimeview->file, "fseek");
442 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
443 textview_show_part(mimeview->textview, partinfo, fp);
448 static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo)
452 if (!partinfo) return;
454 filename = procmime_get_tmp_file_name(partinfo);
456 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
458 (_("Can't get the part of multipart message."));
460 mimeview_change_view_type(mimeview, MIMEVIEW_IMAGE);
461 /* Workaround for the GTK+ bug with handling scroll adjustments
463 imageview_clear(mimeview->imageview);
464 imageview_show_image(mimeview->imageview, partinfo, filename);
471 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
473 TextView *textview = mimeview->textview;
474 ImageView *imageview = mimeview->imageview;
477 if (mimeview->type == type) return;
479 children = gtk_container_children(GTK_CONTAINER(mimeview->mime_vbox));
481 gtkut_container_remove(GTK_CONTAINER(mimeview->mime_vbox),
482 GTK_WIDGET(children->data));
483 g_list_free(children);
488 gtk_container_add(GTK_CONTAINER(mimeview->mime_vbox),
489 GTK_WIDGET_PTR(imageview));
492 gtk_container_add(GTK_CONTAINER(mimeview->mime_vbox),
493 GTK_WIDGET_PTR(textview));
499 mimeview->type = type;
502 static void mimeview_clear(MimeView *mimeview)
504 GtkCList *clist = GTK_CLIST(mimeview->ctree);
506 procmime_mimeinfo_free_all(mimeview->mimeinfo);
507 mimeview->mimeinfo = NULL;
509 gtk_clist_clear(clist);
510 textview_clear(mimeview->textview);
511 imageview_clear(mimeview->imageview);
513 mimeview->opened = NULL;
515 g_free(mimeview->file);
516 mimeview->file = NULL;
518 /* gtk_notebook_set_page(GTK_NOTEBOOK(mimeview->notebook), 0); */
521 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
526 if (mimeview->opened == node) return;
527 mimeview->opened = node;
528 gtk_ctree_node_moveto(ctree, node, -1, 0.5, 0);
530 partinfo = gtk_ctree_node_get_row_data(ctree, node);
531 if (!partinfo) return;
533 /* ungrab the mouse event */
534 if (GTK_WIDGET_HAS_GRAB(ctree)) {
535 gtk_grab_remove(GTK_WIDGET(ctree));
536 if (gdk_pointer_is_grabbed())
537 gdk_pointer_ungrab(GDK_CURRENT_TIME);
540 switch (partinfo->mime_type) {
543 case MIME_TEXT_ENRICHED:
544 case MIME_MESSAGE_RFC822:
546 mimeview_show_message_part(mimeview, partinfo);
548 #if (HAVE_GDK_PIXBUF || HAVE_GDK_IMLIB)
550 mimeview_show_image_part(mimeview, partinfo);
554 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
556 if (g_strcasecmp(partinfo->content_type,
557 "application/pgp-signature") == 0)
558 textview_show_signature_part(mimeview->textview,
562 textview_show_mime_part(mimeview->textview, partinfo);
567 static void mimeview_start_drag(GtkWidget *widget, gint button,
568 GdkEvent *event, MimeView *mimeview)
571 GdkDragContext *context;
575 g_return_if_fail(mimeview != NULL);
576 ctree = GTK_CTREE(mimeview->ctree);
577 partinfo = gtk_ctree_node_get_row_data(ctree, mimeview->opened);
578 if (partinfo->filename == NULL && partinfo->name == NULL) return;
580 list = gtk_target_list_new(mimeview_mime_types, 1);
581 context = gtk_drag_begin(widget, list,
582 GDK_ACTION_COPY, button, event);
583 gtk_drag_set_icon_default(context);
586 static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
589 GtkCList *clist = GTK_CLIST(widget);
593 if (!event) return FALSE;
595 if (event->button == 2 || event->button == 3) {
596 if (!gtk_clist_get_selection_info(clist, event->x, event->y,
599 gtk_clist_unselect_all(clist);
600 gtk_clist_select_row(clist, row, column);
601 gtkut_clist_set_focus_row(clist, row);
604 if (event->button == 2 ||
605 (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
606 /* call external program for image, audio or html */
607 mimeview_launch(mimeview);
608 } else if (event->button == 3) {
609 partinfo = gtk_ctree_node_get_row_data
610 (GTK_CTREE(mimeview->ctree), mimeview->opened);
611 if (partinfo && (partinfo->mime_type == MIME_TEXT ||
612 partinfo->mime_type == MIME_TEXT_HTML ||
613 partinfo->mime_type == MIME_TEXT_ENRICHED ||
614 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
615 partinfo->mime_type == MIME_IMAGE ||
616 partinfo->mime_type == MIME_MULTIPART))
617 menu_set_sensitive(mimeview->popupfactory,
618 "/Display as text", FALSE);
620 menu_set_sensitive(mimeview->popupfactory,
621 "/Display as text", TRUE);
623 partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
624 menu_set_sensitive(mimeview->popupfactory,
627 menu_set_sensitive(mimeview->popupfactory,
630 menu_set_sensitive(mimeview->popupfactory,
632 mimeview_is_signed(mimeview));
635 gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
636 NULL, NULL, NULL, NULL,
637 event->button, event->time);
643 void mimeview_pass_key_press_event(MimeView *mimeview, GdkEventKey *event)
645 mimeview_key_pressed(mimeview->ctree, event, mimeview);
648 #define BREAK_ON_MODIFIER_KEY() \
649 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
651 #define KEY_PRESS_EVENT_STOP() \
652 if (gtk_signal_n_emissions_by_name \
653 (GTK_OBJECT(ctree), "key_press_event") > 0) { \
654 gtk_signal_emit_stop_by_name(GTK_OBJECT(ctree), \
655 "key_press_event"); \
658 static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
661 SummaryView *summaryview;
662 GtkCTree *ctree = GTK_CTREE(widget);
665 if (!event) return FALSE;
666 if (!mimeview->opened) return FALSE;
668 switch (event->keyval) {
670 if (textview_scroll_page(mimeview->textview, FALSE))
673 node = GTK_CTREE_NODE_NEXT(mimeview->opened);
675 gtk_sctree_unselect_all(GTK_SCTREE(ctree));
676 gtk_sctree_select(GTK_SCTREE(ctree), node);
681 textview_scroll_page(mimeview->textview, TRUE);
684 textview_scroll_one_line(mimeview->textview,
685 (event->state & GDK_MOD1_MASK) != 0);
689 BREAK_ON_MODIFIER_KEY();
690 if (!GTK_CTREE_NODE_NEXT(mimeview->opened)) break;
691 KEY_PRESS_EVENT_STOP();
693 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
694 GTK_SCROLL_STEP_FORWARD, 0.0);
698 BREAK_ON_MODIFIER_KEY();
699 if (!GTK_CTREE_NODE_PREV(mimeview->opened)) break;
700 KEY_PRESS_EVENT_STOP();
702 gtk_signal_emit_by_name(GTK_OBJECT(ctree), "scroll_vertical",
703 GTK_SCROLL_STEP_BACKWARD, 0.0);
706 BREAK_ON_MODIFIER_KEY();
707 KEY_PRESS_EVENT_STOP();
708 mimeview_save_as(mimeview);
711 BREAK_ON_MODIFIER_KEY();
712 KEY_PRESS_EVENT_STOP();
713 mimeview_display_as_text(mimeview);
716 BREAK_ON_MODIFIER_KEY();
717 KEY_PRESS_EVENT_STOP();
718 mimeview_launch(mimeview);
723 if (!mimeview->messageview->mainwin) return FALSE;
724 summaryview = mimeview->messageview->mainwin->summaryview;
725 summary_pass_key_press_event(summaryview, event);
729 static void mimeview_drag_data_get(GtkWidget *widget,
730 GdkDragContext *drag_context,
731 GtkSelectionData *selection_data,
736 gchar *filename, *uriname;
739 if (!mimeview->opened) return;
740 if (!mimeview->file) return;
742 partinfo = gtk_ctree_node_get_row_data
743 (GTK_CTREE(mimeview->ctree), mimeview->opened);
744 if (!partinfo) return;
745 if (!partinfo->filename && !partinfo->name) return;
747 filename = partinfo->filename ? partinfo->filename : partinfo->name;
748 filename = g_basename(filename);
749 if (*filename == '\0') return;
751 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
754 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
756 (_("Can't save the part of multipart message."));
758 uriname = g_strconcat("file:/", filename, NULL);
759 gtk_selection_data_set(selection_data, selection_data->target, 8,
760 uriname, strlen(uriname));
766 static void mimeview_display_as_text(MimeView *mimeview)
770 if (!mimeview->opened) return;
772 partinfo = gtk_ctree_node_get_row_data
773 (GTK_CTREE(mimeview->ctree), mimeview->opened);
774 mimeview_show_message_part(mimeview, partinfo);
777 static void mimeview_save_as(MimeView *mimeview)
780 gchar *defname = NULL;
783 if (!mimeview->opened) return;
784 if (!mimeview->file) return;
786 partinfo = gtk_ctree_node_get_row_data
787 (GTK_CTREE(mimeview->ctree), mimeview->opened);
788 g_return_if_fail(partinfo != NULL);
790 if (partinfo->filename)
791 defname = partinfo->filename;
792 else if (partinfo->name) {
793 Xstrdup_a(defname, partinfo->name, return);
794 subst_for_filename(defname);
797 filename = filesel_select_file(_("Save as"), defname);
798 if (!filename) return;
799 if (is_file_exist(filename)) {
802 aval = alertpanel(_("Overwrite"),
803 _("Overwrite existing file?"),
804 _("OK"), _("Cancel"), NULL);
805 if (G_ALERTDEFAULT != aval) return;
808 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
810 (_("Can't save the part of multipart message."));
813 static void mimeview_launch(MimeView *mimeview)
818 if (!mimeview->opened) return;
819 if (!mimeview->file) return;
821 partinfo = gtk_ctree_node_get_row_data
822 (GTK_CTREE(mimeview->ctree), mimeview->opened);
823 g_return_if_fail(partinfo != NULL);
825 filename = procmime_get_tmp_file_name(partinfo);
827 if (procmime_get_part(filename, mimeview->file, partinfo) < 0)
829 (_("Can't save the part of multipart message."));
831 mimeview_view_file(filename, partinfo, NULL);
836 static void mimeview_open_with(MimeView *mimeview)
842 if (!mimeview->opened) return;
843 if (!mimeview->file) return;
845 partinfo = gtk_ctree_node_get_row_data
846 (GTK_CTREE(mimeview->ctree), mimeview->opened);
847 g_return_if_fail(partinfo != NULL);
849 filename = procmime_get_tmp_file_name(partinfo);
851 if (procmime_get_part(filename, mimeview->file, partinfo) < 0) {
853 (_("Can't save the part of multipart message."));
858 if (!prefs_common.mime_open_cmd_history)
859 prefs_common.mime_open_cmd_history =
860 add_history(NULL, prefs_common.mime_open_cmd);
862 cmd = input_dialog_combo
864 _("Enter the command line to open file:\n"
865 "(`%s' will be replaced with file name)"),
866 prefs_common.mime_open_cmd,
867 prefs_common.mime_open_cmd_history);
869 mimeview_view_file(filename, partinfo, cmd);
870 g_free(prefs_common.mime_open_cmd);
871 prefs_common.mime_open_cmd = cmd;
872 prefs_common.mime_open_cmd_history =
873 add_history(prefs_common.mime_open_cmd_history, cmd);
879 static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
880 const gchar *cmdline)
882 static gchar *default_image_cmdline = "display '%s'";
883 static gchar *default_audio_cmdline = "play '%s'";
884 static gchar *default_html_cmdline =
885 "netscape -remote 'openURL(%s,raise)'";
886 static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
890 const gchar *def_cmd;
896 } else if (MIME_APPLICATION_OCTET_STREAM == partinfo->mime_type) {
898 } else if (MIME_IMAGE == partinfo->mime_type) {
899 cmd = prefs_common.mime_image_viewer;
900 def_cmd = default_image_cmdline;
901 } else if (MIME_AUDIO == partinfo->mime_type) {
902 cmd = prefs_common.mime_audio_player;
903 def_cmd = default_audio_cmdline;
904 } else if (MIME_TEXT_HTML == partinfo->mime_type) {
905 cmd = prefs_common.uri_cmd;
906 def_cmd = default_html_cmdline;
908 g_snprintf(m_buf, sizeof(m_buf), mime_cmdline,
909 partinfo->content_type, "%s");
914 if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
916 g_snprintf(buf, sizeof(buf), cmd, filename);
919 g_warning(_("MIME viewer command line is invalid: `%s'"), cmd);
921 g_snprintf(buf, sizeof(buf), def_cmd, filename);
926 execute_command_line(buf, TRUE);
930 static void update_node_name(GtkCTree *ctree, GtkCTreeNode *node,
936 partinfo = gtk_ctree_node_get_row_data(ctree, node);
937 g_return_if_fail(partinfo != NULL);
939 part_name = get_part_name(partinfo);
940 gtk_ctree_node_set_text(ctree, node, COL_NAME, part_name);
943 static void mimeview_update_names(MimeView *mimeview)
945 GtkCTree *ctree = GTK_CTREE(mimeview->ctree);
947 gtk_ctree_pre_recursive(ctree, NULL, update_node_name, NULL);
950 static void mimeview_update_signature_info(MimeView *mimeview)
954 if (!mimeview) return;
955 if (!mimeview->opened) return;
957 partinfo = gtk_ctree_node_get_row_data
958 (GTK_CTREE(mimeview->ctree), mimeview->opened);
959 if (!partinfo) return;
961 if (g_strcasecmp(partinfo->content_type,
962 "application/pgp-signature") == 0) {
963 mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
964 textview_show_signature_part(mimeview->textview, partinfo);
968 static void mimeview_check_signature(MimeView *mimeview)
974 g_return_if_fail (mimeview_is_signed(mimeview));
976 mimeinfo = gtk_ctree_node_get_row_data
977 (GTK_CTREE(mimeview->ctree), mimeview->opened);
978 g_return_if_fail(mimeinfo != NULL);
979 g_return_if_fail(mimeview->file != NULL);
981 while (mimeinfo->parent)
982 mimeinfo = mimeinfo->parent;
984 if ((fp = fopen(mimeview->file, "r")) == NULL) {
985 FILE_OP_ERROR(mimeview->file, "fopen");
990 if (mimeinfo->mime_type == MIME_MULTIPART) {
991 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
992 FILE_OP_ERROR(mimeview->file, "fseek");
993 while (fgets(buf, sizeof(buf), fp) != NULL)
994 if (buf[0] == '\r' || buf[0] == '\n') break;
997 procmime_scan_multipart_message(mimeinfo, fp);
998 rfc2015_check_signature(mimeinfo, fp);
1001 mimeview_update_names(mimeview);
1002 mimeview_update_signature_info(mimeview);
1004 #endif /* USE_GPGME */