sync 099claws
[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 "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 gboolean 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         messageview->msginfo_update_callback_id =
330                 hooks_register_hook(MSGINFO_UPDATE_HOOKLIST, messageview_update_msg, (gpointer) messageview);
331
332         return messageview;
333 }
334
335
336 GList *messageview_get_msgview_list(void)
337 {
338         return msgview_list;
339 }
340
341 void messageview_update_actions_menu(MessageView *msgview)
342 {
343         GtkItemFactory *ifactory;
344
345         /* Messages opened in a new window do not have a menu bar */
346         if (msgview->menubar == NULL)
347                 return;
348         ifactory = gtk_item_factory_from_widget(msgview->menubar);
349         action_update_msgview_menu(ifactory, "/Tools/Actions", msgview);
350 }
351
352 void messageview_add_toolbar(MessageView *msgview, GtkWidget *window) 
353 {
354         GtkWidget *handlebox;
355         GtkWidget *vbox;
356         GtkWidget *menubar;
357         GtkItemFactory *ifactory;
358         guint n_menu_entries;
359
360         vbox = gtk_vbox_new(FALSE, 0);
361         gtk_widget_show(vbox);
362         gtk_container_add(GTK_CONTAINER(window), vbox); 
363         
364         n_menu_entries = sizeof(msgview_entries) / sizeof(msgview_entries[0]);
365         menubar = menubar_create(window, msgview_entries,
366                                  n_menu_entries, "<MessageView>", msgview);
367         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
368
369         handlebox = gtk_handle_box_new();
370         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
371         msgview->toolbar = toolbar_create(TOOLBAR_MSGVIEW, handlebox,
372                                           (gpointer)msgview);
373         msgview->handlebox = handlebox;
374         msgview->menubar   = menubar;
375
376         gtk_container_add(GTK_CONTAINER(vbox),
377                           GTK_WIDGET_PTR(msgview));
378
379         messageview_update_actions_menu(msgview);
380
381         msgview_list = g_list_append(msgview_list, msgview);
382 }
383
384 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
385 {
386         GtkWidget *window;
387         MessageView *msgview;
388
389         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
390         gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
391         gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
392         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
393         gtk_widget_set_size_request(window, prefs_common.msgwin_width,
394                                     prefs_common.msgwin_height);
395
396         msgview = messageview_create(mainwin);
397
398         g_signal_connect(G_OBJECT(window), "size_allocate",
399                          G_CALLBACK(messageview_size_allocate_cb),
400                          msgview);
401         g_signal_connect(G_OBJECT(window), "destroy",
402                          G_CALLBACK(messageview_destroy_cb), msgview);
403         g_signal_connect(G_OBJECT(window), "key_press_event",
404                          G_CALLBACK(key_pressed), msgview);
405
406         messageview_add_toolbar(msgview, window);
407
408         gtk_widget_grab_focus(msgview->mimeview->textview->text);
409         gtk_widget_show(window);
410
411         msgview->new_window = TRUE;
412         msgview->window = window;
413         msgview->visible = TRUE;
414
415         toolbar_set_style(msgview->toolbar->toolbar, msgview->handlebox, 
416                           prefs_common.toolbar_style);
417         messageview_init(msgview);
418
419         return msgview;
420 }
421
422 void messageview_init(MessageView *messageview)
423 {
424         headerview_init(messageview->headerview);
425         mimeview_init(messageview->mimeview);
426         /*messageview_set_font(messageview);*/
427
428         noticeview_hide(messageview->noticeview);
429 }
430
431 static void notification_convert_header(gchar *dest, gint len, 
432                                         const gchar *src_,
433                                         gint header_len)
434 {
435         char *src;
436
437         g_return_if_fail(src_ != NULL);
438         g_return_if_fail(dest != NULL);
439
440         if (len < 1) return;
441
442         Xstrndup_a(src, src_, len, return);
443
444         remove_return(src);
445
446         if (is_ascii_str(src)) {
447                 strncpy2(dest, src, len);
448                 dest[len - 1] = '\0';
449                 return;
450         } else
451                 conv_encode_header(dest, len, src, header_len, FALSE);
452 }
453
454 static gint disposition_notification_send(MsgInfo *msginfo)
455 {
456         gchar buf[BUFFSIZE];
457         gchar tmp[MAXPATHLEN + 1];
458         FILE *fp;
459         GList *ac_list;
460         PrefsAccount *account;
461         gint ok;
462         gchar *to;
463         FolderItem *queue, *outbox;
464         gint num;
465         gchar *path;
466         gchar *addr;
467         gchar *addrp;
468
469         if ((!msginfo->returnreceiptto) && 
470             (!msginfo->dispositionnotificationto)) 
471                 return -1;
472
473         /* RFC2298: Test for Return-Path */
474         if (msginfo->dispositionnotificationto)
475                 to = msginfo->dispositionnotificationto;
476         else
477                 to = msginfo->returnreceiptto;
478
479         ok = procheader_get_header_from_msginfo(msginfo, buf, sizeof(buf),
480                                 "Return-Path:");
481         if (ok == 0) {
482                 gchar *to_addr = g_strdup(to);
483                 extract_address(to_addr);
484                 extract_address(buf);
485                 ok = strcmp(to_addr, buf);
486                 g_free(to_addr);
487         } else {
488                 strncpy(buf, _("<No Return-Path found>"), 
489                                 sizeof(buf));
490         }
491         
492         if (ok != 0) {
493                 AlertValue val;
494                 gchar *message;
495                 message = g_strdup_printf(
496                                  _("The notification address to which the "
497                                    "return receipt is to be sent\n"
498                                    "does not correspond to the return path:\n"
499                                    "Notification address: %s\n"
500                                    "Return path: %s\n"
501                                    "It is advised to not to send the return "
502                                    "receipt."), to, buf);
503                 val = alertpanel(_("Warning"), message, _("Send"),
504                                 _("+Don't Send"), NULL);
505                 g_free(message);                                
506                 if (val != G_ALERTDEFAULT)
507                         return -1;
508         }
509
510         ac_list = account_find_all_from_address(NULL, msginfo->to);
511         ac_list = account_find_all_from_address(ac_list, msginfo->cc);
512
513         if (ac_list == NULL) {
514                 alertpanel_error(_("This message is asking for a return "
515                                    "receipt notification\n"
516                                    "but according to its 'To:' and 'CC:' "
517                                    "headers it was not\nofficially addressed "
518                                    "to you.\n"
519                                    "Receipt notification cancelled."));
520                 return -1;
521         }
522
523         if (g_list_length(ac_list) > 1)
524                 account = select_account_from_list(ac_list);
525         else
526                 account = (PrefsAccount *) ac_list->data;
527         g_list_free(ac_list);
528
529         if (account == NULL)
530                 return -1;
531
532         /* write to temporary file */
533         g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
534                    get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
535
536         if ((fp = fopen(tmp, "wb")) == NULL) {
537                 FILE_OP_ERROR(tmp, "fopen");
538                 return -1;
539         }
540
541         /* chmod for security */
542         if (change_file_mode_rw(fp, tmp) < 0) {
543                 FILE_OP_ERROR(tmp, "chmod");
544                 g_warning("can't change file mode\n");
545         }
546         
547         addr = g_strdup(to);
548         
549         extract_address(addr);
550         addrp = addr;
551         
552         /* write queue headers */
553         fprintf(fp, "AF:\n");
554         fprintf(fp, "NF:0\n");
555         fprintf(fp, "PS:10\n");
556         fprintf(fp, "SRH:1\n");
557         fprintf(fp, "SFN:\n");
558         fprintf(fp, "DSR:\n");
559         fprintf(fp, "MID:\n");
560         fprintf(fp, "CFG:\n");
561         fprintf(fp, "PT:0\n");
562         fprintf(fp, "S:%s\n", account->address);
563         fprintf(fp, "RQ:\n");
564         if (account->smtp_server)
565                 fprintf(fp, "SSV:%s\n", account->smtp_server);
566         else
567                 fprintf(fp, "SSV:\n");
568         fprintf(fp, "SSH:\n");
569         fprintf(fp, "R:<%s>\n", addrp);
570         
571         g_free(addrp);
572         
573         /* check whether we need to save the message */
574         outbox = account_get_special_folder(account, F_OUTBOX); 
575         if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
576                 outbox = NULL;
577         if (outbox) {
578                 path = folder_item_get_identifier(outbox);
579                 fprintf(fp, "SCF:%s\n", path);
580                 g_free(path);
581         }               
582
583         fprintf(fp, "\n");
584         
585         /* Date */
586         get_rfc822_date(buf, sizeof(buf));
587         fprintf(fp, "Date: %s\n", buf);
588
589         /* From */
590         if (account->name && *account->name) {
591                 notification_convert_header
592                         (buf, sizeof(buf), account->name,
593                          strlen("From: "));
594                 fprintf(fp, "From: %s <%s>\n", buf, account->address);
595         } else
596                 fprintf(fp, "From: %s\n", account->address);
597
598         fprintf(fp, "To: %s\n", to);
599
600         /* Subject */
601         notification_convert_header(buf, sizeof(buf), msginfo->subject,
602                                     strlen("Subject: "));
603         fprintf(fp, "Subject: Disposition notification: %s\n", buf);
604
605         /* Message ID */
606         generate_msgid(account->address, buf, sizeof buf);
607         fprintf(fp, "Message-Id: <%s>\n", buf);
608
609         if (fclose(fp) == EOF) {
610                 FILE_OP_ERROR(tmp, "fclose");
611                 unlink(tmp);
612                 return -1;
613         }
614
615         /* put it in queue */
616         queue = account_get_special_folder(account, F_QUEUE);
617         if (!queue) queue = folder_get_default_queue();
618         if (!queue) {
619                 g_warning("can't find queue folder\n");
620                 unlink(tmp);
621                 return -1;
622         }
623         folder_item_scan(queue);
624         if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
625                 g_warning("can't queue the message\n");
626                 unlink(tmp);
627                 return -1;
628         }
629         
630         /* send it */
631         path = folder_item_fetch_msg(queue, num);
632         ok = procmsg_send_message_queue(path);
633         g_free(path);
634         folder_item_remove_msg(queue, num);
635
636         return ok;
637 }
638
639 GList *messageview_get_window_list(void)
640 {
641         return messageview_list;
642 }
643
644 static gboolean find_encrypted_func(GNode *node, gpointer data)
645 {
646         MimeInfo *mimeinfo = (MimeInfo *) node->data;
647         MimeInfo **encinfo = (MimeInfo **) data;
648         
649         if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
650                 *encinfo = mimeinfo;
651                 return TRUE;
652         }
653         
654         return FALSE;
655 }
656
657 static MimeInfo *find_encrypted_part(MimeInfo *rootinfo)
658 {
659         MimeInfo *encinfo = NULL;
660
661         g_node_traverse(rootinfo->node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
662                 find_encrypted_func, &encinfo);
663         
664         return encinfo;
665 }
666
667 gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
668                       gboolean all_headers)
669 {
670         gchar *file;
671         MimeInfo *mimeinfo, *encinfo;
672
673         g_return_val_if_fail(msginfo != NULL, -1);
674
675         mimeinfo = procmime_scan_message(msginfo);
676         if (!mimeinfo) {
677                 textview_show_error(messageview->mimeview->textview);
678                 return -1;
679         }
680
681         while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) {
682                 debug_print("decrypting message part\n");
683                 if (privacy_mimeinfo_decrypt(encinfo) < 0)
684                         break;
685         }
686         
687         file = procmsg_get_message_file_path(msginfo);
688         if (!file) {
689                 g_warning("can't get message file path.\n");
690                 procmime_mimeinfo_free_all(mimeinfo);
691                 textview_show_error(messageview->mimeview->textview);
692                 return -1;
693         }
694
695         if (messageview->msginfo != msginfo) {
696                 procmsg_msginfo_free(messageview->msginfo);
697                 messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
698         }
699         headerview_show(messageview->headerview, messageview->msginfo);
700
701         messageview->all_headers = all_headers;
702         textview_set_all_headers(messageview->mimeview->textview, all_headers);
703
704         mimeview_show_message(messageview->mimeview, mimeinfo, file);
705
706         if ((messageview->msginfo->dispositionnotificationto || 
707              messageview->msginfo->returnreceiptto) &&
708             !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags))
709                 return_receipt_show(messageview->noticeview, messageview->msginfo);
710         else 
711                 noticeview_hide(messageview->noticeview);
712
713         g_free(file);
714
715         return 0;
716 }
717
718 void messageview_reflect_prefs_pixmap_theme(void)
719 {
720         GList *cur;
721         MessageView *msgview;
722
723         for (cur = msgview_list; cur != NULL; cur = cur->next) {
724                 msgview = (MessageView*)cur->data;
725                 toolbar_update(TOOLBAR_MSGVIEW, msgview);
726                 mimeview_update(msgview->mimeview);
727         }
728 }
729
730 void messageview_clear(MessageView *messageview)
731 {
732         procmsg_msginfo_free(messageview->msginfo);
733         messageview->msginfo = NULL;
734         messageview->filtered = FALSE;
735         mimeview_clear(messageview->mimeview);
736         headerview_clear(messageview->headerview);
737         noticeview_hide(messageview->noticeview);
738 }
739
740 void messageview_destroy(MessageView *messageview)
741 {
742         GtkWidget *mimeview  = GTK_WIDGET_PTR(messageview->mimeview);
743
744         debug_print("destroy messageview\n");
745         messageview_list = g_list_remove(messageview_list, messageview);
746
747         hooks_unregister_hook(MSGINFO_UPDATE_HOOKLIST,
748                               messageview->msginfo_update_callback_id);
749
750         headerview_destroy(messageview->headerview);
751         mimeview_destroy(messageview->mimeview);
752         noticeview_destroy(messageview->noticeview);
753
754         procmsg_msginfo_free(messageview->msginfo);
755         toolbar_clear_list(TOOLBAR_MSGVIEW);
756         if (messageview->toolbar) {
757                 toolbar_destroy(messageview->toolbar);
758                 g_free(messageview->toolbar);
759         }
760         
761         msgview_list = g_list_remove(msgview_list, messageview); 
762
763         g_free(messageview);
764 }
765
766 void messageview_delete(MessageView *msgview)
767 {
768         MsgInfo *msginfo = (MsgInfo *) msgview->msginfo;
769         FolderItem *trash = NULL;
770         PrefsAccount *ac = NULL;
771
772         g_return_if_fail(msginfo != NULL);
773
774         /* to get the trash folder, we have to choose either
775          * the folder's or account's trash default - we prefer
776          * the one in the account prefs */
777         if (msginfo->folder) {
778                 if (NULL != (ac = account_find_from_item(msginfo->folder)))
779                         trash = account_get_special_folder(ac, F_TRASH);
780                 if (!trash && msginfo->folder->folder)  
781                         trash = msginfo->folder->folder->trash;
782                 /* if still not found, use the default */
783                 if (!trash) 
784                         trash = folder_get_default_trash();
785         }       
786
787         g_return_if_fail(trash   != NULL);
788
789         if (prefs_common.immediate_exec)
790                 /* TODO: Delete from trash */
791                 folder_item_move_msg(trash, msginfo);
792         else {
793                 procmsg_msginfo_set_to_folder(msginfo, trash);
794                 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
795                 /* NOTE: does not update to next message in summaryview */
796         }
797 }
798
799 /* 
800  * \brief update messageview with currently selected message in summaryview
801  *        leave unchanged if summaryview is empty
802  * \param pointer to MessageView
803  */     
804 static void messageview_update(MessageView *msgview)
805 {
806         SummaryView *summaryview = (SummaryView*)msgview->mainwin->summaryview;
807
808         g_return_if_fail(summaryview != NULL);
809         
810         if (summaryview->selected) {
811                 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
812                 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree, 
813                                                       summaryview->selected);
814                 g_return_if_fail(msginfo != NULL);
815
816                 messageview_show(msgview, msginfo, 
817                                  msgview->all_headers);
818         } 
819 }
820
821 void messageview_quote_color_set(void)
822 {
823 }
824
825 void messageview_set_font(MessageView *messageview)
826 {
827 }
828
829 TextView *messageview_get_current_textview(MessageView *messageview)
830 {
831         TextView *text = NULL;
832
833         text = messageview->mimeview->textview;
834
835         return text;
836 }
837
838 MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
839 {
840         return mimeview_get_selected_part(messageview->mimeview);
841 }
842
843 void messageview_copy_clipboard(MessageView *messageview)
844 {
845         TextView *text;
846
847         text = messageview_get_current_textview(messageview);
848         if (text) {
849                 GtkTextView *textview = GTK_TEXT_VIEW(text->text);
850                 GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
851                 GtkClipboard *clipboard
852                         = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
853
854                 gtk_text_buffer_copy_clipboard(buffer, clipboard);
855         }
856 }
857
858 void messageview_select_all(MessageView *messageview)
859 {
860         TextView *text;
861
862         text = messageview_get_current_textview(messageview);
863         if (text)
864                 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
865 }
866
867 void messageview_set_position(MessageView *messageview, gint pos)
868 {
869         TextView *text;
870
871         text = messageview_get_current_textview(messageview);
872         if (text)
873                 textview_set_position(text, pos);
874 }
875
876 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
877                                    gboolean case_sens)
878 {
879         TextView *text;
880
881         text = messageview_get_current_textview(messageview);
882         if (text)
883                 return textview_search_string(text, str, case_sens);
884         return FALSE;
885 }
886
887 gboolean messageview_search_string_backward(MessageView *messageview,
888                                             const gchar *str,
889                                             gboolean case_sens)
890 {
891         TextView *text;
892
893         text = messageview_get_current_textview(messageview);
894                 return textview_search_string_backward(text,
895                                                        str, case_sens);
896         return FALSE;
897 }
898
899 gboolean messageview_is_visible(MessageView *messageview)
900 {
901         return messageview->visible;
902 }
903
904 void messageview_save_as(MessageView *messageview)
905 {
906         gchar *filename = NULL;
907         MsgInfo *msginfo;
908         gchar *src, *dest;
909
910         if (!messageview->msginfo) return;
911         msginfo = messageview->msginfo;
912
913         if (msginfo->subject) {
914                 Xstrdup_a(filename, msginfo->subject, return);
915                 subst_for_filename(filename);
916         }
917         dest = filesel_select_file(_("Save as"), filename);
918         if (!dest) return;
919         if (is_file_exist(dest)) {
920                 AlertValue aval;
921
922                 aval = alertpanel(_("Overwrite"),
923                                   _("Overwrite existing file?"),
924                                   _("OK"), _("Cancel"), NULL);
925                 if (G_ALERTDEFAULT != aval) return;
926         }
927
928         src = procmsg_get_message_file(msginfo);
929         if (copy_file(src, dest, TRUE) < 0) {
930                 alertpanel_error(_("Can't save the file `%s'."),
931                                  g_basename(dest));
932         }
933         g_free(src);
934 }
935
936 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
937 {
938         messageview_destroy(messageview);
939 }
940
941 static void messageview_size_allocate_cb(GtkWidget *widget,
942                                          GtkAllocation *allocation)
943 {
944         g_return_if_fail(allocation != NULL);
945
946         prefs_common.msgwin_width  = allocation->width;
947         prefs_common.msgwin_height = allocation->height;
948 }
949
950 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
951                         MessageView *messageview)
952 {
953         if (event && event->keyval == GDK_Escape && messageview->window)
954                 gtk_widget_destroy(messageview->window);
955         return FALSE;
956 }
957
958 void messageview_toggle_view_real(MessageView *messageview)
959 {
960         MainWindow *mainwin = messageview->mainwin;
961         union CompositeWin *cwin = &mainwin->win;
962         GtkWidget *vpaned = NULL;
963         GtkWidget *container = NULL;
964         GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
965         
966         switch (mainwin->type) {
967         case SEPARATE_NONE:
968                 vpaned = cwin->sep_none.vpaned;
969                 container = cwin->sep_none.hpaned;
970                 break;
971         case SEPARATE_FOLDER:
972                 vpaned = cwin->sep_folder.vpaned;
973                 container = mainwin->vbox_body;
974                 break;
975         case SEPARATE_MESSAGE:
976         case SEPARATE_BOTH:
977                 return;
978         }
979
980         if (vpaned->parent != NULL) {
981                 gtk_widget_ref(vpaned);
982                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
983                 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
984                 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
985         } else {
986                 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
987                 gtk_container_add(GTK_CONTAINER(container), vpaned);
988                 gtk_widget_unref(vpaned);
989                 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
990                 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
991         }
992 }
993
994 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
995 {
996         noticeview_set_text(noticeview, _("This message asks for a return receipt"));
997         noticeview_set_button_text(noticeview, _("Send receipt"));
998         noticeview_set_button_press_callback(noticeview,
999                                              GTK_SIGNAL_FUNC(return_receipt_send_clicked),
1000                                              (gpointer) msginfo);
1001         noticeview_show(noticeview);
1002 }
1003
1004 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
1005 {
1006         MsgInfo *tmpmsginfo;
1007         gchar *file;
1008
1009         file = procmsg_get_message_file_path(msginfo);
1010         if (!file) {
1011                 g_warning("can't get message file path.\n");
1012                 return;
1013         }
1014
1015         tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
1016         tmpmsginfo->folder = msginfo->folder;
1017         tmpmsginfo->msgnum = msginfo->msgnum;
1018
1019         if (disposition_notification_send(tmpmsginfo) >= 0) {
1020                 procmsg_msginfo_set_flags(msginfo, MSG_RETRCPT_SENT, 0);
1021                 noticeview_hide(noticeview);
1022         }               
1023
1024         procmsg_msginfo_free(tmpmsginfo);
1025         g_free(file);
1026 }
1027
1028 static void select_account_cb(GtkWidget *w, gpointer data)
1029 {
1030         *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
1031 }
1032         
1033 static PrefsAccount *select_account_from_list(GList *ac_list)
1034 {
1035         GtkWidget *optmenu;
1036         GtkWidget *menu;
1037         gint account_id;
1038
1039         g_return_val_if_fail(ac_list != NULL, NULL);
1040         g_return_val_if_fail(ac_list->data != NULL, NULL);
1041         
1042         optmenu = gtk_option_menu_new();
1043         menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
1044         if (!menu)
1045                 return NULL;
1046         gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
1047         gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
1048         account_id = ((PrefsAccount *) ac_list->data)->account_id;
1049         if (alertpanel_with_widget(
1050                                 _("Return Receipt Notification"),
1051                                 _("The message was sent to several of your "
1052                                   "accounts.\n"
1053                                   "Please choose which account do you want to "
1054                                   "use for sending the receipt notification:"),
1055                                 _("Send Notification"), _("+Cancel"), NULL,
1056                                 optmenu) != G_ALERTDEFAULT)
1057                 return NULL;
1058         return account_find_from_id(account_id);
1059 }
1060
1061 /* 
1062  * \brief return selected messageview text, when nothing is 
1063  *        selected and message was filtered, return complete text
1064  *
1065  * \param  pointer to Messageview 
1066  *
1067  * \return pointer to text (needs to be free'd by calling func)
1068  */
1069 gchar *messageview_get_selection(MessageView *msgview)
1070 {
1071         TextView *textview;
1072         gchar *text = NULL;
1073         GtkTextView *edit = NULL;
1074         GtkTextBuffer *textbuf;
1075         gint body_pos = 0;
1076         
1077         g_return_val_if_fail(msgview != NULL, NULL);
1078
1079         textview = messageview_get_current_textview(msgview);
1080         g_return_val_if_fail(textview != NULL, NULL);
1081
1082         edit = GTK_EDITABLE(textview->text);
1083         g_return_val_if_fail(edit != NULL, NULL);
1084         body_pos = textview->body_pos;
1085
1086         textbuf = gtk_text_view_get_buffer(edit);
1087
1088         if (gtk_text_buffer_get_selection_bounds(textbuf, NULL, NULL))
1089                 return gtkut_text_view_get_selection(edit);
1090         else if (msgview->filtered) {
1091                 GtkTextIter start_iter, end_iter;
1092                 gtk_text_buffer_get_iter_at_offset(textbuf, &start_iter, body_pos);
1093                 gtk_text_buffer_get_end_iter(textbuf, &end_iter);
1094                 gtk_text_buffer_get_text(textbuf, &start_iter, &end_iter, FALSE);
1095         } else
1096                 text = NULL;
1097
1098         return text;
1099 }
1100
1101 static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
1102 {
1103         MessageView *messageview = (MessageView *)data;
1104         messageview_save_as(messageview);
1105 }
1106
1107 static void print_cb(gpointer data, guint action, GtkWidget *widget)
1108 {
1109         MessageView *messageview = (MessageView *)data;
1110         gchar *cmdline;
1111         gchar *p;
1112
1113         if (!messageview->msginfo) return;
1114
1115         cmdline = input_dialog(_("Print"),
1116                                _("Enter the print command line:\n"
1117                                  "(`%s' will be replaced with file name)"),
1118                                prefs_common.print_cmd);
1119         if (!cmdline) return;
1120         if (!(p = strchr(cmdline, '%')) || *(p + 1) != 's' ||
1121             strchr(p + 2, '%')) {
1122                 alertpanel_error(_("Print command line is invalid:\n`%s'"),
1123                                  cmdline);
1124                 g_free(cmdline);
1125                 return;
1126         }
1127
1128         procmsg_print_message(messageview->msginfo, cmdline);
1129         g_free(cmdline);
1130 }
1131
1132 static void close_cb(gpointer data, guint action, GtkWidget *widget)
1133 {
1134         MessageView *messageview = (MessageView *)data;
1135         gtk_widget_destroy(messageview->window);
1136 }
1137
1138 static void copy_cb(gpointer data, guint action, GtkWidget *widget)
1139 {
1140         MessageView *messageview = (MessageView *)data;
1141         messageview_copy_clipboard(messageview);
1142 }
1143
1144 static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
1145 {
1146         MessageView *messageview = (MessageView *)data;
1147         messageview_select_all(messageview);
1148 }
1149
1150 static void search_cb(gpointer data, guint action, GtkWidget *widget)
1151 {
1152         MessageView *messageview = (MessageView *)data;
1153         message_search(messageview);
1154 }
1155
1156 static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
1157 {
1158         MessageView *messageview = (MessageView *)data;
1159         const gchar *charset;
1160
1161         if (GTK_CHECK_MENU_ITEM(widget)->active) {
1162                 charset = conv_get_charset_str((CharSet)action);
1163                 g_free(messageview->forced_charset);
1164                 messageview->forced_charset = g_strdup(charset);
1165                 messageview_show(messageview, messageview->msginfo, FALSE);
1166         }
1167 }
1168
1169 static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
1170 {
1171         MessageView *messageview = (MessageView *)data;
1172         SourceWindow *srcwin;
1173
1174         if (!messageview->msginfo) return;
1175
1176         srcwin = source_window_create();
1177         source_window_show_msg(srcwin, messageview->msginfo);
1178         source_window_show(srcwin);
1179 }
1180
1181 static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
1182 {
1183         MessageView *messageview = (MessageView *)data;
1184         MsgInfo *msginfo = messageview->msginfo;
1185
1186         if (!msginfo) return;
1187         messageview->msginfo = NULL;
1188         messageview_show(messageview, msginfo,
1189                          GTK_CHECK_MENU_ITEM(widget)->active);
1190         procmsg_msginfo_free(msginfo);
1191 }
1192
1193 static void compose_cb(gpointer data, guint action, GtkWidget *widget)
1194 {
1195         MessageView *messageview = (MessageView *)data;
1196         PrefsAccount *ac = NULL;
1197         FolderItem *item = NULL;
1198
1199         if (messageview->msginfo)
1200                 item = messageview->msginfo->folder;
1201
1202         if (item) {
1203                 ac = account_find_from_item(item);
1204                 if (ac && ac->protocol == A_NNTP &&
1205                     item->stype == F_NEWS) {
1206                         compose_new(ac, item->path, NULL);
1207                         return;
1208                 }
1209         }
1210
1211         compose_new(ac, NULL, NULL);
1212 }
1213
1214 static void reply_cb(gpointer data, guint action, GtkWidget *widget)
1215 {
1216         MessageView *messageview = (MessageView *)data;
1217         GSList *mlist = NULL;
1218         MsgInfo *msginfo;
1219         gchar *text = NULL;
1220         ComposeMode mode = (ComposeMode)action;
1221         TextView *textview;
1222
1223         msginfo = messageview->msginfo;
1224         mlist = g_slist_append(NULL, msginfo);
1225
1226         textview = messageview_get_current_textview(messageview);
1227         text = gtkut_editable_get_selection
1228                 (GTK_EDITABLE(textview->text));
1229         if (text && *text == '\0') {
1230                 g_free(text);
1231                 text = NULL;
1232         }
1233
1234         switch (mode) {
1235         case COMPOSE_REPLY:
1236                 compose_reply(msginfo, prefs_common.reply_with_quote,
1237                               FALSE, prefs_common.default_reply_list, FALSE, text);
1238                 break;
1239         case COMPOSE_REPLY_WITH_QUOTE:
1240                 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
1241                 break;
1242         case COMPOSE_REPLY_WITHOUT_QUOTE:
1243                 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
1244                 break;
1245         case COMPOSE_REPLY_TO_SENDER:
1246                 compose_reply(msginfo, prefs_common.reply_with_quote,
1247                               FALSE, FALSE, TRUE, text);
1248                 break;
1249         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1250                 compose_followup_and_reply_to(msginfo,
1251                                               prefs_common.reply_with_quote,
1252                                               FALSE, FALSE, text);
1253                 break;
1254         case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1255                 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
1256                 break;
1257         case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1258                 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1259                 break;
1260         case COMPOSE_REPLY_TO_ALL:
1261                 compose_reply(msginfo, prefs_common.reply_with_quote,
1262                               TRUE, FALSE, FALSE, text);
1263                 break;
1264         case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1265                 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
1266                 break;
1267         case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1268                 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1269                 break;
1270         case COMPOSE_REPLY_TO_LIST:
1271                 compose_reply(msginfo, prefs_common.reply_with_quote,
1272                               FALSE, TRUE, FALSE, text);
1273                 break;
1274         case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1275                 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
1276                 break;
1277         case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1278                 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1279                 break;
1280         case COMPOSE_FORWARD:
1281                 if (prefs_common.forward_as_attachment) {
1282                         compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, mlist, text);
1283                         return;
1284                 } else {
1285                         compose_reply_mode(COMPOSE_FORWARD_INLINE, mlist, text);
1286                         return;
1287                 }
1288                 break;
1289         case COMPOSE_FORWARD_INLINE:
1290                 compose_forward(NULL, msginfo, FALSE, text, FALSE);
1291                 break;
1292         case COMPOSE_FORWARD_AS_ATTACH:
1293                 compose_forward_multiple(NULL, mlist);
1294                 break;
1295         case COMPOSE_REDIRECT:
1296                 compose_redirect(NULL, msginfo);
1297                 break;
1298         default:
1299                 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1300         }
1301
1302         /* summary_set_marks_selected(summaryview); */
1303         g_free(text);
1304         g_slist_free(mlist);
1305 }
1306
1307 static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
1308 {
1309         MessageView *messageview = (MessageView *)data;
1310         MsgInfo *msginfo;
1311
1312         if (!messageview->msginfo) return;
1313         msginfo = messageview->msginfo;
1314         if (!msginfo->folder) return;
1315         if (msginfo->folder->stype != F_OUTBOX &&
1316             msginfo->folder->stype != F_DRAFT &&
1317             msginfo->folder->stype != F_QUEUE) return;
1318
1319         compose_reedit(msginfo);
1320 }
1321
1322 static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
1323 {
1324         addressbook_open(NULL);
1325 }
1326
1327 static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
1328 {
1329         MessageView *messageview = (MessageView *)data;
1330         MsgInfo *msginfo;
1331         gchar *from;
1332
1333         if (!messageview->msginfo) return;
1334         msginfo = messageview->msginfo;
1335         Xstrdup_a(from, msginfo->from, return);
1336         eliminate_address_comment(from);
1337         extract_address(from);
1338         addressbook_add_contact(msginfo->fromname, from, NULL);
1339 }
1340
1341 static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1342 {
1343         MessageView *messageview = (MessageView *)data;
1344         FolderItem * item;
1345         
1346         if (!messageview->msginfo) return;
1347         
1348         item = messageview->msginfo->folder;
1349         summary_msginfo_filter_open(item,  messageview->msginfo,
1350                                     (PrefsFilterType)action, 0);
1351 }
1352
1353 static void create_processing_cb(gpointer data, guint action,
1354                                  GtkWidget *widget)
1355 {
1356         MessageView *messageview = (MessageView *)data;
1357         FolderItem * item;
1358         
1359         if (!messageview->msginfo) return;
1360         
1361         item = messageview->msginfo->folder;
1362         summary_msginfo_filter_open(item,  messageview->msginfo,
1363                                     (PrefsFilterType)action, 1);
1364 }
1365
1366 static void about_cb(gpointer data, guint action, GtkWidget *widget)
1367 {
1368         about_show();
1369 }
1370
1371 static gboolean messageview_update_msg(gpointer source, gpointer data)
1372 {
1373         MsgInfoUpdate *msginfo_update = (MsgInfoUpdate *) source;
1374         MessageView *messageview = (MessageView *)data;
1375
1376         if (messageview->msginfo != msginfo_update->msginfo)
1377                 return FALSE;
1378
1379         if (msginfo_update->flags & MSGINFO_UPDATE_DELETED) {
1380                 messageview_clear(messageview);
1381                 messageview_update(messageview);
1382         }
1383
1384         return FALSE;
1385 }