2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkvbox.h>
26 #include <gtk/gtkcontainer.h>
27 #include <gtk/gtkwindow.h>
28 #include <gtk/gtktext.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
36 #include "messageview.h"
37 #include "message_search.h"
38 #include "headerview.h"
39 #include "summaryview.h"
45 #include "sourcewindow.h"
46 #include "addressbook.h"
47 #include "alertpanel.h"
48 #include "inputdialog.h"
49 #include "mainwindow.h"
50 #include "manage_window.h"
52 #include "procheader.h"
56 #include "prefs_common.h"
57 #include "prefs_account.h"
60 #include "send_message.h"
61 #include "stock_pixmap.h"
63 #include "filtering.h"
64 #include "partial_download.h"
65 #include "gedit-print.h"
66 #include "uri_opener.h"
70 static GList *messageview_list = NULL;
72 static gint messageview_delete_cb (GtkWidget *widget,
74 MessageView *messageview);
75 static void messageview_size_allocate_cb(GtkWidget *widget,
76 GtkAllocation *allocation);
77 static gboolean key_pressed (GtkWidget *widget,
79 MessageView *messageview);
81 static void return_receipt_show (NoticeView *noticeview,
83 static void return_receipt_send_clicked (NoticeView *noticeview,
85 static void partial_recv_show (NoticeView *noticeview,
87 static void partial_recv_dload_clicked (NoticeView *noticeview,
89 static void partial_recv_del_clicked (NoticeView *noticeview,
91 static void partial_recv_unmark_clicked (NoticeView *noticeview,
93 static void save_as_cb (gpointer data,
96 static void print_cb (gpointer data,
99 static void close_cb (gpointer data,
102 static void copy_cb (gpointer data,
105 static void allsel_cb (gpointer data,
108 static void search_cb (gpointer data,
112 static void set_charset_cb (gpointer data,
115 static void set_decode_cb (gpointer data,
118 static void view_source_cb (gpointer data,
121 static void show_all_header_cb (gpointer data,
124 static void msg_hide_quotes_cb (gpointer data,
128 static void compose_cb (gpointer data,
131 static void reply_cb (gpointer data,
135 static PrefsAccount *select_account_from_list
137 static void addressbook_open_cb (gpointer data,
140 static void add_address_cb (gpointer data,
143 static void create_filter_cb (gpointer data,
146 static void create_processing_cb (gpointer data,
149 static void open_urls_cb (gpointer data,
153 static void about_cb (gpointer data,
156 static void messageview_update (MessageView *msgview);
157 static gboolean messageview_update_msg (gpointer source, gpointer data);
159 static GList *msgview_list = NULL;
160 static GtkItemFactoryEntry msgview_entries[] =
162 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
163 {N_("/_File/_Save as..."), "<control>S", save_as_cb, 0, NULL},
164 {N_("/_File/_Print..."), "<control>P", print_cb, 0, NULL},
165 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
166 {N_("/_File/_Close"), "<control>W", close_cb, 0, NULL},
168 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
169 {N_("/_Edit/_Copy"), "<control>C", copy_cb, 0, NULL},
170 {N_("/_Edit/Select _all"), "<control>A", allsel_cb, 0, NULL},
171 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
172 {N_("/_Edit/_Find in current message..."),
173 "<control>F", search_cb, 0, NULL},
175 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
177 #define ENC_SEPARATOR \
178 {N_("/_View/Character _encoding/---"), NULL, NULL, 0, "<Separator>"}
179 #define ENC_ACTION(action) \
180 NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
182 {N_("/_View/Character _encoding"), NULL, NULL, 0, "<Branch>"},
183 {N_("/_View/Character _encoding/_Auto detect"),
184 NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
186 {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
187 ENC_ACTION(C_US_ASCII)},
189 {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
190 ENC_ACTION(C_UTF_8)},
192 {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
193 ENC_ACTION(C_ISO_8859_1)},
194 {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
195 ENC_ACTION(C_ISO_8859_15)},
196 {N_("/_View/Character _encoding/Western European (Windows-1252)"),
197 ENC_ACTION(C_WINDOWS_1252)},
199 {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
200 ENC_ACTION(C_ISO_8859_2)},
202 {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
203 ENC_ACTION(C_ISO_8859_13)},
204 {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
205 ENC_ACTION(C_ISO_8859_4)},
207 {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
208 ENC_ACTION(C_ISO_8859_7)},
210 {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
211 ENC_ACTION(C_ISO_8859_8)},
212 {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
213 ENC_ACTION(C_CP1255)},
215 {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
216 ENC_ACTION(C_ISO_8859_6)},
217 {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
218 ENC_ACTION(C_CP1256)},
220 {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
221 ENC_ACTION(C_ISO_8859_9)},
223 {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
224 ENC_ACTION(C_ISO_8859_5)},
225 {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
226 ENC_ACTION(C_KOI8_R)},
227 {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
228 ENC_ACTION(C_KOI8_U)},
229 {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
230 ENC_ACTION(C_CP1251)},
232 {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
233 ENC_ACTION(C_ISO_2022_JP)},
234 {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
235 ENC_ACTION(C_ISO_2022_JP_2)},
236 {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
237 ENC_ACTION(C_EUC_JP)},
238 {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
239 ENC_ACTION(C_SHIFT_JIS)},
241 {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
242 ENC_ACTION(C_GB2312)},
243 {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
245 {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
247 {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
248 ENC_ACTION(C_EUC_TW)},
249 {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
250 ENC_ACTION(C_ISO_2022_CN)},
252 {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
253 ENC_ACTION(C_EUC_KR)},
254 {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
255 ENC_ACTION(C_ISO_2022_KR)},
257 {N_("/_View/Character _encoding/Thai (TIS-620)"),
258 ENC_ACTION(C_TIS_620)},
259 {N_("/_View/Character _encoding/Thai (Windows-874)"),
260 ENC_ACTION(C_WINDOWS_874)},
265 #define DEC_SEPARATOR \
266 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"}
267 #define DEC_ACTION(action) \
268 NULL, set_decode_cb, action, "/View/Decode/Auto detect"
269 {N_("/_View/Decode"), NULL, NULL, 0, "<Branch>"},
270 {N_("/_View/Decode/_Auto detect"),
271 NULL, set_decode_cb, 0, "<RadioItem>"},
272 {N_("/_View/Decode/---"), NULL, NULL, 0, "<Separator>"},
273 {N_("/_View/Decode/_8bit"), DEC_ACTION(ENC_8BIT)},
274 {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
275 {N_("/_View/Decode/_Base64"), DEC_ACTION(ENC_BASE64)},
276 {N_("/_View/Decode/_Uuencode"), DEC_ACTION(ENC_X_UUENCODE)},
281 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
282 {N_("/_View/Mess_age source"), "<control>U", view_source_cb, 0, NULL},
283 {N_("/_View/Show all _headers"),"<control>H", show_all_header_cb, 0, "<ToggleItem>"},
284 {N_("/_View/Quotes"), NULL, NULL, 0, "<Branch>"},
285 {N_("/_View/Quotes/_Fold all"), "<control><shift>Q", msg_hide_quotes_cb, 1, "<ToggleItem>"},
286 {N_("/_View/Quotes/Fold from level _2"),NULL, msg_hide_quotes_cb, 2, "<ToggleItem>"},
287 {N_("/_View/Quotes/Fold from level _3"),NULL, msg_hide_quotes_cb, 3, "<ToggleItem>"},
289 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
290 {N_("/_Message/Compose _new message"),
291 "<control>M", compose_cb, 0, NULL},
292 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
293 {N_("/_Message/_Reply"), "<control>R", reply_cb, COMPOSE_REPLY, NULL},
294 {N_("/_Message/Repl_y to/_all"),
295 "<control><shift>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
296 {N_("/_Message/Repl_y to/_sender"),
297 NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
298 {N_("/_Message/Repl_y to/mailing _list"),
299 "<control>L", reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
300 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
301 {N_("/_Message/_Forward"), "<control><alt>F", reply_cb, COMPOSE_FORWARD_INLINE, NULL},
302 {N_("/_Message/For_ward as attachment"),
303 NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
304 {N_("/_Message/Redirec_t"), NULL, reply_cb, COMPOSE_REDIRECT, NULL},
306 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
307 {N_("/_Tools/_Address book"), "<control><shift>A", addressbook_open_cb, 0, NULL},
308 {N_("/_Tools/Add sender to address boo_k"),
309 NULL, add_address_cb, 0, NULL},
310 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
311 {N_("/_Tools/_Create filter rule"),
312 NULL, NULL, 0, "<Branch>"},
313 {N_("/_Tools/_Create filter rule/_Automatically"),
314 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
315 {N_("/_Tools/_Create filter rule/by _From"),
316 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
317 {N_("/_Tools/_Create filter rule/by _To"),
318 NULL, create_filter_cb, FILTER_BY_TO, NULL},
319 {N_("/_Tools/_Create filter rule/by _Subject"),
320 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
321 {N_("/_Tools/Create processing rule"),
322 NULL, NULL, 0, "<Branch>"},
323 {N_("/_Tools/Create processing rule/_Automatically"),
324 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
325 {N_("/_Tools/Create processing rule/by _From"),
326 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
327 {N_("/_Tools/Create processing rule/by _To"),
328 NULL, create_processing_cb, FILTER_BY_TO, NULL},
329 {N_("/_Tools/Create processing rule/by _Subject"),
330 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
331 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
332 {N_("/_Tools/List _URLs..."), "<shift><control>U", open_urls_cb, 0, NULL},
333 {N_("/_Tools/---"), NULL, NULL, 0, "<Separator>"},
334 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
336 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
337 {N_("/_Help/_About"), NULL, about_cb, 0, NULL}
340 MessageView *messageview_create(MainWindow *mainwin)
342 MessageView *messageview;
344 HeaderView *headerview;
346 NoticeView *noticeview;
348 debug_print("Creating message view...\n");
349 messageview = g_new0(MessageView, 1);
351 headerview = headerview_create();
353 noticeview = noticeview_create(mainwin);
355 mimeview = mimeview_create(mainwin);
356 mimeview->textview = textview_create();
357 mimeview->textview->messageview = messageview;
358 mimeview->messageview = messageview;
360 vbox = gtk_vbox_new(FALSE, 0);
361 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
363 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
365 gtk_box_pack_start(GTK_BOX(vbox),
366 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
367 gtk_widget_show(vbox);
369 messageview->vbox = vbox;
370 messageview->new_window = FALSE;
371 messageview->window = NULL;
372 messageview->headerview = headerview;
373 messageview->mimeview = mimeview;
374 messageview->noticeview = noticeview;
375 messageview->mainwin = mainwin;
377 messageview->statusbar = NULL;
378 messageview->statusbar_cid = 0;
380 messageview->msginfo_update_callback_id =
381 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
386 GList *messageview_get_msgview_list(void)
391 void messageview_update_actions_menu(MessageView *msgview)
393 GtkItemFactory *ifactory;
395 /* Messages opened in a new window do not have a menu bar */
396 if (msgview->menubar == NULL)
398 ifactory = gtk_item_factory_from_widget(msgview->menubar);
399 action_update_msgview_menu(ifactory, "/Tools/Actions", msgview);
402 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
404 GtkWidget *handlebox;
407 GtkWidget *statusbar;
408 guint n_menu_entries;
410 vbox = gtk_vbox_new(FALSE, 0);
411 gtk_widget_show(vbox);
412 gtk_container_add(GTK_CONTAINER(window), vbox);
414 n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
415 menubar = menubar_create(window, msgview_entries,
416 n_menu_entries, "<MessageView>", msgview);
417 gtk_widget_show(menubar);
418 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
420 if (prefs_common.toolbar_detachable) {
421 handlebox = gtk_handle_box_new();
423 handlebox = gtk_hbox_new(FALSE, 0);
425 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
426 gtk_widget_realize(handlebox);
427 msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
430 statusbar = gtk_statusbar_new();
431 gtk_widget_show(statusbar);
432 gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
433 msgview->statusbar = statusbar;
434 msgview->statusbar_cid = gtk_statusbar_get_context_id
435 (GTK_STATUSBAR(statusbar), "Message View");
437 msgview->handlebox = handlebox;
438 msgview->menubar = menubar;
440 gtk_container_add(GTK_CONTAINER(vbox),
441 GTK_WIDGET_PTR(msgview));
443 messageview_update_actions_menu(msgview);
445 msgview_list = g_list_append(msgview_list, msgview);
448 static MessageView *messageview_create_with_new_window_visible(MainWindow *mainwin, gboolean show)
450 MessageView *msgview;
452 static GdkGeometry geometry;
454 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "messageview");
455 gtk_window_set_title(GTK_WINDOW(window), _("Claws Mail - Message View"));
456 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
458 if (!geometry.min_height) {
459 geometry.min_width = 320;
460 geometry.min_height = 200;
462 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
465 gtk_widget_set_size_request(window, prefs_common.msgwin_width,
466 prefs_common.msgwin_height);
468 msgview = messageview_create(mainwin);
470 g_signal_connect(G_OBJECT(window), "size_allocate",
471 G_CALLBACK(messageview_size_allocate_cb),
473 g_signal_connect(G_OBJECT(window), "delete_event",
474 G_CALLBACK(messageview_delete_cb), msgview);
476 maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
478 g_signal_connect(G_OBJECT(window), "key_press_event",
479 G_CALLBACK(key_pressed), msgview);
481 messageview_add_toolbar(msgview, window);
484 gtk_widget_grab_focus(msgview->mimeview->textview->text);
485 gtk_widget_show(window);
487 gtk_widget_realize(window);
490 msgview->new_window = TRUE;
491 msgview->window = window;
492 msgview->visible = TRUE;
494 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
495 prefs_common.toolbar_style);
496 messageview_init(msgview);
501 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
503 return messageview_create_with_new_window_visible(mainwin, TRUE);
505 void messageview_init(MessageView *messageview)
507 headerview_init(messageview->headerview);
508 mimeview_init(messageview->mimeview);
509 /*messageview_set_font(messageview);*/
511 noticeview_hide(messageview->noticeview);
514 static void notification_convert_header(gchar *dest, gint len,
520 g_return_if_fail(src_ != NULL);
521 g_return_if_fail(dest != NULL);
525 Xstrndup_a(src, src_, len, return);
529 if (is_ascii_str(src)) {
530 strncpy2(dest, src, len);
531 dest[len - 1] = '\0';
534 conv_encode_header(dest, len, src, header_len, FALSE);
537 static gint disposition_notification_send(MsgInfo *msginfo)
540 gchar tmp[MAXPATHLEN + 1];
543 PrefsAccount *account = NULL;
546 FolderItem *queue, *outbox;
552 gboolean queued_removed = FALSE;
554 if (!msginfo->extradata)
556 if (!msginfo->extradata->returnreceiptto &&
557 !msginfo->extradata->dispositionnotificationto)
560 /* RFC2298: Test for Return-Path */
561 if (msginfo->extradata->dispositionnotificationto)
562 to = msginfo->extradata->dispositionnotificationto;
564 to = msginfo->extradata->returnreceiptto;
566 ok = procheader_get_header_from_msginfo(msginfo, buf, sizeof(buf),
569 gchar *to_addr = g_strdup(to);
570 extract_address(to_addr);
571 extract_address(buf);
572 ok = strcasecmp(to_addr, buf);
575 strncpy(buf, _("<No Return-Path found>"),
582 message = g_strdup_printf(
583 _("The notification address to which the return receipt is\n"
584 "to be sent does not correspond to the return path:\n"
585 "Notification address: %s\n"
587 "It is advised to not to send the return receipt."),
589 val = alertpanel_full(_("Warning"), message,
590 _("_Don't Send"), _("_Send"), NULL, FALSE,
591 NULL, ALERT_WARNING, G_ALERTDEFAULT);
593 if (val != G_ALERTALTERNATE)
597 ac_list = account_find_all_from_address(NULL, msginfo->to);
598 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
600 if (ac_list == NULL) {
602 alertpanel_full(_("Warning"),
603 _("This message is asking for a return receipt notification\n"
604 "but according to its 'To:' and 'CC:' headers it was not\n"
605 "officially addressed to you.\n"
606 "It is advised to not to send the return receipt."),
607 _("_Don't Send"), _("_Send"), NULL, FALSE,
608 NULL, ALERT_WARNING, G_ALERTDEFAULT);
609 if (val != G_ALERTALTERNATE)
613 if (g_list_length(ac_list) > 1) {
614 if ((account = select_account_from_list(ac_list)) == NULL)
617 else if (ac_list != NULL)
618 account = (PrefsAccount *) ac_list->data;
619 g_list_free(ac_list);
622 account = account_get_default();
623 if (!account || account->protocol == A_NNTP) {
624 alertpanel_error(_("Account for sending mail is not specified.\n"
625 "Please select a mail account before sending."));
629 /* write to temporary file */
630 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%p",
631 get_rc_dir(), G_DIR_SEPARATOR, msginfo);
633 if ((fp = g_fopen(tmp, "wb")) == NULL) {
634 FILE_OP_ERROR(tmp, "fopen");
638 /* chmod for security */
639 if (change_file_mode_rw(fp, tmp) < 0) {
640 FILE_OP_ERROR(tmp, "chmod");
641 g_warning("can't change file mode\n");
646 extract_address(addr);
649 /* write queue headers */
650 fprintf(fp, "AF:\n");
651 fprintf(fp, "NF:0\n");
652 fprintf(fp, "PS:10\n");
653 fprintf(fp, "SRH:1\n");
654 fprintf(fp, "SFN:\n");
655 fprintf(fp, "DSR:\n");
656 fprintf(fp, "MID:\n");
657 fprintf(fp, "CFG:\n");
658 fprintf(fp, "PT:0\n");
659 fprintf(fp, "S:%s\n", account->address);
660 fprintf(fp, "RQ:\n");
661 if (account->smtp_server)
662 fprintf(fp, "SSV:%s\n", account->smtp_server);
664 fprintf(fp, "SSV:\n");
665 fprintf(fp, "SSH:\n");
666 fprintf(fp, "R:<%s>\n", addrp);
670 /* check whether we need to save the message */
671 outbox = account_get_special_folder(account, F_OUTBOX);
672 if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
675 path = folder_item_get_identifier(outbox);
676 fprintf(fp, "SCF:%s\n", path);
680 fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
683 get_rfc822_date(buf, sizeof(buf));
684 fprintf(fp, "Date: %s\n", buf);
687 if (account->name && *account->name) {
688 notification_convert_header
689 (buf, sizeof(buf), account->name,
691 fprintf(fp, "From: %s <%s>\n", buf, account->address);
693 fprintf(fp, "From: %s\n", account->address);
695 fprintf(fp, "To: %s\n", to);
698 notification_convert_header(buf, sizeof(buf), msginfo->subject,
699 strlen("Subject: "));
700 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
703 generate_msgid(buf, sizeof(buf));
704 fprintf(fp, "Message-ID: <%s>\n", buf);
706 if (fclose(fp) == EOF) {
707 FILE_OP_ERROR(tmp, "fclose");
712 /* put it in queue */
713 queue = account_get_special_folder(account, F_QUEUE);
714 if (!queue) queue = folder_get_default_queue();
716 g_warning("can't find queue folder\n");
720 folder_item_scan(queue);
721 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
722 g_warning("can't queue the message\n");
727 if (prefs_common.work_offline &&
728 !inc_offline_should_override(TRUE,
729 _("Claws Mail needs network access in order "
730 "to send this email.")))
734 path = folder_item_fetch_msg(queue, num);
735 ok = procmsg_send_message_queue(path, &foo, queue, num, &queued_removed);
738 if (ok == 0 && !queued_removed)
739 folder_item_remove_msg(queue, num);
744 static gboolean find_encrypted_func(GNode *node, gpointer data)
746 MimeInfo *mimeinfo = (MimeInfo *) node->data;
747 MimeInfo **encinfo = (MimeInfo **) data;
749 if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
757 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
759 MimeInfo *encinfo = NULL;
761 g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
762 find_encrypted_func, &encinfo);
767 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
768 gboolean all_headers)
771 MimeInfo *mimeinfo, *encinfo;
772 gchar *subject = NULL;
773 g_return_val_if_fail(msginfo != NULL, -1);
775 if (messageview->mimeview->textview &&
776 messageview->mimeview->textview->loading) {
777 messageview->mimeview->textview->stop_loading = TRUE;
781 if (messageview->toolbar)
782 toolbar_set_learn_button
783 (messageview->toolbar,
784 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
786 toolbar_set_learn_button
787 (messageview->mainwin->toolbar,
788 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
790 if (messageview->toolbar) {
791 if (messageview->toolbar->learn_ham_btn)
792 gtk_widget_set_sensitive(
793 messageview->toolbar->learn_ham_btn,
794 procmsg_spam_can_learn());
795 if (messageview->toolbar->learn_spam_btn)
796 gtk_widget_set_sensitive(
797 messageview->toolbar->learn_spam_btn,
798 procmsg_spam_can_learn());
800 messageview->updating = TRUE;
801 mimeinfo = procmime_scan_message(msginfo);
802 messageview->updating = FALSE;
804 if (messageview->deferred_destroy) {
805 messageview_destroy(messageview);
810 textview_show_error(messageview->mimeview->textview);
814 while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
815 debug_print("decrypting message part\n");
816 if (privacy_mimeinfo_decrypt(encinfo) < 0) {
817 alertpanel_error(_("Couldn't decrypt: %s"),
818 privacy_get_error());
823 messageview->updating = TRUE;
824 file = procmsg_get_message_file_path(msginfo);
825 messageview->updating = FALSE;
827 if (messageview->deferred_destroy) {
829 messageview_destroy(messageview);
834 g_warning("can't get message file path.\n");
835 procmime_mimeinfo_free_all(mimeinfo);
836 textview_show_error(messageview->mimeview->textview);
840 if (messageview->msginfo != msginfo) {
841 procmsg_msginfo_free(messageview->msginfo);
842 messageview->msginfo = NULL;
843 messageview_set_menu_sensitive(messageview);
844 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
845 if (!messageview->msginfo)
846 messageview->msginfo = procmsg_msginfo_copy(msginfo);
848 messageview->msginfo = NULL;
849 messageview_set_menu_sensitive(messageview);
850 messageview->msginfo = msginfo;
852 headerview_show(messageview->headerview, messageview->msginfo);
854 messageview_set_position(messageview, 0);
856 textview_set_all_headers(messageview->mimeview->textview,
857 messageview->all_headers);
860 maemo_window_full_screen_if_needed(GTK_WINDOW(messageview->window));
862 if (messageview->window) {
863 gtk_window_set_title(GTK_WINDOW(messageview->window),
864 _("Claws Mail - Message View"));
867 mimeview_show_message(messageview->mimeview, mimeinfo, file);
869 messageview_set_position(messageview, 0);
871 if (messageview->window && msginfo->subject) {
872 subject = g_strdup(msginfo->subject);
873 if (!g_utf8_validate(subject, -1, NULL)) {
875 subject = g_malloc(strlen(msginfo->subject)*2 +1);
876 conv_localetodisp(subject, strlen(msginfo->subject)*2 +1,
879 if (g_utf8_validate(subject, -1, NULL))
880 gtk_window_set_title(GTK_WINDOW(messageview->window),
885 if (msginfo && msginfo->folder) {
886 msginfo->folder->last_seen = msginfo->msgnum;
889 main_create_mailing_list_menu(messageview->mainwin, messageview->msginfo);
891 if (messageview->msginfo->extradata
892 && messageview->msginfo->extradata->partial_recv)
893 partial_recv_show(messageview->noticeview,
894 messageview->msginfo);
895 else if (messageview->msginfo->extradata &&
896 (messageview->msginfo->extradata->dispositionnotificationto ||
897 messageview->msginfo->extradata->returnreceiptto) &&
898 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags) &&
899 !prefs_common.never_send_retrcpt)
900 return_receipt_show(messageview->noticeview,
901 messageview->msginfo);
903 noticeview_hide(messageview->noticeview);
905 mimeinfo = procmime_mimeinfo_next(mimeinfo);
906 if (!all_headers && mimeinfo && (mimeinfo->type != MIMETYPE_TEXT ||
907 strcasecmp(mimeinfo->subtype, "plain"))) {
908 if (strcasecmp(mimeinfo->subtype, "html"))
909 mimeview_show_part(messageview->mimeview,mimeinfo);
910 else if (prefs_common.invoke_plugin_on_html)
911 mimeview_select_mimepart_icon(messageview->mimeview,mimeinfo);
919 void messageview_reflect_prefs_pixmap_theme(void)
922 MessageView *msgview;
924 for (cur = msgview_list; cur != NULL; cur = cur->next) {
925 msgview = (MessageView*)cur->data;
926 toolbar_update(TOOLBAR_MSGVIEW, msgview);
927 mimeview_update(msgview->mimeview);
931 void messageview_clear(MessageView *messageview)
935 procmsg_msginfo_free(messageview->msginfo);
936 messageview->msginfo = NULL;
937 messageview->filtered = FALSE;
938 mimeview_clear(messageview->mimeview);
939 headerview_clear(messageview->headerview);
940 noticeview_hide(messageview->noticeview);
943 void messageview_destroy(MessageView *messageview)
945 debug_print("destroy messageview\n");
946 messageview_list = g_list_remove(messageview_list, messageview);
948 if (messageview->mainwin->summaryview->messageview == messageview)
949 messageview->mainwin->summaryview->messageview = NULL;
951 if (messageview->mainwin->summaryview->ext_messageview == messageview)
952 messageview->mainwin->summaryview->ext_messageview = NULL;
954 if (!messageview->deferred_destroy) {
955 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
956 messageview->msginfo_update_callback_id);
959 if (messageview->updating) {
960 debug_print("uh oh, better not touch that now (fetching)\n");
961 messageview->deferred_destroy = TRUE;
962 gtk_widget_hide(messageview->window);
966 if (messageview->mimeview->textview
967 && messageview->mimeview->textview->loading) {
968 debug_print("uh oh, better not touch that now (loading text)\n");
969 messageview->deferred_destroy = TRUE;
970 messageview->mimeview->textview->stop_loading = TRUE;
971 gtk_widget_hide(messageview->window);
975 headerview_destroy(messageview->headerview);
976 mimeview_destroy(messageview->mimeview);
977 noticeview_destroy(messageview->noticeview);
979 procmsg_msginfo_free(messageview->msginfo);
980 toolbar_clear_list(TOOLBAR_MSGVIEW);
981 if (messageview->toolbar) {
982 toolbar_destroy(messageview->toolbar);
983 g_free(messageview->toolbar);
986 msgview_list = g_list_remove(msgview_list, messageview);
988 if (messageview->window)
989 gtk_widget_destroy(messageview->window);
993 void messageview_delete(MessageView *msgview)
995 MsgInfo *msginfo = NULL;
996 FolderItem *trash = NULL;
997 PrefsAccount *ac = NULL;
999 if (msgview->msginfo && msgview->mainwin && msgview->mainwin->summaryview)
1000 msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1002 /* need a procmsg_msginfo_equal() */
1003 if (msginfo && msgview->msginfo &&
1004 msginfo->msgnum == msgview->msginfo->msgnum &&
1005 msginfo->folder == msgview->msginfo->folder) {
1006 summary_delete_trash(msgview->mainwin->summaryview);
1008 msginfo = msgview->msginfo;
1010 g_return_if_fail(msginfo != NULL);
1012 /* to get the trash folder, we have to choose either
1013 * the folder's or account's trash default - we prefer
1014 * the one in the account prefs */
1015 if (msginfo->folder) {
1016 if (NULL != (ac = account_find_from_item(msginfo->folder)))
1017 trash = account_get_special_folder(ac, F_TRASH);
1018 if (!trash && msginfo->folder->folder)
1019 trash = msginfo->folder->folder->trash;
1020 /* if still not found, use the default */
1022 trash = folder_get_default_trash();
1025 g_return_if_fail(trash != NULL);
1027 if (prefs_common.immediate_exec)
1028 /* TODO: Delete from trash */
1029 folder_item_move_msg(trash, msginfo);
1031 procmsg_msginfo_set_to_folder(msginfo, trash);
1032 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
1033 /* NOTE: does not update to next message in summaryview */
1039 * \brief update messageview with currently selected message in summaryview
1040 * leave unchanged if summaryview is empty
1041 * \param pointer to MessageView
1043 static void messageview_update(MessageView *msgview)
1045 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
1047 g_return_if_fail(summaryview != NULL);
1049 if (summaryview->selected) {
1050 MsgInfo *msginfo = summary_get_selected_msg(summaryview);
1051 if (msginfo == NULL)
1054 messageview_show(msgview, msginfo,
1055 msgview->all_headers);
1059 void messageview_quote_color_set(void)
1063 void messageview_set_font(MessageView *messageview)
1067 TextView *messageview_get_current_textview(MessageView *messageview)
1069 TextView *text = NULL;
1071 text = messageview->mimeview->textview;
1076 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
1078 return mimeview_get_selected_part(messageview->mimeview);
1081 void messageview_copy_clipboard(MessageView *messageview)
1085 text = messageview_get_current_textview(messageview);
1087 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
1088 GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
1089 GtkClipboard *clipboard
1090 = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
1092 gtk_text_buffer_copy_clipboard(buffer, clipboard);
1096 void messageview_select_all(MessageView *messageview)
1100 text = messageview_get_current_textview(messageview);
1102 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
1103 GtkTextBuffer *buffer;
1104 GtkTextIter start, end;
1106 buffer = gtk_text_view_get_buffer(textview);
1107 gtk_text_buffer_get_bounds(buffer, &start, &end);
1108 gtk_text_buffer_select_range(buffer, &start, &end);
1112 void messageview_set_position(MessageView *messageview, gint pos)
1116 text = messageview_get_current_textview(messageview);
1118 textview_set_position(text, pos);
1121 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
1126 if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1127 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1128 if (viewer && viewer->text_search) {
1129 return viewer->text_search(viewer, FALSE, str, case_sens);
1133 text = messageview_get_current_textview(messageview);
1135 return textview_search_string(text, str, case_sens);
1139 gboolean messageview_search_string_backward(MessageView *messageview,
1145 if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1146 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1147 if (viewer && viewer->text_search) {
1148 return viewer->text_search(viewer, TRUE, str, case_sens);
1152 text = messageview_get_current_textview(messageview);
1154 return textview_search_string_backward(text,
1159 gboolean messageview_is_visible(MessageView *messageview)
1161 if (messageview == NULL)
1163 return messageview->visible;
1166 static void messageview_save_as(MessageView *messageview)
1168 gchar *filename = NULL;
1170 gchar *src, *dest, *tmp;
1172 if (!messageview->msginfo) return;
1173 msginfo = messageview->msginfo;
1175 if (msginfo->subject) {
1176 Xstrdup_a(filename, msginfo->subject, return);
1177 subst_for_filename(filename);
1179 if (filename && !g_utf8_validate(filename, -1, NULL)) {
1180 gchar *oldstr = filename;
1181 filename = conv_codeset_strdup(filename,
1182 conv_get_locale_charset_str(),
1185 g_warning("messageview_save_as(): failed to convert character set.");
1186 filename = g_strdup(oldstr);
1188 dest = filesel_select_file_save(_("Save as"), filename);
1191 dest = filesel_select_file_save(_("Save as"), filename);
1193 if (is_file_exist(dest)) {
1196 aval = alertpanel(_("Overwrite"),
1197 _("Overwrite existing file?"),
1198 GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
1199 if (G_ALERTALTERNATE != aval) return;
1202 src = procmsg_get_message_file(msginfo);
1203 if (copy_file(src, dest, TRUE) < 0) {
1204 tmp = g_path_get_basename(dest);
1205 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
1212 static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
1213 MessageView *messageview)
1215 messageview_destroy(messageview);
1219 static void messageview_size_allocate_cb(GtkWidget *widget,
1220 GtkAllocation *allocation)
1222 g_return_if_fail(allocation != NULL);
1224 prefs_common.msgwin_width = allocation->width;
1225 prefs_common.msgwin_height = allocation->height;
1228 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
1229 MessageView *messageview)
1231 if (event && event->keyval == GDK_Escape && messageview->window) {
1232 messageview_destroy(messageview);
1236 if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0)
1239 g_signal_stop_emission_by_name(G_OBJECT(widget),
1241 mimeview_pass_key_press_event(messageview->mimeview, event);
1245 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1248 gboolean from_me = FALSE;
1250 && (folder_has_parent_of_type(msginfo->folder, F_QUEUE)
1251 || folder_has_parent_of_type(msginfo->folder, F_DRAFT)))
1254 addr = g_strdup(msginfo->from);
1256 extract_address(addr);
1257 if (account_find_from_address(addr)) {
1264 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1265 noticeview_set_text(noticeview, _("You asked for a return receipt in this message."));
1266 noticeview_set_button_text(noticeview, NULL);
1267 noticeview_set_button_press_callback(noticeview, NULL, NULL);
1269 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1270 noticeview_set_text(noticeview, _("This message asks for a return receipt."));
1271 noticeview_set_button_text(noticeview, _("Send receipt"));
1272 noticeview_set_button_press_callback(noticeview,
1273 G_CALLBACK(return_receipt_send_clicked),
1274 (gpointer) msginfo);
1276 noticeview_show(noticeview);
1279 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1281 MsgInfo *tmpmsginfo;
1284 file = procmsg_get_message_file_path(msginfo);
1286 g_warning("can't get message file path.\n");
1290 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1291 tmpmsginfo->folder = msginfo->folder;
1292 tmpmsginfo->msgnum = msginfo->msgnum;
1294 if (disposition_notification_send(tmpmsginfo) >= 0) {
1295 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1296 noticeview_hide(noticeview);
1299 procmsg_msginfo_free(tmpmsginfo);
1303 static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
1306 gchar *button1 = NULL;
1307 gchar *button2 = NULL;
1308 void *button1_cb = NULL;
1309 void *button2_cb = NULL;
1311 if (!msginfo->extradata)
1313 if (!partial_msg_in_uidl_list(msginfo)) {
1314 text = g_strdup_printf(_("This message has been partially "
1315 "retrieved,\nand has been deleted from the "
1318 switch (msginfo->planned_download) {
1319 case POP3_PARTIAL_DLOAD_UNKN:
1320 text = g_strdup_printf(_("This message has been "
1321 "partially retrieved;\nit is %s."),
1323 (off_t)(msginfo->total_size)));
1324 button1 = _("Mark for download");
1325 button2 = _("Mark for deletion");
1326 button1_cb = partial_recv_dload_clicked;
1327 button2_cb = partial_recv_del_clicked;
1329 case POP3_PARTIAL_DLOAD_DLOAD:
1330 text = g_strdup_printf(_("This message has been "
1331 "partially retrieved;\nit is %s and "
1332 "will be downloaded."),
1334 (off_t)(msginfo->total_size)));
1335 button1 = _("Unmark");
1336 button1_cb = partial_recv_unmark_clicked;
1337 button2 = _("Mark for deletion");
1338 button2_cb = partial_recv_del_clicked;
1340 case POP3_PARTIAL_DLOAD_DELE:
1341 text = g_strdup_printf(_("This message has been "
1342 "partially retrieved;\nit is %s and "
1343 "will be deleted."),
1345 (off_t)(msginfo->total_size)));
1346 button1 = _("Mark for download");
1347 button1_cb = partial_recv_dload_clicked;
1348 button2 = _("Unmark");
1349 button2_cb = partial_recv_unmark_clicked;
1356 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1357 noticeview_set_text(noticeview, text);
1359 noticeview_set_button_text(noticeview, button1);
1360 noticeview_set_button_press_callback(noticeview,
1361 G_CALLBACK(button1_cb), (gpointer) msginfo);
1363 noticeview_set_2ndbutton_text(noticeview, button2);
1364 noticeview_set_2ndbutton_press_callback(noticeview,
1365 G_CALLBACK(button2_cb), (gpointer) msginfo);
1367 noticeview_show(noticeview);
1370 static void partial_recv_dload_clicked(NoticeView *noticeview,
1373 if (partial_mark_for_download(msginfo) == 0) {
1374 partial_recv_show(noticeview, msginfo);
1378 static void partial_recv_del_clicked(NoticeView *noticeview,
1381 if (partial_mark_for_delete(msginfo) == 0) {
1382 partial_recv_show(noticeview, msginfo);
1386 static void partial_recv_unmark_clicked(NoticeView *noticeview,
1389 if (partial_unmark(msginfo) == 0) {
1390 partial_recv_show(noticeview, msginfo);
1394 static void select_account_cb(GtkWidget *w, gpointer data)
1396 *(gint*)data = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), MENU_VAL_ID));
1399 static PrefsAccount *select_account_from_list(GList *ac_list)
1405 g_return_val_if_fail(ac_list != NULL, NULL);
1406 g_return_val_if_fail(ac_list->data != NULL, NULL);
1408 optmenu = gtk_option_menu_new();
1409 menu = gtkut_account_menu_new(ac_list,
1410 G_CALLBACK(select_account_cb),
1414 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1415 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1416 account_id = ((PrefsAccount *) ac_list->data)->account_id;
1417 if (alertpanel_with_widget(
1418 _("Return Receipt Notification"),
1419 _("The message was sent to several of your "
1421 "Please choose which account do you want to "
1422 "use for sending the receipt notification:"),
1423 _("_Cancel"), _("_Send Notification"), NULL,
1424 FALSE, G_ALERTDEFAULT, optmenu) != G_ALERTALTERNATE)
1426 return account_find_from_id(account_id);
1430 * \brief return selected messageview text, when nothing is
1431 * selected and message was filtered, return complete text
1433 * \param pointer to Messageview
1435 * \return pointer to text (needs to be free'd by calling func)
1437 gchar *messageview_get_selection(MessageView *msgview)
1441 GtkTextView *edit = NULL;
1442 GtkTextBuffer *textbuf;
1445 g_return_val_if_fail(msgview != NULL, NULL);
1447 if (msgview->mimeview->type == MIMEVIEW_VIEWER) {
1448 MimeViewer *viewer = msgview->mimeview->mimeviewer;
1449 if (viewer && viewer->get_selection) {
1450 text = viewer->get_selection(viewer);
1456 textview = messageview_get_current_textview(msgview);
1457 g_return_val_if_fail(textview != NULL, NULL);
1459 edit = GTK_TEXT_VIEW(textview->text);
1460 g_return_val_if_fail(edit != NULL, NULL);
1461 body_pos = textview->body_pos;
1463 textbuf = gtk_text_view_get_buffer(edit);
1465 if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
1466 return gtkut_text_view_get_selection(edit);
1467 else if (msgview->filtered) {
1468 GtkTextIter start_iter, end_iter;
1469 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
1470 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
1471 gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
1478 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1480 MessageView *messageview = (MessageView *)data;
1481 messageview_save_as(messageview);
1484 #ifdef USE_GNOMEPRINT
1485 static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gint partnum)
1488 || !mimeview->textview
1489 || !mimeview->textview->text)
1490 alertpanel_warning(_("Cannot print: the message doesn't "
1493 gtk_widget_realize(mimeview->textview->text);
1495 mimeview_select_part_num(mimeview, partnum);
1497 if (mimeview->type == MIMEVIEW_VIEWER) {
1498 MimeViewer *viewer = mimeview->mimeviewer;
1499 if (viewer && viewer->print) {
1500 viewer->print(viewer);
1504 if (sel_start != -1 && sel_end != -1) {
1505 GtkTextIter start, end;
1506 GtkTextView *text = GTK_TEXT_VIEW(mimeview->textview->text);
1507 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1509 gtk_text_buffer_get_iter_at_offset(buffer, &start, sel_start);
1510 gtk_text_buffer_get_iter_at_offset(buffer, &end, sel_end);
1511 gtk_text_buffer_select_range(buffer, &start, &end);
1514 gedit_print(GTK_TEXT_VIEW(mimeview->textview->text));
1518 void messageview_print(MsgInfo *msginfo, gboolean all_headers,
1519 gint sel_start, gint sel_end, gint partnum)
1521 PangoFontDescription *font_desc = NULL;
1522 MessageView *tmpview = messageview_create_with_new_window_visible(
1523 mainwindow_get_mainwindow(), FALSE);
1525 if (prefs_common.use_different_print_font) {
1526 font_desc = pango_font_description_from_string
1527 (prefs_common.printfont);
1529 font_desc = pango_font_description_from_string
1530 (prefs_common.textfont);
1533 gtk_widget_modify_font(tmpview->mimeview->textview->text,
1535 pango_font_description_free(font_desc);
1538 tmpview->all_headers = all_headers;
1539 if (msginfo && messageview_show(tmpview, msginfo,
1540 tmpview->all_headers) >= 0) {
1541 print_mimeview(tmpview->mimeview,
1542 sel_start, sel_end, partnum);
1544 messageview_destroy(tmpview);
1548 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1550 MessageView *messageview = (MessageView *)data;
1551 #ifndef USE_GNOMEPRINT
1552 gchar *cmdline = NULL;
1555 gint sel_start = -1, sel_end = -1, partnum = 0;
1558 if (!messageview->msginfo) return;
1559 #ifndef USE_GNOMEPRINT
1560 cmdline = input_dialog(_("Print"),
1561 _("Enter the print command line:\n"
1562 "('%s' will be replaced with file name)"),
1563 prefs_common.print_cmd);
1564 if (!cmdline) return;
1565 if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1566 strchr(p + 2, '%')) {
1567 alertpanel_error(_("Print command line is invalid:\n'%s'"),
1572 procmsg_print_message(messageview->msginfo, cmdline);
1575 partnum = mimeview_get_selected_part_num(messageview->mimeview);
1576 textview_get_selection_offsets(messageview->mimeview->textview,
1577 &sel_start, &sel_end);
1578 messageview_print(messageview->msginfo, messageview->all_headers,
1579 sel_start, sel_end, partnum);
1583 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1585 MessageView *messageview = (MessageView *)data;
1586 messageview_destroy(messageview);
1589 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1591 MessageView *messageview = (MessageView *)data;
1592 messageview_copy_clipboard(messageview);
1595 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1597 MessageView *messageview = (MessageView *)data;
1598 messageview_select_all(messageview);
1601 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1603 MessageView *messageview = (MessageView *)data;
1604 message_search(messageview);
1607 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1609 MessageView *messageview = (MessageView *)data;
1610 const gchar *charset;
1612 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1613 charset = conv_get_charset_str((CharSet)action);
1614 g_free(messageview->forced_charset);
1615 messageview->forced_charset = g_strdup(charset);
1616 procmime_force_charset(charset);
1618 messageview_show(messageview, messageview->msginfo, FALSE);
1622 static void set_decode_cb(gpointer data, guint action, GtkWidget *widget)
1624 MessageView *messageview = (MessageView *)data;
1625 if (GTK_CHECK_MENU_ITEM(widget)->active) {
1626 messageview->forced_encoding = (EncodingType)action;
1628 messageview_show(messageview, messageview->msginfo, FALSE);
1630 debug_print("forced encoding: %d\n", action);
1635 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1637 MessageView *messageview = (MessageView *)data;
1638 SourceWindow *srcwin;
1640 if (!messageview->msginfo) return;
1642 srcwin = source_window_create();
1643 source_window_show_msg(srcwin, messageview->msginfo);
1644 source_window_show(srcwin);
1647 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1649 MessageView *messageview = (MessageView *)data;
1650 MsgInfo *msginfo = messageview->msginfo;
1652 if (messageview->mimeview->textview &&
1653 messageview->mimeview->textview->loading) {
1656 if (messageview->updating)
1659 messageview->all_headers =
1660 GTK_CHECK_MENU_ITEM(widget)->active;
1661 if (!msginfo) return;
1662 messageview->msginfo = NULL;
1663 messageview_show(messageview, msginfo,
1664 GTK_CHECK_MENU_ITEM(widget)->active);
1665 procmsg_msginfo_free(msginfo);
1666 main_window_set_menu_sensitive(messageview->mainwin);
1669 #define SET_CHECK_MENU_ACTIVE(path, active) \
1671 menuitem = gtk_item_factory_get_widget(ifactory, path); \
1672 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1675 static void msg_hide_quotes_cb(gpointer data, guint action, GtkWidget *widget)
1677 MessageView *messageview = (MessageView *)data;
1678 MsgInfo *msginfo = messageview->msginfo;
1679 static gboolean updating_menu = FALSE;
1680 GtkItemFactory *ifactory = gtk_item_factory_from_widget(messageview->menubar);
1681 GtkWidget *menuitem;
1685 prefs_common.hide_quotes =
1686 GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
1689 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
1690 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
1691 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
1692 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
1693 updating_menu=FALSE;
1694 if (!msginfo) return;
1695 messageview->msginfo = NULL;
1696 messageview_show(messageview, msginfo,
1697 messageview->all_headers);
1698 procmsg_msginfo_free(msginfo);
1700 /* update main window */
1701 main_window_set_menu_sensitive(messageview->mainwin);
1702 summary_redisplay_msg(messageview->mainwin->summaryview);
1704 #undef SET_CHECK_MENU_ACTIVE
1706 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1708 MessageView *messageview = (MessageView *)data;
1709 PrefsAccount *ac = NULL;
1710 FolderItem *item = NULL;
1712 if (messageview->msginfo)
1713 item = messageview->msginfo->folder;
1716 ac = account_find_from_item(item);
1717 if (ac && ac->protocol == A_NNTP &&
1718 item->stype == F_NEWS) {
1719 compose_new(ac, item->path, NULL);
1724 compose_new(ac, NULL, NULL);
1727 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1729 MessageView *messageview = (MessageView *)data;
1730 GSList *msginfo_list = NULL;
1732 g_return_if_fail(messageview->msginfo);
1734 msginfo_list = g_slist_append(msginfo_list, messageview->msginfo);
1735 compose_reply_from_messageview(messageview, msginfo_list, action);
1736 g_slist_free(msginfo_list);
1739 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1741 addressbook_open(NULL);
1744 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1746 MessageView *messageview = (MessageView *)data;
1750 if (!messageview->msginfo) return;
1751 msginfo = messageview->msginfo;
1752 Xstrdup_a(from, msginfo->from, return);
1753 eliminate_address_comment(from);
1754 extract_address(from);
1755 addressbook_add_contact(msginfo->fromname, from, NULL);
1758 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1760 MessageView *messageview = (MessageView *)data;
1763 if (!messageview->msginfo) return;
1765 item = messageview->msginfo->folder;
1766 summary_msginfo_filter_open(item, messageview->msginfo,
1767 (PrefsFilterType)action, 0);
1770 static void create_processing_cb(gpointer data, guint action,
1773 MessageView *messageview = (MessageView *)data;
1776 if (!messageview->msginfo) return;
1778 item = messageview->msginfo->folder;
1779 summary_msginfo_filter_open(item, messageview->msginfo,
1780 (PrefsFilterType)action, 1);
1783 static void open_urls_cb(gpointer data, guint action, GtkWidget *widget)
1785 MessageView *messageview = (MessageView *)data;
1786 messageview_list_urls(messageview);
1789 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1794 static gboolean messageview_update_msg(gpointer source, gpointer data)
1796 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1797 MessageView *messageview = (MessageView *)data;
1799 if (messageview->msginfo != msginfo_update->msginfo)
1802 if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1803 messageview_clear(messageview);
1804 messageview_update(messageview);
1810 void messageview_set_menu_sensitive(MessageView *messageview)
1812 GtkItemFactory *ifactory;
1813 GtkWidget *menuitem = NULL;
1815 if (!messageview || !messageview->new_window)
1817 /* do some smart things */
1818 if (!messageview->menubar) return;
1819 ifactory = gtk_item_factory_from_widget(messageview->menubar);
1820 if (!ifactory) return;
1822 if (prefs_common.hide_quotes) {
1824 if (prefs_common.hide_quotes == 1)
1825 menuitem = gtk_item_factory_get_widget(ifactory,
1826 "/View/Quotes/Fold all");
1827 if (prefs_common.hide_quotes == 2)
1828 menuitem = gtk_item_factory_get_widget(ifactory,
1829 "/View/Quotes/Fold from level 2");
1830 if (prefs_common.hide_quotes == 3)
1831 menuitem = gtk_item_factory_get_widget(ifactory,
1832 "/View/Quotes/Fold from level 3");
1833 gtk_check_menu_item_set_active
1834 (GTK_CHECK_MENU_ITEM(menuitem),
1839 void messageview_learn (MessageView *msgview, gboolean is_spam)
1842 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, TRUE) == 0)
1843 procmsg_msginfo_set_flags(msgview->msginfo, MSG_SPAM, 0);
1845 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
1848 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, FALSE) == 0)
1849 procmsg_msginfo_unset_flags(msgview->msginfo, MSG_SPAM, 0);
1851 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
1853 if (msgview->toolbar)
1854 toolbar_set_learn_button
1856 MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1858 toolbar_set_learn_button
1859 (msgview->mainwin->toolbar,
1860 MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1863 void messageview_list_urls (MessageView *msgview)
1865 GSList *cur = msgview->mimeview->textview->uri_list;
1866 GSList *newlist = NULL;
1867 for (; cur; cur = cur->next) {
1868 ClickableText *uri = (ClickableText *)cur->data;
1869 if (!uri->uri || !g_ascii_strncasecmp(uri->uri, "mailto:", 7)
1872 newlist = g_slist_prepend(newlist, uri);
1874 newlist = g_slist_reverse(newlist);
1875 uri_opener_open(msgview, newlist);
1876 g_slist_free(newlist);