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