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