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