2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 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 <gdk/gdkkeysyms.h>
24 #include <gtk/gtkvbox.h>
25 #include <gtk/gtkcontainer.h>
26 #include <gtk/gtkeditable.h>
27 #include <gtk/gtkwindow.h>
28 #include <gtk/gtktext.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
37 #include "messageview.h"
38 #include "message_search.h"
39 #include "headerview.h"
40 #include "summaryview.h"
46 #include "sourcewindow.h"
47 #include "addressbook.h"
48 #include "alertpanel.h"
49 #include "inputdialog.h"
50 #include "manage_window.h"
52 #include "procheader.h"
56 #include "prefs_common.h"
57 #include "prefs_account.h"
61 #include "send_message.h"
62 #include "stock_pixmap.h"
64 static GList *messageview_list = NULL;
66 static void messageview_change_view_type(MessageView *messageview,
68 static void messageview_destroy_cb (GtkWidget *widget,
69 MessageView *messageview);
70 static void messageview_size_allocate_cb(GtkWidget *widget,
71 GtkAllocation *allocation);
72 static void 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 save_as_cb (gpointer data,
83 static void print_cb (gpointer data,
86 static void close_cb (gpointer data,
89 static void copy_cb (gpointer data,
92 static void allsel_cb (gpointer data,
95 static void search_cb (gpointer data,
99 static void set_charset_cb (gpointer data,
102 static void view_source_cb (gpointer data,
105 static void show_all_header_cb (gpointer data,
109 static void compose_cb (gpointer data,
112 static void reply_cb (gpointer data,
115 static void reedit_cb (gpointer data,
119 static PrefsAccount *select_account_from_list
121 static void addressbook_open_cb (gpointer data,
124 static void add_address_cb (gpointer data,
127 static void create_filter_cb (gpointer data,
131 static void messageview_menubar_cb (MessageView *msgview,
134 static void about_cb (gpointer data,
137 static void messageview_update (MessageView *msgview);
138 static void messageview_update_all (MessageView *msgview);
140 static GList *msgview_list = NULL;
141 static GtkItemFactoryEntry msgview_entries[] =
143 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
144 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
145 {N_("/_File/_Print..."), NULL, print_cb, 0, NULL},
146 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
147 {N_("/_File/_Close"), NULL, close_cb, 0, NULL},
149 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
150 {N_("/_Edit/_Copy"), NULL, copy_cb, 0, NULL},
151 {N_("/_Edit/Select _all"), NULL, allsel_cb, 0, NULL},
152 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
153 {N_("/_Edit/_Find in current message..."),
154 NULL, search_cb, 0, NULL},
156 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
158 #define CODESET_SEPARATOR \
159 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
160 #define CODESET_ACTION(action) \
161 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
163 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
164 {N_("/_View/_Code set/_Auto detect"),
165 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
167 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
168 CODESET_ACTION(C_US_ASCII)},
171 {N_("/_View/_Code set/Unicode (_UTF-8)"),
172 CODESET_ACTION(C_UTF_8)},
175 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
176 CODESET_ACTION(C_ISO_8859_1)},
177 {N_("/_View/_Code set/Western European (ISO-8859-15)"),
178 CODESET_ACTION(C_ISO_8859_15)},
181 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
182 CODESET_ACTION(C_ISO_8859_2)},
184 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
185 CODESET_ACTION(C_ISO_8859_13)},
186 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
187 CODESET_ACTION(C_ISO_8859_4)},
189 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
190 CODESET_ACTION(C_ISO_8859_7)},
192 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
193 CODESET_ACTION(C_ISO_8859_9)},
195 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
196 CODESET_ACTION(C_ISO_8859_5)},
197 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
198 CODESET_ACTION(C_KOI8_R)},
199 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
200 CODESET_ACTION(C_CP1251)},
203 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
204 CODESET_ACTION(C_ISO_2022_JP)},
206 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
207 CODESET_ACTION(C_ISO_2022_JP_2)},
209 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
210 CODESET_ACTION(C_EUC_JP)},
211 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
212 CODESET_ACTION(C_SHIFT_JIS)},
215 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
216 CODESET_ACTION(C_GB2312)},
217 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
218 CODESET_ACTION(C_BIG5)},
219 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
220 CODESET_ACTION(C_EUC_TW)},
221 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
222 CODESET_ACTION(C_ISO_2022_CN)},
224 {N_("/_View/_Code set/Korean (EUC-_KR)"),
225 CODESET_ACTION(C_EUC_KR)},
226 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
227 CODESET_ACTION(C_ISO_2022_KR)},
229 {N_("/_View/_Code set/Thai (TIS-620)"),
230 CODESET_ACTION(C_TIS_620)},
231 {N_("/_View/_Code set/Thai (Windows-874)"),
232 CODESET_ACTION(C_WINDOWS_874)},
235 #undef CODESET_SEPARATOR
236 #undef CODESET_ACTION
238 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
239 {N_("/_View/Mess_age source"), NULL, view_source_cb, 0, NULL},
240 {N_("/_View/Show all _header"), NULL, show_all_header_cb, 0, "<ToggleItem>"},
242 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
243 {N_("/_Message/Compose _new message"),
244 NULL, compose_cb, 0, NULL},
245 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
246 {N_("/_Message/_Reply"), NULL, reply_cb, COMPOSE_REPLY, NULL},
247 {N_("/_Message/Repl_y to/_all"),
248 NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
249 {N_("/_Message/Repl_y to/_sender"),
250 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
251 {N_("/_Message/Repl_y to/mailing _list"),
252 NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
253 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
254 {N_("/_Message/_Forward"), NULL, reply_cb, COMPOSE_FORWARD, NULL},
255 {N_("/_Message/For_ward as attachment"),
256 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
257 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
258 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
259 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
261 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
262 {N_("/_Tools/_Address book"), NULL, addressbook_open_cb, 0, NULL},
263 {N_("/_Tools/Add sender to address boo_k"),
264 NULL, add_address_cb, 0, NULL},
265 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
266 {N_("/_Tools/_Create filter rule"),
267 NULL, NULL, 0, "<Branch>"},
268 {N_("/_Tools/_Create filter rule/_Automatically"),
269 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
270 {N_("/_Tools/_Create filter rule/by _From"),
271 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
272 {N_("/_Tools/_Create filter rule/by _To"),
273 NULL, create_filter_cb, FILTER_BY_TO, NULL},
274 {N_("/_Tools/_Create filter rule/by _Subject"),
275 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
276 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
277 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
279 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
280 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
283 MessageView *messageview_create(MainWindow *mainwin)
285 MessageView *messageview;
287 HeaderView *headerview;
290 NoticeView *noticeview;
292 debug_print("Creating message view...\n");
293 messageview = g_new0(MessageView, 1);
295 messageview->type = MVIEW_TEXT;
297 headerview = headerview_create();
299 noticeview = noticeview_create(mainwin);
301 textview = textview_create();
302 textview->messageview = messageview;
304 mimeview = mimeview_create(mainwin);
305 mimeview->textview = textview_create();
306 mimeview->textview->messageview = messageview;
307 mimeview->messageview = messageview;
309 vbox = gtk_vbox_new(FALSE, 0);
310 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
312 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
314 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(textview),
317 /* to remove without destroyed */
318 gtk_widget_ref(GTK_WIDGET_PTR(textview));
319 gtk_widget_ref(GTK_WIDGET_PTR(mimeview));
320 gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
322 messageview->vbox = vbox;
323 messageview->new_window = FALSE;
324 messageview->window = NULL;
325 messageview->headerview = headerview;
326 messageview->textview = textview;
327 messageview->mimeview = mimeview;
328 messageview->noticeview = noticeview;
329 messageview->mainwin = mainwin;
335 GList *messageview_get_msgview_list(void)
340 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
342 GtkWidget *handlebox;
345 GtkItemFactory *ifactory;
346 guint n_menu_entries;
348 vbox = gtk_vbox_new(FALSE, 0);
349 gtk_widget_show(vbox);
350 gtk_container_add(GTK_CONTAINER(window), vbox);
352 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
353 menubar = menubar_create(window, msgview_entries,
354 n_menu_entries, "<MessageView>", msgview);
355 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
357 handlebox = gtk_handle_box_new();
358 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
359 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
361 msgview->handlebox = handlebox;
362 msgview->menubar = menubar;
364 gtk_container_add(GTK_CONTAINER(vbox),
365 GTK_WIDGET_PTR(msgview));
367 ifactory = gtk_item_factory_from_widget(menubar);
368 action_update_msgview_menu(ifactory, msgview);
370 msgview_list = g_list_append(msgview_list, msgview);
373 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
376 MessageView *msgview;
378 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
379 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
380 gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
381 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
382 gtk_widget_set_usize(window, prefs_common.msgwin_width,
383 prefs_common.msgwin_height);
385 msgview = messageview_create(mainwin);
387 gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
388 GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
390 gtk_signal_connect(GTK_OBJECT(window), "destroy",
391 GTK_SIGNAL_FUNC(messageview_destroy_cb), msgview);
392 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
393 GTK_SIGNAL_FUNC(key_pressed), msgview);
395 messageview_add_toolbar(msgview, window);
397 gtk_widget_grab_focus(msgview->textview->text);
398 gtk_widget_show_all(window);
400 msgview->new_window = TRUE;
401 msgview->window = window;
402 msgview->visible = TRUE;
404 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
405 prefs_common.toolbar_style);
406 messageview_init(msgview);
411 void messageview_init(MessageView *messageview)
413 headerview_init(messageview->headerview);
414 textview_init(messageview->textview);
415 mimeview_init(messageview->mimeview);
416 /*messageview_set_font(messageview);*/
418 noticeview_hide(messageview->noticeview);
421 static void notification_convert_header(gchar *dest, gint len,
427 g_return_if_fail(src_ != NULL);
428 g_return_if_fail(dest != NULL);
432 Xstrndup_a(src, src_, len, return);
436 if (is_ascii_str(src)) {
437 strncpy2(dest, src, len);
438 dest[len - 1] = '\0';
441 conv_encode_header(dest, len, src, header_len, FALSE);
444 static gint disposition_notification_queue(PrefsAccount * account,
445 gchar * to, const gchar *file)
453 debug_print("queueing message...\n");
454 g_return_val_if_fail(account != NULL, -1);
456 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
457 G_DIR_SEPARATOR, (gint)file);
458 if ((fp = fopen(tmp, "wb")) == NULL) {
459 FILE_OP_ERROR(tmp, "fopen");
463 if ((src_fp = fopen(file, "rb")) == NULL) {
464 FILE_OP_ERROR(file, "fopen");
470 if (change_file_mode_rw(fp, tmp) < 0) {
471 FILE_OP_ERROR(tmp, "chmod");
472 g_warning("can't change file mode\n");
475 /* queueing variables */
476 fprintf(fp, "AF:\n");
477 fprintf(fp, "NF:0\n");
478 fprintf(fp, "PS:10\n");
479 fprintf(fp, "SRH:1\n");
480 fprintf(fp, "SFN:\n");
481 fprintf(fp, "DSR:\n");
482 fprintf(fp, "MID:\n");
483 fprintf(fp, "CFG:\n");
484 fprintf(fp, "PT:0\n");
485 fprintf(fp, "S:%s\n", account->address);
486 fprintf(fp, "RQ:\n");
487 if (account->smtp_server)
488 fprintf(fp, "SSV:%s\n", account->smtp_server);
490 fprintf(fp, "SSV:\n");
491 if (account->nntp_server)
492 fprintf(fp, "NSV:%s\n", account->nntp_server);
494 fprintf(fp, "NSV:\n");
495 fprintf(fp, "SSH:\n");
496 fprintf(fp, "R:<%s>", to);
500 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
501 if (fputs(buf, fp) == EOF) {
502 FILE_OP_ERROR(tmp, "fputs");
512 if (fclose(fp) == EOF) {
513 FILE_OP_ERROR(tmp, "fclose");
519 queue = folder_get_default_queue();
520 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
521 g_warning("can't queue the message\n");
531 static gint disposition_notification_send(MsgInfo *msginfo)
534 gchar tmp[MAXPATHLEN + 1];
538 PrefsAccount *account;
542 if ((!msginfo->returnreceiptto) &&
543 (!msginfo->dispositionnotificationto))
546 /* RFC2298: Test for Return-Path */
547 if (msginfo->dispositionnotificationto)
548 to = msginfo->dispositionnotificationto;
550 to = msginfo->returnreceiptto;
552 ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
555 gchar *to_addr = g_strdup(to);
556 extract_address(to_addr);
557 extract_address(buf);
558 ok = strcmp(to_addr, buf);
561 strncpy(buf, _("<No Return-Path found>"),
568 message = g_strdup_printf(
569 _("The notification address to which the "
570 "return receipt is to be sent\n"
571 "does not correspond to the return path:\n"
572 "Notification address: %s\n"
574 "It is advised to not to send the return "
575 "receipt."), to, buf);
576 val = alertpanel(_("Warning"), message, _("Send"),
577 _("+Don't Send"), NULL);
579 if (val != G_ALERTDEFAULT)
583 ac_list = account_find_all_from_address(NULL, msginfo->to);
584 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
586 if (ac_list == NULL) {
587 alertpanel_error(_("This message is asking for a return "
588 "receipt notification\n"
589 "but according to its 'To:' and 'CC:' "
590 "headers it was not\nofficially addressed "
592 "Receipt notification cancelled."));
596 if (g_list_length(ac_list) > 1)
597 account = select_account_from_list(ac_list);
599 account = (PrefsAccount *) ac_list->data;
600 g_list_free(ac_list);
605 /* write to temporary file */
606 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
607 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
609 if ((fp = fopen(tmp, "wb")) == NULL) {
610 FILE_OP_ERROR(tmp, "fopen");
614 /* chmod for security */
615 if (change_file_mode_rw(fp, tmp) < 0) {
616 FILE_OP_ERROR(tmp, "chmod");
617 g_warning("can't change file mode\n");
621 get_rfc822_date(buf, sizeof(buf));
622 fprintf(fp, "Date: %s\n", buf);
625 if (account->name && *account->name) {
626 notification_convert_header
627 (buf, sizeof(buf), account->name,
629 fprintf(fp, "From: %s <%s>\n", buf, account->address);
631 fprintf(fp, "From: %s\n", account->address);
633 fprintf(fp, "To: %s\n", to);
636 notification_convert_header(buf, sizeof(buf), msginfo->subject,
637 strlen("Subject: "));
638 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
640 if (fclose(fp) == EOF) {
641 FILE_OP_ERROR(tmp, "fclose");
646 to_list = address_list_append(NULL, to);
647 ok = send_message(tmp, account, to_list);
650 if (prefs_common.queue_msg) {
655 _("Error occurred while sending the notification.\n"
656 "Put this notification into queue folder?"),
657 _("OK"), _("Cancel"), NULL);
658 if (G_ALERTDEFAULT == val) {
659 ok = disposition_notification_queue(account, to, tmp);
661 alertpanel_error(_("Can't queue the notification."));
664 alertpanel_error_log(_("Error occurred while sending the notification."));
667 if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
672 GList *messageview_get_window_list(void)
674 return messageview_list;
677 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
678 gboolean all_headers)
683 g_return_if_fail(msginfo != NULL);
685 mimeinfo = procmime_scan_message(msginfo);
686 g_return_if_fail(mimeinfo != NULL);
688 file = procmsg_get_message_file_path(msginfo);
690 g_warning("can't get message file path.\n");
691 procmime_mimeinfo_free_all(mimeinfo);
695 if (messageview->msginfo != msginfo) {
696 procmsg_msginfo_free(messageview->msginfo);
697 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
699 headerview_show(messageview->headerview, messageview->msginfo);
701 messageview->all_headers = all_headers;
702 textview_set_all_headers(messageview->textview, all_headers);
703 textview_set_all_headers(messageview->mimeview->textview, all_headers);
705 if (mimeinfo->mime_type != MIME_TEXT) {
706 messageview_change_view_type(messageview, MVIEW_MIME);
707 mimeview_show_message(messageview->mimeview, mimeinfo, file);
709 messageview_change_view_type(messageview, MVIEW_TEXT);
710 textview_show_message(messageview->textview, mimeinfo, file);
711 procmime_mimeinfo_free_all(mimeinfo);
714 if ((messageview->msginfo->dispositionnotificationto ||
715 messageview->msginfo->returnreceiptto) &&
716 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags))
717 return_receipt_show(messageview->noticeview, messageview->msginfo);
719 noticeview_hide(messageview->noticeview);
724 static void messageview_change_view_type(MessageView *messageview,
727 TextView *textview = messageview->textview;
728 MimeView *mimeview = messageview->mimeview;
730 if (messageview->type == type) return;
732 if (type == MVIEW_MIME) {
733 gtkut_container_remove
734 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
735 GTK_WIDGET_PTR(textview));
736 gtk_box_pack_start(GTK_BOX(messageview->vbox),
737 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
738 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
739 GTK_WIDGET_PTR(textview));
740 } else if (type == MVIEW_TEXT) {
741 gtkut_container_remove
742 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
743 GTK_WIDGET_PTR(mimeview));
745 if (mimeview->vbox == GTK_WIDGET_PTR(textview)->parent)
746 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
747 GTK_WIDGET_PTR(textview));
749 gtk_box_pack_start(GTK_BOX(messageview->vbox),
750 GTK_WIDGET_PTR(textview), TRUE, TRUE, 0);
754 messageview->type = type;
757 void messageview_reflect_prefs_pixmap_theme(void)
760 MessageView *msgview;
762 for (cur = msgview_list; cur != NULL; cur = cur->next) {
763 msgview = (MessageView*)cur->data;
764 toolbar_update(TOOLBAR_MSGVIEW, msgview);
765 mimeview_update(msgview->mimeview);
769 void messageview_clear(MessageView *messageview)
771 procmsg_msginfo_free(messageview->msginfo);
772 messageview->msginfo = NULL;
773 messageview_change_view_type(messageview, MVIEW_TEXT);
774 messageview->filtered = FALSE;
775 headerview_clear(messageview->headerview);
776 textview_clear(messageview->textview);
777 noticeview_hide(messageview->noticeview);
780 void messageview_destroy(MessageView *messageview)
782 GtkWidget *textview = GTK_WIDGET_PTR(messageview->textview);
783 GtkWidget *mimeview = GTK_WIDGET_PTR(messageview->mimeview);
785 debug_print("destroy messageview\n");
786 messageview_list = g_list_remove(messageview_list, messageview);
788 headerview_destroy(messageview->headerview);
789 textview_destroy(messageview->textview);
790 mimeview_destroy(messageview->mimeview);
791 noticeview_destroy(messageview->noticeview);
793 procmsg_msginfo_free(messageview->msginfo);
794 toolbar_clear_list(TOOLBAR_MSGVIEW);
795 if (messageview->toolbar) {
796 toolbar_destroy(messageview->toolbar);
797 g_free(messageview->toolbar);
800 msgview_list = g_list_remove(msgview_list, messageview);
804 gtk_widget_unref(textview);
805 gtk_widget_unref(mimeview);
808 void messageview_delete(MessageView *msgview)
810 MsgInfo *msginfo = (MsgInfo*)msgview->msginfo;
811 FolderItem *trash = folder_get_default_trash();
814 g_return_if_fail(msginfo != NULL);
815 g_return_if_fail(trash != NULL);
817 msg_list = folder_item_get_msg_list(msginfo->folder);
819 if (msg_list == NULL) {
820 alertpanel_error(_("Message already removed from folder."));
824 for (; msg_list != NULL; msg_list = msg_list->next) {
825 MsgInfo *msginfo_list = (MsgInfo*)msg_list->data;
827 if (msginfo->msgnum == msginfo_list->msgnum) {
829 if (prefs_common.immediate_exec)
830 folder_item_move_msg(trash, msginfo);
832 procmsg_msginfo_set_to_folder(msginfo, trash);
833 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
834 /* NOTE: does not update to next message in summaryview
838 messageview_update_all(msgview);
845 * scan List of MessageViews checking whether there are any Views holding messages
846 * which need to be updated (another view might have deleted the one this MessagView holds)
848 static void messageview_update_all(MessageView *msgview)
850 MsgInfo *msginfo = (MsgInfo*)msgview->msginfo;
853 g_return_if_fail(msginfo != NULL);
855 for (cur = msgview_list; cur != NULL; cur = cur->next) {
856 MessageView *msgview = (MessageView*)cur->data;
857 MsgInfo *msginfo_list = (MsgInfo*)msgview->msginfo;
859 g_return_if_fail(msginfo != NULL);
861 if (msginfo->msgnum == msginfo_list->msgnum)
862 messageview_update(msgview);
867 * \brief update messageview with currently selected message in summaryview
868 * leave unchanged if summaryview is empty
869 * \param pointer to MessageView
871 static void messageview_update(MessageView *msgview)
873 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
875 g_return_if_fail(summaryview != NULL);
877 if (summaryview->selected) {
878 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
879 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
880 summaryview->selected);
881 g_return_if_fail(msginfo != NULL);
883 messageview_show(msgview, msginfo,
884 msgview->all_headers);
888 void messageview_quote_color_set(void)
892 void messageview_set_font(MessageView *messageview)
894 textview_set_font(messageview->textview, NULL);
897 TextView *messageview_get_current_textview(MessageView *messageview)
899 TextView *text = NULL;
901 if (messageview->type == MVIEW_TEXT)
902 text = messageview->textview;
903 else if (messageview->type == MVIEW_MIME) {
904 if (gtk_notebook_get_current_page
905 (GTK_NOTEBOOK(messageview->mimeview->notebook)) == 0)
906 text = messageview->textview;
907 else if (messageview->mimeview->type == MIMEVIEW_TEXT)
908 text = messageview->mimeview->textview;
914 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
916 if (messageview->type == MVIEW_MIME)
917 return mimeview_get_selected_part(messageview->mimeview);
922 void messageview_copy_clipboard(MessageView *messageview)
926 text = messageview_get_current_textview(messageview);
928 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
931 void messageview_select_all(MessageView *messageview)
935 text = messageview_get_current_textview(messageview);
937 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
940 void messageview_set_position(MessageView *messageview, gint pos)
942 textview_set_position(messageview->textview, pos);
945 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
948 return textview_search_string(messageview->textview, str, case_sens);
952 gboolean messageview_search_string_backward(MessageView *messageview,
956 return textview_search_string_backward(messageview->textview,
961 gboolean messageview_is_visible(MessageView *messageview)
963 return messageview->visible;
966 void messageview_save_as(MessageView *messageview)
968 gchar *filename = NULL;
972 if (!messageview->msginfo) return;
973 msginfo = messageview->msginfo;
975 if (msginfo->subject) {
976 Xstrdup_a(filename, msginfo->subject, return);
977 subst_for_filename(filename);
979 dest = filesel_select_file(_("Save as"), filename);
981 if (is_file_exist(dest)) {
984 aval = alertpanel(_("Overwrite"),
985 _("Overwrite existing file?"),
986 _("OK"), _("Cancel"), NULL);
987 if (G_ALERTDEFAULT != aval) return;
990 src = procmsg_get_message_file(msginfo);
991 if (copy_file(src, dest, TRUE) < 0) {
992 alertpanel_error(_("Can't save the file `%s'."),
998 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
1000 messageview_destroy(messageview);
1003 static void messageview_size_allocate_cb(GtkWidget *widget,
1004 GtkAllocation *allocation)
1006 g_return_if_fail(allocation != NULL);
1008 prefs_common.msgwin_width = allocation->width;
1009 prefs_common.msgwin_height = allocation->height;
1012 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
1013 MessageView *messageview)
1015 if (event && event->keyval == GDK_Escape && messageview->window)
1016 gtk_widget_destroy(messageview->window);
1019 void messageview_toggle_view_real(MessageView *messageview)
1021 MainWindow *mainwin = messageview->mainwin;
1022 union CompositeWin *cwin = &mainwin->win;
1023 GtkWidget *vpaned = NULL;
1024 GtkWidget *container = NULL;
1025 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1027 switch (mainwin->type) {
1029 vpaned = cwin->sep_none.vpaned;
1030 container = cwin->sep_none.hpaned;
1032 case SEPARATE_FOLDER:
1033 vpaned = cwin->sep_folder.vpaned;
1034 container = mainwin->vbox_body;
1036 case SEPARATE_MESSAGE:
1041 if (vpaned->parent != NULL) {
1042 gtk_widget_ref(vpaned);
1043 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1044 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
1045 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
1046 gtk_widget_grab_focus(GTK_WIDGET(messageview->textview->text));
1048 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
1049 gtk_container_add(GTK_CONTAINER(container), vpaned);
1050 gtk_widget_unref(vpaned);
1051 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
1052 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
1056 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1058 noticeview_set_text(noticeview, _("This message asks for a return receipt"));
1059 noticeview_set_button_text(noticeview, _("Send receipt"));
1060 noticeview_set_button_press_callback(noticeview,
1061 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
1062 (gpointer) msginfo);
1063 noticeview_show(noticeview);
1066 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1068 MsgInfo *tmpmsginfo;
1071 file = procmsg_get_message_file_path(msginfo);
1073 g_warning("can't get message file path.\n");
1077 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1078 tmpmsginfo->folder = msginfo->folder;
1079 tmpmsginfo->msgnum = msginfo->msgnum;
1081 if (disposition_notification_send(tmpmsginfo) >= 0) {
1082 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1083 noticeview_hide(noticeview);
1086 procmsg_msginfo_free(tmpmsginfo);
1090 static void select_account_cb(GtkWidget *w, gpointer data)
1092 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
1095 static PrefsAccount *select_account_from_list(GList *ac_list)
1101 g_return_val_if_fail(ac_list != NULL, NULL);
1102 g_return_val_if_fail(ac_list->data != NULL, NULL);
1104 optmenu = gtk_option_menu_new();
1105 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
1108 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1109 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1110 account_id = ((PrefsAccount *) ac_list->data)->account_id;
1111 if (alertpanel_with_widget(
1112 _("Return Receipt Notification"),
1113 _("The message was sent to several of your "
1115 "Please choose which account do you want to "
1116 "use for sending the receipt notification:"),
1117 _("Send Notification"), _("+Cancel"), NULL,
1118 optmenu) != G_ALERTDEFAULT)
1120 return account_find_from_id(account_id);
1124 * \brief return selected messageview text, when nothing is
1125 * selected and message was filtered, return complete text
1127 * \param pointer to Messageview
1129 * \return pointer to text (needs to be free'd by calling func)
1131 gchar *messageview_get_selection(MessageView *msgview)
1135 GtkEditable *edit = NULL;
1138 g_return_val_if_fail(msgview != NULL, NULL);
1140 textview = messageview_get_current_textview(msgview);
1142 edit = GTK_EDITABLE(textview->text);
1143 body_pos = textview->body_pos;
1145 edit = GTK_EDITABLE(msgview->mimeview->textview->text);
1146 body_pos = msgview->mimeview->textview->body_pos;
1149 g_return_val_if_fail(edit != NULL, NULL);
1151 if (edit->has_selection)
1152 text = gtkut_editable_get_selection(edit);
1153 else if (msgview->filtered)
1154 text = gtk_editable_get_chars (edit, body_pos, -1);
1161 static void messageview_delete_cb(MessageView *msgview, guint action, GtkWidget *widget)
1163 messageview_delete(msgview);
1166 static void messageview_menubar_cb(MessageView *msgview, guint action, GtkWidget *widget)
1168 GSList *msginfo_list = NULL;
1172 g_return_if_fail(msgview != NULL);
1174 msginfo = (MsgInfo*)msgview->msginfo;
1175 g_return_if_fail(msginfo != NULL);
1177 msginfo_list = g_slist_append(msginfo_list, msginfo);
1178 g_return_if_fail(msginfo_list);
1180 body = messageview_get_selection(msgview);
1181 compose_reply_mode((ComposeMode)action, msginfo_list, body);
1183 g_slist_free(msginfo_list);
1186 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1188 MessageView *messageview = (MessageView *)data;
1189 messageview_save_as(messageview);
1192 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1194 MessageView *messageview = (MessageView *)data;
1198 if (!messageview->msginfo) return;
1200 cmdline = input_dialog(_("Print"),
1201 _("Enter the print command line:\n"
1202 "(`%s' will be replaced with file name)"),
1203 prefs_common.print_cmd);
1204 if (!cmdline) return;
1205 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1206 strchr(p + 2, '%')) {
1207 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1213 procmsg_print_message(messageview->msginfo, cmdline);
1217 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1219 MessageView *messageview = (MessageView *)data;
1220 gtk_widget_destroy(messageview->window);
1223 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1225 MessageView *messageview = (MessageView *)data;
1226 messageview_copy_clipboard(messageview);
1229 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1231 MessageView *messageview = (MessageView *)data;
1232 messageview_select_all(messageview);
1235 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1237 MessageView *messageview = (MessageView *)data;
1238 message_search(messageview);
1241 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1243 MessageView *messageview = (MessageView *)data;
1244 const gchar *charset;
1246 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1247 charset = conv_get_charset_str((CharSet)action);
1248 g_free(messageview->forced_charset);
1249 messageview->forced_charset = g_strdup(charset);
1250 messageview_show(messageview, messageview->msginfo, FALSE);
1254 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1256 MessageView *messageview = (MessageView *)data;
1257 SourceWindow *srcwin;
1259 if (!messageview->msginfo) return;
1261 srcwin = source_window_create();
1262 source_window_show_msg(srcwin, messageview->msginfo);
1263 source_window_show(srcwin);
1266 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1268 MessageView *messageview = (MessageView *)data;
1269 MsgInfo *msginfo = messageview->msginfo;
1271 if (!msginfo) return;
1272 messageview->msginfo = NULL;
1273 messageview_show(messageview, msginfo,
1274 GTK_CHECK_MENU_ITEM(widget)->active);
1275 procmsg_msginfo_free(msginfo);
1278 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1280 MessageView *messageview = (MessageView *)data;
1281 PrefsAccount *ac = NULL;
1282 FolderItem *item = NULL;
1284 if (messageview->msginfo)
1285 item = messageview->msginfo->folder;
1288 ac = account_find_from_item(item);
1289 if (ac && ac->protocol == A_NNTP &&
1290 item->stype == F_NEWS) {
1291 compose_new(ac, item->path, NULL);
1296 compose_new(ac, NULL, NULL);
1299 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1301 MessageView *messageview = (MessageView *)data;
1302 GSList *mlist = NULL;
1305 ComposeMode mode = (ComposeMode)action;
1307 msginfo = messageview->msginfo;
1308 mlist = g_slist_append(NULL, msginfo);
1310 text = gtkut_editable_get_selection
1311 (GTK_EDITABLE(messageview->textview->text));
1312 if (text && *text == '\0') {
1319 compose_reply(msginfo, prefs_common.reply_with_quote,
1320 FALSE, prefs_common.default_reply_list, FALSE, text);
1322 case COMPOSE_REPLY_WITH_QUOTE:
1323 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
1325 case COMPOSE_REPLY_WITHOUT_QUOTE:
1326 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
1328 case COMPOSE_REPLY_TO_SENDER:
1329 compose_reply(msginfo, prefs_common.reply_with_quote,
1330 FALSE, FALSE, TRUE, text);
1332 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1333 compose_followup_and_reply_to(msginfo,
1334 prefs_common.reply_with_quote,
1335 FALSE, FALSE, text);
1337 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1338 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
1340 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1341 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1343 case COMPOSE_REPLY_TO_ALL:
1344 compose_reply(msginfo, prefs_common.reply_with_quote,
1345 TRUE, FALSE, FALSE, text);
1347 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1348 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
1350 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1351 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1353 case COMPOSE_REPLY_TO_LIST:
1354 compose_reply(msginfo, prefs_common.reply_with_quote,
1355 FALSE, TRUE, FALSE, text);
1357 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1358 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
1360 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1361 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1363 case COMPOSE_FORWARD:
1364 if (prefs_common.forward_as_attachment) {
1365 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, mlist, text);
1368 compose_reply_mode(COMPOSE_FORWARD_INLINE, mlist, text);
1372 case COMPOSE_FORWARD_INLINE:
1373 compose_forward(NULL, msginfo, FALSE, text);
1375 case COMPOSE_FORWARD_AS_ATTACH:
1376 compose_forward_multiple(NULL, mlist);
1378 case COMPOSE_REDIRECT:
1379 compose_redirect(NULL, msginfo);
1382 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1385 /* summary_set_marks_selected(summaryview); */
1387 g_slist_free(mlist);
1390 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1392 MessageView *messageview = (MessageView *)data;
1395 if (!messageview->msginfo) return;
1396 msginfo = messageview->msginfo;
1397 if (!msginfo->folder) return;
1398 if (msginfo->folder->stype != F_OUTBOX &&
1399 msginfo->folder->stype != F_DRAFT &&
1400 msginfo->folder->stype != F_QUEUE) return;
1402 compose_reedit(msginfo);
1405 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1407 addressbook_open(NULL);
1410 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1412 MessageView *messageview = (MessageView *)data;
1416 if (!messageview->msginfo) return;
1417 msginfo = messageview->msginfo;
1418 Xstrdup_a(from, msginfo->from, return);
1419 eliminate_address_comment(from);
1420 extract_address(from);
1421 addressbook_add_contact(msginfo->fromname, from, NULL);
1424 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1426 MessageView *messageview = (MessageView *)data;
1427 gchar *header = NULL;
1430 if (!messageview->msginfo) return;
1432 procmsg_get_filter_keyword(messageview->msginfo, &header, &key,
1433 (PrefsFilterType)action);
1434 prefs_filtering_open(NULL, header, key);
1440 static void about_cb(gpointer data, guint action, GtkWidget *widget)