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