Set name on GTK widgets
[claws.git] / src / messageview.c
blob6b187d619c569b6d2fda5db1a917fbe9edbee2e5
1 /*
2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
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.
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.
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/>.
19 #include "defs.h"
21 #include <glib.h>
22 #include <glib/gi18n.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtk.h>
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <string.h>
29 #include "main.h"
30 #include "messageview.h"
31 #include "message_search.h"
32 #include "headerview.h"
33 #include "summaryview.h"
34 #include "textview.h"
35 #include "mimeview.h"
36 #include "menu.h"
37 #include "about.h"
38 #include "filesel.h"
39 #include "foldersel.h"
40 #include "sourcewindow.h"
41 #include "alertpanel.h"
42 #include "inputdialog.h"
43 #include "mainwindow.h"
44 #include "manage_window.h"
45 #include "procmsg.h"
46 #include "procheader.h"
47 #include "procmime.h"
48 #include "account.h"
49 #include "action.h"
50 #include "prefs_common.h"
51 #include "prefs_account.h"
52 #include "gtkutils.h"
53 #include "utils.h"
54 #include "send_message.h"
55 #include "stock_pixmap.h"
56 #include "hooks.h"
57 #include "filtering.h"
58 #include "partial_download.h"
59 #include "uri_opener.h"
60 #include "inc.h"
61 #include "log.h"
62 #include "privacy.h"
63 #include "combobox.h"
64 #include "printing.h"
65 #include "quoted-printable.h"
66 #include "version.h"
67 #include "statusbar.h"
68 #include "folder_item_prefs.h"
69 #include "avatars.h"
70 #include "file-utils.h"
72 #ifndef USE_ALT_ADDRBOOK
73 #include "addressbook.h"
74 #else
75 #include "addressadd.h"
76 #include "addressbook-dbus.h"
77 #endif
78 static GList *messageview_list = NULL;
80 static gint messageview_delete_cb (GtkWidget *widget,
81 GdkEventAny *event,
82 MessageView *messageview);
83 static void messageview_size_allocate_cb(GtkWidget *widget,
84 GtkAllocation *allocation);
85 static gboolean key_pressed (GtkWidget *widget,
86 GdkEventKey *event,
87 MessageView *messageview);
88 static void return_receipt_show (NoticeView *noticeview,
89 MsgInfo *msginfo);
90 static void return_receipt_send_clicked (NoticeView *noticeview,
91 MsgInfo *msginfo);
92 static void partial_recv_show (NoticeView *noticeview,
93 MsgInfo *msginfo);
94 static void partial_recv_dload_clicked (NoticeView *noticeview,
95 MsgInfo *msginfo);
96 static void partial_recv_del_clicked (NoticeView *noticeview,
97 MsgInfo *msginfo);
98 static void partial_recv_unmark_clicked (NoticeView *noticeview,
99 MsgInfo *msginfo);
100 static void save_as_cb (GtkAction *action,
101 gpointer data);
102 static void page_setup_cb (GtkAction *action,
103 gpointer data);
104 static void print_cb (GtkAction *action,
105 gpointer data);
106 static void close_cb (GtkAction *action,
107 gpointer data);
108 static void copy_cb (GtkAction *action,
109 gpointer data);
110 static void allsel_cb (GtkAction *action,
111 gpointer data);
112 static void search_cb (GtkAction *action,
113 gpointer data);
115 static void prev_cb (GtkAction *action,
116 gpointer data);
117 static void next_cb (GtkAction *action,
118 gpointer data);
119 static void prev_unread_cb (GtkAction *action,
120 gpointer data);
121 static void next_unread_cb (GtkAction *action,
122 gpointer data);
123 static void prev_new_cb (GtkAction *action,
124 gpointer data);
125 static void next_new_cb (GtkAction *action,
126 gpointer data);
127 static void prev_marked_cb (GtkAction *action,
128 gpointer data);
129 static void next_marked_cb (GtkAction *action,
130 gpointer data);
131 static void prev_labeled_cb (GtkAction *action,
132 gpointer data);
133 static void next_labeled_cb (GtkAction *action,
134 gpointer data);
135 static void prev_history_cb (GtkAction *action,
136 gpointer data);
137 static void next_history_cb (GtkAction *action,
138 gpointer data);
139 static void parent_cb (GtkAction *action,
140 gpointer data);
141 static void goto_unread_folder_cb (GtkAction *action,
142 gpointer data);
143 static void goto_folder_cb (GtkAction *action,
144 gpointer data);
146 static void scroll_prev_line_cb (GtkAction *action,
147 gpointer data);
148 static void scroll_next_line_cb (GtkAction *action,
149 gpointer data);
150 static void scroll_next_page_cb (GtkAction *action,
151 gpointer data);
152 static void scroll_prev_page_cb (GtkAction *action,
153 gpointer data);
155 static void set_charset_cb (GtkAction *action, GtkRadioAction *current, gpointer data);
156 static void set_decode_cb (GtkAction *action, GtkRadioAction *current, gpointer data);
158 static void view_source_cb (GtkAction *action,
159 gpointer data);
161 static void show_all_header_cb (GtkToggleAction *action,
162 gpointer data);
163 static void msg_hide_quotes_cb (GtkToggleAction *action,
164 gpointer data);
166 static void compose_cb (GtkAction *action,
167 gpointer data);
168 static void reply_cb (GtkAction *action,
169 gpointer data);
171 static PrefsAccount *select_account_from_list
172 (GList *ac_list,
173 gboolean has_accounts);
174 static void addressbook_open_cb (GtkAction *action,
175 gpointer data);
176 static void add_address_cb (GtkAction *action,
177 gpointer data);
178 static void create_filter_cb (GtkAction *action,
179 gpointer data);
180 static void create_processing_cb (GtkAction *action,
181 gpointer data);
182 static void open_urls_cb (GtkAction *action,
183 gpointer data);
185 static void about_cb (GtkAction *action,
186 gpointer data);
187 static void messageview_update (MessageView *msgview,
188 MsgInfo *old_msginfo);
189 static gboolean messageview_update_msg (gpointer source, gpointer data);
191 static void save_part_as_cb(GtkAction *action, gpointer data);
192 static void view_part_as_text_cb(GtkAction *action, gpointer data);
193 static void open_part_cb(GtkAction *action, gpointer data);
194 #ifndef G_OS_WIN32
195 static void open_part_with_cb(GtkAction *action, gpointer data);
196 #endif
197 static void check_signature_cb(GtkAction *action, gpointer data);
198 static void goto_next_part_cb(GtkAction *action, gpointer data);
199 static void goto_prev_part_cb(GtkAction *action, gpointer data);
201 static void messageview_nothing_cb (GtkAction *action, gpointer data)
206 static GList *msgview_list = NULL;
207 static GtkActionEntry msgview_entries[] =
209 {"Menu", NULL, "Menu", NULL, NULL, NULL },
210 /* menus */
211 {"File", NULL, N_("_File"), NULL, NULL, NULL },
212 {"Edit", NULL, N_("_Edit"), NULL, NULL, NULL },
213 {"View", NULL, N_("_View"), NULL, NULL, NULL },
214 {"Message", NULL, N_("_Message"), NULL, NULL, NULL },
215 {"Tools", NULL, N_("_Tools"), NULL, NULL, NULL },
216 {"Help", NULL, N_("_Help"), NULL, NULL, NULL },
217 {"PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(messageview_nothing_cb) },
219 /* File menu */
220 {"File/SaveAs", NULL, N_("_Save email as..."), "<control>S", NULL, G_CALLBACK(save_as_cb) },
221 {"File/SavePartAs", NULL, N_("_Save part as..."), "Y", NULL, G_CALLBACK(save_part_as_cb) },
222 {"File/PageSetup", NULL, N_("Page setup..."), NULL, NULL, G_CALLBACK(page_setup_cb) },
223 {"File/Print", NULL, N_("_Print..."), "<control>P", NULL, G_CALLBACK(print_cb) },
224 {"File/---", NULL, "---", NULL, NULL, NULL },
225 {"File/Close", NULL, N_("_Close"), "<control>W", NULL, G_CALLBACK(close_cb) },
227 /* Edit menu */
228 {"Edit/Copy", NULL, N_("_Copy"), "<control>C", NULL, G_CALLBACK(copy_cb) },
229 {"Edit/SelectAll", NULL, N_("_Select all"), "<control>A", NULL, G_CALLBACK(allsel_cb) },
230 {"Edit/---", NULL, "---", NULL, NULL, NULL },
231 {"Edit/Find", NULL, N_("_Find"), "<control>F", NULL, G_CALLBACK(search_cb) },
233 /* View menu */
234 {"View/Goto", NULL, N_("_Go to"), NULL, NULL, NULL },
235 {"View/Goto/Prev", NULL, N_("_Previous message"), "P", NULL, G_CALLBACK(prev_cb) },
236 {"View/Goto/Next", NULL, N_("_Next message"), "N", NULL, G_CALLBACK(next_cb) },
237 {"View/Goto/---", NULL, "---", NULL, NULL, NULL },
238 {"View/Goto/PrevUnread", NULL, N_("P_revious unread message"), "<shift>P", NULL, G_CALLBACK(prev_unread_cb) },
239 {"View/Goto/NextUnread", NULL, N_("N_ext unread message"), "<shift>N", NULL, G_CALLBACK(next_unread_cb) },
240 /* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
241 {"View/Goto/PrevNew", NULL, N_("Previous ne_w message"), NULL, NULL, G_CALLBACK(prev_new_cb) },
242 {"View/Goto/NextNew", NULL, N_("Ne_xt new message"), NULL, NULL, G_CALLBACK(next_new_cb) },
243 /* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
244 {"View/Goto/PrevMarked", NULL, N_("Previous _marked message"), NULL, NULL, G_CALLBACK(prev_marked_cb) },
245 {"View/Goto/NextMarked", NULL, N_("Next m_arked message"), NULL, NULL, G_CALLBACK(next_marked_cb) },
246 /* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
247 {"View/Goto/PrevLabeled", NULL, N_("Previous _labeled message"), NULL, NULL, G_CALLBACK(prev_labeled_cb) },
248 {"View/Goto/NextLabeled", NULL, N_("Next la_beled message"), NULL, NULL, G_CALLBACK(next_labeled_cb) },
249 /* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
250 {"View/Goto/PrevHistory", NULL, N_("Previous opened message"), "<alt>Left", NULL, G_CALLBACK(prev_history_cb) },
251 {"View/Goto/NextHistory", NULL, N_("Next opened message"), "<alt>Right", NULL, G_CALLBACK(next_history_cb) },
252 /* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
253 {"View/Goto/ParentMessage", NULL, N_("Parent message"), "<control>Up", NULL, G_CALLBACK(parent_cb) },
254 /* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
255 {"View/Goto/NextUnreadFolder", NULL, N_("Next unread _folder"), "<shift>G", NULL, G_CALLBACK(goto_unread_folder_cb) },
256 {"View/Goto/Folder", NULL, N_("F_older..."), "G", NULL, G_CALLBACK(goto_folder_cb) },
257 /* {"View/Goto/---", NULL, "---", NULL, NULL, NULL }, */
258 {"View/Goto/NextPart", NULL, N_("Next part"), "A", NULL, G_CALLBACK(goto_next_part_cb) },
259 {"View/Goto/PrevPart", NULL, N_("Previous part"), "Z", NULL, G_CALLBACK(goto_prev_part_cb) },
260 {"View/Scroll", NULL, N_("Message scroll"), NULL, NULL, NULL },
261 {"View/Scroll/PrevLine", NULL, N_("Previous line"), NULL, NULL, G_CALLBACK(scroll_prev_line_cb) },
262 {"View/Scroll/NextLine", NULL, N_("Next line"), NULL, NULL, G_CALLBACK(scroll_next_line_cb) },
263 {"View/Scroll/PrevPage", NULL, N_("Previous page"), NULL, NULL, G_CALLBACK(scroll_prev_page_cb) },
264 {"View/Scroll/NextPage", NULL, N_("Next page"), NULL, NULL, G_CALLBACK(scroll_next_page_cb) },
265 /* {"View/Scroll/---", NULL, "---", NULL, NULL, NULL }, */
267 {"View/Encoding", NULL, N_("Character _encoding"), NULL, NULL, NULL }, /* set_charset_cb */
268 {"View/Encoding/---", NULL, "---", NULL, NULL, NULL },
269 #define ENC_ACTION(cs_char,c_char,string) \
270 { "View/Encoding/" cs_char, NULL, N_(string), NULL, NULL, c_char }
272 {"View/Encoding/Western", NULL, N_("Western European"), NULL, NULL, NULL },
273 {"View/Encoding/Baltic", NULL, N_("Baltic"), NULL, NULL, NULL },
274 {"View/Encoding/Hebrew", NULL, N_("Hebrew"), NULL, NULL, NULL },
275 {"View/Encoding/Arabic", NULL, N_("Arabic"), NULL, NULL, NULL },
276 {"View/Encoding/Cyrillic", NULL, N_("Cyrillic"), NULL, NULL, NULL },
277 {"View/Encoding/Japanese", NULL, N_("Japanese"), NULL, NULL, NULL },
278 {"View/Encoding/Chinese", NULL, N_("Chinese"), NULL, NULL, NULL },
279 {"View/Encoding/Korean", NULL, N_("Korean"), NULL, NULL, NULL },
280 {"View/Encoding/Thai", NULL, N_("Thai"), NULL, NULL, NULL },
282 {"View/Decode", NULL, N_("Decode"), NULL, NULL, NULL }, /* set_decode_cb */
283 {"View/Decode/---", NULL, "---", NULL, NULL, NULL },
285 #define DEC_ACTION(cs_type,c_type,string) \
286 { "View/Decode/" cs_type, NULL, N_(string), NULL, NULL, c_type }
288 {"View/---", NULL, "---", NULL, NULL, NULL },
289 {"View/MessageSource", NULL, N_("Mess_age source"), "<control>U", NULL, G_CALLBACK(view_source_cb) },
290 {"View/Part", NULL, N_("Message part"), NULL, NULL, NULL },
291 {"View/Part/AsText", NULL, N_("View as text"), "T", NULL, G_CALLBACK(view_part_as_text_cb) },
292 {"View/Part/Open", NULL, N_("Open"), "L", NULL, G_CALLBACK(open_part_cb) },
293 #ifndef G_OS_WIN32
294 {"View/Part/OpenWith", NULL, N_("Open with..."), "O", NULL, G_CALLBACK(open_part_with_cb) },
295 #endif
297 {"View/Quotes", NULL, N_("Quotes"), NULL, NULL, NULL },
299 /* Message menu */
300 {"Message/Compose", NULL, N_("Compose _new message"), "<control>M", NULL, G_CALLBACK(compose_cb) },
301 {"Message/---", NULL, "---", NULL, NULL, NULL },
303 {"Message/Reply", NULL, N_("_Reply"), "<control>R", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY */
304 {"Message/ReplyTo", NULL, N_("Repl_y to"), NULL, NULL, NULL },
305 {"Message/ReplyTo/All", NULL, N_("_All"), "<control><shift>R", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY_TO_ALL */
306 {"Message/ReplyTo/Sender", NULL, N_("_Sender"), NULL, NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY_TO_SENDER */
307 {"Message/ReplyTo/List", NULL, N_("Mailing _list"), "<control>L", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REPLY_TO_LIST */
308 /* {"Message/---", NULL, "---", NULL, NULL, NULL }, */
310 {"Message/Forward", NULL, N_("_Forward"), "<control><alt>F", NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_FORWARD_INLINE */
311 {"Message/ForwardAtt", NULL, N_("For_ward as attachment"), NULL, NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_FORWARD_AS_ATTACH */
312 {"Message/Redirect", NULL, N_("Redirec_t"), NULL, NULL, G_CALLBACK(reply_cb) }, /* COMPOSE_REDIRECT */
313 {"Message/CheckSignature", NULL, N_("Check signature"), "C", NULL, G_CALLBACK(check_signature_cb) },
315 /* Tools menu */
316 {"Tools/AddressBook", NULL, N_("_Address book"), "<control><shift>A", NULL, G_CALLBACK(addressbook_open_cb) },
317 {"Tools/AddSenderToAB", NULL, N_("Add sender to address boo_k"), NULL, NULL, G_CALLBACK(add_address_cb) },
318 {"Tools/---", NULL, "---", NULL, NULL, NULL },
320 {"Tools/CreateFilterRule", NULL, N_("_Create filter rule"), NULL, NULL, NULL },
321 {"Tools/CreateFilterRule/Automatically", NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_AUTO */
322 {"Tools/CreateFilterRule/ByFrom", NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_FROM */
323 {"Tools/CreateFilterRule/ByTo", NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_TO */
324 {"Tools/CreateFilterRule/BySubject", NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_filter_cb) }, /* FILTER_BY_SUBJECT */
326 {"Tools/CreateProcessingRule", NULL, N_("Create processing rule"), NULL, NULL, NULL },
327 {"Tools/CreateProcessingRule/Automatically", NULL, N_("_Automatically"), NULL, NULL, G_CALLBACK(create_processing_cb) },
328 {"Tools/CreateProcessingRule/ByFrom", NULL, N_("By _From"), NULL, NULL, G_CALLBACK(create_processing_cb) },
329 {"Tools/CreateProcessingRule/ByTo", NULL, N_("By _To"), NULL, NULL, G_CALLBACK(create_processing_cb) },
330 {"Tools/CreateProcessingRule/BySubject", NULL, N_("By _Subject"), NULL, NULL, G_CALLBACK(create_processing_cb) },
331 /* {"Tools/---", NULL, "---", NULL, NULL, NULL }, */
333 {"Tools/ListUrls", NULL, N_("List _URLs..."), "<control><shift>U", NULL, G_CALLBACK(open_urls_cb) },
335 /* {"Tools/---", NULL, "---", NULL, NULL, NULL }, */
336 {"Tools/Actions", NULL, N_("Actio_ns"), NULL, NULL, NULL },
337 {"Tools/Actions/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(messageview_nothing_cb) },
339 /* Help menu */
340 {"Help/About", NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_cb) },
343 static GtkToggleActionEntry msgview_toggle_entries[] =
345 {"View/AllHeaders", NULL, N_("Show all _headers"), "<control>H", NULL, G_CALLBACK(show_all_header_cb), FALSE }, /* toggle */
346 {"View/Quotes/CollapseAll", NULL, N_("_Collapse all"), "<control><shift>Q", NULL, G_CALLBACK(msg_hide_quotes_cb), FALSE }, /* 1 toggle */
347 {"View/Quotes/Collapse2", NULL, N_("Collapse from level _2"), NULL, NULL, G_CALLBACK(msg_hide_quotes_cb), FALSE }, /* 2 toggle */
348 {"View/Quotes/Collapse3", NULL, N_("Collapse from level _3"), NULL, NULL, G_CALLBACK(msg_hide_quotes_cb), FALSE }, /* 3 toggle */
351 static GtkRadioActionEntry msgview_radio_enc_entries[] =
353 ENC_ACTION(CS_AUTO, C_AUTO, N_("_Automatic")), /* RADIO set_charset_cb */
354 ENC_ACTION(CS_US_ASCII, C_US_ASCII, N_("7bit ASCII (US-ASC_II)")), /* RADIO set_charset_cb */
355 ENC_ACTION(CS_UTF_8, C_UTF_8, N_("Unicode (_UTF-8)")), /* RADIO set_charset_cb */
356 ENC_ACTION("Western/"CS_ISO_8859_1, C_ISO_8859_1, "ISO-8859-_1"), /* RADIO set_charset_cb */
357 ENC_ACTION("Western/"CS_ISO_8859_15, C_ISO_8859_15, "ISO-8859-15"), /* RADIO set_charset_cb */
358 ENC_ACTION("Western/"CS_WINDOWS_1252, C_WINDOWS_1252, "Windows-1252"), /* RADIO set_charset_cb */
359 ENC_ACTION(CS_ISO_8859_2, C_ISO_8859_2, N_("Central European (ISO-8859-_2)")), /* RADIO set_charset_cb */
360 ENC_ACTION("Baltic/"CS_ISO_8859_13, C_ISO_8859_13, "ISO-8859-13"), /* RADIO set_charset_cb */
361 ENC_ACTION("Baltic/"CS_ISO_8859_4, C_ISO_8859_14, "ISO-8859-_4"), /* RADIO set_charset_cb */
362 ENC_ACTION(CS_ISO_8859_7, C_ISO_8859_7, N_("Greek (ISO-8859-_7)")), /* RADIO set_charset_cb */
363 ENC_ACTION("Hebrew/"CS_ISO_8859_8, C_ISO_8859_8, "ISO-8859-_8"), /* RADIO set_charset_cb */
364 ENC_ACTION("Hebrew/"CS_WINDOWS_1255, C_WINDOWS_1255, "Windows-1255"), /* RADIO set_charset_cb */
365 ENC_ACTION("Arabic/"CS_ISO_8859_6, C_ISO_8859_6, "ISO-8859-_6"), /* RADIO set_charset_cb */
366 ENC_ACTION("Arabic/"CS_WINDOWS_1256, C_WINDOWS_1256, "Windows-1256"), /* RADIO set_charset_cb */
367 ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO set_charset_cb */
368 ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO set_charset_cb */
369 ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO set_charset_cb */
370 ENC_ACTION("Cyrillic/"CS_MACCYR, C_MACCYR, "MAC_CYR"), /* RADIO set_charset_cb */
371 ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO set_charset_cb */
372 ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO set_charset_cb */
373 ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO set_charset_cb */
374 ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO set_charset_cb */
375 ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO set_charset_cb */
376 ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO set_charset_cb */
377 ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO set_charset_cb */
378 ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO set_charset_cb */
379 ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO set_charset_cb */
380 ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO set_charset_cb */
381 ENC_ACTION("Chinese/"CS_EUC_TW, C_EUC_TW, "EUC-_TW"), /* RADIO set_charset_cb */
382 ENC_ACTION("Korean/"CS_EUC_KR, C_EUC_KR, "_EUC-KR"), /* RADIO set_charset_cb */
383 ENC_ACTION("Korean/"CS_ISO_2022_KR, C_ISO_2022_KR, "_ISO-2022-KR"), /* RADIO set_charset_cb */
384 ENC_ACTION("Thai/"CS_TIS_620, C_TIS_620, "_TIS-620-KR"), /* RADIO set_charset_cb */
385 ENC_ACTION("Thai/"CS_WINDOWS_874, C_WINDOWS_874, "_Windows-874"), /* RADIO set_charset_cb */
388 static GtkRadioActionEntry msgview_radio_dec_entries[] =
390 DEC_ACTION("AutoDetect", 0, N_("_Auto detect")), /* set_decode_cb */
391 /* --- */
392 DEC_ACTION("8bit", ENC_8BIT, "_8bit"),
393 DEC_ACTION("QP", ENC_QUOTED_PRINTABLE, "_Quoted printable"),
394 DEC_ACTION("B64", ENC_BASE64, "_Base64"),
395 DEC_ACTION("Uuencode", ENC_X_UUENCODE, "_Uuencode"),
398 MessageView *messageview_create(MainWindow *mainwin)
400 MessageView *messageview;
401 GtkWidget *vbox;
402 HeaderView *headerview;
403 MimeView *mimeview;
404 NoticeView *noticeview;
406 debug_print("Creating message view...\n");
407 messageview = g_new0(MessageView, 1);
409 headerview = headerview_create();
411 noticeview = noticeview_create(mainwin);
413 mimeview = mimeview_create(mainwin);
414 mimeview->textview = textview_create();
415 mimeview->textview->messageview = messageview;
416 mimeview->messageview = messageview;
418 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
419 gtk_widget_set_name(GTK_WIDGET(vbox), "messageview");
420 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
421 FALSE, FALSE, 0);
422 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
423 FALSE, FALSE, 0);
424 gtk_box_pack_start(GTK_BOX(vbox),
425 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
426 gtk_widget_show(vbox);
428 messageview->vbox = vbox;
429 messageview->new_window = FALSE;
430 messageview->window = NULL;
431 messageview->headerview = headerview;
432 messageview->mimeview = mimeview;
433 messageview->noticeview = noticeview;
434 messageview->mainwin = mainwin;
436 messageview->statusbar = NULL;
437 messageview->statusbar_cid = 0;
439 messageview->show_full_text= FALSE;
440 messageview->update_needed = FALSE;
442 messageview->msginfo_update_callback_id =
443 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
445 return messageview;
448 const GList *messageview_get_msgview_list(void)
450 return msgview_list;
453 void messageview_update_actions_menu(MessageView *msgview)
455 /* Messages opened in a new window do not have a menu bar */
456 if (msgview->menubar == NULL)
457 return;
458 action_update_msgview_menu(msgview->ui_manager, "/Menu/Tools/Actions", msgview);
461 static void messageview_add_toolbar(MessageView *msgview, GtkWidget *window)
463 GtkWidget *handlebox;
464 GtkWidget *vbox;
465 GtkWidget *menubar;
466 #ifndef GENERIC_UMPC
467 GtkWidget *statusbar = NULL;
468 #endif
469 GtkActionGroup *action_group;
472 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
473 gtk_widget_show(vbox);
474 gtk_container_add(GTK_CONTAINER(window), vbox);
476 msgview->ui_manager = gtk_ui_manager_new();
477 action_group = cm_menu_create_action_group_full(msgview->ui_manager,"Menu", msgview_entries,
478 G_N_ELEMENTS(msgview_entries), (gpointer)msgview);
479 gtk_action_group_add_toggle_actions(action_group, msgview_toggle_entries,
480 G_N_ELEMENTS(msgview_toggle_entries), (gpointer)msgview);
481 gtk_action_group_add_radio_actions(action_group, msgview_radio_enc_entries,
482 G_N_ELEMENTS(msgview_radio_enc_entries), C_AUTO, G_CALLBACK(set_charset_cb), (gpointer)msgview);
483 gtk_action_group_add_radio_actions(action_group, msgview_radio_dec_entries,
484 G_N_ELEMENTS(msgview_radio_dec_entries), C_AUTO, G_CALLBACK(set_decode_cb), (gpointer)msgview);
486 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
487 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "File", "File", GTK_UI_MANAGER_MENU)
488 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
489 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "View", "View", GTK_UI_MANAGER_MENU)
490 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Message", "Message", GTK_UI_MANAGER_MENU)
491 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Tools", "Tools", GTK_UI_MANAGER_MENU)
492 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu", "Help", "Help", GTK_UI_MANAGER_MENU)
494 /* File menu */
495 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "SaveAs", "File/SaveAs", GTK_UI_MANAGER_MENUITEM)
496 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "SavePartAs", "File/SavePartAs", GTK_UI_MANAGER_MENUITEM)
497 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Separator1", "File/---", GTK_UI_MANAGER_SEPARATOR)
498 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "PageSetup", "File/PageSetup", GTK_UI_MANAGER_MENUITEM)
499 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Print", "File/Print", GTK_UI_MANAGER_MENUITEM)
500 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Separator2", "File/---", GTK_UI_MANAGER_SEPARATOR)
501 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/File", "Close", "File/Close", GTK_UI_MANAGER_MENUITEM)
503 /* Edit menu */
504 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "Copy", "Edit/Copy", GTK_UI_MANAGER_MENUITEM)
505 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "SelectAll", "Edit/SelectAll", GTK_UI_MANAGER_MENUITEM)
506 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "Separator1", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
507 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Edit", "Find", "Edit/Find", GTK_UI_MANAGER_MENUITEM)
509 /* View menu */
510 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Goto", "View/Goto", GTK_UI_MANAGER_MENU)
511 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Prev", "View/Goto/Prev", GTK_UI_MANAGER_MENUITEM)
512 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Next", "View/Goto/Next", GTK_UI_MANAGER_MENUITEM)
513 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator1", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
514 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevUnread", "View/Goto/PrevUnread", GTK_UI_MANAGER_MENUITEM)
515 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextUnread", "View/Goto/NextUnread", GTK_UI_MANAGER_MENUITEM)
516 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator2", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
517 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevNew", "View/Goto/PrevNew", GTK_UI_MANAGER_MENUITEM)
518 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextNew", "View/Goto/NextNew", GTK_UI_MANAGER_MENUITEM)
519 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator3", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
520 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevMarked", "View/Goto/PrevMarked", GTK_UI_MANAGER_MENUITEM)
521 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextMarked", "View/Goto/NextMarked", GTK_UI_MANAGER_MENUITEM)
522 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator4", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
523 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevLabeled", "View/Goto/PrevLabeled", GTK_UI_MANAGER_MENUITEM)
524 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextLabeled", "View/Goto/NextLabeled", GTK_UI_MANAGER_MENUITEM)
525 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator5", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
526 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevHistory", "View/Goto/PrevHistory", GTK_UI_MANAGER_MENUITEM)
527 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextHistory", "View/Goto/NextHistory", GTK_UI_MANAGER_MENUITEM)
528 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator6", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
529 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "ParentMessage", "View/Goto/ParentMessage", GTK_UI_MANAGER_MENUITEM)
530 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator7", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
531 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextUnreadFolder", "View/Goto/NextUnreadFolder", GTK_UI_MANAGER_MENUITEM)
532 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Folder", "View/Goto/Folder", GTK_UI_MANAGER_MENUITEM)
533 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "Separator8", "View/Goto/---", GTK_UI_MANAGER_SEPARATOR)
534 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "NextPart", "View/Goto/NextPart", GTK_UI_MANAGER_MENUITEM)
535 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Goto", "PrevPart", "View/Goto/PrevPart", GTK_UI_MANAGER_MENUITEM)
537 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Scroll", "View/Scroll", GTK_UI_MANAGER_MENU)
538 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "PrevLine", "View/Scroll/PrevLine", GTK_UI_MANAGER_MENUITEM)
539 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "NextLine", "View/Scroll/NextLine", GTK_UI_MANAGER_MENUITEM)
540 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "PrevPage", "View/Scroll/PrevPage", GTK_UI_MANAGER_MENUITEM)
541 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Scroll", "NextPage", "View/Scroll/NextPage", GTK_UI_MANAGER_MENUITEM)
543 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Separator1", "View/---", GTK_UI_MANAGER_SEPARATOR)
545 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Encoding", "View/Encoding", GTK_UI_MANAGER_MENU)
546 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_AUTO, "View/Encoding/"CS_AUTO, GTK_UI_MANAGER_MENUITEM)
547 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Separator1", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
548 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_US_ASCII, "View/Encoding/"CS_US_ASCII, GTK_UI_MANAGER_MENUITEM)
549 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_UTF_8, "View/Encoding/"CS_UTF_8, GTK_UI_MANAGER_MENUITEM)
550 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Separator2", "View/Encoding/---", GTK_UI_MANAGER_SEPARATOR)
552 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Western", "View/Encoding/Western", GTK_UI_MANAGER_MENU)
553 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)
554 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)
555 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Western", CS_WINDOWS_1252, "View/Encoding/Western/"CS_WINDOWS_1252, GTK_UI_MANAGER_MENUITEM)
557 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_2, "View/Encoding/"CS_ISO_8859_2, GTK_UI_MANAGER_MENUITEM)
559 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Baltic", "View/Encoding/Baltic", GTK_UI_MANAGER_MENU)
560 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)
561 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)
563 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_7, "View/Encoding/"CS_ISO_8859_7, GTK_UI_MANAGER_MENUITEM)
565 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Hebrew", "View/Encoding/Hebrew", GTK_UI_MANAGER_MENU)
566 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)
567 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Hebrew", CS_WINDOWS_1255, "View/Encoding/Hebrew/"CS_WINDOWS_1255, GTK_UI_MANAGER_MENUITEM)
569 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Arabic", "View/Encoding/Arabic", GTK_UI_MANAGER_MENU)
570 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)
571 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Arabic", CS_WINDOWS_1256, "View/Encoding/Arabic/"CS_WINDOWS_1256, GTK_UI_MANAGER_MENUITEM)
573 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", CS_ISO_8859_9, "View/Encoding/"CS_ISO_8859_9, GTK_UI_MANAGER_MENUITEM)
575 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Cyrillic", "View/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
576 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)
577 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_R, "View/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
578 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_MACCYR, "View/Encoding/Cyrillic/"CS_MACCYR, GTK_UI_MANAGER_MENUITEM)
579 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_KOI8_U, "View/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
580 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Cyrillic", CS_WINDOWS_1251, "View/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
582 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Japanese", "View/Encoding/Japanese", GTK_UI_MANAGER_MENU)
583 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)
584 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)
585 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_EUC_JP, "View/Encoding/Japanese/"CS_EUC_JP, GTK_UI_MANAGER_MENUITEM)
586 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Japanese", CS_SHIFT_JIS, "View/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
588 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Chinese", "View/Encoding/Chinese", GTK_UI_MANAGER_MENU)
589 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB18030, "View/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
590 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GB2312, "View/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
591 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_GBK, "View/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
592 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_BIG5, "View/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
593 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Chinese", CS_EUC_TW, "View/Encoding/Chinese/"CS_EUC_TW, GTK_UI_MANAGER_MENUITEM)
595 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Korean", "View/Encoding/Korean", GTK_UI_MANAGER_MENU)
596 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Korean", CS_EUC_KR, "View/Encoding/Korean/"CS_EUC_KR, GTK_UI_MANAGER_MENUITEM)
597 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)
599 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding", "Thai", "View/Encoding/Thai", GTK_UI_MANAGER_MENU)
600 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Thai", CS_TIS_620, "View/Encoding/Thai/"CS_TIS_620, GTK_UI_MANAGER_MENUITEM)
601 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Encoding/Thai", CS_WINDOWS_874, "View/Encoding/Thai/"CS_WINDOWS_874, GTK_UI_MANAGER_MENUITEM)
603 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Decode", "View/Decode", GTK_UI_MANAGER_MENU)
604 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "AutoDetect", "View/Decode/AutoDetect", GTK_UI_MANAGER_MENUITEM)
605 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "Separator1", "View/Decode/---", GTK_UI_MANAGER_SEPARATOR)
606 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "8bit", "View/Decode/8bit", GTK_UI_MANAGER_MENUITEM)
607 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "QP", "View/Decode/QP", GTK_UI_MANAGER_MENUITEM)
608 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "B64", "View/Decode/B64", GTK_UI_MANAGER_MENUITEM)
609 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Decode", "Uuencode", "View/Decode/Uuencode", GTK_UI_MANAGER_MENUITEM)
611 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Separator2", "View/---", GTK_UI_MANAGER_SEPARATOR)
613 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "MessageSource", "View/MessageSource", GTK_UI_MANAGER_MENUITEM)
614 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "AllHeaders", "View/AllHeaders", GTK_UI_MANAGER_MENUITEM)
615 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Quotes", "View/Quotes", GTK_UI_MANAGER_MENU)
616 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Quotes", "CollapseAll", "View/Quotes/CollapseAll", GTK_UI_MANAGER_MENUITEM)
617 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Quotes", "Collapse2", "View/Quotes/Collapse2", GTK_UI_MANAGER_MENUITEM)
618 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Quotes", "Collapse3", "View/Quotes/Collapse3", GTK_UI_MANAGER_MENUITEM)
619 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View", "Part", "View/Part", GTK_UI_MANAGER_MENU)
620 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Part", "AsText", "View/Part/AsText", GTK_UI_MANAGER_MENUITEM)
621 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Part", "Open", "View/Part/Open", GTK_UI_MANAGER_MENUITEM)
622 #ifndef G_OS_WIN32
623 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/View/Part", "OpenWith", "View/Part/OpenWith", GTK_UI_MANAGER_MENUITEM)
624 #endif
626 /* Message menu */
627 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Compose", "Message/Compose", GTK_UI_MANAGER_MENUITEM)
628 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Separator1", "Message/---", GTK_UI_MANAGER_SEPARATOR)
629 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Reply", "Message/Reply", GTK_UI_MANAGER_MENUITEM)
630 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "ReplyTo", "Message/ReplyTo", GTK_UI_MANAGER_MENU)
631 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message/ReplyTo", "All", "Message/ReplyTo/All", GTK_UI_MANAGER_MENUITEM)
632 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message/ReplyTo", "Sender", "Message/ReplyTo/Sender", GTK_UI_MANAGER_MENUITEM)
633 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message/ReplyTo", "List", "Message/ReplyTo/List", GTK_UI_MANAGER_MENUITEM)
634 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
635 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Forward", "Message/Forward", GTK_UI_MANAGER_MENUITEM)
636 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "ForwardAtt", "Message/ForwardAtt", GTK_UI_MANAGER_MENUITEM)
637 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "Redirect", "Message/Redirect", GTK_UI_MANAGER_MENUITEM)
638 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Message", "CheckSignature", "Message/CheckSignature", GTK_UI_MANAGER_MENUITEM)
640 /* Tools menu */
641 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "AddressBook", "Tools/AddressBook", GTK_UI_MANAGER_MENUITEM)
642 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "AddSenderToAB", "Tools/AddSenderToAB", GTK_UI_MANAGER_MENUITEM)
643 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Separator1", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
645 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "CreateFilterRule", "Tools/CreateFilterRule", GTK_UI_MANAGER_MENU)
646 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "Automatically", "Tools/CreateFilterRule/Automatically", GTK_UI_MANAGER_MENUITEM)
647 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "ByFrom", "Tools/CreateFilterRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
648 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "ByTo", "Tools/CreateFilterRule/ByTo", GTK_UI_MANAGER_MENUITEM)
649 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateFilterRule", "BySubject", "Tools/CreateFilterRule/BySubject", GTK_UI_MANAGER_MENUITEM)
651 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "CreateProcessingRule", "Tools/CreateProcessingRule", GTK_UI_MANAGER_MENU)
652 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "Automatically", "Tools/CreateProcessingRule/Automatically", GTK_UI_MANAGER_MENUITEM)
653 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByFrom", "Tools/CreateProcessingRule/ByFrom", GTK_UI_MANAGER_MENUITEM)
654 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "ByTo", "Tools/CreateProcessingRule/ByTo", GTK_UI_MANAGER_MENUITEM)
655 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/CreateProcessingRule", "BySubject", "Tools/CreateProcessingRule/BySubject", GTK_UI_MANAGER_MENUITEM)
656 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Separator2", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
658 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "ListUrls", "Tools/ListUrls", GTK_UI_MANAGER_MENUITEM)
659 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Separator3", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
661 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools", "Actions", "Tools/Actions", GTK_UI_MANAGER_MENU)
662 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Tools/Actions", "PlaceHolder", "Tools/Actions/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
664 /* Help menu */
665 MENUITEM_ADDUI_MANAGER(msgview->ui_manager, "/Menu/Help", "About", "Help/About", GTK_UI_MANAGER_MENUITEM)
667 menubar = gtk_ui_manager_get_widget(msgview->ui_manager, "/Menu");
668 gtk_widget_show_all(menubar);
669 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(msgview->ui_manager));
671 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
673 cm_toggle_menu_set_active_full(msgview->ui_manager, "Menu/View/AllHeaders",
674 prefs_common.show_all_headers);
676 handlebox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
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
694 msgview->handlebox = handlebox;
695 msgview->menubar = menubar;
697 gtk_container_add(GTK_CONTAINER(vbox),
698 GTK_WIDGET_PTR(msgview));
700 messageview_update_actions_menu(msgview);
702 msgview_list = g_list_append(msgview_list, msgview);
705 static MessageView *messageview_create_with_new_window_visible(MainWindow *mainwin, gboolean show)
707 MessageView *msgview;
708 GtkWidget *window;
709 static GdkGeometry geometry;
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);
715 gtk_window_set_default_size(GTK_WINDOW(window), prefs_common.msgwin_width,
716 prefs_common.msgwin_height);
718 if (!geometry.min_height) {
719 geometry.min_width = 320;
720 geometry.min_height = 200;
722 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
723 GDK_HINT_MIN_SIZE);
725 #ifdef G_OS_WIN32
726 gtk_window_move(GTK_WINDOW(window), 48, 48);
727 #endif
729 msgview = messageview_create(mainwin);
731 g_signal_connect(G_OBJECT(window), "size_allocate",
732 G_CALLBACK(messageview_size_allocate_cb),
733 msgview);
734 g_signal_connect(G_OBJECT(window), "delete_event",
735 G_CALLBACK(messageview_delete_cb), msgview);
736 g_signal_connect(G_OBJECT(window), "key_press_event",
737 G_CALLBACK(key_pressed), msgview);
738 messageview_add_toolbar(msgview, window);
740 if (show) {
741 gtk_widget_show(window);
742 } else {
743 gtk_widget_realize(window);
746 msgview->new_window = TRUE;
747 msgview->window = window;
748 msgview->visible = TRUE;
750 toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox,
751 prefs_common.toolbar_style);
752 messageview_init(msgview);
754 if (show) {
755 GTK_EVENTS_FLUSH();
756 gtk_widget_grab_focus(msgview->mimeview->textview->text);
759 return msgview;
762 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
764 return messageview_create_with_new_window_visible(mainwin, TRUE);
766 void messageview_init(MessageView *messageview)
768 headerview_init(messageview->headerview);
769 mimeview_init(messageview->mimeview);
770 /*messageview_set_font(messageview);*/
772 noticeview_hide(messageview->noticeview);
775 static void notification_convert_header(gchar **dest,
776 const gchar *src_,
777 gint header_len)
779 char *src;
781 cm_return_if_fail(src_ != NULL);
783 if (header_len < 1) {
784 *dest = g_strdup("");
785 return;
788 Xstrndup_a(src, src_, strlen(src_), return);
790 remove_return(src);
792 if (is_ascii_str(src)) {
793 *dest = g_strdup(src);
794 return;
795 } else {
796 *dest = g_malloc(BUFFSIZE);
797 conv_encode_header(*dest, BUFFSIZE, src, header_len, FALSE);
801 static gint disposition_notification_send(MsgInfo *msginfo)
803 gchar *buf = NULL;
804 gchar tmp[MAXPATHLEN + 1];
805 FILE *fp;
806 GList *ac_list;
807 PrefsAccount *account = NULL;
808 gint ok;
809 gchar *to;
810 FolderItem *queue, *outbox;
811 gint num;
812 gchar *path;
813 gchar *addr;
814 gchar *addrp;
815 gchar *foo = NULL;
816 gboolean queued_removed = FALSE;
817 gchar *boundary = NULL;
818 gchar buf_date[RFC822_DATE_BUFFSIZE];
819 gchar *date = NULL;
820 gchar *orig_to = NULL;
821 gchar *enc_sub = NULL;
823 if (!msginfo->extradata)
824 return -1;
825 if (!msginfo->extradata->returnreceiptto &&
826 !msginfo->extradata->dispositionnotificationto)
827 return -1;
829 /* RFC2298: Test for Return-Path */
830 if (msginfo->extradata->dispositionnotificationto)
831 to = msginfo->extradata->dispositionnotificationto;
832 else
833 to = msginfo->extradata->returnreceiptto;
835 ok = procheader_get_header_from_msginfo(msginfo, &buf, "Return-Path:");
836 if (ok == 0) {
837 gchar *to_addr = g_strdup(to);
838 extract_address(to_addr);
839 extract_address(buf);
840 ok = strcasecmp(to_addr, buf);
841 g_free(to_addr);
842 } else {
843 buf = g_strdup(_("<No Return-Path found>"));
846 if (ok != 0) {
847 AlertValue val;
848 gchar *message;
849 message = g_markup_printf_escaped(
850 _("The notification address to which the return receipt is\n"
851 "to be sent does not correspond to the return path:\n"
852 "Notification address: %s\n"
853 "Return path: %s\n"
854 "It is advised to not send the return receipt."),
855 to, buf);
856 val = alertpanel_full(_("Warning"), message,
857 _("_Don't Send"), _("_Send"), NULL, ALERTFOCUS_FIRST, FALSE,
858 NULL, ALERT_WARNING);
859 g_free(message);
860 if (val != G_ALERTALTERNATE) {
861 g_free(buf);
862 return -1;
865 g_free(buf);
866 buf = NULL;
868 ac_list = account_find_all_from_address(NULL, msginfo->to);
869 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
871 if (ac_list == NULL) {
872 ac_list = account_find_all();
873 if ((account = select_account_from_list(ac_list, FALSE)) == NULL)
874 return -1;
875 } else if (g_list_length(ac_list) > 1) {
876 if ((account = select_account_from_list(ac_list, TRUE)) == NULL)
877 return -1;
878 } else if (ac_list != NULL)
879 account = (PrefsAccount *) ac_list->data;
880 g_list_free(ac_list);
882 if (account == NULL)
883 account = account_get_default();
884 if (!account || account->protocol == A_NNTP) {
885 alertpanel_error(_("Account for sending mail is not specified.\n"
886 "Please select a mail account before sending."));
887 return -1;
890 /* write to temporary file */
891 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%p",
892 get_rc_dir(), G_DIR_SEPARATOR, msginfo);
894 if ((fp = claws_fopen(tmp, "wb")) == NULL) {
895 FILE_OP_ERROR(tmp, "claws_fopen");
896 return -1;
899 /* chmod for security */
900 if (change_file_mode_rw(fp, tmp) < 0) {
901 FILE_OP_ERROR(tmp, "chmod");
902 g_warning("can't change file mode");
905 addr = g_strdup(to);
907 extract_address(addr);
908 addrp = addr;
910 /* write queue headers */
911 ok = fprintf(fp, "AF:\n"
912 "NF:0\n"
913 "PS:10\n"
914 "SRH:1\n"
915 "SFN:\n"
916 "DSR:\n"
917 "MID:\n"
918 "CFG:\n"
919 "PT:0\n"
920 "S:%s\n"
921 "RQ:\n"
922 "SSV:%s\n"
923 "SSH:\n"
924 "R:<%s>\n",
925 account->address,
926 account->smtp_server?account->smtp_server:"",
927 addrp);
929 g_free(addrp);
930 if (ok < 0)
931 goto FILE_ERROR;
933 /* check whether we need to save the message */
934 outbox = account_get_special_folder(account, F_OUTBOX);
935 if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
936 outbox = NULL;
937 if (outbox) {
938 path = folder_item_get_identifier(outbox);
939 ok = fprintf(fp, "SCF:%s\n", path);
940 g_free(path);
942 if (ok < 0)
943 goto FILE_ERROR;
946 if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0)
947 goto FILE_ERROR;
949 /* Date */
950 get_rfc822_date(buf_date, sizeof(buf_date));
951 if (fprintf(fp, "Date: %s\n", buf_date) < 0)
952 goto FILE_ERROR;
954 /* From */
955 if (account->name && *account->name) {
956 notification_convert_header(&buf, account->name, strlen("From: "));
957 if (buf == NULL)
958 goto FILE_ERROR;
959 if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0) {
960 g_free(buf);
961 goto FILE_ERROR;
963 g_free(buf);
964 buf = NULL;
965 } else
966 goto FILE_ERROR;
968 if (fprintf(fp, "To: %s\n", to) < 0)
969 goto FILE_ERROR;
971 /* Subject */
972 notification_convert_header(&buf, msginfo->subject, strlen("Subject: "));
973 if (buf == NULL)
974 goto FILE_ERROR;
975 if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0) {
976 g_free(buf);
977 goto FILE_ERROR;
979 g_free(buf);
980 buf = NULL;
982 /* Message ID */
983 if (account->gen_msgid) {
984 gchar *addr = prefs_account_generate_msgid(account);
985 if (fprintf(fp, "Message-ID: <%s>\n", addr) < 0) {
986 g_free(addr);
987 goto FILE_ERROR;
989 g_free(addr);
992 boundary = generate_mime_boundary("DN");
993 date = g_strdup(buf_date);
994 if (msginfo->to) {
995 orig_to = g_strdup(msginfo->to);
996 extract_address(orig_to);
998 if (msginfo->subject && *(msginfo->subject)) {
999 enc_sub = g_malloc0(strlen(msginfo->subject)*8);
1000 qp_encode_line(enc_sub, (const guchar *)msginfo->subject);
1001 g_strstrip(enc_sub);
1003 ok = fprintf(fp,"MIME-Version: 1.0\n"
1004 "Content-Type: multipart/report; report-type=disposition-notification;\n"
1005 " boundary=\"%s\"\n"
1006 "\n"
1007 "--%s\n"
1008 "Content-Type: text/plain; charset=UTF-8\n"
1009 "Content-Transfer-Encoding: quoted-printable\n"
1010 "\n"
1011 "The message sent on: %s\n"
1012 "To: %s\n"
1013 "With subject: \"%s\"\n"
1014 "has been displayed at %s.\n"
1015 "\n"
1016 "There is no guarantee that the message has been read or understood.\n"
1017 "\n"
1018 "--%s\n"
1019 "Content-Type: message/disposition-notification\n"
1020 "\n"
1021 "Reporting-UA: %s\n"
1022 "Original-Recipient: rfc822;%s\n"
1023 "Final-Recipient: rfc822;%s\n"
1024 "Original-Message-ID: <%s>\n"
1025 "Disposition: manual-action/MDN-sent-manually; displayed\n"
1026 "\n"
1027 "--%s\n"
1028 "Content-Type: application/octet-stream\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 boundary,
1038 boundary,
1039 msginfo->date,
1040 orig_to?orig_to:"No To:",
1041 enc_sub?enc_sub:"No subject",
1042 date,
1043 boundary,
1044 PROG_VERSION,
1045 orig_to?orig_to:"No To:",
1046 account->address,
1047 msginfo->msgid?msginfo->msgid:"NO MESSAGE ID",
1048 boundary,
1049 PROG_VERSION,
1050 orig_to?orig_to:"No To:",
1051 account->address,
1052 msginfo->msgid?msginfo->msgid:"NO MESSAGE ID",
1053 boundary);
1055 g_free(enc_sub);
1056 g_free(orig_to);
1057 g_free(date);
1058 g_free(boundary);
1060 if (ok < 0)
1061 goto FILE_ERROR;
1063 if (claws_safe_fclose(fp) == EOF) {
1064 FILE_OP_ERROR(tmp, "claws_fclose");
1065 claws_unlink(tmp);
1066 return -1;
1069 /* put it in queue */
1070 queue = account_get_special_folder(account, F_QUEUE);
1071 if (!queue) queue = folder_get_default_queue();
1072 if (!queue) {
1073 g_warning("can't find queue folder");
1074 claws_unlink(tmp);
1075 return -1;
1077 folder_item_scan(queue);
1078 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
1079 g_warning("can't queue the message");
1080 claws_unlink(tmp);
1081 return -1;
1084 if (prefs_common.work_offline &&
1085 !inc_offline_should_override(TRUE,
1086 _("Claws Mail needs network access in order "
1087 "to send this email.")))
1088 return 0;
1090 /* send it */
1091 path = folder_item_fetch_msg(queue, num);
1092 ok = procmsg_send_message_queue_with_lock(path, &foo, queue, num, &queued_removed);
1093 g_free(path);
1094 g_free(foo);
1095 if (ok == 0 && !queued_removed)
1096 folder_item_remove_msg(queue, num);
1098 return ok;
1100 FILE_ERROR:
1101 claws_fclose(fp);
1102 claws_unlink(tmp);
1103 return -1;
1106 static gboolean find_encrypted_func(GNode *node, gpointer data)
1108 MimeInfo *mimeinfo = (MimeInfo *) node->data;
1109 MimeInfo **encinfo = (MimeInfo **) data;
1111 if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
1112 *encinfo = mimeinfo;
1113 return TRUE;
1116 return FALSE;
1119 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
1121 MimeInfo *encinfo = NULL;
1123 g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
1124 find_encrypted_func, &encinfo);
1126 return encinfo;
1129 static gboolean find_broken_func(GNode *node, gpointer data)
1131 MimeInfo *mimeinfo = (MimeInfo *) node->data;
1132 MimeInfo **brokeninfo = (MimeInfo **) data;
1134 if (mimeinfo->broken) {
1135 *brokeninfo = mimeinfo;
1136 return TRUE;
1139 return FALSE;
1142 static MimeInfo *find_broken_part(MimeInfo *rootinfo)
1144 MimeInfo *brokeninfo = NULL;
1146 g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
1147 find_broken_func, &brokeninfo);
1149 return brokeninfo;
1152 static void messageview_register_nav(MessageView *messageview)
1154 gchar *id;
1155 gint pos = -1;
1156 GList *existing;
1158 cm_return_if_fail(messageview);
1159 cm_return_if_fail(messageview->msginfo);
1161 id = procmsg_msginfo_get_identifier(messageview->msginfo);
1162 existing = g_list_find_custom(messageview->trail, id, (GCompareFunc)g_strcmp0);
1164 if (existing != NULL)
1165 pos = g_list_position(messageview->trail, existing);
1166 else
1167 pos = -1;
1169 if (pos != -1) {
1170 messageview->trail_pos = pos;
1171 g_free(id);
1172 } else {
1173 /* Cut the end of the list */
1174 GList *end = g_list_nth(messageview->trail, messageview->trail_pos + 1);
1175 if (end) {
1176 if (end->prev) {
1177 end->prev->next = NULL;
1178 end->prev = NULL;
1179 list_free_strings_full(end);
1180 } else {
1181 list_free_strings_full(messageview->trail);
1182 messageview->trail = NULL;
1185 messageview->trail = g_list_append(messageview->trail, id);
1186 messageview->trail_pos = (gint)g_list_length(messageview->trail) - 1;
1188 /* Cut the beginning if needed */
1189 while (messageview->trail_pos > prefs_common.nav_history_length) {
1190 g_free(messageview->trail->data);
1191 messageview->trail = g_list_delete_link(messageview->trail,
1192 messageview->trail);
1193 messageview->trail_pos--;
1196 messageview_set_menu_sensitive(messageview);
1199 gboolean messageview_nav_has_prev(MessageView *messageview) {
1200 return messageview != NULL && messageview->trail != NULL
1201 && messageview->trail_pos > 0;
1204 gboolean messageview_nav_has_next(MessageView *messageview) {
1205 if (!messageview || !messageview->trail)
1206 return FALSE;
1208 return sc_g_list_bigger(messageview->trail, messageview->trail_pos + 1);
1211 MsgInfo *messageview_nav_get_prev(MessageView *messageview) {
1212 GList *item;
1213 MsgInfo *info;
1215 cm_return_val_if_fail(messageview, NULL);
1216 cm_return_val_if_fail(messageview->trail, NULL);
1218 do {
1219 if (!messageview_nav_has_prev(messageview))
1220 return NULL;
1222 item = g_list_nth(messageview->trail, messageview->trail_pos - 1);
1223 cm_return_val_if_fail(item != NULL, NULL);
1225 info = procmsg_get_msginfo_from_identifier((const gchar *)item->data);
1226 if (info != NULL)
1227 break;
1229 g_free(item->data);
1230 messageview->trail = g_list_delete_link(messageview->trail, item);
1231 if (messageview->trail_pos > 0)
1232 messageview->trail_pos--;
1233 } while (info == NULL);
1235 return info;
1238 MsgInfo *messageview_nav_get_next(MessageView *messageview) {
1239 GList *item;
1240 MsgInfo *info;
1242 cm_return_val_if_fail(messageview, NULL);
1243 cm_return_val_if_fail(messageview->trail, NULL);
1245 do {
1246 if (!messageview_nav_has_next(messageview))
1247 return NULL;
1249 item = g_list_nth(messageview->trail, messageview->trail_pos + 1);
1250 cm_return_val_if_fail(item != NULL, NULL);
1252 info = procmsg_get_msginfo_from_identifier((const gchar *)item->data);
1253 if (info != NULL)
1254 break;
1256 g_free(item->data);
1257 messageview->trail = g_list_delete_link(messageview->trail, item);
1258 } while (info == NULL);
1260 return info;
1263 static gboolean messageview_try_select_mimeinfo(MessageView *messageview, MsgInfo *msginfo, MimeInfo *mimeinfo)
1265 if (mimeinfo->type == MIMETYPE_TEXT) {
1266 if (!strcasecmp(mimeinfo->subtype, "calendar")
1267 && mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
1268 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1269 return TRUE;
1270 } else if (!strcasecmp(mimeinfo->subtype, "html")
1271 && mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT
1272 && ((msginfo->folder && msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS)
1273 || ((msginfo->folder && msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT)
1274 && prefs_common.promote_html_part))) {
1275 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1276 return TRUE;
1279 return FALSE;
1282 static void messageview_find_part_depth_first(MimeInfoSearch *context, MimeMediaType type, const gchar *subtype)
1284 MimeInfo * mimeinfo = context->current;
1286 if (!mimeinfo)
1287 return;
1289 debug_print("found part %d/%s\n", mimeinfo->type, mimeinfo->subtype);
1291 if (mimeinfo->type == type
1292 && !strcasecmp(mimeinfo->subtype, subtype)) {
1293 context->found = mimeinfo;
1294 } else if (mimeinfo->type == MIMETYPE_MULTIPART) {
1295 if (!strcasecmp(mimeinfo->subtype, "alternative")
1296 || !strcasecmp(mimeinfo->subtype, "related")) {
1297 context->found = procmime_mimeinfo_next(mimeinfo);
1298 while (context->found && context->found != context->parent) {
1299 if (context->found->type == type
1300 && !strcasecmp(context->found->subtype, subtype))
1301 break;
1302 context->found = procmime_mimeinfo_next(context->found);
1304 if (context->found == context->parent)
1305 context->found = NULL;
1307 if (!context->found
1308 && (!strcasecmp(mimeinfo->subtype, "related")
1309 || !strcasecmp(mimeinfo->subtype, "mixed"))) {
1310 context->parent = mimeinfo;
1311 context->current = procmime_mimeinfo_next(mimeinfo);
1312 messageview_find_part_depth_first(context, type, subtype);
1317 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
1318 gboolean all_headers)
1320 gchar *text = NULL;
1321 gchar *file;
1322 MimeInfo *mimeinfo, *encinfo, *root;
1323 gchar *subject = NULL;
1324 cm_return_val_if_fail(msginfo != NULL, -1);
1326 if (msginfo != messageview->msginfo)
1327 messageview->show_full_text = FALSE;
1329 if (messageview->mimeview->textview &&
1330 messageview->mimeview->textview->loading) {
1331 messageview->mimeview->textview->stop_loading = TRUE;
1332 return 0;
1335 if (messageview->toolbar)
1336 toolbar_set_learn_button
1337 (messageview->toolbar,
1338 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1339 else
1340 toolbar_set_learn_button
1341 (messageview->mainwin->toolbar,
1342 MSG_IS_SPAM(msginfo->flags)?LEARN_HAM:LEARN_SPAM);
1344 if (messageview->toolbar) {
1345 if (messageview->toolbar->learn_spam_btn) {
1346 gboolean can_learn = FALSE;
1347 if (procmsg_spam_can_learn() &&
1348 (msginfo->folder &&
1349 msginfo->folder->folder->klass->type != F_UNKNOWN &&
1350 msginfo->folder->folder->klass->type != F_NEWS))
1351 can_learn = TRUE;
1353 gtk_widget_set_sensitive(
1354 messageview->toolbar->learn_spam_btn,
1355 can_learn);
1359 noticeview_hide(messageview->noticeview);
1360 mimeview_clear(messageview->mimeview);
1361 messageview->updating = TRUE;
1363 if (msginfo->size > 1024*1024)
1364 statusbar_print_all(_("Fetching message (%s)..."),
1365 to_human_readable(msginfo->size));
1367 file = procmsg_get_message_file_path(msginfo);
1369 if (msginfo->size > 1024*1024)
1370 statusbar_pop_all();
1372 if (!file) {
1373 g_warning("can't get message file path.");
1374 textview_show_error(messageview->mimeview->textview);
1375 return -1;
1378 if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
1379 !folder_has_parent_of_type(msginfo->folder, F_DRAFT))
1380 mimeinfo = procmime_scan_file(file);
1381 else
1382 mimeinfo = procmime_scan_queue_file(file);
1384 messageview->updating = FALSE;
1386 if (messageview->deferred_destroy) {
1387 g_free(file);
1388 messageview_destroy(messageview);
1389 return 0;
1392 if (!mimeinfo) {
1393 textview_show_error(messageview->mimeview->textview);
1394 return -1;
1397 while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
1398 debug_print("decrypting message part\n");
1399 if (privacy_mimeinfo_decrypt(encinfo) < 0) {
1400 text = g_strdup_printf(_("Couldn't decrypt: %s"),
1401 privacy_get_error());
1402 noticeview_show(messageview->noticeview);
1403 noticeview_set_icon(messageview->noticeview,
1404 STOCK_PIXMAP_NOTICE_WARN);
1405 noticeview_set_text(messageview->noticeview, text);
1406 gtk_widget_hide(messageview->noticeview->button);
1407 gtk_widget_hide(messageview->noticeview->button2);
1408 g_free(text);
1409 break;
1413 if (messageview->msginfo != msginfo) {
1414 procmsg_msginfo_free(&(messageview->msginfo));
1415 messageview->msginfo = NULL;
1416 messageview_set_menu_sensitive(messageview);
1417 messageview->msginfo =
1418 procmsg_msginfo_get_full_info_from_file(msginfo, file);
1419 if (!messageview->msginfo)
1420 messageview->msginfo = procmsg_msginfo_copy(msginfo);
1421 } else {
1422 messageview->msginfo = NULL;
1423 messageview_set_menu_sensitive(messageview);
1424 messageview->msginfo = msginfo;
1426 if (prefs_common.display_header_pane)
1427 headerview_show(messageview->headerview, messageview->msginfo);
1429 messageview_register_nav(messageview);
1430 messageview_set_position(messageview, 0);
1432 if (messageview->window) {
1433 gtk_window_set_title(GTK_WINDOW(messageview->window),
1434 _("Claws Mail - Message View"));
1435 GTK_EVENTS_FLUSH();
1437 mimeview_show_message(messageview->mimeview, mimeinfo, file);
1439 #ifndef GENERIC_UMPC
1440 messageview_set_position(messageview, 0);
1441 #endif
1443 if (messageview->window && msginfo->subject) {
1444 subject = g_strdup(msginfo->subject);
1445 if (!g_utf8_validate(subject, -1, NULL)) {
1446 g_free(subject);
1447 subject = g_malloc(strlen(msginfo->subject)*2 +1);
1448 conv_localetodisp(subject, strlen(msginfo->subject)*2 +1,
1449 msginfo->subject);
1451 if (g_utf8_validate(subject, -1, NULL))
1452 gtk_window_set_title(GTK_WINDOW(messageview->window),
1453 subject);
1454 g_free(subject);
1457 if (msginfo->folder) {
1458 msginfo->folder->last_seen = msginfo->msgnum;
1461 main_create_mailing_list_menu(messageview->mainwin, messageview->msginfo);
1463 if (messageview->msginfo && messageview->msginfo->extradata
1464 && messageview->msginfo->extradata->partial_recv
1465 && !noticeview_is_visible(messageview->noticeview))
1466 partial_recv_show(messageview->noticeview,
1467 messageview->msginfo);
1468 else if (messageview->msginfo && messageview->msginfo->extradata &&
1469 (messageview->msginfo->extradata->dispositionnotificationto ||
1470 messageview->msginfo->extradata->returnreceiptto) &&
1471 !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags) &&
1472 !prefs_common.never_send_retrcpt &&
1473 !noticeview_is_visible(messageview->noticeview))
1474 return_receipt_show(messageview->noticeview,
1475 messageview->msginfo);
1477 if (find_broken_part(mimeinfo) != NULL) {
1478 noticeview_set_icon(messageview->noticeview,
1479 STOCK_PIXMAP_NOTICE_WARN);
1480 if (!noticeview_is_visible(messageview->noticeview)) {
1481 noticeview_set_text(messageview->noticeview, _("Message doesn't conform to MIME standard. "
1482 "It may render wrongly."));
1483 gtk_widget_hide(messageview->noticeview->button);
1484 gtk_widget_hide(messageview->noticeview->button2);
1485 } else {
1486 gchar *full = g_strconcat(
1487 gtk_label_get_text(GTK_LABEL(messageview->noticeview->text)),
1488 "\n",
1489 _("Message doesn't conform to MIME standard. "
1490 "It may render wrongly."), NULL);
1491 noticeview_set_text(messageview->noticeview, full);
1492 g_free(full);
1494 noticeview_show(messageview->noticeview);
1497 root = mimeinfo;
1498 mimeinfo = procmime_mimeinfo_next(mimeinfo);
1499 if (!all_headers && mimeinfo
1500 && (mimeinfo->type != MIMETYPE_TEXT
1501 || strcasecmp(mimeinfo->subtype, "plain"))
1502 && (mimeinfo->type != MIMETYPE_MULTIPART
1503 || strcasecmp(mimeinfo->subtype, "signed"))) {
1504 if (strcasecmp(mimeinfo->subtype, "html")) {
1505 MimeInfoSearch context = {
1506 .parent = root,
1507 .current = mimeinfo,
1508 .found = NULL
1510 if (mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
1511 MimeInfoSearch cal_context = context;
1512 messageview_find_part_depth_first(&cal_context, MIMETYPE_TEXT, "calendar");
1513 if (cal_context.found) { /* calendar found */
1514 mimeinfo = cal_context.found;
1515 if (messageview_try_select_mimeinfo(messageview, msginfo, mimeinfo))
1516 goto done;
1519 messageview_find_part_depth_first(&context, MIMETYPE_TEXT, "html");
1520 if (context.found &&
1521 (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_ALWAYS ||
1522 (msginfo->folder->prefs->promote_html_part == HTML_PROMOTE_DEFAULT &&
1523 prefs_common.promote_html_part))) { /* html found */
1524 mimeinfo = context.found;
1525 if (messageview_try_select_mimeinfo(messageview, msginfo, mimeinfo))
1526 goto done;
1527 } else
1528 mimeinfo = root; /* nothing found */
1530 if (!mimeview_show_part(messageview->mimeview, mimeinfo))
1531 mimeview_select_mimepart_icon(messageview->mimeview, root);
1532 goto done;
1533 } else if (prefs_common.invoke_plugin_on_html) {
1534 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1535 goto done;
1538 if (!all_headers && mimeinfo &&
1539 mimeinfo->type == MIMETYPE_MULTIPART &&
1540 mimeview_has_viewer_for_content_type(messageview->mimeview, "text/calendar")) {
1541 /* look for a calendar part or it looks really strange */
1542 while (mimeinfo) {
1543 if (mimeinfo->type == MIMETYPE_TEXT &&
1544 !strcasecmp(mimeinfo->subtype, "calendar")) {
1545 mimeview_select_mimepart_icon(messageview->mimeview, mimeinfo);
1546 goto done;
1548 mimeinfo = procmime_mimeinfo_next(mimeinfo);
1552 mimeview_select_mimepart_icon(messageview->mimeview, root);
1553 done:
1554 messageview_set_menu_sensitive(messageview);
1555 /* plugins may hook in here to work with the message view */
1556 hooks_invoke(MESSAGE_VIEW_SHOW_DONE_HOOKLIST, messageview);
1558 g_free(file);
1560 return 0;
1563 void messageview_reflect_prefs_pixmap_theme(void)
1565 GList *cur;
1566 MessageView *msgview;
1568 for (cur = msgview_list; cur != NULL; cur = cur->next) {
1569 msgview = (MessageView*)cur->data;
1570 toolbar_update(TOOLBAR_MSGVIEW, msgview);
1571 mimeview_update(msgview->mimeview);
1575 void messageview_clear(MessageView *messageview)
1577 if (!messageview)
1578 return;
1579 procmsg_msginfo_free(&(messageview->msginfo));
1580 messageview->msginfo = NULL;
1581 messageview->filtered = FALSE;
1583 if (messageview->window) {
1584 gtk_window_set_title(GTK_WINDOW(messageview->window),
1585 _("Claws Mail - Message View"));
1586 GTK_EVENTS_FLUSH();
1589 mimeview_clear(messageview->mimeview);
1590 headerview_clear(messageview->headerview);
1591 noticeview_hide(messageview->noticeview);
1594 void messageview_destroy(MessageView *messageview)
1596 debug_print("destroy messageview\n");
1597 messageview_list = g_list_remove(messageview_list, messageview);
1599 if (messageview->mainwin->summaryview->messageview == messageview) {
1600 messageview->mainwin->summaryview->displayed = NULL;
1601 messageview->mainwin->summaryview->messageview = NULL;
1603 if (messageview->mainwin->summaryview->ext_messageview == messageview) {
1604 messageview->mainwin->summaryview->displayed = NULL;
1605 messageview->mainwin->summaryview->ext_messageview = NULL;
1607 if (!messageview->deferred_destroy)
1608 hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
1609 messageview->msginfo_update_callback_id);
1611 if (messageview->updating) {
1612 debug_print("uh oh, better not touch that now (fetching)\n");
1613 messageview->deferred_destroy = TRUE;
1614 gtk_widget_hide(messageview->window);
1615 return;
1618 if (messageview->mimeview->textview
1619 && messageview->mimeview->textview->loading) {
1620 debug_print("uh oh, better not touch that now (loading text)\n");
1621 messageview->deferred_destroy = TRUE;
1622 messageview->mimeview->textview->stop_loading = TRUE;
1623 gtk_widget_hide(messageview->window);
1624 return;
1627 headerview_destroy(messageview->headerview);
1628 mimeview_destroy(messageview->mimeview);
1629 noticeview_destroy(messageview->noticeview);
1631 procmsg_msginfo_free(&(messageview->msginfo));
1632 toolbar_clear_list(TOOLBAR_MSGVIEW);
1633 if (messageview->toolbar) {
1634 toolbar_destroy(messageview->toolbar);
1635 g_free(messageview->toolbar);
1638 message_search_close(messageview);
1640 list_free_strings_full(messageview->trail);
1641 msgview_list = g_list_remove(msgview_list, messageview);
1643 if (messageview->window)
1644 gtk_widget_destroy(messageview->window);
1645 g_free(messageview);
1648 void messageview_delete(MessageView *msgview)
1650 MsgInfo *msginfo = NULL;
1651 FolderItem *trash = NULL;
1652 PrefsAccount *ac = NULL;
1654 if (msgview->msginfo && msgview->mainwin && msgview->mainwin->summaryview)
1655 msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1657 /* need a procmsg_msginfo_equal() */
1658 if (msginfo && msgview->msginfo &&
1659 msginfo->msgnum == msgview->msginfo->msgnum &&
1660 msginfo->folder == msgview->msginfo->folder) {
1661 summary_delete_trash(msgview->mainwin->summaryview);
1662 } else {
1663 msginfo = msgview->msginfo;
1665 cm_return_if_fail(msginfo != NULL);
1667 /* We will need to access the original message's msginfo
1668 * later, so we add our own reference. */
1669 procmsg_msginfo_new_ref(msginfo);
1671 /* to get the trash folder, we have to choose either
1672 * the folder's or account's trash default - we prefer
1673 * the one in the account prefs */
1674 if (msginfo->folder) {
1675 if (NULL != (ac = account_find_from_item(msginfo->folder)))
1676 trash = account_get_special_folder(ac, F_TRASH);
1677 if (!trash && msginfo->folder->folder)
1678 trash = msginfo->folder->folder->trash;
1679 /* if still not found, use the default */
1680 if (!trash)
1681 trash = folder_get_default_trash();
1684 cm_return_if_fail(trash != NULL);
1686 if (prefs_common.immediate_exec)
1687 /* TODO: Delete from trash */
1688 folder_item_move_msg(trash, msginfo);
1689 else {
1690 procmsg_msginfo_set_to_folder(msginfo, trash);
1691 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
1692 /* NOTE: does not update to next message in summaryview */
1695 procmsg_msginfo_free(&msginfo);
1697 #ifdef GENERIC_UMPC
1698 if (msgview->window && !prefs_common.always_show_msg) {
1699 messageview_destroy(msgview);
1701 #endif
1705 * \brief update messageview with currently selected message in summaryview
1706 * leave unchanged if summaryview is empty
1707 * \param pointer to MessageView
1709 static void messageview_update(MessageView *msgview, MsgInfo *old_msginfo)
1711 SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
1713 cm_return_if_fail(summaryview != NULL);
1715 if (summaryview->selected) {
1716 MsgInfo *msginfo = summary_get_selected_msg(summaryview);
1717 if (msginfo == NULL || msginfo == old_msginfo)
1718 return;
1720 messageview_show(msgview, msginfo,
1721 msgview->all_headers);
1725 TextView *messageview_get_current_textview(MessageView *messageview)
1727 TextView *text = NULL;
1729 text = messageview->mimeview->textview;
1731 return text;
1734 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
1736 return mimeview_get_selected_part(messageview->mimeview);
1739 void messageview_copy_clipboard(MessageView *messageview)
1741 gchar *text = messageview_get_selection(messageview);
1742 if (text) {
1743 gtk_clipboard_set_text(
1744 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
1745 text, -1);
1747 g_free(text);
1750 void messageview_select_all(MessageView *messageview)
1752 TextView *text;
1754 text = messageview_get_current_textview(messageview);
1755 if (text) {
1756 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
1757 GtkTextBuffer *buffer;
1758 GtkTextIter start, end;
1760 buffer = gtk_text_view_get_buffer(textview);
1761 gtk_text_buffer_get_bounds(buffer, &start, &end);
1762 gtk_text_buffer_select_range(buffer, &start, &end);
1766 void messageview_set_position(MessageView *messageview, gint pos)
1768 TextView *text;
1770 text = messageview_get_current_textview(messageview);
1771 if (text)
1772 textview_set_position(text, pos);
1775 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
1776 gboolean case_sens)
1778 TextView *text;
1780 if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1781 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1782 if (viewer && viewer->text_search) {
1783 return viewer->text_search(viewer, FALSE, str, case_sens);
1787 text = messageview_get_current_textview(messageview);
1788 if (text)
1789 return textview_search_string(text, str, case_sens);
1790 return FALSE;
1793 gboolean messageview_search_string_backward(MessageView *messageview,
1794 const gchar *str,
1795 gboolean case_sens)
1797 TextView *text;
1799 if (messageview->mimeview->type == MIMEVIEW_VIEWER) {
1800 MimeViewer *viewer = messageview->mimeview->mimeviewer;
1801 if (viewer && viewer->text_search) {
1802 return viewer->text_search(viewer, TRUE, str, case_sens);
1806 text = messageview_get_current_textview(messageview);
1807 if (text)
1808 return textview_search_string_backward(text,
1809 str, case_sens);
1810 return FALSE;
1813 gboolean messageview_is_visible(MessageView *messageview)
1815 if (messageview == NULL)
1816 return FALSE;
1817 return messageview->visible;
1820 static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
1821 MessageView *messageview)
1823 messageview_destroy(messageview);
1824 return TRUE;
1827 static void messageview_size_allocate_cb(GtkWidget *widget,
1828 GtkAllocation *allocation)
1830 cm_return_if_fail(allocation != NULL);
1832 gtk_window_get_size(GTK_WINDOW(widget),
1833 &prefs_common.msgwin_width, &prefs_common.msgwin_height);
1836 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
1837 MessageView *messageview)
1839 if (event && event->keyval == GDK_KEY_Escape && messageview->window) {
1840 messageview_destroy(messageview);
1841 return TRUE;
1844 if (event && (event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0)
1845 return FALSE;
1846 if (event && (event->state & GDK_SHIFT_MASK) && event->keyval != GDK_KEY_space)
1847 return FALSE;
1849 return mimeview_pass_key_press_event(messageview->mimeview, event);
1852 static void messageview_show_partial_display_cb(NoticeView *noticeview, MessageView *messageview)
1854 messageview->show_full_text = TRUE;
1855 main_window_cursor_wait(mainwindow_get_mainwindow());
1856 noticeview_hide(messageview->noticeview);
1857 messageview->partial_display_shown = FALSE;
1858 GTK_EVENTS_FLUSH();
1859 mimeview_handle_cmd(messageview->mimeview, "sc://display_as_text", NULL, NULL);
1860 main_window_cursor_normal(mainwindow_get_mainwindow());
1863 void messageview_show_partial_display(MessageView *messageview, MsgInfo *msginfo,
1864 size_t length)
1866 gchar *msg = g_strdup_printf(_("Show all %s."), to_human_readable((goffset)length));
1867 noticeview_set_icon(messageview->noticeview, STOCK_PIXMAP_NOTICE_WARN);
1868 noticeview_set_text(messageview->noticeview, _("Only the first megabyte of text is shown."));
1869 noticeview_set_button_text(messageview->noticeview, msg);
1870 g_free(msg);
1871 noticeview_set_button_press_callback(messageview->noticeview,
1872 G_CALLBACK(messageview_show_partial_display_cb),
1873 (gpointer) messageview);
1874 noticeview_show(messageview->noticeview);
1875 messageview->partial_display_shown = TRUE;
1878 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1880 gchar *addr = NULL;
1881 gboolean from_me = FALSE;
1882 if (msginfo->folder
1883 && (folder_has_parent_of_type(msginfo->folder, F_QUEUE)
1884 || folder_has_parent_of_type(msginfo->folder, F_DRAFT)))
1885 return;
1887 addr = g_strdup(msginfo->from);
1888 if (addr) {
1889 extract_address(addr);
1890 if (account_find_from_address(addr, FALSE)) {
1891 from_me = TRUE;
1893 g_free(addr);
1896 if (from_me) {
1897 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1898 if (MSG_IS_RETRCPT_GOT(msginfo->flags)) {
1899 noticeview_set_text(noticeview, _("You got a return receipt for this message: "
1900 "it has been displayed by the recipient."));
1901 } else {
1902 noticeview_set_text(noticeview, _("You asked for a return receipt in this message."));
1904 noticeview_set_button_text(noticeview, NULL);
1905 noticeview_set_button_press_callback(noticeview, NULL, NULL);
1906 } else {
1907 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1908 noticeview_set_text(noticeview, _("This message asks for a return receipt."));
1909 noticeview_set_button_text(noticeview, _("Send receipt"));
1910 noticeview_set_button_press_callback(noticeview,
1911 G_CALLBACK(return_receipt_send_clicked),
1912 (gpointer) msginfo);
1914 noticeview_show(noticeview);
1917 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1919 MsgInfo *tmpmsginfo;
1920 gchar *file;
1922 file = procmsg_get_message_file_path(msginfo);
1923 if (!file) {
1924 g_warning("can't get message file path.");
1925 return;
1928 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1929 tmpmsginfo->folder = msginfo->folder;
1930 tmpmsginfo->msgnum = msginfo->msgnum;
1932 if (disposition_notification_send(tmpmsginfo) >= 0) {
1933 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1934 noticeview_hide(noticeview);
1937 procmsg_msginfo_free(&tmpmsginfo);
1938 g_free(file);
1941 static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
1943 gchar *text = NULL;
1944 gchar *button1 = NULL;
1945 gchar *button2 = NULL;
1946 void *button1_cb = NULL;
1947 void *button2_cb = NULL;
1949 if (!msginfo->extradata)
1950 return;
1951 if (!partial_msg_in_uidl_list(msginfo)) {
1952 text = g_strdup_printf(_("This message has been partially "
1953 "retrieved,\nand has been deleted from the "
1954 "server."));
1955 } else {
1956 switch (msginfo->planned_download) {
1957 case POP3_PARTIAL_DLOAD_UNKN:
1958 text = g_strdup_printf(_("This message has been "
1959 "partially retrieved;\nit is %s."),
1960 to_human_readable(
1961 (goffset)(msginfo->total_size)));
1962 button1 = _("Mark for download");
1963 button2 = _("Mark for deletion");
1964 button1_cb = partial_recv_dload_clicked;
1965 button2_cb = partial_recv_del_clicked;
1966 break;
1967 case POP3_PARTIAL_DLOAD_DLOAD:
1968 text = g_strdup_printf(_("This message has been "
1969 "partially retrieved;\nit is %s and "
1970 "will be downloaded."),
1971 to_human_readable(
1972 (goffset)(msginfo->total_size)));
1973 button1 = _("Unmark");
1974 button1_cb = partial_recv_unmark_clicked;
1975 button2 = _("Mark for deletion");
1976 button2_cb = partial_recv_del_clicked;
1977 break;
1978 case POP3_PARTIAL_DLOAD_DELE:
1979 text = g_strdup_printf(_("This message has been "
1980 "partially retrieved;\nit is %s and "
1981 "will be deleted."),
1982 to_human_readable(
1983 (goffset)(msginfo->total_size)));
1984 button1 = _("Mark for download");
1985 button1_cb = partial_recv_dload_clicked;
1986 button2 = _("Unmark");
1987 button2_cb = partial_recv_unmark_clicked;
1988 break;
1989 default:
1990 return;
1994 noticeview_set_icon(noticeview, STOCK_PIXMAP_NOTICE_WARN);
1995 noticeview_set_text(noticeview, text);
1996 g_free(text);
1997 noticeview_set_button_text(noticeview, button1);
1998 noticeview_set_button_press_callback(noticeview,
1999 G_CALLBACK(button1_cb), (gpointer) msginfo);
2001 noticeview_set_2ndbutton_text(noticeview, button2);
2002 noticeview_set_2ndbutton_press_callback(noticeview,
2003 G_CALLBACK(button2_cb), (gpointer) msginfo);
2005 noticeview_show(noticeview);
2008 static void partial_recv_dload_clicked(NoticeView *noticeview,
2009 MsgInfo *msginfo)
2011 if (partial_mark_for_download(msginfo) == 0) {
2012 partial_recv_show(noticeview, msginfo);
2016 static void partial_recv_del_clicked(NoticeView *noticeview,
2017 MsgInfo *msginfo)
2019 if (partial_mark_for_delete(msginfo) == 0) {
2020 partial_recv_show(noticeview, msginfo);
2024 static void partial_recv_unmark_clicked(NoticeView *noticeview,
2025 MsgInfo *msginfo)
2027 if (partial_unmark(msginfo) == 0) {
2028 partial_recv_show(noticeview, msginfo);
2032 static void select_account_cb(GtkWidget *w, gpointer data)
2034 *(gint*)data = combobox_get_active_data(GTK_COMBO_BOX(w));
2037 static PrefsAccount *select_account_from_list(GList *ac_list, gboolean has_accounts)
2039 GtkWidget *optmenu;
2040 gint account_id;
2041 AlertValue val;
2043 cm_return_val_if_fail(ac_list != NULL, NULL);
2044 cm_return_val_if_fail(ac_list->data != NULL, NULL);
2046 optmenu = gtkut_account_menu_new(ac_list,
2047 G_CALLBACK(select_account_cb),
2048 &account_id);
2049 if (!optmenu)
2050 return NULL;
2051 account_id = ((PrefsAccount *) ac_list->data)->account_id;
2052 if (!has_accounts) {
2053 gchar *tr;
2054 gchar *text;
2055 tr = g_strdup(C_("'%s' stands for 'To' then 'Cc'",
2056 "This message is asking for a return receipt notification\n"
2057 "but according to its '%s' and '%s' headers it was not\n"
2058 "officially addressed to you.\n"
2059 "It is advised to not send the return receipt."));
2060 text = g_strdup_printf(tr,
2061 prefs_common_translated_header_name("To"),
2062 prefs_common_translated_header_name("Cc"));
2063 val = alertpanel_with_widget(
2064 _("Return Receipt Notification"),
2065 text,
2066 _("_Cancel"), _("_Send Notification"), NULL,
2067 ALERTFOCUS_FIRST, FALSE, optmenu);
2068 g_free(tr);
2069 g_free(text);
2070 } else
2071 val = alertpanel_with_widget(
2072 _("Return Receipt Notification"),
2073 _("More than one of your accounts uses the "
2074 "address that this message was sent to.\n"
2075 "Please choose which account you want to "
2076 "use for sending the receipt notification:"),
2077 _("_Cancel"), _("_Send Notification"), NULL,
2078 ALERTFOCUS_FIRST, FALSE, optmenu);
2080 if (val != G_ALERTALTERNATE)
2081 return NULL;
2082 else
2083 return account_find_from_id(account_id);
2087 * \brief return selected messageview text, when nothing is
2088 * selected and message was filtered, return complete text
2090 * \param pointer to Messageview
2092 * \return pointer to text (needs to be free'd by calling func)
2094 gchar *messageview_get_selection(MessageView *msgview)
2096 TextView *textview;
2097 gchar *text = NULL;
2098 GtkTextView *edit = NULL;
2099 GtkTextBuffer *textbuf;
2100 gint body_pos = 0;
2101 GtkTextIter start_iter, end_iter;
2102 GtkTextMark *body_start, *body_end;
2104 cm_return_val_if_fail(msgview != NULL, NULL);
2106 if (msgview->mimeview->type == MIMEVIEW_VIEWER) {
2107 MimeViewer *viewer = msgview->mimeview->mimeviewer;
2108 if (viewer && viewer->get_selection) {
2109 text = viewer->get_selection(viewer);
2110 if (text)
2111 return text;
2115 textview = messageview_get_current_textview(msgview);
2116 cm_return_val_if_fail(textview != NULL, NULL);
2118 edit = GTK_TEXT_VIEW(textview->text);
2119 cm_return_val_if_fail(edit != NULL, NULL);
2120 body_pos = textview->body_pos;
2122 textbuf = gtk_text_view_get_buffer(edit);
2124 if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL)) {
2125 return gtkut_text_view_get_selection(edit);
2126 } else {
2127 if (msgview->filtered) {
2128 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
2129 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
2130 } else {
2131 body_start = gtk_text_buffer_get_mark(textbuf, "body_start");
2133 /* If there is no body_start mark, an attachment is likely
2134 * selected, and we're looking at instructions on what to do
2135 * with it. No point in quoting that, so we'll just return NULL,
2136 * so that original message body is quoted instead down the line.
2138 if (body_start == NULL) {
2139 return NULL;
2142 gtk_text_buffer_get_iter_at_mark(textbuf, &start_iter, body_start);
2144 body_end = gtk_text_buffer_get_mark(textbuf, "body_end");
2145 if (body_end != NULL) /* Just in case */
2146 gtk_text_buffer_get_iter_at_mark(textbuf, &end_iter, body_end);
2147 else
2148 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
2151 return gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
2154 return text;
2157 static void save_as_cb(GtkAction *action, gpointer data)
2159 MessageView *messageview = (MessageView *)data;
2160 summary_save_as(messageview->mainwin->summaryview);
2163 static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gint partnum)
2165 MainWindow *mainwin;
2166 if (!mimeview
2167 || !mimeview->textview
2168 || !mimeview->textview->text)
2169 alertpanel_warning(_("Cannot print: the message doesn't "
2170 "contain text."));
2171 else {
2172 gtk_widget_realize(mimeview->textview->text);
2173 if (partnum > 0) {
2174 mimeview_select_part_num(mimeview, partnum);
2176 if (mimeview->type == MIMEVIEW_VIEWER) {
2177 MimeViewer *viewer = mimeview->mimeviewer;
2178 if (viewer && viewer->print) {
2179 viewer->print(viewer);
2180 return;
2181 } else {
2182 /* Force text rendering if possible */
2183 MimeInfo *mimepart;
2185 mimepart = mimeview_get_selected_part(mimeview);
2186 if (mimepart == NULL
2187 || (mimepart->type != MIMETYPE_TEXT && mimepart->type != MIMETYPE_MESSAGE)) {
2188 alertpanel_warning(_("Cannot print: the message doesn't "
2189 "contain text."));
2190 return;
2192 mimeview_show_part_as_text(mimeview, mimepart);
2195 if (sel_start != -1 && sel_end != -1) {
2196 GtkTextIter start, end;
2197 GtkTextView *text = GTK_TEXT_VIEW(mimeview->textview->text);
2198 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2200 gtk_text_buffer_get_iter_at_offset(buffer, &start, sel_start);
2201 gtk_text_buffer_get_iter_at_offset(buffer, &end, sel_end);
2202 gtk_text_buffer_select_range(buffer, &start, &end);
2204 /* TODO: Get the real parent window, not the main window */
2205 mainwin = mainwindow_get_mainwindow();
2206 printing_print(GTK_TEXT_VIEW(mimeview->textview->text),
2207 mainwin ? GTK_WINDOW(mainwin->window) : NULL,
2208 sel_start, sel_end,
2209 (mimeview->textview->image
2210 ? GTK_IMAGE(mimeview->textview->image)
2211 : NULL));
2215 void messageview_print(MsgInfo *msginfo, gboolean all_headers,
2216 gint sel_start, gint sel_end, gint partnum)
2218 PangoFontDescription *font_desc = NULL;
2219 MessageView *tmpview = messageview_create_with_new_window_visible(
2220 mainwindow_get_mainwindow(), FALSE);
2222 if (prefs_common.use_different_print_font) {
2223 font_desc = pango_font_description_from_string
2224 (prefs_common.printfont);
2225 } else {
2226 font_desc = pango_font_description_from_string
2227 (prefs_common.textfont);
2229 if (font_desc) {
2230 gtk_widget_override_font(tmpview->mimeview->textview->text,
2231 font_desc);
2232 pango_font_description_free(font_desc);
2235 tmpview->all_headers = all_headers;
2236 if (msginfo && messageview_show(tmpview, msginfo,
2237 tmpview->all_headers) >= 0) {
2238 print_mimeview(tmpview->mimeview,
2239 sel_start, sel_end, partnum);
2241 messageview_destroy(tmpview);
2244 static void page_setup_cb(GtkAction *action, gpointer data)
2246 MessageView *messageview = (MessageView *)data;
2247 printing_page_setup(messageview ?
2248 GTK_WINDOW(messageview->window) : NULL);
2251 static void print_cb(GtkAction *action, gpointer data)
2253 MessageView *messageview = (MessageView *)data;
2254 gint sel_start = -1, sel_end = -1, partnum = 0;
2256 if (!messageview->msginfo) return;
2258 partnum = mimeview_get_selected_part_num(messageview->mimeview);
2259 textview_get_selection_offsets(messageview->mimeview->textview,
2260 &sel_start, &sel_end);
2261 messageview_print(messageview->msginfo, messageview->all_headers,
2262 sel_start, sel_end, partnum);
2265 static void close_cb(GtkAction *action, gpointer data)
2267 MessageView *messageview = (MessageView *)data;
2268 messageview_destroy(messageview);
2271 static void copy_cb(GtkAction *action, gpointer data)
2273 MessageView *messageview = (MessageView *)data;
2274 messageview_copy_clipboard(messageview);
2277 static void allsel_cb(GtkAction *action, gpointer data)
2279 MessageView *messageview = (MessageView *)data;
2280 messageview_select_all(messageview);
2283 static void search_cb(GtkAction *action, gpointer data)
2285 MessageView *messageview = (MessageView *)data;
2286 message_search(messageview);
2289 static void prev_cb(GtkAction *action, gpointer data)
2291 MessageView *messageview = (MessageView *)data;
2292 messageview->updating = TRUE;
2293 summary_select_prev(messageview->mainwin->summaryview);
2294 messageview->updating = FALSE;
2296 if (messageview->deferred_destroy) {
2297 debug_print("messageview got away!\n");
2298 messageview_destroy(messageview);
2299 return;
2301 if (messageview->mainwin->summaryview->selected) {
2302 #ifndef GENERIC_UMPC
2303 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2305 if (msginfo)
2306 messageview_show(messageview, msginfo,
2307 messageview->all_headers);
2308 #endif
2309 } else {
2310 gtk_widget_destroy(messageview->window);
2314 static void next_cb(GtkAction *action, gpointer data)
2316 MessageView *messageview = (MessageView *)data;
2317 messageview->updating = TRUE;
2318 summary_select_next(messageview->mainwin->summaryview);
2319 messageview->updating = FALSE;
2321 if (messageview->deferred_destroy) {
2322 debug_print("messageview got away!\n");
2323 messageview_destroy(messageview);
2324 return;
2326 if (messageview->mainwin->summaryview->selected) {
2327 #ifndef GENERIC_UMPC
2328 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2330 if (msginfo)
2331 messageview_show(messageview, msginfo,
2332 messageview->all_headers);
2333 #endif
2334 } else {
2335 gtk_widget_destroy(messageview->window);
2339 static void prev_unread_cb(GtkAction *action, gpointer data)
2341 MessageView *messageview = (MessageView *)data;
2342 messageview->updating = TRUE;
2343 summary_select_prev_unread(messageview->mainwin->summaryview);
2344 messageview->updating = FALSE;
2346 if (messageview->deferred_destroy) {
2347 debug_print("messageview got away!\n");
2348 messageview_destroy(messageview);
2349 return;
2351 if (messageview->mainwin->summaryview->selected) {
2352 #ifndef GENERIC_UMPC
2353 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2355 if (msginfo)
2356 messageview_show(messageview, msginfo,
2357 messageview->all_headers);
2358 #endif
2359 } else {
2360 gtk_widget_destroy(messageview->window);
2364 static void next_unread_cb(GtkAction *action, gpointer data)
2366 MessageView *messageview = (MessageView *)data;
2367 messageview->updating = TRUE;
2368 summary_select_next_unread(messageview->mainwin->summaryview);
2369 messageview->updating = FALSE;
2371 if (messageview->deferred_destroy) {
2372 debug_print("messageview got away!\n");
2373 messageview_destroy(messageview);
2374 return;
2376 if (messageview->mainwin->summaryview->selected) {
2377 #ifndef GENERIC_UMPC
2378 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2380 if (msginfo)
2381 messageview_show(messageview, msginfo,
2382 messageview->all_headers);
2383 #endif
2384 } else {
2385 gtk_widget_destroy(messageview->window);
2389 static void prev_new_cb(GtkAction *action, gpointer data)
2391 MessageView *messageview = (MessageView *)data;
2392 messageview->updating = TRUE;
2393 summary_select_prev_new(messageview->mainwin->summaryview);
2394 messageview->updating = FALSE;
2396 if (messageview->deferred_destroy) {
2397 debug_print("messageview got away!\n");
2398 messageview_destroy(messageview);
2399 return;
2401 if (messageview->mainwin->summaryview->selected) {
2402 #ifndef GENERIC_UMPC
2403 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2405 if (msginfo)
2406 messageview_show(messageview, msginfo,
2407 messageview->all_headers);
2408 #endif
2409 } else {
2410 gtk_widget_destroy(messageview->window);
2414 static void next_new_cb(GtkAction *action, gpointer data)
2416 MessageView *messageview = (MessageView *)data;
2417 messageview->updating = TRUE;
2418 summary_select_next_new(messageview->mainwin->summaryview);
2419 messageview->updating = FALSE;
2421 if (messageview->deferred_destroy) {
2422 debug_print("messageview got away!\n");
2423 messageview_destroy(messageview);
2424 return;
2426 if (messageview->mainwin->summaryview->selected) {
2427 #ifndef GENERIC_UMPC
2428 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2430 if (msginfo)
2431 messageview_show(messageview, msginfo,
2432 messageview->all_headers);
2433 #endif
2434 } else {
2435 gtk_widget_destroy(messageview->window);
2439 static void prev_marked_cb(GtkAction *action, gpointer data)
2441 MessageView *messageview = (MessageView *)data;
2442 messageview->updating = TRUE;
2443 summary_select_prev_marked(messageview->mainwin->summaryview);
2444 messageview->updating = FALSE;
2446 if (messageview->deferred_destroy) {
2447 debug_print("messageview got away!\n");
2448 messageview_destroy(messageview);
2449 return;
2451 if (messageview->mainwin->summaryview->selected) {
2452 #ifndef GENERIC_UMPC
2453 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2455 if (msginfo)
2456 messageview_show(messageview, msginfo,
2457 messageview->all_headers);
2458 #endif
2459 } else {
2460 gtk_widget_destroy(messageview->window);
2464 static void next_marked_cb(GtkAction *action, gpointer data)
2466 MessageView *messageview = (MessageView *)data;
2467 messageview->updating = TRUE;
2468 summary_select_next_marked(messageview->mainwin->summaryview);
2469 messageview->updating = FALSE;
2471 if (messageview->deferred_destroy) {
2472 debug_print("messageview got away!\n");
2473 messageview_destroy(messageview);
2474 return;
2476 if (messageview->mainwin->summaryview->selected) {
2477 #ifndef GENERIC_UMPC
2478 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2480 if (msginfo)
2481 messageview_show(messageview, msginfo,
2482 messageview->all_headers);
2483 #endif
2484 } else {
2485 gtk_widget_destroy(messageview->window);
2489 static void prev_labeled_cb(GtkAction *action, gpointer data)
2491 MessageView *messageview = (MessageView *)data;
2492 messageview->updating = TRUE;
2493 summary_select_prev_labeled(messageview->mainwin->summaryview);
2494 messageview->updating = FALSE;
2496 if (messageview->deferred_destroy) {
2497 debug_print("messageview got away!\n");
2498 messageview_destroy(messageview);
2499 return;
2501 if (messageview->mainwin->summaryview->selected) {
2502 #ifndef GENERIC_UMPC
2503 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2505 if (msginfo)
2506 messageview_show(messageview, msginfo,
2507 messageview->all_headers);
2508 #endif
2509 } else {
2510 gtk_widget_destroy(messageview->window);
2514 static void next_labeled_cb(GtkAction *action, gpointer data)
2516 MessageView *messageview = (MessageView *)data;
2517 messageview->updating = TRUE;
2518 summary_select_next_labeled(messageview->mainwin->summaryview);
2519 messageview->updating = FALSE;
2521 if (messageview->deferred_destroy) {
2522 debug_print("messageview got away!\n");
2523 messageview_destroy(messageview);
2524 return;
2526 if (messageview->mainwin->summaryview->selected) {
2527 #ifndef GENERIC_UMPC
2528 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2530 if (msginfo)
2531 messageview_show(messageview, msginfo,
2532 messageview->all_headers);
2533 #endif
2534 } else {
2535 gtk_widget_destroy(messageview->window);
2539 static void prev_history_cb(GtkAction *action, gpointer data)
2541 MessageView *messageview = (MessageView *)data;
2542 MsgInfo *info = messageview_nav_get_prev(messageview);
2543 if (info) {
2544 messageview->updating = TRUE;
2545 messageview_show(messageview, info,
2546 messageview->all_headers);
2547 messageview->updating = FALSE;
2548 procmsg_msginfo_free(&info);
2549 if (messageview->deferred_destroy) {
2550 debug_print("messageview got away!\n");
2551 messageview_destroy(messageview);
2552 return;
2557 static void next_history_cb(GtkAction *action, gpointer data)
2559 MessageView *messageview = (MessageView *)data;
2560 MsgInfo *info = messageview_nav_get_next(messageview);
2561 if (info) {
2562 messageview->updating = TRUE;
2563 messageview_show(messageview, info,
2564 messageview->all_headers);
2565 messageview->updating = FALSE;
2566 procmsg_msginfo_free(&info);
2567 if (messageview->deferred_destroy) {
2568 debug_print("messageview got away!\n");
2569 messageview_destroy(messageview);
2570 return;
2575 static void parent_cb(GtkAction *action, gpointer data)
2577 MessageView *messageview = (MessageView *)data;
2578 messageview->updating = TRUE;
2579 summary_select_parent(messageview->mainwin->summaryview);
2580 messageview->updating = FALSE;
2582 if (messageview->deferred_destroy) {
2583 debug_print("messageview got away!\n");
2584 messageview_destroy(messageview);
2585 return;
2587 if (messageview->mainwin->summaryview->selected) {
2588 #ifndef GENERIC_UMPC
2589 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2591 if (msginfo)
2592 messageview_show(messageview, msginfo,
2593 messageview->all_headers);
2594 #endif
2595 } else {
2596 gtk_widget_destroy(messageview->window);
2600 static void goto_unread_folder_cb(GtkAction *action, gpointer data)
2602 MessageView *messageview = (MessageView *)data;
2604 messageview->updating = TRUE;
2605 folderview_select_next_with_flag(messageview->mainwin->folderview, MSG_UNREAD);
2606 messageview->updating = FALSE;
2608 if (messageview->deferred_destroy) {
2609 debug_print("messageview got away!\n");
2610 messageview_destroy(messageview);
2611 return;
2613 if (messageview->mainwin->summaryview->selected) {
2614 #ifndef GENERIC_UMPC
2615 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2617 if (msginfo)
2618 messageview_show(messageview, msginfo,
2619 messageview->all_headers);
2620 #endif
2621 } else {
2622 gtk_widget_destroy(messageview->window);
2626 static void goto_folder_cb(GtkAction *action, gpointer data)
2628 MessageView *messageview = (MessageView *)data;
2629 FolderItem *to_folder;
2631 to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL, FALSE,
2632 _("Select folder to go to"));
2634 if (to_folder) {
2635 folderview_select(messageview->mainwin->folderview, to_folder);
2637 if (messageview->deferred_destroy) {
2638 debug_print("messageview got away!\n");
2639 messageview_destroy(messageview);
2640 return;
2642 if (messageview->mainwin->summaryview->selected) {
2643 #ifndef GENERIC_UMPC
2644 MsgInfo * msginfo = summary_get_selected_msg(messageview->mainwin->summaryview);
2646 if (msginfo)
2647 messageview_show(messageview, msginfo,
2648 messageview->all_headers);
2649 #endif
2650 } else {
2651 gtk_widget_destroy(messageview->window);
2656 static void scroll_prev_line_cb(GtkAction *action, gpointer data)
2658 MessageView *messageview = (MessageView *)data;
2659 mimeview_scroll_one_line(messageview->mimeview,TRUE);
2662 static void scroll_next_line_cb(GtkAction *action, gpointer data)
2664 MessageView *messageview = (MessageView *)data;
2665 mimeview_scroll_one_line(messageview->mimeview,FALSE);
2668 static void scroll_prev_page_cb(GtkAction *action, gpointer data)
2670 MessageView *messageview = (MessageView *)data;
2671 mimeview_scroll_page(messageview->mimeview,TRUE);
2674 static void scroll_next_page_cb(GtkAction *action, gpointer data)
2676 MessageView *messageview = (MessageView *)data;
2677 mimeview_scroll_page(messageview->mimeview,FALSE);
2680 static void set_charset_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
2682 MessageView *messageview = (MessageView *)data;
2683 gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
2684 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
2685 const gchar *charset;
2687 if (active) {
2688 charset = conv_get_charset_str((CharSet)value);
2689 g_free(messageview->forced_charset);
2690 messageview->forced_charset = g_strdup(charset);
2691 procmime_force_charset(charset);
2693 messageview_show(messageview, messageview->msginfo, FALSE);
2697 static void set_decode_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
2699 MessageView *messageview = (MessageView *)data;
2700 gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
2701 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
2703 if (active) {
2704 messageview->forced_encoding = (EncodingType)value;
2706 messageview_show(messageview, messageview->msginfo, FALSE);
2707 debug_print("forced encoding: %d\n", value);
2712 static void view_source_cb(GtkAction *action, gpointer data)
2714 MessageView *messageview = (MessageView *)data;
2715 SourceWindow *srcwin;
2717 if (!messageview->msginfo) return;
2719 srcwin = source_window_create();
2720 source_window_show_msg(srcwin, messageview->msginfo);
2721 source_window_show(srcwin);
2724 static void show_all_header_cb(GtkToggleAction *action, gpointer data)
2726 MessageView *messageview = (MessageView *)data;
2727 MsgInfo *msginfo = messageview->msginfo;
2729 if (messageview->mimeview->textview &&
2730 messageview->mimeview->textview->loading) {
2731 return;
2733 if (messageview->updating)
2734 return;
2736 messageview->all_headers = prefs_common.show_all_headers =
2737 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
2738 if (!msginfo) return;
2739 messageview->msginfo = NULL;
2740 messageview_show(messageview, msginfo, messageview->all_headers);
2741 procmsg_msginfo_free(&msginfo);
2742 main_window_set_menu_sensitive(messageview->mainwin);
2743 summary_redisplay_msg(messageview->mainwin->summaryview);
2746 static void msg_hide_quotes_cb(GtkToggleAction *action, gpointer data)
2748 MessageView *messageview = (MessageView *)data;
2749 MsgInfo *msginfo = messageview->msginfo;
2750 static gboolean updating_menu = FALSE;
2752 if (updating_menu)
2753 return;
2754 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
2755 const gchar *a_name = gtk_action_get_name(GTK_ACTION(action));
2756 if (!strcmp(a_name, "View/Quotes/CollapseAll")) prefs_common.hide_quotes = 1;
2757 else if (!strcmp(a_name, "View/Quotes/Collapse2")) prefs_common.hide_quotes = 2;
2758 else if (!strcmp(a_name, "View/Quotes/Collapse3")) prefs_common.hide_quotes = 3;
2759 } else
2760 prefs_common.hide_quotes = 0;
2762 updating_menu=TRUE;
2764 cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
2765 cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));
2766 cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse3", (prefs_common.hide_quotes == 3));
2768 updating_menu=FALSE;
2769 if (!msginfo) return;
2770 messageview->msginfo = NULL;
2771 messageview_show(messageview, msginfo,
2772 messageview->all_headers);
2773 procmsg_msginfo_free(&msginfo);
2775 /* update main window */
2776 main_window_set_menu_sensitive(messageview->mainwin);
2777 summary_redisplay_msg(messageview->mainwin->summaryview);
2779 #undef SET_CHECK_MENU_ACTIVE
2781 static void compose_cb(GtkAction *action, gpointer data)
2783 MessageView *messageview = (MessageView *)data;
2784 PrefsAccount *ac = NULL;
2785 FolderItem *item = NULL;
2787 if (messageview->msginfo)
2788 item = messageview->msginfo->folder;
2790 if (item) {
2791 ac = account_find_from_item(item);
2792 if (ac && ac->protocol == A_NNTP &&
2793 FOLDER_TYPE(item->folder) == F_NEWS) {
2794 compose_new(ac, item->path, NULL);
2795 return;
2799 compose_new(ac, NULL, NULL);
2802 #define DO_ACTION(name, act) { if (!strcmp(a_name, name)) action = act; }
2804 static void reply_cb(GtkAction *gaction, gpointer data)
2806 MessageView *messageview = (MessageView *)data;
2807 GSList *msginfo_list = NULL;
2808 gint action = COMPOSE_REPLY;
2809 const gchar *a_name = gtk_action_get_name(gaction);
2811 cm_return_if_fail(messageview->msginfo);
2813 DO_ACTION("Message/Reply", COMPOSE_REPLY);
2814 DO_ACTION("Message/ReplyTo/All", COMPOSE_REPLY_TO_ALL);
2815 DO_ACTION("Message/ReplyTo/Sender", COMPOSE_REPLY_TO_SENDER);
2816 DO_ACTION("Message/ReplyTo/List", COMPOSE_REPLY_TO_LIST);
2817 DO_ACTION("Message/Forward", COMPOSE_FORWARD_INLINE);
2818 DO_ACTION("Message/ForwardAtt", COMPOSE_FORWARD_AS_ATTACH);
2819 DO_ACTION("Message/Redirect", COMPOSE_REDIRECT);
2821 msginfo_list = g_slist_append(msginfo_list, messageview->msginfo);
2822 compose_reply_from_messageview(messageview, msginfo_list, action);
2823 g_slist_free(msginfo_list);
2826 static void addressbook_open_cb(GtkAction *action, gpointer data)
2828 #ifndef USE_ALT_ADDRBOOK
2829 addressbook_open(NULL);
2830 #else
2831 GError* error = NULL;
2833 addressbook_dbus_open(FALSE, &error);
2834 if (error) {
2835 g_warning("Failed to open address book: %s", error->message);
2836 g_error_free(error);
2838 #endif
2841 static void add_address_cb(GtkAction *action, gpointer data)
2843 MessageView *messageview = (MessageView *)data;
2844 MsgInfo *msginfo, *full_msginfo;
2845 gchar *from;
2846 GdkPixbuf *picture = NULL;
2847 AvatarRender *avatarr;
2849 if (!messageview->msginfo || !messageview->msginfo->from)
2850 return;
2852 msginfo = messageview->msginfo;
2853 Xstrdup_a(from, msginfo->from, return);
2854 eliminate_address_comment(from);
2855 extract_address(from);
2857 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
2859 avatarr = avatars_avatarrender_new(full_msginfo);
2860 hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
2862 procmsg_msginfo_free(&full_msginfo);
2864 if (avatarr->image != NULL)
2865 picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
2867 #ifndef USE_ALT_ADDRBOOK
2868 addressbook_add_contact(msginfo->fromname, from, NULL, picture);
2869 #else
2870 if (addressadd_selection(msginfo->fromname, from, NULL, picture)) {
2871 debug_print( "addressbook_add_contact - added\n" );
2873 #endif
2874 avatars_avatarrender_free(avatarr);
2877 static void create_filter_cb(GtkAction *gaction, gpointer data)
2879 MessageView *messageview = (MessageView *)data;
2880 FolderItem * item;
2881 gint action = -1;
2882 const gchar *a_name = gtk_action_get_name(gaction);
2884 if (!messageview->msginfo) return;
2886 DO_ACTION("Tools/CreateFilterRule/Automatically", FILTER_BY_AUTO);
2887 DO_ACTION("Tools/CreateFilterRule/ByFrom", FILTER_BY_FROM);
2888 DO_ACTION("Tools/CreateFilterRule/ByTo", FILTER_BY_TO);
2889 DO_ACTION("Tools/CreateFilterRule/BySubject", FILTER_BY_SUBJECT);
2891 item = messageview->msginfo->folder;
2892 summary_msginfo_filter_open(item, messageview->msginfo,
2893 (PrefsFilterType)action, 0);
2896 static void create_processing_cb(GtkAction *gaction, gpointer data)
2898 MessageView *messageview = (MessageView *)data;
2899 FolderItem * item;
2900 gint action = -1;
2901 const gchar *a_name = gtk_action_get_name(gaction);
2903 if (!messageview->msginfo) return;
2905 DO_ACTION("Tools/CreateProcessingRule/Automatically", FILTER_BY_AUTO);
2906 DO_ACTION("Tools/CreateProcessingRule/ByFrom", FILTER_BY_FROM);
2907 DO_ACTION("Tools/CreateProcessingRule/ByTo", FILTER_BY_TO);
2908 DO_ACTION("Tools/CreateProcessingRule/BySubject", FILTER_BY_SUBJECT);
2910 item = messageview->msginfo->folder;
2911 summary_msginfo_filter_open(item, messageview->msginfo,
2912 (PrefsFilterType)action, 1);
2915 static void open_urls_cb(GtkAction *action, gpointer data)
2917 MessageView *messageview = (MessageView *)data;
2918 messageview_list_urls(messageview);
2921 static void about_cb(GtkAction *gaction, gpointer data)
2923 about_show();
2926 static gboolean messageview_update_msg(gpointer source, gpointer data)
2928 MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
2929 MessageView *messageview = (MessageView *)data;
2930 MsgInfo *old_msginfo = messageview->msginfo;
2932 if (messageview->msginfo != msginfo_update->msginfo)
2933 return FALSE;
2935 if ((msginfo_update->flags & MSGINFO_UPDATE_DELETED) ||
2936 MSG_IS_DELETED(old_msginfo->flags))
2938 if (messageview->new_window) {
2939 if (old_msginfo->folder && old_msginfo->folder->total_msgs == 0) {
2940 messageview_clear(messageview);
2941 textview_show_info(messageview->mimeview->textview,
2942 _("\n There are no messages in this folder"));
2943 return FALSE;
2946 if (!prefs_common.always_show_msg) {
2947 messageview_clear(messageview);
2948 textview_show_info(messageview->mimeview->textview,
2949 MSG_IS_DELETED(old_msginfo->flags) ?
2950 _("\n Message has been deleted") :
2951 _("\n Message has been deleted or moved to another folder"));
2952 } else
2953 messageview->update_needed = TRUE;
2955 } else {
2956 messageview_clear(messageview);
2957 messageview_update(messageview, old_msginfo);
2961 return FALSE;
2964 void messageview_set_menu_sensitive(MessageView *messageview)
2966 if (!messageview || !messageview->ui_manager)
2967 return;
2969 cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/CollapseAll", (prefs_common.hide_quotes == 1));
2970 cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse2", (prefs_common.hide_quotes == 2));
2971 cm_toggle_menu_set_active_full(messageview->ui_manager, "Menu/View/Quotes/Collapse3", (prefs_common.hide_quotes == 3));
2972 cm_menu_set_sensitive_full(messageview->ui_manager, "Menu/View/Goto/PrevHistory", messageview_nav_has_prev(messageview));
2973 cm_menu_set_sensitive_full(messageview->ui_manager, "Menu/View/Goto/NextHistory", messageview_nav_has_next(messageview));
2975 cm_menu_set_sensitive_full(messageview->ui_manager, "Menu/Message/CheckSignature", messageview->mimeview->signed_part);
2978 void messageview_learn (MessageView *msgview, gboolean is_spam)
2980 if (is_spam) {
2981 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, TRUE) == 0)
2982 procmsg_msginfo_set_flags(msgview->msginfo, MSG_SPAM, 0);
2983 else
2984 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
2986 } else {
2987 if (procmsg_spam_learner_learn(msgview->msginfo, NULL, FALSE) == 0)
2988 procmsg_msginfo_unset_flags(msgview->msginfo, MSG_SPAM, 0);
2989 else
2990 log_error(LOG_PROTOCOL, _("An error happened while learning.\n"));
2992 if (msgview->toolbar)
2993 toolbar_set_learn_button
2994 (msgview->toolbar,
2995 MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
2996 else
2997 toolbar_set_learn_button
2998 (msgview->mainwin->toolbar,
2999 MSG_IS_SPAM(msgview->msginfo->flags)?LEARN_HAM:LEARN_SPAM);
3002 void messageview_list_urls (MessageView *msgview)
3004 GSList *cur = msgview->mimeview->textview->uri_list;
3005 GSList *newlist = NULL;
3006 GHashTable *uri_hashtable;
3007 gchar *tmp;
3009 uri_hashtable = g_hash_table_new_full(g_str_hash, g_str_equal,
3010 (GDestroyNotify) g_free, NULL);
3012 for (; cur; cur = cur->next) {
3013 ClickableText *uri = (ClickableText *)cur->data;
3014 if (uri->uri &&
3015 (!g_ascii_strncasecmp(uri->uri, "ftp.", 4) ||
3016 !g_ascii_strncasecmp(uri->uri, "ftp:", 4) ||
3017 !g_ascii_strncasecmp(uri->uri, "www.", 4) ||
3018 !g_ascii_strncasecmp(uri->uri, "http:", 5) ||
3019 !g_ascii_strncasecmp(uri->uri, "https:", 6)))
3021 tmp = g_utf8_strdown(uri->uri, -1);
3023 if (g_hash_table_lookup(uri_hashtable, tmp)) {
3024 g_free(tmp);
3025 continue;
3028 newlist = g_slist_prepend(newlist, uri);
3029 g_hash_table_insert(uri_hashtable, tmp,
3030 GUINT_TO_POINTER(g_str_hash(tmp)));
3033 newlist = g_slist_reverse(newlist);
3034 uri_opener_open(msgview, newlist);
3035 g_slist_free(newlist);
3036 g_hash_table_destroy(uri_hashtable);
3039 static void save_part_as_cb(GtkAction *action, gpointer data)
3041 MessageView *messageview = (MessageView *)data;
3043 if (messageview->mimeview)
3044 mimeview_save_as(messageview->mimeview);
3047 static void view_part_as_text_cb(GtkAction *action, gpointer data)
3049 MessageView *messageview = (MessageView *)data;
3051 if (messageview->mimeview)
3052 mimeview_display_as_text(messageview->mimeview);
3055 static void open_part_cb(GtkAction *action, gpointer data)
3057 MessageView *messageview = (MessageView *)data;
3059 if (messageview->mimeview)
3060 mimeview_launch(messageview->mimeview, NULL);
3062 #ifndef G_OS_WIN32
3063 static void open_part_with_cb(GtkAction *action, gpointer data)
3065 MessageView *messageview = (MessageView *)data;
3067 if (messageview->mimeview)
3068 mimeview_open_with(messageview->mimeview);
3070 #endif
3071 static void check_signature_cb(GtkAction *action, gpointer data)
3073 MessageView *messageview = (MessageView *)data;
3075 if (messageview->mimeview)
3076 mimeview_check_signature(messageview->mimeview);
3079 static void goto_next_part_cb(GtkAction *action, gpointer data)
3081 MessageView *messageview = (MessageView *)data;
3083 if (messageview->mimeview)
3084 mimeview_select_next_part(messageview->mimeview);
3087 static void goto_prev_part_cb(GtkAction *action, gpointer data)
3089 MessageView *messageview = (MessageView *)data;
3091 if (messageview->mimeview)
3092 mimeview_select_prev_part(messageview->mimeview);