Statistics
| Revision:

root / src / messageview.c @ 1040

History | View | Annotate | Download (27.5 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 952 hiro
 * Copyright (C) 1999-2006 Hiroyuki Yamamoto
4 1 hiro
 *
5 1 hiro
 * This program is free software; you can redistribute it and/or modify
6 1 hiro
 * it under the terms of the GNU General Public License as published by
7 1 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1 hiro
 * (at your option) any later version.
9 1 hiro
 *
10 1 hiro
 * This program is distributed in the hope that it will be useful,
11 1 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1 hiro
 * GNU General Public License for more details.
14 1 hiro
 *
15 1 hiro
 * You should have received a copy of the GNU General Public License
16 1 hiro
 * along with this program; if not, write to the Free Software
17 1 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1 hiro
 */
19 1 hiro
20 1 hiro
#include "defs.h"
21 1 hiro
22 1 hiro
#include <glib.h>
23 92 hiro
#include <glib/gi18n.h>
24 1 hiro
#include <gdk/gdkkeysyms.h>
25 154 hiro
#include <gtk/gtknotebook.h>
26 1 hiro
#include <gtk/gtkvbox.h>
27 1 hiro
#include <gtk/gtkcontainer.h>
28 1 hiro
#include <gtk/gtkwindow.h>
29 1 hiro
#include <gtk/gtktextview.h>
30 1 hiro
#include <gtk/gtkmenu.h>
31 1 hiro
#include <gtk/gtkmenuitem.h>
32 237 hiro
#include <gtk/gtkcheckmenuitem.h>
33 237 hiro
#include <gtk/gtkstatusbar.h>
34 1 hiro
#include <stdio.h>
35 1 hiro
#include <ctype.h>
36 1 hiro
#include <string.h>
37 1 hiro
38 1 hiro
#include "main.h"
39 1 hiro
#include "messageview.h"
40 1 hiro
#include "message_search.h"
41 1 hiro
#include "headerview.h"
42 1 hiro
#include "textview.h"
43 1 hiro
#include "imageview.h"
44 1 hiro
#include "mimeview.h"
45 1 hiro
#include "menu.h"
46 1 hiro
#include "about.h"
47 1 hiro
#include "filesel.h"
48 1 hiro
#include "sourcewindow.h"
49 1 hiro
#include "addressbook.h"
50 1 hiro
#include "alertpanel.h"
51 1 hiro
#include "inputdialog.h"
52 1 hiro
#include "manage_window.h"
53 1 hiro
#include "procmsg.h"
54 1 hiro
#include "procheader.h"
55 1 hiro
#include "procmime.h"
56 1 hiro
#include "account.h"
57 1 hiro
#include "action.h"
58 1 hiro
#include "prefs_common.h"
59 1 hiro
#include "prefs_account.h"
60 1 hiro
#include "prefs_filter.h"
61 547 hiro
#include "filter.h"
62 1 hiro
#include "gtkutils.h"
63 1 hiro
#include "utils.h"
64 1 hiro
#include "rfc2015.h"
65 1 hiro
66 1 hiro
static GList *messageview_list = NULL;
67 1 hiro
68 154 hiro
static void messageview_change_view_type(MessageView                *messageview,
69 154 hiro
                                         MessageType                 type);
70 976 hiro
static void messageview_set_menu_state        (MessageView                *messageview);
71 976 hiro
72 316 hiro
static gint messageview_delete_cb        (GtkWidget                *widget,
73 316 hiro
                                         GdkEventAny                *event,
74 154 hiro
                                         MessageView                *messageview);
75 154 hiro
static void messageview_size_allocate_cb(GtkWidget                *widget,
76 154 hiro
                                         GtkAllocation                *allocation);
77 154 hiro
static void messageview_switch_page_cb        (GtkNotebook                *notebook,
78 154 hiro
                                         GtkNotebookPage        *page,
79 154 hiro
                                         guint                         page_num,
80 154 hiro
                                         MessageView                *messageview);
81 154 hiro
static gboolean key_pressed                (GtkWidget                *widget,
82 154 hiro
                                         GdkEventKey                *event,
83 154 hiro
                                         MessageView                *messageview);
84 1 hiro
85 1 hiro
static void save_as_cb                        (gpointer         data,
86 1 hiro
                                         guint                 action,
87 1 hiro
                                         GtkWidget        *widget);
88 1 hiro
static void print_cb                        (gpointer         data,
89 1 hiro
                                         guint                 action,
90 1 hiro
                                         GtkWidget        *widget);
91 1 hiro
static void close_cb                        (gpointer         data,
92 1 hiro
                                         guint                 action,
93 1 hiro
                                         GtkWidget        *widget);
94 1 hiro
static void copy_cb                        (gpointer         data,
95 1 hiro
                                         guint                 action,
96 1 hiro
                                         GtkWidget        *widget);
97 1 hiro
static void allsel_cb                        (gpointer         data,
98 1 hiro
                                         guint                 action,
99 1 hiro
                                         GtkWidget        *widget);
100 1 hiro
static void search_cb                        (gpointer         data,
101 1 hiro
                                         guint                 action,
102 1 hiro
                                         GtkWidget        *widget);
103 1 hiro
104 1 hiro
static void set_charset_cb                (gpointer         data,
105 1 hiro
                                         guint                 action,
106 1 hiro
                                         GtkWidget        *widget);
107 1 hiro
static void view_source_cb                (gpointer         data,
108 1 hiro
                                         guint                 action,
109 1 hiro
                                         GtkWidget        *widget);
110 1 hiro
static void show_all_header_cb                (gpointer         data,
111 1 hiro
                                         guint                 action,
112 1 hiro
                                         GtkWidget        *widget);
113 1 hiro
114 1 hiro
static void compose_cb                        (gpointer         data,
115 1 hiro
                                         guint                 action,
116 1 hiro
                                         GtkWidget        *widget);
117 1 hiro
static void reply_cb                        (gpointer         data,
118 1 hiro
                                         guint                 action,
119 1 hiro
                                         GtkWidget        *widget);
120 1 hiro
static void reedit_cb                        (gpointer         data,
121 1 hiro
                                         guint                 action,
122 1 hiro
                                         GtkWidget        *widget);
123 1 hiro
124 1 hiro
static void addressbook_open_cb                (gpointer         data,
125 1 hiro
                                         guint                 action,
126 1 hiro
                                         GtkWidget        *widget);
127 1 hiro
static void add_address_cb                (gpointer         data,
128 1 hiro
                                         guint                 action,
129 1 hiro
                                         GtkWidget        *widget);
130 1 hiro
static void create_filter_cb                (gpointer         data,
131 1 hiro
                                         guint                 action,
132 1 hiro
                                         GtkWidget        *widget);
133 1 hiro
134 1 hiro
static void about_cb                        (gpointer         data,
135 1 hiro
                                         guint                 action,
136 1 hiro
                                         GtkWidget        *widget);
137 1 hiro
138 1 hiro
static GtkItemFactoryEntry msgview_entries[] =
139 1 hiro
{
140 1 hiro
        {N_("/_File"),                        NULL, NULL, 0, "<Branch>"},
141 1 hiro
        {N_("/_File/_Save as..."),        NULL, save_as_cb, 0, NULL},
142 1 hiro
        {N_("/_File/_Print..."),        NULL, print_cb, 0, NULL},
143 1 hiro
        {N_("/_File/---"),                NULL, NULL, 0, "<Separator>"},
144 1 hiro
        {N_("/_File/_Close"),                NULL, close_cb, 0, NULL},
145 1 hiro
146 1 hiro
        {N_("/_Edit"),                        NULL, NULL, 0, "<Branch>"},
147 1 hiro
        {N_("/_Edit/_Copy"),                NULL, copy_cb, 0, NULL},
148 1 hiro
        {N_("/_Edit/Select _all"),        NULL, allsel_cb, 0, NULL},
149 1 hiro
        {N_("/_Edit/---"),                NULL, NULL, 0, "<Separator>"},
150 1 hiro
        {N_("/_Edit/_Find in current message..."),
151 1 hiro
                                        NULL, search_cb, 0, NULL},
152 1 hiro
153 1 hiro
        {N_("/_View"),                        NULL, NULL, 0, "<Branch>"},
154 1 hiro
155 175 hiro
#define ENC_SEPARATOR \
156 175 hiro
        {N_("/_View/Character _encoding/---"),        NULL, NULL, 0, "<Separator>"}
157 175 hiro
#define ENC_ACTION(action) \
158 175 hiro
        NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
159 1 hiro
160 175 hiro
        {N_("/_View/Character _encoding"),        NULL, NULL, 0, "<Branch>"},
161 175 hiro
        {N_("/_View/Character _encoding/_Auto detect"),
162 1 hiro
                                        NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
163 175 hiro
        ENC_SEPARATOR,
164 175 hiro
        {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
165 175 hiro
         ENC_ACTION(C_US_ASCII)},
166 1 hiro
167 175 hiro
        {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
168 175 hiro
         ENC_ACTION(C_UTF_8)},
169 175 hiro
        ENC_SEPARATOR,
170 175 hiro
        {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
171 175 hiro
         ENC_ACTION(C_ISO_8859_1)},
172 175 hiro
        {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
173 175 hiro
         ENC_ACTION(C_ISO_8859_15)},
174 864 hiro
        {N_("/_View/Character _encoding/Western European (Windows-1252)"),
175 864 hiro
         ENC_ACTION(C_WINDOWS_1252)},
176 175 hiro
        ENC_SEPARATOR,
177 175 hiro
        {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
178 175 hiro
         ENC_ACTION(C_ISO_8859_2)},
179 175 hiro
        ENC_SEPARATOR,
180 175 hiro
        {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
181 175 hiro
         ENC_ACTION(C_ISO_8859_13)},
182 175 hiro
        {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
183 175 hiro
         ENC_ACTION(C_ISO_8859_4)},
184 175 hiro
        ENC_SEPARATOR,
185 175 hiro
        {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
186 175 hiro
         ENC_ACTION(C_ISO_8859_7)},
187 175 hiro
        ENC_SEPARATOR,
188 949 hiro
        {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
189 949 hiro
         ENC_ACTION(C_ISO_8859_6)},
190 949 hiro
        {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
191 949 hiro
         ENC_ACTION(C_CP1256)},
192 949 hiro
        ENC_SEPARATOR,
193 312 hiro
        {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
194 312 hiro
         ENC_ACTION(C_ISO_8859_8)},
195 312 hiro
        {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
196 312 hiro
         ENC_ACTION(C_CP1255)},
197 312 hiro
        ENC_SEPARATOR,
198 175 hiro
        {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
199 175 hiro
         ENC_ACTION(C_ISO_8859_9)},
200 175 hiro
        ENC_SEPARATOR,
201 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
202 175 hiro
         ENC_ACTION(C_ISO_8859_5)},
203 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
204 175 hiro
         ENC_ACTION(C_KOI8_R)},
205 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
206 175 hiro
         ENC_ACTION(C_KOI8_U)},
207 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
208 175 hiro
         ENC_ACTION(C_CP1251)},
209 175 hiro
        ENC_SEPARATOR,
210 175 hiro
        {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
211 175 hiro
         ENC_ACTION(C_ISO_2022_JP)},
212 175 hiro
        {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
213 175 hiro
         ENC_ACTION(C_ISO_2022_JP_2)},
214 175 hiro
        {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
215 175 hiro
         ENC_ACTION(C_EUC_JP)},
216 175 hiro
        {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
217 175 hiro
         ENC_ACTION(C_SHIFT_JIS)},
218 175 hiro
        ENC_SEPARATOR,
219 175 hiro
        {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
220 175 hiro
         ENC_ACTION(C_GB2312)},
221 211 hiro
        {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
222 211 hiro
         ENC_ACTION(C_GBK)},
223 175 hiro
        {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
224 175 hiro
         ENC_ACTION(C_BIG5)},
225 175 hiro
        {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
226 175 hiro
         ENC_ACTION(C_EUC_TW)},
227 175 hiro
        {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
228 175 hiro
         ENC_ACTION(C_ISO_2022_CN)},
229 175 hiro
        ENC_SEPARATOR,
230 175 hiro
        {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
231 175 hiro
         ENC_ACTION(C_EUC_KR)},
232 175 hiro
        {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
233 175 hiro
         ENC_ACTION(C_ISO_2022_KR)},
234 175 hiro
        ENC_SEPARATOR,
235 175 hiro
        {N_("/_View/Character _encoding/Thai (TIS-620)"),
236 175 hiro
         ENC_ACTION(C_TIS_620)},
237 175 hiro
        {N_("/_View/Character _encoding/Thai (Windows-874)"),
238 175 hiro
         ENC_ACTION(C_WINDOWS_874)},
239 1 hiro
240 175 hiro
#undef ENC_SEPARATOR
241 175 hiro
#undef ENC_ACTION
242 1 hiro
243 1 hiro
        {N_("/_View/---"),                NULL, NULL, 0, "<Separator>"},
244 1 hiro
        {N_("/_View/Mess_age source"),        NULL, view_source_cb, 0, NULL},
245 1038 hiro
        {N_("/_View/Show all _headers"),
246 1038 hiro
                                        NULL, show_all_header_cb, 0, "<ToggleItem>"},
247 1 hiro
248 1 hiro
        {N_("/_Message"),                NULL, NULL, 0, "<Branch>"},
249 1 hiro
        {N_("/_Message/Compose _new message"),
250 1 hiro
                                        NULL, compose_cb, 0, NULL},
251 1 hiro
        {N_("/_Message/---"),                NULL, NULL, 0, "<Separator>"},
252 1 hiro
        {N_("/_Message/_Reply"),        NULL, reply_cb, COMPOSE_REPLY, NULL},
253 1 hiro
        {N_("/_Message/Repl_y to/_all"),
254 1 hiro
                                        NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
255 1 hiro
        {N_("/_Message/Repl_y to/_sender"),
256 1 hiro
                                        NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
257 1 hiro
        {N_("/_Message/Repl_y to/mailing _list"),
258 1 hiro
                                        NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
259 1 hiro
        {N_("/_Message/---"),                NULL, NULL, 0, "<Separator>"},
260 1 hiro
        {N_("/_Message/_Forward"),        NULL, reply_cb, COMPOSE_FORWARD, NULL},
261 1 hiro
        {N_("/_Message/For_ward as attachment"),
262 1 hiro
                                        NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
263 1 hiro
        {N_("/_Message/Redirec_t"),        NULL, reply_cb, COMPOSE_REDIRECT, NULL},
264 1 hiro
        {N_("/_Message/---"),                NULL, NULL, 0, "<Separator>"},
265 1 hiro
        {N_("/_Message/Re-_edit"),        NULL, reedit_cb, 0, NULL},
266 1 hiro
267 1 hiro
        {N_("/_Tools"),                        NULL, NULL, 0, "<Branch>"},
268 1 hiro
        {N_("/_Tools/_Address book"),        NULL, addressbook_open_cb, 0, NULL},
269 1 hiro
        {N_("/_Tools/Add sender to address boo_k"),
270 1 hiro
                                        NULL, add_address_cb, 0, NULL},
271 1 hiro
        {N_("/_Tools/---"),                NULL, NULL, 0, "<Separator>"},
272 1 hiro
        {N_("/_Tools/_Create filter rule"),
273 1 hiro
                                        NULL, NULL, 0, "<Branch>"},
274 1 hiro
        {N_("/_Tools/_Create filter rule/_Automatically"),
275 547 hiro
                                        NULL, create_filter_cb, FLT_BY_AUTO, NULL},
276 1 hiro
        {N_("/_Tools/_Create filter rule/by _From"),
277 547 hiro
                                        NULL, create_filter_cb, FLT_BY_FROM, NULL},
278 1 hiro
        {N_("/_Tools/_Create filter rule/by _To"),
279 547 hiro
                                        NULL, create_filter_cb, FLT_BY_TO, NULL},
280 1 hiro
        {N_("/_Tools/_Create filter rule/by _Subject"),
281 547 hiro
                                        NULL, create_filter_cb, FLT_BY_SUBJECT, NULL},
282 952 hiro
#ifndef G_OS_WIN32
283 1 hiro
        {N_("/_Tools/---"),                NULL, NULL, 0, "<Separator>"},
284 1 hiro
        {N_("/_Tools/Actio_ns"),        NULL, NULL, 0, "<Branch>"},
285 952 hiro
#endif
286 1 hiro
287 1 hiro
        {N_("/_Help"),                        NULL, NULL, 0, "<Branch>"},
288 1 hiro
        {N_("/_Help/_About"),                NULL, about_cb, 0, NULL}
289 1 hiro
};
290 1 hiro
291 1 hiro
292 1 hiro
MessageView *messageview_create(void)
293 1 hiro
{
294 1 hiro
        MessageView *messageview;
295 1 hiro
        GtkWidget *vbox;
296 154 hiro
        GtkWidget *notebook;
297 1 hiro
        HeaderView *headerview;
298 1 hiro
        TextView *textview;
299 1 hiro
        MimeView *mimeview;
300 1 hiro
301 1 hiro
        debug_print(_("Creating message view...\n"));
302 1 hiro
        messageview = g_new0(MessageView, 1);
303 1 hiro
304 1 hiro
        messageview->type = MVIEW_TEXT;
305 1 hiro
306 1 hiro
        headerview = headerview_create();
307 1 hiro
308 1 hiro
        textview = textview_create();
309 1 hiro
        textview->messageview = messageview;
310 1 hiro
311 1 hiro
        mimeview = mimeview_create();
312 1 hiro
        mimeview->textview = textview_create();
313 1 hiro
        mimeview->textview->messageview = messageview;
314 1 hiro
        mimeview->imageview = imageview_create();
315 1 hiro
        mimeview->imageview->messageview = messageview;
316 1 hiro
        mimeview->messageview = messageview;
317 1 hiro
318 154 hiro
        notebook = gtk_notebook_new();
319 154 hiro
        gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
320 154 hiro
        gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
321 154 hiro
        gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
322 154 hiro
        gtk_widget_show(notebook);
323 154 hiro
324 154 hiro
        gtk_container_add(GTK_CONTAINER(notebook), GTK_WIDGET_PTR(textview));
325 154 hiro
        gtk_notebook_set_tab_label_text
326 154 hiro
                (GTK_NOTEBOOK(notebook), GTK_WIDGET_PTR(textview), _("Text"));
327 154 hiro
328 154 hiro
        gtk_container_add(GTK_CONTAINER(notebook), GTK_WIDGET_PTR(mimeview));
329 154 hiro
        gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook),
330 154 hiro
                                        GTK_WIDGET_PTR(mimeview),
331 154 hiro
                                        _("Attachments"));
332 154 hiro
333 154 hiro
        gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
334 154 hiro
        gtk_widget_show_all(notebook);
335 154 hiro
336 1 hiro
        vbox = gtk_vbox_new(FALSE, 0);
337 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
338 1 hiro
                           FALSE, FALSE, 0);
339 154 hiro
        gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
340 1 hiro
        gtk_widget_show(vbox);
341 1 hiro
342 1 hiro
        /* to remove without destroyed */
343 1 hiro
        gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
344 1 hiro
        gtk_widget_ref(GTK_WIDGET_PTR(mimeview->imageview));
345 1 hiro
346 154 hiro
        g_signal_connect(G_OBJECT(notebook), "switch_page",
347 154 hiro
                         G_CALLBACK(messageview_switch_page_cb), messageview);
348 154 hiro
349 1 hiro
        messageview->vbox        = vbox;
350 154 hiro
        messageview->notebook    = notebook;
351 154 hiro
352 1 hiro
        messageview->new_window  = FALSE;
353 1 hiro
        messageview->window      = NULL;
354 1 hiro
        messageview->window_vbox = NULL;
355 154 hiro
        messageview->body_vbox   = NULL;
356 154 hiro
357 1 hiro
        messageview->headerview  = headerview;
358 1 hiro
        messageview->textview    = textview;
359 1 hiro
        messageview->mimeview    = mimeview;
360 1 hiro
361 1 hiro
        messageview->statusbar     = NULL;
362 1 hiro
        messageview->statusbar_cid = 0;
363 1 hiro
364 154 hiro
        messageview->current_page = 0;
365 154 hiro
366 1 hiro
        return messageview;
367 1 hiro
}
368 1 hiro
369 1 hiro
MessageView *messageview_create_with_new_window(void)
370 1 hiro
{
371 1 hiro
        MessageView *msgview;
372 1 hiro
        GtkWidget *window;
373 1 hiro
        GtkWidget *window_vbox;
374 1 hiro
        GtkWidget *body_vbox;
375 1 hiro
        GtkWidget *menubar;
376 1 hiro
        GtkItemFactory *ifactory;
377 1 hiro
        GtkWidget *statusbar;
378 1 hiro
        guint n_menu_entries;
379 1 hiro
380 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
381 676 hiro
        gtk_window_set_title(GTK_WINDOW(window), _("Message View - Sylpheed"));
382 1 hiro
        gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
383 1 hiro
        gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
384 1 hiro
        gtk_widget_set_size_request(window, prefs_common.msgwin_width,
385 1 hiro
                                    prefs_common.msgwin_height);
386 1 hiro
387 1 hiro
        msgview = messageview_create();
388 1 hiro
389 1 hiro
        window_vbox = gtk_vbox_new(FALSE, 0);
390 1 hiro
        gtk_container_add(GTK_CONTAINER(window), window_vbox);
391 1 hiro
392 1 hiro
        g_signal_connect(G_OBJECT(window), "size_allocate",
393 1 hiro
                         G_CALLBACK(messageview_size_allocate_cb),
394 1 hiro
                         msgview);
395 316 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
396 316 hiro
                         G_CALLBACK(messageview_delete_cb), msgview);
397 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
398 1 hiro
                         G_CALLBACK(key_pressed), msgview);
399 1 hiro
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
400 1 hiro
401 1 hiro
        n_menu_entries = sizeof(msgview_entries) / sizeof (msgview_entries[0]);
402 1 hiro
        menubar = menubar_create(window, msgview_entries, n_menu_entries,
403 1 hiro
                                 "<MessageView>", msgview);
404 1 hiro
#if 0
405 1 hiro
        menu_factory_copy_rc("<Main>", "<MessageView>");
406 1 hiro
#endif
407 1 hiro
        gtk_box_pack_start(GTK_BOX(window_vbox), menubar, FALSE, TRUE, 0);
408 1 hiro
409 1 hiro
        body_vbox = gtk_vbox_new(FALSE, BORDER_WIDTH);
410 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(body_vbox), BORDER_WIDTH);
411 1 hiro
        gtk_box_pack_start(GTK_BOX(window_vbox), body_vbox, TRUE, TRUE, 0);
412 1 hiro
413 1 hiro
        gtk_box_pack_start(GTK_BOX(body_vbox), GTK_WIDGET_PTR(msgview),
414 1 hiro
                           TRUE, TRUE, 0);
415 1 hiro
        gtk_widget_grab_focus(msgview->textview->text);
416 1 hiro
417 1 hiro
        statusbar = gtk_statusbar_new();
418 1 hiro
        gtk_box_pack_end(GTK_BOX(body_vbox), statusbar, FALSE, FALSE, 0);
419 1 hiro
        msgview->statusbar = statusbar;
420 1 hiro
        msgview->statusbar_cid = gtk_statusbar_get_context_id
421 1 hiro
                (GTK_STATUSBAR(statusbar), "Message View");
422 1 hiro
423 1 hiro
        gtk_widget_show_all(window);
424 1 hiro
425 1 hiro
        msgview->new_window = TRUE;
426 1 hiro
        msgview->window = window;
427 1 hiro
        msgview->window_vbox = window_vbox;
428 1 hiro
        msgview->body_vbox = body_vbox;
429 976 hiro
        msgview->menubar = menubar;
430 976 hiro
        msgview->menu_locked = FALSE;
431 1 hiro
        msgview->visible = TRUE;
432 1 hiro
433 1 hiro
        messageview_init(msgview);
434 1 hiro
435 1 hiro
        ifactory = gtk_item_factory_from_widget(menubar);
436 952 hiro
#ifndef G_OS_WIN32
437 1 hiro
        action_update_msgview_menu(ifactory, msgview);
438 952 hiro
#endif
439 1 hiro
440 1 hiro
        messageview_list = g_list_append(messageview_list, msgview);
441 1 hiro
442 1 hiro
        return msgview;
443 1 hiro
}
444 1 hiro
445 1 hiro
void messageview_init(MessageView *messageview)
446 1 hiro
{
447 1 hiro
        headerview_init(messageview->headerview);
448 1 hiro
        textview_init(messageview->textview);
449 1 hiro
        mimeview_init(messageview->mimeview);
450 1 hiro
        /* messageview_set_font(messageview); */
451 1 hiro
}
452 1 hiro
453 1 hiro
GList *messageview_get_window_list(void)
454 1 hiro
{
455 1 hiro
        return messageview_list;
456 1 hiro
}
457 1 hiro
458 1 hiro
gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
459 1 hiro
                      gboolean all_headers)
460 1 hiro
{
461 1 hiro
        gchar *file;
462 1 hiro
        MimeInfo *mimeinfo;
463 1 hiro
464 1 hiro
        g_return_val_if_fail(msginfo != NULL, -1);
465 1 hiro
466 1 hiro
        mimeinfo = procmime_scan_message(msginfo);
467 1 hiro
        if (!mimeinfo) {
468 1 hiro
                messageview_change_view_type(messageview, MVIEW_TEXT);
469 1 hiro
                textview_show_error(messageview->textview);
470 1 hiro
                return -1;
471 1 hiro
        }
472 1 hiro
473 1 hiro
        file = procmsg_get_message_file_path(msginfo);
474 1 hiro
        if (!file) {
475 1 hiro
                g_warning("can't get message file path.\n");
476 1 hiro
                procmime_mimeinfo_free_all(mimeinfo);
477 1 hiro
                messageview_change_view_type(messageview, MVIEW_TEXT);
478 1 hiro
                textview_show_error(messageview->textview);
479 1 hiro
                return -1;
480 1 hiro
        }
481 1 hiro
482 1 hiro
        if (messageview->msginfo != msginfo) {
483 1 hiro
                procmsg_msginfo_free(messageview->msginfo);
484 1 hiro
                messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
485 20 hiro
                if (!messageview->msginfo)
486 20 hiro
                        messageview->msginfo = procmsg_msginfo_copy(msginfo);
487 1 hiro
        }
488 676 hiro
489 676 hiro
        if (messageview->window && msginfo->subject) {
490 676 hiro
                gchar *title;
491 676 hiro
492 676 hiro
                title = g_strconcat(msginfo->subject, " - Sylpheed", NULL);
493 676 hiro
                gtk_window_set_title(GTK_WINDOW(messageview->window), title);
494 676 hiro
                g_free(title);
495 676 hiro
        }
496 1 hiro
        headerview_show(messageview->headerview, messageview->msginfo);
497 1 hiro
498 1 hiro
        textview_set_all_headers(messageview->textview, all_headers);
499 1 hiro
        textview_set_all_headers(messageview->mimeview->textview, all_headers);
500 1 hiro
501 1 hiro
        if (mimeinfo->mime_type != MIME_TEXT &&
502 1 hiro
            mimeinfo->mime_type != MIME_TEXT_HTML) {
503 1 hiro
                messageview_change_view_type(messageview, MVIEW_MIME);
504 1 hiro
                mimeview_show_message(messageview->mimeview, mimeinfo, file);
505 1 hiro
        } else {
506 1 hiro
                messageview_change_view_type(messageview, MVIEW_TEXT);
507 1 hiro
                textview_show_message(messageview->textview, mimeinfo, file);
508 1 hiro
                procmime_mimeinfo_free_all(mimeinfo);
509 1 hiro
        }
510 1 hiro
511 976 hiro
        if (messageview->new_window)
512 976 hiro
                messageview_set_menu_state(messageview);
513 976 hiro
514 1 hiro
        g_free(file);
515 1 hiro
516 1 hiro
        return 0;
517 1 hiro
}
518 1 hiro
519 1 hiro
static void messageview_change_view_type(MessageView *messageview,
520 1 hiro
                                         MessageType type)
521 1 hiro
{
522 154 hiro
        GtkWidget *notebook = messageview->notebook;
523 1 hiro
524 1 hiro
        if (messageview->type == type) return;
525 1 hiro
526 1 hiro
        if (type == MVIEW_MIME) {
527 154 hiro
                gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), TRUE);
528 154 hiro
                gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),
529 154 hiro
                                              messageview->current_page);
530 1 hiro
        } else if (type == MVIEW_TEXT) {
531 154 hiro
                gint current_page = messageview->current_page;
532 1 hiro
533 154 hiro
                gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
534 154 hiro
                gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
535 154 hiro
                messageview->current_page = current_page;
536 154 hiro
                mimeview_clear(messageview->mimeview);
537 1 hiro
        } else
538 1 hiro
                return;
539 1 hiro
540 1 hiro
        messageview->type = type;
541 1 hiro
}
542 1 hiro
543 976 hiro
static void messageview_set_menu_state(MessageView *messageview)
544 976 hiro
{
545 976 hiro
        GtkItemFactory *ifactory;
546 976 hiro
        GtkWidget *menuitem;
547 976 hiro
548 976 hiro
        messageview->menu_locked = TRUE;
549 976 hiro
        ifactory = gtk_item_factory_from_widget(messageview->menubar);
550 976 hiro
        menuitem = gtk_item_factory_get_widget
551 1038 hiro
                (ifactory, "/View/Show all headers");
552 976 hiro
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
553 976 hiro
                                       messageview->textview->show_all_headers);
554 976 hiro
        messageview->menu_locked = FALSE;
555 976 hiro
}
556 976 hiro
557 1 hiro
void messageview_clear(MessageView *messageview)
558 1 hiro
{
559 1 hiro
        procmsg_msginfo_free(messageview->msginfo);
560 1 hiro
        messageview->msginfo = NULL;
561 1 hiro
        messageview_change_view_type(messageview, MVIEW_TEXT);
562 1 hiro
        headerview_clear(messageview->headerview);
563 1 hiro
        textview_clear(messageview->textview);
564 1 hiro
        mimeview_clear(messageview->mimeview);
565 1 hiro
}
566 1 hiro
567 1 hiro
void messageview_destroy(MessageView *messageview)
568 1 hiro
{
569 154 hiro
        GtkWidget *textview  = GTK_WIDGET_PTR(messageview->mimeview->textview);
570 1 hiro
        GtkWidget *imageview = GTK_WIDGET_PTR(messageview->mimeview->imageview);
571 1 hiro
572 1 hiro
        messageview_list = g_list_remove(messageview_list, messageview);
573 1 hiro
574 1 hiro
        headerview_destroy(messageview->headerview);
575 1 hiro
        textview_destroy(messageview->textview);
576 1 hiro
        mimeview_destroy(messageview->mimeview);
577 1 hiro
578 1 hiro
        procmsg_msginfo_free(messageview->msginfo);
579 1 hiro
580 316 hiro
        if (messageview->window)
581 316 hiro
                gtk_widget_destroy(messageview->window);
582 316 hiro
583 1 hiro
        g_free(messageview);
584 1 hiro
585 1 hiro
        gtk_widget_unref(textview);
586 1 hiro
        gtk_widget_unref(imageview);
587 1 hiro
}
588 1 hiro
589 1 hiro
void messageview_quote_color_set(void)
590 1 hiro
{
591 1 hiro
}
592 1 hiro
593 1 hiro
void messageview_set_font(MessageView *messageview)
594 1 hiro
{
595 1 hiro
        textview_set_font(messageview->textview, NULL);
596 1 hiro
}
597 1 hiro
598 1 hiro
TextView *messageview_get_current_textview(MessageView *messageview)
599 1 hiro
{
600 1 hiro
        TextView *text = NULL;
601 1 hiro
602 1 hiro
        if (messageview->type == MVIEW_TEXT)
603 1 hiro
                text = messageview->textview;
604 1 hiro
        else if (messageview->type == MVIEW_MIME) {
605 1 hiro
                if (gtk_notebook_get_current_page
606 154 hiro
                        (GTK_NOTEBOOK(messageview->notebook)) == 0)
607 1 hiro
                        text = messageview->textview;
608 1 hiro
                else if (messageview->mimeview->type == MIMEVIEW_TEXT)
609 1 hiro
                        text = messageview->mimeview->textview;
610 1 hiro
        }
611 1 hiro
612 1 hiro
        return text;
613 1 hiro
}
614 1 hiro
615 1 hiro
MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
616 1 hiro
{
617 1 hiro
        if (messageview->type == MVIEW_MIME)
618 1 hiro
                return mimeview_get_selected_part(messageview->mimeview);
619 1 hiro
620 1 hiro
        return NULL;
621 1 hiro
}
622 1 hiro
623 1 hiro
void messageview_copy_clipboard(MessageView *messageview)
624 1 hiro
{
625 1 hiro
        TextView *text;
626 1 hiro
627 1 hiro
        text = messageview_get_current_textview(messageview);
628 1 hiro
        if (text) {
629 1 hiro
                GtkTextView *textview = GTK_TEXT_VIEW(text->text);
630 1 hiro
                GtkTextBuffer *buffer;
631 1 hiro
                GtkClipboard *clipboard;
632 1 hiro
633 1 hiro
                buffer = gtk_text_view_get_buffer(textview);
634 1 hiro
                clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
635 1 hiro
                gtk_text_buffer_copy_clipboard(buffer, clipboard);
636 1 hiro
        }
637 1 hiro
}
638 1 hiro
639 1 hiro
void messageview_select_all(MessageView *messageview)
640 1 hiro
{
641 1 hiro
        TextView *text;
642 1 hiro
643 1 hiro
        text = messageview_get_current_textview(messageview);
644 130 hiro
        if (text) {
645 130 hiro
                GtkTextView *textview = GTK_TEXT_VIEW(text->text);
646 130 hiro
                GtkTextBuffer *buffer;
647 130 hiro
                GtkTextIter start, end;
648 130 hiro
649 130 hiro
                buffer = gtk_text_view_get_buffer(textview);
650 130 hiro
                gtk_text_buffer_get_bounds(buffer, &start, &end);
651 130 hiro
                gtk_text_buffer_select_range(buffer, &start, &end);
652 130 hiro
        }
653 1 hiro
}
654 1 hiro
655 1 hiro
void messageview_set_position(MessageView *messageview, gint pos)
656 1 hiro
{
657 1 hiro
        textview_set_position(messageview->textview, pos);
658 1 hiro
}
659 1 hiro
660 1 hiro
gboolean messageview_search_string(MessageView *messageview, const gchar *str,
661 1 hiro
                                   gboolean case_sens)
662 1 hiro
{
663 1 hiro
        return textview_search_string(messageview->textview, str, case_sens);
664 1 hiro
        return FALSE;
665 1 hiro
}
666 1 hiro
667 1 hiro
gboolean messageview_search_string_backward(MessageView *messageview,
668 1 hiro
                                            const gchar *str,
669 1 hiro
                                            gboolean case_sens)
670 1 hiro
{
671 1 hiro
        return textview_search_string_backward(messageview->textview,
672 1 hiro
                                               str, case_sens);
673 1 hiro
        return FALSE;
674 1 hiro
}
675 1 hiro
676 1 hiro
gboolean messageview_is_visible(MessageView *messageview)
677 1 hiro
{
678 1 hiro
        return messageview->visible;
679 1 hiro
}
680 1 hiro
681 1 hiro
void messageview_save_as(MessageView *messageview)
682 1 hiro
{
683 1 hiro
        gchar *filename = NULL;
684 1 hiro
        MsgInfo *msginfo;
685 1 hiro
        gchar *src, *dest;
686 1 hiro
687 1 hiro
        if (!messageview->msginfo) return;
688 1 hiro
        msginfo = messageview->msginfo;
689 1 hiro
690 1 hiro
        if (msginfo->subject) {
691 1 hiro
                Xstrdup_a(filename, msginfo->subject, return);
692 1 hiro
                subst_for_filename(filename);
693 1 hiro
        }
694 128 hiro
695 128 hiro
        dest = filesel_save_as(filename);
696 1 hiro
        if (!dest) return;
697 1 hiro
698 1 hiro
        src = procmsg_get_message_file(msginfo);
699 1 hiro
        if (copy_file(src, dest, TRUE) < 0) {
700 1 hiro
                alertpanel_error(_("Can't save the file `%s'."),
701 1 hiro
                                 g_basename(dest));
702 1 hiro
        }
703 1 hiro
        g_free(src);
704 128 hiro
705 128 hiro
        g_free(dest);
706 1 hiro
}
707 1 hiro
708 316 hiro
static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
709 316 hiro
                                  MessageView *messageview)
710 1 hiro
{
711 1 hiro
        messageview_destroy(messageview);
712 316 hiro
        return TRUE;
713 1 hiro
}
714 1 hiro
715 1 hiro
static void messageview_size_allocate_cb(GtkWidget *widget,
716 1 hiro
                                         GtkAllocation *allocation)
717 1 hiro
{
718 1 hiro
        g_return_if_fail(allocation != NULL);
719 1 hiro
720 1 hiro
        prefs_common.msgwin_width  = allocation->width;
721 1 hiro
        prefs_common.msgwin_height = allocation->height;
722 1 hiro
}
723 1 hiro
724 154 hiro
static void messageview_switch_page_cb(GtkNotebook *notebook,
725 154 hiro
                                       GtkNotebookPage *page, guint page_num,
726 154 hiro
                                       MessageView *messageview)
727 154 hiro
{
728 154 hiro
        messageview->current_page = page_num;
729 154 hiro
}
730 154 hiro
731 1 hiro
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
732 1 hiro
                            MessageView *messageview)
733 1 hiro
{
734 316 hiro
        if (event && event->keyval == GDK_Escape && messageview->window) {
735 316 hiro
                messageview_destroy(messageview);
736 316 hiro
                return TRUE;
737 316 hiro
        }
738 1 hiro
        return FALSE;
739 1 hiro
}
740 1 hiro
741 1 hiro
static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
742 1 hiro
{
743 1 hiro
        MessageView *messageview = (MessageView *)data;
744 1 hiro
        messageview_save_as(messageview);
745 1 hiro
}
746 1 hiro
747 1 hiro
static void print_cb(gpointer data, guint action, GtkWidget *widget)
748 1 hiro
{
749 1 hiro
        MessageView *messageview = (MessageView *)data;
750 684 hiro
        const gchar *cmdline;
751 684 hiro
        gchar *msg;
752 1 hiro
753 1 hiro
        if (!messageview->msginfo) return;
754 1 hiro
755 684 hiro
        cmdline = prefs_common.print_cmd;
756 684 hiro
757 684 hiro
        msg = g_strconcat
758 684 hiro
                (_("The message will be printed with the following command:"),
759 684 hiro
                 "\n\n", cmdline ? cmdline : _("(Default print command)"),
760 684 hiro
                 NULL);
761 684 hiro
        if (alertpanel(_("Print"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
762 684 hiro
            != G_ALERTDEFAULT) {
763 684 hiro
                g_free(msg);
764 684 hiro
                return;
765 684 hiro
        }
766 684 hiro
        g_free(msg);
767 684 hiro
768 1035 hiro
        if (cmdline && str_find_format_times(cmdline, 's') != 1) {
769 1 hiro
                alertpanel_error(_("Print command line is invalid:\n`%s'"),
770 1 hiro
                                 cmdline);
771 1 hiro
                return;
772 1 hiro
        }
773 1 hiro
774 1038 hiro
        procmsg_print_message(messageview->msginfo, cmdline,
775 1038 hiro
                              messageview->textview->show_all_headers);
776 1 hiro
}
777 1 hiro
778 1 hiro
static void close_cb(gpointer data, guint action, GtkWidget *widget)
779 1 hiro
{
780 1 hiro
        MessageView *messageview = (MessageView *)data;
781 316 hiro
        messageview_destroy(messageview);
782 1 hiro
}
783 1 hiro
784 1 hiro
static void copy_cb(gpointer data, guint action, GtkWidget *widget)
785 1 hiro
{
786 1 hiro
        MessageView *messageview = (MessageView *)data;
787 1 hiro
        messageview_copy_clipboard(messageview);
788 1 hiro
}
789 1 hiro
790 1 hiro
static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
791 1 hiro
{
792 1 hiro
        MessageView *messageview = (MessageView *)data;
793 1 hiro
        messageview_select_all(messageview);
794 1 hiro
}
795 1 hiro
796 1 hiro
static void search_cb(gpointer data, guint action, GtkWidget *widget)
797 1 hiro
{
798 1 hiro
        MessageView *messageview = (MessageView *)data;
799 1 hiro
        message_search(messageview);
800 1 hiro
}
801 1 hiro
802 1 hiro
static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
803 1 hiro
{
804 1 hiro
        MessageView *messageview = (MessageView *)data;
805 1 hiro
        const gchar *charset;
806 1 hiro
807 1 hiro
        if (GTK_CHECK_MENU_ITEM(widget)->active) {
808 1 hiro
                charset = conv_get_charset_str((CharSet)action);
809 1 hiro
                g_free(messageview->forced_charset);
810 1 hiro
                messageview->forced_charset = g_strdup(charset);
811 1 hiro
                messageview_show(messageview, messageview->msginfo, FALSE);
812 1 hiro
        }
813 1 hiro
}
814 1 hiro
815 1 hiro
static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
816 1 hiro
{
817 1 hiro
        MessageView *messageview = (MessageView *)data;
818 1 hiro
        SourceWindow *srcwin;
819 1 hiro
820 1 hiro
        if (!messageview->msginfo) return;
821 1 hiro
822 1 hiro
        srcwin = source_window_create();
823 1 hiro
        source_window_show_msg(srcwin, messageview->msginfo);
824 1 hiro
        source_window_show(srcwin);
825 1 hiro
}
826 1 hiro
827 1 hiro
static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
828 1 hiro
{
829 1 hiro
        MessageView *messageview = (MessageView *)data;
830 1 hiro
        MsgInfo *msginfo = messageview->msginfo;
831 1 hiro
832 1 hiro
        if (!msginfo) return;
833 976 hiro
        if (messageview->menu_locked) return;
834 976 hiro
835 1 hiro
        messageview->msginfo = NULL;
836 1 hiro
        messageview_show(messageview, msginfo,
837 1 hiro
                         GTK_CHECK_MENU_ITEM(widget)->active);
838 1 hiro
        procmsg_msginfo_free(msginfo);
839 1 hiro
}
840 1 hiro
841 1 hiro
static void compose_cb(gpointer data, guint action, GtkWidget *widget)
842 1 hiro
{
843 1 hiro
        MessageView *messageview = (MessageView *)data;
844 1 hiro
        PrefsAccount *ac = NULL;
845 1 hiro
        FolderItem *item = NULL;
846 1 hiro
847 1 hiro
        if (messageview->msginfo)
848 1 hiro
                item = messageview->msginfo->folder;
849 1 hiro
850 1 hiro
        if (item) {
851 1 hiro
                ac = account_find_from_item(item);
852 1 hiro
                if (ac && ac->protocol == A_NNTP &&
853 1 hiro
                    FOLDER_TYPE(item->folder) == F_NEWS) {
854 1 hiro
                        compose_new(ac, item, item->path, NULL);
855 1 hiro
                        return;
856 1 hiro
                }
857 1 hiro
        }
858 1 hiro
859 1 hiro
        compose_new(ac, item, NULL, NULL);
860 1 hiro
}
861 1 hiro
862 1 hiro
static void reply_cb(gpointer data, guint action, GtkWidget *widget)
863 1 hiro
{
864 1 hiro
        MessageView *messageview = (MessageView *)data;
865 1 hiro
        GSList *mlist = NULL;
866 1 hiro
        MsgInfo *msginfo;
867 1 hiro
        gchar *text = NULL;
868 1 hiro
        ComposeMode mode = (ComposeMode)action;
869 1 hiro
870 1 hiro
        msginfo = messageview->msginfo;
871 1 hiro
        mlist = g_slist_append(NULL, msginfo);
872 1 hiro
873 130 hiro
        text = gtkut_text_view_get_selection
874 130 hiro
                (GTK_TEXT_VIEW(messageview->textview->text));
875 1 hiro
        if (text && *text == '\0') {
876 1 hiro
                g_free(text);
877 1 hiro
                text = NULL;
878 1 hiro
        }
879 1 hiro
880 1 hiro
        if (!COMPOSE_QUOTE_MODE(mode))
881 1 hiro
                mode |= prefs_common.reply_with_quote
882 1 hiro
                        ? COMPOSE_WITH_QUOTE : COMPOSE_WITHOUT_QUOTE;
883 1 hiro
884 1 hiro
        switch (COMPOSE_MODE(mode)) {
885 1 hiro
        case COMPOSE_REPLY:
886 1 hiro
        case COMPOSE_REPLY_TO_SENDER:
887 1 hiro
        case COMPOSE_REPLY_TO_ALL:
888 1 hiro
        case COMPOSE_REPLY_TO_LIST:
889 1 hiro
                compose_reply(msginfo, msginfo->folder, mode, text);
890 1 hiro
                break;
891 1 hiro
        case COMPOSE_FORWARD:
892 1 hiro
                compose_forward(mlist, msginfo->folder, FALSE, text);
893 1 hiro
                break;
894 1 hiro
        case COMPOSE_FORWARD_AS_ATTACH:
895 1 hiro
                compose_forward(mlist, msginfo->folder, TRUE, NULL);
896 1 hiro
                break;
897 1 hiro
        case COMPOSE_REDIRECT:
898 1 hiro
                compose_redirect(msginfo, msginfo->folder);
899 1 hiro
                break;
900 1 hiro
        default:
901 1 hiro
                g_warning("messageview.c: reply_cb(): invalid mode: %d\n",
902 1 hiro
                          mode);
903 1 hiro
        }
904 1 hiro
905 1 hiro
        /* summary_set_marks_selected(summaryview); */
906 1 hiro
        g_free(text);
907 1 hiro
        g_slist_free(mlist);
908 1 hiro
}
909 1 hiro
910 1 hiro
static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
911 1 hiro
{
912 1 hiro
        MessageView *messageview = (MessageView *)data;
913 1 hiro
        MsgInfo *msginfo;
914 1 hiro
915 1 hiro
        if (!messageview->msginfo) return;
916 1 hiro
        msginfo = messageview->msginfo;
917 1 hiro
        if (!msginfo->folder) return;
918 1 hiro
        if (msginfo->folder->stype != F_OUTBOX &&
919 1 hiro
            msginfo->folder->stype != F_DRAFT &&
920 1 hiro
            msginfo->folder->stype != F_QUEUE) return;
921 1 hiro
922 1 hiro
        compose_reedit(msginfo);
923 1 hiro
}
924 1 hiro
925 1 hiro
static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
926 1 hiro
{
927 1 hiro
        addressbook_open(NULL);
928 1 hiro
}
929 1 hiro
930 1 hiro
static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
931 1 hiro
{
932 1 hiro
        MessageView *messageview = (MessageView *)data;
933 1 hiro
        MsgInfo *msginfo;
934 1 hiro
        gchar *from;
935 1 hiro
936 1 hiro
        if (!messageview->msginfo) return;
937 1 hiro
        msginfo = messageview->msginfo;
938 1 hiro
        Xstrdup_a(from, msginfo->from, return);
939 1 hiro
        eliminate_address_comment(from);
940 1 hiro
        extract_address(from);
941 1 hiro
        addressbook_add_contact(msginfo->fromname, from, NULL);
942 1 hiro
}
943 1 hiro
944 1 hiro
static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
945 1 hiro
{
946 1 hiro
        MessageView *messageview = (MessageView *)data;
947 1 hiro
        gchar *header = NULL;
948 1 hiro
        gchar *key = NULL;
949 1 hiro
950 1 hiro
        if (!messageview->msginfo) return;
951 1 hiro
952 547 hiro
        filter_get_keyword_from_msg(messageview->msginfo, &header, &key,
953 547 hiro
                                    (FilterCreateType)action);
954 1 hiro
        prefs_filter_open(messageview->msginfo, header);
955 1 hiro
956 1 hiro
        g_free(header);
957 1 hiro
        g_free(key);
958 1 hiro
}
959 1 hiro
960 1 hiro
static void about_cb(gpointer data, guint action, GtkWidget *widget)
961 1 hiro
{
962 1 hiro
        about_show();
963 1 hiro
}