2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "claws-features.h"
33 #include <glib/gi18n.h>
34 #include <gdk/gdkkeysyms.h>
37 #include <sys/types.h>
44 #include "summaryview.h"
47 #include "alertpanel.h"
48 #include "inputdialog.h"
51 #include "prefs_common.h"
52 #include "procheader.h"
53 #include "stock_pixmap.h"
54 #include "gtk/gtkvscrollbutton.h"
55 #include "gtk/logwindow.h"
57 #include "manage_window.h"
68 #define N_MIMEVIEW_COLS 4
70 static void mimeview_set_multipart_tree (MimeView
*mimeview
,
73 static void mimeview_show_message_part (MimeView
*mimeview
,
75 static void mimeview_change_view_type (MimeView
*mimeview
,
77 static gchar
*mimeview_get_filename_for_part (MimeInfo
*partinfo
,
80 static gboolean
mimeview_write_part (const gchar
*filename
,
83 static void mimeview_selected (GtkTreeSelection
*selection
,
85 static gint
mimeview_button_pressed (GtkWidget
*widget
,
86 GdkEventButton
*event
,
88 static gint
mimeview_key_pressed (GtkWidget
*widget
,
92 static void mimeview_drag_data_get (GtkWidget
*widget
,
93 GdkDragContext
*drag_context
,
94 GtkSelectionData
*selection_data
,
99 static gboolean
mimeview_scrolled (GtkWidget
*widget
,
100 GdkEventScroll
*event
,
103 static void mimeview_save_all (MimeView
*mimeview
);
105 static void mimeview_open_part_with (MimeView
*mimeview
,
109 static void mimeview_send_to (MimeView
*mimeview
,
111 static void mimeview_view_file (const gchar
*filename
,
115 static gboolean
icon_clicked_cb (GtkWidget
*button
,
116 GdkEventButton
*event
,
118 static void icon_selected (MimeView
*mimeview
,
121 static gint
icon_key_pressed (GtkWidget
*button
,
124 static void icon_list_append_icon (MimeView
*mimeview
,
126 static void icon_list_create (MimeView
*mimeview
,
128 static void icon_list_clear (MimeView
*mimeview
);
129 static void icon_list_toggle_by_mime_info (MimeView
*mimeview
,
131 static void ctree_size_allocate_cb (GtkWidget
*widget
,
132 GtkAllocation
*allocation
,
134 static gint
mime_toggle_button_cb(GtkWidget
*button
, GdkEventButton
*event
,
136 static gboolean
part_button_pressed (MimeView
*mimeview
,
137 GdkEventButton
*event
,
139 static void icon_scroll_size_allocate_cb(GtkWidget
*widget
,
140 GtkAllocation
*layout_size
,
142 static MimeInfo
*mimeview_get_part_to_use(MimeView
*mimeview
);
143 static const gchar
*get_part_name(MimeInfo
*partinfo
);
144 static const gchar
*get_part_description(MimeInfo
*partinfo
);
146 static void mimeview_launch_cb(GtkAction
*action
, gpointer data
)
148 MimeView
*mimeview
= (MimeView
*)data
;
149 mimeview_launch(mimeview
, mimeview_get_part_to_use(mimeview
));
153 static void mimeview_open_with_cb(GtkAction
*action
, gpointer data
)
155 mimeview_open_with((MimeView
*)data
);
159 static void mimeview_send_to_cb(GtkAction
*action
, gpointer data
)
161 MimeView
*mimeview
= (MimeView
*)data
;
162 mimeview_send_to(mimeview
, mimeview_get_part_to_use(mimeview
));
165 static void mimeview_display_as_text_cb(GtkAction
*action
, gpointer data
)
167 mimeview_display_as_text((MimeView
*)data
);
170 static void mimeview_save_as_cb(GtkAction
*action
, gpointer data
)
172 mimeview_save_as((MimeView
*)data
);
175 static void mimeview_save_all_cb(GtkAction
*action
, gpointer data
)
177 mimeview_save_all((MimeView
*)data
);
180 static void mimeview_select_next_part_cb(GtkAction
*action
, gpointer data
)
182 mimeview_select_next_part((MimeView
*)data
);
185 static void mimeview_select_prev_part_cb(GtkAction
*action
, gpointer data
)
187 mimeview_select_prev_part((MimeView
*)data
);
190 static GtkActionEntry mimeview_menu_actions
[] = {
191 { "MimeView", NULL
, "MimeView" },
192 { "MimeView/Open", NULL
, N_("_Open"), NULL
, "Open MIME part", G_CALLBACK(mimeview_launch_cb
) },
193 #if (!defined G_OS_WIN32)
194 { "MimeView/OpenWith", NULL
, N_("Open _with..."), NULL
, "Open MIME part with...", G_CALLBACK(mimeview_open_with_cb
) },
196 { "MimeView/SendTo", NULL
, N_("Send to..."), NULL
, "Send to", G_CALLBACK(mimeview_send_to_cb
) },
197 { "MimeView/DisplayAsText", NULL
, N_("_Display as text"), NULL
, "Display as text", G_CALLBACK(mimeview_display_as_text_cb
) },
198 { "MimeView/SaveAs", NULL
, N_("_Save as..."), NULL
, "Save as", G_CALLBACK(mimeview_save_as_cb
) },
199 { "MimeView/SaveAll", NULL
, N_("Save _all..."), NULL
, "Save all parts", G_CALLBACK(mimeview_save_all_cb
) },
200 { "MimeView/NextPart", NULL
, N_("Next part"), NULL
, "Next part", G_CALLBACK(mimeview_select_next_part_cb
) },
201 { "MimeView/PrevPart", NULL
, N_("Previous part"), NULL
, "Previous part", G_CALLBACK(mimeview_select_prev_part_cb
) }
204 static GtkTargetEntry mimeview_mime_types
[] =
206 {"text/uri-list", 0, 0}
209 GSList
*mimeviewer_factories
;
212 static GdkCursor
*hand_cursor
= NULL
;
214 static gboolean
mimeview_visi_notify(GtkWidget
*widget
,
215 GdkEventVisibility
*event
,
218 gdk_window_set_cursor(gtk_widget_get_window(widget
), hand_cursor
);
222 static gboolean
mimeview_leave_notify(GtkWidget
*widget
,
223 GdkEventCrossing
*event
,
226 gdk_window_set_cursor(gtk_widget_get_window(widget
), NULL
);
230 static gboolean
mimeview_enter_notify(GtkWidget
*widget
,
231 GdkEventCrossing
*event
,
234 gdk_window_set_cursor(gtk_widget_get_window(widget
), hand_cursor
);
238 MimeView
*mimeview_create(MainWindow
*mainwin
)
243 GtkWidget
*scrolledwin
;
245 GtkWidget
*mime_notebook
;
246 GtkWidget
*popupmenu
;
247 GtkWidget
*ctree_mainbox
;
249 GtkWidget
*mime_toggle
;
250 GtkWidget
*icon_mainbox
;
251 GtkWidget
*icon_scroll
;
252 GtkWidget
*icon_vbox
;
254 GtkWidget
*scrollbutton
;
256 NoticeView
*siginfoview
;
259 GtkCellRenderer
*renderer
;
260 GtkTreeViewColumn
*column
;
261 GtkTreeSelection
*selection
;
263 gchar
*titles
[N_MIMEVIEW_COLS
];
267 hand_cursor
= gdk_cursor_new(GDK_HAND2
);
269 debug_print("Creating MIME view...\n");
270 mimeview
= g_new0(MimeView
, 1);
272 titles
[COL_MIMETYPE
] = _("MIME Type");
273 titles
[COL_SIZE
] = _("Size");
274 titles
[COL_NAME
] = _("Name");
276 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
277 gtk_widget_show(scrolledwin
);
278 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
279 GTK_POLICY_AUTOMATIC
,
280 GTK_POLICY_AUTOMATIC
);
282 model
= gtk_tree_store_new(N_MIMEVIEW_COLS
,
288 ctree
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(model
));
289 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ctree
), FALSE
);
290 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(ctree
),
291 prefs_common
.use_stripes_everywhere
);
292 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ctree
),
293 prefs_common
.show_col_headers
);
295 renderer
= gtk_cell_renderer_text_new();
296 cols
= gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(ctree
),
297 -1, titles
[COL_MIMETYPE
],renderer
,
298 "text", COL_MIMETYPE
, NULL
);
299 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(ctree
), cols
-1);
301 renderer
= gtk_cell_renderer_text_new();
302 #if(GTK_CHECK_VERSION(2,18,0))
303 gtk_cell_renderer_set_alignment(renderer
, 1, 0.5);
305 cols
= gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(ctree
),
306 -1, titles
[COL_SIZE
], renderer
,
307 "text", COL_SIZE
, NULL
);
308 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(ctree
), cols
-1);
309 gtk_tree_view_column_set_alignment(GTK_TREE_VIEW_COLUMN(column
), 1);
311 renderer
= gtk_cell_renderer_text_new();
312 cols
= gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(ctree
),
313 -1, titles
[COL_NAME
], renderer
,
314 "text", COL_NAME
, NULL
);
315 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(ctree
), cols
-1);
316 gtk_tree_view_column_set_expand(GTK_TREE_VIEW_COLUMN(column
), TRUE
);
318 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(ctree
));
319 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_BROWSE
);
321 gtk_widget_show(ctree
);
322 gtk_container_add(GTK_CONTAINER(scrolledwin
), ctree
);
323 gtk_drag_source_set(ctree
, GDK_BUTTON1_MASK
|GDK_BUTTON3_MASK
,
324 mimeview_mime_types
, 1, GDK_ACTION_COPY
);
326 g_signal_connect(G_OBJECT(selection
), "changed",
327 G_CALLBACK(mimeview_selected
), mimeview
);
328 g_signal_connect(G_OBJECT(ctree
), "button_release_event",
329 G_CALLBACK(mimeview_button_pressed
), mimeview
);
330 g_signal_connect(G_OBJECT(ctree
), "key_press_event",
331 G_CALLBACK(mimeview_key_pressed
), mimeview
);
332 g_signal_connect(G_OBJECT(ctree
), "drag_data_get",
333 G_CALLBACK(mimeview_drag_data_get
), mimeview
);
335 mime_notebook
= gtk_notebook_new();
336 gtk_widget_show(mime_notebook
);
337 gtkut_widget_set_can_focus(mime_notebook
, FALSE
);
338 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(mime_notebook
), FALSE
);
339 gtk_notebook_set_show_border(GTK_NOTEBOOK(mime_notebook
), FALSE
);
341 icon_vbox
= gtk_vbox_new(FALSE
, 2);
342 gtk_widget_show(icon_vbox
);
343 icon_scroll
= gtk_layout_new(NULL
, NULL
);
344 gtk_widget_show(icon_scroll
);
345 gtk_layout_put(GTK_LAYOUT(icon_scroll
), icon_vbox
, 0, 0);
346 scrollbutton
= gtk_vscrollbutton_new(gtk_layout_get_vadjustment(GTK_LAYOUT(icon_scroll
)));
347 gtk_widget_show(scrollbutton
);
349 g_signal_connect(G_OBJECT(icon_scroll
), "scroll_event",
350 G_CALLBACK(mimeview_scrolled
), mimeview
);
352 mime_toggle
= gtk_event_box_new();
353 gtk_event_box_set_visible_window(GTK_EVENT_BOX(mime_toggle
), FALSE
);
355 g_signal_connect(G_OBJECT(mime_toggle
), "motion-notify-event",
356 G_CALLBACK(mimeview_visi_notify
), mimeview
);
357 g_signal_connect(G_OBJECT(mime_toggle
), "leave-notify-event",
358 G_CALLBACK(mimeview_leave_notify
), mimeview
);
359 g_signal_connect(G_OBJECT(mime_toggle
), "enter-notify-event",
360 G_CALLBACK(mimeview_enter_notify
), mimeview
);
362 gtk_container_set_border_width(GTK_CONTAINER(mime_toggle
), 2);
363 gtk_widget_show(mime_toggle
);
364 mimeview
->ctree_mode
= FALSE
;
365 arrow
= gtk_arrow_new(GTK_ARROW_LEFT
, GTK_SHADOW_NONE
);
366 gtk_widget_show(arrow
);
367 gtk_widget_size_request(arrow
, &r
);
368 gtk_container_add(GTK_CONTAINER(mime_toggle
), arrow
);
369 g_signal_connect(G_OBJECT(mime_toggle
), "button_release_event",
370 G_CALLBACK(mime_toggle_button_cb
), mimeview
);
372 icon_mainbox
= gtk_vbox_new(FALSE
, 0);
373 gtk_widget_show(icon_mainbox
);
374 gtk_widget_set_size_request(icon_mainbox
, 32, -1);
375 gtk_box_pack_start(GTK_BOX(icon_mainbox
), mime_toggle
, FALSE
, FALSE
, 0);
376 gtk_box_pack_start(GTK_BOX(icon_mainbox
), icon_scroll
, TRUE
, TRUE
, 3);
377 gtk_box_pack_end(GTK_BOX(icon_mainbox
), scrollbutton
, FALSE
, FALSE
, 0);
378 g_signal_connect(G_OBJECT(icon_mainbox
), "size_allocate",
379 G_CALLBACK(icon_scroll_size_allocate_cb
), mimeview
);
381 ctree_mainbox
= gtk_hbox_new(FALSE
, 0);
382 gtk_box_pack_start(GTK_BOX(ctree_mainbox
), scrolledwin
, TRUE
, TRUE
, 0);
383 g_signal_connect(G_OBJECT(ctree_mainbox
), "size_allocate",
384 G_CALLBACK(ctree_size_allocate_cb
), mimeview
);
386 mimeview
->ui_manager
= gtk_ui_manager_new();
387 mimeview
->action_group
= cm_menu_create_action_group_full(mimeview
->ui_manager
,
388 "MimeView", mimeview_menu_actions
,
389 G_N_ELEMENTS(mimeview_menu_actions
), (gpointer
)mimeview
);
391 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR
)
392 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
393 "/Menus/", "MimeView", "MimeView", GTK_UI_MANAGER_MENU
);
394 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
395 "/Menus/MimeView/", "Open", "MimeView/Open",
396 GTK_UI_MANAGER_MENUITEM
);
397 #if (!defined G_OS_WIN32)
398 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
399 "/Menus/MimeView/", "OpenWith", "MimeView/OpenWith",
400 GTK_UI_MANAGER_MENUITEM
);
402 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
403 "/Menus/MimeView/", "SendTo", "MimeView/SendTo",
404 GTK_UI_MANAGER_MENUITEM
);
405 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
406 "/Menus/MimeView/", "DisplayAsText", "MimeView/DisplayAsText",
407 GTK_UI_MANAGER_MENUITEM
);
408 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
409 "/Menus/MimeView/", "SaveAs", "MimeView/SaveAs",
410 GTK_UI_MANAGER_MENUITEM
);
411 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
412 "/Menus/MimeView/", "SaveAll", "MimeView/SaveAll",
413 GTK_UI_MANAGER_MENUITEM
);
414 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
415 "/Menus/MimeView/", "NextPart", "MimeView/NextPart",
416 GTK_UI_MANAGER_MENUITEM
);
417 MENUITEM_ADDUI_MANAGER(mimeview
->ui_manager
,
418 "/Menus/MimeView/", "PrevPart", "MimeView/PrevPart",
419 GTK_UI_MANAGER_MENUITEM
);
421 popupmenu
= gtk_menu_item_get_submenu(GTK_MENU_ITEM(
422 gtk_ui_manager_get_widget(mimeview
->ui_manager
, "/Menus/MimeView")) );
425 vbox
= gtk_vbox_new(FALSE
, 0);
426 gtk_widget_show(vbox
);
427 siginfoview
= noticeview_create(mainwin
);
428 noticeview_hide(siginfoview
);
429 noticeview_set_icon_clickable(siginfoview
, TRUE
);
430 gtk_box_pack_start(GTK_BOX(vbox
), mime_notebook
, TRUE
, TRUE
, 0);
431 gtk_box_pack_end(GTK_BOX(vbox
), GTK_WIDGET_PTR(siginfoview
), FALSE
, FALSE
, 0);
433 paned
= gtk_vpaned_new();
434 gtk_widget_show(paned
);
435 gtk_paned_pack1(GTK_PANED(paned
), ctree_mainbox
, FALSE
, TRUE
);
436 gtk_paned_pack2(GTK_PANED(paned
), vbox
, TRUE
, TRUE
);
438 hbox
= gtk_hbox_new(FALSE
, 0);
439 gtk_box_pack_start(GTK_BOX(hbox
), paned
, TRUE
, TRUE
, 0);
440 gtk_box_pack_start(GTK_BOX(hbox
), icon_mainbox
, FALSE
, FALSE
, 0);
442 gtk_widget_show(hbox
);
443 gtk_widget_hide(ctree_mainbox
);
445 gtk_widget_set_size_request(mime_toggle
, -1, r
.height
+ 8);
447 mimeview
->hbox
= hbox
;
448 mimeview
->paned
= paned
;
449 mimeview
->scrolledwin
= scrolledwin
;
450 mimeview
->ctree
= ctree
;
451 mimeview
->mime_notebook
= mime_notebook
;
452 mimeview
->popupmenu
= popupmenu
;
454 mimeview
->ctree_mainbox
= ctree_mainbox
;
455 mimeview
->icon_scroll
= icon_scroll
;
456 mimeview
->icon_vbox
= icon_vbox
;
457 mimeview
->icon_mainbox
= icon_mainbox
;
458 mimeview
->icon_count
= 0;
459 mimeview
->mainwin
= mainwin
;
460 mimeview
->mime_toggle
= mime_toggle
;
461 mimeview
->siginfoview
= siginfoview
;
462 mimeview
->scrollbutton
= scrollbutton
;
463 mimeview
->target_list
= gtk_target_list_new(mimeview_mime_types
, 1);
465 mimeviews
= g_slist_prepend(mimeviews
, mimeview
);
470 void mimeview_init(MimeView
*mimeview
)
472 textview_init(mimeview
->textview
);
474 gtk_container_add(GTK_CONTAINER(mimeview
->mime_notebook
),
475 GTK_WIDGET_PTR(mimeview
->textview
));
478 static gboolean
any_part_is_signed(MimeInfo
*mimeinfo
)
481 if (privacy_mimeinfo_is_signed(mimeinfo
))
483 mimeinfo
= procmime_mimeinfo_next(mimeinfo
);
489 void mimeview_show_message(MimeView
*mimeview
, MimeInfo
*mimeinfo
,
492 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
494 mimeview_clear(mimeview
);
496 cm_return_if_fail(file
!= NULL
);
497 cm_return_if_fail(mimeinfo
!= NULL
);
499 mimeview
->mimeinfo
= mimeinfo
;
501 mimeview
->file
= g_strdup(file
);
503 g_signal_handlers_block_by_func(G_OBJECT(ctree
), mimeview_selected
,
506 /* check if the mail's signed - it can change the mail structure */
508 if (any_part_is_signed(mimeinfo
))
509 debug_print("signed mail\n");
511 mimeview_set_multipart_tree(mimeview
, mimeinfo
, NULL
);
512 gtk_tree_view_expand_all(ctree
);
513 icon_list_clear(mimeview
);
514 icon_list_create(mimeview
, mimeinfo
);
516 g_signal_handlers_unblock_by_func(G_OBJECT(ctree
),
517 mimeview_selected
, mimeview
);
521 static void mimeview_check_sig_cancel_now(MimeView
*mimeview
);
524 static void mimeview_free_mimeinfo(MimeView
*mimeview
)
526 gboolean defer
= FALSE
;
528 defer
= (mimeview
->check_data
!= NULL
);
530 mimeview
->check_data
->free_after_use
= TRUE
;
532 if (mimeview
->mimeinfo
!= NULL
&& !defer
) {
533 procmime_mimeinfo_free_all(&mimeview
->mimeinfo
);
534 mimeview
->mimeinfo
= NULL
;
537 debug_print("deferring free(mimeinfo) and cancelling check\n");
538 mimeview_check_sig_cancel_now(mimeview
);
543 void mimeview_destroy(MimeView
*mimeview
)
547 for (cur
= mimeview
->viewers
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
548 MimeViewer
*viewer
= (MimeViewer
*) cur
->data
;
549 viewer
->destroy_viewer(viewer
);
551 g_slist_free(mimeview
->viewers
);
552 gtk_target_list_unref(mimeview
->target_list
);
555 if (mimeview
->check_data
) {
556 mimeview
->check_data
->destroy_mimeview
= TRUE
;
557 debug_print("deferring destroy\n");
561 mimeview_free_mimeinfo(mimeview
);
562 gtk_tree_path_free(mimeview
->opened
);
563 g_free(mimeview
->file
);
565 mimeviews
= g_slist_remove(mimeviews
, mimeview
);
570 MimeInfo
*mimeview_get_selected_part(MimeView
*mimeview
)
572 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
574 GtkTreeSelection
*selection
;
575 MimeInfo
*partinfo
= NULL
;
577 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mimeview
->ctree
));
578 if (gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
579 gtk_tree_model_get(model
, &iter
, COL_DATA
, &partinfo
, -1);
584 MimeInfo
*mimeview_get_node_part(MimeView
*mimeview
, GtkTreePath
*path
)
586 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
590 gtk_tree_model_get_iter(model
, &iter
, path
);
591 gtk_tree_model_get(model
, &iter
, COL_DATA
, &partinfo
, -1);
595 gboolean
mimeview_tree_is_empty(MimeView
*mimeview
)
597 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
599 return !gtk_tree_model_get_iter_first(model
, &iter
);
602 static gboolean
mimeview_tree_next(GtkTreeModel
*model
, GtkTreePath
*path
)
604 GtkTreeIter iter
, parent
;
607 gtk_tree_model_get_iter(model
, &iter
, path
);
609 if (gtk_tree_model_iter_has_child(model
, &iter
)) {
610 gtk_tree_path_down(path
);
614 has_parent
= gtk_tree_model_iter_parent(model
, &parent
, &iter
);
616 if (!gtk_tree_model_iter_next(model
, &iter
)) {
618 GtkTreeIter saved_parent
= parent
;
619 gtk_tree_path_up(path
);
620 if (gtk_tree_model_iter_next(model
, &parent
)) {
621 gtk_tree_path_next(path
);
624 has_parent
= gtk_tree_model_iter_parent(model
, &parent
, &saved_parent
);
629 gtk_tree_path_next(path
);
636 static gboolean
mimeview_tree_prev(MimeView
*mimeview
, GtkTreePath
*path
)
638 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
639 GtkTreeIter iter
, child
, parent
;
642 gtk_tree_model_get_iter(model
, &iter
, path
);
643 has_parent
= gtk_tree_model_iter_parent(model
, &parent
, &iter
);
645 if (gtk_tree_path_prev(path
)) {
646 gtk_tree_model_get_iter(model
, &iter
, path
);
648 if (gtk_tree_model_iter_nth_child(model
, &child
, &iter
, 0)) {
649 gtk_tree_path_down(path
);
651 while (gtk_tree_model_iter_next(model
, &child
))
652 gtk_tree_path_next(path
);
659 gtk_tree_path_up(path
);
666 gint
mimeview_get_selected_part_num(MimeView
*mimeview
)
668 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
673 gtk_tree_model_get_iter_first(model
, &iter
);
674 path
= gtk_tree_model_get_path(model
, &iter
);
677 if (!gtk_tree_path_compare(mimeview
->opened
, path
)) {
678 gtk_tree_path_free(path
);
683 } while (mimeview_tree_next(model
, path
));
685 gtk_tree_path_free(path
);
690 void mimeview_select_part_num(MimeView
*mimeview
, gint i
)
692 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
695 GtkTreeSelection
*selection
;
701 gtk_tree_model_get_iter_first(model
, &iter
);
702 path
= gtk_tree_model_get_path(model
, &iter
);
705 if (!mimeview_tree_next(model
, path
)) {
706 gtk_tree_path_free(path
);
712 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mimeview
->ctree
));
713 gtk_tree_selection_select_path(selection
, path
);
714 gtk_tree_path_free(path
);
717 static void mimeview_set_multipart_tree(MimeView
*mimeview
,
721 GtkTreeStore
*model
= GTK_TREE_STORE(gtk_tree_view_get_model(
722 GTK_TREE_VIEW(mimeview
->ctree
)));
724 gchar
*content_type
, *length
, *name
;
726 cm_return_if_fail(mimeinfo
!= NULL
);
728 while (mimeinfo
!= NULL
) {
729 if (mimeinfo
->type
!= MIMETYPE_UNKNOWN
&& mimeinfo
->subtype
)
730 content_type
= g_strdup_printf("%s/%s",
731 procmime_get_media_type_str(mimeinfo
->type
),
734 content_type
= g_strdup("UNKNOWN");
736 length
= g_strdup(to_human_readable((goffset
) mimeinfo
->length
));
738 if (prefs_common
.attach_desc
)
739 name
= g_strdup(get_part_description(mimeinfo
));
741 name
= g_strdup(get_part_name(mimeinfo
));
743 gtk_tree_store_append(model
, &iter
, parent
);
744 gtk_tree_store_set(model
, &iter
,
745 COL_MIMETYPE
, content_type
,
748 COL_DATA
, mimeinfo
, -1);
749 g_free(content_type
);
753 if (mimeinfo
->node
->children
)
754 mimeview_set_multipart_tree(mimeview
,
755 (MimeInfo
*) mimeinfo
->node
->children
->data
, &iter
);
756 mimeinfo
= mimeinfo
->node
->next
!= NULL
?
757 (MimeInfo
*) mimeinfo
->node
->next
->data
: NULL
;
761 static const gchar
*get_real_part_name(MimeInfo
*partinfo
)
763 const gchar
*name
= NULL
;
765 name
= procmime_mimeinfo_get_parameter(partinfo
, "filename");
767 name
= procmime_mimeinfo_get_parameter(partinfo
, "name");
772 static const gchar
*get_part_name(MimeInfo
*partinfo
)
776 name
= get_real_part_name(partinfo
);
783 static const gchar
*get_part_description(MimeInfo
*partinfo
)
785 if (partinfo
->description
)
786 return partinfo
->description
;
788 return get_part_name(partinfo
);
791 static void mimeview_show_message_part(MimeView
*mimeview
, MimeInfo
*partinfo
)
796 if (!partinfo
) return;
798 fname
= mimeview
->file
;
801 if ((fp
= g_fopen(fname
, "rb")) == NULL
) {
802 FILE_OP_ERROR(fname
, "fopen");
806 if (fseek(fp
, partinfo
->offset
, SEEK_SET
) < 0) {
807 FILE_OP_ERROR(mimeview
->file
, "fseek");
812 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
813 textview_show_part(mimeview
->textview
, partinfo
, fp
);
818 static MimeViewer
*get_viewer_for_content_type(MimeView
*mimeview
, const gchar
*content_type
)
821 MimeViewerFactory
*factory
= NULL
;
822 MimeViewer
*viewer
= NULL
;
823 gchar
*real_contenttype
= NULL
, *tmp
;
825 real_contenttype
= g_utf8_strdown((gchar
*)content_type
, -1);
827 for (cur
= mimeviewer_factories
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
828 MimeViewerFactory
*curfactory
= cur
->data
;
831 while (curfactory
->content_types
[i
] != NULL
) {
832 tmp
= g_utf8_strdown(curfactory
->content_types
[i
], -1);
833 if (g_pattern_match_simple(tmp
, real_contenttype
)) {
834 debug_print("%s\n", curfactory
->content_types
[i
]);
835 factory
= curfactory
;
845 g_free(real_contenttype
);
849 for (cur
= mimeview
->viewers
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
850 MimeViewer
*curviewer
= cur
->data
;
852 if (curviewer
->factory
== factory
)
855 viewer
= factory
->create_viewer();
856 gtk_container_add(GTK_CONTAINER(mimeview
->mime_notebook
),
857 GTK_WIDGET(viewer
->get_widget(viewer
)));
859 mimeview
->viewers
= g_slist_append(mimeview
->viewers
, viewer
);
864 gboolean
mimeview_has_viewer_for_content_type(MimeView
*mimeview
, const gchar
*content_type
)
866 return (get_viewer_for_content_type(mimeview
, content_type
) != NULL
);
869 static MimeViewer
*get_viewer_for_mimeinfo(MimeView
*mimeview
, MimeInfo
*partinfo
)
871 gchar
*content_type
= NULL
;
872 MimeViewer
*viewer
= NULL
;
874 if ((partinfo
->type
== MIMETYPE_APPLICATION
) &&
875 (!g_ascii_strcasecmp(partinfo
->subtype
, "octet-stream"))) {
876 const gchar
*filename
;
878 filename
= procmime_mimeinfo_get_parameter(partinfo
, "filename");
879 if (filename
== NULL
)
880 filename
= procmime_mimeinfo_get_parameter(partinfo
, "name");
881 if (filename
!= NULL
)
882 content_type
= procmime_get_mime_type(filename
);
884 content_type
= procmime_get_content_type_str(partinfo
->type
, partinfo
->subtype
);
887 if (content_type
!= NULL
) {
888 viewer
= get_viewer_for_content_type(mimeview
, content_type
);
889 g_free(content_type
);
895 gboolean
mimeview_show_part(MimeView
*mimeview
, MimeInfo
*partinfo
)
899 if (mimeview
->messageview
->partial_display_shown
) {
900 noticeview_hide(mimeview
->messageview
->noticeview
);
901 mimeview
->messageview
->partial_display_shown
= FALSE
;
904 viewer
= get_viewer_for_mimeinfo(mimeview
, partinfo
);
905 if (viewer
== NULL
) {
906 if (mimeview
->mimeviewer
!= NULL
)
907 mimeview
->mimeviewer
->clear_viewer(mimeview
->mimeviewer
);
908 mimeview
->mimeviewer
= NULL
;
912 if (mimeview
->mimeviewer
!= NULL
)
913 mimeview
->mimeviewer
->clear_viewer(mimeview
->mimeviewer
);
915 if (mimeview
->mimeviewer
!= viewer
)
916 mimeview
->mimeviewer
= viewer
;
918 mimeview_change_view_type(mimeview
, MIMEVIEW_VIEWER
);
919 viewer
->mimeview
= mimeview
;
920 viewer
->show_mimepart(viewer
, mimeview
->file
, partinfo
);
925 static void mimeview_change_view_type(MimeView
*mimeview
, MimeViewType type
)
927 TextView
*textview
= mimeview
->textview
;
928 GtkWidget
*focused
= NULL
;
930 if (mainwindow_get_mainwindow())
931 focused
= gtkut_get_focused_child(
932 GTK_CONTAINER(mainwindow_get_mainwindow()->window
));
934 if ((mimeview
->type
!= MIMEVIEW_VIEWER
) &&
935 (mimeview
->type
== type
)) return;
939 gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview
->mime_notebook
),
940 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview
->mime_notebook
),
941 GTK_WIDGET_PTR(textview
)));
943 case MIMEVIEW_VIEWER
:
944 gtk_notebook_set_current_page(GTK_NOTEBOOK(mimeview
->mime_notebook
),
945 gtk_notebook_page_num(GTK_NOTEBOOK(mimeview
->mime_notebook
),
946 GTK_WIDGET(mimeview
->mimeviewer
->get_widget(mimeview
->mimeviewer
))));
952 gtk_widget_grab_focus(focused
);
953 mimeview
->type
= type
;
956 void mimeview_clear(MimeView
*mimeview
)
963 if (g_slist_find(mimeviews
, mimeview
) == NULL
)
966 noticeview_hide(mimeview
->siginfoview
);
968 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
969 gtk_tree_store_clear(GTK_TREE_STORE(model
));
971 textview_clear(mimeview
->textview
);
972 if (mimeview
->mimeviewer
!= NULL
)
973 mimeview
->mimeviewer
->clear_viewer(mimeview
->mimeviewer
);
975 mimeview_free_mimeinfo(mimeview
);
977 mimeview
->mimeinfo
= NULL
;
979 gtk_tree_path_free(mimeview
->opened
);
980 mimeview
->opened
= NULL
;
982 g_free(mimeview
->file
);
983 mimeview
->file
= NULL
;
985 icon_list_clear(mimeview
);
986 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
989 gchar
* get_message_check_signature_shortcut(MessageView
*messageview
) {
990 GtkUIManager
*ui_manager
;
992 if (messageview
->window
!= NULL
)
993 ui_manager
= messageview
->ui_manager
;
995 ui_manager
= messageview
->mainwin
->ui_manager
;
997 return cm_menu_item_get_shortcut(ui_manager
, "Menu/Message/CheckSignature");
1000 static void check_signature_cb(GtkWidget
*widget
, gpointer user_data
);
1001 static void display_full_info_cb(GtkWidget
*widget
, gpointer user_data
);
1003 static void update_signature_noticeview(MimeView
*mimeview
, MimeInfo
*mimeinfo
,
1004 gboolean special
, SignatureStatus code
)
1006 gchar
*text
= NULL
, *button_text
= NULL
;
1008 StockPixmap icon
= STOCK_PIXMAP_PRIVACY_SIGNED
;
1009 SignatureStatus mycode
= SIGNATURE_UNCHECKED
;
1011 cm_return_if_fail(mimeview
!= NULL
);
1012 cm_return_if_fail(mimeinfo
!= NULL
);
1017 mycode
= privacy_mimeinfo_get_sig_status(mimeinfo
);
1020 case SIGNATURE_UNCHECKED
:
1021 button_text
= _("Check signature");
1022 func
= check_signature_cb
;
1023 icon
= STOCK_PIXMAP_PRIVACY_SIGNED
;
1026 button_text
= _("View full information");
1027 func
= display_full_info_cb
;
1028 icon
= STOCK_PIXMAP_PRIVACY_PASSED
;
1030 case SIGNATURE_WARN
:
1031 button_text
= _("View full information");
1032 func
= display_full_info_cb
;
1033 icon
= STOCK_PIXMAP_PRIVACY_WARN
;
1035 case SIGNATURE_KEY_EXPIRED
:
1036 button_text
= _("View full information");
1037 func
= display_full_info_cb
;
1038 icon
= STOCK_PIXMAP_PRIVACY_EXPIRED
;
1040 case SIGNATURE_INVALID
:
1041 button_text
= _("View full information");
1042 func
= display_full_info_cb
;
1043 icon
= STOCK_PIXMAP_PRIVACY_FAILED
;
1045 case SIGNATURE_CHECK_FAILED
:
1046 case SIGNATURE_CHECK_TIMEOUT
:
1047 button_text
= _("Check again");
1048 func
= check_signature_cb
;
1049 icon
= STOCK_PIXMAP_PRIVACY_UNKNOWN
;
1054 if (mycode
== SIGNATURE_UNCHECKED
) {
1055 gchar
*tmp
= privacy_mimeinfo_sig_info_short(mimeinfo
);
1056 gchar
*shortcut
= get_message_check_signature_shortcut(mimeview
->messageview
);
1058 if (*shortcut
== '\0')
1059 text
= g_strdup_printf(_("%s Click the icon to check it."), tmp
);
1061 text
= g_strdup_printf(_("%s Click the icon or hit '%s' to check it."),
1065 } else if (mycode
!= SIGNATURE_CHECK_TIMEOUT
) {
1066 text
= privacy_mimeinfo_sig_info_short(mimeinfo
);
1067 } else if (mycode
== SIGNATURE_CHECK_TIMEOUT
) {
1068 gchar
*shortcut
= get_message_check_signature_shortcut(mimeview
->messageview
);
1070 if (*shortcut
== '\0')
1071 text
= g_strdup(_("Timeout checking the signature. Click the icon to try again."));
1073 text
= g_strdup_printf(_("Timeout checking the signature. Click the icon or hit '%s' to try again."), shortcut
);
1077 noticeview_set_text(mimeview
->siginfoview
, text
);
1078 gtk_label_set_selectable(GTK_LABEL(mimeview
->siginfoview
->text
), TRUE
);
1081 noticeview_set_button_text(mimeview
->siginfoview
, NULL
);
1082 noticeview_set_button_press_callback(
1083 mimeview
->siginfoview
,
1085 (gpointer
) mimeview
);
1086 noticeview_set_icon(mimeview
->siginfoview
, icon
);
1087 noticeview_set_tooltip(mimeview
->siginfoview
, button_text
);
1089 icon_list_clear(mimeview
);
1090 icon_list_create(mimeview
, mimeview
->mimeinfo
);
1095 /* reset all thread stuff, and do the cleanups we've been left to do */
1096 static void mimeview_check_data_reset(MimeView
*mimeview
)
1099 gboolean must_destroy
;
1101 if (!mimeview
->check_data
)
1104 must_free
= mimeview
->check_data
->free_after_use
;
1105 must_destroy
= mimeview
->check_data
->destroy_mimeview
;
1107 if (mimeview
->check_data
->cancel_th_init
) {
1108 debug_print("killing canceller thread\n");
1109 mimeview
->check_data
->cancel_th_init
= FALSE
;
1110 pthread_cancel(mimeview
->check_data
->cancel_th
);
1114 debug_print("freeing deferred mimeinfo\n");
1115 procmime_mimeinfo_free_all(&mimeview
->check_data
->siginfo
);
1118 g_free(mimeview
->check_data
);
1119 mimeview
->check_data
= NULL
;
1122 debug_print("freeing deferred mimeview\n");
1123 mimeview_free_mimeinfo(mimeview
);
1124 gtk_tree_path_free(mimeview
->opened
);
1125 g_free(mimeview
->file
);
1127 mimeviews
= g_slist_remove(mimeviews
, mimeview
);
1131 /* GUI update once the checker thread is done or killed */
1132 static gboolean
mimeview_check_sig_thread_cb(void *data
)
1134 MimeView
*mimeview
= (MimeView
*) data
;
1135 MimeInfo
*mimeinfo
= mimeview
->siginfo
;
1137 debug_print("mimeview_check_sig_thread_cb\n");
1139 if (mimeinfo
== NULL
) {
1140 /* message changed !? */
1141 g_warning("no more siginfo!");
1145 if (!mimeview
->check_data
) {
1146 g_warning("nothing to check");
1150 if (mimeview
->check_data
->siginfo
!= mimeinfo
) {
1151 /* message changed !? */
1152 g_warning("different siginfo!");
1156 if (mimeview
->check_data
->destroy_mimeview
||
1157 mimeview
->check_data
->free_after_use
) {
1158 debug_print("not bothering, we're changing message\n");
1163 if (mimeview
->check_data
->timeout
)
1164 update_signature_noticeview(mimeview
, mimeview
->siginfo
,
1165 TRUE
, SIGNATURE_CHECK_TIMEOUT
);
1167 update_signature_noticeview(mimeview
, mimeview
->siginfo
,
1171 mimeview_check_data_reset(mimeview
);
1175 /* sig checker thread */
1176 static void *mimeview_check_sig_worker_thread(void *data
)
1178 MimeView
*mimeview
= (MimeView
*)data
;
1179 MimeInfo
*mimeinfo
= mimeview
->siginfo
;
1181 debug_print("checking...\n");
1183 if (!mimeview
->check_data
)
1186 if (mimeinfo
&& mimeinfo
== mimeview
->check_data
->siginfo
) {
1187 privacy_mimeinfo_check_signature(mimeinfo
);
1188 if (mimeview
->check_data
&& mimeview
->check_data
->cancel_th_init
) {
1189 mimeview
->check_data
->cancel_th_init
= FALSE
;
1190 pthread_cancel(mimeview
->check_data
->cancel_th
);
1193 /* that's strange! we changed message without
1194 * getting killed. */
1195 g_warning("different siginfo!");
1196 mimeview_check_data_reset(mimeview
);
1200 /* use g_timeout so that GUI updates is done from the
1202 g_timeout_add(0,mimeview_check_sig_thread_cb
,mimeview
);
1207 /* killer thread - acts when the checker didn't work fast
1209 static void *mimeview_check_sig_cancel_thread(void *data
)
1211 MimeView
*mimeview
= (MimeView
*)data
;
1213 if (!mimeview
->check_data
)
1214 return NULL
; /* nothing to kill ! */
1216 /* wait for a few seconds... */
1217 debug_print("waiting a while\n");
1219 g_usleep(5 * 1000 * 1000);
1221 if (!mimeview
->check_data
)
1222 return NULL
; /* nothing to kill, it's done in time :) */
1224 /* too late, go away checker thread */
1225 debug_print("killing checker thread\n");
1226 if (mimeview
->check_data
->th_init
) {
1227 mimeview
->check_data
->th_init
= FALSE
;
1228 pthread_cancel(mimeview
->check_data
->th
);
1231 /* tell upstream it was a timeout */
1232 mimeview
->check_data
->timeout
= TRUE
;
1233 /* use g_timeout so that GUI updates is done from the
1235 g_timeout_add(0,mimeview_check_sig_thread_cb
,mimeview
);
1240 /* get rid of the checker thread right now - used when changing the
1241 * displayed message for example. */
1242 static void mimeview_check_sig_cancel_now(MimeView
*mimeview
)
1244 if (!mimeview
->check_data
)
1246 debug_print("killing checker thread NOW\n");
1247 if (mimeview
->check_data
->th_init
) {
1248 mimeview
->check_data
->th_init
= FALSE
;
1249 pthread_cancel(mimeview
->check_data
->th
);
1252 /* tell upstream it was a timeout */
1253 mimeview
->check_data
->timeout
= TRUE
;
1254 mimeview_check_sig_thread_cb(mimeview
);
1258 /* creates a thread to check the signature, and a second one
1259 * to kill the first one after a timeout */
1260 static void mimeview_check_sig_in_thread(MimeView
*mimeview
)
1263 pthread_attr_t detach
, detach2
;
1265 if (mimeview
->check_data
) {
1266 g_warning("already checking it");
1270 mimeview
->check_data
= g_new0(SigCheckData
, 1);
1271 mimeview
->check_data
->siginfo
= mimeview
->siginfo
;
1272 debug_print("creating thread\n");
1274 /* init thread attributes and create the checker thread */
1275 if (pthread_attr_init(&detach
) != 0 ||
1276 pthread_attr_setdetachstate(&detach
, PTHREAD_CREATE_DETACHED
) != 0 ||
1277 pthread_attr_init(&detach2
) != 0 ||
1278 pthread_attr_setdetachstate(&detach2
, PTHREAD_CREATE_DETACHED
) != 0 ||
1279 pthread_create(&th
, &detach
,
1280 mimeview_check_sig_worker_thread
,
1282 /* arh. We'll do it synchronously. */
1283 g_warning("can't create thread");
1284 g_free(mimeview
->check_data
);
1285 mimeview
->check_data
= NULL
;
1288 mimeview
->check_data
->th
= th
;
1289 mimeview
->check_data
->th_init
= TRUE
;
1292 /* create the killer thread */
1293 pthread_create(&th2
, &detach2
,
1294 mimeview_check_sig_cancel_thread
,
1297 mimeview
->check_data
->cancel_th
= th2
;
1298 mimeview
->check_data
->cancel_th_init
= TRUE
;
1302 static void check_signature_cb(GtkWidget
*widget
, gpointer user_data
)
1304 MimeView
*mimeview
= (MimeView
*) user_data
;
1305 MimeInfo
*mimeinfo
= mimeview
->siginfo
;
1307 if (mimeinfo
== NULL
)
1310 if (mimeview
->check_data
)
1313 noticeview_set_text(mimeview
->siginfoview
, _("Checking signature..."));
1316 /* let's do it non-blocking */
1317 mimeview_check_sig_in_thread(mimeview
);
1318 if (!mimeview
->check_data
) /* let's check syncronously */
1321 debug_print("checking without thread\n");
1322 privacy_mimeinfo_check_signature(mimeinfo
);
1323 update_signature_noticeview(mimeview
, mimeview
->siginfo
, FALSE
, 0);
1327 void mimeview_check_signature(MimeView
*mimeview
)
1329 check_signature_cb(NULL
, mimeview
);
1332 static void redisplay_email(GtkWidget
*widget
, gpointer user_data
)
1334 MimeView
*mimeview
= (MimeView
*) user_data
;
1335 gtk_tree_path_free(mimeview
->opened
);
1336 mimeview
->opened
= NULL
;
1337 mimeview_selected(gtk_tree_view_get_selection(
1338 GTK_TREE_VIEW(mimeview
->ctree
)), mimeview
);
1341 static void display_full_info_cb(GtkWidget
*widget
, gpointer user_data
)
1343 MimeView
*mimeview
= (MimeView
*) user_data
;
1346 siginfo
= privacy_mimeinfo_sig_info_full(mimeview
->siginfo
);
1347 textview_set_text(mimeview
->textview
, siginfo
);
1349 noticeview_set_button_text(mimeview
->siginfoview
, NULL
);
1350 noticeview_set_button_press_callback(
1351 mimeview
->siginfoview
,
1352 G_CALLBACK(redisplay_email
),
1353 (gpointer
) mimeview
);
1354 noticeview_set_tooltip(mimeview
->siginfoview
, _("Go back to email"));
1357 static void update_signature_info(MimeView
*mimeview
, MimeInfo
*selected
)
1360 MimeInfo
*first_text
;
1362 cm_return_if_fail(mimeview
!= NULL
);
1363 cm_return_if_fail(selected
!= NULL
);
1365 if (selected
->type
== MIMETYPE_MESSAGE
1366 && !g_ascii_strcasecmp(selected
->subtype
, "rfc822")) {
1367 /* if the first text part is signed, check that */
1368 first_text
= selected
;
1369 while (first_text
&& first_text
->type
!= MIMETYPE_TEXT
) {
1370 first_text
= procmime_mimeinfo_next(first_text
);
1373 update_signature_info(mimeview
, first_text
);
1379 while (siginfo
!= NULL
) {
1380 if (privacy_mimeinfo_is_signed(siginfo
))
1382 siginfo
= procmime_mimeinfo_parent(siginfo
);
1384 mimeview
->siginfo
= siginfo
;
1386 /* This shortcut boolean is there to correctly set the menu's
1387 * CheckSignature item sensitivity without killing performance
1388 * each time the menu sensitiveness is updated (a lot).
1390 mimeview
->signed_part
= (siginfo
!= NULL
);
1392 if (siginfo
== NULL
) {
1393 noticeview_hide(mimeview
->siginfoview
);
1397 update_signature_noticeview(mimeview
, siginfo
, FALSE
, 0);
1398 noticeview_show(mimeview
->siginfoview
);
1401 static void mimeview_selected(GtkTreeSelection
*selection
, MimeView
*mimeview
)
1403 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
1404 GtkTreeModel
*model
;
1409 selection
= gtk_tree_view_get_selection(ctree
);
1410 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
1413 path
= gtk_tree_model_get_path(model
, &iter
);
1415 if (mimeview
->opened
&& !gtk_tree_path_compare(mimeview
->opened
, path
)) {
1416 gtk_tree_path_free(path
);
1420 gtk_tree_path_free(mimeview
->opened
);
1421 mimeview
->opened
= path
;
1422 mimeview
->spec_part
= NULL
;
1423 gtk_tree_view_scroll_to_cell(ctree
, path
, NULL
, TRUE
, 0.5, 0);
1425 partinfo
= mimeview_get_node_part(mimeview
, path
);
1426 if (!partinfo
) return;
1428 /* ungrab the mouse event */
1429 if (gtk_widget_has_grab(GTK_WIDGET(ctree
))) {
1430 gtk_grab_remove(GTK_WIDGET(ctree
));
1431 if (gdk_pointer_is_grabbed())
1432 gdk_pointer_ungrab(GDK_CURRENT_TIME
);
1435 mimeview
->textview
->default_text
= FALSE
;
1437 update_signature_info(mimeview
, partinfo
);
1439 if (!mimeview_show_part(mimeview
, partinfo
)) {
1440 switch (partinfo
->type
) {
1442 case MIMETYPE_MESSAGE
:
1443 case MIMETYPE_MULTIPART
:
1444 mimeview_show_message_part(mimeview
, partinfo
);
1448 mimeview
->textview
->default_text
= TRUE
;
1449 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
1450 textview_clear(mimeview
->textview
);
1451 textview_show_mime_part(mimeview
->textview
, partinfo
);
1456 if (mimeview
->siginfo
&& privacy_auto_check_signatures(mimeview
->siginfo
)
1457 && privacy_mimeinfo_get_sig_status(mimeview
->siginfo
) == SIGNATURE_UNCHECKED
) {
1458 mimeview_check_signature(mimeview
);
1462 static gint
mimeview_button_pressed(GtkWidget
*widget
, GdkEventButton
*event
,
1465 GtkTreeSelection
*selection
;
1468 if (!event
) return FALSE
;
1470 if (event
->button
== 2 || event
->button
== 3) {
1471 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(widget
));
1472 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
1475 gtk_tree_selection_select_iter(selection
, &iter
);
1477 part_button_pressed(mimeview
, event
, mimeview_get_selected_part(mimeview
));
1482 static gboolean
mimeview_scrolled(GtkWidget
*widget
, GdkEventScroll
*event
,
1485 GtkVScrollbutton
*scrollbutton
= (GtkVScrollbutton
*)mimeview
->scrollbutton
;
1486 if (event
->direction
== GDK_SCROLL_UP
) {
1487 scrollbutton
->scroll_type
= GTK_SCROLL_STEP_BACKWARD
;
1489 scrollbutton
->scroll_type
= GTK_SCROLL_STEP_FORWARD
;
1491 gtk_vscrollbutton_scroll(scrollbutton
);
1495 /* from gdkevents.c */
1496 #define DOUBLE_CLICK_TIME 250
1498 static gboolean
part_button_pressed(MimeView
*mimeview
, GdkEventButton
*event
,
1501 static MimeInfo
*lastinfo
;
1502 static guint32 lasttime
;
1504 if (event
->button
== 2 ||
1505 (event
->button
== 1 && (event
->time
- lasttime
) < DOUBLE_CLICK_TIME
&& lastinfo
== partinfo
)) {
1506 /* call external program for image, audio or html */
1507 mimeview_launch(mimeview
, partinfo
);
1509 } else if (event
->button
== 3) {
1510 if (partinfo
&& (partinfo
->type
== MIMETYPE_MESSAGE
||
1511 partinfo
->type
== MIMETYPE_IMAGE
||
1512 partinfo
->type
== MIMETYPE_MULTIPART
))
1513 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/DisplayAsText", FALSE
);
1515 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/DisplayAsText", TRUE
);
1518 partinfo
->type
== MIMETYPE_APPLICATION
&&
1519 !g_ascii_strcasecmp(partinfo
->subtype
, "octet-stream"))
1520 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/Open", FALSE
);
1523 cm_menu_set_sensitive_full(mimeview
->ui_manager
, "Menus/MimeView/Open", TRUE
);
1525 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
1526 "pop_partinfo", partinfo
);
1528 gtk_menu_popup(GTK_MENU(mimeview
->popupmenu
),
1529 NULL
, NULL
, NULL
, NULL
,
1530 event
->button
, event
->time
);
1534 lastinfo
= partinfo
;
1535 lasttime
= event
->time
;
1540 gboolean
mimeview_pass_key_press_event(MimeView
*mimeview
, GdkEventKey
*event
)
1542 return mimeview_key_pressed(mimeview
->ctree
, event
, mimeview
);
1545 void mimeview_select_next_part(MimeView
*mimeview
)
1547 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
1548 GtkTreeModel
*model
= gtk_tree_view_get_model(ctree
);
1549 GtkTreeSelection
*selection
;
1552 MimeInfo
*partinfo
= NULL
;
1555 if (!mimeview
->opened
) return;
1557 gtk_tree_model_get_iter(model
, &iter
, mimeview
->opened
);
1558 path
= gtk_tree_model_get_path(model
, &iter
);
1560 has_next
= mimeview_tree_next(model
, path
);
1562 has_next
= gtk_tree_model_get_iter_first(model
, &iter
);
1563 gtk_tree_path_free(path
);
1564 path
= gtk_tree_model_get_path(model
, &iter
);
1568 partinfo
= mimeview_get_node_part(mimeview
, path
);
1569 if (partinfo
->type
== MIMETYPE_MULTIPART
||
1570 (!prefs_common
.show_inline_attachments
&& partinfo
->id
))
1572 selection
= gtk_tree_view_get_selection(ctree
);
1573 gtk_tree_selection_select_path(selection
, path
);
1574 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
1577 gtk_tree_path_free(path
);
1580 void mimeview_select_prev_part(MimeView
*mimeview
)
1582 GtkTreeView
*ctree
= GTK_TREE_VIEW(mimeview
->ctree
);
1583 GtkTreeModel
*model
= gtk_tree_view_get_model(ctree
);
1584 GtkTreeSelection
*selection
;
1587 MimeInfo
*partinfo
= NULL
;
1590 if (!mimeview
->opened
) return;
1592 gtk_tree_model_get_iter(model
, &iter
, mimeview
->opened
);
1593 path
= gtk_tree_model_get_path(model
, &iter
);
1595 has_prev
= mimeview_tree_prev(mimeview
, path
);
1597 while (mimeview_tree_next(model
, path
)) {}
1602 partinfo
= mimeview_get_node_part(mimeview
, path
);
1603 if (partinfo
->type
== MIMETYPE_MULTIPART
||
1604 (!prefs_common
.show_inline_attachments
&& partinfo
->id
))
1606 selection
= gtk_tree_view_get_selection(ctree
);
1607 gtk_tree_selection_select_path(selection
, path
);
1608 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
1611 gtk_tree_path_free(path
);
1614 #define BREAK_ON_MODIFIER_KEY() \
1615 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
1617 static gint
mimeview_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
1620 SummaryView
*summaryview
;
1622 if (!event
) return FALSE
;
1623 if (!mimeview
->opened
) return FALSE
;
1625 summaryview
= mimeview
->messageview
->mainwin
->summaryview
;
1627 if (summaryview
&& quicksearch_has_focus(summaryview
->quicksearch
))
1630 switch (event
->keyval
) {
1633 textview_scroll_max(mimeview
->textview
,
1634 (event
->keyval
== GDK_KEY_Home
));
1636 case GDK_KEY_Page_Down
:
1638 if (mimeview_scroll_page(mimeview
,
1639 (event
->state
& GDK_SHIFT_MASK
) != 0))
1642 if (!(event
->state
& GDK_SHIFT_MASK
))
1643 mimeview_select_next_part(mimeview
);
1645 case GDK_KEY_Page_Up
:
1646 case GDK_KEY_BackSpace
:
1647 mimeview_scroll_page(mimeview
, TRUE
);
1649 case GDK_KEY_Return
:
1650 case GDK_KEY_KP_Enter
:
1651 mimeview_scroll_one_line(mimeview
,
1652 (event
->state
& GDK_MOD1_MASK
) != 0);
1656 mimeview_scroll_one_line(mimeview
, (event
->keyval
== GDK_KEY_Up
));
1662 if (mimeview
->messageview
->new_window
) return FALSE
;
1664 return summary_pass_key_press_event(summaryview
, event
);
1667 static void mimeview_drag_data_get(GtkWidget
*widget
,
1668 GdkDragContext
*drag_context
,
1669 GtkSelectionData
*selection_data
,
1674 gchar
*filename
= NULL
, *uriname
, *tmp
;
1679 if (!mimeview
->opened
) return;
1680 if (!mimeview
->file
) return;
1682 partinfo
= mimeview_get_selected_part(mimeview
);
1683 if (!partinfo
) return;
1685 if (strlen(get_part_name(partinfo
)) > 0) {
1686 filename
= g_path_get_basename(get_part_name(partinfo
));
1687 if (*filename
== '\0') return;
1688 } else if (partinfo
->type
== MIMETYPE_MESSAGE
1689 && !g_ascii_strcasecmp(partinfo
->subtype
, "rfc822")) {
1691 GPtrArray
*headers
= NULL
;
1694 fp
= g_fopen(partinfo
->data
.filename
, "rb");
1695 if (fp
!= NULL
&& fseek(fp
, partinfo
->offset
, SEEK_SET
) == 0) {
1696 headers
= procheader_get_header_array_asis(fp
);
1699 for (i
= 0; i
< headers
->len
; i
++) {
1700 Header
*header
= g_ptr_array_index(headers
, i
);
1701 if (procheader_headername_equal(header
->name
, "Subject")) {
1702 unfold_line(header
->body
);
1703 name
= g_strconcat(header
->body
, ".txt", NULL
);
1704 subst_for_filename(name
);
1707 procheader_header_array_destroy(headers
);
1713 filename
= g_path_get_basename(name
);
1716 if (filename
== NULL
)
1717 filename
= g_path_get_basename("Unnamed part");
1719 if (!g_utf8_validate(filename
, -1, NULL
))
1720 tmp
= conv_codeset_strdup(filename
,
1721 conv_get_locale_charset_str(),
1724 tmp
= g_strdup(filename
);
1727 g_warning("filename not in UTF-8");
1728 tmp
= g_strdup("Unnamed part");
1730 filename
= g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S
,
1734 if (is_file_exist(filename
)) {
1736 gchar
*prefix
= NULL
;
1737 gchar
*new_name
= NULL
;
1738 if (strrchr(tmp
, '.')) {
1739 prefix
= g_strdup(tmp
);
1740 ext
= g_strdup(strrchr(tmp
, '.'));
1741 *(strrchr(prefix
, '.')) = '\0';
1743 prefix
= g_strdup(tmp
);
1747 new_name
= g_strdup_printf("%s.%d%s", prefix
, count
, ext
);
1751 filename
= g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S
,
1754 goto check_new_file
;
1759 if ((err
= procmime_get_part(filename
, partinfo
)) < 0)
1761 (_("Couldn't save the part of multipart message: %s"),
1764 tmp
= g_filename_to_uri(filename
, NULL
, NULL
);
1765 uriname
= g_strconcat(tmp
, "\r\n", NULL
);
1768 gtk_selection_data_set(selection_data
,
1769 gtk_selection_data_get_target(selection_data
), 8,
1770 (guchar
*)uriname
, strlen(uriname
));
1777 * Returns a filename (with path) for an attachment
1778 * \param partinfo The attachment to save
1779 * \param basedir The target directory
1780 * \param number Used for dummy filename if attachment is unnamed
1782 static gchar
*mimeview_get_filename_for_part(MimeInfo
*partinfo
,
1783 const gchar
*basedir
,
1789 filename
= g_strdup(get_part_name(partinfo
));
1790 if (!filename
|| !*filename
) {
1792 filename
= g_strdup_printf("noname.%d", number
);
1795 if (!g_utf8_validate(filename
, -1, NULL
)) {
1796 gchar
*tmp
= conv_filename_to_utf8(filename
);
1801 subst_for_filename(filename
);
1803 fullname
= g_strconcat
1804 (basedir
, G_DIR_SEPARATOR_S
, (g_path_is_absolute(filename
))
1805 ? &filename
[1] : filename
, NULL
);
1808 filename
= conv_filename_from_utf8(fullname
);
1814 * Write a single attachment to file
1815 * \param filename Filename with path
1816 * \param partinfo Attachment to save
1818 static gboolean
mimeview_write_part(const gchar
*filename
,
1824 dir
= g_path_get_dirname(filename
);
1825 if (!is_dir_exist(dir
))
1829 if (is_file_exist(filename
)) {
1834 if (!g_utf8_validate(filename
, -1, NULL
))
1835 tmp
= conv_filename_to_utf8(filename
);
1837 tmp
= g_strdup(filename
);
1839 res
= g_strdup_printf(_("Overwrite existing file '%s'?"),
1842 aval
= alertpanel(_("Overwrite"), res
, GTK_STOCK_CANCEL
,
1843 GTK_STOCK_OK
, NULL
);
1845 if (G_ALERTALTERNATE
!= aval
) return FALSE
;
1848 if ((err
= procmime_get_part(filename
, partinfo
)) < 0) {
1850 (_("Couldn't save the part of multipart message: %s"),
1859 * Menu callback: Save all attached files
1860 * \param mimeview Current display
1862 static void mimeview_save_all(MimeView
*mimeview
)
1866 gchar
*startdir
= NULL
;
1869 if (!mimeview
->opened
) return;
1870 if (!mimeview
->file
) return;
1871 if (!mimeview
->mimeinfo
) return;
1873 partinfo
= mimeview
->mimeinfo
;
1874 if (prefs_common
.attach_save_dir
&& *prefs_common
.attach_save_dir
)
1875 startdir
= g_strconcat(prefs_common
.attach_save_dir
,
1876 G_DIR_SEPARATOR_S
, NULL
);
1878 startdir
= g_strdup(get_home_dir());
1880 manage_window_focus_in(gtk_widget_get_ancestor(mimeview
->hbox
, GTK_TYPE_WINDOW
), NULL
, NULL
);
1881 dirname
= filesel_select_file_save_folder(_("Select destination folder"), startdir
);
1887 if (!is_dir_exist (dirname
)) {
1888 alertpanel_error(_("'%s' is not a directory."),
1895 if (dirname
[strlen(dirname
)-1] == G_DIR_SEPARATOR
)
1896 dirname
[strlen(dirname
)-1] = '\0';
1898 /* Skip the first part, that is sometimes DISPOSITIONTYPE_UNKNOWN */
1899 if (partinfo
&& partinfo
->type
== MIMETYPE_MESSAGE
)
1900 partinfo
= procmime_mimeinfo_next(partinfo
);
1901 if (partinfo
&& partinfo
->type
== MIMETYPE_MULTIPART
) {
1902 partinfo
= procmime_mimeinfo_next(partinfo
);
1903 if (partinfo
&& partinfo
->type
== MIMETYPE_TEXT
)
1904 partinfo
= procmime_mimeinfo_next(partinfo
);
1907 while (partinfo
!= NULL
) {
1908 if (partinfo
->type
!= MIMETYPE_MESSAGE
&&
1909 partinfo
->type
!= MIMETYPE_MULTIPART
&&
1910 (partinfo
->disposition
!= DISPOSITIONTYPE_INLINE
1911 || get_real_part_name(partinfo
) != NULL
)) {
1912 gchar
*filename
= mimeview_get_filename_for_part
1913 (partinfo
, dirname
, number
++);
1915 mimeview_write_part(filename
, partinfo
);
1918 partinfo
= procmime_mimeinfo_next(partinfo
);
1921 g_free(prefs_common
.attach_save_dir
);
1923 prefs_common
.attach_save_dir
= g_filename_to_utf8(dirname
,
1924 -1, NULL
, NULL
, NULL
);
1928 static MimeInfo
*mimeview_get_part_to_use(MimeView
*mimeview
)
1930 MimeInfo
*partinfo
= NULL
;
1931 if (mimeview
->spec_part
) {
1932 partinfo
= mimeview
->spec_part
;
1933 mimeview
->spec_part
= NULL
;
1935 partinfo
= (MimeInfo
*) g_object_get_data
1936 (G_OBJECT(mimeview
->popupmenu
),
1938 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
1939 "pop_partinfo", NULL
);
1941 partinfo
= mimeview_get_selected_part(mimeview
);
1948 * Menu callback: Save the selected attachment
1949 * \param mimeview Current display
1951 void mimeview_save_as(MimeView
*mimeview
)
1954 gchar
*filepath
= NULL
;
1955 gchar
*filedir
= NULL
;
1957 gchar
*partname
= NULL
;
1959 if (!mimeview
->opened
) return;
1960 if (!mimeview
->file
) return;
1962 partinfo
= mimeview_get_part_to_use(mimeview
);
1964 cm_return_if_fail(partinfo
!= NULL
);
1966 if (get_part_name(partinfo
) == NULL
) {
1969 partname
= g_strdup(get_part_name(partinfo
));
1971 if (!g_utf8_validate(partname
, -1, NULL
)) {
1972 gchar
*tmp
= conv_filename_to_utf8(partname
);
1974 tmp
= conv_codeset_strdup(partname
,
1975 conv_get_locale_charset_str(),
1984 subst_for_filename(partname
);
1986 if (prefs_common
.attach_save_dir
&& *prefs_common
.attach_save_dir
)
1987 filepath
= g_strconcat(prefs_common
.attach_save_dir
,
1988 G_DIR_SEPARATOR_S
, partname
, NULL
);
1990 filepath
= g_strdup(partname
);
1994 manage_window_focus_in(gtk_widget_get_ancestor(mimeview
->hbox
, GTK_TYPE_WINDOW
), NULL
, NULL
);
1995 filename
= filesel_select_file_save(_("Save as"), filepath
);
2001 mimeview_write_part(filename
, partinfo
);
2003 filedir
= g_path_get_dirname(filename
);
2004 if (filedir
&& strcmp(filedir
, ".")) {
2005 g_free(prefs_common
.attach_save_dir
);
2006 prefs_common
.attach_save_dir
= g_filename_to_utf8(filedir
, -1, NULL
, NULL
, NULL
);
2013 void mimeview_display_as_text(MimeView
*mimeview
)
2017 if (!mimeview
->opened
) return;
2019 partinfo
= mimeview_get_part_to_use(mimeview
);
2020 mimeview_select_mimepart_icon(mimeview
, partinfo
);
2021 cm_return_if_fail(partinfo
!= NULL
);
2022 mimeview_show_message_part(mimeview
, partinfo
);
2025 void mimeview_launch(MimeView
*mimeview
, MimeInfo
*partinfo
)
2030 if (!mimeview
->opened
) return;
2031 if (!mimeview
->file
) return;
2034 partinfo
= mimeview_get_part_to_use(mimeview
);
2036 cm_return_if_fail(partinfo
!= NULL
);
2038 filename
= procmime_get_tmp_file_name(partinfo
);
2040 if ((err
= procmime_get_part(filename
, partinfo
)) < 0)
2042 (_("Couldn't save the part of multipart message: %s"),
2045 mimeview_view_file(filename
, partinfo
, NULL
, mimeview
);
2051 void mimeview_open_with(MimeView
*mimeview
)
2055 if (!mimeview
) return;
2056 if (!mimeview
->opened
) return;
2057 if (!mimeview
->file
) return;
2059 partinfo
= mimeview_get_part_to_use(mimeview
);
2061 mimeview_open_part_with(mimeview
, partinfo
, FALSE
);
2064 static void mimeview_open_part_with(MimeView
*mimeview
, MimeInfo
*partinfo
, gboolean automatic
)
2068 gchar
*mime_command
= NULL
;
2069 gchar
*content_type
= NULL
;
2072 cm_return_if_fail(partinfo
!= NULL
);
2074 filename
= procmime_get_tmp_file_name(partinfo
);
2076 if ((err
= procmime_get_part(filename
, partinfo
)) < 0) {
2078 (_("Couldn't save the part of multipart message: %s"),
2084 if (!prefs_common
.mime_open_cmd_history
)
2085 prefs_common
.mime_open_cmd_history
=
2086 add_history(NULL
, prefs_common
.mime_open_cmd
);
2088 if ((partinfo
->type
== MIMETYPE_APPLICATION
) &&
2089 (!g_ascii_strcasecmp(partinfo
->subtype
, "octet-stream"))) {
2090 /* guess content-type from filename */
2091 content_type
= procmime_get_mime_type(filename
);
2093 if (content_type
== NULL
) {
2094 content_type
= procmime_get_content_type_str(partinfo
->type
,
2098 if ((partinfo
->type
== MIMETYPE_TEXT
&& !strcmp(partinfo
->subtype
, "html"))
2099 && prefs_common_get_uri_cmd() && prefs_common
.uri_cmd
[0]) {
2100 mime_command
= g_strdup(prefs_common_get_uri_cmd());
2101 g_free(content_type
);
2102 content_type
= NULL
;
2103 } else if (partinfo
->type
!= MIMETYPE_TEXT
|| !prefs_common_get_ext_editor_cmd()
2104 || !prefs_common_get_ext_editor_cmd()[0]) {
2105 mime_command
= mailcap_get_command_for_type(content_type
, filename
);
2107 mime_command
= g_strdup(prefs_common_get_ext_editor_cmd());
2108 g_free(content_type
);
2109 content_type
= NULL
;
2111 if (mime_command
== NULL
) {
2112 /* try with extension this time */
2113 g_free(content_type
);
2114 content_type
= procmime_get_mime_type(filename
);
2115 mime_command
= mailcap_get_command_for_type(content_type
, filename
);
2118 if (mime_command
== NULL
)
2122 gboolean remember
= FALSE
;
2123 if (content_type
!= NULL
)
2124 cmd
= input_dialog_combo_remember
2126 _("Enter the command-line to open file:\n"
2127 "('%s' will be replaced with file name)"),
2128 mime_command
? mime_command
: prefs_common
.mime_open_cmd
,
2129 prefs_common
.mime_open_cmd_history
, &remember
);
2131 cmd
= input_dialog_combo
2133 _("Enter the command-line to open file:\n"
2134 "('%s' will be replaced with file name)"),
2135 mime_command
? mime_command
: prefs_common
.mime_open_cmd
,
2136 prefs_common
.mime_open_cmd_history
);
2137 if (cmd
&& remember
) {
2138 mailcap_update_default(content_type
, cmd
);
2140 g_free(mime_command
);
2145 mimeview_view_file(filename
, partinfo
, cmd
, mimeview
);
2146 g_free(prefs_common
.mime_open_cmd
);
2147 prefs_common
.mime_open_cmd
= cmd
;
2148 prefs_common
.mime_open_cmd_history
=
2149 add_history(prefs_common
.mime_open_cmd_history
, cmd
);
2152 g_free(content_type
);
2157 static void mimeview_send_to(MimeView
*mimeview
, MimeInfo
*partinfo
)
2159 GList
*attach_file
= NULL
;
2160 AttachInfo
*ainfo
= NULL
;
2164 if (!mimeview
->opened
) return;
2165 if (!mimeview
->file
) return;
2167 cm_return_if_fail(partinfo
!= NULL
);
2169 filename
= procmime_get_tmp_file_name(partinfo
);
2171 if (!(err
= procmime_get_part(filename
, partinfo
))) {
2172 ainfo
= g_new0(AttachInfo
, 1);
2173 ainfo
->file
= filename
;
2174 ainfo
->name
= g_strdup(get_part_name(partinfo
));
2175 ainfo
->content_type
= procmime_get_content_type_str(
2176 partinfo
->type
, partinfo
->subtype
);
2177 ainfo
->charset
= g_strdup(procmime_mimeinfo_get_parameter(
2178 partinfo
, "charset"));
2179 attach_file
= g_list_append(attach_file
, ainfo
);
2181 compose_new(NULL
, NULL
, attach_file
);
2183 g_free(ainfo
->name
);
2184 g_free(ainfo
->content_type
);
2185 g_free(ainfo
->charset
);
2187 g_list_free(attach_file
);
2190 (_("Couldn't save the part of multipart message: %s"),
2195 static void mimeview_view_file(const gchar
*filename
, MimeInfo
*partinfo
,
2196 const gchar
*cmd
, MimeView
*mimeview
)
2200 gchar buf
[BUFFSIZE
];
2203 mimeview_open_part_with(mimeview
, partinfo
, TRUE
);
2205 if ((p
= strchr(cmd
, '%')) && *(p
+ 1) == 's' &&
2206 !strchr(p
+ 2, '%')) {
2207 g_snprintf(buf
, sizeof(buf
), cmd
, filename
);
2208 if (!prefs_common
.save_parts_readwrite
)
2209 g_chmod(filename
, S_IRUSR
);
2211 g_chmod(filename
, S_IRUSR
|S_IWUSR
);
2213 g_warning("MIME viewer command-line is invalid: '%s'", cmd
);
2214 mimeview_open_part_with(mimeview
, partinfo
, FALSE
);
2216 if (execute_command_line(buf
, TRUE
, NULL
) != 0) {
2217 if (!prefs_common
.save_parts_readwrite
)
2218 g_chmod(filename
, S_IRUSR
|S_IWUSR
);
2219 mimeview_open_part_with(mimeview
, partinfo
, FALSE
);
2223 SHFILEINFO file_info
;
2224 GError
*error
= NULL
;
2225 gunichar2
*fn16
= g_utf8_to_utf16(filename
, -1, NULL
, NULL
, &error
);
2227 if (error
!= NULL
) {
2228 alertpanel_error(_("Could not convert attachment name to UTF-16:\n\n%s"),
2230 debug_print("filename '%s' conversion to UTF-16 failed\n", filename
);
2231 g_error_free(error
);
2235 if ((SHGetFileInfo((LPCWSTR
)fn16
, 0, &file_info
, sizeof(SHFILEINFO
), SHGFI_EXETYPE
)) != 0) {
2236 AlertValue val
= alertpanel_full(_("Execute untrusted binary?"),
2237 _("This attachment is an executable file. Executing "
2238 "untrusted binaries is dangerous and could probably "
2239 "lead to compromission of your computer.\n\n"
2240 "Do you want to run this file?"), GTK_STOCK_CANCEL
,
2242 NULL
, FALSE
, NULL
, ALERT_WARNING
, G_ALERTDEFAULT
);
2243 if (val
== G_ALERTALTERNATE
) {
2244 debug_print("executing binary\n");
2245 ShellExecute(NULL
, L
"open", (LPCWSTR
)fn16
, NULL
, NULL
, SW_SHOW
);
2248 ShellExecute(NULL
, L
"open", (LPCWSTR
)fn16
, NULL
, NULL
, SW_SHOW
);
2256 void mimeview_register_viewer_factory(MimeViewerFactory
*factory
)
2258 mimeviewer_factories
= g_slist_append(mimeviewer_factories
, factory
);
2261 static gint
cmp_viewer_by_factroy(gconstpointer a
, gconstpointer b
)
2263 return ((MimeViewer
*) a
)->factory
== (MimeViewerFactory
*) b
? 0 : -1;
2266 void mimeview_unregister_viewer_factory(MimeViewerFactory
*factory
)
2268 GSList
*mimeview_list
, *viewer_list
;
2270 for (mimeview_list
= mimeviews
; mimeview_list
!= NULL
; mimeview_list
= g_slist_next(mimeview_list
)) {
2271 MimeView
*mimeview
= (MimeView
*) mimeview_list
->data
;
2273 if (mimeview
->mimeviewer
&& mimeview
->mimeviewer
->factory
== factory
) {
2274 mimeview_change_view_type(mimeview
, MIMEVIEW_TEXT
);
2275 mimeview
->mimeviewer
= NULL
;
2278 while ((viewer_list
= g_slist_find_custom(mimeview
->viewers
, factory
, cmp_viewer_by_factroy
)) != NULL
) {
2279 MimeViewer
*mimeviewer
= (MimeViewer
*) viewer_list
->data
;
2281 mimeviewer
->destroy_viewer(mimeviewer
);
2282 mimeview
->viewers
= g_slist_remove(mimeview
->viewers
, mimeviewer
);
2286 mimeviewer_factories
= g_slist_remove(mimeviewer_factories
, factory
);
2289 static gboolean
icon_clicked_cb (GtkWidget
*button
, GdkEventButton
*event
, MimeView
*mimeview
)
2294 num
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button
), "icon_number"));
2295 partinfo
= g_object_get_data(G_OBJECT(button
), "partinfo");
2297 if (event
->button
== 1) {
2298 icon_selected(mimeview
, num
, partinfo
);
2299 gtk_widget_grab_focus(button
);
2300 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
2302 part_button_pressed(mimeview
, event
, partinfo
);
2307 static void icon_selected (MimeView
*mimeview
, gint num
, MimeInfo
*partinfo
)
2309 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mimeview
->ctree
));
2312 MimeInfo
*curr
= NULL
;
2314 gtk_tree_model_get_iter_first(model
, &iter
);
2315 path
= gtk_tree_model_get_path(model
, &iter
);
2318 gtk_tree_model_get_iter(model
, &iter
, path
);
2319 gtk_tree_model_get(model
, &iter
, COL_DATA
, &curr
, -1);
2320 if (curr
== partinfo
) {
2321 GtkTreeSelection
*sel
= gtk_tree_view_get_selection(
2322 GTK_TREE_VIEW(mimeview
->ctree
));
2323 gtk_tree_selection_select_iter(sel
, &iter
);
2324 gtk_tree_path_free(path
);
2327 } while (mimeview_tree_next(model
, path
));
2329 gtk_tree_path_free(path
);
2332 void mimeview_select_mimepart_icon(MimeView
*mimeview
, MimeInfo
*partinfo
)
2334 icon_list_toggle_by_mime_info(mimeview
, partinfo
);
2335 icon_selected(mimeview
, -1, partinfo
);
2338 static gint
icon_key_pressed(GtkWidget
*button
, GdkEventKey
*event
,
2341 SummaryView
*summaryview
;
2343 if (!event
) return FALSE
;
2345 switch (event
->keyval
) {
2347 if (mimeview_scroll_page(mimeview
, FALSE
))
2350 mimeview_select_next_part(mimeview
);
2354 case GDK_KEY_BackSpace
:
2355 mimeview_scroll_page(mimeview
, TRUE
);
2357 case GDK_KEY_Return
:
2358 case GDK_KEY_KP_Enter
:
2359 mimeview_scroll_one_line(mimeview
,
2360 (event
->state
& GDK_MOD1_MASK
) != 0);
2363 BREAK_ON_MODIFIER_KEY();
2364 mimeview_save_as(mimeview
);
2367 BREAK_ON_MODIFIER_KEY();
2368 mimeview_display_as_text(mimeview
);
2371 BREAK_ON_MODIFIER_KEY();
2372 mimeview_launch(mimeview
, NULL
);
2376 BREAK_ON_MODIFIER_KEY();
2377 mimeview_open_with(mimeview
);
2381 BREAK_ON_MODIFIER_KEY();
2382 mimeview_check_signature(mimeview
);
2385 BREAK_ON_MODIFIER_KEY();
2386 mimeview_select_next_part(mimeview
);
2392 if (!mimeview
->messageview
->mainwin
) return FALSE
;
2393 summaryview
= mimeview
->messageview
->mainwin
->summaryview
;
2394 return summary_pass_key_press_event(summaryview
, event
);
2397 static gboolean
icon_popup_menu(GtkWidget
*widget
, gpointer data
)
2399 MimeView
*mimeview
= (MimeView
*)data
;
2400 MimeInfo
*partinfo
= g_object_get_data(G_OBJECT(widget
), "partinfo");
2402 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
2403 "pop_partinfo", partinfo
);
2404 gtk_menu_popup(GTK_MENU(mimeview
->popupmenu
),
2405 NULL
, NULL
, NULL
, NULL
,
2406 0, gtk_get_current_event_time());
2410 static void icon_list_append_icon (MimeView
*mimeview
, MimeInfo
*mimeinfo
)
2412 GtkWidget
*pixmap
= NULL
;
2417 const gchar
*desc
= NULL
;
2418 gchar
*sigshort
= NULL
;
2419 gchar
*content_type
;
2422 MimeInfo
*siginfo
= NULL
;
2423 MimeInfo
*encrypted
= NULL
;
2428 if (!prefs_common
.show_inline_attachments
&& mimeinfo
->id
)
2431 vbox
= mimeview
->icon_vbox
;
2432 mimeview
->icon_count
++;
2433 button
= gtk_event_box_new();
2435 g_signal_connect(G_OBJECT(button
), "motion-notify-event",
2436 G_CALLBACK(mimeview_visi_notify
), mimeview
);
2437 g_signal_connect(G_OBJECT(button
), "leave-notify-event",
2438 G_CALLBACK(mimeview_leave_notify
), mimeview
);
2439 g_signal_connect(G_OBJECT(button
), "enter-notify-event",
2440 G_CALLBACK(mimeview_enter_notify
), mimeview
);
2442 gtk_container_set_border_width(GTK_CONTAINER(button
), 2);
2443 g_object_set_data(G_OBJECT(button
), "icon_number",
2444 GINT_TO_POINTER(mimeview
->icon_count
));
2445 g_object_set_data(G_OBJECT(button
), "partinfo",
2448 switch (mimeinfo
->type
) {
2451 if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "html"))
2452 stockp
= STOCK_PIXMAP_MIME_TEXT_HTML
;
2453 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "enriched"))
2454 stockp
= STOCK_PIXMAP_MIME_TEXT_ENRICHED
;
2455 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "calendar"))
2456 stockp
= STOCK_PIXMAP_MIME_TEXT_CALENDAR
;
2457 else if (mimeinfo
->subtype
&& (!g_ascii_strcasecmp(mimeinfo
->subtype
, "x-patch")
2458 || !g_ascii_strcasecmp(mimeinfo
->subtype
, "x-diff")))
2459 stockp
= STOCK_PIXMAP_MIME_TEXT_PATCH
;
2461 stockp
= STOCK_PIXMAP_MIME_TEXT_PLAIN
;
2463 case MIMETYPE_MESSAGE
:
2464 stockp
= STOCK_PIXMAP_MIME_MESSAGE
;
2466 case MIMETYPE_APPLICATION
:
2467 if (mimeinfo
->subtype
&& (!g_ascii_strcasecmp(mimeinfo
->subtype
, "pgp-signature")
2468 || !g_ascii_strcasecmp(mimeinfo
->subtype
, "x-pkcs7-signature")
2469 || !g_ascii_strcasecmp(mimeinfo
->subtype
, "pkcs7-signature")))
2470 stockp
= STOCK_PIXMAP_MIME_PGP_SIG
;
2471 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "pdf"))
2472 stockp
= STOCK_PIXMAP_MIME_PDF
;
2473 else if (mimeinfo
->subtype
&& !g_ascii_strcasecmp(mimeinfo
->subtype
, "postscript"))
2474 stockp
= STOCK_PIXMAP_MIME_PS
;
2476 stockp
= STOCK_PIXMAP_MIME_APPLICATION
;
2478 case MIMETYPE_IMAGE
:
2479 stockp
= STOCK_PIXMAP_MIME_IMAGE
;
2481 case MIMETYPE_AUDIO
:
2482 stockp
= STOCK_PIXMAP_MIME_AUDIO
;
2485 stockp
= STOCK_PIXMAP_MIME_UNKNOWN
;
2489 partinfo
= mimeinfo
;
2490 while (partinfo
!= NULL
) {
2491 if (privacy_mimeinfo_is_signed(partinfo
)) {
2495 if (privacy_mimeinfo_is_encrypted(partinfo
)) {
2496 encrypted
= partinfo
;
2499 partinfo
= procmime_mimeinfo_parent(partinfo
);
2502 if (siginfo
!= NULL
) {
2503 switch (privacy_mimeinfo_get_sig_status(siginfo
)) {
2504 case SIGNATURE_UNCHECKED
:
2505 case SIGNATURE_CHECK_FAILED
:
2506 case SIGNATURE_CHECK_TIMEOUT
:
2507 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2508 STOCK_PIXMAP_PRIVACY_EMBLEM_SIGNED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2511 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2512 STOCK_PIXMAP_PRIVACY_EMBLEM_PASSED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2514 case SIGNATURE_WARN
:
2515 case SIGNATURE_KEY_EXPIRED
:
2516 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2517 STOCK_PIXMAP_PRIVACY_EMBLEM_WARN
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2519 case SIGNATURE_INVALID
:
2520 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2521 STOCK_PIXMAP_PRIVACY_EMBLEM_FAILED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2524 sigshort
= privacy_mimeinfo_sig_info_short(siginfo
);
2525 } else if (encrypted
!= NULL
) {
2526 pixmap
= stock_pixmap_widget_with_overlay(stockp
,
2527 STOCK_PIXMAP_PRIVACY_EMBLEM_ENCRYPTED
, OVERLAY_BOTTOM_RIGHT
, 6, 3);
2529 pixmap
= stock_pixmap_widget_with_overlay(stockp
, 0,
2530 OVERLAY_NONE
, 6, 3);
2532 gtk_container_add(GTK_CONTAINER(button
), pixmap
);
2534 if (prefs_common
.attach_desc
)
2535 desc
= get_part_description(mimeinfo
);
2537 desc
= get_part_name(mimeinfo
);
2540 content_type
= procmime_get_content_type_str(mimeinfo
->type
,
2543 tip
= g_strconcat("<b>", _("Type:"), " </b>", content_type
,
2544 "\n<b>", _("Size:"), " </b>",
2545 to_human_readable((goffset
)mimeinfo
->length
), NULL
);
2546 g_free(content_type
);
2547 if (desc
&& *desc
) {
2548 gchar
*tmp
= NULL
, *escaped
= NULL
;
2549 if (!g_utf8_validate(desc
, -1, NULL
)) {
2550 tmp
= conv_filename_to_utf8(desc
);
2552 tmp
= g_strdup(desc
);
2554 escaped
= g_markup_escape_text(tmp
,-1);
2556 tiptmp
= g_strconcat(tip
, "\n<b>",
2557 prefs_common
.attach_desc
&& mimeinfo
->description
?
2558 _("Description:") : _("Filename:"),
2559 " </b>", escaped
, NULL
);
2565 if (sigshort
&& *sigshort
) {
2566 tiptmp
= g_strjoin("\n", tip
, g_markup_escape_text(sigshort
, -1), NULL
);
2572 gtk_widget_set_tooltip_markup(button
, tip
);
2574 gtk_widget_show_all(button
);
2575 gtk_drag_source_set(button
, GDK_BUTTON1_MASK
|GDK_BUTTON3_MASK
,
2576 mimeview_mime_types
, 1, GDK_ACTION_COPY
);
2578 g_signal_connect(G_OBJECT(button
), "popup-menu",
2579 G_CALLBACK(icon_popup_menu
), mimeview
);
2580 g_signal_connect(G_OBJECT(button
), "button_release_event",
2581 G_CALLBACK(icon_clicked_cb
), mimeview
);
2582 g_signal_connect(G_OBJECT(button
), "key_press_event",
2583 G_CALLBACK(icon_key_pressed
), mimeview
);
2584 g_signal_connect(G_OBJECT(button
), "drag_data_get",
2585 G_CALLBACK(mimeview_drag_data_get
), mimeview
);
2586 gtk_box_pack_start(GTK_BOX(vbox
), button
, FALSE
, FALSE
, 0);
2588 gtk_widget_size_request(pixmap
, &r
);
2589 gtk_widget_set_size_request(button
, -1, r
.height
+ 4);
2594 static void icon_list_clear (MimeView
*mimeview
)
2596 GList
*child
, *orig
;
2599 orig
= gtk_container_get_children(GTK_CONTAINER(mimeview
->icon_vbox
));
2600 for (child
= orig
; child
!= NULL
; child
= g_list_next(child
)) {
2601 gtkut_container_remove(GTK_CONTAINER(mimeview
->icon_vbox
),
2602 GTK_WIDGET(child
->data
));
2605 mimeview
->icon_count
= 0;
2606 adj
= gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview
->icon_scroll
));
2607 gtk_adjustment_set_value(adj
, gtk_adjustment_get_lower(adj
));
2608 gtk_adjustment_changed(adj
);
2612 *\brief Used to 'click' the next or previous icon.
2614 *\return true if the icon 'number' exists and was selected.
2616 static void icon_scroll_size_allocate_cb(GtkWidget
*widget
,
2617 GtkAllocation
*size
, MimeView
*mimeview
)
2619 GtkAllocation vbox_size
;
2620 GtkAllocation layout_size
;
2625 adj
= gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview
->icon_scroll
));
2627 gtk_widget_get_allocation(mimeview
->icon_vbox
, &vbox_size
);
2628 gtk_widget_get_allocation(mimeview
->icon_scroll
, &layout_size
);
2630 gtk_layout_get_size(GTK_LAYOUT(mimeview
->icon_scroll
), &width
, &height
);
2631 gtk_layout_set_size(GTK_LAYOUT(mimeview
->icon_scroll
),
2633 MAX(vbox_size
.height
, layout_size
.height
));
2634 gtk_adjustment_set_step_increment(adj
, 10);
2637 static void icon_list_create(MimeView
*mimeview
, MimeInfo
*mimeinfo
)
2639 GtkRequisition size
;
2640 GtkRequisition requisition
;
2642 cm_return_if_fail(mimeinfo
!= NULL
);
2644 while (mimeinfo
!= NULL
) {
2645 if (mimeinfo
->type
!= MIMETYPE_MULTIPART
)
2646 icon_list_append_icon(mimeview
, mimeinfo
);
2647 if (mimeinfo
->node
->children
!= NULL
)
2648 icon_list_create(mimeview
,
2649 (MimeInfo
*) mimeinfo
->node
->children
->data
);
2650 mimeinfo
= mimeinfo
->node
->next
!= NULL
2651 ? (MimeInfo
*) mimeinfo
->node
->next
->data
2654 gtk_widget_size_request(mimeview
->icon_vbox
, &size
);
2655 gtk_widget_get_requisition(mimeview
->icon_mainbox
, &requisition
);
2656 if (size
.width
> requisition
.width
) {
2657 gtk_widget_set_size_request(mimeview
->icon_mainbox
,
2660 if (mimeview
->opened
)
2661 icon_list_toggle_by_mime_info(mimeview
,
2662 mimeview_get_node_part(mimeview
, mimeview
->opened
));
2665 static void icon_list_toggle_by_mime_info (MimeView
*mimeview
,
2668 GList
*children
, *child
;
2670 children
= gtk_container_get_children(GTK_CONTAINER(mimeview
->icon_vbox
));
2671 for (child
= children
; child
!= NULL
; child
= g_list_next(child
)) {
2672 gboolean
*highlight
= NULL
;
2673 GtkWidget
*icon
= gtk_bin_get_child(GTK_BIN(child
->data
));
2675 if (!GTK_IS_EVENT_BOX(child
->data
))
2678 highlight
= g_object_get_data(G_OBJECT(icon
), "highlight");
2679 *highlight
= (g_object_get_data(G_OBJECT(child
->data
),
2680 "partinfo") == (gpointer
)mimeinfo
);
2682 gtk_widget_queue_draw(icon
);
2684 g_list_free(children
);
2687 static void ctree_size_allocate_cb(GtkWidget
*widget
, GtkAllocation
*allocation
,
2690 prefs_common
.mimeview_tree_height
= allocation
->height
;
2693 static gint
mime_toggle_button_cb(GtkWidget
*button
, GdkEventButton
*event
,
2696 g_object_ref(button
);
2698 mimeview_leave_notify(button
, NULL
, NULL
);
2700 mimeview
->ctree_mode
= !mimeview
->ctree_mode
;
2701 if (mimeview
->ctree_mode
) {
2702 gtk_arrow_set(GTK_ARROW(gtk_bin_get_child(GTK_BIN((button
)))), GTK_ARROW_RIGHT
,
2704 gtk_widget_hide(mimeview
->icon_mainbox
);
2705 gtk_widget_show(mimeview
->ctree_mainbox
);
2706 gtk_paned_set_position(GTK_PANED(mimeview
->paned
),
2707 prefs_common
.mimeview_tree_height
);
2709 gtkut_container_remove(GTK_CONTAINER(mimeview
->icon_mainbox
),
2711 gtk_box_pack_end(GTK_BOX(mimeview
->ctree_mainbox
),
2712 button
, FALSE
, FALSE
, 0);
2714 gtk_arrow_set(GTK_ARROW(gtk_bin_get_child(GTK_BIN((button
)))), GTK_ARROW_LEFT
,
2716 gtk_widget_hide(mimeview
->ctree_mainbox
);
2717 gtk_widget_show(mimeview
->icon_mainbox
);
2718 gtk_paned_set_position(GTK_PANED(mimeview
->paned
), 0);
2720 gtkut_container_remove(GTK_CONTAINER(mimeview
->ctree_mainbox
),
2722 gtk_box_pack_start(GTK_BOX(mimeview
->icon_mainbox
),
2723 button
, FALSE
, FALSE
, 0);
2724 gtk_box_reorder_child(GTK_BOX(gtk_widget_get_parent(button
)), button
, 0);
2725 if (mimeview
->opened
)
2726 icon_list_toggle_by_mime_info(mimeview
,
2727 mimeview_get_node_part(mimeview
, mimeview
->opened
));
2728 summary_grab_focus(mimeview
->mainwin
->summaryview
);
2730 g_object_unref(button
);
2734 void mimeview_update (MimeView
*mimeview
)
2736 if (mimeview
&& mimeview
->mimeinfo
) {
2737 icon_list_clear(mimeview
);
2738 icon_list_create(mimeview
, mimeview
->mimeinfo
);
2742 void mimeview_handle_cmd(MimeView
*mimeview
, const gchar
*cmd
, GdkEventButton
*event
, gpointer data
)
2744 MessageView
*msgview
= NULL
;
2745 MainWindow
*mainwin
= NULL
;
2750 msgview
= mimeview
->messageview
;
2754 mainwin
= msgview
->mainwin
;
2758 g_object_set_data(G_OBJECT(mimeview
->popupmenu
),
2759 "pop_partinfo", NULL
);
2761 if (!strcmp(cmd
, "sc://view_log"))
2762 log_window_show(mainwin
->logwin
);
2763 else if (!strcmp(cmd
, "sc://save_as"))
2764 mimeview_save_as(mimeview
);
2765 else if (!strcmp(cmd
, "sc://display_as_text"))
2766 mimeview_display_as_text(mimeview
);
2768 else if (!strcmp(cmd
, "sc://open_with"))
2769 mimeview_open_with(mimeview
);
2771 else if (!strcmp(cmd
, "sc://open"))
2772 mimeview_launch(mimeview
, NULL
);
2773 else if (!strcmp(cmd
, "sc://select_attachment") && data
!= NULL
) {
2774 icon_list_toggle_by_mime_info(mimeview
, (MimeInfo
*)data
);
2775 icon_selected(mimeview
, -1, (MimeInfo
*)data
);
2776 } else if (!strcmp(cmd
, "sc://open_attachment") && data
!= NULL
) {
2777 mimeview_launch(mimeview
, (MimeInfo
*)data
);
2778 } else if (!strcmp(cmd
, "sc://menu_attachment") && data
!= NULL
) {
2779 mimeview
->spec_part
= (MimeInfo
*)data
;
2780 part_button_pressed(mimeview
, event
, (MimeInfo
*)data
);
2781 } else if (!strncmp(cmd
, "sc://search_tags:", strlen("sc://search_tags:"))) {
2782 const gchar
*tagname
= cmd
+ strlen("sc://search_tags:");
2783 gchar
*buf
= g_strdup_printf("tag matchcase \"%s\"", tagname
);
2784 gtk_toggle_button_set_active(
2785 GTK_TOGGLE_BUTTON(mimeview
->messageview
->mainwin
->summaryview
->toggle_search
),
2787 quicksearch_set(mimeview
->messageview
->mainwin
->summaryview
->quicksearch
,
2788 ADVANCED_SEARCH_EXTENDED
, buf
);
2793 gboolean
mimeview_scroll_page(MimeView
*mimeview
, gboolean up
)
2795 if (mimeview
->type
== MIMEVIEW_TEXT
)
2796 return textview_scroll_page(mimeview
->textview
, up
);
2797 else if (mimeview
->mimeviewer
) {
2798 MimeViewer
*mimeviewer
= mimeview
->mimeviewer
;
2799 if (mimeviewer
->scroll_page
)
2800 return mimeviewer
->scroll_page(mimeviewer
, up
);
2805 void mimeview_scroll_one_line(MimeView
*mimeview
, gboolean up
)
2807 if (mimeview
->type
== MIMEVIEW_TEXT
)
2808 textview_scroll_one_line(mimeview
->textview
, up
);
2809 else if (mimeview
->mimeviewer
) {
2810 MimeViewer
*mimeviewer
= mimeview
->mimeviewer
;
2811 if (mimeviewer
->scroll_one_line
)
2812 mimeviewer
->scroll_one_line(mimeviewer
, up
);