2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 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.
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkvbox.h>
26 #include <gtk/gtkcontainer.h>
27 #include <gtk/gtkwindow.h>
28 #include <gtk/gtktext.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
36 #include "messageview.h"
37 #include "message_search.h"
38 #include "headerview.h"
39 #include "summaryview.h"
45 #include "sourcewindow.h"
46 #include "addressbook.h"
47 #include "alertpanel.h"
48 #include "inputdialog.h"
49 #include "manage_window.h"
51 #include "procheader.h"
55 #include "prefs_common.h"
56 #include "prefs_account.h"
59 #include "send_message.h"
60 #include "stock_pixmap.h"
62 #include "filtering.h"
63 #include "partial_download.h"
65 static GList *messageview_list = NULL;
67 static gint messageview_delete_cb (GtkWidget *widget,
69 MessageView *messageview);
70 static void messageview_size_allocate_cb(GtkWidget *widget,
71 GtkAllocation *allocation);
72 static gboolean key_pressed (GtkWidget *widget,
74 MessageView *messageview);
76 static void return_receipt_show (NoticeView *noticeview,
78 static void return_receipt_send_clicked (NoticeView *noticeview,
80 static void partial_recv_show (NoticeView *noticeview,
82 static void partial_recv_dload_clicked (NoticeView *noticeview,
84 static void partial_recv_del_clicked (NoticeView *noticeview,
86 static void partial_recv_unmark_clicked (NoticeView *noticeview,
88 static void save_as_cb (gpointer data,
91 static void print_cb (gpointer data,
94 static void close_cb (gpointer data,
97 static void copy_cb (gpointer data,
100 static void allsel_cb (gpointer data,
103 static void search_cb (gpointer data,
107 static void set_charset_cb (gpointer data,
110 static void set_decode_cb (gpointer data,
113 static void view_source_cb (gpointer data,
116 static void show_all_header_cb (gpointer data,
120 static void compose_cb (gpointer data,
123 static void reply_cb (gpointer data,
126 static void reedit_cb (gpointer data,
130 static PrefsAccount *select_account_from_list
132 static void addressbook_open_cb (gpointer data,
135 static void add_address_cb (gpointer data,
138 static void create_filter_cb (gpointer data,
141 static void create_processing_cb (gpointer data,
145 static void about_cb (gpointer data,
148 static void messageview_update (MessageView *msgview);
149 static gboolean messageview_update_msg (gpointer source, gpointer data);
151 static GList *msgview_list = NULL;
152 static GtkItemFactoryEntry msgview_entries[] =
154 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
155 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
156 {N_("/_File/_Print..."), NULL, print_cb, 0, NULL},
157 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
158 {N_("/_File/_Close"), NULL, close_cb, 0, NULL},
160 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
161 {N_("/_Edit/_Copy"), NULL, copy_cb, 0, NULL},
162 {N_("/_Edit/Select _all"), NULL, allsel_cb, 0, NULL},
163 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
164 {N_("/_Edit/_Find in current message..."),
165 NULL, search_cb, 0, NULL},
167 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
169 #define ENC_SEPARATOR \
170 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
171 #define ENC_ACTION(action) \
172 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
174 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
175 {N_("/_View/Character _encoding/_Auto detect"),
176 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
178 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
179 ENC_ACTION(C_US_ASCII)},
181 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
182 ENC_ACTION(C_UTF_8)},
184 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
185 ENC_ACTION(C_ISO_8859_1)},
186 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
187 ENC_ACTION(C_ISO_8859_15)},
189 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
190 ENC_ACTION(C_ISO_8859_2)},
192 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
193 ENC_ACTION(C_ISO_8859_13)},
194 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
195 ENC_ACTION(C_ISO_8859_4)},
197 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
198 ENC_ACTION(C_ISO_8859_7)},
200 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
201 ENC_ACTION(C_ISO_8859_8)},
202 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
203 ENC_ACTION(C_CP1255)},
205 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
206 ENC_ACTION(C_ISO_8859_9)},
208 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
209 ENC_ACTION(C_ISO_8859_5)},
210 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
211 ENC_ACTION(C_KOI8_R)},
212 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
213 ENC_ACTION(C_KOI8_U)},
214 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
215 ENC_ACTION(C_CP1251)},
217 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
218 ENC_ACTION(C_ISO_2022_JP)},
219 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
220 ENC_ACTION(C_ISO_2022_JP_2)},
221 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
222 ENC_ACTION(C_EUC_JP)},
223 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
224 ENC_ACTION(C_SHIFT_JIS)},
226 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
227 ENC_ACTION(C_GB2312)},
228 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
230 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
232 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
233 ENC_ACTION(C_EUC_TW)},
234 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
235 ENC_ACTION(C_ISO_2022_CN)},
237 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
238 ENC_ACTION(C_EUC_KR)},
239 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
240 ENC_ACTION(C_ISO_2022_KR)},
242 {N_("/_View/Character _encoding/Thai (TIS-620)"),
243 ENC_ACTION(C_TIS_620)},
244 {N_("/_View/Character _encoding/Thai (Windows-874)"),
245 ENC_ACTION(C_WINDOWS_874)},
250 #define DEC_SEPARATOR \
251 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
252 #define DEC_ACTION(action) \
253 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
254 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
255 {N_("/_View/Decode/_Auto detect"),
256 NULL, set_decode_cb, 0, "<RadioItem>"},
257 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
258 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
259 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
260 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
261 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
266 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
267 {N_("/_View/Mess_age source"), NULL, view_source_cb, 0, NULL},
268 {N_("/_View/Show all _headers"),NULL, show_all_header_cb, 0, "<ToggleItem>"},
270 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
271 {N_("/_Message/Compose _new message"),
272 NULL, compose_cb, 0, NULL},
273 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
274 {N_("/_Message/_Reply"), NULL, reply_cb, COMPOSE_REPLY, NULL},
275 {N_("/_Message/Repl_y to/_all"),
276 NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
277 {N_("/_Message/Repl_y to/_sender"),
278 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
279 {N_("/_Message/Repl_y to/mailing _list"),
280 NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
281 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
282 {N_("/_Message/_Forward"), NULL, reply_cb, COMPOSE_FORWARD, NULL},
283 {N_("/_Message/For_ward as attachment"),
284 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
285 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
286 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
287 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
289 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
290 {N_("/_Tools/_Address book"), NULL, addressbook_open_cb, 0, NULL},
291 {N_("/_Tools/Add sender to address boo_k"),
292 NULL, add_address_cb, 0, NULL},
293 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
294 {N_("/_Tools/_Create filter rule"),
295 NULL, NULL, 0, "<Branch>"},
296 {N_("/_Tools/_Create filter rule/_Automatically"),
297 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
298 {N_("/_Tools/_Create filter rule/by _From"),
299 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
300 {N_("/_Tools/_Create filter rule/by _To"),
301 NULL, create_filter_cb, FILTER_BY_TO, NULL},
302 {N_("/_Tools/_Create filter rule/by _Subject"),
303 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
304 {N_("/_Tools/Create processing rule"),
305 NULL, NULL, 0, "<Branch>"},
306 {N_("/_Tools/Create processing rule/_Automatically"),
307 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
308 {N_("/_Tools/Create processing rule/by _From"),
309 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
310 {N_("/_Tools/Create processing rule/by _To"),
311 NULL, create_processing_cb, FILTER_BY_TO, NULL},
312 {N_("/_Tools/Create processing rule/by _Subject"),
313 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
314 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
315 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
317 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
318 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
321 MessageView *messageview_create(MainWindow *mainwin)
323 MessageView *messageview;
325 HeaderView *headerview;
327 NoticeView *noticeview;
329 debug_print("Creating message view...\n");
330 messageview = g_new0(MessageView, 1);
332 headerview = headerview_create();
334 noticeview = noticeview_create(mainwin);
336 mimeview = mimeview_create(mainwin);
337 mimeview->textview = textview_create();
338 mimeview->textview->messageview = messageview;
339 mimeview->messageview = messageview;
341 vbox = gtk_vbox_new(FALSE, 0);
342 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
344 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
346 gtk_box_pack_start(GTK_BOX(vbox),
347 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
348 gtk_widget_show(vbox);
350 messageview->vbox = vbox;
351 messageview->new_window = FALSE;
352 messageview->window = NULL;
353 messageview->headerview = headerview;
354 messageview->mimeview = mimeview;
355 messageview->noticeview = noticeview;
356 messageview->mainwin = mainwin;
358 messageview->statusbar = NULL;
359 messageview->statusbar_cid = 0;
361 messageview->msginfo_update_callback_id =
362 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
367 GList *messageview_get_msgview_list(void)
372 void messageview_update_actions_menu(MessageView *msgview)
374 GtkItemFactory *ifactory;
376 /* Messages opened in a new window do not have a menu bar */
377 if (msgview->menubar == NULL)
379 ifactory = gtk_item_factory_from_widget(msgview->menubar);
380 action_update_msgview_menu(ifactory, "/Tools/Actions", msgview);
383 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
385 GtkWidget *handlebox;
388 GtkWidget *statusbar;
389 guint n_menu_entries;
391 vbox = gtk_vbox_new(FALSE, 0);
392 gtk_widget_show(vbox);
393 gtk_container_add(GTK_CONTAINER(window), vbox);
395 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
396 menubar = menubar_create(window, msgview_entries,
397 n_menu_entries, "<MessageView>", msgview);
398 gtk_widget_show(menubar);
399 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
401 handlebox = gtk_handle_box_new();
402 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
403 gtk_widget_realize(handlebox);
404 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
407 statusbar = gtk_statusbar_new();
408 gtk_widget_show(statusbar);
409 gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
410 msgview->statusbar = statusbar;
411 msgview->statusbar_cid = gtk_statusbar_get_context_id
412 (GTK_STATUSBAR(statusbar), "Message View");
414 msgview->handlebox = handlebox;
415 msgview->menubar = menubar;
417 gtk_container_add(GTK_CONTAINER(vbox),
418 GTK_WIDGET_PTR(msgview));
420 messageview_update_actions_menu(msgview);
422 msgview_list = g_list_append(msgview_list, msgview);
425 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
427 MessageView *msgview;
429 static GdkGeometry geometry;
431 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
432 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
433 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
435 if (!geometry.min_height) {
436 geometry.min_width = 320;
437 geometry.min_height = 200;
439 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
442 gtk_widget_set_size_request(window, prefs_common.msgwin_width,
443 prefs_common.msgwin_height);
445 msgview = messageview_create(mainwin);
447 g_signal_connect(G_OBJECT(window), "size_allocate",
448 G_CALLBACK(messageview_size_allocate_cb),
450 g_signal_connect(G_OBJECT(window), "delete_event",
451 G_CALLBACK(messageview_delete_cb), msgview);
452 g_signal_connect(G_OBJECT(window), "key_press_event",
453 G_CALLBACK(key_pressed), msgview);
455 messageview_add_toolbar(msgview, window);
457 gtk_widget_grab_focus(msgview->mimeview->textview->text);
458 gtk_widget_show(window);
460 msgview->new_window = TRUE;
461 msgview->window = window;
462 msgview->visible = TRUE;
464 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
465 prefs_common.toolbar_style);
466 messageview_init(msgview);
471 void messageview_init(MessageView *messageview)
473 headerview_init(messageview->headerview);
474 mimeview_init(messageview->mimeview);
475 /*messageview_set_font(messageview);*/
477 noticeview_hide(messageview->noticeview);
480 static void notification_convert_header(gchar *dest, gint len,
486 g_return_if_fail(src_ != NULL);
487 g_return_if_fail(dest != NULL);
491 Xstrndup_a(src, src_, len, return);
495 if (is_ascii_str(src)) {
496 strncpy2(dest, src, len);
497 dest[len - 1] = '\0';
500 conv_encode_header(dest, len, src, header_len, FALSE);
503 static gint disposition_notification_send(MsgInfo *msginfo)
506 gchar tmp[MAXPATHLEN + 1];
509 PrefsAccount *account = NULL;
512 FolderItem *queue, *outbox;
518 if ((!msginfo->returnreceiptto) &&
519 (!msginfo->dispositionnotificationto))
522 /* RFC2298: Test for Return-Path */
523 if (msginfo->dispositionnotificationto)
524 to = msginfo->dispositionnotificationto;
526 to = msginfo->returnreceiptto;
528 ok = procheader_get_header_from_msginfo(msginfo, buf, sizeof(buf),
531 gchar *to_addr = g_strdup(to);
532 extract_address(to_addr);
533 extract_address(buf);
534 ok = strcmp(to_addr, buf);
537 strncpy(buf, _("<No Return-Path found>"),
544 message = g_strdup_printf(
545 _("The notification address to which the "
546 "return receipt is to be sent\n"
547 "does not correspond to the return path:\n"
548 "Notification address: %s\n"
550 "It is advised to not to send the return "
551 "receipt."), to, buf);
552 val = alertpanel_with_type(_("Warning"), message, _("Send"),
553 _("+Don't Send"), NULL, NULL, ALERT_WARNING);
555 if (val != G_ALERTDEFAULT)
559 ac_list = account_find_all_from_address(NULL, msginfo->to);
560 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
562 if (ac_list == NULL) {
564 alertpanel_with_type(_("Warning"),
565 _("This message is asking for a return "
566 "receipt notification\n"
567 "but according to its 'To:' and 'CC:' "
568 "headers it was not\nofficially addressed "
570 "It is advised to not to send the return ."
572 _("Send"), _("+Don't Send"), NULL,
573 NULL, ALERT_WARNING);
574 if (val != G_ALERTDEFAULT)
578 if (g_list_length(ac_list) > 1)
579 account = select_account_from_list(ac_list);
580 else if (ac_list != NULL)
581 account = (PrefsAccount *) ac_list->data;
582 g_list_free(ac_list);
585 account = account_get_default();
586 if (!account || account->protocol == A_NNTP) {
587 alertpanel_error(_("Account for sending mail is not specified.\n"
588 "Please select a mail account before sending."));
592 /* write to temporary file */
593 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
594 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
596 if ((fp = fopen(tmp, "wb")) == NULL) {
597 FILE_OP_ERROR(tmp, "fopen");
601 /* chmod for security */
602 if (change_file_mode_rw(fp, tmp) < 0) {
603 FILE_OP_ERROR(tmp, "chmod");
604 g_warning("can't change file mode\n");
609 extract_address(addr);
612 /* write queue headers */
613 fprintf(fp, "AF:\n");
614 fprintf(fp, "NF:0\n");
615 fprintf(fp, "PS:10\n");
616 fprintf(fp, "SRH:1\n");
617 fprintf(fp, "SFN:\n");
618 fprintf(fp, "DSR:\n");
619 fprintf(fp, "MID:\n");
620 fprintf(fp, "CFG:\n");
621 fprintf(fp, "PT:0\n");
622 fprintf(fp, "S:%s\n", account->address);
623 fprintf(fp, "RQ:\n");
624 if (account->smtp_server)
625 fprintf(fp, "SSV:%s\n", account->smtp_server);
627 fprintf(fp, "SSV:\n");
628 fprintf(fp, "SSH:\n");
629 fprintf(fp, "R:<%s>\n", addrp);
633 /* check whether we need to save the message */
634 outbox = account_get_special_folder(account, F_OUTBOX);
635 if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
638 path = folder_item_get_identifier(outbox);
639 fprintf(fp, "SCF:%s\n", path);
646 get_rfc822_date(buf, sizeof(buf));
647 fprintf(fp, "Date: %s\n", buf);
650 if (account->name && *account->name) {
651 notification_convert_header
652 (buf, sizeof(buf), account->name,
654 fprintf(fp, "From: %s <%s>\n", buf, account->address);
656 fprintf(fp, "From: %s\n", account->address);
658 fprintf(fp, "To: %s\n", to);
661 notification_convert_header(buf, sizeof(buf), msginfo->subject,
662 strlen("Subject: "));
663 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
666 generate_msgid(buf, sizeof(buf));
667 fprintf(fp, "Message-ID: <%s>\n", buf);
669 if (fclose(fp) == EOF) {
670 FILE_OP_ERROR(tmp, "fclose");
675 /* put it in queue */
676 queue = account_get_special_folder(account, F_QUEUE);
677 if (!queue) queue = folder_get_default_queue();
679 g_warning("can't find queue folder\n");
683 folder_item_scan(queue);
684 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
685 g_warning("can't queue the message\n");
690 if (prefs_common.work_offline)
691 if (alertpanel(_("Offline warning"),
692 _("You're working offline. Override?"),
693 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
697 path = folder_item_fetch_msg(queue, num);
698 ok = procmsg_send_message_queue(path);
700 folder_item_remove_msg(queue, num);
705 GList *messageview_get_window_list(void)
707 return messageview_list;
710 static gboolean find_encrypted_func(GNode *node, gpointer data)
712 MimeInfo *mimeinfo = (MimeInfo *) node->data;
713 MimeInfo **encinfo = (MimeInfo **) data;
715 if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
723 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
725 MimeInfo *encinfo = NULL;
727 g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
728 find_encrypted_func, &encinfo);
733 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
734 gboolean all_headers)
737 MimeInfo *mimeinfo, *encinfo;
739 g_return_val_if_fail(msginfo != NULL, -1);
741 mimeinfo = procmime_scan_message(msginfo);
743 textview_show_error(messageview->mimeview->textview);
747 while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
748 debug_print("decrypting message part\n");
749 if (privacy_mimeinfo_decrypt(encinfo) < 0)
753 file = procmsg_get_message_file_path(msginfo);
755 g_warning("can't get message file path.\n");
756 procmime_mimeinfo_free_all(mimeinfo);
757 textview_show_error(messageview->mimeview->textview);
761 if (messageview->msginfo != msginfo) {
762 procmsg_msginfo_free(messageview->msginfo);
763 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
764 if (!messageview->msginfo)
765 messageview->msginfo = procmsg_msginfo_copy(msginfo);
767 headerview_show(messageview->headerview, messageview->msginfo);
769 textview_set_all_headers(messageview->mimeview->textview,
770 messageview->all_headers);
772 mimeview_show_message(messageview->mimeview, mimeinfo, file);
773 messageview_set_position(messageview, 0);
775 if (messageview->msginfo->partial_recv)
776 partial_recv_show(messageview->noticeview,
777 messageview->msginfo);
778 else if ((messageview->msginfo->dispositionnotificationto ||
779 messageview->msginfo->returnreceiptto) &&
780 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags))
781 return_receipt_show(messageview->noticeview,
782 messageview->msginfo);
784 noticeview_hide(messageview->noticeview);
786 mimeinfo = procmime_mimeinfo_next(mimeinfo);
787 if (mimeinfo && (mimeinfo->type != MIMETYPE_TEXT ||
788 (strcmp(mimeinfo->subtype, "plain") &&
789 strcmp(mimeinfo->subtype, "html")))) {
790 mimeview_show_part(messageview->mimeview,mimeinfo);
798 void messageview_reflect_prefs_pixmap_theme(void)
801 MessageView *msgview;
803 for (cur = msgview_list; cur != NULL; cur = cur->next) {
804 msgview = (MessageView*)cur->data;
805 toolbar_update(TOOLBAR_MSGVIEW, msgview);
806 mimeview_update(msgview->mimeview);
810 void messageview_clear(MessageView *messageview)
812 procmsg_msginfo_free(messageview->msginfo);
813 messageview->msginfo = NULL;
814 messageview->filtered = FALSE;
815 mimeview_clear(messageview->mimeview);
816 headerview_clear(messageview->headerview);
817 noticeview_hide(messageview->noticeview);
820 void messageview_destroy(MessageView *messageview)
822 debug_print("destroy messageview\n");
823 messageview_list = g_list_remove(messageview_list, messageview);
825 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
826 messageview->msginfo_update_callback_id);
828 headerview_destroy(messageview->headerview);
829 mimeview_destroy(messageview->mimeview);
830 noticeview_destroy(messageview->noticeview);
832 procmsg_msginfo_free(messageview->msginfo);
833 toolbar_clear_list(TOOLBAR_MSGVIEW);
834 if (messageview->toolbar) {
835 toolbar_destroy(messageview->toolbar);
836 g_free(messageview->toolbar);
839 msgview_list = g_list_remove(msgview_list, messageview);
841 if (messageview->window)
842 gtk_widget_destroy(messageview->window);
846 void messageview_delete(MessageView *msgview)
848 MsgInfo *msginfo = NULL;
849 FolderItem *trash = NULL;
850 PrefsAccount *ac = NULL;
852 if (msgview->msginfo && msgview->mainwin && msgview->mainwin->summaryview)
853 msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
855 /* need a procmsg_msginfo_equal() */
856 if (msginfo && msgview->msginfo &&
857 msginfo->msgnum == msgview->msginfo->msgnum &&
858 msginfo->folder == msgview->msginfo->folder) {
859 summary_delete_trash(msgview->mainwin->summaryview);
861 msginfo = msgview->msginfo;
863 g_return_if_fail(msginfo != NULL);
865 /* to get the trash folder, we have to choose either
866 * the folder's or account's trash default - we prefer
867 * the one in the account prefs */
868 if (msginfo->folder) {
869 if (NULL != (ac = account_find_from_item(msginfo->folder)))
870 trash = account_get_special_folder(ac, F_TRASH);
871 if (!trash && msginfo->folder->folder)
872 trash = msginfo->folder->folder->trash;
873 /* if still not found, use the default */
875 trash = folder_get_default_trash();
878 g_return_if_fail(trash != NULL);
880 if (prefs_common.immediate_exec)
881 /* TODO: Delete from trash */
882 folder_item_move_msg(trash, msginfo);
884 procmsg_msginfo_set_to_folder(msginfo, trash);
885 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
886 /* NOTE: does not update to next message in summaryview */
892 * \brief update messageview with currently selected message in summaryview
893 * leave unchanged if summaryview is empty
894 * \param pointer to MessageView
896 static void messageview_update(MessageView *msgview)
898 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
900 g_return_if_fail(summaryview != NULL);
902 if (summaryview->selected) {
903 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
904 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
905 summaryview->selected);
906 g_return_if_fail(msginfo != NULL);
908 messageview_show(msgview, msginfo,
909 msgview->all_headers);
913 void messageview_quote_color_set(void)
917 void messageview_set_font(MessageView *messageview)
921 TextView *messageview_get_current_textview(MessageView *messageview)
923 TextView *text = NULL;
925 text = messageview->mimeview->textview;
930 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
932 return mimeview_get_selected_part(messageview->mimeview);
935 void messageview_copy_clipboard(MessageView *messageview)
939 text = messageview_get_current_textview(messageview);
941 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
942 GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
943 GtkClipboard *clipboard
944 = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
946 gtk_text_buffer_copy_clipboard(buffer, clipboard);
950 void messageview_select_all(MessageView *messageview)
954 text = messageview_get_current_textview(messageview);
956 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
957 GtkTextBuffer *buffer;
958 GtkTextIter start, end;
960 buffer = gtk_text_view_get_buffer(textview);
961 gtk_text_buffer_get_bounds(buffer, &start, &end);
962 gtk_text_buffer_select_range(buffer, &start, &end);
966 void messageview_set_position(MessageView *messageview, gint pos)
970 text = messageview_get_current_textview(messageview);
972 textview_set_position(text, pos);
975 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
980 text = messageview_get_current_textview(messageview);
982 return textview_search_string(text, str, case_sens);
986 gboolean messageview_search_string_backward(MessageView *messageview,
992 text = messageview_get_current_textview(messageview);
994 return textview_search_string_backward(text,
999 gboolean messageview_is_visible(MessageView *messageview)
1001 return messageview->visible;
1004 void messageview_save_as(MessageView *messageview)
1006 gchar *filename = NULL;
1008 gchar *src, *dest, *tmp;
1010 if (!messageview->msginfo) return;
1011 msginfo = messageview->msginfo;
1013 if (msginfo->subject) {
1014 Xstrdup_a(filename, msginfo->subject, return);
1015 subst_for_filename(filename);
1017 dest = filesel_select_file_save(_("Save as"), filename);
1019 if (is_file_exist(dest)) {
1022 aval = alertpanel(_("Overwrite"),
1023 _("Overwrite existing file?"),
1024 GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1025 if (G_ALERTDEFAULT != aval) return;
1028 src = procmsg_get_message_file(msginfo);
1029 if (copy_file(src, dest, TRUE) < 0) {
1030 tmp = g_path_get_basename(dest);
1031 alertpanel_error(_("Can't save the file `%s'."), tmp);
1038 static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
1039 MessageView *messageview)
1041 messageview_destroy(messageview);
1045 static void messageview_size_allocate_cb(GtkWidget *widget,
1046 GtkAllocation *allocation)
1048 g_return_if_fail(allocation != NULL);
1050 prefs_common.msgwin_width = allocation->width;
1051 prefs_common.msgwin_height = allocation->height;
1054 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
1055 MessageView *messageview)
1057 if (event && event->keyval == GDK_Escape && messageview->window) {
1058 messageview_destroy(messageview);
1064 void messageview_toggle_view_real(MessageView *messageview)
1066 MainWindow *mainwin = messageview->mainwin;
1067 union CompositeWin *cwin = &mainwin->win;
1068 GtkWidget *vpaned = NULL;
1069 GtkWidget *container = NULL;
1070 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1072 switch (mainwin->type) {
1074 vpaned = cwin->sep_none.vpaned;
1075 container = cwin->sep_none.hpaned;
1077 case SEPARATE_FOLDER:
1078 vpaned = cwin->sep_folder.vpaned;
1079 container = mainwin->vbox_body;
1081 case SEPARATE_MESSAGE:
1086 if (vpaned->parent != NULL) {
1087 gtk_widget_ref(vpaned);
1088 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1089 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
1090 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
1092 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
1093 gtk_container_add(GTK_CONTAINER(container), vpaned);
1094 gtk_widget_unref(vpaned);
1095 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
1096 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
1100 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1102 noticeview_set_text(noticeview, _("This message asks for a return receipt."));
1103 noticeview_set_button_text(noticeview, _("Send receipt"));
1104 noticeview_set_button_press_callback(noticeview,
1105 G_CALLBACK(return_receipt_send_clicked),
1106 (gpointer) msginfo);
1107 noticeview_show(noticeview);
1110 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1112 MsgInfo *tmpmsginfo;
1115 file = procmsg_get_message_file_path(msginfo);
1117 g_warning("can't get message file path.\n");
1121 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1122 tmpmsginfo->folder = msginfo->folder;
1123 tmpmsginfo->msgnum = msginfo->msgnum;
1125 if (disposition_notification_send(tmpmsginfo) >= 0) {
1126 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1127 noticeview_hide(noticeview);
1130 procmsg_msginfo_free(tmpmsginfo);
1134 static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
1137 gchar *button1 = NULL;
1138 gchar *button2 = NULL;
1139 void *button1_cb = NULL;
1140 void *button2_cb = NULL;
1142 if (!partial_msg_in_uidl_list(msginfo)) {
1143 text = g_strdup_printf(_("This message has been partially "
1144 "retrieved,\nand has been deleted from the "
1147 switch (msginfo->planned_download) {
1148 case POP3_PARTIAL_DLOAD_UNKN:
1149 text = g_strdup_printf(_("This message has been "
1150 "partially retrieved;\nit is %s."),
1152 (off_t)(msginfo->total_size)));
1153 button1 = _("Mark for download");
1154 button2 = _("Mark for deletion");
1155 button1_cb = partial_recv_dload_clicked;
1156 button2_cb = partial_recv_del_clicked;
1158 case POP3_PARTIAL_DLOAD_DLOAD:
1159 text = g_strdup_printf(_("This message has been "
1160 "partially retrieved;\nit is %s and "
1161 "will be downloaded."),
1163 (off_t)(msginfo->total_size)));
1164 button1 = _("Unmark");
1165 button1_cb = partial_recv_unmark_clicked;
1166 button2 = _("Mark for deletion");
1167 button2_cb = partial_recv_del_clicked;
1169 case POP3_PARTIAL_DLOAD_DELE:
1170 text = g_strdup_printf(_("This message has been "
1171 "partially retrieved;\nit is %s and "
1172 "will be deleted."),
1174 (off_t)(msginfo->total_size)));
1175 button1 = _("Mark for download");
1176 button1_cb = partial_recv_dload_clicked;
1177 button2 = _("Unmark");
1178 button2_cb = partial_recv_unmark_clicked;
1185 noticeview_set_text(noticeview, text);
1187 noticeview_set_button_text(noticeview, button1);
1188 noticeview_set_button_press_callback(noticeview,
1189 G_CALLBACK(button1_cb), (gpointer) msginfo);
1191 noticeview_set_2ndbutton_text(noticeview, button2);
1192 noticeview_set_2ndbutton_press_callback(noticeview,
1193 G_CALLBACK(button2_cb), (gpointer) msginfo);
1195 noticeview_show(noticeview);
1198 static void partial_recv_dload_clicked(NoticeView *noticeview,
1201 if (partial_mark_for_download(msginfo) == 0) {
1202 partial_recv_show(noticeview, msginfo);
1206 static void partial_recv_del_clicked(NoticeView *noticeview,
1209 if (partial_mark_for_delete(msginfo) == 0) {
1210 partial_recv_show(noticeview, msginfo);
1214 static void partial_recv_unmark_clicked(NoticeView *noticeview,
1217 if (partial_unmark(msginfo) == 0) {
1218 partial_recv_show(noticeview, msginfo);
1222 static void select_account_cb(GtkWidget *w, gpointer data)
1224 *(gint*)data = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), MENU_VAL_ID));
1227 static PrefsAccount *select_account_from_list(GList *ac_list)
1233 g_return_val_if_fail(ac_list != NULL, NULL);
1234 g_return_val_if_fail(ac_list->data != NULL, NULL);
1236 optmenu = gtk_option_menu_new();
1237 menu = gtkut_account_menu_new(ac_list,
1238 G_CALLBACK(select_account_cb),
1242 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1243 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1244 account_id = ((PrefsAccount *) ac_list->data)->account_id;
1245 if (alertpanel_with_widget(
1246 _("Return Receipt Notification"),
1247 _("The message was sent to several of your "
1249 "Please choose which account do you want to "
1250 "use for sending the receipt notification:"),
1251 _("Send Notification"), _("+Cancel"), NULL,
1252 optmenu) != G_ALERTDEFAULT)
1254 return account_find_from_id(account_id);
1258 * \brief return selected messageview text, when nothing is
1259 * selected and message was filtered, return complete text
1261 * \param pointer to Messageview
1263 * \return pointer to text (needs to be free'd by calling func)
1265 gchar *messageview_get_selection(MessageView *msgview)
1269 GtkTextView *edit = NULL;
1270 GtkTextBuffer *textbuf;
1273 g_return_val_if_fail(msgview != NULL, NULL);
1275 textview = messageview_get_current_textview(msgview);
1276 g_return_val_if_fail(textview != NULL, NULL);
1278 edit = GTK_TEXT_VIEW(textview->text);
1279 g_return_val_if_fail(edit != NULL, NULL);
1280 body_pos = textview->body_pos;
1282 textbuf = gtk_text_view_get_buffer(edit);
1284 if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
1285 return gtkut_text_view_get_selection(edit);
1286 else if (msgview->filtered) {
1287 GtkTextIter start_iter, end_iter;
1288 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
1289 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
1290 gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
1297 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1299 MessageView *messageview = (MessageView *)data;
1300 messageview_save_as(messageview);
1303 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1305 MessageView *messageview = (MessageView *)data;
1309 if (!messageview->msginfo) return;
1311 cmdline = input_dialog(_("Print"),
1312 _("Enter the print command line:\n"
1313 "(`%s' will be replaced with file name)"),
1314 prefs_common.print_cmd);
1315 if (!cmdline) return;
1316 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1317 strchr(p + 2, '%')) {
1318 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1324 procmsg_print_message(messageview->msginfo, cmdline);
1328 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1330 MessageView *messageview = (MessageView *)data;
1331 messageview_destroy(messageview);
1334 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1336 MessageView *messageview = (MessageView *)data;
1337 messageview_copy_clipboard(messageview);
1340 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1342 MessageView *messageview = (MessageView *)data;
1343 messageview_select_all(messageview);
1346 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1348 MessageView *messageview = (MessageView *)data;
1349 message_search(messageview);
1352 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1354 MessageView *messageview = (MessageView *)data;
1355 const gchar *charset;
1357 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1358 charset = conv_get_charset_str((CharSet)action);
1359 g_free(messageview->forced_charset);
1360 messageview->forced_charset = g_strdup(charset);
1361 procmime_force_charset(charset);
1363 messageview_show(messageview, messageview->msginfo, FALSE);
1367 static void set_decode_cb(gpointer data, guint action, GtkWidget *widget)
1369 MessageView *messageview = (MessageView *)data;
1370 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1371 messageview->forced_encoding = (EncodingType)action;
1373 messageview_show(messageview, messageview->msginfo, FALSE);
1375 debug_print("forced encoding: %d\n", action);
1380 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1382 MessageView *messageview = (MessageView *)data;
1383 SourceWindow *srcwin;
1385 if (!messageview->msginfo) return;
1387 srcwin = source_window_create();
1388 source_window_show_msg(srcwin, messageview->msginfo);
1389 source_window_show(srcwin);
1392 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1394 MessageView *messageview = (MessageView *)data;
1395 MsgInfo *msginfo = messageview->msginfo;
1397 messageview->all_headers =
1398 GTK_CHECK_MENU_ITEM(widget)->active;
1399 if (!msginfo) return;
1400 messageview->msginfo = NULL;
1401 messageview_show(messageview, msginfo,
1402 GTK_CHECK_MENU_ITEM(widget)->active);
1403 procmsg_msginfo_free(msginfo);
1404 main_window_set_menu_sensitive(messageview->mainwin);
1407 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1409 MessageView *messageview = (MessageView *)data;
1410 PrefsAccount *ac = NULL;
1411 FolderItem *item = NULL;
1413 if (messageview->msginfo)
1414 item = messageview->msginfo->folder;
1417 ac = account_find_from_item(item);
1418 if (ac && ac->protocol == A_NNTP &&
1419 item->stype == F_NEWS) {
1420 compose_new(ac, item->path, NULL);
1425 compose_new(ac, NULL, NULL);
1428 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1430 MessageView *messageview = (MessageView *)data;
1431 GSList *msginfo_list = NULL;
1433 g_return_if_fail(messageview->msginfo);
1435 msginfo_list = g_slist_append(msginfo_list, messageview->msginfo);
1436 compose_reply_from_messageview(messageview, msginfo_list, action);
1437 g_slist_free(msginfo_list);
1440 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1442 MessageView *messageview = (MessageView *)data;
1445 if (!messageview->msginfo) return;
1446 msginfo = messageview->msginfo;
1447 if (!msginfo->folder) return;
1448 if (msginfo->folder->stype != F_OUTBOX &&
1449 msginfo->folder->stype != F_DRAFT &&
1450 msginfo->folder->stype != F_QUEUE) return;
1452 compose_reedit(msginfo);
1455 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1457 addressbook_open(NULL);
1460 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1462 MessageView *messageview = (MessageView *)data;
1466 if (!messageview->msginfo) return;
1467 msginfo = messageview->msginfo;
1468 Xstrdup_a(from, msginfo->from, return);
1469 eliminate_address_comment(from);
1470 extract_address(from);
1471 addressbook_add_contact(msginfo->fromname, from, NULL);
1474 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1476 MessageView *messageview = (MessageView *)data;
1479 if (!messageview->msginfo) return;
1481 item = messageview->msginfo->folder;
1482 summary_msginfo_filter_open(item, messageview->msginfo,
1483 (PrefsFilterType)action, 0);
1486 static void create_processing_cb(gpointer data, guint action,
1489 MessageView *messageview = (MessageView *)data;
1492 if (!messageview->msginfo) return;
1494 item = messageview->msginfo->folder;
1495 summary_msginfo_filter_open(item, messageview->msginfo,
1496 (PrefsFilterType)action, 1);
1499 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1504 static gboolean messageview_update_msg(gpointer source, gpointer data)
1506 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1507 MessageView *messageview = (MessageView *)data;
1509 if (messageview->msginfo != msginfo_update->msginfo)
1512 if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1513 messageview_clear(messageview);
1514 messageview_update(messageview);
1520 void messageview_set_menu_sensitive(MessageView *messageview)
1522 GtkItemFactory *ifactory;
1523 GtkWidget *menuitem;
1525 if (!messageview || !messageview->new_window)
1527 /* do some smart things */
1528 if (!messageview->menubar) return;
1529 ifactory = gtk_item_factory_from_widget(messageview->menubar);
1530 if (!ifactory) return;
1531 if (messageview->mainwin->type == SEPARATE_MESSAGE) {
1532 menuitem = gtk_item_factory_get_widget(ifactory, "/View/Show all headers");
1533 gtk_check_menu_item_set_active
1534 (GTK_CHECK_MENU_ITEM(menuitem),
1535 messageview->mimeview->textview->show_all_headers);