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"
65 static GList *messageview_list = NULL;
67 static void messageview_change_view_type(MessageView *messageview,
69 static void messageview_destroy_cb (GtkWidget *widget,
70 MessageView *messageview);
71 static void messageview_size_allocate_cb(GtkWidget *widget,
72 GtkAllocation *allocation);
73 static void key_pressed (GtkWidget *widget,
75 MessageView *messageview);
77 static void return_receipt_show (NoticeView *noticeview,
79 static void return_receipt_send_clicked (NoticeView *noticeview,
81 static void save_as_cb (gpointer data,
84 static void print_cb (gpointer data,
87 static void close_cb (gpointer data,
90 static void copy_cb (gpointer data,
93 static void allsel_cb (gpointer data,
96 static void search_cb (gpointer data,
100 static void set_charset_cb (gpointer data,
103 static void view_source_cb (gpointer data,
106 static void show_all_header_cb (gpointer data,
110 static void compose_cb (gpointer data,
113 static void reply_cb (gpointer data,
116 static void reedit_cb (gpointer data,
120 static PrefsAccount *select_account_from_list
122 static void addressbook_open_cb (gpointer data,
125 static void add_address_cb (gpointer data,
128 static void create_filter_cb (gpointer data,
132 static void about_cb (gpointer data,
135 static void messageview_update (MessageView *msgview);
136 static gboolean messageview_update_msg (gpointer source, gpointer data);
138 static GList *msgview_list = NULL;
139 static GtkItemFactoryEntry msgview_entries[] =
141 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
142 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
143 {N_("/_File/_Print..."), NULL, print_cb, 0, NULL},
144 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
145 {N_("/_File/_Close"), NULL, close_cb, 0, NULL},
147 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
148 {N_("/_Edit/_Copy"), NULL, copy_cb, 0, NULL},
149 {N_("/_Edit/Select _all"), NULL, allsel_cb, 0, NULL},
150 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
151 {N_("/_Edit/_Find in current message..."),
152 NULL, search_cb, 0, NULL},
154 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
156 #define CODESET_SEPARATOR \
157 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
158 #define CODESET_ACTION(action) \
159 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
161 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
162 {N_("/_View/_Code set/_Auto detect"),
163 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
165 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
166 CODESET_ACTION(C_US_ASCII)},
169 {N_("/_View/_Code set/Unicode (_UTF-8)"),
170 CODESET_ACTION(C_UTF_8)},
173 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
174 CODESET_ACTION(C_ISO_8859_1)},
175 {N_("/_View/_Code set/Western European (ISO-8859-15)"),
176 CODESET_ACTION(C_ISO_8859_15)},
179 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
180 CODESET_ACTION(C_ISO_8859_2)},
182 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
183 CODESET_ACTION(C_ISO_8859_13)},
184 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
185 CODESET_ACTION(C_ISO_8859_4)},
187 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
188 CODESET_ACTION(C_ISO_8859_7)},
190 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
191 CODESET_ACTION(C_ISO_8859_9)},
193 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
194 CODESET_ACTION(C_ISO_8859_5)},
195 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
196 CODESET_ACTION(C_KOI8_R)},
197 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
198 CODESET_ACTION(C_CP1251)},
201 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
202 CODESET_ACTION(C_ISO_2022_JP)},
204 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
205 CODESET_ACTION(C_ISO_2022_JP_2)},
207 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
208 CODESET_ACTION(C_EUC_JP)},
209 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
210 CODESET_ACTION(C_SHIFT_JIS)},
213 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
214 CODESET_ACTION(C_GB2312)},
215 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
216 CODESET_ACTION(C_BIG5)},
217 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
218 CODESET_ACTION(C_EUC_TW)},
219 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
220 CODESET_ACTION(C_ISO_2022_CN)},
222 {N_("/_View/_Code set/Korean (EUC-_KR)"),
223 CODESET_ACTION(C_EUC_KR)},
224 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
225 CODESET_ACTION(C_ISO_2022_KR)},
227 {N_("/_View/_Code set/Thai (TIS-620)"),
228 CODESET_ACTION(C_TIS_620)},
229 {N_("/_View/_Code set/Thai (Windows-874)"),
230 CODESET_ACTION(C_WINDOWS_874)},
233 #undef CODESET_SEPARATOR
234 #undef CODESET_ACTION
236 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
237 {N_("/_View/Mess_age source"), NULL, view_source_cb, 0, NULL},
238 {N_("/_View/Show all _header"), NULL, show_all_header_cb, 0, "<ToggleItem>"},
240 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
241 {N_("/_Message/Compose _new message"),
242 NULL, compose_cb, 0, NULL},
243 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
244 {N_("/_Message/_Reply"), NULL, reply_cb, COMPOSE_REPLY, NULL},
245 {N_("/_Message/Repl_y to/_all"),
246 NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
247 {N_("/_Message/Repl_y to/_sender"),
248 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
249 {N_("/_Message/Repl_y to/mailing _list"),
250 NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
251 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
252 {N_("/_Message/_Forward"), NULL, reply_cb, COMPOSE_FORWARD, NULL},
253 {N_("/_Message/For_ward as attachment"),
254 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
255 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
256 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
257 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
259 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
260 {N_("/_Tools/_Address book"), NULL, addressbook_open_cb, 0, NULL},
261 {N_("/_Tools/Add sender to address boo_k"),
262 NULL, add_address_cb, 0, NULL},
263 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
264 {N_("/_Tools/_Create filter rule"),
265 NULL, NULL, 0, "<Branch>"},
266 {N_("/_Tools/_Create filter rule/_Automatically"),
267 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
268 {N_("/_Tools/_Create filter rule/by _From"),
269 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
270 {N_("/_Tools/_Create filter rule/by _To"),
271 NULL, create_filter_cb, FILTER_BY_TO, NULL},
272 {N_("/_Tools/_Create filter rule/by _Subject"),
273 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
274 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
275 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
277 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
278 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
281 MessageView *messageview_create(MainWindow *mainwin)
283 MessageView *messageview;
285 HeaderView *headerview;
288 NoticeView *noticeview;
290 debug_print("Creating message view...\n");
291 messageview = g_new0(MessageView, 1);
293 messageview->type = MVIEW_TEXT;
295 headerview = headerview_create();
297 noticeview = noticeview_create(mainwin);
299 textview = textview_create();
300 textview->messageview = messageview;
302 mimeview = mimeview_create(mainwin);
303 mimeview->textview = textview_create();
304 mimeview->textview->messageview = messageview;
305 mimeview->messageview = messageview;
307 vbox = gtk_vbox_new(FALSE, 0);
308 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
310 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
312 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(textview),
314 gtk_widget_show(vbox);
316 /* to remove without destroyed */
317 gtk_widget_ref(GTK_WIDGET_PTR(textview));
318 gtk_widget_ref(GTK_WIDGET_PTR(mimeview));
319 gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
321 messageview->vbox = vbox;
322 messageview->new_window = FALSE;
323 messageview->window = NULL;
324 messageview->headerview = headerview;
325 messageview->textview = textview;
326 messageview->mimeview = mimeview;
327 messageview->noticeview = noticeview;
328 messageview->mainwin = mainwin;
329 messageview->msginfo_update_callback_id =
330 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
336 GList *messageview_get_msgview_list(void)
341 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
343 GtkWidget *handlebox;
346 GtkItemFactory *ifactory;
347 guint n_menu_entries;
349 vbox = gtk_vbox_new(FALSE, 0);
350 gtk_widget_show(vbox);
351 gtk_container_add(GTK_CONTAINER(window), vbox);
353 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
354 menubar = menubar_create(window, msgview_entries,
355 n_menu_entries, "<MessageView>", msgview);
356 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
358 handlebox = gtk_handle_box_new();
359 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
360 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
362 msgview->handlebox = handlebox;
363 msgview->menubar = menubar;
365 gtk_container_add(GTK_CONTAINER(vbox),
366 GTK_WIDGET_PTR(msgview));
368 ifactory = gtk_item_factory_from_widget(menubar);
369 action_update_msgview_menu(ifactory, msgview);
371 msgview_list = g_list_append(msgview_list, msgview);
374 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
377 MessageView *msgview;
379 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
380 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
381 gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
382 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
383 gtk_widget_set_usize(window, prefs_common.msgwin_width,
384 prefs_common.msgwin_height);
386 msgview = messageview_create(mainwin);
388 gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
389 GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
391 gtk_signal_connect(GTK_OBJECT(window), "destroy",
392 GTK_SIGNAL_FUNC(messageview_destroy_cb), msgview);
393 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
394 GTK_SIGNAL_FUNC(key_pressed), msgview);
396 messageview_add_toolbar(msgview, window);
398 gtk_widget_grab_focus(msgview->textview->text);
399 gtk_widget_show_all(window);
401 msgview->new_window = TRUE;
402 msgview->window = window;
403 msgview->visible = TRUE;
405 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
406 prefs_common.toolbar_style);
407 messageview_init(msgview);
412 void messageview_init(MessageView *messageview)
414 headerview_init(messageview->headerview);
415 textview_init(messageview->textview);
416 mimeview_init(messageview->mimeview);
417 /*messageview_set_font(messageview);*/
419 noticeview_hide(messageview->noticeview);
422 static void notification_convert_header(gchar *dest, gint len,
428 g_return_if_fail(src_ != NULL);
429 g_return_if_fail(dest != NULL);
433 Xstrndup_a(src, src_, len, return);
437 if (is_ascii_str(src)) {
438 strncpy2(dest, src, len);
439 dest[len - 1] = '\0';
442 conv_encode_header(dest, len, src, header_len, FALSE);
445 static gint disposition_notification_send(MsgInfo *msginfo)
448 gchar tmp[MAXPATHLEN + 1];
451 PrefsAccount *account;
454 FolderItem *queue, *outbox;
458 if ((!msginfo->returnreceiptto) &&
459 (!msginfo->dispositionnotificationto))
462 /* RFC2298: Test for Return-Path */
463 if (msginfo->dispositionnotificationto)
464 to = msginfo->dispositionnotificationto;
466 to = msginfo->returnreceiptto;
468 ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
471 gchar *to_addr = g_strdup(to);
472 extract_address(to_addr);
473 extract_address(buf);
474 ok = strcmp(to_addr, buf);
477 strncpy(buf, _("<No Return-Path found>"),
484 message = g_strdup_printf(
485 _("The notification address to which the "
486 "return receipt is to be sent\n"
487 "does not correspond to the return path:\n"
488 "Notification address: %s\n"
490 "It is advised to not to send the return "
491 "receipt."), to, buf);
492 val = alertpanel(_("Warning"), message, _("Send"),
493 _("+Don't Send"), NULL);
495 if (val != G_ALERTDEFAULT)
499 ac_list = account_find_all_from_address(NULL, msginfo->to);
500 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
502 if (ac_list == NULL) {
503 alertpanel_error(_("This message is asking for a return "
504 "receipt notification\n"
505 "but according to its 'To:' and 'CC:' "
506 "headers it was not\nofficially addressed "
508 "Receipt notification cancelled."));
512 if (g_list_length(ac_list) > 1)
513 account = select_account_from_list(ac_list);
515 account = (PrefsAccount *) ac_list->data;
516 g_list_free(ac_list);
521 /* write to temporary file */
522 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
523 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
525 if ((fp = fopen(tmp, "wb")) == NULL) {
526 FILE_OP_ERROR(tmp, "fopen");
530 /* chmod for security */
531 if (change_file_mode_rw(fp, tmp) < 0) {
532 FILE_OP_ERROR(tmp, "chmod");
533 g_warning("can't change file mode\n");
536 /* write queue headers */
537 fprintf(fp, "AF:\n");
538 fprintf(fp, "NF:0\n");
539 fprintf(fp, "PS:10\n");
540 fprintf(fp, "SRH:1\n");
541 fprintf(fp, "SFN:\n");
542 fprintf(fp, "DSR:\n");
543 fprintf(fp, "MID:\n");
544 fprintf(fp, "CFG:\n");
545 fprintf(fp, "PT:0\n");
546 fprintf(fp, "S:%s\n", account->address);
547 fprintf(fp, "RQ:\n");
548 if (account->smtp_server)
549 fprintf(fp, "SSV:%s\n", account->smtp_server);
551 fprintf(fp, "SSV:\n");
552 fprintf(fp, "SSH:\n");
553 fprintf(fp, "R:<%s>\n", to);
555 /* check whether we need to save the message */
556 outbox = account_get_special_folder(account, F_OUTBOX);
557 if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
560 path = folder_item_get_identifier(outbox);
561 fprintf(fp, "SCF:%s\n", path);
568 get_rfc822_date(buf, sizeof(buf));
569 fprintf(fp, "Date: %s\n", buf);
572 if (account->name && *account->name) {
573 notification_convert_header
574 (buf, sizeof(buf), account->name,
576 fprintf(fp, "From: %s <%s>\n", buf, account->address);
578 fprintf(fp, "From: %s\n", account->address);
580 fprintf(fp, "To: %s\n", to);
583 notification_convert_header(buf, sizeof(buf), msginfo->subject,
584 strlen("Subject: "));
585 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
588 generate_msgid(account->address, buf, sizeof buf);
589 fprintf(fp, "Message-Id: <%s>\n", buf);
591 if (fclose(fp) == EOF) {
592 FILE_OP_ERROR(tmp, "fclose");
597 /* put it in queue */
598 queue = account_get_special_folder(account, F_QUEUE);
599 if (!queue) queue = folder_get_default_queue();
601 g_warning("can't find queue folder\n");
605 folder_item_scan(queue);
606 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
607 g_warning("can't queue the message\n");
613 path = folder_item_fetch_msg(queue, num);
614 ok = procmsg_send_message_queue(path);
616 folder_item_remove_msg(queue, num);
621 GList *messageview_get_window_list(void)
623 return messageview_list;
626 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
627 gboolean all_headers)
632 g_return_if_fail(msginfo != NULL);
634 mimeinfo = procmime_scan_message(msginfo);
635 g_return_if_fail(mimeinfo != NULL);
637 file = procmsg_get_message_file_path(msginfo);
639 g_warning("can't get message file path.\n");
640 procmime_mimeinfo_free_all(mimeinfo);
644 if (messageview->msginfo != msginfo) {
645 procmsg_msginfo_free(messageview->msginfo);
646 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
648 headerview_show(messageview->headerview, messageview->msginfo);
650 messageview->all_headers = all_headers;
651 textview_set_all_headers(messageview->textview, all_headers);
652 textview_set_all_headers(messageview->mimeview->textview, all_headers);
654 if (mimeinfo->type != MIMETYPE_TEXT) {
655 messageview_change_view_type(messageview, MVIEW_MIME);
656 mimeview_show_message(messageview->mimeview, mimeinfo, file);
658 messageview_change_view_type(messageview, MVIEW_TEXT);
659 textview_show_message(messageview->textview, mimeinfo, file);
660 procmime_mimeinfo_free_all(mimeinfo);
663 if ((messageview->msginfo->dispositionnotificationto ||
664 messageview->msginfo->returnreceiptto) &&
665 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags))
666 return_receipt_show(messageview->noticeview, messageview->msginfo);
668 noticeview_hide(messageview->noticeview);
673 static void messageview_change_view_type(MessageView *messageview,
676 TextView *textview = messageview->textview;
677 MimeView *mimeview = messageview->mimeview;
678 gboolean hadfocus = GTK_WIDGET_HAS_FOCUS(textview->text);
680 if (messageview->type == type) return;
682 if (type == MVIEW_MIME) {
683 gtkut_container_remove
684 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
685 GTK_WIDGET_PTR(textview));
686 gtk_box_pack_start(GTK_BOX(messageview->vbox),
687 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
688 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
689 GTK_WIDGET_PTR(textview));
690 } else if (type == MVIEW_TEXT) {
691 gtkut_container_remove
692 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
693 GTK_WIDGET_PTR(mimeview));
695 if (mimeview->vbox == GTK_WIDGET_PTR(textview)->parent)
696 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
697 GTK_WIDGET_PTR(textview));
699 gtk_box_pack_start(GTK_BOX(messageview->vbox),
700 GTK_WIDGET_PTR(textview), TRUE, TRUE, 0);
703 if (hadfocus) gtk_widget_grab_focus(textview->text);
705 messageview->type = type;
708 void messageview_reflect_prefs_pixmap_theme(void)
711 MessageView *msgview;
713 for (cur = msgview_list; cur != NULL; cur = cur->next) {
714 msgview = (MessageView*)cur->data;
715 toolbar_update(TOOLBAR_MSGVIEW, msgview);
716 mimeview_update(msgview->mimeview);
720 void messageview_clear(MessageView *messageview)
722 procmsg_msginfo_free(messageview->msginfo);
723 messageview->msginfo = NULL;
724 messageview_change_view_type(messageview, MVIEW_TEXT);
725 messageview->filtered = FALSE;
726 headerview_clear(messageview->headerview);
727 textview_clear(messageview->textview);
728 noticeview_hide(messageview->noticeview);
731 void messageview_destroy(MessageView *messageview)
733 GtkWidget *textview = GTK_WIDGET_PTR(messageview->textview);
734 GtkWidget *mimeview = GTK_WIDGET_PTR(messageview->mimeview);
736 debug_print("destroy messageview\n");
737 messageview_list = g_list_remove(messageview_list, messageview);
739 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
740 messageview->msginfo_update_callback_id);
742 headerview_destroy(messageview->headerview);
743 textview_destroy(messageview->textview);
744 mimeview_destroy(messageview->mimeview);
745 noticeview_destroy(messageview->noticeview);
747 procmsg_msginfo_free(messageview->msginfo);
748 toolbar_clear_list(TOOLBAR_MSGVIEW);
749 if (messageview->toolbar) {
750 toolbar_destroy(messageview->toolbar);
751 g_free(messageview->toolbar);
754 msgview_list = g_list_remove(msgview_list, messageview);
758 gtk_widget_unref(textview);
759 gtk_widget_unref(mimeview);
762 void messageview_delete(MessageView *msgview)
764 MsgInfo *msginfo = (MsgInfo *) msgview->msginfo;
765 FolderItem *trash = folder_get_default_trash();
767 g_return_if_fail(msginfo != NULL);
768 g_return_if_fail(trash != NULL);
770 if (prefs_common.immediate_exec)
771 /* TODO: Delete from trash */
772 folder_item_move_msg(trash, msginfo);
774 procmsg_msginfo_set_to_folder(msginfo, trash);
775 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
776 /* NOTE: does not update to next message in summaryview */
781 * \brief update messageview with currently selected message in summaryview
782 * leave unchanged if summaryview is empty
783 * \param pointer to MessageView
785 static void messageview_update(MessageView *msgview)
787 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
789 g_return_if_fail(summaryview != NULL);
791 if (summaryview->selected) {
792 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
793 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
794 summaryview->selected);
795 g_return_if_fail(msginfo != NULL);
797 messageview_show(msgview, msginfo,
798 msgview->all_headers);
802 void messageview_quote_color_set(void)
806 void messageview_set_font(MessageView *messageview)
808 textview_set_font(messageview->textview, NULL);
811 TextView *messageview_get_current_textview(MessageView *messageview)
813 TextView *text = NULL;
815 if (messageview->type == MVIEW_TEXT)
816 text = messageview->textview;
817 else if (messageview->type == MVIEW_MIME) {
818 if (gtk_notebook_get_current_page
819 (GTK_NOTEBOOK(messageview->mimeview->notebook)) == 0)
820 text = messageview->textview;
821 else if (messageview->mimeview->type == MIMEVIEW_TEXT)
822 text = messageview->mimeview->textview;
828 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
830 if (messageview->type == MVIEW_MIME)
831 return mimeview_get_selected_part(messageview->mimeview);
836 void messageview_copy_clipboard(MessageView *messageview)
840 text = messageview_get_current_textview(messageview);
842 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
845 void messageview_select_all(MessageView *messageview)
849 text = messageview_get_current_textview(messageview);
851 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
854 void messageview_set_position(MessageView *messageview, gint pos)
856 textview_set_position(messageview->textview, pos);
859 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
862 return textview_search_string(messageview->textview, str, case_sens);
866 gboolean messageview_search_string_backward(MessageView *messageview,
870 return textview_search_string_backward(messageview->textview,
875 gboolean messageview_is_visible(MessageView *messageview)
877 return messageview->visible;
880 void messageview_save_as(MessageView *messageview)
882 gchar *filename = NULL;
886 if (!messageview->msginfo) return;
887 msginfo = messageview->msginfo;
889 if (msginfo->subject) {
890 Xstrdup_a(filename, msginfo->subject, return);
891 subst_for_filename(filename);
893 dest = filesel_select_file(_("Save as"), filename);
895 if (is_file_exist(dest)) {
898 aval = alertpanel(_("Overwrite"),
899 _("Overwrite existing file?"),
900 _("OK"), _("Cancel"), NULL);
901 if (G_ALERTDEFAULT != aval) return;
904 src = procmsg_get_message_file(msginfo);
905 if (copy_file(src, dest, TRUE) < 0) {
906 alertpanel_error(_("Can't save the file `%s'."),
912 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
914 messageview_destroy(messageview);
917 static void messageview_size_allocate_cb(GtkWidget *widget,
918 GtkAllocation *allocation)
920 g_return_if_fail(allocation != NULL);
922 prefs_common.msgwin_width = allocation->width;
923 prefs_common.msgwin_height = allocation->height;
926 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
927 MessageView *messageview)
929 if (event && event->keyval == GDK_Escape && messageview->window)
930 gtk_widget_destroy(messageview->window);
933 void messageview_toggle_view_real(MessageView *messageview)
935 MainWindow *mainwin = messageview->mainwin;
936 union CompositeWin *cwin = &mainwin->win;
937 GtkWidget *vpaned = NULL;
938 GtkWidget *container = NULL;
939 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
941 switch (mainwin->type) {
943 vpaned = cwin->sep_none.vpaned;
944 container = cwin->sep_none.hpaned;
946 case SEPARATE_FOLDER:
947 vpaned = cwin->sep_folder.vpaned;
948 container = mainwin->vbox_body;
950 case SEPARATE_MESSAGE:
955 if (vpaned->parent != NULL) {
956 gtk_widget_ref(vpaned);
957 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
958 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
959 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
960 gtk_widget_grab_focus(GTK_WIDGET(messageview->textview->text));
962 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
963 gtk_container_add(GTK_CONTAINER(container), vpaned);
964 gtk_widget_unref(vpaned);
965 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
966 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
970 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
972 noticeview_set_text(noticeview, _("This message asks for a return receipt"));
973 noticeview_set_button_text(noticeview, _("Send receipt"));
974 noticeview_set_button_press_callback(noticeview,
975 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
977 noticeview_show(noticeview);
980 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
985 file = procmsg_get_message_file_path(msginfo);
987 g_warning("can't get message file path.\n");
991 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
992 tmpmsginfo->folder = msginfo->folder;
993 tmpmsginfo->msgnum = msginfo->msgnum;
995 if (disposition_notification_send(tmpmsginfo) >= 0) {
996 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
997 noticeview_hide(noticeview);
1000 procmsg_msginfo_free(tmpmsginfo);
1004 static void select_account_cb(GtkWidget *w, gpointer data)
1006 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
1009 static PrefsAccount *select_account_from_list(GList *ac_list)
1015 g_return_val_if_fail(ac_list != NULL, NULL);
1016 g_return_val_if_fail(ac_list->data != NULL, NULL);
1018 optmenu = gtk_option_menu_new();
1019 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
1022 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1023 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1024 account_id = ((PrefsAccount *) ac_list->data)->account_id;
1025 if (alertpanel_with_widget(
1026 _("Return Receipt Notification"),
1027 _("The message was sent to several of your "
1029 "Please choose which account do you want to "
1030 "use for sending the receipt notification:"),
1031 _("Send Notification"), _("+Cancel"), NULL,
1032 optmenu) != G_ALERTDEFAULT)
1034 return account_find_from_id(account_id);
1038 * \brief return selected messageview text, when nothing is
1039 * selected and message was filtered, return complete text
1041 * \param pointer to Messageview
1043 * \return pointer to text (needs to be free'd by calling func)
1045 gchar *messageview_get_selection(MessageView *msgview)
1049 GtkEditable *edit = NULL;
1052 g_return_val_if_fail(msgview != NULL, NULL);
1054 textview = messageview_get_current_textview(msgview);
1056 edit = GTK_EDITABLE(textview->text);
1057 body_pos = textview->body_pos;
1059 edit = GTK_EDITABLE(msgview->mimeview->textview->text);
1060 body_pos = msgview->mimeview->textview->body_pos;
1063 g_return_val_if_fail(edit != NULL, NULL);
1065 if (edit->has_selection)
1066 text = gtkut_editable_get_selection(edit);
1067 else if (msgview->filtered)
1068 text = gtk_editable_get_chars (edit, body_pos, -1);
1075 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1077 MessageView *messageview = (MessageView *)data;
1078 messageview_save_as(messageview);
1081 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1083 MessageView *messageview = (MessageView *)data;
1087 if (!messageview->msginfo) return;
1089 cmdline = input_dialog(_("Print"),
1090 _("Enter the print command line:\n"
1091 "(`%s' will be replaced with file name)"),
1092 prefs_common.print_cmd);
1093 if (!cmdline) return;
1094 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1095 strchr(p + 2, '%')) {
1096 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1102 procmsg_print_message(messageview->msginfo, cmdline);
1106 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1108 MessageView *messageview = (MessageView *)data;
1109 gtk_widget_destroy(messageview->window);
1112 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1114 MessageView *messageview = (MessageView *)data;
1115 messageview_copy_clipboard(messageview);
1118 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1120 MessageView *messageview = (MessageView *)data;
1121 messageview_select_all(messageview);
1124 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1126 MessageView *messageview = (MessageView *)data;
1127 message_search(messageview);
1130 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1132 MessageView *messageview = (MessageView *)data;
1133 const gchar *charset;
1135 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1136 charset = conv_get_charset_str((CharSet)action);
1137 g_free(messageview->forced_charset);
1138 messageview->forced_charset = g_strdup(charset);
1139 messageview_show(messageview, messageview->msginfo, FALSE);
1143 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1145 MessageView *messageview = (MessageView *)data;
1146 SourceWindow *srcwin;
1148 if (!messageview->msginfo) return;
1150 srcwin = source_window_create();
1151 source_window_show_msg(srcwin, messageview->msginfo);
1152 source_window_show(srcwin);
1155 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1157 MessageView *messageview = (MessageView *)data;
1158 MsgInfo *msginfo = messageview->msginfo;
1160 if (!msginfo) return;
1161 messageview->msginfo = NULL;
1162 messageview_show(messageview, msginfo,
1163 GTK_CHECK_MENU_ITEM(widget)->active);
1164 procmsg_msginfo_free(msginfo);
1167 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1169 MessageView *messageview = (MessageView *)data;
1170 PrefsAccount *ac = NULL;
1171 FolderItem *item = NULL;
1173 if (messageview->msginfo)
1174 item = messageview->msginfo->folder;
1177 ac = account_find_from_item(item);
1178 if (ac && ac->protocol == A_NNTP &&
1179 item->stype == F_NEWS) {
1180 compose_new(ac, item->path, NULL);
1185 compose_new(ac, NULL, NULL);
1188 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1190 MessageView *messageview = (MessageView *)data;
1191 GSList *mlist = NULL;
1194 ComposeMode mode = (ComposeMode)action;
1196 msginfo = messageview->msginfo;
1197 mlist = g_slist_append(NULL, msginfo);
1199 text = gtkut_editable_get_selection
1200 (GTK_EDITABLE(messageview->textview->text));
1201 if (text && *text == '\0') {
1208 compose_reply(msginfo, prefs_common.reply_with_quote,
1209 FALSE, prefs_common.default_reply_list, FALSE, text);
1211 case COMPOSE_REPLY_WITH_QUOTE:
1212 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
1214 case COMPOSE_REPLY_WITHOUT_QUOTE:
1215 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
1217 case COMPOSE_REPLY_TO_SENDER:
1218 compose_reply(msginfo, prefs_common.reply_with_quote,
1219 FALSE, FALSE, TRUE, text);
1221 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1222 compose_followup_and_reply_to(msginfo,
1223 prefs_common.reply_with_quote,
1224 FALSE, FALSE, text);
1226 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1227 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
1229 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1230 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1232 case COMPOSE_REPLY_TO_ALL:
1233 compose_reply(msginfo, prefs_common.reply_with_quote,
1234 TRUE, FALSE, FALSE, text);
1236 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1237 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
1239 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1240 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1242 case COMPOSE_REPLY_TO_LIST:
1243 compose_reply(msginfo, prefs_common.reply_with_quote,
1244 FALSE, TRUE, FALSE, text);
1246 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1247 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
1249 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1250 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1252 case COMPOSE_FORWARD:
1253 if (prefs_common.forward_as_attachment) {
1254 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, mlist, text);
1257 compose_reply_mode(COMPOSE_FORWARD_INLINE, mlist, text);
1261 case COMPOSE_FORWARD_INLINE:
1262 compose_forward(NULL, msginfo, FALSE, text);
1264 case COMPOSE_FORWARD_AS_ATTACH:
1265 compose_forward_multiple(NULL, mlist);
1267 case COMPOSE_REDIRECT:
1268 compose_redirect(NULL, msginfo);
1271 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1274 /* summary_set_marks_selected(summaryview); */
1276 g_slist_free(mlist);
1279 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1281 MessageView *messageview = (MessageView *)data;
1284 if (!messageview->msginfo) return;
1285 msginfo = messageview->msginfo;
1286 if (!msginfo->folder) return;
1287 if (msginfo->folder->stype != F_OUTBOX &&
1288 msginfo->folder->stype != F_DRAFT &&
1289 msginfo->folder->stype != F_QUEUE) return;
1291 compose_reedit(msginfo);
1294 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1296 addressbook_open(NULL);
1299 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1301 MessageView *messageview = (MessageView *)data;
1305 if (!messageview->msginfo) return;
1306 msginfo = messageview->msginfo;
1307 Xstrdup_a(from, msginfo->from, return);
1308 eliminate_address_comment(from);
1309 extract_address(from);
1310 addressbook_add_contact(msginfo->fromname, from, NULL);
1313 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1315 MessageView *messageview = (MessageView *)data;
1316 gchar *header = NULL;
1319 if (!messageview->msginfo) return;
1321 procmsg_get_filter_keyword(messageview->msginfo, &header, &key,
1322 (PrefsFilterType)action);
1323 prefs_filtering_open(NULL, header, key);
1329 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1334 static gboolean messageview_update_msg(gpointer source, gpointer data)
1336 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1337 MessageView *messageview = (MessageView *)data;
1339 if (messageview->msginfo != msginfo_update->msginfo)
1342 if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1343 messageview_clear(messageview);
1344 messageview_update(messageview);