2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 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 #include "filtering.h"
66 static GList *messageview_list = NULL;
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 gboolean key_pressed (GtkWidget *widget,
74 MessageView *messageview);
76 static void return_receipt_show (NoticeView *noticeview,
78 static void return_receipt_send_clicked (NoticeView *noticeview,
80 static void 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,
130 static void create_processing_cb (gpointer data,
134 static void about_cb (gpointer data,
137 static void messageview_update (MessageView *msgview);
138 static gboolean messageview_update_msg (gpointer source, gpointer data);
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 (KOI8-U)"),
200 CODESET_ACTION(C_KOI8_U)},
201 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
202 CODESET_ACTION(C_CP1251)},
205 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
206 CODESET_ACTION(C_ISO_2022_JP)},
208 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
209 CODESET_ACTION(C_ISO_2022_JP_2)},
211 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
212 CODESET_ACTION(C_EUC_JP)},
213 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
214 CODESET_ACTION(C_SHIFT_JIS)},
217 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
218 CODESET_ACTION(C_GB2312)},
219 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
220 CODESET_ACTION(C_BIG5)},
221 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
222 CODESET_ACTION(C_EUC_TW)},
223 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
224 CODESET_ACTION(C_ISO_2022_CN)},
226 {N_("/_View/_Code set/Korean (EUC-_KR)"),
227 CODESET_ACTION(C_EUC_KR)},
228 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
229 CODESET_ACTION(C_ISO_2022_KR)},
231 {N_("/_View/_Code set/Thai (TIS-620)"),
232 CODESET_ACTION(C_TIS_620)},
233 {N_("/_View/_Code set/Thai (Windows-874)"),
234 CODESET_ACTION(C_WINDOWS_874)},
237 #undef CODESET_SEPARATOR
238 #undef CODESET_ACTION
240 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
241 {N_("/_View/Mess_age source"), NULL, view_source_cb, 0, NULL},
242 {N_("/_View/Show all _headers"),NULL, show_all_header_cb, 0, "<ToggleItem>"},
244 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
245 {N_("/_Message/Compose _new message"),
246 NULL, compose_cb, 0, NULL},
247 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
248 {N_("/_Message/_Reply"), NULL, reply_cb, COMPOSE_REPLY, NULL},
249 {N_("/_Message/Repl_y to/_all"),
250 NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
251 {N_("/_Message/Repl_y to/_sender"),
252 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
253 {N_("/_Message/Repl_y to/mailing _list"),
254 NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
255 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
256 {N_("/_Message/_Forward"), NULL, reply_cb, COMPOSE_FORWARD, NULL},
257 {N_("/_Message/For_ward as attachment"),
258 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
259 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
260 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
261 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
263 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
264 {N_("/_Tools/_Address book"), NULL, addressbook_open_cb, 0, NULL},
265 {N_("/_Tools/Add sender to address boo_k"),
266 NULL, add_address_cb, 0, NULL},
267 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
268 {N_("/_Tools/_Create filter rule"),
269 NULL, NULL, 0, "<Branch>"},
270 {N_("/_Tools/_Create filter rule/_Automatically"),
271 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
272 {N_("/_Tools/_Create filter rule/by _From"),
273 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
274 {N_("/_Tools/_Create filter rule/by _To"),
275 NULL, create_filter_cb, FILTER_BY_TO, NULL},
276 {N_("/_Tools/_Create filter rule/by _Subject"),
277 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
278 {N_("/_Tools/Create processing rule/"),
279 NULL, NULL, 0, "<Branch>"},
280 {N_("/_Tools/Create processing rule/_Automatically"),
281 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
282 {N_("/_Tools/Create processing rule/by _From"),
283 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
284 {N_("/_Tools/Create processing rule/by _To"),
285 NULL, create_processing_cb, FILTER_BY_TO, NULL},
286 {N_("/_Tools/Create processing rule/by _Subject"),
287 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
288 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
289 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
291 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
292 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
295 MessageView *messageview_create(MainWindow *mainwin)
297 MessageView *messageview;
299 HeaderView *headerview;
301 NoticeView *noticeview;
303 debug_print("Creating message view...\n");
304 messageview = g_new0(MessageView, 1);
306 headerview = headerview_create();
308 noticeview = noticeview_create(mainwin);
310 mimeview = mimeview_create(mainwin);
311 mimeview->textview = textview_create();
312 mimeview->textview->messageview = messageview;
313 mimeview->messageview = messageview;
315 vbox = gtk_vbox_new(FALSE, 0);
316 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
318 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
320 gtk_box_pack_start(GTK_BOX(vbox),
321 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
322 gtk_widget_show(vbox);
324 messageview->vbox = vbox;
325 messageview->new_window = FALSE;
326 messageview->window = NULL;
327 messageview->headerview = headerview;
328 messageview->mimeview = mimeview;
329 messageview->noticeview = noticeview;
330 messageview->mainwin = mainwin;
332 messageview->statusbar = NULL;
333 messageview->statusbar_cid = 0;
335 messageview->msginfo_update_callback_id =
336 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
341 GList *messageview_get_msgview_list(void)
346 void messageview_update_actions_menu(MessageView *msgview)
348 GtkItemFactory *ifactory;
350 /* Messages opened in a new window do not have a menu bar */
351 if (msgview->menubar == NULL)
353 ifactory = gtk_item_factory_from_widget(msgview->menubar);
354 action_update_msgview_menu(ifactory, "/Tools/Actions", msgview);
357 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
359 GtkWidget *handlebox;
362 GtkWidget *statusbar;
363 guint n_menu_entries;
365 vbox = gtk_vbox_new(FALSE, 0);
366 gtk_widget_show(vbox);
367 gtk_container_add(GTK_CONTAINER(window), vbox);
369 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
370 menubar = menubar_create(window, msgview_entries,
371 n_menu_entries, "<MessageView>", msgview);
372 gtk_widget_show(menubar);
373 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
375 handlebox = gtk_handle_box_new();
376 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
377 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
380 statusbar = gtk_statusbar_new();
381 gtk_widget_show(statusbar);
382 gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
383 msgview->statusbar = statusbar;
384 msgview->statusbar_cid = gtk_statusbar_get_context_id
385 (GTK_STATUSBAR(statusbar), "Message View");
387 msgview->handlebox = handlebox;
388 msgview->menubar = menubar;
390 gtk_container_add(GTK_CONTAINER(vbox),
391 GTK_WIDGET_PTR(msgview));
393 messageview_update_actions_menu(msgview);
395 msgview_list = g_list_append(msgview_list, msgview);
398 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
400 MessageView *msgview;
403 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
404 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
405 gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
406 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
407 gtk_widget_set_size_request(window, prefs_common.msgwin_width,
408 prefs_common.msgwin_height);
410 msgview = messageview_create(mainwin);
412 g_signal_connect(G_OBJECT(window), "size_allocate",
413 G_CALLBACK(messageview_size_allocate_cb),
415 g_signal_connect(G_OBJECT(window), "destroy",
416 G_CALLBACK(messageview_destroy_cb), msgview);
417 g_signal_connect(G_OBJECT(window), "key_press_event",
418 G_CALLBACK(key_pressed), msgview);
420 messageview_add_toolbar(msgview, window);
422 gtk_widget_grab_focus(msgview->mimeview->textview->text);
423 gtk_widget_show(window);
425 msgview->new_window = TRUE;
426 msgview->window = window;
427 msgview->visible = TRUE;
429 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
430 prefs_common.toolbar_style);
431 messageview_init(msgview);
436 void messageview_init(MessageView *messageview)
438 headerview_init(messageview->headerview);
439 mimeview_init(messageview->mimeview);
440 /*messageview_set_font(messageview);*/
442 noticeview_hide(messageview->noticeview);
445 static void notification_convert_header(gchar *dest, gint len,
451 g_return_if_fail(src_ != NULL);
452 g_return_if_fail(dest != NULL);
456 Xstrndup_a(src, src_, len, return);
460 if (is_ascii_str(src)) {
461 strncpy2(dest, src, len);
462 dest[len - 1] = '\0';
465 conv_encode_header(dest, len, src, header_len, FALSE);
468 static gint disposition_notification_send(MsgInfo *msginfo)
471 gchar tmp[MAXPATHLEN + 1];
474 PrefsAccount *account;
477 FolderItem *queue, *outbox;
483 if ((!msginfo->returnreceiptto) &&
484 (!msginfo->dispositionnotificationto))
487 /* RFC2298: Test for Return-Path */
488 if (msginfo->dispositionnotificationto)
489 to = msginfo->dispositionnotificationto;
491 to = msginfo->returnreceiptto;
493 ok = procheader_get_header_from_msginfo(msginfo, buf, sizeof(buf),
496 gchar *to_addr = g_strdup(to);
497 extract_address(to_addr);
498 extract_address(buf);
499 ok = strcmp(to_addr, buf);
502 strncpy(buf, _("<No Return-Path found>"),
509 message = g_strdup_printf(
510 _("The notification address to which the "
511 "return receipt is to be sent\n"
512 "does not correspond to the return path:\n"
513 "Notification address: %s\n"
515 "It is advised to not to send the return "
516 "receipt."), to, buf);
517 val = alertpanel(_("Warning"), message, _("Send"),
518 _("+Don't Send"), NULL);
520 if (val != G_ALERTDEFAULT)
524 ac_list = account_find_all_from_address(NULL, msginfo->to);
525 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
527 if (ac_list == NULL) {
528 alertpanel_error(_("This message is asking for a return "
529 "receipt notification\n"
530 "but according to its 'To:' and 'CC:' "
531 "headers it was not\nofficially addressed "
533 "Receipt notification cancelled."));
537 if (g_list_length(ac_list) > 1)
538 account = select_account_from_list(ac_list);
540 account = (PrefsAccount *) ac_list->data;
541 g_list_free(ac_list);
546 /* write to temporary file */
547 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
548 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
550 if ((fp = fopen(tmp, "wb")) == NULL) {
551 FILE_OP_ERROR(tmp, "fopen");
555 /* chmod for security */
556 if (change_file_mode_rw(fp, tmp) < 0) {
557 FILE_OP_ERROR(tmp, "chmod");
558 g_warning("can't change file mode\n");
563 extract_address(addr);
566 /* write queue headers */
567 fprintf(fp, "AF:\n");
568 fprintf(fp, "NF:0\n");
569 fprintf(fp, "PS:10\n");
570 fprintf(fp, "SRH:1\n");
571 fprintf(fp, "SFN:\n");
572 fprintf(fp, "DSR:\n");
573 fprintf(fp, "MID:\n");
574 fprintf(fp, "CFG:\n");
575 fprintf(fp, "PT:0\n");
576 fprintf(fp, "S:%s\n", account->address);
577 fprintf(fp, "RQ:\n");
578 if (account->smtp_server)
579 fprintf(fp, "SSV:%s\n", account->smtp_server);
581 fprintf(fp, "SSV:\n");
582 fprintf(fp, "SSH:\n");
583 fprintf(fp, "R:<%s>\n", addrp);
587 /* check whether we need to save the message */
588 outbox = account_get_special_folder(account, F_OUTBOX);
589 if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
592 path = folder_item_get_identifier(outbox);
593 fprintf(fp, "SCF:%s\n", path);
600 get_rfc822_date(buf, sizeof(buf));
601 fprintf(fp, "Date: %s\n", buf);
604 if (account->name && *account->name) {
605 notification_convert_header
606 (buf, sizeof(buf), account->name,
608 fprintf(fp, "From: %s <%s>\n", buf, account->address);
610 fprintf(fp, "From: %s\n", account->address);
612 fprintf(fp, "To: %s\n", to);
615 notification_convert_header(buf, sizeof(buf), msginfo->subject,
616 strlen("Subject: "));
617 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
620 generate_msgid(account->address, buf, sizeof buf);
621 fprintf(fp, "Message-Id: <%s>\n", buf);
623 if (fclose(fp) == EOF) {
624 FILE_OP_ERROR(tmp, "fclose");
629 /* put it in queue */
630 queue = account_get_special_folder(account, F_QUEUE);
631 if (!queue) queue = folder_get_default_queue();
633 g_warning("can't find queue folder\n");
637 folder_item_scan(queue);
638 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
639 g_warning("can't queue the message\n");
645 path = folder_item_fetch_msg(queue, num);
646 ok = procmsg_send_message_queue(path);
648 folder_item_remove_msg(queue, num);
653 GList *messageview_get_window_list(void)
655 return messageview_list;
658 static gboolean find_encrypted_func(GNode *node, gpointer data)
660 MimeInfo *mimeinfo = (MimeInfo *) node->data;
661 MimeInfo **encinfo = (MimeInfo **) data;
663 if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
671 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
673 MimeInfo *encinfo = NULL;
675 g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
676 find_encrypted_func, &encinfo);
681 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
682 gboolean all_headers)
685 MimeInfo *mimeinfo, *encinfo;
687 g_return_val_if_fail(msginfo != NULL, -1);
689 mimeinfo = procmime_scan_message(msginfo);
691 textview_show_error(messageview->mimeview->textview);
695 while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
696 debug_print("decrypting message part\n");
697 if (privacy_mimeinfo_decrypt(encinfo) < 0)
701 file = procmsg_get_message_file_path(msginfo);
703 g_warning("can't get message file path.\n");
704 procmime_mimeinfo_free_all(mimeinfo);
705 textview_show_error(messageview->mimeview->textview);
709 if (messageview->msginfo != msginfo) {
710 procmsg_msginfo_free(messageview->msginfo);
711 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
713 headerview_show(messageview->headerview, messageview->msginfo);
715 messageview->all_headers = all_headers;
716 textview_set_all_headers(messageview->mimeview->textview, all_headers);
718 mimeview_show_message(messageview->mimeview, mimeinfo, file);
720 if ((messageview->msginfo->dispositionnotificationto ||
721 messageview->msginfo->returnreceiptto) &&
722 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags))
723 return_receipt_show(messageview->noticeview, messageview->msginfo);
725 noticeview_hide(messageview->noticeview);
732 void messageview_reflect_prefs_pixmap_theme(void)
735 MessageView *msgview;
737 for (cur = msgview_list; cur != NULL; cur = cur->next) {
738 msgview = (MessageView*)cur->data;
739 toolbar_update(TOOLBAR_MSGVIEW, msgview);
740 mimeview_update(msgview->mimeview);
744 void messageview_clear(MessageView *messageview)
746 procmsg_msginfo_free(messageview->msginfo);
747 messageview->msginfo = NULL;
748 messageview->filtered = FALSE;
749 mimeview_clear(messageview->mimeview);
750 headerview_clear(messageview->headerview);
751 noticeview_hide(messageview->noticeview);
754 void messageview_destroy(MessageView *messageview)
756 debug_print("destroy messageview\n");
757 messageview_list = g_list_remove(messageview_list, messageview);
759 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
760 messageview->msginfo_update_callback_id);
762 headerview_destroy(messageview->headerview);
763 mimeview_destroy(messageview->mimeview);
764 noticeview_destroy(messageview->noticeview);
766 procmsg_msginfo_free(messageview->msginfo);
767 toolbar_clear_list(TOOLBAR_MSGVIEW);
768 if (messageview->toolbar) {
769 toolbar_destroy(messageview->toolbar);
770 g_free(messageview->toolbar);
773 msgview_list = g_list_remove(msgview_list, messageview);
778 void messageview_delete(MessageView *msgview)
780 MsgInfo *msginfo = NULL;
781 FolderItem *trash = NULL;
782 PrefsAccount *ac = NULL;
784 if (msgview->msginfo && msgview->mainwin && msgview->mainwin->summaryview)
785 msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
787 /* need a procmsg_msginfo_equal() */
788 if (msginfo && msgview->msginfo &&
789 msginfo->msgnum == msgview->msginfo->msgnum &&
790 msginfo->folder == msgview->msginfo->folder) {
791 summary_delete(msgview->mainwin->summaryview);
793 msginfo = msgview->msginfo;
795 g_return_if_fail(msginfo != NULL);
797 /* to get the trash folder, we have to choose either
798 * the folder's or account's trash default - we prefer
799 * the one in the account prefs */
800 if (msginfo->folder) {
801 if (NULL != (ac = account_find_from_item(msginfo->folder)))
802 trash = account_get_special_folder(ac, F_TRASH);
803 if (!trash && msginfo->folder->folder)
804 trash = msginfo->folder->folder->trash;
805 /* if still not found, use the default */
807 trash = folder_get_default_trash();
810 g_return_if_fail(trash != NULL);
812 if (prefs_common.immediate_exec)
813 /* TODO: Delete from trash */
814 folder_item_move_msg(trash, msginfo);
816 procmsg_msginfo_set_to_folder(msginfo, trash);
817 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
818 /* NOTE: does not update to next message in summaryview */
824 * \brief update messageview with currently selected message in summaryview
825 * leave unchanged if summaryview is empty
826 * \param pointer to MessageView
828 static void messageview_update(MessageView *msgview)
830 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
832 g_return_if_fail(summaryview != NULL);
834 if (summaryview->selected) {
835 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
836 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
837 summaryview->selected);
838 g_return_if_fail(msginfo != NULL);
840 messageview_show(msgview, msginfo,
841 msgview->all_headers);
845 void messageview_quote_color_set(void)
849 void messageview_set_font(MessageView *messageview)
853 TextView *messageview_get_current_textview(MessageView *messageview)
855 TextView *text = NULL;
857 text = messageview->mimeview->textview;
862 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
864 return mimeview_get_selected_part(messageview->mimeview);
867 void messageview_copy_clipboard(MessageView *messageview)
871 text = messageview_get_current_textview(messageview);
873 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
874 GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
875 GtkClipboard *clipboard
876 = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
878 gtk_text_buffer_copy_clipboard(buffer, clipboard);
882 void messageview_select_all(MessageView *messageview)
886 text = messageview_get_current_textview(messageview);
888 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
891 void messageview_set_position(MessageView *messageview, gint pos)
895 text = messageview_get_current_textview(messageview);
897 textview_set_position(text, pos);
900 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
905 text = messageview_get_current_textview(messageview);
907 return textview_search_string(text, str, case_sens);
911 gboolean messageview_search_string_backward(MessageView *messageview,
917 text = messageview_get_current_textview(messageview);
919 return textview_search_string_backward(text,
924 gboolean messageview_is_visible(MessageView *messageview)
926 return messageview->visible;
929 void messageview_save_as(MessageView *messageview)
931 gchar *filename = NULL;
935 if (!messageview->msginfo) return;
936 msginfo = messageview->msginfo;
938 if (msginfo->subject) {
939 Xstrdup_a(filename, msginfo->subject, return);
940 subst_for_filename(filename);
942 dest = filesel_select_file(_("Save as"), filename);
944 if (is_file_exist(dest)) {
947 aval = alertpanel(_("Overwrite"),
948 _("Overwrite existing file?"),
949 _("OK"), _("Cancel"), NULL);
950 if (G_ALERTDEFAULT != aval) return;
953 src = procmsg_get_message_file(msginfo);
954 if (copy_file(src, dest, TRUE) < 0) {
955 alertpanel_error(_("Can't save the file `%s'."),
961 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
963 messageview_destroy(messageview);
966 static void messageview_size_allocate_cb(GtkWidget *widget,
967 GtkAllocation *allocation)
969 g_return_if_fail(allocation != NULL);
971 prefs_common.msgwin_width = allocation->width;
972 prefs_common.msgwin_height = allocation->height;
975 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
976 MessageView *messageview)
978 if (event && event->keyval == GDK_Escape && messageview->window)
979 gtk_widget_destroy(messageview->window);
983 void messageview_toggle_view_real(MessageView *messageview)
985 MainWindow *mainwin = messageview->mainwin;
986 union CompositeWin *cwin = &mainwin->win;
987 GtkWidget *vpaned = NULL;
988 GtkWidget *container = NULL;
989 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
991 switch (mainwin->type) {
993 vpaned = cwin->sep_none.vpaned;
994 container = cwin->sep_none.hpaned;
996 case SEPARATE_FOLDER:
997 vpaned = cwin->sep_folder.vpaned;
998 container = mainwin->vbox_body;
1000 case SEPARATE_MESSAGE:
1005 if (vpaned->parent != NULL) {
1006 gtk_widget_ref(vpaned);
1007 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1008 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
1009 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
1011 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
1012 gtk_container_add(GTK_CONTAINER(container), vpaned);
1013 gtk_widget_unref(vpaned);
1014 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
1015 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
1019 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1021 noticeview_set_text(noticeview, _("This message asks for a return receipt"));
1022 noticeview_set_button_text(noticeview, _("Send receipt"));
1023 noticeview_set_button_press_callback(noticeview,
1024 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
1025 (gpointer) msginfo);
1026 noticeview_show(noticeview);
1029 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1031 MsgInfo *tmpmsginfo;
1034 file = procmsg_get_message_file_path(msginfo);
1036 g_warning("can't get message file path.\n");
1040 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1041 tmpmsginfo->folder = msginfo->folder;
1042 tmpmsginfo->msgnum = msginfo->msgnum;
1044 if (disposition_notification_send(tmpmsginfo) >= 0) {
1045 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1046 noticeview_hide(noticeview);
1049 procmsg_msginfo_free(tmpmsginfo);
1053 static void select_account_cb(GtkWidget *w, gpointer data)
1055 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
1058 static PrefsAccount *select_account_from_list(GList *ac_list)
1064 g_return_val_if_fail(ac_list != NULL, NULL);
1065 g_return_val_if_fail(ac_list->data != NULL, NULL);
1067 optmenu = gtk_option_menu_new();
1068 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
1071 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1072 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1073 account_id = ((PrefsAccount *) ac_list->data)->account_id;
1074 if (alertpanel_with_widget(
1075 _("Return Receipt Notification"),
1076 _("The message was sent to several of your "
1078 "Please choose which account do you want to "
1079 "use for sending the receipt notification:"),
1080 _("Send Notification"), _("+Cancel"), NULL,
1081 optmenu) != G_ALERTDEFAULT)
1083 return account_find_from_id(account_id);
1087 * \brief return selected messageview text, when nothing is
1088 * selected and message was filtered, return complete text
1090 * \param pointer to Messageview
1092 * \return pointer to text (needs to be free'd by calling func)
1094 gchar *messageview_get_selection(MessageView *msgview)
1098 GtkTextView *edit = NULL;
1099 GtkTextBuffer *textbuf;
1102 g_return_val_if_fail(msgview != NULL, NULL);
1104 textview = messageview_get_current_textview(msgview);
1105 g_return_val_if_fail(textview != NULL, NULL);
1107 edit = GTK_EDITABLE(textview->text);
1108 g_return_val_if_fail(edit != NULL, NULL);
1109 body_pos = textview->body_pos;
1111 textbuf = gtk_text_view_get_buffer(edit);
1113 if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
1114 return gtkut_text_view_get_selection(edit);
1115 else if (msgview->filtered) {
1116 GtkTextIter start_iter, end_iter;
1117 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
1118 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
1119 gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
1126 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1128 MessageView *messageview = (MessageView *)data;
1129 messageview_save_as(messageview);
1132 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1134 MessageView *messageview = (MessageView *)data;
1138 if (!messageview->msginfo) return;
1140 cmdline = input_dialog(_("Print"),
1141 _("Enter the print command line:\n"
1142 "(`%s' will be replaced with file name)"),
1143 prefs_common.print_cmd);
1144 if (!cmdline) return;
1145 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1146 strchr(p + 2, '%')) {
1147 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1153 procmsg_print_message(messageview->msginfo, cmdline);
1157 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1159 MessageView *messageview = (MessageView *)data;
1160 gtk_widget_destroy(messageview->window);
1163 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1165 MessageView *messageview = (MessageView *)data;
1166 messageview_copy_clipboard(messageview);
1169 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1171 MessageView *messageview = (MessageView *)data;
1172 messageview_select_all(messageview);
1175 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1177 MessageView *messageview = (MessageView *)data;
1178 message_search(messageview);
1181 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1183 MessageView *messageview = (MessageView *)data;
1184 const gchar *charset;
1186 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1187 charset = conv_get_charset_str((CharSet)action);
1188 g_free(messageview->forced_charset);
1189 messageview->forced_charset = g_strdup(charset);
1190 messageview_show(messageview, messageview->msginfo, FALSE);
1194 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1196 MessageView *messageview = (MessageView *)data;
1197 SourceWindow *srcwin;
1199 if (!messageview->msginfo) return;
1201 srcwin = source_window_create();
1202 source_window_show_msg(srcwin, messageview->msginfo);
1203 source_window_show(srcwin);
1206 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1208 MessageView *messageview = (MessageView *)data;
1209 MsgInfo *msginfo = messageview->msginfo;
1211 if (!msginfo) return;
1212 messageview->msginfo = NULL;
1213 messageview_show(messageview, msginfo,
1214 GTK_CHECK_MENU_ITEM(widget)->active);
1215 procmsg_msginfo_free(msginfo);
1216 main_window_set_menu_sensitive(messageview->mainwin);
1219 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1221 MessageView *messageview = (MessageView *)data;
1222 PrefsAccount *ac = NULL;
1223 FolderItem *item = NULL;
1225 if (messageview->msginfo)
1226 item = messageview->msginfo->folder;
1229 ac = account_find_from_item(item);
1230 if (ac && ac->protocol == A_NNTP &&
1231 item->stype == F_NEWS) {
1232 compose_new(ac, item->path, NULL);
1237 compose_new(ac, NULL, NULL);
1240 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1242 MessageView *messageview = (MessageView *)data;
1243 GSList *mlist = NULL;
1246 ComposeMode mode = (ComposeMode)action;
1249 msginfo = messageview->msginfo;
1250 mlist = g_slist_append(NULL, msginfo);
1252 textview = messageview_get_current_textview(messageview);
1253 text = gtkut_editable_get_selection
1254 (GTK_EDITABLE(textview->text));
1255 if (text && *text == '\0') {
1262 compose_reply(msginfo, prefs_common.reply_with_quote,
1263 FALSE, prefs_common.default_reply_list, FALSE, text);
1265 case COMPOSE_REPLY_WITH_QUOTE:
1266 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
1268 case COMPOSE_REPLY_WITHOUT_QUOTE:
1269 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
1271 case COMPOSE_REPLY_TO_SENDER:
1272 compose_reply(msginfo, prefs_common.reply_with_quote,
1273 FALSE, FALSE, TRUE, text);
1275 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1276 compose_followup_and_reply_to(msginfo,
1277 prefs_common.reply_with_quote,
1278 FALSE, FALSE, text);
1280 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1281 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
1283 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1284 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1286 case COMPOSE_REPLY_TO_ALL:
1287 compose_reply(msginfo, prefs_common.reply_with_quote,
1288 TRUE, FALSE, FALSE, text);
1290 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1291 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
1293 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1294 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1296 case COMPOSE_REPLY_TO_LIST:
1297 compose_reply(msginfo, prefs_common.reply_with_quote,
1298 FALSE, TRUE, FALSE, text);
1300 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1301 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
1303 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1304 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1306 case COMPOSE_FORWARD:
1307 if (prefs_common.forward_as_attachment) {
1308 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, mlist, text);
1311 compose_reply_mode(COMPOSE_FORWARD_INLINE, mlist, text);
1315 case COMPOSE_FORWARD_INLINE:
1316 compose_forward(NULL, msginfo, FALSE, text, FALSE);
1318 case COMPOSE_FORWARD_AS_ATTACH:
1319 compose_forward_multiple(NULL, mlist);
1321 case COMPOSE_REDIRECT:
1322 compose_redirect(NULL, msginfo);
1325 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1328 /* summary_set_marks_selected(summaryview); */
1330 g_slist_free(mlist);
1333 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1335 MessageView *messageview = (MessageView *)data;
1338 if (!messageview->msginfo) return;
1339 msginfo = messageview->msginfo;
1340 if (!msginfo->folder) return;
1341 if (msginfo->folder->stype != F_OUTBOX &&
1342 msginfo->folder->stype != F_DRAFT &&
1343 msginfo->folder->stype != F_QUEUE) return;
1345 compose_reedit(msginfo);
1348 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1350 addressbook_open(NULL);
1353 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1355 MessageView *messageview = (MessageView *)data;
1359 if (!messageview->msginfo) return;
1360 msginfo = messageview->msginfo;
1361 Xstrdup_a(from, msginfo->from, return);
1362 eliminate_address_comment(from);
1363 extract_address(from);
1364 addressbook_add_contact(msginfo->fromname, from, NULL);
1367 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1369 MessageView *messageview = (MessageView *)data;
1372 if (!messageview->msginfo) return;
1374 item = messageview->msginfo->folder;
1375 summary_msginfo_filter_open(item, messageview->msginfo,
1376 (PrefsFilterType)action, 0);
1379 static void create_processing_cb(gpointer data, guint action,
1382 MessageView *messageview = (MessageView *)data;
1385 if (!messageview->msginfo) return;
1387 item = messageview->msginfo->folder;
1388 summary_msginfo_filter_open(item, messageview->msginfo,
1389 (PrefsFilterType)action, 1);
1392 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1397 static gboolean messageview_update_msg(gpointer source, gpointer data)
1399 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1400 MessageView *messageview = (MessageView *)data;
1402 if (messageview->msginfo != msginfo_update->msginfo)
1405 if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1406 messageview_clear(messageview);
1407 messageview_update(messageview);
1413 void messageview_set_menu_sensitive(MessageView *messageview)
1415 GtkItemFactory *ifactory;
1416 GtkWidget *menuitem;
1418 if (!messageview && !messageview->new_window)
1420 /* do some smart things */
1421 if (!messageview->menubar) return;
1422 ifactory = gtk_item_factory_from_widget(messageview->menubar);
1423 if (!ifactory) return;
1424 if (messageview->mainwin->type == SEPARATE_MESSAGE) {
1425 menuitem = gtk_item_factory_get_widget(ifactory, "/View/Show all headers");
1426 gtk_check_menu_item_set_active
1427 (GTK_CHECK_MENU_ITEM(menuitem),
1428 messageview->mimeview->textview->show_all_headers);