0.8.11claws79
[claws.git] / src / messageview.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkvbox.h>
25 #include <gtk/gtkcontainer.h>
26 #include <gtk/gtkeditable.h>
27 #include <gtk/gtkwindow.h>
28 #include <gtk/gtktext.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <string.h>
34
35 #include "intl.h"
36 #include "main.h"
37 #include "messageview.h"
38 #include "message_search.h"
39 #include "headerview.h"
40 #include "summaryview.h"
41 #include "textview.h"
42 #include "mimeview.h"
43 #include "menu.h"
44 #include "about.h"
45 #include "filesel.h"
46 #include "sourcewindow.h"
47 #include "addressbook.h"
48 #include "alertpanel.h"
49 #include "inputdialog.h"
50 #include "manage_window.h"
51 #include "procmsg.h"
52 #include "procheader.h"
53 #include "procmime.h"
54 #include "account.h"
55 #include "prefs_common.h"
56 #include "prefs_account.h"
57 #include "gtkutils.h"
58 #include "utils.h"
59 #include "rfc2015.h"
60 #include "send_message.h"
61 #include "pgptext.h"
62 #include "stock_pixmap.h"
63
64
65 static void messageview_change_view_type(MessageView    *messageview,
66                                          MessageType     type);
67 static void messageview_destroy_cb      (GtkWidget      *widget,
68                                          MessageView    *messageview);
69 static void messageview_size_allocate_cb(GtkWidget      *widget,
70                                          GtkAllocation  *allocation);
71 static void key_pressed                 (GtkWidget      *widget,
72                                          GdkEventKey    *event,
73                                          MessageView    *messageview);
74
75 static void return_receipt_show         (NoticeView     *noticeview, 
76                                          MsgInfo        *msginfo);      
77 static void return_receipt_send_clicked (NoticeView     *noticeview, 
78                                          MsgInfo        *msginfo);
79 static void save_as_cb                  (gpointer        data,
80                                          guint           action,
81                                          GtkWidget      *widget);
82 static void print_cb                    (gpointer        data,
83                                          guint           action,
84                                          GtkWidget      *widget);
85 static void close_cb                    (gpointer        data,
86                                          guint           action,
87                                          GtkWidget      *widget);
88 static void copy_cb                     (gpointer        data,
89                                          guint           action,
90                                          GtkWidget      *widget);
91 static void allsel_cb                   (gpointer        data,
92                                          guint           action,
93                                          GtkWidget      *widget);
94 static void search_cb                   (gpointer        data,
95                                          guint           action,
96                                          GtkWidget      *widget);
97
98 static void set_charset_cb              (gpointer        data,
99                                          guint           action,
100                                          GtkWidget      *widget);
101 static void view_source_cb              (gpointer        data,
102                                          guint           action,
103                                          GtkWidget      *widget);
104 static void show_all_header_cb          (gpointer        data,
105                                          guint           action,
106                                          GtkWidget      *widget);
107
108 static void compose_cb                  (gpointer        data,
109                                          guint           action,
110                                          GtkWidget      *widget);
111 static void reply_cb                    (gpointer        data,
112                                          guint           action,
113                                          GtkWidget      *widget);
114 static void reedit_cb                   (gpointer        data,
115                                          guint           action,
116                                          GtkWidget      *widget);
117
118 static PrefsAccount *select_account_from_list
119                                         (GList          *ac_list);
120 static void addressbook_open_cb         (gpointer        data,
121                                          guint           action,
122                                          GtkWidget      *widget);
123 static void add_address_cb              (gpointer        data,
124                                          guint           action,
125                                          GtkWidget      *widget);
126 static void create_filter_cb            (gpointer        data,
127                                          guint           action,
128                                          GtkWidget      *widget);
129
130 static void messageview_menubar_cb      (MessageView    *msgview,
131                                          guint           action, 
132                                          GtkWidget      *widget);
133 static void about_cb                    (gpointer        data,
134                                          guint           action,
135                                          GtkWidget      *widget);
136 static void messageview_update          (MessageView *msgview);
137 static void messageview_update_all      (MessageView *msgview);
138
139 static GList *msgview_list = NULL;
140 static GtkItemFactoryEntry msgview_entries[] =
141 {
142         {N_("/_File"),                  NULL, NULL, 0, "<Branch>"},
143         {N_("/_File/_Save as..."),      NULL, save_as_cb, 0, NULL},
144         {N_("/_File/_Print..."),        NULL, print_cb, 0, NULL},
145         {N_("/_File/---"),              NULL, NULL, 0, "<Separator>"},
146         {N_("/_File/_Close"),           NULL, close_cb, 0, NULL},
147
148         {N_("/_Edit"),                  NULL, NULL, 0, "<Branch>"},
149         {N_("/_Edit/_Copy"),            NULL, copy_cb, 0, NULL},
150         {N_("/_Edit/Select _all"),      NULL, allsel_cb, 0, NULL},
151         {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
152         {N_("/_Edit/_Find in current message..."),
153                                         NULL, search_cb, 0, NULL},
154
155         {N_("/_View"),                  NULL, NULL, 0, "<Branch>"},
156
157 #define CODESET_SEPARATOR \
158         {N_("/_View/_Code set/---"),    NULL, NULL, 0, "<Separator>"}
159 #define CODESET_ACTION(action) \
160         NULL, set_charset_cb, action, "/View/Code set/Auto detect"
161
162         {N_("/_View/_Code set"),        NULL, NULL, 0, "<Branch>"},
163         {N_("/_View/_Code set/_Auto detect"),
164                                         NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
165         CODESET_SEPARATOR,
166         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
167          CODESET_ACTION(C_US_ASCII)},
168
169 #if HAVE_ICONV
170         {N_("/_View/_Code set/Unicode (_UTF-8)"),
171          CODESET_ACTION(C_UTF_8)},
172         CODESET_SEPARATOR,
173 #endif
174         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
175          CODESET_ACTION(C_ISO_8859_1)},
176         {N_("/_View/_Code set/Western European (ISO-8859-15)"),
177          CODESET_ACTION(C_ISO_8859_15)},
178         CODESET_SEPARATOR,
179 #if HAVE_ICONV
180         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
181          CODESET_ACTION(C_ISO_8859_2)},
182         CODESET_SEPARATOR,
183         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
184          CODESET_ACTION(C_ISO_8859_13)},
185         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
186          CODESET_ACTION(C_ISO_8859_4)},
187         CODESET_SEPARATOR,
188         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
189          CODESET_ACTION(C_ISO_8859_7)},
190         CODESET_SEPARATOR,
191         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
192          CODESET_ACTION(C_ISO_8859_9)},
193         CODESET_SEPARATOR,
194         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
195          CODESET_ACTION(C_ISO_8859_5)},
196         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
197          CODESET_ACTION(C_KOI8_R)},
198         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
199          CODESET_ACTION(C_CP1251)},
200         CODESET_SEPARATOR,
201 #endif
202         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
203          CODESET_ACTION(C_ISO_2022_JP)},
204 #if HAVE_ICONV
205         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
206          CODESET_ACTION(C_ISO_2022_JP_2)},
207 #endif
208         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
209          CODESET_ACTION(C_EUC_JP)},
210         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
211          CODESET_ACTION(C_SHIFT_JIS)},
212 #if HAVE_ICONV
213         CODESET_SEPARATOR,
214         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
215          CODESET_ACTION(C_GB2312)},
216         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
217          CODESET_ACTION(C_BIG5)},
218         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
219          CODESET_ACTION(C_EUC_TW)},
220         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
221          CODESET_ACTION(C_ISO_2022_CN)},
222         CODESET_SEPARATOR,
223         {N_("/_View/_Code set/Korean (EUC-_KR)"),
224          CODESET_ACTION(C_EUC_KR)},
225         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
226          CODESET_ACTION(C_ISO_2022_KR)},
227         CODESET_SEPARATOR,
228         {N_("/_View/_Code set/Thai (TIS-620)"),
229          CODESET_ACTION(C_TIS_620)},
230         {N_("/_View/_Code set/Thai (Windows-874)"),
231          CODESET_ACTION(C_WINDOWS_874)},
232 #endif
233
234 #undef CODESET_SEPARATOR
235 #undef CODESET_ACTION
236
237         {N_("/_View/---"),              NULL, NULL, 0, "<Separator>"},
238         {N_("/_View/Mess_age source"),  NULL, view_source_cb, 0, NULL},
239         {N_("/_View/Show all _header"), NULL, show_all_header_cb, 0, "<ToggleItem>"},
240
241         {N_("/_Message"),               NULL, NULL, 0, "<Branch>"},
242         {N_("/_Message/Compose _new message"),
243                                         NULL, compose_cb, 0, NULL},
244         {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
245         {N_("/_Message/_Reply"),        NULL, reply_cb, COMPOSE_REPLY, NULL},
246         {N_("/_Message/Repl_y to/_all"),
247                                         NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
248         {N_("/_Message/Repl_y to/_sender"),
249                                         NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
250         {N_("/_Message/Repl_y to/mailing _list"),
251                                         NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
252         {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
253         {N_("/_Message/_Forward"),      NULL, reply_cb, COMPOSE_FORWARD, NULL},
254         {N_("/_Message/For_ward as attachment"),
255                                         NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
256         {N_("/_Message/Redirec_t"),     NULL, reply_cb, COMPOSE_REDIRECT, NULL},
257         {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
258         {N_("/_Message/Re-_edit"),      NULL, reedit_cb, 0, NULL},
259
260         {N_("/_Tools"),                 NULL, NULL, 0, "<Branch>"},
261         {N_("/_Tools/_Address book"),   NULL, addressbook_open_cb, 0, NULL},
262         {N_("/_Tools/Add sender to address boo_k"),
263                                         NULL, add_address_cb, 0, NULL},
264         {N_("/_Tools/---"),             NULL, NULL, 0, "<Separator>"},
265         {N_("/_Tools/_Create filter rule"),
266                                         NULL, NULL, 0, "<Branch>"},
267         {N_("/_Tools/_Create filter rule/_Automatically"),
268                                         NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
269         {N_("/_Tools/_Create filter rule/by _From"),
270                                         NULL, create_filter_cb, FILTER_BY_FROM, NULL},
271         {N_("/_Tools/_Create filter rule/by _To"),
272                                         NULL, create_filter_cb, FILTER_BY_TO, NULL},
273         {N_("/_Tools/_Create filter rule/by _Subject"),
274                                         NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
275
276         {N_("/_Help"),                  NULL, NULL, 0, "<Branch>"},
277         {N_("/_Help/_About"),           NULL, about_cb, 0, NULL}
278 };
279
280 MessageView *messageview_create(MainWindow *mainwin)
281 {
282         MessageView *messageview;
283         GtkWidget *vbox;
284         HeaderView *headerview;
285         TextView *textview;
286         MimeView *mimeview;
287         NoticeView *noticeview;
288
289         debug_print("Creating message view...\n");
290         messageview = g_new0(MessageView, 1);
291
292         messageview->type = MVIEW_TEXT;
293
294         headerview = headerview_create();
295
296         noticeview = noticeview_create(mainwin);
297
298         textview = textview_create();
299         textview->messageview = messageview;
300
301         mimeview = mimeview_create();
302         mimeview->textview = textview_create();
303         mimeview->textview->messageview = messageview;
304         mimeview->messageview = messageview;
305
306         vbox = gtk_vbox_new(FALSE, 0);
307         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
308                            FALSE, FALSE, 0);
309         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
310                            FALSE, FALSE, 0);
311         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(textview),
312                            TRUE, TRUE, 0);
313
314         /* to remove without destroyed */
315         gtk_widget_ref(GTK_WIDGET_PTR(textview));
316         gtk_widget_ref(GTK_WIDGET_PTR(mimeview));
317         gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
318
319         messageview->vbox       = vbox;
320         messageview->new_window = FALSE;
321         messageview->window     = NULL;
322         messageview->headerview = headerview;
323         messageview->textview   = textview;
324         messageview->mimeview   = mimeview;
325         messageview->noticeview = noticeview;
326         messageview->mainwin    = mainwin;
327
328         return messageview;
329 }
330
331
332 GList *messageview_get_msgview_list(void)
333 {
334         return msgview_list;
335 }
336
337 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window) 
338 {
339         GtkWidget *handlebox;
340         GtkWidget *vbox;
341         GtkWidget *menubar;
342         guint n_menu_entries;
343
344         vbox = gtk_vbox_new(FALSE, 0);
345         gtk_widget_show(vbox);
346         gtk_container_add(GTK_CONTAINER(window), vbox); 
347         
348         n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
349         menubar = menubar_create(window, msgview_entries,
350                                  n_menu_entries, "<MessageView>", msgview);
351         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
352
353         handlebox = gtk_handle_box_new();
354         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
355         msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
356                                           (gpointer)msgview);
357         msgview->handlebox = handlebox;
358         msgview->menubar   = menubar;
359
360         gtk_container_add(GTK_CONTAINER(vbox),
361                           GTK_WIDGET_PTR(msgview));
362
363         msgview_list = g_list_append(msgview_list, msgview);
364 }
365
366 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
367 {
368         GtkWidget *window;
369         MessageView *msgview;
370
371         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
372         gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
373         gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
374         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
375         gtk_widget_set_usize(window, prefs_common.msgwin_width,
376                              prefs_common.msgwin_height);
377
378         msgview = messageview_create(mainwin);
379
380         gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
381                            GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
382                            msgview);
383         gtk_signal_connect(GTK_OBJECT(window), "destroy",
384                            GTK_SIGNAL_FUNC(messageview_destroy_cb), msgview);
385         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
386                            GTK_SIGNAL_FUNC(key_pressed), msgview);
387
388         messageview_add_toolbar(msgview, window);
389
390         gtk_widget_grab_focus(msgview->textview->text);
391         gtk_widget_show_all(window);
392
393         msgview->new_window = TRUE;
394         msgview->window = window;
395         msgview->visible = TRUE;
396
397         toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox, 
398                           prefs_common.toolbar_style);
399         messageview_init(msgview);
400
401         return msgview;
402 }
403
404 void messageview_init(MessageView *messageview)
405 {
406         headerview_init(messageview->headerview);
407         textview_init(messageview->textview);
408         mimeview_init(messageview->mimeview);
409         /*messageview_set_font(messageview);*/
410
411         noticeview_hide(messageview->noticeview);
412 }
413
414 static void notification_convert_header(gchar *dest, gint len, 
415                                         const gchar *src_,
416                                         gint header_len)
417 {
418         char *src;
419
420         g_return_if_fail(src_ != NULL);
421         g_return_if_fail(dest != NULL);
422
423         if (len < 1) return;
424
425         Xstrndup_a(src, src_, len, return);
426
427         remove_return(src);
428
429         if (is_ascii_str(src)) {
430                 strncpy2(dest, src, len);
431                 dest[len - 1] = '\0';
432                 return;
433         } else
434                 conv_encode_header(dest, len, src, header_len);
435 }
436
437 static gint disposition_notification_queue(PrefsAccount * account,
438                                            gchar * to, const gchar *file)
439 {
440         FolderItem *queue;
441         gchar *tmp;
442         FILE *fp, *src_fp;
443         gchar buf[BUFFSIZE];
444         gint num;
445
446         debug_print("queueing message...\n");
447         g_return_val_if_fail(account != NULL, -1);
448
449         tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
450                               G_DIR_SEPARATOR, (gint)file);
451         if ((fp = fopen(tmp, "wb")) == NULL) {
452                 FILE_OP_ERROR(tmp, "fopen");
453                 g_free(tmp);
454                 return -1;
455         }
456         if ((src_fp = fopen(file, "rb")) == NULL) {
457                 FILE_OP_ERROR(file, "fopen");
458                 fclose(fp);
459                 unlink(tmp);
460                 g_free(tmp);
461                 return -1;
462         }
463         if (change_file_mode_rw(fp, tmp) < 0) {
464                 FILE_OP_ERROR(tmp, "chmod");
465                 g_warning("can't change file mode\n");
466         }
467
468         /* queueing variables */
469         fprintf(fp, "AF:\n");
470         fprintf(fp, "NF:0\n");
471         fprintf(fp, "PS:10\n");
472         fprintf(fp, "SRH:1\n");
473         fprintf(fp, "SFN:\n");
474         fprintf(fp, "DSR:\n");
475         fprintf(fp, "MID:\n");
476         fprintf(fp, "CFG:\n");
477         fprintf(fp, "PT:0\n");
478         fprintf(fp, "S:%s\n", account->address);
479         fprintf(fp, "RQ:\n");
480         if (account->smtp_server)
481                 fprintf(fp, "SSV:%s\n", account->smtp_server);
482         else
483                 fprintf(fp, "SSV:\n");
484         if (account->nntp_server)
485                 fprintf(fp, "NSV:%s\n", account->nntp_server);
486         else
487                 fprintf(fp, "NSV:\n");
488         fprintf(fp, "SSH:\n");
489         fprintf(fp, "R:<%s>", to);
490         fprintf(fp, "\n");
491         fprintf(fp, "\n");
492
493         while (fgets(buf, sizeof(buf), src_fp) != NULL) {
494                 if (fputs(buf, fp) == EOF) {
495                         FILE_OP_ERROR(tmp, "fputs");
496                         fclose(fp);
497                         fclose(src_fp);
498                         unlink(tmp);
499                         g_free(tmp);
500                         return -1;
501                 }
502         }
503
504         fclose(src_fp);
505         if (fclose(fp) == EOF) {
506                 FILE_OP_ERROR(tmp, "fclose");
507                 unlink(tmp);
508                 g_free(tmp);
509                 return -1;
510         }
511
512         queue = folder_get_default_queue();
513         if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
514                 g_warning("can't queue the message\n");
515                 unlink(tmp);
516                 g_free(tmp);
517                 return -1;
518         }
519         g_free(tmp);
520
521         return 0;
522 }
523
524 static gint disposition_notification_send(MsgInfo *msginfo)
525 {
526         gchar buf[BUFFSIZE];
527         gchar tmp[MAXPATHLEN + 1];
528         FILE *fp;
529         GSList *to_list;
530         GList *ac_list;
531         PrefsAccount *account;
532         gint ok;
533         gchar *to;
534
535         if ((!msginfo->returnreceiptto) && 
536             (!msginfo->dispositionnotificationto)) 
537                 return -1;
538
539         /* RFC2298: Test for Return-Path */
540         if (msginfo->dispositionnotificationto)
541                 to = msginfo->dispositionnotificationto;
542         else
543                 to = msginfo->returnreceiptto;
544
545         ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
546                                 "Return-Path:");
547         if (ok == 0) {
548                 gchar *to_addr = g_strdup(to);
549                 extract_address(to_addr);
550                 extract_address(buf);
551                 ok = strcmp(to_addr, buf);
552                 g_free(to_addr);
553         } else {
554                 strncpy(buf, _("<No Return-Path found>"), 
555                                 sizeof(buf));
556         }
557         
558         if (ok != 0) {
559                 AlertValue val;
560                 gchar *message;
561                 message = g_strdup_printf(
562                                  _("The notification address to which the "
563                                    "return receipt is to be sent\n"
564                                    "does not correspond to the return path:\n"
565                                    "Notification address: %s\n"
566                                    "Return path: %s\n"
567                                    "It is advised to not to send the return "
568                                    "receipt."), to, buf);
569                 val = alertpanel(_("Warning"), message, _("Send"),
570                                 _("+Don't Send"), NULL);
571                 if (val != G_ALERTDEFAULT)
572                         return -1;
573         }
574
575         ac_list = account_find_all_from_address(NULL, msginfo->to);
576         ac_list = account_find_all_from_address(ac_list, msginfo->cc);
577
578         if (ac_list == NULL) {
579                 alertpanel_error(_("This message is asking for a return "
580                                    "receipt notification\n"
581                                    "but according to its 'To:' and 'CC:' "
582                                    "headers it was not\nofficially addressed "
583                                    "to you.\n"
584                                    "Receipt notification cancelled."));
585                 return -1;
586         }
587
588         if (g_list_length(ac_list) > 1)
589                 account = select_account_from_list(ac_list);
590         else
591                 account = (PrefsAccount *) ac_list->data;
592         g_list_free(ac_list);
593
594         if (account == NULL)
595                 return -1;
596
597         /* write to temporary file */
598         g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
599                    get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
600
601         if ((fp = fopen(tmp, "wb")) == NULL) {
602                 FILE_OP_ERROR(tmp, "fopen");
603                 return -1;
604         }
605
606         /* chmod for security */
607         if (change_file_mode_rw(fp, tmp) < 0) {
608                 FILE_OP_ERROR(tmp, "chmod");
609                 g_warning("can't change file mode\n");
610         }
611
612         /* Date */
613         get_rfc822_date(buf, sizeof(buf));
614         fprintf(fp, "Date: %s\n", buf);
615
616         /* From */
617         if (account->name && *account->name) {
618                 notification_convert_header
619                         (buf, sizeof(buf), account->name,
620                          strlen("From: "));
621                 fprintf(fp, "From: %s <%s>\n", buf, account->address);
622         } else
623                 fprintf(fp, "From: %s\n", account->address);
624
625         fprintf(fp, "To: %s\n", to);
626
627         /* Subject */
628         notification_convert_header(buf, sizeof(buf), msginfo->subject,
629                                     strlen("Subject: "));
630         fprintf(fp, "Subject: Disposition notification: %s\n", buf);
631
632         if (fclose(fp) == EOF) {
633                 FILE_OP_ERROR(tmp, "fclose");
634                 unlink(tmp);
635                 return -1;
636         }
637
638         to_list = address_list_append(NULL, to);
639         ok = send_message(tmp, account, to_list);
640         
641         if (ok < 0) {
642                 if (prefs_common.queue_msg) {
643                         AlertValue val;
644                         
645                         val = alertpanel
646                                 (_("Queueing"),
647                                  _("Error occurred while sending the notification.\n"
648                                    "Put this notification into queue folder?"),
649                                  _("OK"), _("Cancel"), NULL);
650                         if (G_ALERTDEFAULT == val) {
651                                 ok = disposition_notification_queue(account, to, tmp);
652                                 if (ok < 0)
653                                         alertpanel_error(_("Can't queue the notification."));
654                         }
655                 } else
656                         alertpanel_error_log(_("Error occurred while sending the notification."));
657         }
658
659         if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
660
661         return ok;
662 }
663
664 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
665                       gboolean all_headers)
666 {
667         FILE *fp;
668         gchar *file;
669         MimeInfo *mimeinfo;
670
671         g_return_if_fail(msginfo != NULL);
672
673 #if USE_GPGME
674         if ((fp = procmsg_open_message_decrypted(msginfo, &mimeinfo)) == NULL)
675                 return;
676 #else /* !USE_GPGME */
677         if ((fp = procmsg_open_message(msginfo)) == NULL) return;
678         mimeinfo = procmime_scan_mime_header(fp);
679 #endif /* USE_GPGME */
680         fclose(fp);
681         if (!mimeinfo) return;
682
683         file = procmsg_get_message_file_path(msginfo);
684         if (!file) {
685                 g_warning("can't get message file path.\n");
686                 procmime_mimeinfo_free_all(mimeinfo);
687                 return;
688         }
689
690         if (messageview->msginfo != msginfo) {
691                 procmsg_msginfo_free(messageview->msginfo);
692                 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
693         }
694         headerview_show(messageview->headerview, messageview->msginfo);
695
696         messageview->all_headers = all_headers;
697         textview_set_all_headers(messageview->textview, all_headers);
698         textview_set_all_headers(messageview->mimeview->textview, all_headers);
699
700         if (mimeinfo->mime_type != MIME_TEXT &&
701             mimeinfo->mime_type != MIME_TEXT_HTML) {
702                 messageview_change_view_type(messageview, MVIEW_MIME);
703                 mimeview_show_message(messageview->mimeview, mimeinfo, file);
704         } else {
705                 messageview_change_view_type(messageview, MVIEW_TEXT);
706                 textview_show_message(messageview->textview, mimeinfo, file);
707                 procmime_mimeinfo_free_all(mimeinfo);
708         }
709
710         if (MSG_IS_RETRCPT_PENDING(msginfo->flags))
711                 return_receipt_show(messageview->noticeview, msginfo);
712         else 
713                 noticeview_hide(messageview->noticeview);
714
715         g_free(file);
716 }
717
718 static void messageview_change_view_type(MessageView *messageview,
719                                          MessageType type)
720 {
721         TextView *textview = messageview->textview;
722         MimeView *mimeview = messageview->mimeview;
723
724         if (messageview->type == type) return;
725
726         if (type == MVIEW_MIME) {
727                 gtkut_container_remove
728                         (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
729                          GTK_WIDGET_PTR(textview));
730                 gtk_box_pack_start(GTK_BOX(messageview->vbox),
731                                    GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
732                 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
733                                   GTK_WIDGET_PTR(textview));
734         } else if (type == MVIEW_TEXT) {
735                 gtkut_container_remove
736                         (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
737                          GTK_WIDGET_PTR(mimeview));
738
739                 if (mimeview->vbox == GTK_WIDGET_PTR(textview)->parent)
740                         gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
741                                                GTK_WIDGET_PTR(textview));
742
743                 gtk_box_pack_start(GTK_BOX(messageview->vbox),
744                                    GTK_WIDGET_PTR(textview), TRUE, TRUE, 0);
745         } else
746                 return;
747
748         messageview->type = type;
749 }
750
751 void messageview_reflect_prefs_pixmap_theme(void)
752 {
753         GList *cur;
754         MessageView *msgview;
755
756         for (cur = msgview_list; cur != NULL; cur = cur->next) {
757                 msgview = (MessageView*)cur->data;
758                 toolbar_update(TOOLBAR_MSGVIEW, msgview);
759         }
760 }
761
762 void messageview_clear(MessageView *messageview)
763 {
764         procmsg_msginfo_free(messageview->msginfo);
765         messageview->msginfo = NULL;
766         messageview_change_view_type(messageview, MVIEW_TEXT);
767         headerview_clear(messageview->headerview);
768         textview_clear(messageview->textview);
769         noticeview_hide(messageview->noticeview);
770 }
771
772 void messageview_destroy(MessageView *messageview)
773 {
774         GtkWidget *textview  = GTK_WIDGET_PTR(messageview->textview);
775         GtkWidget *mimeview  = GTK_WIDGET_PTR(messageview->mimeview);
776
777         debug_print("destroy messageview\n");
778         headerview_destroy(messageview->headerview);
779         textview_destroy(messageview->textview);
780         mimeview_destroy(messageview->mimeview);
781         noticeview_destroy(messageview->noticeview);
782
783         procmsg_msginfo_free(messageview->msginfo);
784         toolbar_clear_list(TOOLBAR_MSGVIEW);
785         if (messageview->toolbar) {
786                 toolbar_destroy(messageview->toolbar);
787                 g_free(messageview->toolbar);
788         }
789         
790         msgview_list = g_list_remove(msgview_list, messageview); 
791
792         g_free(messageview);
793
794         gtk_widget_unref(textview);
795         gtk_widget_unref(mimeview);
796 }
797
798 void messageview_delete(MessageView *msgview)
799 {
800         MsgInfo *msginfo = (MsgInfo*)msgview->msginfo;
801         SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
802         FolderItem *trash = folder_get_default_trash();
803         GSList *msg_list;
804
805         g_return_if_fail(msginfo != NULL);
806         g_return_if_fail(trash   != NULL);
807         
808         msg_list = folder_item_get_msg_list(msginfo->folder);
809         
810         if (msg_list == NULL) {
811                 alertpanel_error(_("Message already removed from folder."));
812                 return;
813         }
814         
815         for (; msg_list != NULL; msg_list = msg_list->next) {
816                 MsgInfo *msginfo_list = (MsgInfo*)msg_list->data;
817                 
818                 if (msginfo->msgnum == msginfo_list->msgnum) {
819
820                         if (prefs_common.immediate_exec)
821                                 folder_item_move_msg(trash, msginfo);
822                         else {
823                                 procmsg_msginfo_set_to_folder(msginfo, trash);
824                                 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
825                                 /* NOTE: does not update to next message in summaryview
826                                  */
827                         }
828                                 
829                         messageview_update_all(msgview);
830                         break;
831                 }
832         }
833 }
834
835 /*      
836  * scan List of MessageViews checking whether there are any Views holding messages 
837  * which need to be updated (another view might have deleted the one this MessagView holds)
838  */
839 static void messageview_update_all(MessageView *msgview)
840 {
841         MsgInfo *msginfo = (MsgInfo*)msgview->msginfo;
842         GList *cur;
843         
844         g_return_if_fail(msginfo != NULL);
845
846         for (cur = msgview_list; cur != NULL; cur = cur->next) {
847                 MessageView *msgview = (MessageView*)cur->data;
848                 MsgInfo *msginfo_list = (MsgInfo*)msgview->msginfo;
849                 
850                 g_return_if_fail(msginfo != NULL);
851
852                 if (msginfo->msgnum == msginfo_list->msgnum)
853                         messageview_update(msgview);
854         }
855 }
856
857 /* 
858  * \brief update messageview with currently selected message in summaryview
859  *        leave unchanged if summaryview is empty
860  * \param pointer to MessageView
861  */     
862 static void messageview_update(MessageView *msgview)
863 {
864         SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
865
866         g_return_if_fail(summaryview != NULL);
867         
868         if (summaryview->selected) {
869                 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
870                 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree, 
871                                                       summaryview->selected);
872                 g_return_if_fail(msginfo != NULL);
873
874                 messageview_show(msgview, msginfo, 
875                                  msgview->all_headers);
876         } 
877 }
878
879 void messageview_quote_color_set(void)
880 {
881 }
882
883 void messageview_set_font(MessageView *messageview)
884 {
885         textview_set_font(messageview->textview, NULL);
886 }
887
888 TextView *messageview_get_current_textview(MessageView *messageview)
889 {
890         TextView *text = NULL;
891
892         if (messageview->type == MVIEW_TEXT)
893                 text = messageview->textview;
894         else if (messageview->type == MVIEW_MIME) {
895                 if (gtk_notebook_get_current_page
896                         (GTK_NOTEBOOK(messageview->mimeview->notebook)) == 0)
897                         text = messageview->textview;
898                 else if (messageview->mimeview->type == MIMEVIEW_TEXT)
899                         text = messageview->mimeview->textview;
900         }
901
902         return text;
903 }
904
905 void messageview_copy_clipboard(MessageView *messageview)
906 {
907         TextView *text;
908
909         text = messageview_get_current_textview(messageview);
910         if (text)
911                 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
912 }
913
914 void messageview_select_all(MessageView *messageview)
915 {
916         TextView *text;
917
918         text = messageview_get_current_textview(messageview);
919         if (text)
920                 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
921 }
922
923 void messageview_set_position(MessageView *messageview, gint pos)
924 {
925         textview_set_position(messageview->textview, pos);
926 }
927
928 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
929                                    gboolean case_sens)
930 {
931         return textview_search_string(messageview->textview, str, case_sens);
932         return FALSE;
933 }
934
935 gboolean messageview_search_string_backward(MessageView *messageview,
936                                             const gchar *str,
937                                             gboolean case_sens)
938 {
939         return textview_search_string_backward(messageview->textview,
940                                                str, case_sens);
941         return FALSE;
942 }
943
944 gboolean messageview_is_visible(MessageView *messageview)
945 {
946         return messageview->visible;
947 }
948
949 void messageview_save_as(MessageView *messageview)
950 {
951         gchar *filename = NULL;
952         MsgInfo *msginfo;
953         gchar *src, *dest;
954
955         if (!messageview->msginfo) return;
956         msginfo = messageview->msginfo;
957
958         if (msginfo->subject) {
959                 Xstrdup_a(filename, msginfo->subject, return);
960                 subst_for_filename(filename);
961         }
962         dest = filesel_select_file(_("Save as"), filename);
963         if (!dest) return;
964         if (is_file_exist(dest)) {
965                 AlertValue aval;
966
967                 aval = alertpanel(_("Overwrite"),
968                                   _("Overwrite existing file?"),
969                                   _("OK"), _("Cancel"), NULL);
970                 if (G_ALERTDEFAULT != aval) return;
971         }
972
973         src = procmsg_get_message_file(msginfo);
974         if (copy_file(src, dest, TRUE) < 0) {
975                 alertpanel_error(_("Can't save the file `%s'."),
976                                  g_basename(dest));
977         }
978         g_free(src);
979 }
980
981 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
982 {
983         messageview_destroy(messageview);
984 }
985
986 static void messageview_size_allocate_cb(GtkWidget *widget,
987                                          GtkAllocation *allocation)
988 {
989         g_return_if_fail(allocation != NULL);
990
991         prefs_common.msgwin_width  = allocation->width;
992         prefs_common.msgwin_height = allocation->height;
993 }
994
995 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
996                         MessageView *messageview)
997 {
998         if (event && event->keyval == GDK_Escape && messageview->window)
999                 gtk_widget_destroy(messageview->window);
1000 }
1001
1002 void messageview_toggle_view_real(MessageView *messageview)
1003 {
1004         MainWindow *mainwin = messageview->mainwin;
1005         union CompositeWin *cwin = &mainwin->win;
1006         GtkWidget *vpaned = NULL;
1007         GtkWidget *container = NULL;
1008         GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1009         
1010         switch (mainwin->type) {
1011         case SEPARATE_NONE:
1012                 vpaned = cwin->sep_none.vpaned;
1013                 container = cwin->sep_none.hpaned;
1014                 break;
1015         case SEPARATE_FOLDER:
1016                 vpaned = cwin->sep_folder.vpaned;
1017                 container = mainwin->vbox_body;
1018                 break;
1019         case SEPARATE_MESSAGE:
1020         case SEPARATE_BOTH:
1021                 return;
1022         }
1023
1024         if (vpaned->parent != NULL) {
1025                 gtk_widget_ref(vpaned);
1026                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1027                 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
1028                 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
1029                 gtk_widget_grab_focus(GTK_WIDGET(messageview->textview->text));
1030         } else {
1031                 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
1032                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1033                 gtk_widget_unref(vpaned);
1034                 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
1035                 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
1036         }
1037 }
1038
1039 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
1040 {
1041         noticeview_set_text(noticeview, _("This messages asks for a return receipt."));
1042         noticeview_set_button_text(noticeview, _("Send receipt"));
1043         noticeview_set_button_press_callback(noticeview,
1044                                              GTK_SIGNAL_FUNC(return_receipt_send_clicked),
1045                                              (gpointer) msginfo);
1046         noticeview_show(noticeview);
1047 }
1048
1049 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1050 {
1051         MsgInfo *tmpmsginfo;
1052         gchar *file;
1053
1054         file = procmsg_get_message_file_path(msginfo);
1055         if (!file) {
1056                 g_warning("can't get message file path.\n");
1057                 return;
1058         }
1059
1060         tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1061         tmpmsginfo->folder = msginfo->folder;
1062         tmpmsginfo->msgnum = msginfo->msgnum;
1063
1064         if (disposition_notification_send(tmpmsginfo) >= 0) {
1065                 procmsg_msginfo_unset_flags(msginfo, MSG_RETRCPT_PENDING, 0);
1066                 noticeview_hide(noticeview);
1067         }               
1068
1069         procmsg_msginfo_free(tmpmsginfo);
1070         g_free(file);
1071 }
1072
1073 static void select_account_cb(GtkWidget *w, gpointer data)
1074 {
1075         *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
1076 }
1077         
1078 static PrefsAccount *select_account_from_list(GList *ac_list)
1079 {
1080         GtkWidget *optmenu;
1081         GtkWidget *menu;
1082         gint account_id;
1083
1084         g_return_val_if_fail(ac_list != NULL, NULL);
1085         g_return_val_if_fail(ac_list->data != NULL, NULL);
1086         
1087         optmenu = gtk_option_menu_new();
1088         menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
1089         if (!menu)
1090                 return NULL;
1091         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1092         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1093         account_id = ((PrefsAccount *) ac_list->data)->account_id;
1094         if (alertpanel_with_widget(
1095                                 _("Return Receipt Notification"),
1096                                 _("The message was sent to several of your "
1097                                   "accounts.\n"
1098                                   "Please choose which account do you want to "
1099                                   "use for sending the receipt notification:"),
1100                                 _("Send Notification"), _("+Cancel"), NULL,
1101                                 optmenu) != G_ALERTDEFAULT)
1102                 return NULL;
1103         return account_find_from_id(account_id);
1104 }
1105
1106
1107 /* 
1108  * \brief return selected messageview text used by composing 
1109  *        to reply to selected text only
1110  *
1111  * \param  pointer to Messageview 
1112  *
1113  * \return pointer to text (needs to be free'd by calling func)
1114  */
1115 gchar *messageview_get_selection(MessageView *msgview)
1116 {
1117         gchar *text = NULL;
1118         
1119         g_return_val_if_fail(msgview != NULL, NULL);
1120
1121         text = gtkut_editable_get_selection
1122                 (GTK_EDITABLE(msgview->textview->text));
1123         
1124         if (!text && msgview->type == MVIEW_MIME
1125             && msgview->mimeview->type == MIMEVIEW_TEXT
1126             && msgview->mimeview->textview
1127             && !msgview->mimeview->textview->default_text) {
1128                 text = gtkut_editable_get_selection 
1129                         (GTK_EDITABLE(msgview->mimeview->textview->text));   
1130         }
1131
1132         return text;
1133 }
1134
1135 static void messageview_delete_cb(MessageView *msgview, guint action, GtkWidget *widget)
1136 {
1137         messageview_delete(msgview);
1138 }
1139
1140 static void messageview_menubar_cb(MessageView *msgview, guint action, GtkWidget *widget)
1141 {
1142         GSList *msginfo_list = NULL;
1143         gchar *body;
1144         MsgInfo *msginfo;
1145
1146         g_return_if_fail(msgview != NULL);
1147
1148         msginfo = (MsgInfo*)msgview->msginfo;
1149         g_return_if_fail(msginfo != NULL);
1150
1151         msginfo_list = g_slist_append(msginfo_list, msginfo);
1152         g_return_if_fail(msginfo_list);
1153
1154         body =  messageview_get_selection(msgview);
1155         compose_reply_mode((ComposeMode)action, msginfo_list, body);
1156         g_free(body);
1157         g_slist_free(msginfo_list);
1158 }
1159
1160 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1161 {
1162         MessageView *messageview = (MessageView *)data;
1163         messageview_save_as(messageview);
1164 }
1165
1166 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1167 {
1168         MessageView *messageview = (MessageView *)data;
1169         gchar *cmdline;
1170         gchar *p;
1171
1172         if (!messageview->msginfo) return;
1173
1174         cmdline = input_dialog(_("Print"),
1175                                _("Enter the print command line:\n"
1176                                  "(`%s' will be replaced with file name)"),
1177                                prefs_common.print_cmd);
1178         if (!cmdline) return;
1179         if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1180             strchr(p + 2, '%')) {
1181                 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1182                                  cmdline);
1183                 g_free(cmdline);
1184                 return;
1185         }
1186
1187         procmsg_print_message(messageview->msginfo, cmdline);
1188         g_free(cmdline);
1189 }
1190
1191 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1192 {
1193         MessageView *messageview = (MessageView *)data;
1194         gtk_widget_destroy(messageview->window);
1195 }
1196
1197 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1198 {
1199         MessageView *messageview = (MessageView *)data;
1200         messageview_copy_clipboard(messageview);
1201 }
1202
1203 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1204 {
1205         MessageView *messageview = (MessageView *)data;
1206         messageview_select_all(messageview);
1207 }
1208
1209 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1210 {
1211         MessageView *messageview = (MessageView *)data;
1212         message_search(messageview);
1213 }
1214
1215 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1216 {
1217         MessageView *messageview = (MessageView *)data;
1218         const gchar *charset;
1219
1220         if (GTK_CHECK_MENU_ITEM(widget)->active) {
1221                 charset = conv_get_charset_str((CharSet)action);
1222                 g_free(messageview->forced_charset);
1223                 messageview->forced_charset = g_strdup(charset);
1224                 messageview_show(messageview, messageview->msginfo, FALSE);
1225         }
1226 }
1227
1228 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1229 {
1230         MessageView *messageview = (MessageView *)data;
1231         SourceWindow *srcwin;
1232
1233         if (!messageview->msginfo) return;
1234
1235         srcwin = source_window_create();
1236         source_window_show_msg(srcwin, messageview->msginfo);
1237         source_window_show(srcwin);
1238 }
1239
1240 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1241 {
1242         MessageView *messageview = (MessageView *)data;
1243         MsgInfo *msginfo = messageview->msginfo;
1244
1245         if (!msginfo) return;
1246         messageview->msginfo = NULL;
1247         messageview_show(messageview, msginfo,
1248                          GTK_CHECK_MENU_ITEM(widget)->active);
1249         procmsg_msginfo_free(msginfo);
1250 }
1251
1252 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1253 {
1254         MessageView *messageview = (MessageView *)data;
1255         PrefsAccount *ac = NULL;
1256         FolderItem *item = NULL;
1257
1258         if (messageview->msginfo)
1259                 item = messageview->msginfo->folder;
1260
1261         if (item) {
1262                 ac = account_find_from_item(item);
1263                 if (ac && ac->protocol == A_NNTP &&
1264                     item->stype == F_NEWS) {
1265                         compose_new(ac, item->path, NULL);
1266                         return;
1267                 }
1268         }
1269
1270         compose_new(ac, NULL, NULL);
1271 }
1272
1273 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1274 {
1275         MessageView *messageview = (MessageView *)data;
1276         GSList *mlist = NULL;
1277         MsgInfo *msginfo;
1278         gchar *text = NULL;
1279         ComposeMode mode = (ComposeMode)action;
1280
1281         msginfo = messageview->msginfo;
1282         mlist = g_slist_append(NULL, msginfo);
1283
1284         text = gtkut_editable_get_selection
1285                 (GTK_EDITABLE(messageview->textview->text));
1286         if (text && *text == '\0') {
1287                 g_free(text);
1288                 text = NULL;
1289         }
1290
1291         switch (mode) {
1292         case COMPOSE_REPLY:
1293                 compose_reply(msginfo, prefs_common.reply_with_quote,
1294                               FALSE, prefs_common.default_reply_list, FALSE, text);
1295                 break;
1296         case COMPOSE_REPLY_WITH_QUOTE:
1297                 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
1298                 break;
1299         case COMPOSE_REPLY_WITHOUT_QUOTE:
1300                 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
1301                 break;
1302         case COMPOSE_REPLY_TO_SENDER:
1303                 compose_reply(msginfo, prefs_common.reply_with_quote,
1304                               FALSE, FALSE, TRUE, text);
1305                 break;
1306         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1307                 compose_followup_and_reply_to(msginfo,
1308                                               prefs_common.reply_with_quote,
1309                                               FALSE, FALSE, text);
1310                 break;
1311         case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1312                 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
1313                 break;
1314         case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1315                 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1316                 break;
1317         case COMPOSE_REPLY_TO_ALL:
1318                 compose_reply(msginfo, prefs_common.reply_with_quote,
1319                               TRUE, FALSE, FALSE, text);
1320                 break;
1321         case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1322                 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
1323                 break;
1324         case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1325                 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1326                 break;
1327         case COMPOSE_REPLY_TO_LIST:
1328                 compose_reply(msginfo, prefs_common.reply_with_quote,
1329                               FALSE, TRUE, FALSE, text);
1330                 break;
1331         case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1332                 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
1333                 break;
1334         case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1335                 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1336                 break;
1337         case COMPOSE_FORWARD:
1338                 if (prefs_common.forward_as_attachment) {
1339                         compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, mlist, text);
1340                         return;
1341                 } else {
1342                         compose_reply_mode(COMPOSE_FORWARD_INLINE, mlist, text);
1343                         return;
1344                 }
1345                 break;
1346         case COMPOSE_FORWARD_INLINE:
1347                 compose_forward(NULL, msginfo, FALSE, text);
1348                 break;
1349         case COMPOSE_FORWARD_AS_ATTACH:
1350                 compose_forward_multiple(NULL, mlist);
1351                 break;
1352         case COMPOSE_REDIRECT:
1353                 compose_redirect(NULL, msginfo);
1354                 break;
1355         default:
1356                 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1357         }
1358
1359         /* summary_set_marks_selected(summaryview); */
1360         g_free(text);
1361         g_slist_free(mlist);
1362 }
1363
1364 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1365 {
1366         MessageView *messageview = (MessageView *)data;
1367         MsgInfo *msginfo;
1368
1369         if (!messageview->msginfo) return;
1370         msginfo = messageview->msginfo;
1371         if (!msginfo->folder) return;
1372         if (msginfo->folder->stype != F_OUTBOX &&
1373             msginfo->folder->stype != F_DRAFT &&
1374             msginfo->folder->stype != F_QUEUE) return;
1375
1376         compose_reedit(msginfo);
1377 }
1378
1379 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1380 {
1381         addressbook_open(NULL);
1382 }
1383
1384 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1385 {
1386         MessageView *messageview = (MessageView *)data;
1387         MsgInfo *msginfo;
1388         gchar *from;
1389
1390         if (!messageview->msginfo) return;
1391         msginfo = messageview->msginfo;
1392         Xstrdup_a(from, msginfo->from, return);
1393         eliminate_address_comment(from);
1394         extract_address(from);
1395         addressbook_add_contact(msginfo->fromname, from, NULL);
1396 }
1397
1398 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1399 {
1400         MessageView *messageview = (MessageView *)data;
1401         gchar *header = NULL;
1402         gchar *key = NULL;
1403
1404         if (!messageview->msginfo) return;
1405
1406         procmsg_get_filter_keyword(messageview->msginfo, &header, &key,
1407                                    (PrefsFilterType)action);
1408         prefs_filtering_open(NULL, header, key);
1409
1410         g_free(header);
1411         g_free(key);
1412 }
1413
1414 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1415 {
1416         about_show();
1417 }