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