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"
55 #include "prefs_common.h"
56 #include "prefs_account.h"
60 #include "send_message.h"
62 #include "stock_pixmap.h"
65 static void messageview_change_view_type(MessageView *messageview,
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 void 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 save_as_cb (gpointer data,
82 static void print_cb (gpointer data,
85 static void close_cb (gpointer data,
88 static void copy_cb (gpointer data,
91 static void allsel_cb (gpointer data,
94 static void search_cb (gpointer data,
98 static void set_charset_cb (gpointer data,
101 static void view_source_cb (gpointer data,
104 static void show_all_header_cb (gpointer data,
108 static void compose_cb (gpointer data,
111 static void reply_cb (gpointer data,
114 static void reedit_cb (gpointer data,
118 static PrefsAccount *select_account_from_list
120 static void addressbook_open_cb (gpointer data,
123 static void add_address_cb (gpointer data,
126 static void create_filter_cb (gpointer data,
130 static void messageview_menubar_cb (MessageView *msgview,
133 static void about_cb (gpointer data,
136 static void messageview_update (MessageView *msgview);
137 static void messageview_update_all (MessageView *msgview);
139 static GList *msgview_list = NULL;
140 static GtkItemFactoryEntry msgview_entries[] =
142 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
143 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
144 {N_("/_File/_Print..."), NULL, print_cb, 0, NULL},
145 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
146 {N_("/_File/_Close"), NULL, close_cb, 0, NULL},
148 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
149 {N_("/_Edit/_Copy"), NULL, copy_cb, 0, NULL},
150 {N_("/_Edit/Select _all"), NULL, allsel_cb, 0, NULL},
151 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
152 {N_("/_Edit/_Find in current message..."),
153 NULL, search_cb, 0, NULL},
155 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
157 #define CODESET_SEPARATOR \
158 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
159 #define CODESET_ACTION(action) \
160 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
162 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
163 {N_("/_View/_Code set/_Auto detect"),
164 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
166 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
167 CODESET_ACTION(C_US_ASCII)},
170 {N_("/_View/_Code set/Unicode (_UTF-8)"),
171 CODESET_ACTION(C_UTF_8)},
174 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
175 CODESET_ACTION(C_ISO_8859_1)},
176 {N_("/_View/_Code set/Western European (ISO-8859-15)"),
177 CODESET_ACTION(C_ISO_8859_15)},
180 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
181 CODESET_ACTION(C_ISO_8859_2)},
183 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
184 CODESET_ACTION(C_ISO_8859_13)},
185 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
186 CODESET_ACTION(C_ISO_8859_4)},
188 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
189 CODESET_ACTION(C_ISO_8859_7)},
191 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
192 CODESET_ACTION(C_ISO_8859_9)},
194 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
195 CODESET_ACTION(C_ISO_8859_5)},
196 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
197 CODESET_ACTION(C_KOI8_R)},
198 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
199 CODESET_ACTION(C_CP1251)},
202 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
203 CODESET_ACTION(C_ISO_2022_JP)},
205 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
206 CODESET_ACTION(C_ISO_2022_JP_2)},
208 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
209 CODESET_ACTION(C_EUC_JP)},
210 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
211 CODESET_ACTION(C_SHIFT_JIS)},
214 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
215 CODESET_ACTION(C_GB2312)},
216 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
217 CODESET_ACTION(C_BIG5)},
218 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
219 CODESET_ACTION(C_EUC_TW)},
220 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
221 CODESET_ACTION(C_ISO_2022_CN)},
223 {N_("/_View/_Code set/Korean (EUC-_KR)"),
224 CODESET_ACTION(C_EUC_KR)},
225 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
226 CODESET_ACTION(C_ISO_2022_KR)},
228 {N_("/_View/_Code set/Thai (TIS-620)"),
229 CODESET_ACTION(C_TIS_620)},
230 {N_("/_View/_Code set/Thai (Windows-874)"),
231 CODESET_ACTION(C_WINDOWS_874)},
234 #undef CODESET_SEPARATOR
235 #undef CODESET_ACTION
237 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
238 {N_("/_View/Mess_age source"), NULL, view_source_cb, 0, NULL},
239 {N_("/_View/Show all _header"), NULL, show_all_header_cb, 0, "<ToggleItem>"},
241 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
242 {N_("/_Message/Compose _new message"),
243 NULL, compose_cb, 0, NULL},
244 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
245 {N_("/_Message/_Reply"), NULL, reply_cb, COMPOSE_REPLY, NULL},
246 {N_("/_Message/Repl_y to/_all"),
247 NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
248 {N_("/_Message/Repl_y to/_sender"),
249 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
250 {N_("/_Message/Repl_y to/mailing _list"),
251 NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
252 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
253 {N_("/_Message/_Forward"), NULL, reply_cb, COMPOSE_FORWARD, NULL},
254 {N_("/_Message/For_ward as attachment"),
255 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
256 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
257 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
258 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
260 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
261 {N_("/_Tools/_Address book"), NULL, addressbook_open_cb, 0, NULL},
262 {N_("/_Tools/Add sender to address boo_k"),
263 NULL, add_address_cb, 0, NULL},
264 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
265 {N_("/_Tools/_Create filter rule"),
266 NULL, NULL, 0, "<Branch>"},
267 {N_("/_Tools/_Create filter rule/_Automatically"),
268 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
269 {N_("/_Tools/_Create filter rule/by _From"),
270 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
271 {N_("/_Tools/_Create filter rule/by _To"),
272 NULL, create_filter_cb, FILTER_BY_TO, NULL},
273 {N_("/_Tools/_Create filter rule/by _Subject"),
274 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
276 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
277 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
280 MessageView *messageview_create(MainWindow *mainwin)
282 MessageView *messageview;
284 HeaderView *headerview;
287 NoticeView *noticeview;
289 debug_print("Creating message view...\n");
290 messageview = g_new0(MessageView, 1);
292 messageview->type = MVIEW_TEXT;
294 headerview = headerview_create();
296 noticeview = noticeview_create(mainwin);
298 textview = textview_create();
299 textview->messageview = messageview;
301 mimeview = mimeview_create();
302 mimeview->textview = textview_create();
303 mimeview->textview->messageview = messageview;
304 mimeview->messageview = messageview;
306 vbox = gtk_vbox_new(FALSE, 0);
307 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
309 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
311 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(textview),
314 /* to remove without destroyed */
315 gtk_widget_ref(GTK_WIDGET_PTR(textview));
316 gtk_widget_ref(GTK_WIDGET_PTR(mimeview));
317 gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
319 messageview->vbox = vbox;
320 messageview->new_window = FALSE;
321 messageview->window = NULL;
322 messageview->headerview = headerview;
323 messageview->textview = textview;
324 messageview->mimeview = mimeview;
325 messageview->noticeview = noticeview;
326 messageview->mainwin = mainwin;
332 GList *messageview_get_msgview_list(void)
337 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
339 GtkWidget *handlebox;
342 guint n_menu_entries;
344 vbox = gtk_vbox_new(FALSE, 0);
345 gtk_widget_show(vbox);
346 gtk_container_add(GTK_CONTAINER(window), vbox);
348 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
349 menubar = menubar_create(window, msgview_entries,
350 n_menu_entries, "<MessageView>", msgview);
351 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
353 handlebox = gtk_handle_box_new();
354 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
355 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
357 msgview->handlebox = handlebox;
358 msgview->menubar = menubar;
360 gtk_container_add(GTK_CONTAINER(vbox),
361 GTK_WIDGET_PTR(msgview));
363 msgview_list = g_list_append(msgview_list, msgview);
366 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
369 MessageView *msgview;
371 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
372 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
373 gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
374 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
375 gtk_widget_set_usize(window, prefs_common.msgwin_width,
376 prefs_common.msgwin_height);
378 msgview = messageview_create(mainwin);
380 gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
381 GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
383 gtk_signal_connect(GTK_OBJECT(window), "destroy",
384 GTK_SIGNAL_FUNC(messageview_destroy_cb), msgview);
385 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
386 GTK_SIGNAL_FUNC(key_pressed), msgview);
388 messageview_add_toolbar(msgview, window);
390 gtk_widget_grab_focus(msgview->textview->text);
391 gtk_widget_show_all(window);
393 msgview->new_window = TRUE;
394 msgview->window = window;
395 msgview->visible = TRUE;
397 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
398 prefs_common.toolbar_style);
399 messageview_init(msgview);
404 void messageview_init(MessageView *messageview)
406 headerview_init(messageview->headerview);
407 textview_init(messageview->textview);
408 mimeview_init(messageview->mimeview);
409 /*messageview_set_font(messageview);*/
411 noticeview_hide(messageview->noticeview);
414 static void notification_convert_header(gchar *dest, gint len,
420 g_return_if_fail(src_ != NULL);
421 g_return_if_fail(dest != NULL);
425 Xstrndup_a(src, src_, len, return);
429 if (is_ascii_str(src)) {
430 strncpy2(dest, src, len);
431 dest[len - 1] = '\0';
434 conv_encode_header(dest, len, src, header_len);
437 static gint disposition_notification_queue(PrefsAccount * account,
438 gchar * to, const gchar *file)
446 debug_print("queueing message...\n");
447 g_return_val_if_fail(account != NULL, -1);
449 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
450 G_DIR_SEPARATOR, (gint)file);
451 if ((fp = fopen(tmp, "wb")) == NULL) {
452 FILE_OP_ERROR(tmp, "fopen");
456 if ((src_fp = fopen(file, "rb")) == NULL) {
457 FILE_OP_ERROR(file, "fopen");
463 if (change_file_mode_rw(fp, tmp) < 0) {
464 FILE_OP_ERROR(tmp, "chmod");
465 g_warning("can't change file mode\n");
468 /* queueing variables */
469 fprintf(fp, "AF:\n");
470 fprintf(fp, "NF:0\n");
471 fprintf(fp, "PS:10\n");
472 fprintf(fp, "SRH:1\n");
473 fprintf(fp, "SFN:\n");
474 fprintf(fp, "DSR:\n");
475 fprintf(fp, "MID:\n");
476 fprintf(fp, "CFG:\n");
477 fprintf(fp, "PT:0\n");
478 fprintf(fp, "S:%s\n", account->address);
479 fprintf(fp, "RQ:\n");
480 if (account->smtp_server)
481 fprintf(fp, "SSV:%s\n", account->smtp_server);
483 fprintf(fp, "SSV:\n");
484 if (account->nntp_server)
485 fprintf(fp, "NSV:%s\n", account->nntp_server);
487 fprintf(fp, "NSV:\n");
488 fprintf(fp, "SSH:\n");
489 fprintf(fp, "R:<%s>", to);
493 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
494 if (fputs(buf, fp) == EOF) {
495 FILE_OP_ERROR(tmp, "fputs");
505 if (fclose(fp) == EOF) {
506 FILE_OP_ERROR(tmp, "fclose");
512 queue = folder_get_default_queue();
513 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
514 g_warning("can't queue the message\n");
524 static gint disposition_notification_send(MsgInfo *msginfo)
527 gchar tmp[MAXPATHLEN + 1];
531 PrefsAccount *account;
535 if ((!msginfo->returnreceiptto) &&
536 (!msginfo->dispositionnotificationto))
539 /* RFC2298: Test for Return-Path */
540 if (msginfo->dispositionnotificationto)
541 to = msginfo->dispositionnotificationto;
543 to = msginfo->returnreceiptto;
545 ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
548 gchar *to_addr = g_strdup(to);
549 extract_address(to_addr);
550 extract_address(buf);
551 ok = strcmp(to_addr, buf);
554 strncpy(buf, _("<No Return-Path found>"),
561 message = g_strdup_printf(
562 _("The notification address to which the "
563 "return receipt is to be sent\n"
564 "does not correspond to the return path:\n"
565 "Notification address: %s\n"
567 "It is advised to not to send the return "
568 "receipt."), to, buf);
569 val = alertpanel(_("Warning"), message, _("Send"),
570 _("+Don't Send"), NULL);
571 if (val != G_ALERTDEFAULT)
575 ac_list = account_find_all_from_address(NULL, msginfo->to);
576 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
578 if (ac_list == NULL) {
579 alertpanel_error(_("This message is asking for a return "
580 "receipt notification\n"
581 "but according to its 'To:' and 'CC:' "
582 "headers it was not\nofficially addressed "
584 "Receipt notification cancelled."));
588 if (g_list_length(ac_list) > 1)
589 account = select_account_from_list(ac_list);
591 account = (PrefsAccount *) ac_list->data;
592 g_list_free(ac_list);
597 /* write to temporary file */
598 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
599 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
601 if ((fp = fopen(tmp, "wb")) == NULL) {
602 FILE_OP_ERROR(tmp, "fopen");
606 /* chmod for security */
607 if (change_file_mode_rw(fp, tmp) < 0) {
608 FILE_OP_ERROR(tmp, "chmod");
609 g_warning("can't change file mode\n");
613 get_rfc822_date(buf, sizeof(buf));
614 fprintf(fp, "Date: %s\n", buf);
617 if (account->name && *account->name) {
618 notification_convert_header
619 (buf, sizeof(buf), account->name,
621 fprintf(fp, "From: %s <%s>\n", buf, account->address);
623 fprintf(fp, "From: %s\n", account->address);
625 fprintf(fp, "To: %s\n", to);
628 notification_convert_header(buf, sizeof(buf), msginfo->subject,
629 strlen("Subject: "));
630 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
632 if (fclose(fp) == EOF) {
633 FILE_OP_ERROR(tmp, "fclose");
638 to_list = address_list_append(NULL, to);
639 ok = send_message(tmp, account, to_list);
642 if (prefs_common.queue_msg) {
647 _("Error occurred while sending the notification.\n"
648 "Put this notification into queue folder?"),
649 _("OK"), _("Cancel"), NULL);
650 if (G_ALERTDEFAULT == val) {
651 ok = disposition_notification_queue(account, to, tmp);
653 alertpanel_error(_("Can't queue the notification."));
656 alertpanel_error_log(_("Error occurred while sending the notification."));
659 if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
664 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
665 gboolean all_headers)
671 g_return_if_fail(msginfo != NULL);
674 if ((fp = procmsg_open_message_decrypted(msginfo, &mimeinfo)) == NULL)
676 #else /* !USE_GPGME */
677 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
678 mimeinfo = procmime_scan_mime_header(fp);
679 #endif /* USE_GPGME */
681 if (!mimeinfo) return;
683 file = procmsg_get_message_file_path(msginfo);
685 g_warning("can't get message file path.\n");
686 procmime_mimeinfo_free_all(mimeinfo);
690 if (messageview->msginfo != msginfo) {
691 procmsg_msginfo_free(messageview->msginfo);
692 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
694 headerview_show(messageview->headerview, messageview->msginfo);
696 messageview->all_headers = all_headers;
697 textview_set_all_headers(messageview->textview, all_headers);
698 textview_set_all_headers(messageview->mimeview->textview, all_headers);
700 if (mimeinfo->mime_type != MIME_TEXT &&
701 mimeinfo->mime_type != MIME_TEXT_HTML) {
702 messageview_change_view_type(messageview, MVIEW_MIME);
703 mimeview_show_message(messageview->mimeview, mimeinfo, file);
705 messageview_change_view_type(messageview, MVIEW_TEXT);
706 textview_show_message(messageview->textview, mimeinfo, file);
707 procmime_mimeinfo_free_all(mimeinfo);
710 if (MSG_IS_RETRCPT_PENDING(msginfo->flags))
711 return_receipt_show(messageview->noticeview, msginfo);
713 noticeview_hide(messageview->noticeview);
718 static void messageview_change_view_type(MessageView *messageview,
721 TextView *textview = messageview->textview;
722 MimeView *mimeview = messageview->mimeview;
724 if (messageview->type == type) return;
726 if (type == MVIEW_MIME) {
727 gtkut_container_remove
728 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
729 GTK_WIDGET_PTR(textview));
730 gtk_box_pack_start(GTK_BOX(messageview->vbox),
731 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
732 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
733 GTK_WIDGET_PTR(textview));
734 } else if (type == MVIEW_TEXT) {
735 gtkut_container_remove
736 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
737 GTK_WIDGET_PTR(mimeview));
739 if (mimeview->vbox == GTK_WIDGET_PTR(textview)->parent)
740 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
741 GTK_WIDGET_PTR(textview));
743 gtk_box_pack_start(GTK_BOX(messageview->vbox),
744 GTK_WIDGET_PTR(textview), TRUE, TRUE, 0);
748 messageview->type = type;
751 void messageview_reflect_prefs_pixmap_theme(void)
754 MessageView *msgview;
756 for (cur = msgview_list; cur != NULL; cur = cur->next) {
757 msgview = (MessageView*)cur->data;
758 toolbar_update(TOOLBAR_MSGVIEW, msgview);
762 void messageview_clear(MessageView *messageview)
764 procmsg_msginfo_free(messageview->msginfo);
765 messageview->msginfo = NULL;
766 messageview_change_view_type(messageview, MVIEW_TEXT);
767 headerview_clear(messageview->headerview);
768 textview_clear(messageview->textview);
769 noticeview_hide(messageview->noticeview);
772 void messageview_destroy(MessageView *messageview)
774 GtkWidget *textview = GTK_WIDGET_PTR(messageview->textview);
775 GtkWidget *mimeview = GTK_WIDGET_PTR(messageview->mimeview);
777 debug_print("destroy messageview\n");
778 headerview_destroy(messageview->headerview);
779 textview_destroy(messageview->textview);
780 mimeview_destroy(messageview->mimeview);
781 noticeview_destroy(messageview->noticeview);
783 procmsg_msginfo_free(messageview->msginfo);
784 toolbar_clear_list(TOOLBAR_MSGVIEW);
785 if (messageview->toolbar) {
786 toolbar_destroy(messageview->toolbar);
787 g_free(messageview->toolbar);
790 msgview_list = g_list_remove(msgview_list, messageview);
794 gtk_widget_unref(textview);
795 gtk_widget_unref(mimeview);
798 void messageview_delete(MessageView *msgview)
800 MsgInfo *msginfo = (MsgInfo*)msgview->msginfo;
801 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
802 FolderItem *trash = folder_get_default_trash();
805 g_return_if_fail(msginfo != NULL);
806 g_return_if_fail(trash != NULL);
808 msg_list = folder_item_get_msg_list(msginfo->folder);
810 if (msg_list == NULL) {
811 alertpanel_error(_("Message already removed from folder."));
815 for (; msg_list != NULL; msg_list = msg_list->next) {
816 MsgInfo *msginfo_list = (MsgInfo*)msg_list->data;
818 if (msginfo->msgnum == msginfo_list->msgnum) {
820 if (prefs_common.immediate_exec)
821 folder_item_move_msg(trash, msginfo);
823 procmsg_msginfo_set_to_folder(msginfo, trash);
824 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
825 /* NOTE: does not update to next message in summaryview
829 messageview_update_all(msgview);
836 * scan List of MessageViews checking whether there are any Views holding messages
837 * which need to be updated (another view might have deleted the one this MessagView holds)
839 static void messageview_update_all(MessageView *msgview)
841 MsgInfo *msginfo = (MsgInfo*)msgview->msginfo;
844 g_return_if_fail(msginfo != NULL);
846 for (cur = msgview_list; cur != NULL; cur = cur->next) {
847 MessageView *msgview = (MessageView*)cur->data;
848 MsgInfo *msginfo_list = (MsgInfo*)msgview->msginfo;
850 g_return_if_fail(msginfo != NULL);
852 if (msginfo->msgnum == msginfo_list->msgnum)
853 messageview_update(msgview);
858 * \brief update messageview with currently selected message in summaryview
859 * leave unchanged if summaryview is empty
860 * \param pointer to MessageView
862 static void messageview_update(MessageView *msgview)
864 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
866 g_return_if_fail(summaryview != NULL);
868 if (summaryview->selected) {
869 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
870 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
871 summaryview->selected);
872 g_return_if_fail(msginfo != NULL);
874 messageview_show(msgview, msginfo,
875 msgview->all_headers);
879 void messageview_quote_color_set(void)
883 void messageview_set_font(MessageView *messageview)
885 textview_set_font(messageview->textview, NULL);
888 TextView *messageview_get_current_textview(MessageView *messageview)
890 TextView *text = NULL;
892 if (messageview->type == MVIEW_TEXT)
893 text = messageview->textview;
894 else if (messageview->type == MVIEW_MIME) {
895 if (gtk_notebook_get_current_page
896 (GTK_NOTEBOOK(messageview->mimeview->notebook)) == 0)
897 text = messageview->textview;
898 else if (messageview->mimeview->type == MIMEVIEW_TEXT)
899 text = messageview->mimeview->textview;
905 void messageview_copy_clipboard(MessageView *messageview)
909 text = messageview_get_current_textview(messageview);
911 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
914 void messageview_select_all(MessageView *messageview)
918 text = messageview_get_current_textview(messageview);
920 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
923 void messageview_set_position(MessageView *messageview, gint pos)
925 textview_set_position(messageview->textview, pos);
928 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
931 return textview_search_string(messageview->textview, str, case_sens);
935 gboolean messageview_search_string_backward(MessageView *messageview,
939 return textview_search_string_backward(messageview->textview,
944 gboolean messageview_is_visible(MessageView *messageview)
946 return messageview->visible;
949 void messageview_save_as(MessageView *messageview)
951 gchar *filename = NULL;
955 if (!messageview->msginfo) return;
956 msginfo = messageview->msginfo;
958 if (msginfo->subject) {
959 Xstrdup_a(filename, msginfo->subject, return);
960 subst_for_filename(filename);
962 dest = filesel_select_file(_("Save as"), filename);
964 if (is_file_exist(dest)) {
967 aval = alertpanel(_("Overwrite"),
968 _("Overwrite existing file?"),
969 _("OK"), _("Cancel"), NULL);
970 if (G_ALERTDEFAULT != aval) return;
973 src = procmsg_get_message_file(msginfo);
974 if (copy_file(src, dest, TRUE) < 0) {
975 alertpanel_error(_("Can't save the file `%s'."),
981 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
983 messageview_destroy(messageview);
986 static void messageview_size_allocate_cb(GtkWidget *widget,
987 GtkAllocation *allocation)
989 g_return_if_fail(allocation != NULL);
991 prefs_common.msgwin_width = allocation->width;
992 prefs_common.msgwin_height = allocation->height;
995 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
996 MessageView *messageview)
998 if (event && event->keyval == GDK_Escape && messageview->window)
999 gtk_widget_destroy(messageview->window);
1002 void messageview_toggle_view_real(MessageView *messageview)
1004 MainWindow *mainwin = messageview->mainwin;
1005 union CompositeWin *cwin = &mainwin->win;
1006 GtkWidget *vpaned = NULL;
1007 GtkWidget *container = NULL;
1008 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1010 switch (mainwin->type) {
1012 vpaned = cwin->sep_none.vpaned;
1013 container = cwin->sep_none.hpaned;
1015 case SEPARATE_FOLDER:
1016 vpaned = cwin->sep_folder.vpaned;
1017 container = mainwin->vbox_body;
1019 case SEPARATE_MESSAGE:
1024 if (vpaned->parent != NULL) {
1025 gtk_widget_ref(vpaned);
1026 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1027 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
1028 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
1029 gtk_widget_grab_focus(GTK_WIDGET(messageview->textview->text));
1031 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
1032 gtk_container_add(GTK_CONTAINER(container), vpaned);
1033 gtk_widget_unref(vpaned);
1034 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
1035 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
1039 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1041 noticeview_set_text(noticeview, _("This messages asks for a return receipt."));
1042 noticeview_set_button_text(noticeview, _("Send receipt"));
1043 noticeview_set_button_press_callback(noticeview,
1044 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
1045 (gpointer) msginfo);
1046 noticeview_show(noticeview);
1049 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1051 MsgInfo *tmpmsginfo;
1054 file = procmsg_get_message_file_path(msginfo);
1056 g_warning("can't get message file path.\n");
1060 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1061 tmpmsginfo->folder = msginfo->folder;
1062 tmpmsginfo->msgnum = msginfo->msgnum;
1064 if (disposition_notification_send(tmpmsginfo) >= 0) {
1065 procmsg_msginfo_unset_flags(msginfo, MSG_RETRCPT_PENDING, 0);
1066 noticeview_hide(noticeview);
1069 procmsg_msginfo_free(tmpmsginfo);
1073 static void select_account_cb(GtkWidget *w, gpointer data)
1075 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
1078 static PrefsAccount *select_account_from_list(GList *ac_list)
1084 g_return_val_if_fail(ac_list != NULL, NULL);
1085 g_return_val_if_fail(ac_list->data != NULL, NULL);
1087 optmenu = gtk_option_menu_new();
1088 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
1091 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1092 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1093 account_id = ((PrefsAccount *) ac_list->data)->account_id;
1094 if (alertpanel_with_widget(
1095 _("Return Receipt Notification"),
1096 _("The message was sent to several of your "
1098 "Please choose which account do you want to "
1099 "use for sending the receipt notification:"),
1100 _("Send Notification"), _("+Cancel"), NULL,
1101 optmenu) != G_ALERTDEFAULT)
1103 return account_find_from_id(account_id);
1108 * \brief return selected messageview text used by composing
1109 * to reply to selected text only
1111 * \param pointer to Messageview
1113 * \return pointer to text (needs to be free'd by calling func)
1115 gchar *messageview_get_selection(MessageView *msgview)
1119 g_return_val_if_fail(msgview != NULL, NULL);
1121 text = gtkut_editable_get_selection
1122 (GTK_EDITABLE(msgview->textview->text));
1124 if (!text && msgview->type == MVIEW_MIME
1125 && msgview->mimeview->type == MIMEVIEW_TEXT
1126 && msgview->mimeview->textview
1127 && !msgview->mimeview->textview->default_text) {
1128 text = gtkut_editable_get_selection
1129 (GTK_EDITABLE(msgview->mimeview->textview->text));
1135 static void messageview_delete_cb(MessageView *msgview, guint action, GtkWidget *widget)
1137 messageview_delete(msgview);
1140 static void messageview_menubar_cb(MessageView *msgview, guint action, GtkWidget *widget)
1142 GSList *msginfo_list = NULL;
1146 g_return_if_fail(msgview != NULL);
1148 msginfo = (MsgInfo*)msgview->msginfo;
1149 g_return_if_fail(msginfo != NULL);
1151 msginfo_list = g_slist_append(msginfo_list, msginfo);
1152 g_return_if_fail(msginfo_list);
1154 body = messageview_get_selection(msgview);
1155 compose_reply_mode((ComposeMode)action, msginfo_list, body);
1157 g_slist_free(msginfo_list);
1160 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1162 MessageView *messageview = (MessageView *)data;
1163 messageview_save_as(messageview);
1166 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1168 MessageView *messageview = (MessageView *)data;
1172 if (!messageview->msginfo) return;
1174 cmdline = input_dialog(_("Print"),
1175 _("Enter the print command line:\n"
1176 "(`%s' will be replaced with file name)"),
1177 prefs_common.print_cmd);
1178 if (!cmdline) return;
1179 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1180 strchr(p + 2, '%')) {
1181 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1187 procmsg_print_message(messageview->msginfo, cmdline);
1191 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1193 MessageView *messageview = (MessageView *)data;
1194 gtk_widget_destroy(messageview->window);
1197 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1199 MessageView *messageview = (MessageView *)data;
1200 messageview_copy_clipboard(messageview);
1203 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1205 MessageView *messageview = (MessageView *)data;
1206 messageview_select_all(messageview);
1209 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1211 MessageView *messageview = (MessageView *)data;
1212 message_search(messageview);
1215 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1217 MessageView *messageview = (MessageView *)data;
1218 const gchar *charset;
1220 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1221 charset = conv_get_charset_str((CharSet)action);
1222 g_free(messageview->forced_charset);
1223 messageview->forced_charset = g_strdup(charset);
1224 messageview_show(messageview, messageview->msginfo, FALSE);
1228 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1230 MessageView *messageview = (MessageView *)data;
1231 SourceWindow *srcwin;
1233 if (!messageview->msginfo) return;
1235 srcwin = source_window_create();
1236 source_window_show_msg(srcwin, messageview->msginfo);
1237 source_window_show(srcwin);
1240 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1242 MessageView *messageview = (MessageView *)data;
1243 MsgInfo *msginfo = messageview->msginfo;
1245 if (!msginfo) return;
1246 messageview->msginfo = NULL;
1247 messageview_show(messageview, msginfo,
1248 GTK_CHECK_MENU_ITEM(widget)->active);
1249 procmsg_msginfo_free(msginfo);
1252 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1254 MessageView *messageview = (MessageView *)data;
1255 PrefsAccount *ac = NULL;
1256 FolderItem *item = NULL;
1258 if (messageview->msginfo)
1259 item = messageview->msginfo->folder;
1262 ac = account_find_from_item(item);
1263 if (ac && ac->protocol == A_NNTP &&
1264 item->stype == F_NEWS) {
1265 compose_new(ac, item->path, NULL);
1270 compose_new(ac, NULL, NULL);
1273 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1275 MessageView *messageview = (MessageView *)data;
1276 GSList *mlist = NULL;
1279 ComposeMode mode = (ComposeMode)action;
1281 msginfo = messageview->msginfo;
1282 mlist = g_slist_append(NULL, msginfo);
1284 text = gtkut_editable_get_selection
1285 (GTK_EDITABLE(messageview->textview->text));
1286 if (text && *text == '\0') {
1293 compose_reply(msginfo, prefs_common.reply_with_quote,
1294 FALSE, prefs_common.default_reply_list, FALSE, text);
1296 case COMPOSE_REPLY_WITH_QUOTE:
1297 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
1299 case COMPOSE_REPLY_WITHOUT_QUOTE:
1300 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
1302 case COMPOSE_REPLY_TO_SENDER:
1303 compose_reply(msginfo, prefs_common.reply_with_quote,
1304 FALSE, FALSE, TRUE, text);
1306 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1307 compose_followup_and_reply_to(msginfo,
1308 prefs_common.reply_with_quote,
1309 FALSE, FALSE, text);
1311 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1312 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
1314 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1315 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1317 case COMPOSE_REPLY_TO_ALL:
1318 compose_reply(msginfo, prefs_common.reply_with_quote,
1319 TRUE, FALSE, FALSE, text);
1321 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1322 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
1324 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1325 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1327 case COMPOSE_REPLY_TO_LIST:
1328 compose_reply(msginfo, prefs_common.reply_with_quote,
1329 FALSE, TRUE, FALSE, text);
1331 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1332 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
1334 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1335 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1337 case COMPOSE_FORWARD:
1338 if (prefs_common.forward_as_attachment) {
1339 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, mlist, text);
1342 compose_reply_mode(COMPOSE_FORWARD_INLINE, mlist, text);
1346 case COMPOSE_FORWARD_INLINE:
1347 compose_forward(NULL, msginfo, FALSE, text);
1349 case COMPOSE_FORWARD_AS_ATTACH:
1350 compose_forward_multiple(NULL, mlist);
1352 case COMPOSE_REDIRECT:
1353 compose_redirect(NULL, msginfo);
1356 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1359 /* summary_set_marks_selected(summaryview); */
1361 g_slist_free(mlist);
1364 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1366 MessageView *messageview = (MessageView *)data;
1369 if (!messageview->msginfo) return;
1370 msginfo = messageview->msginfo;
1371 if (!msginfo->folder) return;
1372 if (msginfo->folder->stype != F_OUTBOX &&
1373 msginfo->folder->stype != F_DRAFT &&
1374 msginfo->folder->stype != F_QUEUE) return;
1376 compose_reedit(msginfo);
1379 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1381 addressbook_open(NULL);
1384 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1386 MessageView *messageview = (MessageView *)data;
1390 if (!messageview->msginfo) return;
1391 msginfo = messageview->msginfo;
1392 Xstrdup_a(from, msginfo->from, return);
1393 eliminate_address_comment(from);
1394 extract_address(from);
1395 addressbook_add_contact(msginfo->fromname, from, NULL);
1398 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1400 MessageView *messageview = (MessageView *)data;
1401 gchar *header = NULL;
1404 if (!messageview->msginfo) return;
1406 procmsg_get_filter_keyword(messageview->msginfo, &header, &key,
1407 (PrefsFilterType)action);
1408 prefs_filtering_open(NULL, header, key);
1414 static void about_cb(gpointer data, guint action, GtkWidget *widget)