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