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