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_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 about_cb (gpointer data,
133 static void messageview_update (MessageView *msgview);
134 static gboolean messageview_update_msg (gpointer source, gpointer data);
136 static GList *msgview_list = NULL;
137 static GtkItemFactoryEntry msgview_entries[] =
139 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
140 {N_("/_File/_Save as..."), NULL, save_as_cb, 0, NULL},
141 {N_("/_File/_Print..."), NULL, print_cb, 0, NULL},
142 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
143 {N_("/_File/_Close"), NULL, close_cb, 0, NULL},
145 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
146 {N_("/_Edit/_Copy"), NULL, copy_cb, 0, NULL},
147 {N_("/_Edit/Select _all"), NULL, allsel_cb, 0, NULL},
148 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
149 {N_("/_Edit/_Find in current message..."),
150 NULL, search_cb, 0, NULL},
152 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
154 #define CODESET_SEPARATOR \
155 {N_("/_View/_Code set/---"), NULL, NULL, 0, "<Separator>"}
156 #define CODESET_ACTION(action) \
157 NULL, set_charset_cb, action, "/View/Code set/Auto detect"
159 {N_("/_View/_Code set"), NULL, NULL, 0, "<Branch>"},
160 {N_("/_View/_Code set/_Auto detect"),
161 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
163 {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
164 CODESET_ACTION(C_US_ASCII)},
167 {N_("/_View/_Code set/Unicode (_UTF-8)"),
168 CODESET_ACTION(C_UTF_8)},
171 {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
172 CODESET_ACTION(C_ISO_8859_1)},
173 {N_("/_View/_Code set/Western European (ISO-8859-15)"),
174 CODESET_ACTION(C_ISO_8859_15)},
177 {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
178 CODESET_ACTION(C_ISO_8859_2)},
180 {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
181 CODESET_ACTION(C_ISO_8859_13)},
182 {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
183 CODESET_ACTION(C_ISO_8859_4)},
185 {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
186 CODESET_ACTION(C_ISO_8859_7)},
188 {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
189 CODESET_ACTION(C_ISO_8859_9)},
191 {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
192 CODESET_ACTION(C_ISO_8859_5)},
193 {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
194 CODESET_ACTION(C_KOI8_R)},
195 {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
196 CODESET_ACTION(C_CP1251)},
199 {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
200 CODESET_ACTION(C_ISO_2022_JP)},
202 {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
203 CODESET_ACTION(C_ISO_2022_JP_2)},
205 {N_("/_View/_Code set/Japanese (_EUC-JP)"),
206 CODESET_ACTION(C_EUC_JP)},
207 {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
208 CODESET_ACTION(C_SHIFT_JIS)},
211 {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
212 CODESET_ACTION(C_GB2312)},
213 {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
214 CODESET_ACTION(C_BIG5)},
215 {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
216 CODESET_ACTION(C_EUC_TW)},
217 {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
218 CODESET_ACTION(C_ISO_2022_CN)},
220 {N_("/_View/_Code set/Korean (EUC-_KR)"),
221 CODESET_ACTION(C_EUC_KR)},
222 {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
223 CODESET_ACTION(C_ISO_2022_KR)},
225 {N_("/_View/_Code set/Thai (TIS-620)"),
226 CODESET_ACTION(C_TIS_620)},
227 {N_("/_View/_Code set/Thai (Windows-874)"),
228 CODESET_ACTION(C_WINDOWS_874)},
231 #undef CODESET_SEPARATOR
232 #undef CODESET_ACTION
234 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
235 {N_("/_View/Mess_age source"), NULL, view_source_cb, 0, NULL},
236 {N_("/_View/Show all _header"), NULL, show_all_header_cb, 0, "<ToggleItem>"},
238 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
239 {N_("/_Message/Compose _new message"),
240 NULL, compose_cb, 0, NULL},
241 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
242 {N_("/_Message/_Reply"), NULL, reply_cb, COMPOSE_REPLY, NULL},
243 {N_("/_Message/Repl_y to/_all"),
244 NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
245 {N_("/_Message/Repl_y to/_sender"),
246 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
247 {N_("/_Message/Repl_y to/mailing _list"),
248 NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
249 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
250 {N_("/_Message/_Forward"), NULL, reply_cb, COMPOSE_FORWARD, NULL},
251 {N_("/_Message/For_ward as attachment"),
252 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
253 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
254 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
255 {N_("/_Message/Re-_edit"), NULL, reedit_cb, 0, NULL},
257 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
258 {N_("/_Tools/_Address book"), NULL, addressbook_open_cb, 0, NULL},
259 {N_("/_Tools/Add sender to address boo_k"),
260 NULL, add_address_cb, 0, NULL},
261 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
262 {N_("/_Tools/_Create filter rule"),
263 NULL, NULL, 0, "<Branch>"},
264 {N_("/_Tools/_Create filter rule/_Automatically"),
265 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
266 {N_("/_Tools/_Create filter rule/by _From"),
267 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
268 {N_("/_Tools/_Create filter rule/by _To"),
269 NULL, create_filter_cb, FILTER_BY_TO, NULL},
270 {N_("/_Tools/_Create filter rule/by _Subject"),
271 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
272 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
273 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
275 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
276 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
279 MessageView *messageview_create(MainWindow *mainwin)
281 MessageView *messageview;
283 HeaderView *headerview;
285 NoticeView *noticeview;
287 debug_print("Creating message view...\n");
288 messageview = g_new0(MessageView, 1);
290 headerview = headerview_create();
292 noticeview = noticeview_create(mainwin);
294 mimeview = mimeview_create(mainwin);
295 mimeview->textview = textview_create();
296 mimeview->textview->messageview = messageview;
297 mimeview->messageview = messageview;
299 vbox = gtk_vbox_new(FALSE, 0);
300 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
302 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
304 gtk_box_pack_start(GTK_BOX(vbox),
305 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
306 gtk_widget_show(vbox);
308 messageview->vbox = vbox;
309 messageview->new_window = FALSE;
310 messageview->window = NULL;
311 messageview->headerview = headerview;
312 messageview->mimeview = mimeview;
313 messageview->noticeview = noticeview;
314 messageview->mainwin = mainwin;
315 messageview->msginfo_update_callback_id =
316 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
322 GList *messageview_get_msgview_list(void)
327 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
329 GtkWidget *handlebox;
332 GtkItemFactory *ifactory;
333 guint n_menu_entries;
335 vbox = gtk_vbox_new(FALSE, 0);
336 gtk_widget_show(vbox);
337 gtk_container_add(GTK_CONTAINER(window), vbox);
339 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
340 menubar = menubar_create(window, msgview_entries,
341 n_menu_entries, "<MessageView>", msgview);
342 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
344 handlebox = gtk_handle_box_new();
345 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
346 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
348 msgview->handlebox = handlebox;
349 msgview->menubar = menubar;
351 gtk_container_add(GTK_CONTAINER(vbox),
352 GTK_WIDGET_PTR(msgview));
354 ifactory = gtk_item_factory_from_widget(menubar);
355 action_update_msgview_menu(ifactory, msgview);
357 msgview_list = g_list_append(msgview_list, msgview);
360 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
363 MessageView *msgview;
365 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
366 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
367 gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
368 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
369 gtk_widget_set_usize(window, prefs_common.msgwin_width,
370 prefs_common.msgwin_height);
372 msgview = messageview_create(mainwin);
374 gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
375 GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
377 gtk_signal_connect(GTK_OBJECT(window), "destroy",
378 GTK_SIGNAL_FUNC(messageview_destroy_cb), msgview);
379 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
380 GTK_SIGNAL_FUNC(key_pressed), msgview);
382 messageview_add_toolbar(msgview, window);
384 gtk_widget_grab_focus(msgview->mimeview->textview->text);
385 gtk_widget_show(window);
387 msgview->new_window = TRUE;
388 msgview->window = window;
389 msgview->visible = TRUE;
391 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
392 prefs_common.toolbar_style);
393 messageview_init(msgview);
398 void messageview_init(MessageView *messageview)
400 headerview_init(messageview->headerview);
401 mimeview_init(messageview->mimeview);
402 /*messageview_set_font(messageview);*/
404 noticeview_hide(messageview->noticeview);
407 static void notification_convert_header(gchar *dest, gint len,
413 g_return_if_fail(src_ != NULL);
414 g_return_if_fail(dest != NULL);
418 Xstrndup_a(src, src_, len, return);
422 if (is_ascii_str(src)) {
423 strncpy2(dest, src, len);
424 dest[len - 1] = '\0';
427 conv_encode_header(dest, len, src, header_len, FALSE);
430 static gint disposition_notification_send(MsgInfo *msginfo)
433 gchar tmp[MAXPATHLEN + 1];
436 PrefsAccount *account;
439 FolderItem *queue, *outbox;
443 if ((!msginfo->returnreceiptto) &&
444 (!msginfo->dispositionnotificationto))
447 /* RFC2298: Test for Return-Path */
448 if (msginfo->dispositionnotificationto)
449 to = msginfo->dispositionnotificationto;
451 to = msginfo->returnreceiptto;
453 ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
456 gchar *to_addr = g_strdup(to);
457 extract_address(to_addr);
458 extract_address(buf);
459 ok = strcmp(to_addr, buf);
462 strncpy(buf, _("<No Return-Path found>"),
469 message = g_strdup_printf(
470 _("The notification address to which the "
471 "return receipt is to be sent\n"
472 "does not correspond to the return path:\n"
473 "Notification address: %s\n"
475 "It is advised to not to send the return "
476 "receipt."), to, buf);
477 val = alertpanel(_("Warning"), message, _("Send"),
478 _("+Don't Send"), NULL);
480 if (val != G_ALERTDEFAULT)
484 ac_list = account_find_all_from_address(NULL, msginfo->to);
485 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
487 if (ac_list == NULL) {
488 alertpanel_error(_("This message is asking for a return "
489 "receipt notification\n"
490 "but according to its 'To:' and 'CC:' "
491 "headers it was not\nofficially addressed "
493 "Receipt notification cancelled."));
497 if (g_list_length(ac_list) > 1)
498 account = select_account_from_list(ac_list);
500 account = (PrefsAccount *) ac_list->data;
501 g_list_free(ac_list);
506 /* write to temporary file */
507 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
508 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
510 if ((fp = fopen(tmp, "wb")) == NULL) {
511 FILE_OP_ERROR(tmp, "fopen");
515 /* chmod for security */
516 if (change_file_mode_rw(fp, tmp) < 0) {
517 FILE_OP_ERROR(tmp, "chmod");
518 g_warning("can't change file mode\n");
521 /* write queue headers */
522 fprintf(fp, "AF:\n");
523 fprintf(fp, "NF:0\n");
524 fprintf(fp, "PS:10\n");
525 fprintf(fp, "SRH:1\n");
526 fprintf(fp, "SFN:\n");
527 fprintf(fp, "DSR:\n");
528 fprintf(fp, "MID:\n");
529 fprintf(fp, "CFG:\n");
530 fprintf(fp, "PT:0\n");
531 fprintf(fp, "S:%s\n", account->address);
532 fprintf(fp, "RQ:\n");
533 if (account->smtp_server)
534 fprintf(fp, "SSV:%s\n", account->smtp_server);
536 fprintf(fp, "SSV:\n");
537 fprintf(fp, "SSH:\n");
538 fprintf(fp, "R:<%s>\n", to);
540 /* check whether we need to save the message */
541 outbox = account_get_special_folder(account, F_OUTBOX);
542 if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
545 path = folder_item_get_identifier(outbox);
546 fprintf(fp, "SCF:%s\n", path);
553 get_rfc822_date(buf, sizeof(buf));
554 fprintf(fp, "Date: %s\n", buf);
557 if (account->name && *account->name) {
558 notification_convert_header
559 (buf, sizeof(buf), account->name,
561 fprintf(fp, "From: %s <%s>\n", buf, account->address);
563 fprintf(fp, "From: %s\n", account->address);
565 fprintf(fp, "To: %s\n", to);
568 notification_convert_header(buf, sizeof(buf), msginfo->subject,
569 strlen("Subject: "));
570 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
573 generate_msgid(account->address, buf, sizeof buf);
574 fprintf(fp, "Message-Id: <%s>\n", buf);
576 if (fclose(fp) == EOF) {
577 FILE_OP_ERROR(tmp, "fclose");
582 /* put it in queue */
583 queue = account_get_special_folder(account, F_QUEUE);
584 if (!queue) queue = folder_get_default_queue();
586 g_warning("can't find queue folder\n");
590 folder_item_scan(queue);
591 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
592 g_warning("can't queue the message\n");
598 path = folder_item_fetch_msg(queue, num);
599 ok = procmsg_send_message_queue(path);
601 folder_item_remove_msg(queue, num);
606 GList *messageview_get_window_list(void)
608 return messageview_list;
611 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
612 gboolean all_headers)
617 g_return_if_fail(msginfo != NULL);
619 mimeinfo = procmime_scan_message(msginfo);
620 g_return_if_fail(mimeinfo != NULL);
622 file = procmsg_get_message_file_path(msginfo);
624 g_warning("can't get message file path.\n");
625 procmime_mimeinfo_free_all(mimeinfo);
629 if (messageview->msginfo != msginfo) {
630 procmsg_msginfo_free(messageview->msginfo);
631 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
633 headerview_show(messageview->headerview, messageview->msginfo);
635 messageview->all_headers = all_headers;
636 textview_set_all_headers(messageview->mimeview->textview, all_headers);
638 mimeview_show_message(messageview->mimeview, mimeinfo, file);
640 if ((messageview->msginfo->dispositionnotificationto ||
641 messageview->msginfo->returnreceiptto) &&
642 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags))
643 return_receipt_show(messageview->noticeview, messageview->msginfo);
645 noticeview_hide(messageview->noticeview);
650 void messageview_reflect_prefs_pixmap_theme(void)
653 MessageView *msgview;
655 for (cur = msgview_list; cur != NULL; cur = cur->next) {
656 msgview = (MessageView*)cur->data;
657 toolbar_update(TOOLBAR_MSGVIEW, msgview);
658 mimeview_update(msgview->mimeview);
662 void messageview_clear(MessageView *messageview)
664 procmsg_msginfo_free(messageview->msginfo);
665 messageview->msginfo = NULL;
666 messageview->filtered = FALSE;
667 mimeview_clear(messageview->mimeview);
668 headerview_clear(messageview->headerview);
669 noticeview_hide(messageview->noticeview);
672 void messageview_destroy(MessageView *messageview)
674 GtkWidget *mimeview = GTK_WIDGET_PTR(messageview->mimeview);
676 debug_print("destroy messageview\n");
677 messageview_list = g_list_remove(messageview_list, messageview);
679 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
680 messageview->msginfo_update_callback_id);
682 headerview_destroy(messageview->headerview);
683 mimeview_destroy(messageview->mimeview);
684 noticeview_destroy(messageview->noticeview);
686 procmsg_msginfo_free(messageview->msginfo);
687 toolbar_clear_list(TOOLBAR_MSGVIEW);
688 if (messageview->toolbar) {
689 toolbar_destroy(messageview->toolbar);
690 g_free(messageview->toolbar);
693 msgview_list = g_list_remove(msgview_list, messageview);
697 gtk_widget_unref(mimeview);
700 void messageview_delete(MessageView *msgview)
702 MsgInfo *msginfo = (MsgInfo *) msgview->msginfo;
703 FolderItem *trash = folder_get_default_trash();
705 g_return_if_fail(msginfo != NULL);
706 g_return_if_fail(trash != NULL);
708 if (prefs_common.immediate_exec)
709 /* TODO: Delete from trash */
710 folder_item_move_msg(trash, msginfo);
712 procmsg_msginfo_set_to_folder(msginfo, trash);
713 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
714 /* NOTE: does not update to next message in summaryview */
719 * \brief update messageview with currently selected message in summaryview
720 * leave unchanged if summaryview is empty
721 * \param pointer to MessageView
723 static void messageview_update(MessageView *msgview)
725 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
727 g_return_if_fail(summaryview != NULL);
729 if (summaryview->selected) {
730 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
731 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
732 summaryview->selected);
733 g_return_if_fail(msginfo != NULL);
735 messageview_show(msgview, msginfo,
736 msgview->all_headers);
740 void messageview_quote_color_set(void)
744 void messageview_set_font(MessageView *messageview)
748 TextView *messageview_get_current_textview(MessageView *messageview)
750 TextView *text = NULL;
752 text = messageview->mimeview->textview;
757 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
759 return mimeview_get_selected_part(messageview->mimeview);
762 void messageview_copy_clipboard(MessageView *messageview)
766 text = messageview_get_current_textview(messageview);
768 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
771 void messageview_select_all(MessageView *messageview)
775 text = messageview_get_current_textview(messageview);
777 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
780 void messageview_set_position(MessageView *messageview, gint pos)
784 text = messageview_get_current_textview(messageview);
786 textview_set_position(text, pos);
789 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
794 text = messageview_get_current_textview(messageview);
796 return textview_search_string(text, str, case_sens);
800 gboolean messageview_search_string_backward(MessageView *messageview,
806 text = messageview_get_current_textview(messageview);
807 return textview_search_string_backward(text,
812 gboolean messageview_is_visible(MessageView *messageview)
814 return messageview->visible;
817 void messageview_save_as(MessageView *messageview)
819 gchar *filename = NULL;
823 if (!messageview->msginfo) return;
824 msginfo = messageview->msginfo;
826 if (msginfo->subject) {
827 Xstrdup_a(filename, msginfo->subject, return);
828 subst_for_filename(filename);
830 dest = filesel_select_file(_("Save as"), filename);
832 if (is_file_exist(dest)) {
835 aval = alertpanel(_("Overwrite"),
836 _("Overwrite existing file?"),
837 _("OK"), _("Cancel"), NULL);
838 if (G_ALERTDEFAULT != aval) return;
841 src = procmsg_get_message_file(msginfo);
842 if (copy_file(src, dest, TRUE) < 0) {
843 alertpanel_error(_("Can't save the file `%s'."),
849 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
851 messageview_destroy(messageview);
854 static void messageview_size_allocate_cb(GtkWidget *widget,
855 GtkAllocation *allocation)
857 g_return_if_fail(allocation != NULL);
859 prefs_common.msgwin_width = allocation->width;
860 prefs_common.msgwin_height = allocation->height;
863 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
864 MessageView *messageview)
866 if (event && event->keyval == GDK_Escape && messageview->window)
867 gtk_widget_destroy(messageview->window);
870 void messageview_toggle_view_real(MessageView *messageview)
872 MainWindow *mainwin = messageview->mainwin;
873 union CompositeWin *cwin = &mainwin->win;
874 GtkWidget *vpaned = NULL;
875 GtkWidget *container = NULL;
876 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
878 switch (mainwin->type) {
880 vpaned = cwin->sep_none.vpaned;
881 container = cwin->sep_none.hpaned;
883 case SEPARATE_FOLDER:
884 vpaned = cwin->sep_folder.vpaned;
885 container = mainwin->vbox_body;
887 case SEPARATE_MESSAGE:
892 if (vpaned->parent != NULL) {
893 gtk_widget_ref(vpaned);
894 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
895 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
896 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
898 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
899 gtk_container_add(GTK_CONTAINER(container), vpaned);
900 gtk_widget_unref(vpaned);
901 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
902 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
906 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
908 noticeview_set_text(noticeview, _("This message asks for a return receipt"));
909 noticeview_set_button_text(noticeview, _("Send receipt"));
910 noticeview_set_button_press_callback(noticeview,
911 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
913 noticeview_show(noticeview);
916 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
921 file = procmsg_get_message_file_path(msginfo);
923 g_warning("can't get message file path.\n");
927 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
928 tmpmsginfo->folder = msginfo->folder;
929 tmpmsginfo->msgnum = msginfo->msgnum;
931 if (disposition_notification_send(tmpmsginfo) >= 0) {
932 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
933 noticeview_hide(noticeview);
936 procmsg_msginfo_free(tmpmsginfo);
940 static void select_account_cb(GtkWidget *w, gpointer data)
942 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
945 static PrefsAccount *select_account_from_list(GList *ac_list)
951 g_return_val_if_fail(ac_list != NULL, NULL);
952 g_return_val_if_fail(ac_list->data != NULL, NULL);
954 optmenu = gtk_option_menu_new();
955 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
958 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
959 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
960 account_id = ((PrefsAccount *) ac_list->data)->account_id;
961 if (alertpanel_with_widget(
962 _("Return Receipt Notification"),
963 _("The message was sent to several of your "
965 "Please choose which account do you want to "
966 "use for sending the receipt notification:"),
967 _("Send Notification"), _("+Cancel"), NULL,
968 optmenu) != G_ALERTDEFAULT)
970 return account_find_from_id(account_id);
974 * \brief return selected messageview text, when nothing is
975 * selected and message was filtered, return complete text
977 * \param pointer to Messageview
979 * \return pointer to text (needs to be free'd by calling func)
981 gchar *messageview_get_selection(MessageView *msgview)
985 GtkEditable *edit = NULL;
988 g_return_val_if_fail(msgview != NULL, NULL);
990 textview = messageview_get_current_textview(msgview);
991 g_return_val_if_fail(textview != NULL, NULL);
993 edit = GTK_EDITABLE(textview->text);
994 g_return_val_if_fail(edit != NULL, NULL);
995 body_pos = textview->body_pos;
997 if (edit->has_selection)
998 text = gtkut_editable_get_selection(edit);
999 else if (msgview->filtered)
1000 text = gtk_editable_get_chars (edit, body_pos, -1);
1007 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1009 MessageView *messageview = (MessageView *)data;
1010 messageview_save_as(messageview);
1013 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1015 MessageView *messageview = (MessageView *)data;
1019 if (!messageview->msginfo) return;
1021 cmdline = input_dialog(_("Print"),
1022 _("Enter the print command line:\n"
1023 "(`%s' will be replaced with file name)"),
1024 prefs_common.print_cmd);
1025 if (!cmdline) return;
1026 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1027 strchr(p + 2, '%')) {
1028 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1034 procmsg_print_message(messageview->msginfo, cmdline);
1038 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1040 MessageView *messageview = (MessageView *)data;
1041 gtk_widget_destroy(messageview->window);
1044 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1046 MessageView *messageview = (MessageView *)data;
1047 messageview_copy_clipboard(messageview);
1050 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1052 MessageView *messageview = (MessageView *)data;
1053 messageview_select_all(messageview);
1056 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1058 MessageView *messageview = (MessageView *)data;
1059 message_search(messageview);
1062 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1064 MessageView *messageview = (MessageView *)data;
1065 const gchar *charset;
1067 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1068 charset = conv_get_charset_str((CharSet)action);
1069 g_free(messageview->forced_charset);
1070 messageview->forced_charset = g_strdup(charset);
1071 messageview_show(messageview, messageview->msginfo, FALSE);
1075 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1077 MessageView *messageview = (MessageView *)data;
1078 SourceWindow *srcwin;
1080 if (!messageview->msginfo) return;
1082 srcwin = source_window_create();
1083 source_window_show_msg(srcwin, messageview->msginfo);
1084 source_window_show(srcwin);
1087 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1089 MessageView *messageview = (MessageView *)data;
1090 MsgInfo *msginfo = messageview->msginfo;
1092 if (!msginfo) return;
1093 messageview->msginfo = NULL;
1094 messageview_show(messageview, msginfo,
1095 GTK_CHECK_MENU_ITEM(widget)->active);
1096 procmsg_msginfo_free(msginfo);
1099 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1101 MessageView *messageview = (MessageView *)data;
1102 PrefsAccount *ac = NULL;
1103 FolderItem *item = NULL;
1105 if (messageview->msginfo)
1106 item = messageview->msginfo->folder;
1109 ac = account_find_from_item(item);
1110 if (ac && ac->protocol == A_NNTP &&
1111 item->stype == F_NEWS) {
1112 compose_new(ac, item->path, NULL);
1117 compose_new(ac, NULL, NULL);
1120 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1122 MessageView *messageview = (MessageView *)data;
1123 GSList *mlist = NULL;
1126 ComposeMode mode = (ComposeMode)action;
1129 msginfo = messageview->msginfo;
1130 mlist = g_slist_append(NULL, msginfo);
1132 textview = messageview_get_current_textview(messageview);
1133 text = gtkut_editable_get_selection
1134 (GTK_EDITABLE(textview->text));
1135 if (text && *text == '\0') {
1142 compose_reply(msginfo, prefs_common.reply_with_quote,
1143 FALSE, prefs_common.default_reply_list, FALSE, text);
1145 case COMPOSE_REPLY_WITH_QUOTE:
1146 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
1148 case COMPOSE_REPLY_WITHOUT_QUOTE:
1149 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
1151 case COMPOSE_REPLY_TO_SENDER:
1152 compose_reply(msginfo, prefs_common.reply_with_quote,
1153 FALSE, FALSE, TRUE, text);
1155 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1156 compose_followup_and_reply_to(msginfo,
1157 prefs_common.reply_with_quote,
1158 FALSE, FALSE, text);
1160 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1161 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
1163 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1164 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1166 case COMPOSE_REPLY_TO_ALL:
1167 compose_reply(msginfo, prefs_common.reply_with_quote,
1168 TRUE, FALSE, FALSE, text);
1170 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1171 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
1173 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1174 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1176 case COMPOSE_REPLY_TO_LIST:
1177 compose_reply(msginfo, prefs_common.reply_with_quote,
1178 FALSE, TRUE, FALSE, text);
1180 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1181 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
1183 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1184 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1186 case COMPOSE_FORWARD:
1187 if (prefs_common.forward_as_attachment) {
1188 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, mlist, text);
1191 compose_reply_mode(COMPOSE_FORWARD_INLINE, mlist, text);
1195 case COMPOSE_FORWARD_INLINE:
1196 compose_forward(NULL, msginfo, FALSE, text);
1198 case COMPOSE_FORWARD_AS_ATTACH:
1199 compose_forward_multiple(NULL, mlist);
1201 case COMPOSE_REDIRECT:
1202 compose_redirect(NULL, msginfo);
1205 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1208 /* summary_set_marks_selected(summaryview); */
1210 g_slist_free(mlist);
1213 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1215 MessageView *messageview = (MessageView *)data;
1218 if (!messageview->msginfo) return;
1219 msginfo = messageview->msginfo;
1220 if (!msginfo->folder) return;
1221 if (msginfo->folder->stype != F_OUTBOX &&
1222 msginfo->folder->stype != F_DRAFT &&
1223 msginfo->folder->stype != F_QUEUE) return;
1225 compose_reedit(msginfo);
1228 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1230 addressbook_open(NULL);
1233 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1235 MessageView *messageview = (MessageView *)data;
1239 if (!messageview->msginfo) return;
1240 msginfo = messageview->msginfo;
1241 Xstrdup_a(from, msginfo->from, return);
1242 eliminate_address_comment(from);
1243 extract_address(from);
1244 addressbook_add_contact(msginfo->fromname, from, NULL);
1247 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1249 MessageView *messageview = (MessageView *)data;
1250 gchar *header = NULL;
1253 if (!messageview->msginfo) return;
1255 procmsg_get_filter_keyword(messageview->msginfo, &header, &key,
1256 (PrefsFilterType)action);
1257 prefs_filtering_open(NULL, header, key);
1263 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1268 static gboolean messageview_update_msg(gpointer source, gpointer data)
1270 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1271 MessageView *messageview = (MessageView *)data;
1273 if (messageview->msginfo != msginfo_update->msginfo)
1276 if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1277 messageview_clear(messageview);
1278 messageview_update(messageview);