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