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