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