2007-07-13 [colin] 2.10.0cvs19
[claws.git] / src / messageview.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4  *
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 3 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
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>
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <string.h>
34
35 #include "main.h"
36 #include "messageview.h"
37 #include "message_search.h"
38 #include "headerview.h"
39 #include "summaryview.h"
40 #include "textview.h"
41 #include "mimeview.h"
42 #include "menu.h"
43 #include "about.h"
44 #include "filesel.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"
51 #include "procmsg.h"
52 #include "procheader.h"
53 #include "procmime.h"
54 #include "account.h"
55 #include "action.h"
56 #include "prefs_common.h"
57 #include "prefs_account.h"
58 #include "gtkutils.h"
59 #include "utils.h"
60 #include "send_message.h"
61 #include "stock_pixmap.h"
62 #include "hooks.h"
63 #include "filtering.h"
64 #include "partial_download.h"
65 #include "gedit-print.h"
66 #include "uri_opener.h"
67 #include "inc.h"
68 #include "log.h"
69
70 static GList *messageview_list = NULL;
71
72 static gint messageview_delete_cb       (GtkWidget              *widget,
73                                          GdkEventAny            *event,
74                                          MessageView            *messageview);
75 static void messageview_size_allocate_cb(GtkWidget      *widget,
76                                          GtkAllocation  *allocation);
77 static gboolean key_pressed             (GtkWidget      *widget,
78                                          GdkEventKey    *event,
79                                          MessageView    *messageview);
80
81 static void return_receipt_show         (NoticeView     *noticeview, 
82                                          MsgInfo        *msginfo);      
83 static void return_receipt_send_clicked (NoticeView     *noticeview, 
84                                          MsgInfo        *msginfo);
85 static void partial_recv_show           (NoticeView     *noticeview, 
86                                          MsgInfo        *msginfo);      
87 static void partial_recv_dload_clicked  (NoticeView     *noticeview, 
88                                          MsgInfo        *msginfo);
89 static void partial_recv_del_clicked    (NoticeView     *noticeview, 
90                                          MsgInfo        *msginfo);
91 static void partial_recv_unmark_clicked (NoticeView     *noticeview, 
92                                          MsgInfo        *msginfo);
93 static void save_as_cb                  (gpointer        data,
94                                          guint           action,
95                                          GtkWidget      *widget);
96 static void print_cb                    (gpointer        data,
97                                          guint           action,
98                                          GtkWidget      *widget);
99 static void close_cb                    (gpointer        data,
100                                          guint           action,
101                                          GtkWidget      *widget);
102 static void copy_cb                     (gpointer        data,
103                                          guint           action,
104                                          GtkWidget      *widget);
105 static void allsel_cb                   (gpointer        data,
106                                          guint           action,
107                                          GtkWidget      *widget);
108 static void search_cb                   (gpointer        data,
109                                          guint           action,
110                                          GtkWidget      *widget);
111
112 static void set_charset_cb              (gpointer        data,
113                                          guint           action,
114                                          GtkWidget      *widget);
115 static void set_decode_cb               (gpointer        data,
116                                          guint           action,
117                                          GtkWidget      *widget);
118 static void view_source_cb              (gpointer        data,
119                                          guint           action,
120                                          GtkWidget      *widget);
121 static void show_all_header_cb          (gpointer        data,
122                                          guint           action,
123                                          GtkWidget      *widget);
124 static void msg_hide_quotes_cb          (gpointer        data,
125                                          guint           action,
126                                          GtkWidget      *widget);
127
128 static void compose_cb                  (gpointer        data,
129                                          guint           action,
130                                          GtkWidget      *widget);
131 static void reply_cb                    (gpointer        data,
132                                          guint           action,
133                                          GtkWidget      *widget);
134
135 static PrefsAccount *select_account_from_list
136                                         (GList          *ac_list);
137 static void addressbook_open_cb         (gpointer        data,
138                                          guint           action,
139                                          GtkWidget      *widget);
140 static void add_address_cb              (gpointer        data,
141                                          guint           action,
142                                          GtkWidget      *widget);
143 static void create_filter_cb            (gpointer        data,
144                                          guint           action,
145                                          GtkWidget      *widget);
146 static void create_processing_cb        (gpointer        data,
147                                          guint           action,
148                                          GtkWidget      *widget);
149 static void open_urls_cb                (gpointer        data,
150                                          guint           action,
151                                          GtkWidget      *widget);
152
153 static void about_cb                    (gpointer        data,
154                                          guint           action,
155                                          GtkWidget      *widget);
156 static void messageview_update          (MessageView *msgview);
157 static gboolean messageview_update_msg  (gpointer source, gpointer data);
158
159 static GList *msgview_list = NULL;
160 static GtkItemFactoryEntry msgview_entries[] =
161 {
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},
167
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},
174
175         {N_("/_View"),                  NULL, NULL, 0, "<Branch>"},
176
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"
181
182         {N_("/_View/Character _encoding"),      NULL, NULL, 0, "<Branch>"},
183         {N_("/_View/Character _encoding/_Auto detect"),
184                                         NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
185         ENC_SEPARATOR,
186         {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
187          ENC_ACTION(C_US_ASCII)},
188
189         {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
190          ENC_ACTION(C_UTF_8)},
191         ENC_SEPARATOR,
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)},
198         ENC_SEPARATOR,
199         {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
200          ENC_ACTION(C_ISO_8859_2)},
201         ENC_SEPARATOR,
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)},
206         ENC_SEPARATOR,
207         {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
208          ENC_ACTION(C_ISO_8859_7)},
209         ENC_SEPARATOR,
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)},
214         ENC_SEPARATOR,
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)},
219         ENC_SEPARATOR,
220         {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
221          ENC_ACTION(C_ISO_8859_9)},
222         ENC_SEPARATOR,
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)},
231         ENC_SEPARATOR,
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)},
240         ENC_SEPARATOR,
241         {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
242          ENC_ACTION(C_GB2312)},
243         {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
244          ENC_ACTION(C_GBK)},
245         {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
246          ENC_ACTION(C_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)},
251         ENC_SEPARATOR,
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)},
256         ENC_SEPARATOR,
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)},
261
262 #undef ENC_SEPARATOR
263 #undef ENC_ACTION
264
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)},
277
278 #undef DEC_SEPARATOR
279 #undef DEC_ACTION
280
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>"},
288
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},
305
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>"},
335
336         {N_("/_Help"),                  NULL, NULL, 0, "<Branch>"},
337         {N_("/_Help/_About"),           NULL, about_cb, 0, NULL}
338 };
339
340 MessageView *messageview_create(MainWindow *mainwin)
341 {
342         MessageView *messageview;
343         GtkWidget *vbox;
344         HeaderView *headerview;
345         MimeView *mimeview;
346         NoticeView *noticeview;
347
348         debug_print("Creating message view...\n");
349         messageview = g_new0(MessageView, 1);
350
351         headerview = headerview_create();
352
353         noticeview = noticeview_create(mainwin);
354
355         mimeview = mimeview_create(mainwin);
356         mimeview->textview = textview_create();
357         mimeview->textview->messageview = messageview;
358         mimeview->messageview = messageview;
359
360         vbox = gtk_vbox_new(FALSE, 0);
361         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
362                            FALSE, FALSE, 0);
363         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
364                            FALSE, FALSE, 0);
365         gtk_box_pack_start(GTK_BOX(vbox),
366                            GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
367         gtk_widget_show(vbox);
368
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;
376
377         messageview->statusbar     = NULL;
378         messageview->statusbar_cid = 0;
379
380         messageview->msginfo_update_callback_id =
381                 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
382
383         return messageview;
384 }
385
386 GList *messageview_get_msgview_list(void)
387 {
388         return msgview_list;
389 }
390
391 void messageview_update_actions_menu(MessageView *msgview)
392 {
393         GtkItemFactory *ifactory;
394
395         /* Messages opened in a new window do not have a menu bar */
396         if (msgview->menubar == NULL)
397                 return;
398         ifactory = gtk_item_factory_from_widget(msgview->menubar);
399         action_update_msgview_menu(ifactory, "/Tools/Actions", msgview);
400 }
401
402 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window) 
403 {
404         GtkWidget *handlebox;
405         GtkWidget *vbox;
406         GtkWidget *menubar;
407         GtkWidget *statusbar;
408         guint n_menu_entries;
409
410         vbox = gtk_vbox_new(FALSE, 0);
411         gtk_widget_show(vbox);
412         gtk_container_add(GTK_CONTAINER(window), vbox); 
413
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);
419
420         if (prefs_common.toolbar_detachable) {
421                 handlebox = gtk_handle_box_new();
422         } else {
423                 handlebox = gtk_hbox_new(FALSE, 0);
424         }
425         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
426         gtk_widget_realize(handlebox);
427 #ifdef MAEMO
428         msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, window,
429                                           (gpointer)msgview);
430 #else
431         msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
432                                           (gpointer)msgview);
433 #endif
434
435         statusbar = gtk_statusbar_new();
436         gtk_widget_show(statusbar);
437         gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
438         msgview->statusbar = statusbar;
439         msgview->statusbar_cid = gtk_statusbar_get_context_id
440                 (GTK_STATUSBAR(statusbar), "Message View");
441
442         msgview->handlebox = handlebox;
443         msgview->menubar   = menubar;
444
445         gtk_container_add(GTK_CONTAINER(vbox),
446                           GTK_WIDGET_PTR(msgview));
447
448         messageview_update_actions_menu(msgview);
449
450         msgview_list = g_list_append(msgview_list, msgview);
451 }
452
453 static MessageView *messageview_create_with_new_window_visible(MainWindow *mainwin, gboolean show)
454 {
455         MessageView *msgview;
456         GtkWidget *window;
457         static GdkGeometry geometry;
458
459         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "messageview");
460         gtk_window_set_title(GTK_WINDOW(window), _("Claws Mail - Message View"));
461         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
462
463         if (!geometry.min_height) {
464                 geometry.min_width = 320;
465                 geometry.min_height = 200;
466         }
467         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
468                                       GDK_HINT_MIN_SIZE);
469
470         gtk_widget_set_size_request(window, prefs_common.msgwin_width,
471                                     prefs_common.msgwin_height);
472
473         msgview = messageview_create(mainwin);
474
475         g_signal_connect(G_OBJECT(window), "size_allocate",
476                          G_CALLBACK(messageview_size_allocate_cb),
477                          msgview);
478         g_signal_connect(G_OBJECT(window), "delete_event",
479                          G_CALLBACK(messageview_delete_cb), msgview);
480 #ifdef MAEMO
481         maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
482 #else
483         g_signal_connect(G_OBJECT(window), "key_press_event",
484                          G_CALLBACK(key_pressed), msgview);
485 #endif
486         messageview_add_toolbar(msgview, window);
487
488         if (show) {
489                 gtk_widget_grab_focus(msgview->mimeview->textview->text);
490                 gtk_widget_show(window);
491         } else {
492                 gtk_widget_realize(window);
493         }
494
495         msgview->new_window = TRUE;
496         msgview->window = window;
497         msgview->visible = TRUE;
498
499         toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox, 
500                           prefs_common.toolbar_style);
501         messageview_init(msgview);
502
503         return msgview;
504 }
505
506 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
507 {
508         return messageview_create_with_new_window_visible(mainwin, TRUE);
509 }
510 void messageview_init(MessageView *messageview)
511 {
512         headerview_init(messageview->headerview);
513         mimeview_init(messageview->mimeview);
514         /*messageview_set_font(messageview);*/
515
516         noticeview_hide(messageview->noticeview);
517 }
518
519 static void notification_convert_header(gchar *dest, gint len, 
520                                         const gchar *src_,
521                                         gint header_len)
522 {
523         char *src;
524
525         g_return_if_fail(src_ != NULL);
526         g_return_if_fail(dest != NULL);
527
528         if (len < 1) return;
529
530         Xstrndup_a(src, src_, len, return);
531
532         remove_return(src);
533
534         if (is_ascii_str(src)) {
535                 strncpy2(dest, src, len);
536                 dest[len - 1] = '\0';
537                 return;
538         } else
539                 conv_encode_header(dest, len, src, header_len, FALSE);
540 }
541
542 static gint disposition_notification_send(MsgInfo *msginfo)
543 {
544         gchar buf[BUFFSIZE];
545         gchar tmp[MAXPATHLEN + 1];
546         FILE *fp;
547         GList *ac_list;
548         PrefsAccount *account = NULL;
549         gint ok;
550         gchar *to;
551         FolderItem *queue, *outbox;
552         gint num;
553         gchar *path;
554         gchar *addr;
555         gchar *addrp;
556         gchar *foo = NULL;
557         gboolean queued_removed = FALSE;
558         
559         if (!msginfo->extradata)
560                 return -1;
561         if (!msginfo->extradata->returnreceiptto && 
562             !msginfo->extradata->dispositionnotificationto) 
563                 return -1;
564
565         /* RFC2298: Test for Return-Path */
566         if (msginfo->extradata->dispositionnotificationto)
567                 to = msginfo->extradata->dispositionnotificationto;
568         else
569                 to = msginfo->extradata->returnreceiptto;
570
571         ok = procheader_get_header_from_msginfo(msginfo, buf, sizeof(buf),
572                                 "Return-Path:");
573         if (ok == 0) {
574                 gchar *to_addr = g_strdup(to);
575                 extract_address(to_addr);
576                 extract_address(buf);
577                 ok = strcasecmp(to_addr, buf);
578                 g_free(to_addr);
579         } else {
580                 strncpy(buf, _("<No Return-Path found>"), 
581                                 sizeof(buf));
582         }
583         
584         if (ok != 0) {
585                 AlertValue val;
586                 gchar *message;
587                 message = g_strdup_printf(
588                   _("The notification address to which the return receipt is\n"
589                     "to be sent does not correspond to the return path:\n"
590                     "Notification address: %s\n"
591                     "Return path: %s\n"
592                     "It is advised to not to send the return receipt."),
593                   to, buf);
594                 val = alertpanel_full(_("Warning"), message,
595                                 _("_Don't Send"), _("_Send"), NULL, FALSE,
596                                 NULL, ALERT_WARNING, G_ALERTDEFAULT);
597                 g_free(message);                                
598                 if (val != G_ALERTALTERNATE)
599                         return -1;
600         }
601
602         ac_list = account_find_all_from_address(NULL, msginfo->to);
603         ac_list = account_find_all_from_address(ac_list, msginfo->cc);
604
605         if (ac_list == NULL) {
606                 AlertValue val = 
607                 alertpanel_full(_("Warning"),
608                   _("This message is asking for a return receipt notification\n"
609                     "but according to its 'To:' and 'CC:' headers it was not\n"
610                     "officially addressed to you.\n"
611                     "It is advised to not to send the return receipt."),
612                   _("_Don't Send"), _("_Send"), NULL, FALSE,
613                   NULL, ALERT_WARNING, G_ALERTDEFAULT);
614                 if (val != G_ALERTALTERNATE)
615                         return -1;
616         }
617
618         if (g_list_length(ac_list) > 1) {
619                 if ((account = select_account_from_list(ac_list)) == NULL)
620                         return -1;
621         }
622         else if (ac_list != NULL)
623                 account = (PrefsAccount *) ac_list->data;
624         g_list_free(ac_list);
625
626         if (account == NULL)
627                 account = account_get_default();
628         if (!account || account->protocol == A_NNTP) {
629                 alertpanel_error(_("Account for sending mail is not specified.\n"
630                                    "Please select a mail account before sending."));
631                 return -1;
632         }
633
634         /* write to temporary file */
635         g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%p",
636                    get_rc_dir(), G_DIR_SEPARATOR, msginfo);
637
638         if ((fp = g_fopen(tmp, "wb")) == NULL) {
639                 FILE_OP_ERROR(tmp, "fopen");
640                 return -1;
641         }
642
643         /* chmod for security */
644         if (change_file_mode_rw(fp, tmp) < 0) {
645                 FILE_OP_ERROR(tmp, "chmod");
646                 g_warning("can't change file mode\n");
647         }
648         
649         addr = g_strdup(to);
650         
651         extract_address(addr);
652         addrp = addr;
653         
654         /* write queue headers */
655         fprintf(fp, "AF:\n");
656         fprintf(fp, "NF:0\n");
657         fprintf(fp, "PS:10\n");
658         fprintf(fp, "SRH:1\n");
659         fprintf(fp, "SFN:\n");
660         fprintf(fp, "DSR:\n");
661         fprintf(fp, "MID:\n");
662         fprintf(fp, "CFG:\n");
663         fprintf(fp, "PT:0\n");
664         fprintf(fp, "S:%s\n", account->address);
665         fprintf(fp, "RQ:\n");
666         if (account->smtp_server)
667                 fprintf(fp, "SSV:%s\n", account->smtp_server);
668         else
669                 fprintf(fp, "SSV:\n");
670         fprintf(fp, "SSH:\n");
671         fprintf(fp, "R:<%s>\n", addrp);
672         
673         g_free(addrp);
674         
675         /* check whether we need to save the message */
676         outbox = account_get_special_folder(account, F_OUTBOX); 
677         if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
678                 outbox = NULL;
679         if (outbox) {
680                 path = folder_item_get_identifier(outbox);
681                 fprintf(fp, "SCF:%s\n", path);
682                 g_free(path);
683         }               
684
685         fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
686         
687         /* Date */
688         get_rfc822_date(buf, sizeof(buf));
689         fprintf(fp, "Date: %s\n", buf);
690
691         /* From */
692         if (account->name && *account->name) {
693                 notification_convert_header
694                         (buf, sizeof(buf), account->name,
695                          strlen("From: "));
696                 fprintf(fp, "From: %s <%s>\n", buf, account->address);
697         } else
698                 fprintf(fp, "From: %s\n", account->address);
699
700         fprintf(fp, "To: %s\n", to);
701
702         /* Subject */
703         notification_convert_header(buf, sizeof(buf), msginfo->subject,
704                                     strlen("Subject: "));
705         fprintf(fp, "Subject: Disposition notification: %s\n", buf);
706
707         /* Message ID */
708         generate_msgid(buf, sizeof(buf));
709         fprintf(fp, "Message-ID: <%s>\n", buf);
710
711         if (fclose(fp) == EOF) {
712                 FILE_OP_ERROR(tmp, "fclose");
713                 g_unlink(tmp);
714                 return -1;
715         }
716
717         /* put it in queue */
718         queue = account_get_special_folder(account, F_QUEUE);
719         if (!queue) queue = folder_get_default_queue();
720         if (!queue) {
721                 g_warning("can't find queue folder\n");
722                 g_unlink(tmp);
723                 return -1;
724         }
725         folder_item_scan(queue);
726         if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
727                 g_warning("can't queue the message\n");
728                 g_unlink(tmp);
729                 return -1;
730         }
731                 
732         if (prefs_common.work_offline && 
733             !inc_offline_should_override(TRUE,
734                 _("Claws Mail needs network access in order "
735                   "to send this email.")))
736                 return 0;
737
738         /* send it */
739         path = folder_item_fetch_msg(queue, num);
740         ok = procmsg_send_message_queue(path, &foo, queue, num, &queued_removed);
741         g_free(path);
742         g_free(foo);
743         if (ok == 0 && !queued_removed)
744                 folder_item_remove_msg(queue, num);
745
746         return ok;
747 }
748
749 static gboolean find_encrypted_func(GNode *node, gpointer data)
750 {
751         MimeInfo *mimeinfo = (MimeInfo *) node->data;
752         MimeInfo **encinfo = (MimeInfo **) data;
753         
754         if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
755                 *encinfo = mimeinfo;
756                 return TRUE;
757         }
758         
759         return FALSE;
760 }
761
762 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
763 {
764         MimeInfo *encinfo = NULL;
765
766         g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
767                 find_encrypted_func, &encinfo);
768         
769         return encinfo;
770 }
771
772 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
773                       gboolean all_headers)
774 {
775         gchar *file;
776         MimeInfo *mimeinfo, *encinfo;
777         gchar *subject = NULL;
778         g_return_val_if_fail(msginfo != NULL, -1);
779
780         if (messageview->mimeview->textview &&
781             messageview->mimeview->textview->loading) {
782                 messageview->mimeview->textview->stop_loading = TRUE;
783                 return 0;
784         }
785
786         if (messageview->toolbar)
787                 toolbar_set_learn_button
788                         (messageview->toolbar,
789                          MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
790         else
791                 toolbar_set_learn_button
792                         (messageview->mainwin->toolbar,
793                          MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
794
795         if (messageview->toolbar) {
796                 if (messageview->toolbar->learn_ham_btn)
797                         gtk_widget_set_sensitive(
798                                 messageview->toolbar->learn_ham_btn, 
799                                 procmsg_spam_can_learn());
800                 if (messageview->toolbar->learn_spam_btn)
801                         gtk_widget_set_sensitive(
802                                 messageview->toolbar->learn_spam_btn, 
803                                 procmsg_spam_can_learn());
804         }
805         messageview->updating = TRUE;
806         mimeinfo = procmime_scan_message(msginfo);
807         messageview->updating = FALSE;
808         
809         if (messageview->deferred_destroy) {
810                 messageview_destroy(messageview);
811                 return 0;
812         }
813
814         if (!mimeinfo) {
815                 textview_show_error(messageview->mimeview->textview);
816                 return -1;
817         }
818
819         while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
820                 debug_print("decrypting message part\n");
821                 if (privacy_mimeinfo_decrypt(encinfo) < 0) {
822                         alertpanel_error(_("Couldn't decrypt: %s"),
823                                 privacy_get_error());
824                         break;
825                 }
826         }
827         
828         messageview->updating = TRUE;
829         file = procmsg_get_message_file_path(msginfo);
830         messageview->updating = FALSE;
831         
832         if (messageview->deferred_destroy) {
833                 g_free(file);
834                 messageview_destroy(messageview);
835                 return 0;
836         }
837
838         if (!file) {
839                 g_warning("can't get message file path.\n");
840                 procmime_mimeinfo_free_all(mimeinfo);
841                 textview_show_error(messageview->mimeview->textview);
842                 return -1;
843         }
844         
845         if (messageview->msginfo != msginfo) {
846                 procmsg_msginfo_free(messageview->msginfo);
847                 messageview->msginfo = NULL;
848                 messageview_set_menu_sensitive(messageview);
849                 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
850                 if (!messageview->msginfo)
851                         messageview->msginfo = procmsg_msginfo_copy(msginfo);
852         } else {
853                 messageview->msginfo = NULL;
854                 messageview_set_menu_sensitive(messageview);
855                 messageview->msginfo = msginfo;
856         }
857         headerview_show(messageview->headerview, messageview->msginfo);
858
859         messageview_set_position(messageview, 0);
860
861         textview_set_all_headers(messageview->mimeview->textview, 
862                         messageview->all_headers);
863
864 #ifdef MAEMO
865         maemo_window_full_screen_if_needed(GTK_WINDOW(messageview->window));
866 #endif
867         if (messageview->window) {
868                 gtk_window_set_title(GTK_WINDOW(messageview->window), 
869                                 _("Claws Mail - Message View"));
870                 GTK_EVENTS_FLUSH();
871         }
872         mimeview_show_message(messageview->mimeview, mimeinfo, file);
873         
874         messageview_set_position(messageview, 0);
875
876         if (messageview->window && msginfo->subject) {
877                 subject = g_strdup(msginfo->subject);
878                 if (!g_utf8_validate(subject, -1, NULL)) {
879                         g_free(subject);
880                         subject = g_malloc(strlen(msginfo->subject)*2 +1);
881                         conv_localetodisp(subject, strlen(msginfo->subject)*2 +1, 
882                                 msginfo->subject);
883                 }
884                 if (g_utf8_validate(subject, -1, NULL))
885                         gtk_window_set_title(GTK_WINDOW(messageview->window), 
886                                 subject);
887                 g_free(subject);
888         }
889
890         if (msginfo && msginfo->folder) {
891                 msginfo->folder->last_seen = msginfo->msgnum;   
892         }
893
894         main_create_mailing_list_menu(messageview->mainwin, messageview->msginfo);
895
896         if (messageview->msginfo && messageview->msginfo->extradata
897             && messageview->msginfo->extradata->partial_recv)
898                 partial_recv_show(messageview->noticeview, 
899                                   messageview->msginfo);
900         else if (messageview->msginfo && messageview->msginfo->extradata &&
901             (messageview->msginfo->extradata->dispositionnotificationto || 
902              messageview->msginfo->extradata->returnreceiptto) &&
903             !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags) &&
904             !prefs_common.never_send_retrcpt)
905                 return_receipt_show(messageview->noticeview, 
906                                     messageview->msginfo);
907         else 
908                 noticeview_hide(messageview->noticeview);
909
910         mimeinfo = procmime_mimeinfo_next(mimeinfo);
911         if (!all_headers && mimeinfo && (mimeinfo->type != MIMETYPE_TEXT || 
912             strcasecmp(mimeinfo->subtype, "plain"))) {
913                 if (strcasecmp(mimeinfo->subtype, "html"))
914                         mimeview_show_part(messageview->mimeview,mimeinfo);
915                 else if (prefs_common.invoke_plugin_on_html)
916                         mimeview_select_mimepart_icon(messageview->mimeview,mimeinfo);
917         }
918
919         g_free(file);
920
921         return 0;
922 }
923
924 void messageview_reflect_prefs_pixmap_theme(void)
925 {
926         GList *cur;
927         MessageView *msgview;
928
929         for (cur = msgview_list; cur != NULL; cur = cur->next) {
930                 msgview = (MessageView*)cur->data;
931                 toolbar_update(TOOLBAR_MSGVIEW, msgview);
932                 mimeview_update(msgview->mimeview);
933         }
934 }
935
936 void messageview_clear(MessageView *messageview)
937 {
938         if (!messageview)
939                 return;
940         procmsg_msginfo_free(messageview->msginfo);
941         messageview->msginfo = NULL;
942         messageview->filtered = FALSE;
943         mimeview_clear(messageview->mimeview);
944         headerview_clear(messageview->headerview);
945         noticeview_hide(messageview->noticeview);
946 }
947
948 void messageview_destroy(MessageView *messageview)
949 {
950         debug_print("destroy messageview\n");
951         messageview_list = g_list_remove(messageview_list, messageview);
952
953         if (messageview->mainwin->summaryview->messageview == messageview)
954                 messageview->mainwin->summaryview->messageview = NULL;
955
956         if (messageview->mainwin->summaryview->ext_messageview == messageview)
957                 messageview->mainwin->summaryview->ext_messageview = NULL;
958
959         if (!messageview->deferred_destroy) {
960                 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
961                               messageview->msginfo_update_callback_id);
962         }
963
964         if (messageview->updating) {
965                 debug_print("uh oh, better not touch that now (fetching)\n");
966                 messageview->deferred_destroy = TRUE;
967                 gtk_widget_hide(messageview->window);
968                 return;
969         }
970         
971         if (messageview->mimeview->textview
972         &&  messageview->mimeview->textview->loading) {
973                 debug_print("uh oh, better not touch that now (loading text)\n");
974                 messageview->deferred_destroy = TRUE;
975                 messageview->mimeview->textview->stop_loading = TRUE;
976                 gtk_widget_hide(messageview->window);
977                 return;
978         }
979
980         headerview_destroy(messageview->headerview);
981         mimeview_destroy(messageview->mimeview);
982         noticeview_destroy(messageview->noticeview);
983
984         procmsg_msginfo_free(messageview->msginfo);
985         toolbar_clear_list(TOOLBAR_MSGVIEW);
986         if (messageview->toolbar) {
987                 toolbar_destroy(messageview->toolbar);
988                 g_free(messageview->toolbar);
989         }
990         
991         msgview_list = g_list_remove(msgview_list, messageview); 
992
993         if (messageview->window)
994                 gtk_widget_destroy(messageview->window);
995         g_free(messageview);
996 }
997
998 void messageview_delete(MessageView *msgview)
999 {
1000         MsgInfo *msginfo = NULL;
1001         FolderItem *trash = NULL;
1002         PrefsAccount *ac = NULL;
1003
1004         if (msgview->msginfo && msgview->mainwin && msgview->mainwin->summaryview)
1005                 msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1006         
1007         /* need a procmsg_msginfo_equal() */
1008         if (msginfo && msgview->msginfo && 
1009             msginfo->msgnum == msgview->msginfo->msgnum && 
1010             msginfo->folder == msgview->msginfo->folder) {
1011                 summary_delete_trash(msgview->mainwin->summaryview);
1012         } else {                
1013                 msginfo = msgview->msginfo;
1014
1015                 g_return_if_fail(msginfo != NULL);
1016
1017                 /* to get the trash folder, we have to choose either
1018                  * the folder's or account's trash default - we prefer
1019                  * the one in the account prefs */
1020                 if (msginfo->folder) {
1021                         if (NULL != (ac = account_find_from_item(msginfo->folder)))
1022                                 trash = account_get_special_folder(ac, F_TRASH);
1023                         if (!trash && msginfo->folder->folder)  
1024                                 trash = msginfo->folder->folder->trash;
1025                         /* if still not found, use the default */
1026                         if (!trash) 
1027                                 trash = folder_get_default_trash();
1028                 }       
1029
1030                 g_return_if_fail(trash != NULL);
1031
1032                 if (prefs_common.immediate_exec)
1033                         /* TODO: Delete from trash */
1034                         folder_item_move_msg(trash, msginfo);
1035                 else {
1036                         procmsg_msginfo_set_to_folder(msginfo, trash);
1037                         procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
1038                         /* NOTE: does not update to next message in summaryview */
1039                 }
1040         }               
1041 }
1042
1043 /* 
1044  * \brief update messageview with currently selected message in summaryview
1045  *        leave unchanged if summaryview is empty
1046  * \param pointer to MessageView
1047  */     
1048 static void messageview_update(MessageView *msgview)
1049 {
1050         SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
1051
1052         g_return_if_fail(summaryview != NULL);
1053         
1054         if (summaryview->selected) {
1055                 MsgInfo *msginfo = summary_get_selected_msg(summaryview);
1056                 if (msginfo == NULL)
1057                         return;
1058
1059                 messageview_show(msgview, msginfo, 
1060                                  msgview->all_headers);
1061         } 
1062 }
1063
1064 void messageview_quote_color_set(void)
1065 {
1066 }
1067
1068 void messageview_set_font(MessageView *messageview)
1069 {
1070 }
1071
1072 TextView *messageview_get_current_textview(MessageView *messageview)
1073 {
1074         TextView *text = NULL;
1075
1076         text = messageview->mimeview->textview;
1077
1078         return text;
1079 }
1080
1081 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
1082 {
1083         return mimeview_get_selected_part(messageview->mimeview);
1084 }
1085
1086 void messageview_copy_clipboard(MessageView *messageview)
1087 {
1088         gchar *text = messageview_get_selection(messageview);
1089         if (text) {
1090                 gtk_clipboard_set_text(
1091                         gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
1092                         text, -1);
1093         }
1094         g_free(text);
1095 }
1096
1097 void messageview_select_all(MessageView *messageview)
1098 {
1099         TextView *text;
1100
1101         text = messageview_get_current_textview(messageview);
1102         if (text) {
1103                 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
1104                 GtkTextBuffer *buffer;
1105                 GtkTextIter start, end;
1106
1107                 buffer = gtk_text_view_get_buffer(textview);
1108                 gtk_text_buffer_get_bounds(buffer, &start, &end);
1109                 gtk_text_buffer_select_range(buffer, &start, &end);
1110         }
1111 }
1112
1113 void messageview_set_position(MessageView *messageview, gint pos)
1114 {
1115         TextView *text;
1116
1117         text = messageview_get_current_textview(messageview);
1118         if (text)
1119                 textview_set_position(text, pos);
1120 }
1121
1122 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
1123                                    gboolean case_sens)
1124 {
1125         TextView *text;
1126
1127         if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1128                 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1129                 if (viewer && viewer->text_search) {
1130                         return viewer->text_search(viewer, FALSE, str, case_sens);
1131                 }
1132         }
1133
1134         text = messageview_get_current_textview(messageview);
1135         if (text)
1136                 return textview_search_string(text, str, case_sens);
1137         return FALSE;
1138 }
1139
1140 gboolean messageview_search_string_backward(MessageView *messageview,
1141                                             const gchar *str,
1142                                             gboolean case_sens)
1143 {
1144         TextView *text;
1145
1146         if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1147                 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1148                 if (viewer && viewer->text_search) {
1149                         return viewer->text_search(viewer, TRUE, str, case_sens);
1150                 }
1151         }
1152
1153         text = messageview_get_current_textview(messageview);
1154         if (text)       
1155                 return textview_search_string_backward(text,
1156                                                        str, case_sens);
1157         return FALSE;
1158 }
1159
1160 gboolean messageview_is_visible(MessageView *messageview)
1161 {
1162         if (messageview == NULL)
1163                 return FALSE;
1164         return messageview->visible;
1165 }
1166
1167 static void messageview_save_as(MessageView *messageview)
1168 {
1169         gchar *filename = NULL;
1170         MsgInfo *msginfo;
1171         gchar *src, *dest, *tmp;
1172
1173         if (!messageview->msginfo) return;
1174         msginfo = messageview->msginfo;
1175
1176         if (msginfo->subject) {
1177                 Xstrdup_a(filename, msginfo->subject, return);
1178                 subst_for_filename(filename);
1179         }
1180         if (filename && !g_utf8_validate(filename, -1, NULL)) {
1181                 gchar *oldstr = filename;
1182                 filename = conv_codeset_strdup(filename,
1183                                                conv_get_locale_charset_str(),
1184                                                CS_UTF_8);
1185                 if (!filename) {
1186                         g_warning("messageview_save_as(): failed to convert character set.");
1187                         filename = g_strdup(oldstr);
1188                 }
1189                 dest = filesel_select_file_save(_("Save as"), filename);
1190                 g_free(filename);
1191         } else
1192                 dest = filesel_select_file_save(_("Save as"), filename);
1193         if (!dest) return;
1194         if (is_file_exist(dest)) {
1195                 AlertValue aval;
1196
1197                 aval = alertpanel(_("Overwrite"),
1198                                   _("Overwrite existing file?"),
1199                                   GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
1200                 if (G_ALERTALTERNATE != aval) return;
1201         }
1202
1203         src = procmsg_get_message_file(msginfo);
1204         if (copy_file(src, dest, TRUE) < 0) {
1205                 tmp =  g_path_get_basename(dest);
1206                 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
1207                 g_free(tmp);
1208         }
1209         g_free(dest);
1210         g_free(src);
1211 }
1212
1213 static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
1214                                   MessageView *messageview)
1215 {
1216         messageview_destroy(messageview);
1217         return TRUE;
1218 }
1219
1220 static void messageview_size_allocate_cb(GtkWidget *widget,
1221                                          GtkAllocation *allocation)
1222 {
1223         g_return_if_fail(allocation != NULL);
1224
1225         prefs_common.msgwin_width  = allocation->width;
1226         prefs_common.msgwin_height = allocation->height;
1227 }
1228
1229 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
1230                         MessageView *messageview)
1231 {
1232         if (event && event->keyval == GDK_Escape && messageview->window) {
1233                 messageview_destroy(messageview);
1234                 return TRUE;
1235         }
1236
1237         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0)
1238                 return FALSE;
1239
1240         g_signal_stop_emission_by_name(G_OBJECT(widget),
1241                                         "key_press_event");
1242         mimeview_pass_key_press_event(messageview->mimeview, event);
1243         return FALSE;
1244 }
1245
1246 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1247 {
1248         gchar *addr = NULL;
1249         gboolean from_me = FALSE;
1250         if (msginfo->folder 
1251                 && (folder_has_parent_of_type(msginfo->folder, F_QUEUE)
1252                  || folder_has_parent_of_type(msginfo->folder, F_DRAFT)))
1253                 return;
1254
1255         addr = g_strdup(msginfo->from);
1256         if (addr) {
1257                 extract_address(addr);
1258                 if (account_find_from_address(addr)) {
1259                         from_me = TRUE;
1260                 }
1261                 g_free(addr);
1262         }
1263
1264         if (from_me) {
1265                 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1266                 noticeview_set_text(noticeview, _("You asked for a return receipt in this message."));
1267                 noticeview_set_button_text(noticeview, NULL);
1268                 noticeview_set_button_press_callback(noticeview, NULL, NULL);
1269         } else {
1270                 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1271                 noticeview_set_text(noticeview, _("This message asks for a return receipt."));
1272                 noticeview_set_button_text(noticeview, _("Send receipt"));
1273                 noticeview_set_button_press_callback(noticeview,
1274                                                      G_CALLBACK(return_receipt_send_clicked),
1275                                                      (gpointer) msginfo);
1276         }
1277         noticeview_show(noticeview);
1278 }
1279
1280 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1281 {
1282         MsgInfo *tmpmsginfo;
1283         gchar *file;
1284
1285         file = procmsg_get_message_file_path(msginfo);
1286         if (!file) {
1287                 g_warning("can't get message file path.\n");
1288                 return;
1289         }
1290
1291         tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1292         tmpmsginfo->folder = msginfo->folder;
1293         tmpmsginfo->msgnum = msginfo->msgnum;
1294
1295         if (disposition_notification_send(tmpmsginfo) >= 0) {
1296                 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1297                 noticeview_hide(noticeview);
1298         }               
1299
1300         procmsg_msginfo_free(tmpmsginfo);
1301         g_free(file);
1302 }
1303
1304 static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
1305 {
1306         gchar *text = NULL;
1307         gchar *button1 = NULL;
1308         gchar *button2 = NULL;
1309         void  *button1_cb = NULL;
1310         void  *button2_cb = NULL;
1311
1312         if (!msginfo->extradata)
1313                 return;
1314         if (!partial_msg_in_uidl_list(msginfo)) {
1315                 text = g_strdup_printf(_("This message has been partially "
1316                                 "retrieved,\nand has been deleted from the "
1317                                 "server."));
1318         } else {
1319                 switch (msginfo->planned_download) {
1320                 case POP3_PARTIAL_DLOAD_UNKN:
1321                         text = g_strdup_printf(_("This message has been "
1322                                         "partially retrieved;\nit is %s."),
1323                                         to_human_readable(
1324                                                 (off_t)(msginfo->total_size)));
1325                         button1 = _("Mark for download");
1326                         button2 = _("Mark for deletion");
1327                         button1_cb = partial_recv_dload_clicked;
1328                         button2_cb = partial_recv_del_clicked;
1329                         break;
1330                 case POP3_PARTIAL_DLOAD_DLOAD:
1331                         text = g_strdup_printf(_("This message has been "
1332                                         "partially retrieved;\nit is %s and "
1333                                         "will be downloaded."),
1334                                         to_human_readable(
1335                                                 (off_t)(msginfo->total_size)));
1336                         button1 = _("Unmark");
1337                         button1_cb = partial_recv_unmark_clicked;
1338                         button2 = _("Mark for deletion");
1339                         button2_cb = partial_recv_del_clicked;
1340                         break;
1341                 case POP3_PARTIAL_DLOAD_DELE:
1342                         text = g_strdup_printf(_("This message has been "
1343                                         "partially retrieved;\nit is %s and "
1344                                         "will be deleted."),
1345                                         to_human_readable(
1346                                                 (off_t)(msginfo->total_size)));
1347                         button1 = _("Mark for download");
1348                         button1_cb = partial_recv_dload_clicked;
1349                         button2 = _("Unmark");
1350                         button2_cb = partial_recv_unmark_clicked;
1351                         break;
1352                 default:
1353                         return;
1354                 }
1355         }
1356         
1357         noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1358         noticeview_set_text(noticeview, text);
1359         g_free(text);
1360         noticeview_set_button_text(noticeview, button1);
1361         noticeview_set_button_press_callback(noticeview,
1362                      G_CALLBACK(button1_cb), (gpointer) msginfo);
1363
1364         noticeview_set_2ndbutton_text(noticeview, button2);
1365         noticeview_set_2ndbutton_press_callback(noticeview,
1366                      G_CALLBACK(button2_cb), (gpointer) msginfo);
1367
1368         noticeview_show(noticeview);
1369 }
1370
1371 static void partial_recv_dload_clicked(NoticeView *noticeview, 
1372                                        MsgInfo *msginfo)
1373 {
1374         if (partial_mark_for_download(msginfo) == 0) {
1375                 partial_recv_show(noticeview, msginfo);
1376         }
1377 }
1378
1379 static void partial_recv_del_clicked(NoticeView *noticeview, 
1380                                        MsgInfo *msginfo)
1381 {
1382         if (partial_mark_for_delete(msginfo) == 0) {
1383                 partial_recv_show(noticeview, msginfo);
1384         }
1385 }
1386
1387 static void partial_recv_unmark_clicked(NoticeView *noticeview, 
1388                                        MsgInfo *msginfo)
1389 {
1390         if (partial_unmark(msginfo) == 0) {
1391                 partial_recv_show(noticeview, msginfo);
1392         }
1393 }
1394
1395 static void select_account_cb(GtkWidget *w, gpointer data)
1396 {
1397         *(gint*)data = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), MENU_VAL_ID));
1398 }
1399         
1400 static PrefsAccount *select_account_from_list(GList *ac_list)
1401 {
1402         GtkWidget *optmenu;
1403         GtkWidget *menu;
1404         gint account_id;
1405
1406         g_return_val_if_fail(ac_list != NULL, NULL);
1407         g_return_val_if_fail(ac_list->data != NULL, NULL);
1408         
1409         optmenu = gtk_option_menu_new();
1410         menu = gtkut_account_menu_new(ac_list, 
1411                         G_CALLBACK(select_account_cb), 
1412                         &account_id);
1413         if (!menu)
1414                 return NULL;
1415         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1416         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1417         account_id = ((PrefsAccount *) ac_list->data)->account_id;
1418         if (alertpanel_with_widget(
1419                                 _("Return Receipt Notification"),
1420                                 _("The message was sent to several of your "
1421                                   "accounts.\n"
1422                                   "Please choose which account do you want to "
1423                                   "use for sending the receipt notification:"),
1424                                 _("_Cancel"), _("_Send Notification"), NULL,
1425                                 FALSE, G_ALERTDEFAULT, optmenu) != G_ALERTALTERNATE)
1426                 return NULL;
1427         return account_find_from_id(account_id);
1428 }
1429
1430 /* 
1431  * \brief return selected messageview text, when nothing is 
1432  *        selected and message was filtered, return complete text
1433  *
1434  * \param  pointer to Messageview 
1435  *
1436  * \return pointer to text (needs to be free'd by calling func)
1437  */
1438 gchar *messageview_get_selection(MessageView *msgview)
1439 {
1440         TextView *textview;
1441         gchar *text = NULL;
1442         GtkTextView *edit = NULL;
1443         GtkTextBuffer *textbuf;
1444         gint body_pos = 0;
1445         
1446         g_return_val_if_fail(msgview != NULL, NULL);
1447
1448         if (msgview->mimeview->type == MIMEVIEW_VIEWER) {
1449                 MimeViewer *viewer = msgview->mimeview->mimeviewer;
1450                 if (viewer && viewer->get_selection) {
1451                         text = viewer->get_selection(viewer);
1452                         if (text)
1453                                 return text;
1454                 }
1455         }
1456
1457         textview = messageview_get_current_textview(msgview);
1458         g_return_val_if_fail(textview != NULL, NULL);
1459
1460         edit = GTK_TEXT_VIEW(textview->text);
1461         g_return_val_if_fail(edit != NULL, NULL);
1462         body_pos = textview->body_pos;
1463
1464         textbuf = gtk_text_view_get_buffer(edit);
1465
1466         if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
1467                 return gtkut_text_view_get_selection(edit);
1468         else if (msgview->filtered) {
1469                 GtkTextIter start_iter, end_iter;
1470                 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
1471                 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
1472                 gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
1473         } else
1474                 text = NULL;
1475
1476         return text;
1477 }
1478
1479 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1480 {
1481         MessageView *messageview = (MessageView *)data;
1482         messageview_save_as(messageview);
1483 }
1484
1485 #ifdef USE_GNOMEPRINT
1486 static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gint partnum) 
1487 {
1488         if (!mimeview 
1489         ||  !mimeview->textview
1490         ||  !mimeview->textview->text)
1491                 alertpanel_warning(_("Cannot print: the message doesn't "
1492                                      "contain text."));
1493         else {
1494                 gtk_widget_realize(mimeview->textview->text);
1495                 if (partnum > 0) {
1496                         mimeview_select_part_num(mimeview, partnum);
1497                 }
1498                 if (mimeview->type == MIMEVIEW_VIEWER) {
1499                         MimeViewer *viewer = mimeview->mimeviewer;
1500                         if (viewer && viewer->print) {
1501                                 viewer->print(viewer);
1502                                 return;
1503                         }
1504                 }
1505                 if (sel_start != -1 && sel_end != -1) {
1506                         GtkTextIter start, end;
1507                         GtkTextView *text = GTK_TEXT_VIEW(mimeview->textview->text);
1508                         GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1509
1510                         gtk_text_buffer_get_iter_at_offset(buffer, &start, sel_start);
1511                         gtk_text_buffer_get_iter_at_offset(buffer, &end, sel_end);
1512                         gtk_text_buffer_select_range(buffer, &start, &end);
1513                 }
1514
1515                 gedit_print(GTK_TEXT_VIEW(mimeview->textview->text));
1516         }
1517 }
1518
1519 void messageview_print(MsgInfo *msginfo, gboolean all_headers, 
1520                         gint sel_start, gint sel_end, gint partnum) 
1521 {
1522         PangoFontDescription *font_desc = NULL;
1523         MessageView *tmpview = messageview_create_with_new_window_visible(
1524                                 mainwindow_get_mainwindow(), FALSE);
1525
1526         if (prefs_common.use_different_print_font) {
1527                 font_desc = pango_font_description_from_string
1528                                                 (prefs_common.printfont);
1529         } else {
1530                 font_desc = pango_font_description_from_string
1531                                                 (prefs_common.textfont);
1532         }
1533         if (font_desc) {
1534                 gtk_widget_modify_font(tmpview->mimeview->textview->text, 
1535                         font_desc);
1536                 pango_font_description_free(font_desc);
1537         }
1538
1539         tmpview->all_headers = all_headers;
1540         if (msginfo && messageview_show(tmpview, msginfo, 
1541                 tmpview->all_headers) >= 0) {
1542                         print_mimeview(tmpview->mimeview, 
1543                                 sel_start, sel_end, partnum);
1544         }
1545         messageview_destroy(tmpview);
1546 }
1547 #endif
1548
1549 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1550 {
1551         MessageView *messageview = (MessageView *)data;
1552 #ifndef USE_GNOMEPRINT
1553         gchar *cmdline = NULL;
1554         gchar *p;
1555 #else
1556         gint sel_start = -1, sel_end = -1, partnum = 0;
1557 #endif
1558
1559         if (!messageview->msginfo) return;
1560 #ifndef USE_GNOMEPRINT
1561         cmdline = input_dialog(_("Print"),
1562                                _("Enter the print command line:\n"
1563                                  "('%s' will be replaced with file name)"),
1564                                prefs_common.print_cmd);
1565         if (!cmdline) return;
1566         if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1567             strchr(p + 2, '%')) {
1568                 alertpanel_error(_("Print command line is invalid:\n'%s'"),
1569                                  cmdline);
1570                 g_free(cmdline);
1571                 return;
1572         }
1573         procmsg_print_message(messageview->msginfo, cmdline);
1574         g_free(cmdline);
1575 #else
1576         partnum = mimeview_get_selected_part_num(messageview->mimeview);
1577         textview_get_selection_offsets(messageview->mimeview->textview,
1578                 &sel_start, &sel_end);
1579         messageview_print(messageview->msginfo, messageview->all_headers, 
1580                 sel_start, sel_end, partnum);
1581 #endif
1582 }
1583
1584 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1585 {
1586         MessageView *messageview = (MessageView *)data;
1587         messageview_destroy(messageview);
1588 }
1589
1590 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1591 {
1592         MessageView *messageview = (MessageView *)data;
1593         messageview_copy_clipboard(messageview);
1594 }
1595
1596 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1597 {
1598         MessageView *messageview = (MessageView *)data;
1599         messageview_select_all(messageview);
1600 }
1601
1602 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1603 {
1604         MessageView *messageview = (MessageView *)data;
1605         message_search(messageview);
1606 }
1607
1608 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1609 {
1610         MessageView *messageview = (MessageView *)data;
1611         const gchar *charset;
1612
1613         if (GTK_CHECK_MENU_ITEM(widget)->active) {
1614                 charset = conv_get_charset_str((CharSet)action);
1615                 g_free(messageview->forced_charset);
1616                 messageview->forced_charset = g_strdup(charset);
1617                 procmime_force_charset(charset);
1618                 
1619                 messageview_show(messageview, messageview->msginfo, FALSE);
1620         }
1621 }
1622
1623 static void set_decode_cb(gpointer data, guint action, GtkWidget *widget)
1624 {
1625         MessageView *messageview = (MessageView *)data;
1626         if (GTK_CHECK_MENU_ITEM(widget)->active) {
1627                 messageview->forced_encoding = (EncodingType)action;
1628
1629                 messageview_show(messageview, messageview->msginfo, FALSE);
1630                 
1631                 debug_print("forced encoding: %d\n", action);
1632         }
1633 }
1634
1635
1636 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1637 {
1638         MessageView *messageview = (MessageView *)data;
1639         SourceWindow *srcwin;
1640
1641         if (!messageview->msginfo) return;
1642
1643         srcwin = source_window_create();
1644         source_window_show_msg(srcwin, messageview->msginfo);
1645         source_window_show(srcwin);
1646 }
1647
1648 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1649 {
1650         MessageView *messageview = (MessageView *)data;
1651         MsgInfo *msginfo = messageview->msginfo;
1652
1653         if (messageview->mimeview->textview &&
1654             messageview->mimeview->textview->loading) {
1655                 return;
1656         }
1657         if (messageview->updating)
1658                 return;
1659
1660         messageview->all_headers = 
1661                         GTK_CHECK_MENU_ITEM(widget)->active;
1662         if (!msginfo) return;
1663         messageview->msginfo = NULL;
1664         messageview_show(messageview, msginfo,
1665                          GTK_CHECK_MENU_ITEM(widget)->active);
1666         procmsg_msginfo_free(msginfo);
1667         main_window_set_menu_sensitive(messageview->mainwin);
1668 }
1669
1670 #define SET_CHECK_MENU_ACTIVE(path, active) \
1671 { \
1672         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1673         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1674 }
1675
1676 static void msg_hide_quotes_cb(gpointer data, guint action, GtkWidget *widget)
1677 {
1678         MessageView *messageview = (MessageView *)data;
1679         MsgInfo *msginfo = messageview->msginfo;
1680         static gboolean updating_menu = FALSE;
1681         GtkItemFactory *ifactory = gtk_item_factory_from_widget(messageview->menubar);
1682         GtkWidget *menuitem;
1683         if (updating_menu)
1684                 return;
1685
1686         prefs_common.hide_quotes = 
1687                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
1688         
1689         updating_menu=TRUE;
1690         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
1691         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
1692         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
1693         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);      
1694         updating_menu=FALSE;
1695         if (!msginfo) return;
1696         messageview->msginfo = NULL;
1697         messageview_show(messageview, msginfo,
1698                          messageview->all_headers);
1699         procmsg_msginfo_free(msginfo);
1700         
1701         /* update main window */
1702         main_window_set_menu_sensitive(messageview->mainwin);
1703         summary_redisplay_msg(messageview->mainwin->summaryview);
1704 }
1705 #undef SET_CHECK_MENU_ACTIVE
1706
1707 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1708 {
1709         MessageView *messageview = (MessageView *)data;
1710         PrefsAccount *ac = NULL;
1711         FolderItem *item = NULL;
1712
1713         if (messageview->msginfo)
1714                 item = messageview->msginfo->folder;
1715
1716         if (item) {
1717                 ac = account_find_from_item(item);
1718                 if (ac && ac->protocol == A_NNTP &&
1719                     item->stype == F_NEWS) {
1720                         compose_new(ac, item->path, NULL);
1721                         return;
1722                 }
1723         }
1724
1725         compose_new(ac, NULL, NULL);
1726 }
1727
1728 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1729 {
1730         MessageView *messageview = (MessageView *)data;
1731         GSList *msginfo_list = NULL;
1732
1733         g_return_if_fail(messageview->msginfo);
1734
1735         msginfo_list = g_slist_append(msginfo_list, messageview->msginfo);
1736         compose_reply_from_messageview(messageview, msginfo_list, action);
1737         g_slist_free(msginfo_list);
1738 }
1739
1740 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1741 {
1742         addressbook_open(NULL);
1743 }
1744
1745 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1746 {
1747         MessageView *messageview = (MessageView *)data;
1748         MsgInfo *msginfo;
1749         gchar *from;
1750
1751         if (!messageview->msginfo) return;
1752         msginfo = messageview->msginfo;
1753         Xstrdup_a(from, msginfo->from, return);
1754         eliminate_address_comment(from);
1755         extract_address(from);
1756         addressbook_add_contact(msginfo->fromname, from, NULL);
1757 }
1758
1759 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1760 {
1761         MessageView *messageview = (MessageView *)data;
1762         FolderItem * item;
1763         
1764         if (!messageview->msginfo) return;
1765         
1766         item = messageview->msginfo->folder;
1767         summary_msginfo_filter_open(item,  messageview->msginfo,
1768                                     (PrefsFilterType)action, 0);
1769 }
1770
1771 static void create_processing_cb(gpointer data, guint action,
1772                                  GtkWidget *widget)
1773 {
1774         MessageView *messageview = (MessageView *)data;
1775         FolderItem * item;
1776         
1777         if (!messageview->msginfo) return;
1778         
1779         item = messageview->msginfo->folder;
1780         summary_msginfo_filter_open(item,  messageview->msginfo,
1781                                     (PrefsFilterType)action, 1);
1782 }
1783
1784 static void open_urls_cb(gpointer data, guint action, GtkWidget *widget)
1785 {
1786         MessageView *messageview = (MessageView *)data;
1787         messageview_list_urls(messageview);
1788 }
1789
1790 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1791 {
1792         about_show();
1793 }
1794
1795 static gboolean messageview_update_msg(gpointer source, gpointer data)
1796 {
1797         MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1798         MessageView *messageview = (MessageView *)data;
1799
1800         if (messageview->msginfo != msginfo_update->msginfo)
1801                 return FALSE;
1802
1803         if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1804                 messageview_clear(messageview);
1805                 messageview_update(messageview);
1806         }
1807
1808         return FALSE;
1809 }
1810
1811 void messageview_set_menu_sensitive(MessageView *messageview)
1812 {
1813         GtkItemFactory *ifactory;
1814         GtkWidget *menuitem = NULL;
1815
1816         if (!messageview || !messageview->new_window) 
1817                 return;
1818         /* do some smart things */
1819         if (!messageview->menubar) return;
1820         ifactory = gtk_item_factory_from_widget(messageview->menubar);
1821         if (!ifactory) return;
1822
1823         if (prefs_common.hide_quotes) {
1824                 menuitem = NULL;
1825                 if (prefs_common.hide_quotes == 1)
1826                         menuitem = gtk_item_factory_get_widget(ifactory, 
1827                                         "/View/Quotes/Fold all");
1828                 if (prefs_common.hide_quotes == 2)
1829                         menuitem = gtk_item_factory_get_widget(ifactory, 
1830                                         "/View/Quotes/Fold from level 2");
1831                 if (prefs_common.hide_quotes == 3)
1832                         menuitem = gtk_item_factory_get_widget(ifactory, 
1833                                         "/View/Quotes/Fold from level 3");
1834                 gtk_check_menu_item_set_active
1835                         (GTK_CHECK_MENU_ITEM(menuitem),
1836                          TRUE);
1837         }
1838 }
1839
1840 void messageview_learn (MessageView *msgview, gboolean is_spam)
1841 {
1842         if (is_spam) {
1843                 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, TRUE) == 0)
1844                         procmsg_msginfo_set_flags(msgview->msginfo, MSG_SPAM, 0);
1845                 else
1846                         log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
1847                 
1848         } else {
1849                 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, FALSE) == 0)
1850                         procmsg_msginfo_unset_flags(msgview->msginfo, MSG_SPAM, 0);
1851                 else
1852                         log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
1853         }
1854         if (msgview->toolbar)
1855                 toolbar_set_learn_button
1856                         (msgview->toolbar,
1857                          MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1858         else
1859                 toolbar_set_learn_button
1860                         (msgview->mainwin->toolbar,
1861                          MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1862 }
1863
1864 void messageview_list_urls (MessageView *msgview)
1865 {
1866         GSList *cur = msgview->mimeview->textview->uri_list;
1867         GSList *newlist = NULL;
1868         for (; cur; cur = cur->next) {
1869                 ClickableText *uri = (ClickableText *)cur->data;
1870                 if (!uri->uri || !g_ascii_strncasecmp(uri->uri, "mailto:", 7) 
1871                 ||  uri->is_quote)
1872                         continue;
1873                 newlist = g_slist_prepend(newlist, uri);
1874         }
1875         newlist = g_slist_reverse(newlist);
1876         uri_opener_open(msgview, newlist);
1877         g_slist_free(newlist);
1878 }