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