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