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 void messageview_destroy_cb (GtkWidget *widget,
68 MessageView *messageview);
69 static void messageview_size_allocate_cb(GtkWidget *widget,
70 GtkAllocation *allocation);
71 static gboolean key_pressed (GtkWidget *widget,
73 MessageView *messageview);
75 static void return_receipt_show (NoticeView *noticeview,
77 static void return_receipt_send_clicked (NoticeView *noticeview,
79 static void partial_recv_show (NoticeView *noticeview,
81 static void partial_recv_dload_clicked (NoticeView *noticeview,
83 static void partial_recv_del_clicked (NoticeView *noticeview,
85 static void partial_recv_unmark_clicked (NoticeView *noticeview,
87 static void save_as_cb (gpointer data,
90 static void print_cb (gpointer data,
93 static void close_cb (gpointer data,
96 static void copy_cb (gpointer data,
99 static void allsel_cb (gpointer data,
102 static void search_cb (gpointer data,
106 static void set_charset_cb (gpointer data,
109 static void set_decode_cb (gpointer data,
112 static void view_source_cb (gpointer data,
115 static void show_all_header_cb (gpointer data,
119 static void compose_cb (gpointer data,
122 static void reply_cb (gpointer data,
125 static void reedit_cb (gpointer data,
129 static PrefsAccount *select_account_from_list
131 static void addressbook_open_cb (gpointer data,
134 static void add_address_cb (gpointer data,
137 static void create_filter_cb (gpointer data,
140 static void create_processing_cb (gpointer data,
144 static void about_cb (gpointer data,
147 static void messageview_update (MessageView *msgview);
148 static gboolean messageview_update_msg (gpointer source, gpointer data);
150 static GList *msgview_list = NULL;
151 static GtkItemFactoryEntry msgview_entries[] =
153 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
154 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
155 {N_("/_File/_Print..."), NULL, print_cb, 0, NULL},
156 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
157 {N_("/_File/_Close"), NULL, close_cb, 0, NULL},
159 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
160 {N_("/_Edit/_Copy"), NULL, copy_cb, 0, NULL},
161 {N_("/_Edit/Select _all"), NULL, allsel_cb, 0, NULL},
162 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
163 {N_("/_Edit/_Find in current message..."),
164 NULL, search_cb, 0, NULL},
166 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
168 #define ENC_SEPARATOR \
169 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
170 #define ENC_ACTION(action) \
171 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
173 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
174 {N_("/_View/Character _encoding/_Auto detect"),
175 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
177 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
178 ENC_ACTION(C_US_ASCII)},
180 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
181 ENC_ACTION(C_UTF_8)},
183 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
184 ENC_ACTION(C_ISO_8859_1)},
185 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
186 ENC_ACTION(C_ISO_8859_15)},
188 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
189 ENC_ACTION(C_ISO_8859_2)},
191 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
192 ENC_ACTION(C_ISO_8859_13)},
193 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
194 ENC_ACTION(C_ISO_8859_4)},
196 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
197 ENC_ACTION(C_ISO_8859_7)},
199 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
200 ENC_ACTION(C_ISO_8859_9)},
202 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
203 ENC_ACTION(C_ISO_8859_5)},
204 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
205 ENC_ACTION(C_KOI8_R)},
206 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
207 ENC_ACTION(C_KOI8_U)},
208 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
209 ENC_ACTION(C_CP1251)},
211 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
212 ENC_ACTION(C_ISO_2022_JP)},
213 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
214 ENC_ACTION(C_ISO_2022_JP_2)},
215 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
216 ENC_ACTION(C_EUC_JP)},
217 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
218 ENC_ACTION(C_SHIFT_JIS)},
220 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
221 ENC_ACTION(C_GB2312)},
222 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
224 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
225 ENC_ACTION(C_EUC_TW)},
226 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
227 ENC_ACTION(C_ISO_2022_CN)},
229 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
230 ENC_ACTION(C_EUC_KR)},
231 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
232 ENC_ACTION(C_ISO_2022_KR)},
234 {N_("/_View/Character _encoding/Thai (TIS-620)"),
235 ENC_ACTION(C_TIS_620)},
236 {N_("/_View/Character _encoding/Thai (Windows-874)"),
237 ENC_ACTION(C_WINDOWS_874)},
242 #define DEC_SEPARATOR \
243 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
244 #define DEC_ACTION(action) \
245 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
246 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
247 {N_("/_View/Decode/_Auto detect"),
248 NULL, set_decode_cb, 0, "<RadioItem>"},
249 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
250 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
251 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
252 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
253 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
258 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
259 {N_("/_View/Mess_age source"), NULL, view_source_cb, 0, NULL},
260 {N_("/_View/Show all _headers"),NULL, show_all_header_cb, 0, "<ToggleItem>"},
262 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
263 {N_("/_Message/Compose _new message"),
264 NULL, compose_cb, 0, NULL},
265 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
266 {N_("/_Message/_Reply"), NULL, reply_cb, COMPOSE_REPLY, NULL},
267 {N_("/_Message/Repl_y to/_all"),
268 NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
269 {N_("/_Message/Repl_y to/_sender"),
270 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
271 {N_("/_Message/Repl_y to/mailing _list"),
272 NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
273 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
274 {N_("/_Message/_Forward"), NULL, reply_cb, COMPOSE_FORWARD, NULL},
275 {N_("/_Message/For_ward as attachment"),
276 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
277 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
278 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
279 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
281 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
282 {N_("/_Tools/_Address book"), NULL, addressbook_open_cb, 0, NULL},
283 {N_("/_Tools/Add sender to address boo_k"),
284 NULL, add_address_cb, 0, NULL},
285 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
286 {N_("/_Tools/_Create filter rule"),
287 NULL, NULL, 0, "<Branch>"},
288 {N_("/_Tools/_Create filter rule/_Automatically"),
289 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
290 {N_("/_Tools/_Create filter rule/by _From"),
291 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
292 {N_("/_Tools/_Create filter rule/by _To"),
293 NULL, create_filter_cb, FILTER_BY_TO, NULL},
294 {N_("/_Tools/_Create filter rule/by _Subject"),
295 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
296 {N_("/_Tools/Create processing rule"),
297 NULL, NULL, 0, "<Branch>"},
298 {N_("/_Tools/Create processing rule/_Automatically"),
299 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
300 {N_("/_Tools/Create processing rule/by _From"),
301 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
302 {N_("/_Tools/Create processing rule/by _To"),
303 NULL, create_processing_cb, FILTER_BY_TO, NULL},
304 {N_("/_Tools/Create processing rule/by _Subject"),
305 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
306 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
307 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
309 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
310 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
313 MessageView *messageview_create(MainWindow *mainwin)
315 MessageView *messageview;
317 HeaderView *headerview;
319 NoticeView *noticeview;
321 debug_print("Creating message view...\n");
322 messageview = g_new0(MessageView, 1);
324 headerview = headerview_create();
326 noticeview = noticeview_create(mainwin);
328 mimeview = mimeview_create(mainwin);
329 mimeview->textview = textview_create();
330 mimeview->textview->messageview = messageview;
331 mimeview->messageview = messageview;
333 vbox = gtk_vbox_new(FALSE, 0);
334 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
336 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
338 gtk_box_pack_start(GTK_BOX(vbox),
339 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
340 gtk_widget_show(vbox);
342 messageview->vbox = vbox;
343 messageview->new_window = FALSE;
344 messageview->window = NULL;
345 messageview->headerview = headerview;
346 messageview->mimeview = mimeview;
347 messageview->noticeview = noticeview;
348 messageview->mainwin = mainwin;
350 messageview->statusbar = NULL;
351 messageview->statusbar_cid = 0;
353 messageview->msginfo_update_callback_id =
354 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
359 GList *messageview_get_msgview_list(void)
364 void messageview_update_actions_menu(MessageView *msgview)
366 GtkItemFactory *ifactory;
368 /* Messages opened in a new window do not have a menu bar */
369 if (msgview->menubar == NULL)
371 ifactory = gtk_item_factory_from_widget(msgview->menubar);
372 action_update_msgview_menu(ifactory, "/Tools/Actions", msgview);
375 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
377 GtkWidget *handlebox;
380 GtkWidget *statusbar;
381 guint n_menu_entries;
383 vbox = gtk_vbox_new(FALSE, 0);
384 gtk_widget_show(vbox);
385 gtk_container_add(GTK_CONTAINER(window), vbox);
387 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
388 menubar = menubar_create(window, msgview_entries,
389 n_menu_entries, "<MessageView>", msgview);
390 gtk_widget_show(menubar);
391 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
393 handlebox = gtk_handle_box_new();
394 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
395 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
398 statusbar = gtk_statusbar_new();
399 gtk_widget_show(statusbar);
400 gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
401 msgview->statusbar = statusbar;
402 msgview->statusbar_cid = gtk_statusbar_get_context_id
403 (GTK_STATUSBAR(statusbar), "Message View");
405 msgview->handlebox = handlebox;
406 msgview->menubar = menubar;
408 gtk_container_add(GTK_CONTAINER(vbox),
409 GTK_WIDGET_PTR(msgview));
411 messageview_update_actions_menu(msgview);
413 msgview_list = g_list_append(msgview_list, msgview);
416 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
418 MessageView *msgview;
421 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
422 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
423 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
424 gtk_widget_set_size_request(window, prefs_common.msgwin_width,
425 prefs_common.msgwin_height);
427 msgview = messageview_create(mainwin);
429 g_signal_connect(G_OBJECT(window), "size_allocate",
430 G_CALLBACK(messageview_size_allocate_cb),
432 g_signal_connect(G_OBJECT(window), "destroy",
433 G_CALLBACK(messageview_destroy_cb), msgview);
434 g_signal_connect(G_OBJECT(window), "key_press_event",
435 G_CALLBACK(key_pressed), msgview);
437 messageview_add_toolbar(msgview, window);
439 gtk_widget_grab_focus(msgview->mimeview->textview->text);
440 gtk_widget_show(window);
442 msgview->new_window = TRUE;
443 msgview->window = window;
444 msgview->visible = TRUE;
446 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
447 prefs_common.toolbar_style);
448 messageview_init(msgview);
453 void messageview_init(MessageView *messageview)
455 headerview_init(messageview->headerview);
456 mimeview_init(messageview->mimeview);
457 /*messageview_set_font(messageview);*/
459 noticeview_hide(messageview->noticeview);
462 static void notification_convert_header(gchar *dest, gint len,
468 g_return_if_fail(src_ != NULL);
469 g_return_if_fail(dest != NULL);
473 Xstrndup_a(src, src_, len, return);
477 if (is_ascii_str(src)) {
478 strncpy2(dest, src, len);
479 dest[len - 1] = '\0';
482 conv_encode_header(dest, len, src, header_len, FALSE);
485 static gint disposition_notification_send(MsgInfo *msginfo)
488 gchar tmp[MAXPATHLEN + 1];
491 PrefsAccount *account;
494 FolderItem *queue, *outbox;
500 if ((!msginfo->returnreceiptto) &&
501 (!msginfo->dispositionnotificationto))
504 /* RFC2298: Test for Return-Path */
505 if (msginfo->dispositionnotificationto)
506 to = msginfo->dispositionnotificationto;
508 to = msginfo->returnreceiptto;
510 ok = procheader_get_header_from_msginfo(msginfo, buf, sizeof(buf),
513 gchar *to_addr = g_strdup(to);
514 extract_address(to_addr);
515 extract_address(buf);
516 ok = strcmp(to_addr, buf);
519 strncpy(buf, _("<No Return-Path found>"),
526 message = g_strdup_printf(
527 _("The notification address to which the "
528 "return receipt is to be sent\n"
529 "does not correspond to the return path:\n"
530 "Notification address: %s\n"
532 "It is advised to not to send the return "
533 "receipt."), to, buf);
534 val = alertpanel_with_type(_("Warning"), message, _("Send"),
535 _("+Don't Send"), NULL, NULL, ALERT_WARNING);
537 if (val != G_ALERTDEFAULT)
541 ac_list = account_find_all_from_address(NULL, msginfo->to);
542 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
544 if (ac_list == NULL) {
545 alertpanel_error(_("This message is asking for a return "
546 "receipt notification\n"
547 "but according to its 'To:' and 'CC:' "
548 "headers it was not\nofficially addressed "
550 "Receipt notification cancelled."));
554 if (g_list_length(ac_list) > 1)
555 account = select_account_from_list(ac_list);
557 account = (PrefsAccount *) ac_list->data;
558 g_list_free(ac_list);
563 /* write to temporary file */
564 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
565 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
567 if ((fp = fopen(tmp, "wb")) == NULL) {
568 FILE_OP_ERROR(tmp, "fopen");
572 /* chmod for security */
573 if (change_file_mode_rw(fp, tmp) < 0) {
574 FILE_OP_ERROR(tmp, "chmod");
575 g_warning("can't change file mode\n");
580 extract_address(addr);
583 /* write queue headers */
584 fprintf(fp, "AF:\n");
585 fprintf(fp, "NF:0\n");
586 fprintf(fp, "PS:10\n");
587 fprintf(fp, "SRH:1\n");
588 fprintf(fp, "SFN:\n");
589 fprintf(fp, "DSR:\n");
590 fprintf(fp, "MID:\n");
591 fprintf(fp, "CFG:\n");
592 fprintf(fp, "PT:0\n");
593 fprintf(fp, "S:%s\n", account->address);
594 fprintf(fp, "RQ:\n");
595 if (account->smtp_server)
596 fprintf(fp, "SSV:%s\n", account->smtp_server);
598 fprintf(fp, "SSV:\n");
599 fprintf(fp, "SSH:\n");
600 fprintf(fp, "R:<%s>\n", addrp);
604 /* check whether we need to save the message */
605 outbox = account_get_special_folder(account, F_OUTBOX);
606 if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
609 path = folder_item_get_identifier(outbox);
610 fprintf(fp, "SCF:%s\n", path);
617 get_rfc822_date(buf, sizeof(buf));
618 fprintf(fp, "Date: %s\n", buf);
621 if (account->name && *account->name) {
622 notification_convert_header
623 (buf, sizeof(buf), account->name,
625 fprintf(fp, "From: %s <%s>\n", buf, account->address);
627 fprintf(fp, "From: %s\n", account->address);
629 fprintf(fp, "To: %s\n", to);
632 notification_convert_header(buf, sizeof(buf), msginfo->subject,
633 strlen("Subject: "));
634 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
637 generate_msgid(buf, sizeof(buf));
638 fprintf(fp, "Message-ID: <%s>\n", buf);
640 if (fclose(fp) == EOF) {
641 FILE_OP_ERROR(tmp, "fclose");
646 /* put it in queue */
647 queue = account_get_special_folder(account, F_QUEUE);
648 if (!queue) queue = folder_get_default_queue();
650 g_warning("can't find queue folder\n");
654 folder_item_scan(queue);
655 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
656 g_warning("can't queue the message\n");
661 if (prefs_common.work_offline)
662 if (alertpanel(_("Offline warning"),
663 _("You're working offline. Override?"),
664 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
668 path = folder_item_fetch_msg(queue, num);
669 ok = procmsg_send_message_queue(path);
671 folder_item_remove_msg(queue, num);
676 GList *messageview_get_window_list(void)
678 return messageview_list;
681 static gboolean find_encrypted_func(GNode *node, gpointer data)
683 MimeInfo *mimeinfo = (MimeInfo *) node->data;
684 MimeInfo **encinfo = (MimeInfo **) data;
686 if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
694 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
696 MimeInfo *encinfo = NULL;
698 g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
699 find_encrypted_func, &encinfo);
704 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
705 gboolean all_headers)
708 MimeInfo *mimeinfo, *encinfo;
710 g_return_val_if_fail(msginfo != NULL, -1);
712 mimeinfo = procmime_scan_message(msginfo);
714 textview_show_error(messageview->mimeview->textview);
718 while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
719 debug_print("decrypting message part\n");
720 if (privacy_mimeinfo_decrypt(encinfo) < 0)
724 file = procmsg_get_message_file_path(msginfo);
726 g_warning("can't get message file path.\n");
727 procmime_mimeinfo_free_all(mimeinfo);
728 textview_show_error(messageview->mimeview->textview);
732 if (messageview->msginfo != msginfo) {
733 procmsg_msginfo_free(messageview->msginfo);
734 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
735 if (!messageview->msginfo)
736 messageview->msginfo = procmsg_msginfo_copy(msginfo);
738 headerview_show(messageview->headerview, messageview->msginfo);
740 messageview->all_headers = all_headers;
741 textview_set_all_headers(messageview->mimeview->textview, all_headers);
743 mimeview_show_message(messageview->mimeview, mimeinfo, file);
744 messageview_set_position(messageview, 0);
746 if (messageview->msginfo->partial_recv)
747 partial_recv_show(messageview->noticeview,
748 messageview->msginfo);
749 else if ((messageview->msginfo->dispositionnotificationto ||
750 messageview->msginfo->returnreceiptto) &&
751 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags))
752 return_receipt_show(messageview->noticeview,
753 messageview->msginfo);
755 noticeview_hide(messageview->noticeview);
757 mimeinfo = procmime_mimeinfo_next(mimeinfo);
758 if (mimeinfo && (mimeinfo->type != MIMETYPE_TEXT ||
759 (strcmp(mimeinfo->subtype, "plain") &&
760 strcmp(mimeinfo->subtype, "html")))) {
761 mimeview_show_part(messageview->mimeview,mimeinfo);
769 void messageview_reflect_prefs_pixmap_theme(void)
772 MessageView *msgview;
774 for (cur = msgview_list; cur != NULL; cur = cur->next) {
775 msgview = (MessageView*)cur->data;
776 toolbar_update(TOOLBAR_MSGVIEW, msgview);
777 mimeview_update(msgview->mimeview);
781 void messageview_clear(MessageView *messageview)
783 procmsg_msginfo_free(messageview->msginfo);
784 messageview->msginfo = NULL;
785 messageview->filtered = FALSE;
786 mimeview_clear(messageview->mimeview);
787 headerview_clear(messageview->headerview);
788 noticeview_hide(messageview->noticeview);
791 void messageview_destroy(MessageView *messageview)
793 debug_print("destroy messageview\n");
794 messageview_list = g_list_remove(messageview_list, messageview);
796 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
797 messageview->msginfo_update_callback_id);
799 headerview_destroy(messageview->headerview);
800 mimeview_destroy(messageview->mimeview);
801 noticeview_destroy(messageview->noticeview);
803 procmsg_msginfo_free(messageview->msginfo);
804 toolbar_clear_list(TOOLBAR_MSGVIEW);
805 if (messageview->toolbar) {
806 toolbar_destroy(messageview->toolbar);
807 g_free(messageview->toolbar);
810 msgview_list = g_list_remove(msgview_list, messageview);
815 void messageview_delete(MessageView *msgview)
817 MsgInfo *msginfo = NULL;
818 FolderItem *trash = NULL;
819 PrefsAccount *ac = NULL;
821 if (msgview->msginfo && msgview->mainwin && msgview->mainwin->summaryview)
822 msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
824 /* need a procmsg_msginfo_equal() */
825 if (msginfo && msgview->msginfo &&
826 msginfo->msgnum == msgview->msginfo->msgnum &&
827 msginfo->folder == msgview->msginfo->folder) {
828 summary_delete(msgview->mainwin->summaryview);
830 msginfo = msgview->msginfo;
832 g_return_if_fail(msginfo != NULL);
834 /* to get the trash folder, we have to choose either
835 * the folder's or account's trash default - we prefer
836 * the one in the account prefs */
837 if (msginfo->folder) {
838 if (NULL != (ac = account_find_from_item(msginfo->folder)))
839 trash = account_get_special_folder(ac, F_TRASH);
840 if (!trash && msginfo->folder->folder)
841 trash = msginfo->folder->folder->trash;
842 /* if still not found, use the default */
844 trash = folder_get_default_trash();
847 g_return_if_fail(trash != NULL);
849 if (prefs_common.immediate_exec)
850 /* TODO: Delete from trash */
851 folder_item_move_msg(trash, msginfo);
853 procmsg_msginfo_set_to_folder(msginfo, trash);
854 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
855 /* NOTE: does not update to next message in summaryview */
861 * \brief update messageview with currently selected message in summaryview
862 * leave unchanged if summaryview is empty
863 * \param pointer to MessageView
865 static void messageview_update(MessageView *msgview)
867 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
869 g_return_if_fail(summaryview != NULL);
871 if (summaryview->selected) {
872 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
873 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
874 summaryview->selected);
875 g_return_if_fail(msginfo != NULL);
877 messageview_show(msgview, msginfo,
878 msgview->all_headers);
882 void messageview_quote_color_set(void)
886 void messageview_set_font(MessageView *messageview)
890 TextView *messageview_get_current_textview(MessageView *messageview)
892 TextView *text = NULL;
894 text = messageview->mimeview->textview;
899 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
901 return mimeview_get_selected_part(messageview->mimeview);
904 void messageview_copy_clipboard(MessageView *messageview)
908 text = messageview_get_current_textview(messageview);
910 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
911 GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
912 GtkClipboard *clipboard
913 = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
915 gtk_text_buffer_copy_clipboard(buffer, clipboard);
919 void messageview_select_all(MessageView *messageview)
923 text = messageview_get_current_textview(messageview);
925 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
926 GtkTextBuffer *buffer;
927 GtkTextIter start, end;
929 buffer = gtk_text_view_get_buffer(textview);
930 gtk_text_buffer_get_bounds(buffer, &start, &end);
931 gtk_text_buffer_select_range(buffer, &start, &end);
935 void messageview_set_position(MessageView *messageview, gint pos)
939 text = messageview_get_current_textview(messageview);
941 textview_set_position(text, pos);
944 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
949 text = messageview_get_current_textview(messageview);
951 return textview_search_string(text, str, case_sens);
955 gboolean messageview_search_string_backward(MessageView *messageview,
961 text = messageview_get_current_textview(messageview);
963 return textview_search_string_backward(text,
968 gboolean messageview_is_visible(MessageView *messageview)
970 return messageview->visible;
973 void messageview_save_as(MessageView *messageview)
975 gchar *filename = NULL;
977 gchar *src, *dest, *tmp;
979 if (!messageview->msginfo) return;
980 msginfo = messageview->msginfo;
982 if (msginfo->subject) {
983 Xstrdup_a(filename, msginfo->subject, return);
984 subst_for_filename(filename);
986 dest = filesel_select_file_save(_("Save as"), filename);
988 if (is_file_exist(dest)) {
991 aval = alertpanel(_("Overwrite"),
992 _("Overwrite existing file?"),
993 GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
994 if (G_ALERTDEFAULT != aval) return;
997 src = procmsg_get_message_file(msginfo);
998 if (copy_file(src, dest, TRUE) < 0) {
999 tmp = g_path_get_basename(dest);
1000 alertpanel_error(_("Can't save the file `%s'."), tmp);
1007 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
1009 messageview_destroy(messageview);
1012 static void messageview_size_allocate_cb(GtkWidget *widget,
1013 GtkAllocation *allocation)
1015 g_return_if_fail(allocation != NULL);
1017 prefs_common.msgwin_width = allocation->width;
1018 prefs_common.msgwin_height = allocation->height;
1021 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
1022 MessageView *messageview)
1024 if (event && event->keyval == GDK_Escape && messageview->window)
1025 gtk_widget_destroy(messageview->window);
1029 void messageview_toggle_view_real(MessageView *messageview)
1031 MainWindow *mainwin = messageview->mainwin;
1032 union CompositeWin *cwin = &mainwin->win;
1033 GtkWidget *vpaned = NULL;
1034 GtkWidget *container = NULL;
1035 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1037 switch (mainwin->type) {
1039 vpaned = cwin->sep_none.vpaned;
1040 container = cwin->sep_none.hpaned;
1042 case SEPARATE_FOLDER:
1043 vpaned = cwin->sep_folder.vpaned;
1044 container = mainwin->vbox_body;
1046 case SEPARATE_MESSAGE:
1051 if (vpaned->parent != NULL) {
1052 gtk_widget_ref(vpaned);
1053 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1054 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
1055 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
1057 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
1058 gtk_container_add(GTK_CONTAINER(container), vpaned);
1059 gtk_widget_unref(vpaned);
1060 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
1061 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
1065 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1067 noticeview_set_text(noticeview, _("This message asks for a return receipt."));
1068 noticeview_set_button_text(noticeview, _("Send receipt"));
1069 noticeview_set_button_press_callback(noticeview,
1070 G_CALLBACK(return_receipt_send_clicked),
1071 (gpointer) msginfo);
1072 noticeview_show(noticeview);
1075 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1077 MsgInfo *tmpmsginfo;
1080 file = procmsg_get_message_file_path(msginfo);
1082 g_warning("can't get message file path.\n");
1086 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1087 tmpmsginfo->folder = msginfo->folder;
1088 tmpmsginfo->msgnum = msginfo->msgnum;
1090 if (disposition_notification_send(tmpmsginfo) >= 0) {
1091 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1092 noticeview_hide(noticeview);
1095 procmsg_msginfo_free(tmpmsginfo);
1099 static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
1102 gchar *button1 = NULL;
1103 gchar *button2 = NULL;
1104 void *button1_cb = NULL;
1105 void *button2_cb = NULL;
1107 if (!partial_msg_in_uidl_list(msginfo)) {
1108 text = g_strdup_printf(_("This message has been partially "
1109 "retrieved,\nand has been deleted from the "
1112 switch (msginfo->planned_download) {
1113 case POP3_PARTIAL_DLOAD_UNKN:
1114 text = g_strdup_printf(_("This message has been "
1115 "partially retrieved;\nit is %s."),
1117 (off_t)(msginfo->total_size)));
1118 button1 = _("Mark for download");
1119 button2 = _("Mark for deletion");
1120 button1_cb = partial_recv_dload_clicked;
1121 button2_cb = partial_recv_del_clicked;
1123 case POP3_PARTIAL_DLOAD_DLOAD:
1124 text = g_strdup_printf(_("This message has been "
1125 "partially retrieved;\nit is %s and "
1126 "will be downloaded."),
1128 (off_t)(msginfo->total_size)));
1129 button1 = _("Unmark");
1130 button1_cb = partial_recv_unmark_clicked;
1131 button2 = _("Mark for deletion");
1132 button2_cb = partial_recv_del_clicked;
1134 case POP3_PARTIAL_DLOAD_DELE:
1135 text = g_strdup_printf(_("This message has been "
1136 "partially retrieved;\nit is %s and "
1137 "will be deleted."),
1139 (off_t)(msginfo->total_size)));
1140 button1 = _("Mark for download");
1141 button1_cb = partial_recv_dload_clicked;
1142 button2 = _("Unmark");
1143 button2_cb = partial_recv_unmark_clicked;
1150 noticeview_set_text(noticeview, text);
1152 noticeview_set_button_text(noticeview, button1);
1153 noticeview_set_button_press_callback(noticeview,
1154 G_CALLBACK(button1_cb), (gpointer) msginfo);
1156 noticeview_set_2ndbutton_text(noticeview, button2);
1157 noticeview_set_2ndbutton_press_callback(noticeview,
1158 G_CALLBACK(button2_cb), (gpointer) msginfo);
1160 noticeview_show(noticeview);
1163 static void partial_recv_dload_clicked(NoticeView *noticeview,
1166 if (partial_mark_for_download(msginfo) == 0) {
1167 partial_recv_show(noticeview, msginfo);
1171 static void partial_recv_del_clicked(NoticeView *noticeview,
1174 if (partial_mark_for_delete(msginfo) == 0) {
1175 partial_recv_show(noticeview, msginfo);
1179 static void partial_recv_unmark_clicked(NoticeView *noticeview,
1182 if (partial_unmark(msginfo) == 0) {
1183 partial_recv_show(noticeview, msginfo);
1187 static void select_account_cb(GtkWidget *w, gpointer data)
1189 *(gint*)data = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), MENU_VAL_ID));
1192 static PrefsAccount *select_account_from_list(GList *ac_list)
1198 g_return_val_if_fail(ac_list != NULL, NULL);
1199 g_return_val_if_fail(ac_list->data != NULL, NULL);
1201 optmenu = gtk_option_menu_new();
1202 menu = gtkut_account_menu_new(ac_list,
1203 G_CALLBACK(select_account_cb),
1207 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1208 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1209 account_id = ((PrefsAccount *) ac_list->data)->account_id;
1210 if (alertpanel_with_widget(
1211 _("Return Receipt Notification"),
1212 _("The message was sent to several of your "
1214 "Please choose which account do you want to "
1215 "use for sending the receipt notification:"),
1216 _("Send Notification"), _("+Cancel"), NULL,
1217 optmenu) != G_ALERTDEFAULT)
1219 return account_find_from_id(account_id);
1223 * \brief return selected messageview text, when nothing is
1224 * selected and message was filtered, return complete text
1226 * \param pointer to Messageview
1228 * \return pointer to text (needs to be free'd by calling func)
1230 gchar *messageview_get_selection(MessageView *msgview)
1234 GtkTextView *edit = NULL;
1235 GtkTextBuffer *textbuf;
1238 g_return_val_if_fail(msgview != NULL, NULL);
1240 textview = messageview_get_current_textview(msgview);
1241 g_return_val_if_fail(textview != NULL, NULL);
1243 edit = GTK_TEXT_VIEW(textview->text);
1244 g_return_val_if_fail(edit != NULL, NULL);
1245 body_pos = textview->body_pos;
1247 textbuf = gtk_text_view_get_buffer(edit);
1249 if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
1250 return gtkut_text_view_get_selection(edit);
1251 else if (msgview->filtered) {
1252 GtkTextIter start_iter, end_iter;
1253 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
1254 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
1255 gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
1262 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1264 MessageView *messageview = (MessageView *)data;
1265 messageview_save_as(messageview);
1268 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1270 MessageView *messageview = (MessageView *)data;
1274 if (!messageview->msginfo) return;
1276 cmdline = input_dialog(_("Print"),
1277 _("Enter the print command line:\n"
1278 "(`%s' will be replaced with file name)"),
1279 prefs_common.print_cmd);
1280 if (!cmdline) return;
1281 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1282 strchr(p + 2, '%')) {
1283 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1289 procmsg_print_message(messageview->msginfo, cmdline);
1293 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1295 MessageView *messageview = (MessageView *)data;
1296 gtk_widget_destroy(messageview->window);
1299 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1301 MessageView *messageview = (MessageView *)data;
1302 messageview_copy_clipboard(messageview);
1305 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1307 MessageView *messageview = (MessageView *)data;
1308 messageview_select_all(messageview);
1311 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1313 MessageView *messageview = (MessageView *)data;
1314 message_search(messageview);
1317 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1319 MessageView *messageview = (MessageView *)data;
1320 const gchar *charset;
1322 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1323 charset = conv_get_charset_str((CharSet)action);
1324 g_free(messageview->forced_charset);
1325 messageview->forced_charset = g_strdup(charset);
1326 procmime_force_charset(charset);
1328 messageview_show(messageview, messageview->msginfo, FALSE);
1332 static void set_decode_cb(gpointer data, guint action, GtkWidget *widget)
1334 MessageView *messageview = (MessageView *)data;
1335 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1336 messageview->forced_encoding = (EncodingType)action;
1338 messageview_show(messageview, messageview->msginfo, FALSE);
1340 debug_print("forced encoding: %d\n", action);
1345 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1347 MessageView *messageview = (MessageView *)data;
1348 SourceWindow *srcwin;
1350 if (!messageview->msginfo) return;
1352 srcwin = source_window_create();
1353 source_window_show_msg(srcwin, messageview->msginfo);
1354 source_window_show(srcwin);
1357 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1359 MessageView *messageview = (MessageView *)data;
1360 MsgInfo *msginfo = messageview->msginfo;
1362 if (!msginfo) return;
1363 messageview->msginfo = NULL;
1364 messageview_show(messageview, msginfo,
1365 GTK_CHECK_MENU_ITEM(widget)->active);
1366 procmsg_msginfo_free(msginfo);
1367 main_window_set_menu_sensitive(messageview->mainwin);
1370 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1372 MessageView *messageview = (MessageView *)data;
1373 PrefsAccount *ac = NULL;
1374 FolderItem *item = NULL;
1376 if (messageview->msginfo)
1377 item = messageview->msginfo->folder;
1380 ac = account_find_from_item(item);
1381 if (ac && ac->protocol == A_NNTP &&
1382 item->stype == F_NEWS) {
1383 compose_new(ac, item->path, NULL);
1388 compose_new(ac, NULL, NULL);
1391 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1393 MessageView *messageview = (MessageView *)data;
1394 GSList *msginfo_list = NULL;
1397 g_return_if_fail(messageview->msginfo);
1399 msginfo_list = g_slist_append(msginfo_list, messageview->msginfo);
1400 compose_reply_from_messageview(messageview, msginfo_list, action);
1401 g_slist_free(msginfo_list);
1404 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1406 MessageView *messageview = (MessageView *)data;
1409 if (!messageview->msginfo) return;
1410 msginfo = messageview->msginfo;
1411 if (!msginfo->folder) return;
1412 if (msginfo->folder->stype != F_OUTBOX &&
1413 msginfo->folder->stype != F_DRAFT &&
1414 msginfo->folder->stype != F_QUEUE) return;
1416 compose_reedit(msginfo);
1419 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1421 addressbook_open(NULL);
1424 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1426 MessageView *messageview = (MessageView *)data;
1430 if (!messageview->msginfo) return;
1431 msginfo = messageview->msginfo;
1432 Xstrdup_a(from, msginfo->from, return);
1433 eliminate_address_comment(from);
1434 extract_address(from);
1435 addressbook_add_contact(msginfo->fromname, from, NULL);
1438 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1440 MessageView *messageview = (MessageView *)data;
1443 if (!messageview->msginfo) return;
1445 item = messageview->msginfo->folder;
1446 summary_msginfo_filter_open(item, messageview->msginfo,
1447 (PrefsFilterType)action, 0);
1450 static void create_processing_cb(gpointer data, guint action,
1453 MessageView *messageview = (MessageView *)data;
1456 if (!messageview->msginfo) return;
1458 item = messageview->msginfo->folder;
1459 summary_msginfo_filter_open(item, messageview->msginfo,
1460 (PrefsFilterType)action, 1);
1463 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1468 static gboolean messageview_update_msg(gpointer source, gpointer data)
1470 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1471 MessageView *messageview = (MessageView *)data;
1473 if (messageview->msginfo != msginfo_update->msginfo)
1476 if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1477 messageview_clear(messageview);
1478 messageview_update(messageview);
1484 void messageview_set_menu_sensitive(MessageView *messageview)
1486 GtkItemFactory *ifactory;
1487 GtkWidget *menuitem;
1489 if (!messageview || !messageview->new_window)
1491 /* do some smart things */
1492 if (!messageview->menubar) return;
1493 ifactory = gtk_item_factory_from_widget(messageview->menubar);
1494 if (!ifactory) return;
1495 if (messageview->mainwin->type == SEPARATE_MESSAGE) {
1496 menuitem = gtk_item_factory_get_widget(ifactory, "/View/Show all headers");
1497 gtk_check_menu_item_set_active
1498 (GTK_CHECK_MENU_ITEM(menuitem),
1499 messageview->mimeview->textview->show_all_headers);