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