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