fde21b8514190bf504dbc41dc168fa4c1e912900
[claws.git] / src / messageview.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2011 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/gtk.h>
26 #include <stdio.h>
27 #include <ctype.h>
28 #include <string.h>
29
30 #include "main.h"
31 #include "messageview.h"
32 #include "message_search.h"
33 #include "headerview.h"
34 #include "summaryview.h"
35 #include "textview.h"
36 #include "mimeview.h"
37 #include "menu.h"
38 #include "about.h"
39 #include "filesel.h"
40 #include "foldersel.h"
41 #include "sourcewindow.h"
42 #include "addressbook.h"
43 #include "alertpanel.h"
44 #include "inputdialog.h"
45 #include "mainwindow.h"
46 #include "manage_window.h"
47 #include "procmsg.h"
48 #include "procheader.h"
49 #include "procmime.h"
50 #include "account.h"
51 #include "action.h"
52 #include "prefs_common.h"
53 #include "prefs_account.h"
54 #include "gtkutils.h"
55 #include "utils.h"
56 #include "send_message.h"
57 #include "stock_pixmap.h"
58 #include "hooks.h"
59 #include "filtering.h"
60 #include "partial_download.h"
61 #include "uri_opener.h"
62 #include "inc.h"
63 #include "log.h"
64 #include "combobox.h"
65 #include "printing.h"
66 #include "quoted-printable.h"
67 #include "version.h"
68 #include "statusbar.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 #ifndef MAEMO
78 static gboolean key_pressed             (GtkWidget      *widget,
79                                          GdkEventKey    *event,
80                                          MessageView    *messageview);
81 #endif
82 static void return_receipt_show         (NoticeView     *noticeview, 
83                                          MsgInfo        *msginfo);      
84 static void return_receipt_send_clicked (NoticeView     *noticeview, 
85                                          MsgInfo        *msginfo);
86 static void partial_recv_show           (NoticeView     *noticeview, 
87                                          MsgInfo        *msginfo);      
88 static void partial_recv_dload_clicked  (NoticeView     *noticeview, 
89                                          MsgInfo        *msginfo);
90 static void partial_recv_del_clicked    (NoticeView     *noticeview, 
91                                          MsgInfo        *msginfo);
92 static void partial_recv_unmark_clicked (NoticeView     *noticeview, 
93                                          MsgInfo        *msginfo);
94 static void save_as_cb                  (GtkAction      *action,
95                                          gpointer        data);
96 static void page_setup_cb               (GtkAction      *action,
97                                          gpointer        data);
98 static void print_cb                    (GtkAction      *action,
99                                          gpointer        data);
100 static void close_cb                    (GtkAction      *action,
101                                          gpointer        data);
102 static void copy_cb                     (GtkAction      *action,
103                                          gpointer        data);
104 static void allsel_cb                   (GtkAction      *action,
105                                          gpointer        data);
106 static void search_cb                   (GtkAction      *action,
107                                          gpointer        data);
108
109 static void prev_cb                     (GtkAction      *action,
110                                          gpointer        data);
111 static void next_cb                     (GtkAction      *action,
112                                          gpointer        data);
113 static void prev_unread_cb              (GtkAction      *action,
114                                          gpointer        data);
115 static void next_unread_cb              (GtkAction      *action,
116                                          gpointer        data);
117 static void prev_new_cb                 (GtkAction      *action,
118                                          gpointer        data);
119 static void next_new_cb                 (GtkAction      *action,
120                                          gpointer        data);
121 static void prev_marked_cb              (GtkAction      *action,
122                                          gpointer        data);
123 static void next_marked_cb              (GtkAction      *action,
124                                          gpointer        data);
125 static void prev_labeled_cb             (GtkAction      *action,
126                                          gpointer        data);
127 static void next_labeled_cb             (GtkAction      *action,
128                                          gpointer        data);
129 static void prev_history_cb             (GtkAction      *action,
130                                          gpointer        data);
131 static void next_history_cb             (GtkAction      *action,
132                                          gpointer        data);
133 static void parent_cb                   (GtkAction      *action,
134                                          gpointer        data);
135 static void goto_unread_folder_cb       (GtkAction      *action,
136                                          gpointer        data);
137 static void goto_folder_cb              (GtkAction      *action,
138                                          gpointer        data);
139
140 static void scroll_prev_line_cb         (GtkAction      *action,
141                                          gpointer        data);
142 static void scroll_next_line_cb         (GtkAction      *action,
143                                           gpointer        data);
144 static void scroll_next_page_cb         (GtkAction      *action,
145                                          gpointer        data);
146 static void scroll_prev_page_cb         (GtkAction      *action,
147                                          gpointer        data);
148
149 static void set_charset_cb              (GtkAction *action, GtkRadioAction *current, gpointer data);
150 static void set_decode_cb               (GtkAction *action, GtkRadioAction *current, gpointer data);
151
152 static void view_source_cb              (GtkAction      *action,
153                                          gpointer        data);
154
155 static void show_all_header_cb          (GtkToggleAction        *action,
156                                          gpointer        data);
157 static void msg_hide_quotes_cb          (GtkToggleAction        *action,
158                                          gpointer        data);
159
160 static void compose_cb                  (GtkAction      *action,
161                                          gpointer        data);
162 static void reply_cb                    (GtkAction      *action,
163                                          gpointer        data);
164
165 static PrefsAccount *select_account_from_list
166                                         (GList          *ac_list);
167 static void addressbook_open_cb         (GtkAction      *action,
168                                          gpointer        data);
169 static void add_address_cb              (GtkAction      *action,
170                                          gpointer        data);
171 static void create_filter_cb            (GtkAction      *action,
172                                          gpointer        data);
173 static void create_processing_cb        (GtkAction      *action,
174                                          gpointer        data);
175 static void open_urls_cb                (GtkAction      *action,
176                                          gpointer        data);
177
178 static void about_cb                    (GtkAction      *action,
179                                          gpointer        data);
180 static void messageview_update          (MessageView    *msgview,
181                                          MsgInfo        *old_msginfo);
182 static gboolean messageview_update_msg  (gpointer source, gpointer data);
183
184 static void messageview_nothing_cb         (GtkAction *action, gpointer data)
185 {
186
187 }
188
189 static GList *msgview_list = NULL;
190 static GtkActionEntry msgview_entries[] =
191 {
192         {"Menu",                        NULL, "Menu" },
193 /* menus */
194         {"File",                        NULL, N_("_File") },
195         {"Edit",                        NULL, N_("_Edit") },
196         {"View",                        NULL, N_("_View") },
197         {"Message",                     NULL, N_("_Message") },
198         {"Tools",                       NULL, N_("_Tools") },
199         {"Help",                        NULL, N_("_Help") },
200         {"PlaceHolder",                 NULL, "Placeholder", NULL, NULL, G_CALLBACK(messageview_nothing_cb) },
201
202 /* File menu */
203         {"File/SaveAs",                 NULL, N_("_Save as..."), "<control>S", NULL, G_CALLBACK(save_as_cb) },
204         {"File/PageSetup",              NULL, N_("Page setup..."), NULL, NULL, G_CALLBACK(page_setup_cb) },
205         {"File/Print",                  NULL, N_("_Print..."), "<control>P", NULL, G_CALLBACK(print_cb) },
206         {"File/---",                    NULL, "---", NULL, NULL, NULL },
207         {"File/Close",                  NULL, N_("_Close"), "<control>W", NULL, G_CALLBACK(close_cb) },
208
209 /* Edit menu */
210         {"Edit/Copy",                   NULL, N_("_Copy"), "<control>C", NULL, G_CALLBACK(copy_cb) },
211         {"Edit/SelectAll",              NULL, N_("_Select all"), "<control>A", NULL, G_CALLBACK(allsel_cb) },
212         {"Edit/---",                    NULL, "---", NULL, NULL, NULL },
213         {"Edit/Find",                   NULL, N_("_Find"), "<control>F", NULL, G_CALLBACK(search_cb) },
214         
215 /* View menu */
216         {"View/Goto",                   NULL, N_("_Go to") },
217         {"View/Goto/Prev",              NULL, N_("_Previous message"), "P", NULL, G_CALLBACK(prev_cb) },
218         {"View/Goto/Next",              NULL, N_("_Next message"), "N", NULL, G_CALLBACK(next_cb) },
219         {"View/Goto/---",               NULL, "---", NULL, NULL, NULL },
220         {"View/Goto/PrevUnread",        NULL, N_("P_revious unread message"), "<shift>P", NULL, G_CALLBACK(prev_unread_cb) },
221         {"View/Goto/NextUnread",        NULL, N_("N_ext unread message"), "<shift>N", NULL, G_CALLBACK(next_unread_cb) },
222         /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
223         {"View/Goto/PrevNew",           NULL, N_("Previous ne_w message"), NULL, NULL, G_CALLBACK(prev_new_cb) },
224         {"View/Goto/NextNew",           NULL, N_("Ne_xt new message"), NULL, NULL, G_CALLBACK(next_new_cb) },
225         /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
226         {"View/Goto/PrevMarked",        NULL, N_("Previous _marked message"), NULL, NULL, G_CALLBACK(prev_marked_cb) },
227         {"View/Goto/NextMarked",        NULL, N_("Next m_arked message"), NULL, NULL, G_CALLBACK(next_marked_cb) },
228         /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
229         {"View/Goto/PrevLabeled",       NULL, N_("Previous _labeled message"), NULL, NULL, G_CALLBACK(prev_labeled_cb) },
230         {"View/Goto/NextLabeled",       NULL, N_("Next la_beled message"), NULL, NULL, G_CALLBACK(next_labeled_cb) },
231         /* {"View/Goto/---",                    NULL, "---", NULL, NULL, NULL }, */
232         {"View/Goto/PrevHistory",       NULL, N_("Previous opened message"), "<alt>Left", NULL, G_CALLBACK(prev_history_cb) },
233         {"View/Goto/NextHistory",       NULL, N_("Next opened message"), "<alt>Right", NULL, G_CALLBACK(next_history_cb) },
234         /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
235         {"View/Goto/ParentMessage",     NULL, N_("Parent message"), "<control>Up", NULL, G_CALLBACK(parent_cb) },
236         /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
237         {"View/Goto/NextUnreadFolder",  NULL, N_("Next unread _folder"), "<shift>G", NULL, G_CALLBACK(goto_unread_folder_cb) },
238         {"View/Goto/OtherFolder",       NULL, N_("_Other folder..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
239         /* {"View/Goto/---",            NULL, "---", NULL, NULL, NULL }, */
240         {"View/Scroll",                 NULL, N_("Message scroll") },
241         {"View/Scroll/PrevLine",        NULL, N_("Previous line"), NULL, NULL, G_CALLBACK(scroll_prev_line_cb) },
242         {"View/Scroll/NextLine",        NULL, N_("Next line"), NULL, NULL, G_CALLBACK(scroll_next_line_cb) },
243         {"View/Scroll/PrevPage",        NULL, N_("Previous page"), NULL, NULL, G_CALLBACK(scroll_prev_page_cb) },
244         {"View/Scroll/NextPage",        NULL, N_("Next page"), NULL, NULL, G_CALLBACK(scroll_next_page_cb) },
245         /* {"View/Scroll/---",          NULL, "---", NULL, NULL, NULL }, */
246
247         {"View/Encoding",               NULL, N_("Character _encoding") }, /* set_charset_cb */
248         {"View/Encoding/---",           NULL, "---" },
249 #define ENC_ACTION(cs_char,c_char,string) \
250         { "View/Encoding/" cs_char, NULL, N_(string), NULL, NULL, c_char }
251
252         {"View/Encoding/Western",       NULL, N_("Western European") },
253         {"View/Encoding/Baltic",        NULL, N_("Baltic") },
254         {"View/Encoding/Hebrew",        NULL, N_("Hebrew") },
255         {"View/Encoding/Arabic",        NULL, N_("Arabic") },
256         {"View/Encoding/Cyrillic",      NULL, N_("Cyrillic") },
257         {"View/Encoding/Japanese",      NULL, N_("Japanese") },
258         {"View/Encoding/Chinese",       NULL, N_("Chinese") },
259         {"View/Encoding/Korean",        NULL, N_("Korean") },
260         {"View/Encoding/Thai",          NULL, N_("Thai") },
261
262         {"View/Decode",                 NULL, N_("Decode") }, /* set_decode_cb */
263         {"View/Decode/---",             NULL, "---" },
264
265 #define DEC_ACTION(cs_type,c_type,string) \
266         { "View/Decode/" cs_type, NULL, N_(string), NULL, NULL, c_type }
267
268         {"View/---",                    NULL, "---", NULL, NULL, NULL },
269         {"View/MessageSource",          NULL, N_("Mess_age source"), "<control>U", NULL, G_CALLBACK(view_source_cb) },
270
271         {"View/Quotes",                 NULL, N_("Quotes") }, 
272
273 /* Message menu */
274         {"Message/Compose",             NULL, N_("Compose _new message"), "<control>M", NULL, G_CALLBACK(compose_cb) },
275         {"Message/---",                 NULL, "---", NULL, NULL, NULL },
276
277         {"Message/Reply",               NULL, N_("_Reply"), "<control>R", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY */
278         {"Message/ReplyTo",             NULL, N_("Repl_y to") }, 
279         {"Message/ReplyTo/All",         NULL, N_("_all"), "<control><shift>R", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY_TO_ALL */
280         {"Message/ReplyTo/Sender",      NULL, N_("_sender"), NULL, NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY_TO_SENDER */
281         {"Message/ReplyTo/List",        NULL, N_("mailing _list"), "<control>L", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY_TO_LIST */
282         /* {"Message/---",                      NULL, "---", NULL, NULL, NULL }, */
283
284         {"Message/Forward",             NULL, N_("_Forward"), "<control><alt>F", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_FORWARD_INLINE */
285         {"Message/ForwardAtt",          NULL, N_("For_ward as attachment"), NULL, NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_FORWARD_AS_ATTACH */
286         {"Message/Redirect",            NULL, N_("Redirec_t"), NULL, NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REDIRECT */
287
288 /* Tools menu */        
289         {"Tools/AddressBook",           NULL, N_("_Address book"), "<control><shift>A", NULL, G_CALLBACK(addressbook_open_cb) }, 
290         {"Tools/AddSenderToAB",         NULL, N_("Add sender to address boo_k"), NULL, NULL, G_CALLBACK(add_address_cb) }, 
291         {"Tools/---",                   NULL, "---", NULL, NULL, NULL },
292
293         {"Tools/CreateFilterRule",                      NULL, N_("_Create filter rule") },
294         {"Tools/CreateFilterRule/Automatically",        NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_AUTO */
295         {"Tools/CreateFilterRule/ByFrom",               NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_FROM */
296         {"Tools/CreateFilterRule/ByTo",                 NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_TO     */
297         {"Tools/CreateFilterRule/BySubject",            NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_SUBJECT */
298
299         {"Tools/CreateProcessingRule",                  NULL, N_("Create processing rule") },
300         {"Tools/CreateProcessingRule/Automatically",    NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
301         {"Tools/CreateProcessingRule/ByFrom",           NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
302         {"Tools/CreateProcessingRule/ByTo",             NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
303         {"Tools/CreateProcessingRule/BySubject",                NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_processing_cb) }, 
304
305         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
306
307         {"Tools/ListUrls",              NULL, N_("List _URLs..."), "<control><shift>U", NULL, G_CALLBACK(open_urls_cb) }, 
308
309         /* {"Tools/---",                        NULL, "---", NULL, NULL, NULL }, */
310         {"Tools/Actions",       NULL, N_("Actio_ns") },
311         {"Tools/Actions/PlaceHolder",   NULL, "Placeholder", NULL, NULL, G_CALLBACK(messageview_nothing_cb) },
312
313 /* Help menu */
314         {"Help/About",          NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_cb) }, 
315 };
316
317 static GtkToggleActionEntry msgview_toggle_entries[] =
318 {
319         {"View/AllHeaders",             NULL, N_("Show all _headers"), "<control>H", NULL, G_CALLBACK(show_all_header_cb) }, /* toggle */
320         {"View/Quotes/CollapseAll",     NULL, N_("_Collapse all"), "<control><shift>Q", NULL, G_CALLBACK(msg_hide_quotes_cb) }, /* 1 toggle */
321         {"View/Quotes/Collapse2",               NULL, N_("Collapse from level _2"), NULL, NULL, G_CALLBACK(msg_hide_quotes_cb) }, /* 2 toggle */
322         {"View/Quotes/Collapse3",               NULL, N_("Collapse from level _3"), NULL, NULL, G_CALLBACK(msg_hide_quotes_cb) }, /* 3 toggle */
323 };
324
325 static GtkRadioActionEntry msgview_radio_enc_entries[] =
326 {
327         ENC_ACTION(CS_AUTO, C_AUTO, N_("_Automatic")), /* RADIO set_charset_cb */
328         ENC_ACTION(CS_US_ASCII, C_US_ASCII, N_("7bit ASCII (US-ASC_II)")), /* RADIO set_charset_cb */
329         ENC_ACTION(CS_UTF_8, C_UTF_8, N_("Unicode (_UTF-8)")), /* RADIO set_charset_cb */
330         ENC_ACTION("Western/"CS_ISO_8859_1, C_ISO_8859_1, "ISO-8859-_1"), /* RADIO set_charset_cb */
331         ENC_ACTION("Western/"CS_ISO_8859_15, C_ISO_8859_15, "ISO-8859-15"), /* RADIO set_charset_cb */
332         ENC_ACTION("Western/"CS_WINDOWS_1252, C_WINDOWS_1252, "Windows-1252"), /* RADIO set_charset_cb */
333         ENC_ACTION(CS_ISO_8859_2, C_ISO_8859_2, N_("Central European (ISO-8859-_2)")), /* RADIO set_charset_cb */
334         ENC_ACTION("Baltic/"CS_ISO_8859_13, C_ISO_8859_13, "ISO-8859-13"), /* RADIO set_charset_cb */
335         ENC_ACTION("Baltic/"CS_ISO_8859_4, C_ISO_8859_14, "ISO-8859-_4"), /* RADIO set_charset_cb */
336         ENC_ACTION(CS_ISO_8859_7, C_ISO_8859_7, N_("Greek (ISO-8859-_7)")), /* RADIO set_charset_cb */
337         ENC_ACTION("Hebrew/"CS_ISO_8859_8, C_ISO_8859_8, "ISO-8859-_8"), /* RADIO set_charset_cb */
338         ENC_ACTION("Hebrew/"CS_WINDOWS_1255, C_WINDOWS_1255, "Windows-1255"), /* RADIO set_charset_cb */
339         ENC_ACTION("Arabic/"CS_ISO_8859_6, C_ISO_8859_6, "ISO-8859-_6"), /* RADIO set_charset_cb */
340         ENC_ACTION("Arabic/"CS_WINDOWS_1256, C_WINDOWS_1256, "Windows-1256"), /* RADIO set_charset_cb */
341         ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO set_charset_cb */
342         ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO set_charset_cb */
343         ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO set_charset_cb */
344         ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO set_charset_cb */
345         ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO set_charset_cb */
346         ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO set_charset_cb */
347         ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO set_charset_cb */
348         ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO set_charset_cb */
349         ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO set_charset_cb */
350         ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO set_charset_cb */
351         ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO set_charset_cb */
352         ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO set_charset_cb */
353         ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO set_charset_cb */
354         ENC_ACTION("Chinese/"CS_EUC_TW, C_EUC_TW, "EUC-_TW"), /* RADIO set_charset_cb */
355         ENC_ACTION("Korean/"CS_EUC_KR, C_EUC_KR, "_EUC-KR"), /* RADIO set_charset_cb */
356         ENC_ACTION("Korean/"CS_ISO_2022_KR, C_ISO_2022_KR, "_ISO-2022-KR"), /* RADIO set_charset_cb */
357         ENC_ACTION("Thai/"CS_TIS_620, C_TIS_620, "_TIS-620-KR"), /* RADIO set_charset_cb */
358         ENC_ACTION("Thai/"CS_WINDOWS_874, C_WINDOWS_874, "_Windows-874"), /* RADIO set_charset_cb */
359 };
360
361 static GtkRadioActionEntry msgview_radio_dec_entries[] =
362 {
363         DEC_ACTION("AutoDetect", 0, N_("_Auto detect")),        /* set_decode_cb */
364         /* --- */
365         DEC_ACTION("8bit", ENC_8BIT, "_8bit"),
366         DEC_ACTION("QP", ENC_QUOTED_PRINTABLE, "_Quoted printable"),
367         DEC_ACTION("B64", ENC_BASE64, "_Base64"),
368         DEC_ACTION("Uuencode", ENC_X_UUENCODE, "_Uuencode"),
369 };
370
371 MessageView *messageview_create(MainWindow *mainwin)
372 {
373         MessageView *messageview;
374         GtkWidget *vbox;
375         HeaderView *headerview;
376         MimeView *mimeview;
377         NoticeView *noticeview;
378
379         debug_print("Creating message view...\n");
380         messageview = g_new0(MessageView, 1);
381
382         headerview = headerview_create();
383
384         noticeview = noticeview_create(mainwin);
385
386         mimeview = mimeview_create(mainwin);
387         mimeview->textview = textview_create();
388         mimeview->textview->messageview = messageview;
389         mimeview->messageview = messageview;
390
391         vbox = gtk_vbox_new(FALSE, 0);
392         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
393                            FALSE, FALSE, 0);
394         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
395                            FALSE, FALSE, 0);
396         gtk_box_pack_start(GTK_BOX(vbox),
397                            GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
398         gtk_widget_show(vbox);
399
400         messageview->vbox        = vbox;
401         messageview->new_window  = FALSE;
402         messageview->window      = NULL;
403         messageview->headerview  = headerview;
404         messageview->mimeview    = mimeview;
405         messageview->noticeview = noticeview;
406         messageview->mainwin    = mainwin;
407
408         messageview->statusbar     = NULL;
409         messageview->statusbar_cid = 0;
410
411         messageview->show_full_text= FALSE;
412         messageview->update_needed = FALSE;
413
414         messageview->msginfo_update_callback_id =
415                 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
416
417         return messageview;
418 }
419
420 GList *messageview_get_msgview_list(void)
421 {
422         return msgview_list;
423 }
424
425 void messageview_update_actions_menu(MessageView *msgview)
426 {
427         /* Messages opened in a new window do not have a menu bar */
428         if (msgview->menubar == NULL)
429                 return;
430         action_update_msgview_menu(msgview->ui_manager, "/Menu/Tools/Actions", msgview);
431 }
432
433 static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window) 
434 {
435         GtkWidget *handlebox;
436         GtkWidget *vbox;
437         GtkWidget *menubar;
438 #ifndef GENERIC_UMPC
439         GtkWidget *statusbar = NULL;
440 #endif
441         GtkActionGroup *action_group;
442
443
444         vbox = gtk_vbox_new(FALSE, 0);
445         gtk_widget_show(vbox);
446         gtk_container_add(GTK_CONTAINER(window), vbox); 
447
448         msgview->ui_manager = gtk_ui_manager_new();
449         action_group = cm_menu_create_action_group_full(msgview->ui_manager,"Menu", msgview_entries,
450                         G_N_ELEMENTS(msgview_entries), (gpointer)msgview);
451         gtk_action_group_add_toggle_actions(action_group, msgview_toggle_entries,
452                         G_N_ELEMENTS(msgview_toggle_entries), (gpointer)msgview);
453         gtk_action_group_add_radio_actions(action_group, msgview_radio_enc_entries,
454                         G_N_ELEMENTS(msgview_radio_enc_entries), C_AUTO, G_CALLBACK(set_charset_cb), (gpointer)msgview);
455         gtk_action_group_add_radio_actions(action_group, msgview_radio_dec_entries,
456                         G_N_ELEMENTS(msgview_radio_dec_entries), C_AUTO, G_CALLBACK(set_decode_cb), (gpointer)msgview);
457
458 #ifndef MAEMO
459         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
460 #else
461         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_POPUP)
462 #endif
463
464         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "File", "File", GTK_UI_MANAGER_MENU)
465         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
466         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "View", "View", GTK_UI_MANAGER_MENU)
467         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Message", "Message", GTK_UI_MANAGER_MENU)
468         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Tools", "Tools", GTK_UI_MANAGER_MENU)
469         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Help", "Help", GTK_UI_MANAGER_MENU)
470
471 /* File menu */
472         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
473         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "PageSetup", "File/PageSetup", GTK_UI_MANAGER_MENUITEM)
474         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
475         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Separator1", "File/---", GTK_UI_MANAGER_SEPARATOR)
476         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Close", "File/Close", GTK_UI_MANAGER_MENUITEM)
477
478 /* Edit menu */
479         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "Copy", "Edit/Copy", GTK_UI_MANAGER_MENUITEM)
480         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "SelectAll", "Edit/SelectAll", GTK_UI_MANAGER_MENUITEM)
481         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "Separator1", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
482         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "Find", "Edit/Find", GTK_UI_MANAGER_MENUITEM)
483
484 /* View menu */
485         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Goto", "View/Goto", GTK_UI_MANAGER_MENU)
486         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Prev", "View/Goto/Prev", GTK_UI_MANAGER_MENUITEM)
487         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Next", "View/Goto/Next", GTK_UI_MANAGER_MENUITEM)
488         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator1", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
489         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevUnread", "View/Goto/PrevUnread", GTK_UI_MANAGER_MENUITEM)
490         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextUnread", "View/Goto/NextUnread", GTK_UI_MANAGER_MENUITEM)
491         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator2", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
492         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevNew", "View/Goto/PrevNew", GTK_UI_MANAGER_MENUITEM)
493         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextNew", "View/Goto/NextNew", GTK_UI_MANAGER_MENUITEM)
494         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator3", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
495         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevMarked", "View/Goto/PrevMarked", GTK_UI_MANAGER_MENUITEM)
496         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextMarked", "View/Goto/NextMarked", GTK_UI_MANAGER_MENUITEM)
497         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator4", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
498         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevLabeled", "View/Goto/PrevLabeled", GTK_UI_MANAGER_MENUITEM)
499         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextLabeled", "View/Goto/NextLabeled", GTK_UI_MANAGER_MENUITEM)
500         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator5", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
501         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevHistory", "View/Goto/PrevHistory", GTK_UI_MANAGER_MENUITEM)
502         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextHistory", "View/Goto/NextHistory", GTK_UI_MANAGER_MENUITEM)
503         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator6", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
504         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "ParentMessage", "View/Goto/ParentMessage", GTK_UI_MANAGER_MENUITEM)
505         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator7", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
506         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextUnreadFolder", "View/Goto/NextUnreadFolder", GTK_UI_MANAGER_MENUITEM)
507         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "OtherFolder", "View/Goto/OtherFolder", GTK_UI_MANAGER_MENUITEM)
508
509         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Scroll", "View/Scroll", GTK_UI_MANAGER_MENU)
510         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "PrevLine", "View/Scroll/PrevLine", GTK_UI_MANAGER_MENUITEM)
511         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "NextLine", "View/Scroll/NextLine", GTK_UI_MANAGER_MENUITEM)
512         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "PrevPage", "View/Scroll/PrevPage", GTK_UI_MANAGER_MENUITEM)
513         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "NextPage", "View/Scroll/NextPage", GTK_UI_MANAGER_MENUITEM)
514
515         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Separator1", "View/---", GTK_UI_MANAGER_SEPARATOR)
516
517         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Encoding", "View/Encoding", GTK_UI_MANAGER_MENU)
518         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_AUTO, "View/Encoding/"CS_AUTO, GTK_UI_MANAGER_MENUITEM)
519         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Separator1", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
520         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_US_ASCII, "View/Encoding/"CS_US_ASCII, GTK_UI_MANAGER_MENUITEM)
521         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_UTF_8, "View/Encoding/"CS_UTF_8, GTK_UI_MANAGER_MENUITEM)
522         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Separator2", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
523
524         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Western", "View/Encoding/Western", GTK_UI_MANAGER_MENU)
525         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Western", CS_ISO_8859_1, "View/Encoding/Western/"CS_ISO_8859_1, GTK_UI_MANAGER_MENUITEM)
526         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Western", CS_ISO_8859_15, "View/Encoding/Western/"CS_ISO_8859_15, GTK_UI_MANAGER_MENUITEM)
527         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Western", CS_WINDOWS_1252, "View/Encoding/Western/"CS_WINDOWS_1252, GTK_UI_MANAGER_MENUITEM)
528
529         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_2, "View/Encoding/"CS_ISO_8859_2, GTK_UI_MANAGER_MENUITEM)
530
531         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Baltic", "View/Encoding/Baltic", GTK_UI_MANAGER_MENU)
532         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Baltic", CS_ISO_8859_13, "View/Encoding/Baltic/"CS_ISO_8859_13, GTK_UI_MANAGER_MENUITEM)
533         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Baltic", CS_ISO_8859_4, "View/Encoding/Baltic/"CS_ISO_8859_4, GTK_UI_MANAGER_MENUITEM)
534
535         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_7, "View/Encoding/"CS_ISO_8859_7, GTK_UI_MANAGER_MENUITEM)
536
537         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Hebrew", "View/Encoding/Hebrew", GTK_UI_MANAGER_MENU)
538         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Hebrew", CS_ISO_8859_8, "View/Encoding/Hebrew/"CS_ISO_8859_8, GTK_UI_MANAGER_MENUITEM)
539         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Hebrew", CS_WINDOWS_1255, "View/Encoding/Hebrew/"CS_WINDOWS_1255, GTK_UI_MANAGER_MENUITEM)
540
541         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Arabic", "View/Encoding/Arabic", GTK_UI_MANAGER_MENU)
542         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Arabic", CS_ISO_8859_6, "View/Encoding/Arabic/"CS_ISO_8859_6, GTK_UI_MANAGER_MENUITEM)
543         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Arabic", CS_WINDOWS_1256, "View/Encoding/Arabic/"CS_WINDOWS_1256, GTK_UI_MANAGER_MENUITEM)
544
545         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_9, "View/Encoding/"CS_ISO_8859_9, GTK_UI_MANAGER_MENUITEM)
546
547         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Cyrillic", "View/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
548         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_ISO_8859_5, "View/Encoding/Cyrillic/"CS_ISO_8859_5, GTK_UI_MANAGER_MENUITEM)
549         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_R, "View/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
550         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_U, "View/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
551         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_WINDOWS_1251, "View/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
552
553         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Japanese", "View/Encoding/Japanese", GTK_UI_MANAGER_MENU)
554         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_ISO_2022_JP, "View/Encoding/Japanese/"CS_ISO_2022_JP, GTK_UI_MANAGER_MENUITEM)
555         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_ISO_2022_JP_2, "View/Encoding/Japanese/"CS_ISO_2022_JP_2, GTK_UI_MANAGER_MENUITEM)
556         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_EUC_JP, "View/Encoding/Japanese/"CS_EUC_JP, GTK_UI_MANAGER_MENUITEM)
557         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_SHIFT_JIS, "View/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
558
559         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Chinese", "View/Encoding/Chinese", GTK_UI_MANAGER_MENU)
560         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB18030, "View/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
561         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB2312, "View/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
562         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GBK, "View/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
563         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_BIG5, "View/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
564         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_EUC_TW, "View/Encoding/Chinese/"CS_EUC_TW, GTK_UI_MANAGER_MENUITEM)
565
566         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Korean", "View/Encoding/Korean", GTK_UI_MANAGER_MENU)
567         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Korean", CS_EUC_KR, "View/Encoding/Korean/"CS_EUC_KR, GTK_UI_MANAGER_MENUITEM)
568         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Korean", CS_ISO_2022_KR, "View/Encoding/Korean/"CS_ISO_2022_KR, GTK_UI_MANAGER_MENUITEM)
569
570         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Thai", "View/Encoding/Thai", GTK_UI_MANAGER_MENU)
571         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Thai", CS_TIS_620, "View/Encoding/Thai/"CS_TIS_620, GTK_UI_MANAGER_MENUITEM)
572         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Thai", CS_WINDOWS_874, "View/Encoding/Thai/"CS_WINDOWS_874, GTK_UI_MANAGER_MENUITEM)
573
574         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Decode", "View/Decode", GTK_UI_MANAGER_MENU)
575         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "AutoDetect", "View/Decode/AutoDetect", GTK_UI_MANAGER_MENUITEM)
576         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "Separator1", "View/Decode/---", GTK_UI_MANAGER_SEPARATOR)
577         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "8bit", "View/Decode/8bit", GTK_UI_MANAGER_MENUITEM)
578         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "QP", "View/Decode/QP", GTK_UI_MANAGER_MENUITEM)
579         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "B64", "View/Decode/B64", GTK_UI_MANAGER_MENUITEM)
580         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "Uuencode", "View/Decode/Uuencode", GTK_UI_MANAGER_MENUITEM)
581
582         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Separator2", "View/---", GTK_UI_MANAGER_SEPARATOR)
583
584         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
585         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
586         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Quotes", "View/Quotes", GTK_UI_MANAGER_MENU)
587         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Quotes", "CollapseAll", "View/Quotes/CollapseAll", GTK_UI_MANAGER_MENUITEM)
588         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Quotes", "Collapse2", "View/Quotes/Collapse2", GTK_UI_MANAGER_MENUITEM)
589         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Quotes", "Collapse3", "View/Quotes/Collapse3", GTK_UI_MANAGER_MENUITEM)
590
591 /* Message menu */
592         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Compose", "Message/Compose", GTK_UI_MANAGER_MENUITEM)
593         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
594         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Reply", "Message/Reply", GTK_UI_MANAGER_MENUITEM)
595         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "ReplyTo", "Message/ReplyTo", GTK_UI_MANAGER_MENU)
596         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message/ReplyTo", "All", "Message/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
597         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message/ReplyTo", "Sender", "Message/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
598         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message/ReplyTo", "List", "Message/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
599         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
600         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Forward", "Message/Forward", GTK_UI_MANAGER_MENUITEM)
601         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "ForwardAtt", "Message/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
602         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Redirect", "Message/Redirect", GTK_UI_MANAGER_MENUITEM)
603
604 /* Tools menu */
605         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "AddressBook", "Tools/AddressBook", GTK_UI_MANAGER_MENUITEM)
606         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
607         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Separator1", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
608
609         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "CreateFilterRule", "Tools/CreateFilterRule", GTK_UI_MANAGER_MENU)
610         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
611         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
612         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
613         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
614
615         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "CreateProcessingRule", "Tools/CreateProcessingRule", GTK_UI_MANAGER_MENU)
616         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
617         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
618         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
619         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
620         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Separator2", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
621         
622         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "ListUrls", "Tools/ListUrls", GTK_UI_MANAGER_MENUITEM)
623         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Separator3", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
624
625         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Actions", "Tools/Actions", GTK_UI_MANAGER_MENU)
626         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/Actions", "PlaceHolder", "Tools/Actions/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
627
628 /* Help menu */
629         MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Help", "About", "Help/About", GTK_UI_MANAGER_MENUITEM)
630
631         menubar = gtk_ui_manager_get_widget(msgview->ui_manager, "/Menu");
632         gtk_widget_show_all(menubar);
633         gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(msgview->ui_manager));
634
635 #ifndef MAEMO
636         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
637 #else
638         hildon_window_set_menu(HILDON_WINDOW(window), GTK_MENU(menubar));
639 #endif
640
641         cm_toggle_menu_set_active_full(msgview->ui_manager, "Menu/View/AllHeaders",
642                                         prefs_common.show_all_headers);
643
644         if (prefs_common.toolbar_detachable) {
645                 handlebox = gtk_handle_box_new();
646         } else {
647                 handlebox = gtk_hbox_new(FALSE, 0);
648         }
649         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
650         gtk_widget_realize(handlebox);
651 #ifdef MAEMO
652         msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, window,
653                                           (gpointer)msgview);
654         msgview->statusbar = NULL;
655         msgview->statusbar_cid = 0;
656 #else
657         msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
658                                           (gpointer)msgview);
659 #ifndef GENERIC_UMPC
660         statusbar = gtk_statusbar_new();
661         gtk_widget_show(statusbar);
662         gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
663         msgview->statusbar = statusbar;
664         msgview->statusbar_cid = gtk_statusbar_get_context_id
665                 (GTK_STATUSBAR(statusbar), "Message View");
666 #else
667         msgview->statusbar = NULL;
668         msgview->statusbar_cid = 0;
669 #endif
670 #endif
671
672
673         msgview->handlebox = handlebox;
674         msgview->menubar   = menubar;
675
676         gtk_container_add(GTK_CONTAINER(vbox),
677                           GTK_WIDGET_PTR(msgview));
678
679         messageview_update_actions_menu(msgview);
680
681         msgview_list = g_list_append(msgview_list, msgview);
682 }
683
684 static MessageView *messageview_create_with_new_window_visible(MainWindow *mainwin, gboolean show)
685 {
686         MessageView *msgview;
687         GtkWidget *window;
688         static GdkGeometry geometry;
689
690         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "messageview");
691         gtk_window_set_title(GTK_WINDOW(window), _("Claws Mail - Message View"));
692         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
693
694         if (!geometry.min_height) {
695                 geometry.min_width = 320;
696                 geometry.min_height = 200;
697         }
698         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
699                                       GDK_HINT_MIN_SIZE);
700
701         gtk_widget_set_size_request(window, prefs_common.msgwin_width,
702                                     prefs_common.msgwin_height);
703 #ifdef G_OS_WIN32
704         gtk_window_move(GTK_WINDOW(window), 48, 48);
705 #endif
706
707         msgview = messageview_create(mainwin);
708
709         g_signal_connect(G_OBJECT(window), "size_allocate",
710                          G_CALLBACK(messageview_size_allocate_cb),
711                          msgview);
712         g_signal_connect(G_OBJECT(window), "delete_event",
713                          G_CALLBACK(messageview_delete_cb), msgview);
714 #ifdef MAEMO
715         maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
716 #else
717         g_signal_connect(G_OBJECT(window), "key_press_event",
718                          G_CALLBACK(key_pressed), msgview);
719 #endif
720         messageview_add_toolbar(msgview, window);
721
722         if (show) {
723                 gtk_widget_grab_focus(msgview->mimeview->textview->text);
724                 gtk_widget_show(window);
725         } else {
726                 gtk_widget_realize(window);
727         }
728
729         msgview->new_window = TRUE;
730         msgview->window = window;
731         msgview->visible = TRUE;
732
733         toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox, 
734                           prefs_common.toolbar_style);
735         messageview_init(msgview);
736
737         return msgview;
738 }
739
740 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
741 {
742         return messageview_create_with_new_window_visible(mainwin, TRUE);
743 }
744 void messageview_init(MessageView *messageview)
745 {
746         headerview_init(messageview->headerview);
747         mimeview_init(messageview->mimeview);
748         /*messageview_set_font(messageview);*/
749
750         noticeview_hide(messageview->noticeview);
751 }
752
753 static void notification_convert_header(gchar *dest, gint len, 
754                                         const gchar *src_,
755                                         gint header_len)
756 {
757         char *src;
758
759         cm_return_if_fail(src_ != NULL);
760         cm_return_if_fail(dest != NULL);
761
762         if (len < 1) return;
763
764         Xstrndup_a(src, src_, len, return);
765
766         remove_return(src);
767
768         if (is_ascii_str(src)) {
769                 strncpy2(dest, src, len);
770                 dest[len - 1] = '\0';
771                 return;
772         } else
773                 conv_encode_header(dest, len, src, header_len, FALSE);
774 }
775
776 static gint disposition_notification_send(MsgInfo *msginfo)
777 {
778         gchar buf[BUFFSIZE];
779         gchar tmp[MAXPATHLEN + 1];
780         FILE *fp;
781         GList *ac_list;
782         PrefsAccount *account = NULL;
783         gint ok;
784         gchar *to;
785         FolderItem *queue, *outbox;
786         gint num;
787         gchar *path;
788         gchar *addr;
789         gchar *addrp;
790         gchar *foo = NULL;
791         gboolean queued_removed = FALSE;
792         gchar *boundary = NULL;
793         gchar *date = NULL;
794         gchar *orig_to = NULL;
795         gchar *enc_sub = NULL;
796
797         if (!msginfo->extradata)
798                 return -1;
799         if (!msginfo->extradata->returnreceiptto && 
800             !msginfo->extradata->dispositionnotificationto) 
801                 return -1;
802
803         /* RFC2298: Test for Return-Path */
804         if (msginfo->extradata->dispositionnotificationto)
805                 to = msginfo->extradata->dispositionnotificationto;
806         else
807                 to = msginfo->extradata->returnreceiptto;
808
809         ok = procheader_get_header_from_msginfo(msginfo, buf, sizeof(buf),
810                                 "Return-Path:");
811         if (ok == 0) {
812                 gchar *to_addr = g_strdup(to);
813                 extract_address(to_addr);
814                 extract_address(buf);
815                 ok = strcasecmp(to_addr, buf);
816                 g_free(to_addr);
817         } else {
818                 strncpy(buf, _("<No Return-Path found>"), 
819                                 sizeof(buf));
820         }
821         
822         if (ok != 0) {
823                 AlertValue val;
824                 gchar *message;
825                 message = g_markup_printf_escaped(
826                   _("The notification address to which the return receipt is\n"
827                     "to be sent does not correspond to the return path:\n"
828                     "Notification address: %s\n"
829                     "Return path: %s\n"
830                     "It is advised to not to send the return receipt."),
831                   to, buf);
832                 val = alertpanel_full(_("Warning"), message,
833                                 _("_Don't Send"), _("_Send"), NULL, FALSE,
834                                 NULL, ALERT_WARNING, G_ALERTDEFAULT);
835                 g_free(message);                                
836                 if (val != G_ALERTALTERNATE)
837                         return -1;
838         }
839
840         ac_list = account_find_all_from_address(NULL, msginfo->to);
841         ac_list = account_find_all_from_address(ac_list, msginfo->cc);
842
843         if (ac_list == NULL) {
844                 AlertValue val = 
845                 alertpanel_full(_("Warning"),
846                   _("This message is asking for a return receipt notification\n"
847                     "but according to its 'To:' and 'CC:' headers it was not\n"
848                     "officially addressed to you.\n"
849                     "It is advised to not to send the return receipt."),
850                   _("_Don't Send"), _("_Send"), NULL, FALSE,
851                   NULL, ALERT_WARNING, G_ALERTDEFAULT);
852                 if (val != G_ALERTALTERNATE)
853                         return -1;
854         }
855
856         if (g_list_length(ac_list) > 1) {
857                 if ((account = select_account_from_list(ac_list)) == NULL)
858                         return -1;
859         }
860         else if (ac_list != NULL)
861                 account = (PrefsAccount *) ac_list->data;
862         g_list_free(ac_list);
863
864         if (account == NULL)
865                 account = account_get_default();
866         if (!account || account->protocol == A_NNTP) {
867                 alertpanel_error(_("Account for sending mail is not specified.\n"
868                                    "Please select a mail account before sending."));
869                 return -1;
870         }
871
872         /* write to temporary file */
873         g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%p",
874                    get_rc_dir(), G_DIR_SEPARATOR, msginfo);
875
876         if ((fp = g_fopen(tmp, "wb")) == NULL) {
877                 FILE_OP_ERROR(tmp, "fopen");
878                 return -1;
879         }
880
881         /* chmod for security */
882         if (change_file_mode_rw(fp, tmp) < 0) {
883                 FILE_OP_ERROR(tmp, "chmod");
884                 g_warning("can't change file mode\n");
885         }
886         
887         addr = g_strdup(to);
888         
889         extract_address(addr);
890         addrp = addr;
891         
892         /* write queue headers */
893         ok = fprintf(fp, "AF:\n"
894                     "NF:0\n"
895                     "PS:10\n"
896                     "SRH:1\n"
897                     "SFN:\n"
898                     "DSR:\n"
899                     "MID:\n"
900                     "CFG:\n"
901                     "PT:0\n"
902                     "S:%s\n"
903                     "RQ:\n"
904                     "SSV:%s\n"
905                     "SSH:\n"
906                     "R:<%s>\n", 
907                     account->address,
908                     account->smtp_server?account->smtp_server:"",
909                     addrp);
910
911         g_free(addrp);
912         if (ok < 0)
913                 goto FILE_ERROR;
914         
915         /* check whether we need to save the message */
916         outbox = account_get_special_folder(account, F_OUTBOX); 
917         if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
918                 outbox = NULL;
919         if (outbox) {
920                 path = folder_item_get_identifier(outbox);
921                 ok = fprintf(fp, "SCF:%s\n", path);
922                 g_free(path);
923                 
924                 if (ok < 0)
925                         goto FILE_ERROR;
926         }               
927
928         if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0)
929                 goto FILE_ERROR;
930
931         /* Date */
932         get_rfc822_date(buf, sizeof(buf));
933         if (fprintf(fp, "Date: %s\n", buf) < 0)
934                 goto FILE_ERROR;
935
936         /* From */
937         if (account->name && *account->name) {
938                 notification_convert_header
939                         (buf, sizeof(buf), account->name,
940                          strlen("From: "));
941                 if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0)
942                         goto FILE_ERROR;
943         } else
944                 if (fprintf(fp, "From: %s\n", account->address) < 0)
945                         goto FILE_ERROR;
946
947         if (fprintf(fp, "To: %s\n", to) < 0)
948                 goto FILE_ERROR;
949
950         /* Subject */
951         notification_convert_header(buf, sizeof(buf), msginfo->subject,
952                                     strlen("Subject: "));
953         if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0)
954                 goto FILE_ERROR;
955
956         /* Message ID */
957         if (account->set_domain && account->domain) {
958                 g_snprintf(buf, sizeof(buf), "%s", account->domain); 
959         } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
960                 g_snprintf(buf, sizeof(buf), "%s", 
961                         strchr(account->address, '@') ?
962                                 strchr(account->address, '@')+1 :
963                                 account->address);
964         } else {
965                 g_snprintf(buf, sizeof(buf), "%s", "");
966         }
967         
968         if (account->gen_msgid) {
969                 gchar *addr = NULL;
970                 if (account->msgid_with_addr) {
971                         addr = account->address;
972                 }
973                 generate_msgid(buf, sizeof(buf), addr);
974
975                 if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0)
976                         goto FILE_ERROR;
977         }
978
979         boundary = generate_mime_boundary("DN");
980         get_rfc822_date(buf, sizeof(buf));
981         date = g_strdup(buf);
982         if (msginfo->to) {
983                 orig_to = g_strdup(msginfo->to);
984                 extract_address(orig_to);
985         }
986         if (msginfo->subject && *(msginfo->subject)) {
987                 enc_sub = g_malloc0(strlen(msginfo->subject)*8);
988                 qp_encode_line(enc_sub, (const guchar *)msginfo->subject);
989                 g_strstrip(enc_sub);
990         }
991         ok = fprintf(fp,"MIME-Version: 1.0\n"
992                         "Content-Type: multipart/report; report-type=disposition-notification;\n"
993                         "  boundary=\"%s\"\n"
994                         "\n"
995                         "--%s\n"
996                         "Content-Type: text/plain; charset=UTF-8\n"
997                         "Content-Transfer-Encoding: quoted-printable\n"
998                         "\n"
999                         "The message sent on: %s\n"
1000                         "To: %s\n"
1001                         "With subject: \"%s\"\n"
1002                         "has been displayed at %s.\n"
1003                         "\n"
1004                         "There is no guarantee that the message has been read or understood.\n"
1005                         "\n"
1006                         "--%s\n"
1007                         "Content-Type: message/disposition-notification\n"
1008                         "\n"
1009                         "Reporting-UA: %s\n"
1010                         "Original-Recipient: rfc822;%s\n"
1011                         "Final-Recipient: rfc822;%s\n"
1012                         "Original-Message-ID: <%s>\n"
1013                         "Disposition: manual-action/MDN-sent-manually; displayed\n"
1014                         "\n"
1015                         "--%s\n"
1016                         "Content-Type: application/octet-stream\n"
1017                         "Reporting-UA: %s\n"
1018                         "Original-Recipient: rfc822;%s\n"
1019                         "Final-Recipient: rfc822;%s\n"
1020                         "Original-Message-ID: <%s>\n"
1021                         "Disposition: manual-action/MDN-sent-manually; displayed\n"
1022                         "\n"
1023                         "--%s--\n", 
1024                         boundary, 
1025                         boundary,
1026                         msginfo->date, 
1027                         orig_to?orig_to:"No To:",
1028                         enc_sub?enc_sub:"No subject",
1029                         date,
1030                         boundary,
1031                         PROG_VERSION,
1032                         orig_to?orig_to:"No To:",
1033                         account->address,
1034                         msginfo->msgid?msginfo->msgid:"NO MESSAGE ID",
1035                         boundary,
1036                         PROG_VERSION,
1037                         orig_to?orig_to:"No To:",
1038                         account->address,
1039                         msginfo->msgid?msginfo->msgid:"NO MESSAGE ID",
1040                         boundary);
1041
1042         g_free(enc_sub);
1043         g_free(orig_to);
1044         g_free(date);
1045         g_free(boundary);
1046
1047         if (ok < 0)
1048                 goto FILE_ERROR;        
1049
1050         if (fclose(fp) == EOF) {
1051                 FILE_OP_ERROR(tmp, "fclose");
1052                 claws_unlink(tmp);
1053                 return -1;
1054         }
1055
1056         /* put it in queue */
1057         queue = account_get_special_folder(account, F_QUEUE);
1058         if (!queue) queue = folder_get_default_queue();
1059         if (!queue) {
1060                 g_warning("can't find queue folder\n");
1061                 claws_unlink(tmp);
1062                 return -1;
1063         }
1064         folder_item_scan(queue);
1065         if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
1066                 g_warning("can't queue the message\n");
1067                 claws_unlink(tmp);
1068                 return -1;
1069         }
1070                 
1071         if (prefs_common.work_offline && 
1072             !inc_offline_should_override(TRUE,
1073                 _("Claws Mail needs network access in order "
1074                   "to send this email.")))
1075                 return 0;
1076
1077         /* send it */
1078         path = folder_item_fetch_msg(queue, num);
1079         ok = procmsg_send_message_queue_with_lock(path, &foo, queue, num, &queued_removed);
1080         g_free(path);
1081         g_free(foo);
1082         if (ok == 0 && !queued_removed)
1083                 folder_item_remove_msg(queue, num);
1084
1085         return ok;
1086
1087 FILE_ERROR:
1088         fclose(fp);
1089         claws_unlink(tmp);
1090         return -1;
1091 }
1092
1093 static gboolean find_encrypted_func(GNode *node, gpointer data)
1094 {
1095         MimeInfo *mimeinfo = (MimeInfo *) node->data;
1096         MimeInfo **encinfo = (MimeInfo **) data;
1097         
1098         if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
1099                 *encinfo = mimeinfo;
1100                 return TRUE;
1101         }
1102         
1103         return FALSE;
1104 }
1105
1106 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
1107 {
1108         MimeInfo *encinfo = NULL;
1109
1110         g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
1111                 find_encrypted_func, &encinfo);
1112         
1113         return encinfo;
1114 }
1115
1116 static gboolean find_broken_func(GNode *node, gpointer data)
1117 {
1118         MimeInfo *mimeinfo = (MimeInfo *) node->data;
1119         MimeInfo **brokeninfo = (MimeInfo **) data;
1120         
1121         if (mimeinfo->broken) {
1122                 *brokeninfo = mimeinfo;
1123                 return TRUE;
1124         }
1125         
1126         return FALSE;
1127 }
1128
1129 static MimeInfo *find_broken_part(MimeInfo *rootinfo)
1130 {
1131         MimeInfo *brokeninfo = NULL;
1132
1133         g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
1134                 find_broken_func, &brokeninfo);
1135         
1136         return brokeninfo;
1137 }
1138
1139 static void messageview_register_nav(MessageView *messageview)
1140 {
1141         gchar *id;
1142         gint pos = -1;
1143         GList *existing;
1144
1145         cm_return_if_fail(messageview);
1146         cm_return_if_fail(messageview->msginfo);
1147
1148         id = procmsg_msginfo_get_identifier(messageview->msginfo);
1149         existing = g_list_find_custom(messageview->trail, id, (GCompareFunc)g_strcmp0);
1150
1151         if (existing != NULL)
1152                 pos = g_list_position(messageview->trail, existing);
1153         else
1154                 pos = -1;
1155
1156         if (pos != -1) {
1157                 messageview->trail_pos = pos;
1158                 g_free(id);
1159         } else {
1160                 /* Cut the end of the list */
1161                 GList *end = g_list_nth(messageview->trail, messageview->trail_pos + 1);
1162                 if (end) {
1163                         if (end->prev) {
1164                                 end->prev->next = NULL;
1165                                 end->prev = NULL;
1166                                 list_free_strings(end);
1167                                 g_list_free(end);
1168                         } else {
1169                                 list_free_strings(messageview->trail);
1170                                 g_list_free(messageview->trail);
1171                                 messageview->trail = NULL;
1172                         }
1173                 }
1174                 messageview->trail = g_list_append(messageview->trail, id);
1175                 messageview->trail_pos = g_list_length(messageview->trail) - 1;
1176                 
1177                 /* Cut the beginning if needed */
1178                 while (messageview->trail_pos > prefs_common.nav_history_length) {
1179                         g_free(messageview->trail->data);
1180                         messageview->trail = g_list_delete_link(messageview->trail,
1181                                                 messageview->trail);
1182                         messageview->trail_pos--;
1183                 }
1184         }
1185         messageview_set_menu_sensitive(messageview);
1186 }
1187
1188 gboolean messageview_nav_has_prev(MessageView *messageview) {
1189         return messageview->trail != NULL &&  messageview->trail_pos > 0;
1190 }
1191
1192 gboolean messageview_nav_has_next(MessageView *messageview) {
1193         if (!messageview->trail)
1194                 return FALSE;
1195         
1196         return sc_g_list_bigger(messageview->trail, messageview->trail_pos + 1);
1197 }
1198
1199 MsgInfo *messageview_nav_get_prev(MessageView *messageview) {
1200         GList *item;
1201         MsgInfo *info;
1202
1203         cm_return_val_if_fail(messageview, NULL);
1204         cm_return_val_if_fail(messageview->trail, NULL);
1205
1206         do {
1207                 if (!messageview_nav_has_prev(messageview))
1208                         return NULL;
1209
1210                 item = g_list_nth(messageview->trail, messageview->trail_pos - 1);
1211                 cm_return_val_if_fail(item != NULL, NULL);
1212
1213                 info = procmsg_get_msginfo_from_identifier((const gchar *)item->data);
1214                 if (info != NULL)
1215                         break;
1216
1217                 g_free(item->data);
1218                 messageview->trail = g_list_delete_link(messageview->trail, item);
1219                 if (messageview->trail_pos > 0)
1220                         messageview->trail_pos--;
1221         } while (info == NULL);
1222
1223         return info;
1224 }
1225
1226 MsgInfo *messageview_nav_get_next(MessageView *messageview) {
1227         GList *item;
1228         MsgInfo *info;
1229
1230         cm_return_val_if_fail(messageview, NULL);
1231         cm_return_val_if_fail(messageview->trail, NULL);
1232
1233         do {
1234                 if (!messageview_nav_has_next(messageview))
1235                         return NULL;
1236
1237                 item = g_list_nth(messageview->trail, messageview->trail_pos + 1);
1238                 cm_return_val_if_fail(item != NULL, NULL);
1239
1240                 info = procmsg_get_msginfo_from_identifier((const gchar *)item->data);
1241                 if (info != NULL)
1242                         break;
1243
1244                 g_free(item->data);
1245                 messageview->trail = g_list_delete_link(messageview->trail, item);
1246         } while (info == NULL);
1247         
1248         return info;
1249 }
1250
1251 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
1252                       gboolean all_headers)
1253 {
1254         gchar *text = NULL;
1255         gchar *file;
1256         MimeInfo *mimeinfo, *encinfo, *brokeninfo, *root;
1257         gchar *subject = NULL;
1258         cm_return_val_if_fail(msginfo != NULL, -1);
1259
1260         if (msginfo != messageview->msginfo)
1261                 messageview->show_full_text = FALSE;
1262
1263         if (messageview->mimeview->textview &&
1264             messageview->mimeview->textview->loading) {
1265                 messageview->mimeview->textview->stop_loading = TRUE;
1266                 return 0;
1267         }
1268
1269         if (messageview->toolbar)
1270                 toolbar_set_learn_button
1271                         (messageview->toolbar,
1272                          MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1273         else
1274                 toolbar_set_learn_button
1275                         (messageview->mainwin->toolbar,
1276                          MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1277
1278         if (messageview->toolbar) {
1279                 if (messageview->toolbar->learn_spam_btn) {
1280                         gboolean can_learn = FALSE;
1281                         if (procmsg_spam_can_learn() &&
1282                             (msginfo->folder &&
1283                              msginfo->folder->folder->klass->type != F_UNKNOWN &&
1284                              msginfo->folder->folder->klass->type != F_NEWS))
1285                                 can_learn = TRUE;
1286
1287                         gtk_widget_set_sensitive(
1288                                 messageview->toolbar->learn_spam_btn, 
1289                                 can_learn);
1290                 }
1291         }
1292         
1293         noticeview_hide(messageview->noticeview);
1294         mimeview_clear(messageview->mimeview);
1295         messageview->updating = TRUE;
1296
1297         if (msginfo->size > 1024*1024)
1298                 statuswindow_print_all(_("Fetching message (%s)..."),
1299                         to_human_readable(msginfo->size));
1300         
1301         file = procmsg_get_message_file_path(msginfo);
1302
1303         if (msginfo->size > 1024*1024)
1304                 statuswindow_pop_all();
1305
1306         if (!file) {
1307                 g_warning("can't get message file path.\n");
1308                 textview_show_error(messageview->mimeview->textview);
1309                 return -1;
1310         }
1311         
1312         if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
1313             !folder_has_parent_of_type(msginfo->folder, F_DRAFT))
1314                 mimeinfo = procmime_scan_file(file);
1315         else
1316                 mimeinfo = procmime_scan_queue_file(file);
1317
1318         messageview->updating = FALSE;
1319         
1320         if (messageview->deferred_destroy) {
1321                 g_free(file);
1322                 messageview_destroy(messageview);
1323                 return 0;
1324         }
1325
1326         if (!mimeinfo) {
1327                 textview_show_error(messageview->mimeview->textview);
1328                 return -1;
1329         }
1330
1331         while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
1332                 debug_print("decrypting message part\n");
1333                 if (privacy_mimeinfo_decrypt(encinfo) < 0) {
1334                         text = g_strdup_printf(_("Couldn't decrypt: %s"),
1335                                                privacy_get_error());
1336                         noticeview_show(messageview->noticeview);
1337                         noticeview_set_icon(messageview->noticeview,
1338                                             STOCK_PIXMAP_NOTICE_WARN);
1339                         noticeview_set_text(messageview->noticeview, text);
1340                         gtk_widget_hide(messageview->noticeview->button);
1341                         gtk_widget_hide(messageview->noticeview->button2);
1342                         g_free(text);
1343                         break;
1344                 }
1345         }
1346                         
1347         if (messageview->msginfo != msginfo) {
1348                 procmsg_msginfo_free(messageview->msginfo);
1349                 messageview->msginfo = NULL;
1350                 messageview_set_menu_sensitive(messageview);
1351                 messageview->msginfo = 
1352                         procmsg_msginfo_get_full_info_from_file(msginfo, file);
1353                 if (!messageview->msginfo)
1354                         messageview->msginfo = procmsg_msginfo_copy(msginfo);
1355         } else {
1356                 messageview->msginfo = NULL;
1357                 messageview_set_menu_sensitive(messageview);
1358                 messageview->msginfo = msginfo;
1359         }
1360         headerview_show(messageview->headerview, messageview->msginfo);
1361
1362         messageview_register_nav(messageview);
1363         messageview_set_position(messageview, 0);
1364
1365 #ifdef MAEMO
1366         maemo_window_full_screen_if_needed(GTK_WINDOW(messageview->window));
1367 #endif
1368         if (messageview->window) {
1369                 gtk_window_set_title(GTK_WINDOW(messageview->window), 
1370                                 _("Claws Mail - Message View"));
1371                 GTK_EVENTS_FLUSH();
1372         }
1373         mimeview_show_message(messageview->mimeview, mimeinfo, file);
1374         
1375 #ifndef GENERIC_UMPC
1376         messageview_set_position(messageview, 0);
1377 #endif
1378
1379         if (messageview->window && msginfo->subject) {
1380                 subject = g_strdup(msginfo->subject);
1381                 if (!g_utf8_validate(subject, -1, NULL)) {
1382                         g_free(subject);
1383                         subject = g_malloc(strlen(msginfo->subject)*2 +1);
1384                         conv_localetodisp(subject, strlen(msginfo->subject)*2 +1, 
1385                                 msginfo->subject);
1386                 }
1387                 if (g_utf8_validate(subject, -1, NULL))
1388                         gtk_window_set_title(GTK_WINDOW(messageview->window), 
1389                                 subject);
1390                 g_free(subject);
1391         }
1392
1393         if (msginfo && msginfo->folder) {
1394                 msginfo->folder->last_seen = msginfo->msgnum;   
1395         }
1396
1397         main_create_mailing_list_menu(messageview->mainwin, messageview->msginfo);
1398
1399         if (messageview->msginfo && messageview->msginfo->extradata
1400             && messageview->msginfo->extradata->partial_recv
1401             && !noticeview_is_visible(messageview->noticeview))
1402                 partial_recv_show(messageview->noticeview, 
1403                                   messageview->msginfo);
1404         else if (messageview->msginfo && messageview->msginfo->extradata &&
1405             (messageview->msginfo->extradata->dispositionnotificationto || 
1406              messageview->msginfo->extradata->returnreceiptto) &&
1407             !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags) &&
1408             !prefs_common.never_send_retrcpt &&
1409             !noticeview_is_visible(messageview->noticeview))
1410                 return_receipt_show(messageview->noticeview, 
1411                                     messageview->msginfo);
1412
1413         if ((brokeninfo = find_broken_part(mimeinfo)) != NULL) {
1414                 noticeview_set_icon(messageview->noticeview,
1415                                     STOCK_PIXMAP_NOTICE_WARN);
1416                 if (!noticeview_is_visible(messageview->noticeview)) {
1417                         noticeview_set_text(messageview->noticeview, _("Message doesn't conform to MIME standard. "
1418                                                 "It may render wrongly."));
1419                         gtk_widget_hide(messageview->noticeview->button);
1420                         gtk_widget_hide(messageview->noticeview->button2);
1421                 } else {
1422                         gchar *full = g_strconcat(
1423                                         gtk_label_get_text(GTK_LABEL(messageview->noticeview->text)), 
1424                                         "\n", 
1425                                         _("Message doesn't conform to MIME standard. "
1426                                         "It may render wrongly."), NULL);
1427                         noticeview_set_text(messageview->noticeview, full);
1428                         g_free(full);
1429                 }
1430                 noticeview_show(messageview->noticeview);
1431         }
1432                         
1433         root = mimeinfo;
1434         mimeinfo = procmime_mimeinfo_next(mimeinfo);
1435         if (!all_headers && mimeinfo 
1436                         && (mimeinfo->type != MIMETYPE_TEXT || 
1437             strcasecmp(mimeinfo->subtype, "plain")) 
1438                         && (mimeinfo->type != MIMETYPE_MULTIPART || 
1439             strcasecmp(mimeinfo->subtype, "signed"))) {
1440                 if (strcasecmp(mimeinfo->subtype, "html")) {
1441                         MimeInfo *saved_mimeinfo = mimeinfo;
1442                         MimeInfo *alt_parent = mimeinfo;
1443
1444                         /* if multipart/{related,mixed} part, look inside for a multipart/alternative child */
1445                         if (mimeinfo->type == MIMETYPE_MULTIPART &&
1446                             (!strcasecmp(mimeinfo->subtype, "related") ||
1447                              !strcasecmp(mimeinfo->subtype, "mixed"))) {
1448                                 for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
1449                                         if (mimeinfo->node->parent != saved_mimeinfo->node) {
1450                                                 /* only consider children of the 
1451                                                  * multipart/{related,mixed} part */
1452                                                 continue;
1453                                         }
1454                                         if (mimeinfo->type == MIMETYPE_MULTIPART && 
1455                                             !strcasecmp(mimeinfo->subtype, "alternative")) {
1456                                                 /* we got an alternative part */
1457                                                 alt_parent = mimeinfo;
1458                                                 break;
1459                                         }
1460                                         if (mimeinfo->type == MIMETYPE_TEXT && 
1461                                             !strcasecmp(mimeinfo->subtype, "calendar") &&
1462                                             mimeview_has_viewer_for_content_type(messageview->mimeview,
1463                                                                                  "text/calendar")) {
1464                                                 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1465                                                 goto done;
1466                                         } else if (mimeinfo->type == MIMETYPE_TEXT && 
1467                                             !strcasecmp(mimeinfo->subtype, "html") &&
1468                                             prefs_common.promote_html_part) {
1469                                                 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1470                                                 goto done;
1471                                         }
1472                                 }
1473                         }
1474
1475                         /* if we now have a multipart/alternative part (possibly inside a
1476                          * multipart/{related,mixed} part, look for an HTML part inside */
1477                         if (mimeinfo && mimeinfo->type == MIMETYPE_MULTIPART &&
1478                             !strcasecmp(mimeinfo->subtype, "alternative")) {
1479                                 for (; mimeinfo; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
1480                                         if (mimeinfo->node->parent != alt_parent->node) {
1481                                                 /* only consider children of the 
1482                                                  * multipart/alternative part, so as
1483                                                  * not to show html attachments */
1484                                                 continue;
1485                                         }
1486                                         if (mimeinfo->type == MIMETYPE_TEXT && 
1487                                             !strcasecmp(mimeinfo->subtype, "calendar") &&
1488                                             mimeview_has_viewer_for_content_type(messageview->mimeview,
1489                                                                                  "text/calendar")) {
1490                                                 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1491                                                 goto done;
1492                                         } else if (mimeinfo->type == MIMETYPE_TEXT && 
1493                                             !strcasecmp(mimeinfo->subtype, "html") &&
1494                                             prefs_common.promote_html_part) {
1495                                                 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1496                                                 goto done;
1497                                         }
1498                                 }
1499                         }
1500                         
1501                         /* if we didn't find anything, go back to start */
1502                         if (!mimeinfo) 
1503                                 mimeinfo = saved_mimeinfo;
1504
1505                         if (!mimeview_show_part(messageview->mimeview, mimeinfo))
1506                                 mimeview_select_mimepart_icon(messageview->mimeview, root);
1507                         goto done;
1508                 } else if (prefs_common.invoke_plugin_on_html) {
1509                         mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1510                         goto done;
1511                 }
1512         }
1513         if (!all_headers && mimeinfo &&
1514             mimeinfo->type == MIMETYPE_MULTIPART &&
1515             mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
1516                 /* look for a calendar part or it looks really strange */
1517                 while (mimeinfo) {
1518                         if (mimeinfo->type == MIMETYPE_TEXT &&
1519                             !strcasecmp(mimeinfo->subtype, "calendar")) {
1520                                 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1521                                 goto done;
1522                         }
1523                         mimeinfo = procmime_mimeinfo_next(mimeinfo);
1524                 }
1525         }
1526
1527         mimeview_select_mimepart_icon(messageview->mimeview, root);
1528 done:
1529         /* plugins may hook in here to work with the message view */
1530         hooks_invoke(MESSAGE_VIEW_SHOW_DONE_HOOKLIST, messageview);
1531
1532         g_free(file);
1533
1534         return 0;
1535 }
1536
1537 void messageview_reflect_prefs_pixmap_theme(void)
1538 {
1539         GList *cur;
1540         MessageView *msgview;
1541
1542         for (cur = msgview_list; cur != NULL; cur = cur->next) {
1543                 msgview = (MessageView*)cur->data;
1544                 toolbar_update(TOOLBAR_MSGVIEW, msgview);
1545                 mimeview_update(msgview->mimeview);
1546         }
1547 }
1548
1549 void messageview_clear(MessageView *messageview)
1550 {
1551         if (!messageview)
1552                 return;
1553         procmsg_msginfo_free(messageview->msginfo);
1554         messageview->msginfo = NULL;
1555         messageview->filtered = FALSE;
1556
1557         if (messageview->window) {
1558                 gtk_window_set_title(GTK_WINDOW(messageview->window), 
1559                                 _("Claws Mail - Message View"));
1560                 GTK_EVENTS_FLUSH();
1561         }
1562
1563         mimeview_clear(messageview->mimeview);
1564         headerview_clear(messageview->headerview);
1565         noticeview_hide(messageview->noticeview);
1566 }
1567
1568 void messageview_destroy(MessageView *messageview)
1569 {
1570         debug_print("destroy messageview\n");
1571         messageview_list = g_list_remove(messageview_list, messageview);
1572
1573         if (messageview->mainwin->summaryview->messageview == messageview) {
1574                 messageview->mainwin->summaryview->displayed = NULL;
1575                 messageview->mainwin->summaryview->messageview = NULL;
1576         }
1577         if (messageview->mainwin->summaryview->ext_messageview == messageview) {
1578                 messageview->mainwin->summaryview->displayed = NULL;
1579                 messageview->mainwin->summaryview->ext_messageview = NULL;
1580         }
1581         if (!messageview->deferred_destroy)
1582                 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
1583                               messageview->msginfo_update_callback_id);
1584
1585         if (messageview->updating) {
1586                 debug_print("uh oh, better not touch that now (fetching)\n");
1587                 messageview->deferred_destroy = TRUE;
1588                 gtk_widget_hide(messageview->window);
1589                 return;
1590         }
1591         
1592         if (messageview->mimeview->textview
1593         &&  messageview->mimeview->textview->loading) {
1594                 debug_print("uh oh, better not touch that now (loading text)\n");
1595                 messageview->deferred_destroy = TRUE;
1596                 messageview->mimeview->textview->stop_loading = TRUE;
1597                 gtk_widget_hide(messageview->window);
1598                 return;
1599         }
1600
1601         headerview_destroy(messageview->headerview);
1602         mimeview_destroy(messageview->mimeview);
1603         noticeview_destroy(messageview->noticeview);
1604
1605         procmsg_msginfo_free(messageview->msginfo);
1606         toolbar_clear_list(TOOLBAR_MSGVIEW);
1607         if (messageview->toolbar) {
1608                 toolbar_destroy(messageview->toolbar);
1609                 g_free(messageview->toolbar);
1610         }
1611
1612         list_free_strings(messageview->trail);
1613         g_list_free(messageview->trail);
1614         msgview_list = g_list_remove(msgview_list, messageview); 
1615
1616         if (messageview->window)
1617                 gtk_widget_destroy(messageview->window);
1618         g_free(messageview);
1619 }
1620
1621 void messageview_delete(MessageView *msgview)
1622 {
1623         MsgInfo *msginfo = NULL;
1624         FolderItem *trash = NULL;
1625         PrefsAccount *ac = NULL;
1626
1627         if (msgview->msginfo && msgview->mainwin && msgview->mainwin->summaryview)
1628                 msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1629         
1630         /* need a procmsg_msginfo_equal() */
1631         if (msginfo && msgview->msginfo && 
1632             msginfo->msgnum == msgview->msginfo->msgnum && 
1633             msginfo->folder == msgview->msginfo->folder) {
1634                 summary_delete_trash(msgview->mainwin->summaryview);
1635         } else {                
1636                 msginfo = msgview->msginfo;
1637
1638                 cm_return_if_fail(msginfo != NULL);
1639
1640                 /* to get the trash folder, we have to choose either
1641                  * the folder's or account's trash default - we prefer
1642                  * the one in the account prefs */
1643                 if (msginfo->folder) {
1644                         if (NULL != (ac = account_find_from_item(msginfo->folder)))
1645                                 trash = account_get_special_folder(ac, F_TRASH);
1646                         if (!trash && msginfo->folder->folder)  
1647                                 trash = msginfo->folder->folder->trash;
1648                         /* if still not found, use the default */
1649                         if (!trash) 
1650                                 trash = folder_get_default_trash();
1651                 }       
1652
1653                 cm_return_if_fail(trash != NULL);
1654
1655                 if (prefs_common.immediate_exec)
1656                         /* TODO: Delete from trash */
1657                         folder_item_move_msg(trash, msginfo);
1658                 else {
1659                         procmsg_msginfo_set_to_folder(msginfo, trash);
1660                         procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
1661                         /* NOTE: does not update to next message in summaryview */
1662                 }
1663         }
1664 #ifdef GENERIC_UMPC
1665         if (msgview->window && !prefs_common.always_show_msg) {
1666                 messageview_destroy(msgview);
1667         }
1668 #endif
1669 }
1670
1671 /* 
1672  * \brief update messageview with currently selected message in summaryview
1673  *        leave unchanged if summaryview is empty
1674  * \param pointer to MessageView
1675  */     
1676 static void messageview_update(MessageView *msgview, MsgInfo *old_msginfo)
1677 {
1678         SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
1679
1680         cm_return_if_fail(summaryview != NULL);
1681         
1682         if (summaryview->selected) {
1683                 MsgInfo *msginfo = summary_get_selected_msg(summaryview);
1684                 if (msginfo == NULL || msginfo == old_msginfo)
1685                         return;
1686
1687                 messageview_show(msgview, msginfo, 
1688                                  msgview->all_headers);
1689         } 
1690 }
1691
1692 TextView *messageview_get_current_textview(MessageView *messageview)
1693 {
1694         TextView *text = NULL;
1695
1696         text = messageview->mimeview->textview;
1697
1698         return text;
1699 }
1700
1701 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
1702 {
1703         return mimeview_get_selected_part(messageview->mimeview);
1704 }
1705
1706 void messageview_copy_clipboard(MessageView *messageview)
1707 {
1708         gchar *text = messageview_get_selection(messageview);
1709         if (text) {
1710                 gtk_clipboard_set_text(
1711                         gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
1712                         text, -1);
1713         }
1714         g_free(text);
1715 }
1716
1717 void messageview_select_all(MessageView *messageview)
1718 {
1719         TextView *text;
1720
1721         text = messageview_get_current_textview(messageview);
1722         if (text) {
1723                 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
1724                 GtkTextBuffer *buffer;
1725                 GtkTextIter start, end;
1726
1727                 buffer = gtk_text_view_get_buffer(textview);
1728                 gtk_text_buffer_get_bounds(buffer, &start, &end);
1729                 gtk_text_buffer_select_range(buffer, &start, &end);
1730         }
1731 }
1732
1733 void messageview_set_position(MessageView *messageview, gint pos)
1734 {
1735         TextView *text;
1736
1737         text = messageview_get_current_textview(messageview);
1738         if (text)
1739                 textview_set_position(text, pos);
1740 }
1741
1742 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
1743                                    gboolean case_sens)
1744 {
1745         TextView *text;
1746
1747         if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1748                 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1749                 if (viewer && viewer->text_search) {
1750                         return viewer->text_search(viewer, FALSE, str, case_sens);
1751                 }
1752         }
1753
1754         text = messageview_get_current_textview(messageview);
1755         if (text)
1756                 return textview_search_string(text, str, case_sens);
1757         return FALSE;
1758 }
1759
1760 gboolean messageview_search_string_backward(MessageView *messageview,
1761                                             const gchar *str,
1762                                             gboolean case_sens)
1763 {
1764         TextView *text;
1765
1766         if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1767                 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1768                 if (viewer && viewer->text_search) {
1769                         return viewer->text_search(viewer, TRUE, str, case_sens);
1770                 }
1771         }
1772
1773         text = messageview_get_current_textview(messageview);
1774         if (text)       
1775                 return textview_search_string_backward(text,
1776                                                        str, case_sens);
1777         return FALSE;
1778 }
1779
1780 gboolean messageview_is_visible(MessageView *messageview)
1781 {
1782         if (messageview == NULL)
1783                 return FALSE;
1784         return messageview->visible;
1785 }
1786
1787 static void messageview_save_as(MessageView *messageview)
1788 {
1789         gchar *filename = NULL;
1790         MsgInfo *msginfo;
1791         gchar *src, *dest, *tmp;
1792
1793         if (!messageview->msginfo) return;
1794         msginfo = messageview->msginfo;
1795
1796         if (msginfo->subject) {
1797                 Xstrdup_a(filename, msginfo->subject, return);
1798                 subst_for_filename(filename);
1799         }
1800         if (filename && !g_utf8_validate(filename, -1, NULL)) {
1801                 gchar *oldstr = filename;
1802                 filename = conv_codeset_strdup(filename,
1803                                                conv_get_locale_charset_str(),
1804                                                CS_UTF_8);
1805                 if (!filename) {
1806                         g_warning("messageview_save_as(): failed to convert character set.");
1807                         filename = g_strdup(oldstr);
1808                 }
1809                 dest = filesel_select_file_save(_("Save as"), filename);
1810                 g_free(filename);
1811         } else
1812                 dest = filesel_select_file_save(_("Save as"), filename);
1813         if (!dest) return;
1814         if (is_file_exist(dest)) {
1815                 AlertValue aval;
1816
1817                 aval = alertpanel(_("Overwrite"),
1818                                   _("Overwrite existing file?"),
1819                                   GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
1820                 if (G_ALERTALTERNATE != aval) return;
1821         }
1822
1823         src = procmsg_get_message_file(msginfo);
1824         if (copy_file(src, dest, TRUE) < 0) {
1825                 tmp =  g_path_get_basename(dest);
1826                 alertpanel_error(_("Couldn't save the file '%s'."), tmp);
1827                 g_free(tmp);
1828         }
1829         g_free(dest);
1830         g_free(src);
1831 }
1832
1833 static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
1834                                   MessageView *messageview)
1835 {
1836         messageview_destroy(messageview);
1837         return TRUE;
1838 }
1839
1840 static void messageview_size_allocate_cb(GtkWidget *widget,
1841                                          GtkAllocation *allocation)
1842 {
1843         cm_return_if_fail(allocation != NULL);
1844
1845         prefs_common.msgwin_width  = allocation->width;
1846         prefs_common.msgwin_height = allocation->height;
1847 }
1848 #ifndef MAEMO
1849 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
1850                         MessageView *messageview)
1851 {
1852         if (event && event->keyval == GDK_KEY_Escape && messageview->window) {
1853                 messageview_destroy(messageview);
1854                 return TRUE;
1855         }
1856
1857         if (event && (event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0)
1858                 return FALSE;
1859         if (event && (event->state & GDK_SHIFT_MASK) && event->keyval != GDK_KEY_space) 
1860                 return FALSE;
1861
1862         return mimeview_pass_key_press_event(messageview->mimeview, event);
1863 }
1864 #endif
1865
1866 static void messageview_show_partial_display_cb(NoticeView *noticeview, MessageView *messageview)
1867 {
1868         messageview->show_full_text = TRUE;
1869         main_window_cursor_wait(mainwindow_get_mainwindow());
1870         noticeview_hide(messageview->noticeview);
1871         messageview->partial_display_shown = FALSE;
1872         GTK_EVENTS_FLUSH();
1873         mimeview_handle_cmd(messageview->mimeview, "sc://display_as_text", NULL, NULL);
1874         main_window_cursor_normal(mainwindow_get_mainwindow());
1875 }
1876
1877 void messageview_show_partial_display(MessageView *messageview, MsgInfo *msginfo,
1878                                              size_t length)
1879 {
1880         gchar *msg = g_strdup_printf(_("Show all %s."), to_human_readable((goffset)length));
1881         noticeview_set_icon(messageview->noticeview, STOCK_PIXMAP_NOTICE_WARN);
1882         noticeview_set_text(messageview->noticeview, _("Only the first megabyte of text is shown."));
1883         noticeview_set_button_text(messageview->noticeview, msg);
1884         g_free(msg);
1885         noticeview_set_button_press_callback(messageview->noticeview,
1886                                              G_CALLBACK(messageview_show_partial_display_cb),
1887                                              (gpointer) messageview);
1888         noticeview_show(messageview->noticeview);
1889         messageview->partial_display_shown = TRUE;
1890 }
1891
1892 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1893 {
1894         gchar *addr = NULL;
1895         gboolean from_me = FALSE;
1896         if (msginfo->folder 
1897                 && (folder_has_parent_of_type(msginfo->folder, F_QUEUE)
1898                  || folder_has_parent_of_type(msginfo->folder, F_DRAFT)))
1899                 return;
1900
1901         addr = g_strdup(msginfo->from);
1902         if (addr) {
1903                 extract_address(addr);
1904                 if (account_find_from_address(addr, FALSE)) {
1905                         from_me = TRUE;
1906                 }
1907                 g_free(addr);
1908         }
1909
1910         if (from_me) {
1911                 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1912                 if (MSG_IS_RETRCPT_GOT(msginfo->flags)) {
1913                         noticeview_set_text(noticeview, _("You got a return receipt for this message : "
1914                                                           "it has been displayed by the recipient."));
1915                 } else {
1916                         noticeview_set_text(noticeview, _("You asked for a return receipt in this message."));
1917                 }
1918                 noticeview_set_button_text(noticeview, NULL);
1919                 noticeview_set_button_press_callback(noticeview, NULL, NULL);
1920         } else {
1921                 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1922                 noticeview_set_text(noticeview, _("This message asks for a return receipt."));
1923                 noticeview_set_button_text(noticeview, _("Send receipt"));
1924                 noticeview_set_button_press_callback(noticeview,
1925                                                      G_CALLBACK(return_receipt_send_clicked),
1926                                                      (gpointer) msginfo);
1927         }
1928         noticeview_show(noticeview);
1929 }
1930
1931 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1932 {
1933         MsgInfo *tmpmsginfo;
1934         gchar *file;
1935
1936         file = procmsg_get_message_file_path(msginfo);
1937         if (!file) {
1938                 g_warning("can't get message file path.\n");
1939                 return;
1940         }
1941
1942         tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1943         tmpmsginfo->folder = msginfo->folder;
1944         tmpmsginfo->msgnum = msginfo->msgnum;
1945
1946         if (disposition_notification_send(tmpmsginfo) >= 0) {
1947                 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1948                 noticeview_hide(noticeview);
1949         }               
1950
1951         procmsg_msginfo_free(tmpmsginfo);
1952         g_free(file);
1953 }
1954
1955 static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
1956 {
1957         gchar *text = NULL;
1958         gchar *button1 = NULL;
1959         gchar *button2 = NULL;
1960         void  *button1_cb = NULL;
1961         void  *button2_cb = NULL;
1962
1963         if (!msginfo->extradata)
1964                 return;
1965         if (!partial_msg_in_uidl_list(msginfo)) {
1966                 text = g_strdup_printf(_("This message has been partially "
1967                                 "retrieved,\nand has been deleted from the "
1968                                 "server."));
1969         } else {
1970                 switch (msginfo->planned_download) {
1971                 case POP3_PARTIAL_DLOAD_UNKN:
1972                         text = g_strdup_printf(_("This message has been "
1973                                         "partially retrieved;\nit is %s."),
1974                                         to_human_readable(
1975                                                 (goffset)(msginfo->total_size)));
1976                         button1 = _("Mark for download");
1977                         button2 = _("Mark for deletion");
1978                         button1_cb = partial_recv_dload_clicked;
1979                         button2_cb = partial_recv_del_clicked;
1980                         break;
1981                 case POP3_PARTIAL_DLOAD_DLOAD:
1982                         text = g_strdup_printf(_("This message has been "
1983                                         "partially retrieved;\nit is %s and "
1984                                         "will be downloaded."),
1985                                         to_human_readable(
1986                                                 (goffset)(msginfo->total_size)));
1987                         button1 = _("Unmark");
1988                         button1_cb = partial_recv_unmark_clicked;
1989                         button2 = _("Mark for deletion");
1990                         button2_cb = partial_recv_del_clicked;
1991                         break;
1992                 case POP3_PARTIAL_DLOAD_DELE:
1993                         text = g_strdup_printf(_("This message has been "
1994                                         "partially retrieved;\nit is %s and "
1995                                         "will be deleted."),
1996                                         to_human_readable(
1997                                                 (goffset)(msginfo->total_size)));
1998                         button1 = _("Mark for download");
1999                         button1_cb = partial_recv_dload_clicked;
2000                         button2 = _("Unmark");
2001                         button2_cb = partial_recv_unmark_clicked;
2002                         break;
2003                 default:
2004                         return;
2005                 }
2006         }
2007         
2008         noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
2009         noticeview_set_text(noticeview, text);
2010         g_free(text);
2011         noticeview_set_button_text(noticeview, button1);
2012         noticeview_set_button_press_callback(noticeview,
2013                      G_CALLBACK(button1_cb), (gpointer) msginfo);
2014
2015         noticeview_set_2ndbutton_text(noticeview, button2);
2016         noticeview_set_2ndbutton_press_callback(noticeview,
2017                      G_CALLBACK(button2_cb), (gpointer) msginfo);
2018
2019         noticeview_show(noticeview);
2020 }
2021
2022 static void partial_recv_dload_clicked(NoticeView *noticeview, 
2023                                        MsgInfo *msginfo)
2024 {
2025         if (partial_mark_for_download(msginfo) == 0) {
2026                 partial_recv_show(noticeview, msginfo);
2027         }
2028 }
2029
2030 static void partial_recv_del_clicked(NoticeView *noticeview, 
2031                                        MsgInfo *msginfo)
2032 {
2033         if (partial_mark_for_delete(msginfo) == 0) {
2034                 partial_recv_show(noticeview, msginfo);
2035         }
2036 }
2037
2038 static void partial_recv_unmark_clicked(NoticeView *noticeview, 
2039                                        MsgInfo *msginfo)
2040 {
2041         if (partial_unmark(msginfo) == 0) {
2042                 partial_recv_show(noticeview, msginfo);
2043         }
2044 }
2045
2046 static void select_account_cb(GtkWidget *w, gpointer data)
2047 {
2048         *(gint*)data = combobox_get_active_data(GTK_COMBO_BOX(w));
2049 }
2050
2051 static PrefsAccount *select_account_from_list(GList *ac_list)
2052 {
2053         GtkWidget *optmenu;
2054         gint account_id;
2055
2056         cm_return_val_if_fail(ac_list != NULL, NULL);
2057         cm_return_val_if_fail(ac_list->data != NULL, NULL);
2058         
2059         optmenu = gtkut_account_menu_new(ac_list,
2060                         G_CALLBACK(select_account_cb),
2061                         &account_id);
2062         if (!optmenu)
2063                 return NULL;
2064         account_id = ((PrefsAccount *) ac_list->data)->account_id;
2065         if (alertpanel_with_widget(
2066                                 _("Return Receipt Notification"),
2067                                 _("The message was sent to several of your "
2068                                   "accounts.\n"
2069                                   "Please choose which account do you want to "
2070                                   "use for sending the receipt notification:"),
2071                                 _("_Cancel"), _("_Send Notification"), NULL,
2072                                 FALSE, G_ALERTDEFAULT, optmenu) != G_ALERTALTERNATE)
2073                 return NULL;
2074         return account_find_from_id(account_id);
2075 }
2076
2077 /* 
2078  * \brief return selected messageview text, when nothing is 
2079  *        selected and message was filtered, return complete text
2080  *
2081  * \param  pointer to Messageview 
2082  *
2083  * \return pointer to text (needs to be free'd by calling func)
2084  */
2085 gchar *messageview_get_selection(MessageView *msgview)
2086 {
2087         TextView *textview;
2088         gchar *text = NULL;
2089         GtkTextView *edit = NULL;
2090         GtkTextBuffer *textbuf;
2091         gint body_pos = 0;
2092         
2093         cm_return_val_if_fail(msgview != NULL, NULL);
2094
2095         if (msgview->mimeview->type == MIMEVIEW_VIEWER) {
2096                 MimeViewer *viewer = msgview->mimeview->mimeviewer;
2097                 if (viewer && viewer->get_selection) {
2098                         text = viewer->get_selection(viewer);
2099                         if (text)
2100                                 return text;
2101                 }
2102         }
2103
2104         textview = messageview_get_current_textview(msgview);
2105         cm_return_val_if_fail(textview != NULL, NULL);
2106
2107         edit = GTK_TEXT_VIEW(textview->text);
2108         cm_return_val_if_fail(edit != NULL, NULL);
2109         body_pos = textview->body_pos;
2110
2111         textbuf = gtk_text_view_get_buffer(edit);
2112
2113         if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
2114                 return gtkut_text_view_get_selection(edit);
2115         else if (msgview->filtered) {
2116                 GtkTextIter start_iter, end_iter;
2117                 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
2118                 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
2119                 gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
2120         } else
2121                 text = NULL;
2122
2123         return text;
2124 }
2125
2126 static void save_as_cb(GtkAction *action, gpointer data)
2127 {
2128         MessageView *messageview = (MessageView *)data;
2129         messageview_save_as(messageview);
2130 }
2131
2132 static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gint partnum) 
2133 {
2134         MainWindow *mainwin;
2135         if (!mimeview 
2136         ||  !mimeview->textview
2137         ||  !mimeview->textview->text)
2138                 alertpanel_warning(_("Cannot print: the message doesn't "
2139                                      "contain text."));
2140         else {
2141                 gtk_widget_realize(mimeview->textview->text);
2142                 if (partnum > 0) {
2143                         mimeview_select_part_num(mimeview, partnum);
2144                 }
2145                 if (mimeview->type == MIMEVIEW_VIEWER) {
2146                         MimeViewer *viewer = mimeview->mimeviewer;
2147                         if (viewer && viewer->print) {
2148                                 viewer->print(viewer);
2149                                 return;
2150                         }
2151                 }
2152                 if (sel_start != -1 && sel_end != -1) {
2153                         GtkTextIter start, end;
2154                         GtkTextView *text = GTK_TEXT_VIEW(mimeview->textview->text);
2155                         GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2156
2157                         gtk_text_buffer_get_iter_at_offset(buffer, &start, sel_start);
2158                         gtk_text_buffer_get_iter_at_offset(buffer, &end, sel_end);
2159                         gtk_text_buffer_select_range(buffer, &start, &end);
2160                 }
2161                 /* TODO: Get the real parent window, not the main window */
2162                 mainwin = mainwindow_get_mainwindow();
2163                 printing_print(GTK_TEXT_VIEW(mimeview->textview->text),
2164                                mainwin ? GTK_WINDOW(mainwin->window) : NULL,
2165                                 sel_start, sel_end);
2166         }
2167 }
2168
2169 void messageview_print(MsgInfo *msginfo, gboolean all_headers, 
2170                         gint sel_start, gint sel_end, gint partnum) 
2171 {
2172         PangoFontDescription *font_desc = NULL;
2173         MessageView *tmpview = messageview_create_with_new_window_visible(
2174                                 mainwindow_get_mainwindow(), FALSE);
2175
2176         if (prefs_common.use_different_print_font) {
2177                 font_desc = pango_font_description_from_string
2178                                                 (prefs_common.printfont);
2179         } else {
2180                 font_desc = pango_font_description_from_string
2181                                                 (prefs_common.textfont);
2182         }
2183         if (font_desc) {
2184                 gtk_widget_modify_font(tmpview->mimeview->textview->text, 
2185                         font_desc);
2186                 pango_font_description_free(font_desc);
2187         }
2188
2189         tmpview->all_headers = all_headers;
2190         if (msginfo && messageview_show(tmpview, msginfo, 
2191                 tmpview->all_headers) >= 0) {
2192                         print_mimeview(tmpview->mimeview, 
2193                                 sel_start, sel_end, partnum);
2194         }
2195         messageview_destroy(tmpview);
2196 }
2197
2198 static void page_setup_cb(GtkAction *action, gpointer data)
2199 {
2200         MessageView *messageview = (MessageView *)data;
2201         printing_page_setup(messageview ?
2202                             GTK_WINDOW(messageview->window) : NULL);
2203 }
2204
2205 static void print_cb(GtkAction *action, gpointer data)
2206 {
2207         MessageView *messageview = (MessageView *)data;
2208         gint sel_start = -1, sel_end = -1, partnum = 0;
2209
2210         if (!messageview->msginfo) return;
2211
2212         partnum = mimeview_get_selected_part_num(messageview->mimeview);
2213         textview_get_selection_offsets(messageview->mimeview->textview,
2214                 &sel_start, &sel_end);
2215         messageview_print(messageview->msginfo, messageview->all_headers, 
2216                 sel_start, sel_end, partnum);
2217 }
2218
2219 static void close_cb(GtkAction *action, gpointer data)
2220 {
2221         MessageView *messageview = (MessageView *)data;
2222         messageview_destroy(messageview);
2223 }
2224
2225 static void copy_cb(GtkAction *action, gpointer data)
2226 {
2227         MessageView *messageview = (MessageView *)data;
2228         messageview_copy_clipboard(messageview);
2229 }
2230
2231 static void allsel_cb(GtkAction *action, gpointer data)
2232 {
2233         MessageView *messageview = (MessageView *)data;
2234         messageview_select_all(messageview);
2235 }
2236
2237 static void search_cb(GtkAction *action, gpointer data)
2238 {
2239         MessageView *messageview = (MessageView *)data;
2240         message_search(messageview);
2241 }
2242
2243 static void prev_cb(GtkAction *action, gpointer data)
2244 {
2245         MessageView *messageview = (MessageView *)data;
2246         messageview->updating = TRUE;
2247         summary_step(messageview->mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2248         messageview->updating = FALSE;
2249
2250         if (messageview->deferred_destroy) {
2251                 debug_print("messageview got away!\n");
2252                 messageview_destroy(messageview);
2253                 return;
2254         }
2255         if (messageview->mainwin->summaryview->selected) {
2256 #ifndef GENERIC_UMPC
2257                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2258                        
2259                 if (msginfo)
2260                         messageview_show(messageview, msginfo, 
2261                                          messageview->all_headers);
2262 #endif
2263         } else {
2264                 gtk_widget_destroy(messageview->window);
2265         }
2266 }
2267
2268 static void next_cb(GtkAction *action, gpointer data)
2269 {
2270         MessageView *messageview = (MessageView *)data;
2271         messageview->updating = TRUE;
2272         summary_step(messageview->mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2273         messageview->updating = FALSE;
2274
2275         if (messageview->deferred_destroy) {
2276                 debug_print("messageview got away!\n");
2277                 messageview_destroy(messageview);
2278                 return;
2279         }
2280         if (messageview->mainwin->summaryview->selected) {
2281 #ifndef GENERIC_UMPC
2282                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2283                        
2284                 if (msginfo)
2285                         messageview_show(messageview, msginfo, 
2286                                          messageview->all_headers);
2287 #endif
2288         } else {
2289                 gtk_widget_destroy(messageview->window);
2290         }
2291 }
2292
2293 static void prev_unread_cb(GtkAction *action, gpointer data)
2294 {
2295         MessageView *messageview = (MessageView *)data;
2296         messageview->updating = TRUE;
2297         summary_select_prev_unread(messageview->mainwin->summaryview);
2298         messageview->updating = FALSE;
2299
2300         if (messageview->deferred_destroy) {
2301                 debug_print("messageview got away!\n");
2302                 messageview_destroy(messageview);
2303                 return;
2304         }
2305         if (messageview->mainwin->summaryview->selected) {
2306 #ifndef GENERIC_UMPC
2307                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2308                        
2309                 if (msginfo)
2310                         messageview_show(messageview, msginfo, 
2311                                          messageview->all_headers);
2312 #endif
2313         } else {
2314                 gtk_widget_destroy(messageview->window);
2315         }
2316 }
2317
2318 static void next_unread_cb(GtkAction *action, gpointer data)
2319 {
2320         MessageView *messageview = (MessageView *)data;
2321         messageview->updating = TRUE;
2322         summary_select_next_unread(messageview->mainwin->summaryview);
2323         messageview->updating = FALSE;
2324
2325         if (messageview->deferred_destroy) {
2326                 debug_print("messageview got away!\n");
2327                 messageview_destroy(messageview);
2328                 return;
2329         }
2330         if (messageview->mainwin->summaryview->selected) {
2331 #ifndef GENERIC_UMPC
2332                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2333                        
2334                 if (msginfo)
2335                         messageview_show(messageview, msginfo, 
2336                                          messageview->all_headers);
2337 #endif
2338         } else {
2339                 gtk_widget_destroy(messageview->window);
2340         }
2341 }
2342
2343 static void prev_new_cb(GtkAction *action, gpointer data)
2344 {
2345         MessageView *messageview = (MessageView *)data;
2346         messageview->updating = TRUE;
2347         summary_select_prev_new(messageview->mainwin->summaryview);
2348         messageview->updating = FALSE;
2349
2350         if (messageview->deferred_destroy) {
2351                 debug_print("messageview got away!\n");
2352                 messageview_destroy(messageview);
2353                 return;
2354         }
2355         if (messageview->mainwin->summaryview->selected) {
2356 #ifndef GENERIC_UMPC
2357                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2358                        
2359                 if (msginfo)
2360                         messageview_show(messageview, msginfo, 
2361                                          messageview->all_headers);
2362 #endif
2363         } else {
2364                 gtk_widget_destroy(messageview->window);
2365         }
2366 }
2367
2368 static void next_new_cb(GtkAction *action, gpointer data)
2369 {
2370         MessageView *messageview = (MessageView *)data;
2371         messageview->updating = TRUE;
2372         summary_select_next_new(messageview->mainwin->summaryview);
2373         messageview->updating = FALSE;
2374
2375         if (messageview->deferred_destroy) {
2376                 debug_print("messageview got away!\n");
2377                 messageview_destroy(messageview);
2378                 return;
2379         }
2380         if (messageview->mainwin->summaryview->selected) {
2381 #ifndef GENERIC_UMPC
2382                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2383                        
2384                 if (msginfo)
2385                         messageview_show(messageview, msginfo, 
2386                                          messageview->all_headers);
2387 #endif
2388         } else {
2389                 gtk_widget_destroy(messageview->window);
2390         }
2391 }
2392
2393 static void prev_marked_cb(GtkAction *action, gpointer data)
2394 {
2395         MessageView *messageview = (MessageView *)data;
2396         messageview->updating = TRUE;
2397         summary_select_prev_marked(messageview->mainwin->summaryview);
2398         messageview->updating = FALSE;
2399
2400         if (messageview->deferred_destroy) {
2401                 debug_print("messageview got away!\n");
2402                 messageview_destroy(messageview);
2403                 return;
2404         }
2405         if (messageview->mainwin->summaryview->selected) {
2406 #ifndef GENERIC_UMPC
2407                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2408                        
2409                 if (msginfo)
2410                         messageview_show(messageview, msginfo, 
2411                                          messageview->all_headers);
2412 #endif
2413         } else {
2414                 gtk_widget_destroy(messageview->window);
2415         }
2416 }
2417
2418 static void next_marked_cb(GtkAction *action, gpointer data)
2419 {
2420         MessageView *messageview = (MessageView *)data;
2421         messageview->updating = TRUE;
2422         summary_select_next_marked(messageview->mainwin->summaryview);
2423         messageview->updating = FALSE;
2424
2425         if (messageview->deferred_destroy) {
2426                 debug_print("messageview got away!\n");
2427                 messageview_destroy(messageview);
2428                 return;
2429         }
2430         if (messageview->mainwin->summaryview->selected) {
2431 #ifndef GENERIC_UMPC
2432                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2433                        
2434                 if (msginfo)
2435                         messageview_show(messageview, msginfo, 
2436                                          messageview->all_headers);
2437 #endif
2438         } else {
2439                 gtk_widget_destroy(messageview->window);
2440         }
2441 }
2442
2443 static void prev_labeled_cb(GtkAction *action, gpointer data)
2444 {
2445         MessageView *messageview = (MessageView *)data;
2446         messageview->updating = TRUE;
2447         summary_select_prev_labeled(messageview->mainwin->summaryview);
2448         messageview->updating = FALSE;
2449
2450         if (messageview->deferred_destroy) {
2451                 debug_print("messageview got away!\n");
2452                 messageview_destroy(messageview);
2453                 return;
2454         }
2455         if (messageview->mainwin->summaryview->selected) {
2456 #ifndef GENERIC_UMPC
2457                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2458                        
2459                 if (msginfo)
2460                         messageview_show(messageview, msginfo, 
2461                                          messageview->all_headers);
2462 #endif
2463         } else {
2464                 gtk_widget_destroy(messageview->window);
2465         }
2466 }
2467
2468 static void next_labeled_cb(GtkAction *action, gpointer data)
2469 {
2470         MessageView *messageview = (MessageView *)data;
2471         messageview->updating = TRUE;
2472         summary_select_next_labeled(messageview->mainwin->summaryview);
2473         messageview->updating = FALSE;
2474
2475         if (messageview->deferred_destroy) {
2476                 debug_print("messageview got away!\n");
2477                 messageview_destroy(messageview);
2478                 return;
2479         }
2480         if (messageview->mainwin->summaryview->selected) {
2481 #ifndef GENERIC_UMPC
2482                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2483                        
2484                 if (msginfo)
2485                         messageview_show(messageview, msginfo, 
2486                                          messageview->all_headers);
2487 #endif
2488         } else {
2489                 gtk_widget_destroy(messageview->window);
2490         }
2491 }
2492
2493 static void prev_history_cb(GtkAction *action, gpointer data)
2494 {
2495         MessageView *messageview = (MessageView *)data;
2496         MsgInfo *info = messageview_nav_get_prev(messageview);
2497         if (info) {
2498                 messageview->updating = TRUE;
2499                 messageview_show(messageview, info, 
2500                                          messageview->all_headers);
2501                 messageview->updating = FALSE;
2502                 procmsg_msginfo_free(info);
2503                 if (messageview->deferred_destroy) {
2504                         debug_print("messageview got away!\n");
2505                         messageview_destroy(messageview);
2506                         return;
2507                 }
2508         }
2509 }
2510
2511 static void next_history_cb(GtkAction *action, gpointer data)
2512 {
2513         MessageView *messageview = (MessageView *)data;
2514         MsgInfo *info = messageview_nav_get_next(messageview);
2515         if (info) {
2516                 messageview->updating = TRUE;
2517                 messageview_show(messageview, info, 
2518                                          messageview->all_headers);
2519                 messageview->updating = FALSE;
2520                 procmsg_msginfo_free(info);
2521                 if (messageview->deferred_destroy) {
2522                         debug_print("messageview got away!\n");
2523                         messageview_destroy(messageview);
2524                         return;
2525                 }
2526         }
2527 }
2528
2529 static void parent_cb(GtkAction *action, gpointer data)
2530 {
2531         MessageView *messageview = (MessageView *)data;
2532         messageview->updating = TRUE;
2533         summary_select_parent(messageview->mainwin->summaryview);
2534         messageview->updating = FALSE;
2535
2536         if (messageview->deferred_destroy) {
2537                 debug_print("messageview got away!\n");
2538                 messageview_destroy(messageview);
2539                 return;
2540         }
2541         if (messageview->mainwin->summaryview->selected) {
2542 #ifndef GENERIC_UMPC
2543                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2544                        
2545                 if (msginfo)
2546                         messageview_show(messageview, msginfo, 
2547                                          messageview->all_headers);
2548 #endif
2549         } else {
2550                 gtk_widget_destroy(messageview->window);
2551         }
2552 }
2553
2554 static void goto_unread_folder_cb(GtkAction *action, gpointer data)
2555 {
2556         MessageView *messageview = (MessageView *)data;
2557         messageview->updating = TRUE;
2558         folderview_select_next_unread(messageview->mainwin->folderview, FALSE);
2559         messageview->updating = FALSE;
2560
2561         if (messageview->deferred_destroy) {
2562                 debug_print("messageview got away!\n");
2563                 messageview_destroy(messageview);
2564                 return;
2565         }
2566         if (messageview->mainwin->summaryview->selected) {
2567 #ifndef GENERIC_UMPC
2568                 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2569                        
2570                 if (msginfo)
2571                         messageview_show(messageview, msginfo, 
2572                                          messageview->all_headers);
2573 #endif
2574         } else {
2575                 gtk_widget_destroy(messageview->window);
2576         }
2577 }
2578
2579 static void goto_folder_cb(GtkAction *action, gpointer data)
2580 {
2581         MessageView *messageview = (MessageView *)data;
2582         messageview->updating = TRUE;
2583         FolderItem *to_folder;
2584         messageview->updating = FALSE;
2585
2586         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL, FALSE);
2587
2588         if (to_folder) {
2589                 folderview_select(messageview->mainwin->folderview, to_folder);
2590
2591                 if (messageview->deferred_destroy) {
2592                         debug_print("messageview got away!\n");
2593                         messageview_destroy(messageview);
2594                         return;
2595                 }
2596                 if (messageview->mainwin->summaryview->selected) {
2597 #ifndef GENERIC_UMPC
2598                         MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2599                        
2600                         if (msginfo)
2601                                 messageview_show(messageview, msginfo, 
2602                                                  messageview->all_headers);
2603 #endif
2604                 } else {
2605                         gtk_widget_destroy(messageview->window);
2606                 }
2607         }
2608 }
2609
2610 static void scroll_prev_line_cb(GtkAction *action, gpointer data)
2611 {
2612         MessageView *messageview = (MessageView *)data;
2613         mimeview_scroll_one_line(messageview->mimeview,TRUE);
2614 }
2615
2616 static void scroll_next_line_cb(GtkAction *action, gpointer data)
2617 {
2618         MessageView *messageview = (MessageView *)data;
2619         mimeview_scroll_one_line(messageview->mimeview,FALSE);
2620 }
2621
2622 static void scroll_prev_page_cb(GtkAction *action, gpointer data)
2623 {
2624         MessageView *messageview = (MessageView *)data;
2625         mimeview_scroll_page(messageview->mimeview,TRUE);
2626 }
2627
2628 static void scroll_next_page_cb(GtkAction *action, gpointer data)
2629 {
2630         MessageView *messageview = (MessageView *)data;
2631         mimeview_scroll_page(messageview->mimeview,FALSE);
2632 }
2633
2634 static void set_charset_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
2635 {
2636         MessageView *messageview = (MessageView *)data;
2637         gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
2638         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
2639         const gchar *charset;
2640
2641         if (active) {
2642                 charset = conv_get_charset_str((CharSet)value);
2643                 g_free(messageview->forced_charset);
2644                 messageview->forced_charset = g_strdup(charset);
2645                 procmime_force_charset(charset);
2646                 
2647                 messageview_show(messageview, messageview->msginfo, FALSE);
2648         }
2649 }
2650
2651 static void set_decode_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
2652 {
2653         MessageView *messageview = (MessageView *)data;
2654         gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
2655         gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
2656
2657         if (active) {
2658                 messageview->forced_encoding = (EncodingType)value;
2659
2660                 messageview_show(messageview, messageview->msginfo, FALSE);
2661                 debug_print("forced encoding: %d\n", value);
2662         }
2663 }
2664
2665
2666 static void view_source_cb(GtkAction *action, gpointer data)
2667 {
2668         MessageView *messageview = (MessageView *)data;
2669         SourceWindow *srcwin;
2670
2671         if (!messageview->msginfo) return;
2672
2673         srcwin = source_window_create();
2674         source_window_show_msg(srcwin, messageview->msginfo);
2675         source_window_show(srcwin);
2676 }
2677
2678 static void show_all_header_cb(GtkToggleAction *action, gpointer data)
2679 {
2680         MessageView *messageview = (MessageView *)data;
2681         MsgInfo *msginfo = messageview->msginfo;
2682
2683         if (messageview->mimeview->textview &&
2684             messageview->mimeview->textview->loading) {
2685                 return;
2686         }
2687         if (messageview->updating)
2688                 return;
2689
2690         messageview->all_headers = prefs_common.show_all_headers =
2691                         gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
2692         if (!msginfo) return;
2693         messageview->msginfo = NULL;
2694         messageview_show(messageview, msginfo, messageview->all_headers);
2695         procmsg_msginfo_free(msginfo);
2696         main_window_set_menu_sensitive(messageview->mainwin);
2697         summary_redisplay_msg(messageview->mainwin->summaryview);
2698 }
2699
2700 static void msg_hide_quotes_cb(GtkToggleAction *action, gpointer data)
2701 {
2702         MessageView *messageview = (MessageView *)data;
2703         MsgInfo *msginfo = messageview->msginfo;
2704         static gboolean updating_menu = FALSE;
2705
2706         if (updating_menu)
2707                 return;
2708         if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
2709                 const gchar *a_name = gtk_action_get_name(GTK_ACTION(action));
2710                 if (!strcmp(a_name, "View/Quotes/CollapseAll")) prefs_common.hide_quotes = 1;
2711                 else if (!strcmp(a_name, "View/Quotes/Collapse2")) prefs_common.hide_quotes = 2;
2712                 else if (!strcmp(a_name, "View/Quotes/Collapse3")) prefs_common.hide_quotes = 3;
2713         } else
2714                 prefs_common.hide_quotes = 0;
2715         
2716         updating_menu=TRUE;
2717         
2718         cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
2719         cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));
2720         cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse3", (prefs_common.hide_quotes == 3));
2721
2722         updating_menu=FALSE;
2723         if (!msginfo) return;
2724         messageview->msginfo = NULL;
2725         messageview_show(messageview, msginfo,
2726                          messageview->all_headers);
2727         procmsg_msginfo_free(msginfo);
2728         
2729         /* update main window */
2730         main_window_set_menu_sensitive(messageview->mainwin);
2731         summary_redisplay_msg(messageview->mainwin->summaryview);
2732 }
2733 #undef SET_CHECK_MENU_ACTIVE
2734
2735 static void compose_cb(GtkAction *action, gpointer data)
2736 {
2737         MessageView *messageview = (MessageView *)data;
2738         PrefsAccount *ac = NULL;
2739         FolderItem *item = NULL;
2740
2741         if (messageview->msginfo)
2742                 item = messageview->msginfo->folder;
2743
2744         if (item) {
2745                 ac = account_find_from_item(item);
2746                 if (ac && ac->protocol == A_NNTP &&
2747                     FOLDER_TYPE(item->folder) == F_NEWS) {
2748                         compose_new(ac, item->path, NULL);
2749                         return;
2750                 }
2751         }
2752
2753         compose_new(ac, NULL, NULL);
2754 }
2755
2756 #define DO_ACTION(name, act)    { if (!strcmp(a_name, name)) action = act; }
2757
2758 static void reply_cb(GtkAction *gaction, gpointer data)
2759 {
2760         MessageView *messageview = (MessageView *)data;
2761         GSList *msginfo_list = NULL;
2762         gint action = COMPOSE_REPLY;
2763         const gchar *a_name = gtk_action_get_name(gaction);
2764         
2765         cm_return_if_fail(messageview->msginfo);
2766
2767         DO_ACTION("Message/Reply", COMPOSE_REPLY);
2768         DO_ACTION("Message/ReplyTo/All", COMPOSE_REPLY_TO_ALL);
2769         DO_ACTION("Message/ReplyTo/Sender", COMPOSE_REPLY_TO_SENDER);
2770         DO_ACTION("Message/ReplyTo/List", COMPOSE_REPLY_TO_LIST);
2771         DO_ACTION("Message/Forward", COMPOSE_FORWARD_INLINE);
2772         DO_ACTION("Message/ForwardAtt", COMPOSE_FORWARD_AS_ATTACH);
2773         DO_ACTION("Message/Redirect", COMPOSE_REDIRECT);
2774
2775         msginfo_list = g_slist_append(msginfo_list, messageview->msginfo);
2776         compose_reply_from_messageview(messageview, msginfo_list, action);
2777         g_slist_free(msginfo_list);
2778 }
2779
2780 static void addressbook_open_cb(GtkAction *action, gpointer data)
2781 {
2782         addressbook_open(NULL);
2783 }
2784
2785 static void add_address_cb(GtkAction *action, gpointer data)
2786 {
2787         MessageView *messageview = (MessageView *)data;
2788         MsgInfo *msginfo, *full_msginfo;
2789         gchar *from;
2790         GtkWidget *image = NULL;
2791         GdkPixbuf *picture = NULL;
2792
2793         if (!messageview->msginfo || !messageview->msginfo->from) 
2794                 return;
2795
2796         msginfo = messageview->msginfo;
2797         Xstrdup_a(from, msginfo->from, return);
2798         eliminate_address_comment(from);
2799         extract_address(from);
2800         
2801         full_msginfo = procmsg_msginfo_get_full_info(msginfo);
2802         if (full_msginfo &&
2803             full_msginfo->extradata &&
2804             full_msginfo->extradata->face) {
2805                 image = face_get_from_header(full_msginfo->extradata->face);
2806         } 
2807 #if HAVE_LIBCOMPFACE
2808         else if (full_msginfo &&
2809                  full_msginfo->extradata &&
2810                  full_msginfo->extradata->xface) {
2811                 image = xface_get_from_header(full_msginfo->extradata->xface,
2812                                 &(gtk_widget_get_style(messageview->mainwin->summaryview->ctree)->white),
2813                                 gtk_widget_get_window(messageview->window));
2814         }
2815 #endif
2816         procmsg_msginfo_free(full_msginfo);
2817         if (image)
2818                 picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
2819
2820         addressbook_add_contact(msginfo->fromname, from, NULL, picture);
2821
2822         if (image)
2823                 gtk_widget_destroy(image);
2824 }
2825
2826 static void create_filter_cb(GtkAction *gaction, gpointer data)
2827 {
2828         MessageView *messageview = (MessageView *)data;
2829         FolderItem * item;
2830         gint action = -1;
2831         const gchar *a_name = gtk_action_get_name(gaction);
2832
2833         if (!messageview->msginfo) return;
2834
2835         DO_ACTION("Tools/CreateFilterRule/Automatically", FILTER_BY_AUTO);
2836         DO_ACTION("Tools/CreateFilterRule/ByFrom", FILTER_BY_FROM);
2837         DO_ACTION("Tools/CreateFilterRule/ByTo", FILTER_BY_TO);
2838         DO_ACTION("Tools/CreateFilterRule/BySubject", FILTER_BY_SUBJECT);
2839         
2840         item = messageview->msginfo->folder;
2841         summary_msginfo_filter_open(item,  messageview->msginfo,
2842                                     (PrefsFilterType)action, 0);
2843 }
2844
2845 static void create_processing_cb(GtkAction *gaction, gpointer data)
2846 {
2847         MessageView *messageview = (MessageView *)data;
2848         FolderItem * item;
2849         gint action = -1;
2850         const gchar *a_name = gtk_action_get_name(gaction);
2851         
2852         if (!messageview->msginfo) return;
2853         
2854         DO_ACTION("Tools/CreateProcessingRule/Automatically", FILTER_BY_AUTO);
2855         DO_ACTION("Tools/CreateProcessingRule/ByFrom", FILTER_BY_FROM);
2856         DO_ACTION("Tools/CreateProcessingRule/ByTo", FILTER_BY_TO);
2857         DO_ACTION("Tools/CreateProcessingRule/BySubject", FILTER_BY_SUBJECT);
2858
2859         item = messageview->msginfo->folder;
2860         summary_msginfo_filter_open(item,  messageview->msginfo,
2861                                     (PrefsFilterType)action, 1);
2862 }
2863
2864 static void open_urls_cb(GtkAction *action, gpointer data)
2865 {
2866         MessageView *messageview = (MessageView *)data;
2867         messageview_list_urls(messageview);
2868 }
2869
2870 static void about_cb(GtkAction *gaction, gpointer data)
2871 {
2872         about_show();
2873 }
2874
2875 static gboolean messageview_update_msg(gpointer source, gpointer data)
2876 {
2877         MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
2878         MessageView *messageview = (MessageView *)data;
2879         MsgInfo *old_msginfo = messageview->msginfo;
2880
2881         if (messageview->msginfo != msginfo_update->msginfo)
2882                 return FALSE;
2883
2884         if ((msginfo_update->flags & MSGINFO_UPDATE_DELETED) ||
2885             MSG_IS_DELETED(old_msginfo->flags))
2886         {
2887                 if (messageview->new_window) {
2888                         if (old_msginfo->folder && old_msginfo->folder->total_msgs == 0) {
2889                                 messageview_clear(messageview);
2890                                 textview_show_info(messageview->mimeview->textview,
2891                                         _("\n  There are no messages in this folder"));
2892                                 return FALSE;
2893                         }
2894                         
2895                         if (!prefs_common.always_show_msg) {
2896                                 messageview_clear(messageview);
2897                                 textview_show_info(messageview->mimeview->textview,
2898                                         MSG_IS_DELETED(old_msginfo->flags) ?
2899                                         _("\n  Message has been deleted") :
2900                                         _("\n  Message has been moved to trash"));
2901                         } else
2902                                 messageview->update_needed = TRUE;
2903
2904                 } else {
2905                         messageview_clear(messageview);
2906                         messageview_update(messageview, old_msginfo);
2907                 }
2908         } 
2909
2910         return FALSE;
2911 }
2912
2913 void messageview_set_menu_sensitive(MessageView *messageview)
2914 {
2915         if (!messageview || !messageview->new_window) 
2916                 return;
2917         /* do some smart things */
2918         if (!messageview->menubar) return;
2919
2920         cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
2921         cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));
2922         cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse3", (prefs_common.hide_quotes == 3));
2923         cm_menu_set_sensitive_full(messageview->ui_manager, "Menu/View/Goto/PrevHistory", messageview_nav_has_prev(messageview));
2924         cm_menu_set_sensitive_full(messageview->ui_manager, "Menu/View/Goto/NextHistory", messageview_nav_has_next(messageview));
2925 }
2926
2927 void messageview_learn (MessageView *msgview, gboolean is_spam)
2928 {
2929         if (is_spam) {
2930                 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, TRUE) == 0)
2931                         procmsg_msginfo_set_flags(msgview->msginfo, MSG_SPAM, 0);
2932                 else
2933                         log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
2934                 
2935         } else {
2936                 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, FALSE) == 0)
2937                         procmsg_msginfo_unset_flags(msgview->msginfo, MSG_SPAM, 0);
2938                 else
2939                         log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
2940         }
2941         if (msgview->toolbar)
2942                 toolbar_set_learn_button
2943                         (msgview->toolbar,
2944                          MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
2945         else
2946                 toolbar_set_learn_button
2947                         (msgview->mainwin->toolbar,
2948                          MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
2949 }
2950
2951 void messageview_list_urls (MessageView *msgview)
2952 {
2953         GSList *cur = msgview->mimeview->textview->uri_list;
2954         GSList *newlist = NULL;
2955         GHashTable *uri_hashtable;
2956         gchar *tmp;
2957         
2958         uri_hashtable = g_hash_table_new_full(g_str_hash, g_str_equal,
2959                                          (GDestroyNotify) g_free, NULL);
2960         
2961         for (; cur; cur = cur->next) {
2962                 ClickableText *uri = (ClickableText *)cur->data;
2963                 if (uri->uri &&
2964                     (!g_ascii_strncasecmp(uri->uri, "ftp.", 4) ||
2965                      !g_ascii_strncasecmp(uri->uri, "ftp:", 4) ||
2966                      !g_ascii_strncasecmp(uri->uri, "www.", 4) ||
2967                      !g_ascii_strncasecmp(uri->uri, "http:", 5) ||
2968                      !g_ascii_strncasecmp(uri->uri, "https:", 6)))
2969                 {
2970                         tmp = g_utf8_strdown(uri->uri, -1);
2971                         
2972                         if (g_hash_table_lookup(uri_hashtable, tmp)) {
2973                                 g_free(tmp);
2974                                 continue;
2975                         }
2976                         
2977                         newlist = g_slist_prepend(newlist, uri);
2978                         g_hash_table_insert(uri_hashtable, tmp,
2979                                             GUINT_TO_POINTER(g_str_hash(tmp)));
2980                 }
2981         }
2982         newlist = g_slist_reverse(newlist);
2983         uri_opener_open(msgview, newlist);
2984         g_slist_free(newlist);
2985         g_hash_table_destroy(uri_hashtable);
2986 }