c76e225501bf1f7c5f03c437d74e1656553f93f9
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkwindow.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtksignal.h>
29 #include <gtk/gtkvbox.h>
30 #include <gtk/gtkcontainer.h>
31 #include <gtk/gtkstatusbar.h>
32 #include <gtk/gtkprogressbar.h>
33 #include <gtk/gtkhpaned.h>
34 #include <gtk/gtkvpaned.h>
35 #include <gtk/gtkcheckmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkeditable.h>
38 #include <gtk/gtkmenu.h>
39 #include <gtk/gtkmenuitem.h>
40 #include <gtk/gtkhandlebox.h>
41 #include <gtk/gtktoolbar.h>
42 #include <gtk/gtkbutton.h>
43 #include <gtk/gtktooltips.h>
44 #include <string.h>
45
46 #include "main.h"
47 #include "mainwindow.h"
48 #include "folderview.h"
49 #include "foldersel.h"
50 #include "summaryview.h"
51 #include "summary_search.h"
52 #include "messageview.h"
53 #include "message_search.h"
54 #include "headerview.h"
55 #include "menu.h"
56 #include "stock_pixmap.h"
57 #include "folder.h"
58 #include "inc.h"
59 #include "compose.h"
60 #include "procmsg.h"
61 #include "import.h"
62 #include "export.h"
63 #include "prefs_common.h"
64 #include "prefs_actions.h"
65 #include "prefs_filtering.h"
66 #include "prefs_account.h"
67 #include "prefs_summary_column.h"
68 #include "prefs_folder_column.h"
69 #include "prefs_template.h"
70 #include "action.h"
71 #include "account.h"
72 #include "addressbook.h"
73 #include "logwindow.h"
74 #include "manage_window.h"
75 #include "alertpanel.h"
76 #include "statusbar.h"
77 #include "inputdialog.h"
78 #include "utils.h"
79 #include "gtkutils.h"
80 #include "codeconv.h"
81 #include "about.h"
82 #include "manual.h"
83 #include "version.h"
84 #include "ssl_manager.h"
85 #include "sslcertwindow.h"
86 #include "prefs_gtk.h"
87 #include "pluginwindow.h"
88 #include "hooks.h"
89 #include "progressindicator.h"
90 #include "localfolder.h"
91 #include "filtering.h"
92 #include "folderutils.h"
93 #include "foldersort.h"
94 #include "icon_legend.h"
95 #include "colorlabel.h"
96 #include "textview.h"
97
98 #define AC_LABEL_WIDTH  240
99
100 /* list of all instantiated MainWindow */
101 static GList *mainwin_list = NULL;
102
103 static GdkCursor *watch_cursor = NULL;
104
105 static void main_window_menu_callback_block     (MainWindow     *mainwin);
106 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
107
108 static void main_window_show_cur_account        (MainWindow     *mainwin);
109
110 static void main_window_set_widgets             (MainWindow     *mainwin,
111                                                  SeparateType    type);
112
113 static void toolbar_child_attached              (GtkWidget      *widget,
114                                                  GtkWidget      *child,
115                                                  gpointer        data);
116 static void toolbar_child_detached              (GtkWidget      *widget,
117                                                  GtkWidget      *child,
118                                                  gpointer        data);
119
120 static gboolean ac_label_button_pressed         (GtkWidget      *widget,
121                                                  GdkEventButton *event,
122                                                  gpointer        data);
123
124 static gint main_window_close_cb                (GtkWidget      *widget,
125                                                  GdkEventAny    *event,
126                                                  gpointer        data);
127 static gint folder_window_close_cb              (GtkWidget      *widget,
128                                                  GdkEventAny    *event,
129                                                  gpointer        data);
130 static gint message_window_close_cb             (GtkWidget      *widget,
131                                                  GdkEventAny    *event,
132                                                  gpointer        data);
133
134 static void main_window_size_allocate_cb        (GtkWidget      *widget,
135                                                  GtkAllocation  *allocation,
136                                                  gpointer        data);
137 static void folder_window_size_allocate_cb      (GtkWidget      *widget,
138                                                  GtkAllocation  *allocation,
139                                                  gpointer        data);
140 static void message_window_size_allocate_cb     (GtkWidget      *widget,
141                                                  GtkAllocation  *allocation,
142                                                  gpointer        data);
143
144 static void update_folderview_cb (MainWindow    *mainwin,
145                                   guint          action,
146                                   GtkWidget     *widget);
147 static void add_mailbox_cb       (MainWindow    *mainwin,
148                                   guint          action,
149                                   GtkWidget     *widget);
150 static void foldersort_cb        (MainWindow    *mainwin,
151                                   guint          action,
152                                   GtkWidget     *widget);
153 static void import_mbox_cb       (MainWindow    *mainwin,
154                                   guint          action,
155                                   GtkWidget     *widget);
156 static void export_mbox_cb       (MainWindow    *mainwin,
157                                   guint          action,
158                                   GtkWidget     *widget);
159 static void export_list_mbox_cb  (MainWindow    *mainwin, 
160                                   guint          action,
161                                   GtkWidget     *widget);
162 static void empty_trash_cb       (MainWindow    *mainwin,
163                                   guint          action,
164                                   GtkWidget     *widget);
165
166 static void save_as_cb           (MainWindow    *mainwin,
167                                   guint          action,
168                                   GtkWidget     *widget);
169 static void print_cb             (MainWindow    *mainwin,
170                                   guint          action,
171                                   GtkWidget     *widget);
172 static void app_exit_cb          (MainWindow    *mainwin,
173                                   guint          action,
174                                   GtkWidget     *widget);
175
176 static void search_cb            (MainWindow    *mainwin,
177                                   guint          action,
178                                   GtkWidget     *widget);
179
180 static void toggle_folder_cb     (MainWindow    *mainwin,
181                                   guint          action,
182                                   GtkWidget     *widget);
183 static void toggle_message_cb    (MainWindow    *mainwin,
184                                   guint          action,
185                                   GtkWidget     *widget);
186 static void toggle_toolbar_cb    (MainWindow    *mainwin,
187                                   guint          action,
188                                   GtkWidget     *widget);
189 static void toggle_statusbar_cb  (MainWindow    *mainwin,
190                                   guint          action,
191                                   GtkWidget     *widget);
192 static void separate_widget_cb   (MainWindow    *mainwin,
193                                   guint          action,
194                                   GtkWidget     *widget);
195
196 static void addressbook_open_cb (MainWindow     *mainwin,
197                                  guint           action,
198                                  GtkWidget      *widget);
199 static void log_window_show_cb  (MainWindow     *mainwin,
200                                  guint           action,
201                                  GtkWidget      *widget);
202
203 static void inc_cancel_cb               (MainWindow     *mainwin,
204                                          guint           action,
205                                          GtkWidget      *widget);
206
207 static void open_msg_cb                 (MainWindow     *mainwin,
208                                          guint           action,
209                                          GtkWidget      *widget);
210
211 static void view_source_cb              (MainWindow     *mainwin,
212                                          guint           action,
213                                          GtkWidget      *widget);
214
215 static void show_all_header_cb          (MainWindow     *mainwin,
216                                          guint           action,
217                                          GtkWidget      *widget);
218
219 static void move_to_cb                  (MainWindow     *mainwin,
220                                          guint           action,
221                                          GtkWidget      *widget);
222 static void copy_to_cb                  (MainWindow     *mainwin,
223                                          guint           action,
224                                          GtkWidget      *widget);
225 static void delete_cb                   (MainWindow     *mainwin,
226                                          guint           action,
227                                          GtkWidget      *widget);
228 static void delete_trash_cb                     (MainWindow     *mainwin,
229                                          guint           action,
230                                          GtkWidget      *widget);
231
232 static void cancel_cb                   (MainWindow     *mainwin,
233                                          guint           action,
234                                          GtkWidget      *widget);
235
236 static void mark_cb                     (MainWindow     *mainwin,
237                                          guint           action,
238                                          GtkWidget      *widget);
239 static void unmark_cb                   (MainWindow     *mainwin,
240                                          guint           action,
241                                          GtkWidget      *widget);
242
243 static void mark_as_unread_cb           (MainWindow     *mainwin,
244                                          guint           action,
245                                          GtkWidget      *widget);
246 static void mark_as_read_cb             (MainWindow     *mainwin,
247                                          guint           action,
248                                          GtkWidget      *widget);
249 static void mark_all_read_cb            (MainWindow     *mainwin,
250                                          guint           action,
251                                          GtkWidget      *widget);
252 static void mark_as_spam_cb             (MainWindow     *mainwin, 
253                                          guint           action,
254                                          GtkWidget      *widget);
255
256 static void reedit_cb                   (MainWindow     *mainwin,
257                                          guint           action,
258                                          GtkWidget      *widget);
259
260 static void add_address_cb              (MainWindow     *mainwin,
261                                          guint           action,
262                                          GtkWidget      *widget);
263
264 static void set_charset_cb              (MainWindow     *mainwin,
265                                          guint           action,
266                                          GtkWidget      *widget);
267
268 static void set_decode_cb               (MainWindow     *mainwin,
269                                          guint           action,
270                                          GtkWidget      *widget);
271
272 static void hide_read_messages   (MainWindow    *mainwin,
273                                   guint          action,
274                                   GtkWidget     *widget);
275
276 static void thread_cb            (MainWindow    *mainwin,
277                                   guint          action,
278                                   GtkWidget     *widget);
279 static void expand_threads_cb    (MainWindow    *mainwin,
280                                   guint          action,
281                                   GtkWidget     *widget);
282 static void collapse_threads_cb  (MainWindow    *mainwin,
283                                   guint          action,
284                                   GtkWidget     *widget);
285
286 static void set_summary_display_item_cb  (MainWindow    *mainwin,
287                                   guint          action,
288                                   GtkWidget     *widget);
289 static void set_folder_display_item_cb   (MainWindow    *mainwin,
290                                   guint          action,
291                                   GtkWidget     *widget);
292 static void sort_summary_cb      (MainWindow    *mainwin,
293                                   guint          action,
294                                   GtkWidget     *widget);
295 static void sort_summary_type_cb (MainWindow    *mainwin,
296                                   guint          action,
297                                   GtkWidget     *widget);
298 static void attract_by_subject_cb(MainWindow    *mainwin,
299                                   guint          action,
300                                   GtkWidget     *widget);
301
302 static void delete_duplicated_cb (MainWindow    *mainwin,
303                                   guint          action,
304                                   GtkWidget     *widget);
305 static void delete_duplicated_all_cb (MainWindow        *mainwin,
306                                   guint          action,
307                                   GtkWidget     *widget);
308 static void filter_cb            (MainWindow    *mainwin,
309                                   guint          action,
310                                   GtkWidget     *widget);
311 static void execute_summary_cb   (MainWindow    *mainwin,
312                                   guint          action,
313                                   GtkWidget     *widget);
314 static void update_summary_cb    (MainWindow    *mainwin,
315                                   guint          action,
316                                   GtkWidget     *widget);
317
318 static void prev_cb              (MainWindow    *mainwin,
319                                   guint          action,
320                                   GtkWidget     *widget);
321 static void next_cb              (MainWindow    *mainwin,
322                                   guint          action,
323                                   GtkWidget     *widget);
324 static void next_unread_cb       (MainWindow    *mainwin,
325                                   guint          action,
326                                   GtkWidget     *widget);
327 static void prev_unread_cb       (MainWindow    *mainwin,
328                                   guint          action,
329                                   GtkWidget     *widget);
330
331 static void prev_new_cb          (MainWindow    *mainwin,
332                                   guint          action,
333                                   GtkWidget     *widget);
334 static void next_new_cb          (MainWindow    *mainwin,
335                                   guint          action,
336                                   GtkWidget     *widget);
337 static void prev_marked_cb       (MainWindow    *mainwin,
338                                   guint          action,
339                                   GtkWidget     *widget);
340 static void next_marked_cb       (MainWindow    *mainwin,
341                                   guint          action,
342                                   GtkWidget     *widget);
343 static void prev_labeled_cb      (MainWindow    *mainwin,
344                                   guint          action,
345                                   GtkWidget     *widget);
346 static void next_labeled_cb      (MainWindow    *mainwin,
347                                   guint          action,
348                                   GtkWidget     *widget);
349
350 static void goto_folder_cb       (MainWindow    *mainwin,
351                                   guint          action,
352                                   GtkWidget     *widget);
353
354 static void copy_cb              (MainWindow    *mainwin,
355                                   guint          action,
356                                   GtkWidget     *widget);
357 static void allsel_cb            (MainWindow    *mainwin,
358                                   guint          action,
359                                   GtkWidget     *widget);
360 static void select_thread_cb     (MainWindow    *mainwin,
361                                   guint          action,
362                                   GtkWidget     *widget);
363
364 static void create_filter_cb     (MainWindow    *mainwin,
365                                   guint          action,
366                                   GtkWidget     *widget);
367 static void create_processing_cb (MainWindow    *mainwin,
368                                   guint          action,
369                                   GtkWidget     *widget);
370
371 static void prefs_template_open_cb      (MainWindow     *mainwin,
372                                          guint           action,
373                                          GtkWidget      *widget);
374 static void prefs_actions_open_cb       (MainWindow     *mainwin,
375                                          guint           action,
376                                          GtkWidget      *widget);
377 static void prefs_account_open_cb       (MainWindow     *mainwin,
378                                          guint           action,
379                                          GtkWidget      *widget);
380
381 static void prefs_pre_processing_open_cb  (MainWindow   *mainwin,
382                                            guint         action,
383                                            GtkWidget    *widget);
384
385 static void prefs_post_processing_open_cb (MainWindow   *mainwin,
386                                            guint         action,
387                                            GtkWidget    *widget);
388
389 static void prefs_filtering_open_cb     (MainWindow     *mainwin,
390                                          guint           action,
391                                          GtkWidget      *widget);
392 #ifdef USE_OPENSSL
393 static void ssl_manager_open_cb         (MainWindow     *mainwin,
394                                          guint           action,
395                                          GtkWidget      *widget);
396 #endif
397 static void new_account_cb       (MainWindow    *mainwin,
398                                   guint          action,
399                                   GtkWidget     *widget);
400
401 static void account_selector_menu_cb     (GtkMenuItem   *menuitem,
402                                           gpointer       data);
403 static void account_receive_menu_cb      (GtkMenuItem   *menuitem,
404                                           gpointer       data);
405 static void account_compose_menu_cb      (GtkMenuItem   *menuitem,
406                                           gpointer       data);
407
408 static void prefs_open_cb       (GtkMenuItem    *menuitem,
409                                  gpointer        data);
410 static void plugins_open_cb     (GtkMenuItem    *menuitem,
411                                  gpointer        data);
412
413 static void online_switch_clicked(GtkButton     *btn, 
414                                   gpointer data);
415
416 static void manual_open_cb       (MainWindow    *mainwin,
417                                   guint          action,
418                                   GtkWidget     *widget);
419
420 static void legend_open_cb       (GtkMenuItem   *menuitem,
421                                   gpointer       data);
422
423 static void scan_tree_func       (Folder        *folder,
424                                   FolderItem    *item,
425                                   gpointer       data);
426                                   
427 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
428
429 static void addr_harvest_cb      ( MainWindow  *mainwin,
430                                    guint       action,
431                                    GtkWidget   *widget );
432
433 static void addr_harvest_msg_cb  ( MainWindow  *mainwin,
434                                    guint       action,
435                                    GtkWidget   *widget );
436 static void sync_cb              ( MainWindow *mainwin, 
437                                    guint action, 
438                                    GtkWidget *widget );
439
440 static gboolean mainwindow_focus_in_event       (GtkWidget      *widget, 
441                                                  GdkEventFocus  *focus,
442                                                  gpointer        data);
443 void main_window_reply_cb                       (MainWindow     *mainwin, 
444                                                  guint           action,
445                                                  GtkWidget      *widget);
446 gboolean mainwindow_progressindicator_hook      (gpointer        source,
447                                                  gpointer        userdata);
448
449 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
450                                        MsgInfo *msginfo);
451
452 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
453         
454 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
455
456 static void mailing_list_compose(GtkWidget *w, gpointer *data);
457  
458 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
459 #define  SEPARATE_ACTION 500 
460 static void mainwindow_quicksearch              (MainWindow     *mainwin, 
461                                                  guint           action, 
462                                                  GtkWidget      *widget);
463
464 static GtkItemFactoryEntry mainwin_entries[] =
465 {
466         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
467         {N_("/_File/_Add mailbox"),             NULL, NULL, 0, "<Branch>"},
468         {N_("/_File/_Add mailbox/MH..."),       NULL, add_mailbox_cb, 0, NULL},
469         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
470         {N_("/_File/Change folder order..."),   NULL, foldersort_cb,  0, NULL},
471         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
472         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
473         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
474         {N_("/_File/Exp_ort selected to mbox file..."), 
475                                                 NULL, export_list_mbox_cb, 0, NULL},
476         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
477         {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
478         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
479         {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
480         {N_("/_File/_Print..."),                "<control>P", print_cb, 0, NULL},
481         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
482         {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
483         {N_("/_File/Synchronise folders"),      "<control><shift>S", sync_cb, 0, NULL},
484         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
485         /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
486         {N_("/_File/E_xit"),                    "<control>Q", app_exit_cb, 0, NULL},
487
488         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
489         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
490         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
491         {N_("/_Edit/Select _thread"),           NULL, select_thread_cb, 0, NULL},
492         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
493         {N_("/_Edit/_Find in current message..."),
494                                                 "<control>F", search_cb, 0, NULL},
495         {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
496         {N_("/_Edit/_Quick search"),            "slash", mainwindow_quicksearch, 0, NULL},
497         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
498         {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
499         {N_("/_View/Show or hi_de/_Folder tree"),
500                                                 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
501         {N_("/_View/Show or hi_de/_Message view"),
502                                                 "V", toggle_message_cb, 0, "<ToggleItem>"},
503         {N_("/_View/Show or hi_de/_Toolbar"),
504                                                 NULL, NULL, 0, "<Branch>"},
505         {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
506                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
507         {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
508                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
509         {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
510                                                 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
511         {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
512                                                 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
513         {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
514                                                 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
515         {N_("/_View/Show or hi_de/Status _bar"),
516                                                 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
517         {N_("/_View/Set displayed _columns"),   NULL, NULL, 0, "<Branch>"},
518         {N_("/_View/Set displayed _columns/in _Folder list..."),        NULL, set_folder_display_item_cb, 0, NULL},
519         {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
520
521         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
522         {N_("/_View/Separate f_older tree"),    NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
523         {N_("/_View/Separate _message view"),   NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
524         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
525         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
526         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
527         {N_("/_View/_Sort/by S_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
528         {N_("/_View/_Sort/by _Date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
529         {N_("/_View/_Sort/by _From"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
530         {N_("/_View/_Sort/by _To"),             NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
531         {N_("/_View/_Sort/by S_ubject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
532         {N_("/_View/_Sort/by _color label"),
533                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
534         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
535         {N_("/_View/_Sort/by _status"),         NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
536         {N_("/_View/_Sort/by a_ttachment"),
537                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
538         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
539         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
540         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
541         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
542         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
543         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
544         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
545         {N_("/_View/_Sort/_Attract by subject"),
546                                                 NULL, attract_by_subject_cb, 0, NULL},
547         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
548         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
549         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
550         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
551
552         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
553         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
554         {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
555         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
556         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
557         {N_("/_View/_Go to/P_revious unread message"),
558                                                 "<shift>P", prev_unread_cb, 0, NULL},
559         {N_("/_View/_Go to/N_ext unread message"),
560                                                 "<shift>N", next_unread_cb, 0, NULL},
561         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
562         {N_("/_View/_Go to/Previous ne_w message"),     NULL, prev_new_cb, 0, NULL},
563         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
564         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
565         {N_("/_View/_Go to/Previous _marked message"),
566                                                 NULL, prev_marked_cb, 0, NULL},
567         {N_("/_View/_Go to/Next m_arked message"),
568                                                 NULL, next_marked_cb, 0, NULL},
569         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
570         {N_("/_View/_Go to/Previous _labeled message"),
571                                                 NULL, prev_labeled_cb, 0, NULL},
572         {N_("/_View/_Go to/Next la_beled message"),
573                                                 NULL, next_labeled_cb, 0, NULL},
574         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
575         {N_("/_View/_Go to/Other _folder..."),  "G", goto_folder_cb, 0, NULL},
576         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
577
578 #define ENC_SEPARATOR \
579         {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"}
580 #define ENC_ACTION(action) \
581          NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
582
583         {N_("/_View/Character _encoding"),              NULL, NULL, 0, "<Branch>"},
584         {N_("/_View/Character _encoding/_Auto detect"),
585          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
586         {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"},
587         {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
588          ENC_ACTION(C_US_ASCII)},
589         {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
590          ENC_ACTION(C_UTF_8)},
591         ENC_SEPARATOR,
592
593         {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
594          ENC_ACTION(C_ISO_8859_1)},
595         {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
596          ENC_ACTION(C_ISO_8859_15)},
597         {N_("/_View/Character _encoding/Western European (Windows-1252)"),
598          ENC_ACTION(C_WINDOWS_1252)},
599         ENC_SEPARATOR,
600
601         {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
602          ENC_ACTION(C_ISO_8859_2)},
603         ENC_SEPARATOR,
604
605         {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
606          ENC_ACTION(C_ISO_8859_13)},
607         {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
608          ENC_ACTION(C_ISO_8859_4)},
609         ENC_SEPARATOR,
610
611         {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
612          ENC_ACTION(C_ISO_8859_7)},
613         ENC_SEPARATOR,
614
615         {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
616          ENC_ACTION(C_ISO_8859_8)},
617         {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
618          ENC_ACTION(C_CP1255)},
619         ENC_SEPARATOR,
620
621         {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
622          ENC_ACTION(C_ISO_8859_6)},
623         {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
624          ENC_ACTION(C_CP1256)},
625         ENC_SEPARATOR,
626
627         {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
628          ENC_ACTION(C_ISO_8859_9)},
629         ENC_SEPARATOR,
630
631         {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
632          ENC_ACTION(C_ISO_8859_5)},
633         {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
634          ENC_ACTION(C_KOI8_R)},
635         {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
636          ENC_ACTION(C_KOI8_U)},
637         {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
638          ENC_ACTION(C_CP1251)},
639         ENC_SEPARATOR,
640
641         {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
642          ENC_ACTION(C_ISO_2022_JP)},
643         {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
644          ENC_ACTION(C_ISO_2022_JP_2)},
645         {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
646          ENC_ACTION(C_EUC_JP)},
647         {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
648          ENC_ACTION(C_SHIFT_JIS)},
649         ENC_SEPARATOR,
650
651         {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
652          ENC_ACTION(C_GB2312)},
653         {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
654          ENC_ACTION(C_GBK)},
655         {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
656          ENC_ACTION(C_BIG5)},
657         {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
658          ENC_ACTION(C_EUC_TW)},
659         {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
660          ENC_ACTION(C_ISO_2022_CN)},
661         ENC_SEPARATOR,
662
663         {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
664          ENC_ACTION(C_EUC_KR)},
665         {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
666          ENC_ACTION(C_ISO_2022_KR)},
667         ENC_SEPARATOR,
668
669         {N_("/_View/Character _encoding/Thai (TIS-620)"),
670          ENC_ACTION(C_TIS_620)},
671         {N_("/_View/Character _encoding/Thai (Windows-874)"),
672          ENC_ACTION(C_WINDOWS_874)},
673
674 #undef ENC_SEPARATOR
675 #undef ENC_ACTION
676
677 #define DEC_SEPARATOR \
678         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"}
679 #define DEC_ACTION(action) \
680          NULL, set_decode_cb, action, "/View/Decode/Auto detect"
681         {N_("/_View/Decode"),           NULL, NULL, 0, "<Branch>"},
682         {N_("/_View/Decode/_Auto detect"),
683          NULL, set_decode_cb, 0, "<RadioItem>"},
684         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"},
685         {N_("/_View/Decode/_8bit"),             DEC_ACTION(ENC_8BIT)},
686         {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
687         {N_("/_View/Decode/_Base64"),           DEC_ACTION(ENC_BASE64)},
688         {N_("/_View/Decode/_Uuencode"),         DEC_ACTION(ENC_X_UUENCODE)},
689
690 #undef DEC_SEPARATOR
691 #undef DEC_ACTION
692
693         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
694         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
695         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
696         {N_("/_View/Show all headers"),         "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
697         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
698         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
699
700         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
701         {N_("/_Message/Recei_ve"),              NULL, NULL, 0, "<Branch>"},
702         {N_("/_Message/Recei_ve/Get from _current account"),
703                                                 "<control>I",   inc_mail_cb, 0, NULL},
704         {N_("/_Message/Recei_ve/Get from _all accounts"),
705                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
706         {N_("/_Message/Recei_ve/Cancel receivin_g"),
707                                                 NULL, inc_cancel_cb, 0, NULL},
708         {N_("/_Message/Recei_ve/---"),          NULL, NULL, 0, "<Separator>"},
709         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
710         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
711         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
712         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
713         {N_("/_Message/_Reply"),                "<control>R",   main_window_reply_cb, COMPOSE_REPLY, NULL},
714         {N_("/_Message/Repl_y to"),             NULL, NULL, 0, "<Branch>"},
715         {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
716         {N_("/_Message/Repl_y to/_sender"),     NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
717         {N_("/_Message/Repl_y to/mailing _list"),
718                                                 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
719         {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
720         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
721         {N_("/_Message/_Forward"),              "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
722         {N_("/_Message/For_ward as attachment"),        NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
723         {N_("/_Message/Redirect"),              NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
724
725         {N_("/_Message/Mailing-_List"),                 NULL, NULL, 0, "<Branch>"},
726         {N_("/_Message/Mailing-_List/Post"),            NULL, NULL, 0, "<Branch>"},
727         {N_("/_Message/Mailing-_List/Help"),            NULL, NULL, 0, "<Branch>"},
728         {N_("/_Message/Mailing-_List/Subscribe"),       NULL, NULL, 0, "<Branch>"},
729         {N_("/_Message/Mailing-_List/Unsubscribe"),     NULL, NULL, 0, "<Branch>"},
730         {N_("/_Message/Mailing-_List/View archive"),    NULL, NULL, 0, "<Branch>"},
731         {N_("/_Message/Mailing-_List/Contact owner"),   NULL, NULL, 0, "<Branch>"},
732         
733         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
734         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
735         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
736         {N_("/_Message/Move to _trash"),        "<control>D", delete_trash_cb,  0, NULL},
737         {N_("/_Message/_Delete..."),            NULL, delete_cb,  0, NULL},
738         {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
739         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
740         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
741         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
742         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
743         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
744         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
745         {N_("/_Message/_Mark/Mark as rea_d"),   NULL, mark_as_read_cb, 0, NULL},
746         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
747         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
748         {N_("/_Message/_Mark/Mark as _spam"),   NULL, mark_as_spam_cb, 1, NULL},
749         {N_("/_Message/_Mark/Mark as _ham"),    NULL, mark_as_spam_cb, 0, NULL},
750         {N_("/_Message/Color la_bel"),          NULL, NULL,            0, NULL},
751         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
752         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
753
754         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
755         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
756         {N_("/_Tools/Add sender to address boo_k"),
757                                                 NULL, add_address_cb, 0, NULL},
758         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
759         {N_("/_Tools/_Harvest addresses/from _Folder..."),
760                                                 NULL, addr_harvest_cb, 0, NULL},
761         {N_("/_Tools/_Harvest addresses/from _Messages..."),
762                                                 NULL, addr_harvest_msg_cb, 0, NULL},
763         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
764         {N_("/_Tools/_Filter all messages in folder"),
765                                                 NULL, filter_cb, 0, NULL},
766         {N_("/_Tools/Filter _selected messages"),
767                                                 NULL, filter_cb, 1, NULL},
768         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
769         {N_("/_Tools/_Create filter rule/_Automatically"),
770                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
771         {N_("/_Tools/_Create filter rule/by _From"),
772                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
773         {N_("/_Tools/_Create filter rule/by _To"),
774                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
775         {N_("/_Tools/_Create filter rule/by _Subject"),
776                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
777         {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
778         {N_("/_Tools/C_reate processing rule/_Automatically"),
779                                                 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
780         {N_("/_Tools/C_reate processing rule/by _From"),
781                                                 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
782         {N_("/_Tools/C_reate processing rule/by _To"),
783                                                 NULL, create_processing_cb, FILTER_BY_TO, NULL},
784         {N_("/_Tools/C_reate processing rule/by _Subject"),
785                                                 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
786         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
787         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
788         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
789         {N_("/_Tools/Ch_eck for new messages in all folders"),
790                                                 NULL, update_folderview_cb, 0, NULL},
791         {N_("/_Tools/Delete du_plicated messages"),
792                                                 NULL, NULL, 0, "<Branch>"},
793         {N_("/_Tools/Delete du_plicated messages/In selected folder"),
794                                                 NULL, delete_duplicated_cb,   0, NULL},
795         {N_("/_Tools/Delete du_plicated messages/In all folders"),
796                                                 NULL, delete_duplicated_all_cb,   0, NULL},
797         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
798         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
799 #ifdef USE_OPENSSL
800         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
801         {N_("/_Tools/SSL cer_tificates..."),    
802                                                 NULL, ssl_manager_open_cb, 0, NULL},
803 #endif
804         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
805         {N_("/_Tools/_Log window"),             "<shift><control>L", log_window_show_cb, 0, NULL},
806
807         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
808         {N_("/_Configuration/C_hange current account"),
809                                                 NULL, NULL, 0, "<Branch>"},
810         {N_("/_Configuration/_Preferences for current account..."),
811                                                 NULL, prefs_account_open_cb, 0, NULL},
812         {N_("/_Configuration/Create _new account..."),
813                                                 NULL, new_account_cb, 0, NULL},
814         {N_("/_Configuration/_Edit accounts..."),
815                                                 NULL, account_edit_open, 0, NULL},
816         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
817         {N_("/_Configuration/P_references..."),
818                                                 NULL, prefs_open_cb, 0, NULL},
819         {N_("/_Configuration/Pre-pr_ocessing..."),
820                                                 NULL, prefs_pre_processing_open_cb, 0, NULL},
821         {N_("/_Configuration/Post-pro_cessing..."),
822                                                 NULL, prefs_post_processing_open_cb, 0, NULL},
823         {N_("/_Configuration/_Filtering..."),
824                                                 NULL, prefs_filtering_open_cb, 0, NULL},
825         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
826         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
827         {N_("/_Configuration/Plu_gins..."),     NULL, plugins_open_cb, 0, NULL},
828
829         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
830         {N_("/_Help/_Manual"),                  NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
831         {N_("/_Help/_Online User-contributed FAQ"),     
832                                                 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
833         {N_("/_Help/Icon _Legend"),             NULL, legend_open_cb, 0, NULL},
834         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
835         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
836 };
837
838 static gboolean offline_ask_sync = TRUE;
839 static guint lastkey;
840
841 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
842                                             GObject *arg1,
843                                             guint value,
844                                             GdkModifierType mod,
845                                             gpointer user_data) 
846 {
847         MainWindow *mainwin = (MainWindow *)user_data;
848
849         if (mainwin->summaryview &&
850             mainwin->summaryview->quicksearch &&
851             quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
852             (mod == 0 || mod == GDK_SHIFT_MASK)) {
853                 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
854                 return TRUE;
855         }
856         return FALSE;
857 }
858
859 #define N_COLOR_LABELS colorlabel_get_color_count()
860
861 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
862                                                           gpointer data)
863 {
864         MainWindow *mainwin;
865         GtkMenuShell *menu;
866         GtkCheckMenuItem **items;
867         gint n;
868         GList *cur, *sel;
869
870         mainwin = (MainWindow *)data;
871         g_return_if_fail(mainwin != NULL);
872
873         sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
874         if (!sel) return;
875
876         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
877         g_return_if_fail(menu != NULL);
878
879         Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
880
881         /* NOTE: don't return prematurely because we set the "dont_toggle"
882          * state for check menu items */
883         g_object_set_data(G_OBJECT(menu), "dont_toggle",
884                           GINT_TO_POINTER(1));
885
886         /* clear items. get item pointers. */
887         for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
888                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
889                         gtk_check_menu_item_set_active
890                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
891                         items[n] = GTK_CHECK_MENU_ITEM(cur->data);
892                         n++;
893                 }
894         }
895
896         if (n == (N_COLOR_LABELS + 1)) {
897                 /* iterate all messages and set the state of the appropriate
898                  * items */
899                 for (; sel != NULL; sel = sel->next) {
900                         MsgInfo *msginfo;
901                         gint clabel;
902
903                         msginfo = gtk_ctree_node_get_row_data
904                                 (GTK_CTREE(mainwin->summaryview->ctree),
905                                  GTK_CTREE_NODE(sel->data));
906                         if (msginfo) {
907                                 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
908                                 if (!items[clabel]->active)
909                                         gtk_check_menu_item_set_active
910                                                 (items[clabel], TRUE);
911                         }
912                 }
913         } else
914                 g_warning("invalid number of color elements (%d)\n", n);
915
916         /* reset "dont_toggle" state */
917         g_object_set_data(G_OBJECT(menu), "dont_toggle",
918                           GINT_TO_POINTER(0));
919 }
920
921 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
922                                                      gpointer data)
923 {
924         guint color = GPOINTER_TO_UINT(data);
925         MainWindow *mainwin;
926
927         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
928         g_return_if_fail(mainwin != NULL);
929
930         /* "dont_toggle" state set? */
931         if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
932                                 "dont_toggle"))
933                 return;
934
935         summary_set_colorlabel(mainwin->summaryview, color, NULL);
936 }
937
938 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
939 {
940         GtkWidget *label_menuitem;
941         GtkWidget *menu;
942         GtkWidget *item;
943         gint i;
944
945         label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
946                                                    "/Message/Color label");
947         g_signal_connect(G_OBJECT(label_menuitem), "activate",
948                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
949                            mainwin);
950         gtk_widget_show(label_menuitem);
951
952         menu = gtk_menu_new();
953
954         /* create sub items. for the menu item activation callback we pass the
955          * index of label_colors[] as data parameter. for the None color we
956          * pass an invalid (high) value. also we attach a data pointer so we
957          * can always get back the Mainwindow pointer. */
958
959         item = gtk_check_menu_item_new_with_label(_("None"));
960         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
961         g_signal_connect(G_OBJECT(item), "activate",
962                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
963                            GUINT_TO_POINTER(0));
964         g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
965         gtk_widget_show(item);
966
967         gtk_widget_add_accelerator(item, "activate", 
968                                    mainwin->menu_factory->accel_group, 
969                                    GDK_0, GDK_CONTROL_MASK,
970                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
971
972         item = gtk_menu_item_new();
973         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
974         gtk_widget_show(item);
975
976         /* create pixmap/label menu items */
977         for (i = 0; i < N_COLOR_LABELS; i++) {
978                 item = colorlabel_create_check_color_menu_item(
979                         i, refresh, MAINWIN_COLORMENU);
980                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
981                 g_signal_connect(G_OBJECT(item), "activate",
982                                  G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
983                                  GUINT_TO_POINTER(i + 1));
984                 g_object_set_data(G_OBJECT(item), "mainwin",
985                                   mainwin);
986                 gtk_widget_show(item);
987                 gtk_widget_add_accelerator(item, "activate", 
988                                    mainwin->menu_factory->accel_group, 
989                                    GDK_1+i, GDK_CONTROL_MASK,
990                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
991         }
992
993         gtk_widget_show(menu);
994         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
995         mainwin->colorlabel_menu = menu;
996 }
997
998
999 MainWindow *main_window_create(SeparateType type)
1000 {
1001         MainWindow *mainwin;
1002         GtkWidget *window;
1003         GtkWidget *vbox;
1004         GtkWidget *menubar;
1005         GtkWidget *handlebox;
1006         GtkWidget *vbox_body;
1007         GtkWidget *hbox_stat;
1008         GtkWidget *statusbar;
1009         GtkWidget *progressbar;
1010         GtkWidget *statuslabel;
1011         GtkWidget *ac_button;
1012         GtkWidget *ac_label;
1013         GtkWidget *online_pixmap;
1014         GtkWidget *offline_pixmap;
1015         GtkWidget *online_switch;
1016         GtkWidget *offline_switch;
1017         GtkTooltips *offline_tip;
1018         GtkTooltips *online_tip;
1019         GtkTooltips *sel_ac_tip;
1020
1021         FolderView *folderview;
1022         SummaryView *summaryview;
1023         MessageView *messageview;
1024         GdkColormap *colormap;
1025         GdkColor color[4];
1026         gboolean success[4];
1027         GtkItemFactory *ifactory;
1028         GtkWidget *ac_menu;
1029         GtkWidget *menuitem;
1030         gint i;
1031         guint n_menu_entries;
1032
1033         static GdkGeometry geometry;
1034
1035         debug_print("Creating main window...\n");
1036         mainwin = g_new0(MainWindow, 1);
1037
1038         /* main window */
1039         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1040         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1041         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1042
1043         if (!geometry.min_height) {
1044                 geometry.min_width = 320;
1045                 geometry.min_height = 200;
1046         }
1047         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1048                                       GDK_HINT_MIN_SIZE);
1049
1050         g_signal_connect(G_OBJECT(window), "delete_event",
1051                          G_CALLBACK(main_window_close_cb), mainwin);
1052         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1053         g_signal_connect(G_OBJECT(window), "focus_in_event",
1054                          G_CALLBACK(mainwindow_focus_in_event),
1055                          mainwin);
1056         g_signal_connect(G_OBJECT(window), "key_press_event",
1057                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1058
1059         gtk_widget_realize(window);
1060         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1061         
1062
1063         gtkut_widget_set_app_icon(window);
1064
1065         vbox = gtk_vbox_new(FALSE, 0);
1066         gtk_widget_show(vbox);
1067         gtk_container_add(GTK_CONTAINER(window), vbox);
1068
1069         /* menu bar */
1070         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1071         menubar = menubar_create(window, mainwin_entries, 
1072                                  n_menu_entries, "<Main>", mainwin);
1073         gtk_widget_show(menubar);
1074         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1075         ifactory = gtk_item_factory_from_widget(menubar);
1076
1077 /*      gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1078         main_create_mailing_list_menu (mainwin, NULL); */
1079
1080         menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1081
1082         if (prefs_common.toolbar_detachable) {
1083                 handlebox = gtk_handle_box_new();
1084                 gtk_widget_show(handlebox);
1085                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1086                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1087                                  G_CALLBACK(toolbar_child_attached), mainwin);
1088                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1089                                  G_CALLBACK(toolbar_child_detached), mainwin);
1090         } else {
1091                 handlebox = gtk_hbox_new(FALSE, 0);
1092                 gtk_widget_show(handlebox);
1093                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1094         }
1095         /* link window to mainwin->window to avoid gdk warnings */
1096         mainwin->window       = window;
1097         
1098         /* create toolbar */
1099         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1100                                           handlebox, 
1101                                           (gpointer)mainwin);
1102         toolbar_set_learn_button
1103                 (mainwin->toolbar,
1104                  LEARN_SPAM);
1105
1106         /* vbox that contains body */
1107         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1108         gtk_widget_show(vbox_body);
1109         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1110         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1111
1112         hbox_stat = gtk_hbox_new(FALSE, 2);
1113         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1114
1115         statusbar = statusbar_create();
1116         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1117
1118         progressbar = gtk_progress_bar_new();
1119         gtk_widget_set_size_request(progressbar, 120, 1);
1120         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1121
1122         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1123         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1124         online_tip = gtk_tooltips_new();
1125         online_switch = gtk_button_new ();
1126         gtk_tooltips_set_tip(GTK_TOOLTIPS(online_tip),online_switch, 
1127                              _("You are online. Click the icon to go offline"), NULL);
1128         offline_tip = gtk_tooltips_new();
1129         offline_switch = gtk_button_new ();
1130         gtk_tooltips_set_tip(GTK_TOOLTIPS(offline_tip),offline_switch, 
1131                              _("You are offline. Click the icon to go online"),
1132                              NULL);
1133         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1134         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1135         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1136         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1137         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1138         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1139         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1140         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1141         
1142         statuslabel = gtk_label_new("");
1143         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1144
1145         sel_ac_tip = gtk_tooltips_new();
1146         ac_button = gtk_button_new();
1147         gtk_tooltips_set_tip(GTK_TOOLTIPS(sel_ac_tip),
1148                              ac_button, _("Select account"), NULL);
1149         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1150         gtk_widget_set_size_request(ac_button, -1, 0);
1151         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1152         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1153                          G_CALLBACK(ac_label_button_pressed), mainwin);
1154
1155         ac_label = gtk_label_new("");
1156         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1157
1158         gtk_widget_show_all(hbox_stat);
1159
1160         gtk_widget_hide(offline_switch);
1161         /* create views */
1162         mainwin->folderview  = folderview  = folderview_create();
1163         mainwin->summaryview = summaryview = summary_create();
1164         mainwin->messageview = messageview = messageview_create(mainwin);
1165         mainwin->logwin      = log_window_create();
1166
1167         folderview->mainwin      = mainwin;
1168         folderview->summaryview  = summaryview;
1169
1170         summaryview->mainwin     = mainwin;
1171         summaryview->folderview  = folderview;
1172         summaryview->messageview = messageview;
1173         summaryview->window      = window;
1174
1175         messageview->statusbar   = statusbar;
1176         mainwin->vbox           = vbox;
1177         mainwin->menubar        = menubar;
1178         mainwin->menu_factory   = ifactory;
1179         mainwin->handlebox      = handlebox;
1180         mainwin->vbox_body      = vbox_body;
1181         mainwin->hbox_stat      = hbox_stat;
1182         mainwin->statusbar      = statusbar;
1183         mainwin->progressbar    = progressbar;
1184         mainwin->statuslabel    = statuslabel;
1185         mainwin->online_switch  = online_switch;
1186         mainwin->online_pixmap  = online_pixmap;
1187         mainwin->offline_pixmap = offline_pixmap;
1188         mainwin->ac_button      = ac_button;
1189         mainwin->ac_label       = ac_label;
1190         mainwin->offline_switch    = offline_switch;
1191         
1192         /* set context IDs for status bar */
1193         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1194                 (GTK_STATUSBAR(statusbar), "Main Window");
1195         mainwin->folderview_cid = gtk_statusbar_get_context_id
1196                 (GTK_STATUSBAR(statusbar), "Folder View");
1197         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1198                 (GTK_STATUSBAR(statusbar), "Summary View");
1199         mainwin->messageview_cid = gtk_statusbar_get_context_id
1200                 (GTK_STATUSBAR(statusbar), "Message View");
1201
1202         messageview->statusbar_cid = mainwin->messageview_cid;
1203
1204         /* allocate colors for summary view and folder view */
1205         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1206         summaryview->color_marked.blue = (guint16)65535;
1207
1208         summaryview->color_dim.red = summaryview->color_dim.green =
1209                 summaryview->color_dim.blue = COLOR_DIM;
1210
1211         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1212                                        &folderview->color_new);
1213
1214         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1215                                        &folderview->color_op);
1216
1217         summaryview->color_important.red = 0;
1218         summaryview->color_important.green = 0;
1219         summaryview->color_important.blue = (guint16)65535;
1220
1221         color[0] = summaryview->color_marked;
1222         color[1] = summaryview->color_dim;
1223         color[2] = folderview->color_new;
1224         color[3] = folderview->color_op;
1225
1226         colormap = gdk_drawable_get_colormap(window->window);
1227         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1228         for (i = 0; i < 4; i++) {
1229                 if (success[i] == FALSE)
1230                         g_warning("MainWindow: color allocation %d failed\n", i);
1231         }
1232
1233         debug_print("done.\n");
1234
1235         messageview->visible = prefs_common.msgview_visible;
1236
1237         main_window_set_widgets(mainwin, type);
1238
1239         g_signal_connect(G_OBJECT(window), "size_allocate",
1240                          G_CALLBACK(main_window_size_allocate_cb),
1241                          mainwin);
1242
1243         /* set menu items */
1244         menuitem = gtk_item_factory_get_item
1245                 (ifactory, "/View/Character encoding/Auto detect");
1246         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1247
1248         switch (prefs_common.toolbar_style) {
1249         case TOOLBAR_NONE:
1250                 menuitem = gtk_item_factory_get_item
1251                         (ifactory, "/View/Show or hide/Toolbar/Hide");
1252                 break;
1253         case TOOLBAR_ICON:
1254                 menuitem = gtk_item_factory_get_item
1255                         (ifactory, "/View/Show or hide/Toolbar/Icons only");
1256                 break;
1257         case TOOLBAR_TEXT:
1258                 menuitem = gtk_item_factory_get_item
1259                         (ifactory, "/View/Show or hide/Toolbar/Text only");
1260                 break;
1261         case TOOLBAR_BOTH:
1262                 menuitem = gtk_item_factory_get_item
1263                         (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1264                 break;
1265         case TOOLBAR_BOTH_HORIZ:
1266                 menuitem = gtk_item_factory_get_item
1267                         (ifactory,
1268                          "/View/Show or hide/Toolbar/Text beside icons");
1269         }
1270         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1271
1272         gtk_widget_hide(mainwin->hbox_stat);
1273         menuitem = gtk_item_factory_get_item
1274                 (ifactory, "/View/Show or hide/Status bar");
1275         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1276                                        prefs_common.show_statusbar);
1277         
1278         /* set account selection menu */
1279         ac_menu = gtk_item_factory_get_widget
1280                 (ifactory, "/Configuration/Change current account");
1281         mainwin->ac_menu = ac_menu;
1282
1283         toolbar_main_set_sensitive(mainwin);
1284
1285         /* create actions menu */
1286         main_window_update_actions_menu(mainwin);
1287
1288         main_create_mailing_list_menu (mainwin, NULL);
1289
1290         /* attach accel groups to main window */
1291 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
1292         gtk_window_add_accel_group                                      \
1293                 (GTK_WINDOW(win),                                       \
1294                  gtk_item_factory_from_widget(menu)->accel_group);      \
1295         g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1296                         "accel_activate",                               \
1297                         G_CALLBACK(main_window_accel_activate), mainwin);
1298                          
1299         
1300         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1301         
1302         /* connect the accelerators for equivalent 
1303            menu items in different menus             */
1304         menu_connect_identical_items();
1305
1306
1307         gtk_window_iconify(GTK_WINDOW(mainwin->window));
1308
1309         gtk_widget_show(mainwin->window);
1310
1311         /* initialize views */
1312         folderview_init(folderview);
1313         summary_init(summaryview);
1314         messageview_init(messageview);
1315         log_window_init(mainwin->logwin);
1316         log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
1317                                 prefs_common.loglength);
1318 #ifdef USE_OPENSSL
1319         sslcertwindow_register_hook();
1320 #endif
1321         mainwin->lock_count = 0;
1322         mainwin->menu_lock_count = 0;
1323         mainwin->cursor_count = 0;
1324
1325         mainwin->progressindicator_hook =
1326                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1327
1328         if (!watch_cursor)
1329                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1330
1331         mainwin_list = g_list_append(mainwin_list, mainwin);
1332
1333         /* init work_offline */
1334         if (prefs_common.work_offline)
1335                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1336
1337         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1338
1339         return mainwin;
1340 }
1341
1342 void main_window_destroy(MainWindow *mainwin)
1343 {
1344         /* TODO : destroy other component */
1345         messageview_destroy(mainwin->messageview);
1346         mainwin->messageview = NULL;    
1347 }
1348
1349 void main_window_update_actions_menu(MainWindow *mainwin)
1350 {
1351         GtkItemFactory *ifactory;
1352
1353         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1354         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1355 }
1356
1357 void main_window_cursor_wait(MainWindow *mainwin)
1358 {
1359
1360         if (mainwin->cursor_count == 0) {
1361                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1362                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1363         }
1364         
1365         mainwin->cursor_count++;
1366
1367         gdk_flush();
1368 }
1369
1370 void main_window_cursor_normal(MainWindow *mainwin)
1371 {
1372         if (mainwin->cursor_count)
1373                 mainwin->cursor_count--;
1374
1375         if (mainwin->cursor_count == 0) {
1376                 gdk_window_set_cursor(mainwin->window->window, NULL);
1377                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1378         }
1379         gdk_flush();
1380 }
1381
1382 /* lock / unlock the user-interface */
1383 void main_window_lock(MainWindow *mainwin)
1384 {
1385         if (mainwin->lock_count == 0)
1386                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1387
1388         mainwin->lock_count++;
1389
1390         main_window_set_menu_sensitive(mainwin);
1391         toolbar_main_set_sensitive(mainwin);
1392 }
1393
1394 void main_window_unlock(MainWindow *mainwin)
1395 {
1396         if (mainwin->lock_count)
1397                 mainwin->lock_count--;
1398
1399         main_window_set_menu_sensitive(mainwin);
1400         toolbar_main_set_sensitive(mainwin);
1401
1402         if (mainwin->lock_count == 0)
1403                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1404 }
1405
1406 static void main_window_menu_callback_block(MainWindow *mainwin)
1407 {
1408         mainwin->menu_lock_count++;
1409 }
1410
1411 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1412 {
1413         if (mainwin->menu_lock_count)
1414                 mainwin->menu_lock_count--;
1415 }
1416
1417 static guint prefs_tag = 0;
1418
1419 void main_window_reflect_prefs_all(void)
1420 {
1421         main_window_reflect_prefs_all_real(FALSE);
1422 }
1423
1424 static gboolean reflect_prefs_timeout_cb(gpointer data) 
1425 {
1426         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1427         GList *cur;
1428         MainWindow *mainwin;
1429         GtkWidget *pixmap;
1430
1431         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1432                 mainwin = (MainWindow *)cur->data;
1433
1434                 main_window_show_cur_account(mainwin);
1435                 main_window_set_menu_sensitive(mainwin);
1436                 toolbar_main_set_sensitive(mainwin);
1437
1438                 /* pixmap themes */
1439                 if (pixmap_theme_changed) {
1440                         toolbar_update(TOOLBAR_MAIN, mainwin);
1441                         messageview_reflect_prefs_pixmap_theme();
1442                         compose_reflect_prefs_pixmap_theme();
1443                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1444                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1445
1446                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1447                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1448                                              mainwin->online_pixmap);
1449                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1450                         gtk_widget_show(pixmap);
1451                         mainwin->online_pixmap = pixmap;
1452                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1453                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1454                                              mainwin->offline_pixmap);
1455                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1456                         gtk_widget_show(pixmap);
1457                         mainwin->offline_pixmap = pixmap;
1458                 }
1459                 
1460                 headerview_set_font(mainwin->messageview->headerview);
1461                 headerview_set_visibility(mainwin->messageview->headerview,
1462                                           prefs_common.display_header_pane);
1463                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1464                 folderview_reflect_prefs();
1465                 summary_reflect_prefs();
1466                 summary_redisplay_msg(mainwin->summaryview);
1467         }
1468         prefs_tag = 0;
1469         return FALSE;
1470 }
1471
1472 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1473 {
1474         GtkMenuShell *menu;
1475         GList *cur;
1476
1477         /* re-create colorlabel submenu */
1478         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1479         g_return_if_fail(menu != NULL);
1480
1481         /* clear items. get item pointers. */
1482         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1483                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1484         }
1485         mainwindow_colorlabel_menu_create(mainwin, TRUE);
1486         summary_reflect_prefs_custom_colors(mainwin->summaryview);
1487
1488 }
1489
1490 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1491 {
1492         if (prefs_tag == 0 || pixmap_theme_changed) {
1493                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
1494                                                 GINT_TO_POINTER(pixmap_theme_changed));
1495         }
1496 }
1497
1498 void main_window_set_summary_column(void)
1499 {
1500         GList *cur;
1501         MainWindow *mainwin;
1502
1503         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1504                 mainwin = (MainWindow *)cur->data;
1505                 summary_set_column_order(mainwin->summaryview);
1506         }
1507 }
1508
1509 void main_window_set_folder_column(void)
1510 {
1511         GList *cur;
1512         MainWindow *mainwin;
1513
1514         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1515                 mainwin = (MainWindow *)cur->data;
1516                 folderview_set_column_order(mainwin->folderview);
1517         }
1518 }
1519
1520 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1521                                                   GList *account_list)
1522 {
1523         GList *cur_ac, *cur_item;
1524         GtkWidget *menuitem;
1525         PrefsAccount *ac_prefs;
1526
1527         /* destroy all previous menu item */
1528         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1529         while (cur_item != NULL) {
1530                 GList *next = cur_item->next;
1531                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1532                 cur_item = next;
1533         }
1534
1535         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1536                 ac_prefs = (PrefsAccount *)cur_ac->data;
1537
1538                 menuitem = gtk_menu_item_new_with_label
1539                         (ac_prefs->account_name
1540                          ? ac_prefs->account_name : _("Untitled"));
1541                 gtk_widget_show(menuitem);
1542                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1543                 g_signal_connect(G_OBJECT(menuitem), "activate",
1544                                  G_CALLBACK(account_selector_menu_cb),
1545                                  ac_prefs);
1546         }
1547 }
1548
1549 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1550                                                  GList *account_list)
1551 {
1552         GList *cur_ac, *cur_item;
1553         GtkWidget *menu;
1554         GtkWidget *menuitem;
1555         PrefsAccount *ac_prefs;
1556
1557         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1558                                            "/Message/Receive");
1559
1560         /* search for separator */
1561         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1562              cur_item = cur_item->next) {
1563                 if (GTK_BIN(cur_item->data)->child == NULL) {
1564                         cur_item = cur_item->next;
1565                         break;
1566                 }
1567         }
1568
1569         /* destroy all previous menu item */
1570         while (cur_item != NULL) {
1571                 GList *next = cur_item->next;
1572                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1573                 cur_item = next;
1574         }
1575
1576         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1577                 ac_prefs = (PrefsAccount *)cur_ac->data;
1578
1579                 menuitem = gtk_menu_item_new_with_label
1580                         (ac_prefs->account_name ? ac_prefs->account_name
1581                          : _("Untitled"));
1582                 gtk_widget_show(menuitem);
1583                 gtk_menu_append(GTK_MENU(menu), menuitem);
1584                 g_signal_connect(G_OBJECT(menuitem), "activate",
1585                                  G_CALLBACK(account_receive_menu_cb),
1586                                  ac_prefs);
1587         }
1588 }
1589
1590 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1591                                                        GList *account_list)
1592 {
1593         GList *cur_ac, *cur_item;
1594         GtkWidget *menuitem;
1595         PrefsAccount *ac_prefs;
1596         GtkWidget *menu = NULL;
1597
1598         if (mainwin->toolbar->getall_btn == NULL
1599         ||  mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1600                 return;
1601
1602         menu = mainwin->toolbar->getall_combo->menu;
1603
1604         /* destroy all previous menu item */
1605         cur_item = GTK_MENU_SHELL(menu)->children;
1606         while (cur_item != NULL) {
1607                 GList *next = cur_item->next;
1608                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1609                 cur_item = next;
1610         }
1611
1612         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1613                 ac_prefs = (PrefsAccount *)cur_ac->data;
1614
1615                 menuitem = gtk_menu_item_new_with_label
1616                         (ac_prefs->account_name
1617                          ? ac_prefs->account_name : _("Untitled"));
1618                 gtk_widget_show(menuitem);
1619                 gtk_menu_append(GTK_MENU(menu), menuitem);
1620                 g_signal_connect(G_OBJECT(menuitem), "activate",
1621                                  G_CALLBACK(account_receive_menu_cb),
1622                                  ac_prefs);
1623         }
1624 }
1625
1626 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1627                                                        GList *account_list)
1628 {
1629         GList *cur_ac, *cur_item;
1630         GtkWidget *menuitem;
1631         PrefsAccount *ac_prefs;
1632         GtkWidget *menu = NULL;
1633
1634         if (mainwin->toolbar->compose_mail_btn == NULL
1635         ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
1636                 return;
1637
1638         menu = mainwin->toolbar->compose_combo->menu;
1639
1640         /* destroy all previous menu item */
1641         cur_item = GTK_MENU_SHELL(menu)->children;
1642         while (cur_item != NULL) {
1643                 GList *next = cur_item->next;
1644                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1645                 cur_item = next;
1646         }
1647
1648         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1649                 ac_prefs = (PrefsAccount *)cur_ac->data;
1650
1651                 menuitem = gtk_menu_item_new_with_label
1652                         (ac_prefs->account_name
1653                          ? ac_prefs->account_name : _("Untitled"));
1654                 gtk_widget_show(menuitem);
1655                 gtk_menu_append(GTK_MENU(menu), menuitem);
1656                 g_signal_connect(G_OBJECT(menuitem), "activate",
1657                                  G_CALLBACK(account_compose_menu_cb),
1658                                  ac_prefs);
1659         }
1660 }
1661
1662 void main_window_set_account_menu(GList *account_list)
1663 {
1664         GList *cur;
1665         MainWindow *mainwin;
1666
1667         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1668                 mainwin = (MainWindow *)cur->data;
1669                 main_window_set_account_selector_menu(mainwin, account_list);
1670                 main_window_set_account_receive_menu(mainwin, account_list);
1671                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1672                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1673         }
1674 }
1675
1676 void main_window_set_account_menu_only_toolbar(GList *account_list)
1677 {
1678         GList *cur;
1679         MainWindow *mainwin;
1680
1681         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1682                 mainwin = (MainWindow *)cur->data;
1683                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1684                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1685         }
1686 }
1687
1688 static void main_window_show_cur_account(MainWindow *mainwin)
1689 {
1690         gchar *buf;
1691         gchar *ac_name;
1692
1693         ac_name = g_strdup(cur_account
1694                            ? (cur_account->account_name
1695                               ? cur_account->account_name : _("Untitled"))
1696                            : _("none"));
1697
1698         if (cur_account)
1699                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1700         else
1701                 buf = g_strdup(PROG_VERSION);
1702         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1703         g_free(buf);
1704
1705         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1706         gtk_widget_queue_resize(mainwin->ac_button);
1707
1708         g_free(ac_name);
1709 }
1710
1711 GtkWidget *main_window_get_folder_window(MainWindow *mainwin)
1712 {
1713         switch (mainwin->type) {
1714         case SEPARATE_FOLDER:
1715                 return mainwin->win.sep_folder.folderwin;
1716         case SEPARATE_BOTH:
1717                 return mainwin->win.sep_both.folderwin;
1718         default:
1719                 return NULL;
1720         }
1721 }
1722
1723 GtkWidget *main_window_get_message_window(MainWindow *mainwin)
1724 {
1725         switch (mainwin->type) {
1726         case SEPARATE_MESSAGE:
1727                 return mainwin->win.sep_message.messagewin;
1728         case SEPARATE_BOTH:
1729                 return mainwin->win.sep_both.messagewin;
1730         default:
1731                 return NULL;
1732         }
1733 }
1734
1735 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1736 {
1737         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1738         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1739         /* GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview); */
1740         GtkWidget *message_wid = mainwin->messageview->vbox;
1741
1742         debug_print("Changing window separation type from %d to %d\n",
1743                     mainwin->type, type);
1744
1745         if (mainwin->type == type) return;
1746
1747         /* remove widgets from those containers */
1748         gtk_widget_ref(folder_wid);
1749         gtk_widget_ref(summary_wid);
1750         gtk_widget_ref(message_wid);
1751         gtkut_container_remove
1752                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1753         gtkut_container_remove
1754                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1755         gtkut_container_remove
1756                 (GTK_CONTAINER(message_wid->parent), message_wid);
1757
1758         /* clean containers */
1759         switch (mainwin->type) {
1760         case SEPARATE_NONE:
1761                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1762                 break;
1763         case SEPARATE_FOLDER:
1764                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1765                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1766                 break;
1767         case SEPARATE_MESSAGE:
1768                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1769                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1770                 break;
1771         case SEPARATE_BOTH:
1772                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1773                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1774                 break;
1775         }
1776
1777         gtk_widget_hide(mainwin->window);
1778         main_window_set_widgets(mainwin, type);
1779         gtk_widget_show(mainwin->window);
1780
1781         gtk_widget_unref(folder_wid);
1782         gtk_widget_unref(summary_wid);
1783         gtk_widget_unref(message_wid);
1784 }
1785
1786 void main_window_toggle_message_view(MainWindow *mainwin)
1787 {
1788         SummaryView *summaryview = mainwin->summaryview;
1789         union CompositeWin *cwin = &mainwin->win;
1790         GtkWidget *vpaned = NULL;
1791         GtkWidget *container = NULL;
1792         GtkWidget *msgwin = NULL;
1793
1794         switch (mainwin->type) {
1795         case SEPARATE_NONE:
1796                 vpaned = cwin->sep_none.vpaned;
1797                 container = cwin->sep_none.hpaned;
1798                 break;
1799         case SEPARATE_FOLDER:
1800                 vpaned = cwin->sep_folder.vpaned;
1801                 container = mainwin->vbox_body;
1802                 break;
1803         case SEPARATE_MESSAGE:
1804                 msgwin = mainwin->win.sep_message.messagewin;
1805                 break;
1806         case SEPARATE_BOTH:
1807                 msgwin = mainwin->win.sep_both.messagewin;
1808                 break;
1809         }
1810
1811         if (msgwin) {
1812                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1813                         gtk_widget_hide(msgwin);
1814                         mainwin->messageview->visible = FALSE;
1815                         summaryview->displayed = NULL;
1816                 } else {
1817                         gtk_widget_show(msgwin);
1818                         mainwin->messageview->visible = TRUE;
1819                 }
1820         } else if (vpaned->parent != NULL) {
1821                 mainwin->messageview->visible = FALSE;
1822                 summaryview->displayed = NULL;
1823                 gtk_widget_ref(vpaned);
1824                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1825                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1826         } else {
1827                 mainwin->messageview->visible = TRUE;
1828                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1829                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1830                 gtk_widget_unref(vpaned);
1831         }
1832
1833         if (messageview_is_visible(mainwin->messageview))
1834                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1835                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1836         else
1837                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1838                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1839
1840         if (mainwin->messageview->visible == FALSE)
1841                 messageview_clear(mainwin->messageview);
1842
1843         main_window_set_menu_sensitive(mainwin);
1844
1845         prefs_common.msgview_visible = mainwin->messageview->visible;
1846
1847         gtk_widget_grab_focus(summaryview->ctree);
1848 }
1849
1850 void main_window_get_size(MainWindow *mainwin)
1851 {
1852         GtkAllocation *allocation;
1853
1854         if (mainwin_list == NULL || mainwin->messageview == NULL) {
1855                 debug_print("called after messageview "
1856                             "has been deallocated!\n");
1857                 return;
1858         }
1859
1860         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1861
1862         if (allocation->width > 1 && allocation->height > 1) {
1863                 prefs_common.summaryview_width = allocation->width;
1864
1865                 if ((mainwin->type == SEPARATE_NONE ||
1866                      mainwin->type == SEPARATE_FOLDER) &&
1867                     messageview_is_visible(mainwin->messageview))
1868                         prefs_common.summaryview_height = allocation->height;
1869
1870                 prefs_common.mainview_width = allocation->width;
1871         }
1872
1873         allocation = &mainwin->window->allocation;
1874         if (allocation->width > 1 && allocation->height > 1) {
1875                 prefs_common.mainview_height = allocation->height;
1876                 prefs_common.mainwin_width   = allocation->width;
1877                 prefs_common.mainwin_height  = allocation->height;
1878         }
1879
1880         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1881         if (allocation->width > 1 && allocation->height > 1) {
1882                 prefs_common.folderview_width  = allocation->width;
1883                 prefs_common.folderview_height = allocation->height;
1884         }
1885
1886         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
1887         if (allocation->width > 1 && allocation->height > 1) {
1888                 prefs_common.msgview_width = allocation->width;
1889                 prefs_common.msgview_height = allocation->height;
1890         }
1891
1892 /*      debug_print("summaryview size: %d x %d\n",
1893                     prefs_common.summaryview_width,
1894                     prefs_common.summaryview_height);
1895         debug_print("folderview size: %d x %d\n",
1896                     prefs_common.folderview_width,
1897                     prefs_common.folderview_height);
1898         debug_print("messageview size: %d x %d\n",
1899                     prefs_common.msgview_width,
1900                     prefs_common.msgview_height); */
1901 }
1902
1903 void main_window_get_position(MainWindow *mainwin)
1904 {
1905         gint x, y;
1906         GtkWidget *window;
1907
1908         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1909
1910         prefs_common.mainview_x = x;
1911         prefs_common.mainview_y = y;
1912         prefs_common.mainwin_x = x;
1913         prefs_common.mainwin_y = y;
1914
1915         debug_print("main window position: %d, %d\n", x, y);
1916
1917         window = main_window_get_folder_window(mainwin);
1918         if (window) {
1919                 gtkut_widget_get_uposition(window, &x, &y);
1920                 prefs_common.folderwin_x = x;
1921                 prefs_common.folderwin_y = y;
1922                 debug_print("folder window position: %d, %d\n", x, y);
1923         }
1924         window = main_window_get_message_window(mainwin);
1925         if (window) {
1926                 gtkut_widget_get_uposition(window, &x, &y);
1927                 prefs_common.main_msgwin_x = x;
1928                 prefs_common.main_msgwin_y = y;
1929                 debug_print("message window position: %d, %d\n", x, y);
1930         }
1931 }
1932
1933 void main_window_progress_on(MainWindow *mainwin)
1934 {
1935         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
1936 }
1937
1938 void main_window_progress_off(MainWindow *mainwin)
1939 {
1940         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
1941         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
1942 }
1943
1944 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
1945 {
1946         gchar buf[32];
1947
1948         g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
1949         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
1950         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
1951                                 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
1952 }
1953
1954 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1955 {
1956         if (confirm) {
1957                 if (alertpanel(_("Empty trash"),
1958                                _("Delete all messages in trash folders?"),
1959                                GTK_STOCK_CANCEL, _("+_Empty trash"), NULL)
1960                     != G_ALERTALTERNATE)
1961                         return;
1962                 manage_window_focus_in(mainwin->window, NULL, NULL);
1963         }
1964
1965         procmsg_empty_all_trash();
1966
1967         if (mainwin->summaryview->folder_item &&
1968             mainwin->summaryview->folder_item->stype == F_TRASH)
1969                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1970 }
1971
1972 void main_window_add_mailbox(MainWindow *mainwin)
1973 {
1974         gchar *path;
1975         Folder *folder;
1976
1977         path = input_dialog(_("Add mailbox"),
1978                             _("Input the location of mailbox.\n"
1979                               "If the existing mailbox is specified, it will be\n"
1980                               "scanned automatically."),
1981                             "Mail");
1982         if (!path) return;
1983         if (folder_find_from_path(path)) {
1984                 alertpanel_error(_("The mailbox '%s' already exists."), path);
1985                 g_free(path);
1986                 return;
1987         }
1988         folder = folder_new(folder_get_class_from_string("mh"), 
1989                             !strcmp(path, "Mail") ? _("Mailbox") : 
1990                             g_path_get_basename(path), path);
1991         g_free(path);
1992
1993         if (folder->klass->create_tree(folder) < 0) {
1994                 alertpanel_error(_("Creation of the mailbox failed.\n"
1995                                    "Maybe some files already exist, or you don't have the permission to write there."));
1996                 folder_destroy(folder);
1997                 return;
1998         }
1999
2000         folder_add(folder);
2001         folder_set_ui_func(folder, scan_tree_func, mainwin);
2002         folder_scan_tree(folder, TRUE);
2003         folder_set_ui_func(folder, NULL, NULL);
2004 }
2005
2006 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2007 {
2008         SensitiveCond state = 0;
2009         SummarySelection selection;
2010         FolderItem *item = mainwin->summaryview->folder_item;
2011         GList *account_list = account_get_list();
2012         
2013         selection = summary_get_selection_type(mainwin->summaryview);
2014
2015         if (mainwin->lock_count == 0)
2016                 state |= M_UNLOCKED;
2017         if (selection != SUMMARY_NONE)
2018                 state |= M_MSG_EXIST;
2019         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2020                 state |= M_EXEC;
2021                 /*              if (item->folder->type != F_NEWS) */
2022                 state |= M_ALLOW_DELETE;
2023
2024                 if (prefs_common.immediate_exec == 0
2025                     && mainwin->lock_count == 0)
2026                         state |= M_DELAY_EXEC;
2027
2028                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2029                     || selection != SUMMARY_NONE)
2030                         state |= M_HIDE_READ_MSG;       
2031         }               
2032         if (mainwin->summaryview->threaded)
2033                 state |= M_THREADED;
2034         else
2035                 state |= M_UNTHREADED;  
2036         if (selection == SUMMARY_SELECTED_SINGLE ||
2037             selection == SUMMARY_SELECTED_MULTIPLE)
2038                 state |= M_TARGET_EXIST;
2039         if (selection == SUMMARY_SELECTED_SINGLE)
2040                 state |= M_SINGLE_TARGET_EXIST;
2041         if (mainwin->summaryview->folder_item &&
2042             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2043                 state |= M_NEWS;
2044         else
2045                 state |= M_NOT_NEWS;
2046         if (selection == SUMMARY_SELECTED_SINGLE &&
2047             (item &&
2048              (folder_has_parent_of_type(item, F_DRAFT) ||
2049               folder_has_parent_of_type(item, F_OUTBOX) ||
2050               folder_has_parent_of_type(item, F_QUEUE))))
2051                 state |= M_ALLOW_REEDIT;
2052         if (cur_account)
2053                 state |= M_HAVE_ACCOUNT;
2054         
2055         for ( ; account_list != NULL; account_list = account_list->next) {
2056                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2057                         state |= M_HAVE_NEWS_ACCOUNT;
2058                         break;
2059                 }
2060         }
2061         
2062         if (procmsg_spam_can_learn()) {
2063                 state |= M_CAN_LEARN_SPAM;
2064         }
2065
2066         if (inc_is_active())
2067                 state |= M_INC_ACTIVE;
2068
2069         if (mainwin->summaryview->deleted > 0 ||
2070             mainwin->summaryview->moved > 0 ||
2071             mainwin->summaryview->copied > 0)
2072                 state |= M_DELAY_EXEC;
2073
2074         return state;
2075 }
2076
2077
2078
2079 void main_window_set_menu_sensitive(MainWindow *mainwin)
2080 {
2081         GtkItemFactory *ifactory = mainwin->menu_factory;
2082         SensitiveCond state;
2083         gboolean sensitive;
2084         GtkWidget *menu;
2085         GtkWidget *menuitem;
2086         SummaryView *summaryview;
2087         gchar *menu_path;
2088         gint i;
2089         GList *cur_item;
2090
2091         static const struct {
2092                 gchar *const entry;
2093                 SensitiveCond cond;
2094         } entry[] = {
2095                 {"/File/Save as...", M_TARGET_EXIST},
2096                 {"/File/Print..."  , M_TARGET_EXIST},
2097                 {"/File/Exit"      , M_UNLOCKED},
2098
2099                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
2100
2101                 {"/View/Sort"                      , M_EXEC},
2102                 {"/View/Thread view"               , M_EXEC},
2103                 {"/View/Expand all threads"        , M_MSG_EXIST},
2104                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2105                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2106                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2107                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2108                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2109                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2110                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2111                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
2112                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2113                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2114                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2115                 {"/View/Show all headers"          , M_SINGLE_TARGET_EXIST},
2116                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2117
2118                 {"/Message/Receive/Get from current account"
2119                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2120                 {"/Message/Receive/Get from all accounts"
2121                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2122                 {"/Message/Receive/Cancel receiving"
2123                                                  , M_INC_ACTIVE},
2124
2125                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2126                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
2127                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
2128                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
2129                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2130                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2131                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
2132                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2133                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2134                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2135                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2136                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2137                 {"/Message/Mark"                  , M_TARGET_EXIST},
2138                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2139                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2140                 {"/Message/Color label"           , M_TARGET_EXIST},
2141                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2142
2143                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2144                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2145                 {"/Tools/Harvest addresses/from Messages..."
2146                                                        , M_TARGET_EXIST},
2147                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2148                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2149                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2150                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2151                 {"/Tools/Actions"                      , M_TARGET_EXIST},
2152                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2153                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2154
2155                 {"/Configuration", M_UNLOCKED},
2156
2157                 {NULL, 0}
2158         };
2159
2160         state = main_window_get_current_state(mainwin);
2161
2162         for (i = 0; entry[i].entry != NULL; i++) {
2163                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2164                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2165         }
2166
2167         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2168
2169         /* search for separator */
2170         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2171              cur_item = cur_item->next) {
2172                 if (GTK_BIN(cur_item->data)->child == NULL) {
2173                         cur_item = cur_item->next;
2174                         break;
2175                 }
2176         }
2177
2178         for (; cur_item != NULL; cur_item = cur_item->next) {
2179                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2180                                          (M_UNLOCKED & state) != 0);
2181         }
2182
2183         main_window_menu_callback_block(mainwin);
2184
2185 #define SET_CHECK_MENU_ACTIVE(path, active) \
2186 { \
2187         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2188         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2189 }
2190
2191         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2192                               messageview_is_visible(mainwin->messageview));
2193
2194         summaryview = mainwin->summaryview;
2195         menu_path = "/View/Sort/Don't sort";
2196
2197         switch (summaryview->sort_key) {
2198         case SORT_BY_NUMBER:
2199                 menu_path = "/View/Sort/by number"; break;
2200         case SORT_BY_SIZE:
2201                 menu_path = "/View/Sort/by Size"; break;
2202         case SORT_BY_DATE:
2203                 menu_path = "/View/Sort/by Date"; break;
2204         case SORT_BY_FROM:
2205                 menu_path = "/View/Sort/by From"; break;
2206         case SORT_BY_TO:
2207                 menu_path = "/View/Sort/by To"; break;
2208         case SORT_BY_SUBJECT:
2209                 menu_path = "/View/Sort/by Subject"; break;
2210         case SORT_BY_LABEL:
2211                 menu_path = "/View/Sort/by color label"; break;
2212         case SORT_BY_MARK:
2213                 menu_path = "/View/Sort/by mark"; break;
2214         case SORT_BY_STATUS:
2215                 menu_path = "/View/Sort/by status"; break;
2216         case SORT_BY_MIME:
2217                 menu_path = "/View/Sort/by attachment"; break;
2218         case SORT_BY_SCORE:
2219                 menu_path = "/View/Sort/by score"; break;
2220         case SORT_BY_LOCKED:
2221                 menu_path = "/View/Sort/by locked"; break;
2222         case SORT_BY_NONE:
2223         default:
2224                 menu_path = "/View/Sort/Don't sort"; break;
2225         }
2226         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2227
2228         if (summaryview->sort_type == SORT_ASCENDING) {
2229                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2230         } else {
2231                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2232         }
2233
2234         if (summaryview->sort_key != SORT_BY_NONE) {
2235                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2236                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2237         } else {
2238                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2239                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2240         }
2241
2242         if (mainwin->messageview 
2243         &&  mainwin->messageview->mimeview
2244         &&  mainwin->messageview->mimeview->textview)
2245                 SET_CHECK_MENU_ACTIVE("/View/Show all headers",
2246                               mainwin->messageview->mimeview->textview->show_all_headers);
2247         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2248
2249 #undef SET_CHECK_MENU_ACTIVE
2250
2251         main_window_menu_callback_unblock(mainwin);
2252 }
2253
2254 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2255 {
2256         GtkItemFactory *ifactory;
2257         gint is_menu = 0;
2258         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2259         
2260         if (msginfo) 
2261                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2262         if (is_menu)
2263                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2264                                 (ifactory,"/Message/Mailing-List"), TRUE);
2265         else
2266                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2267                                 (ifactory,"/Message/Mailing-List"), FALSE);
2268 }
2269
2270 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2271 {
2272         gint menu_nb = 0;
2273         GtkWidget *menuitem;
2274
2275         /* Mailing list post */
2276         if (msginfo && !strcmp2 (msginfo->list_post, "NO")) {
2277                 msginfo->list_post = g_strdup (_("No posting allowed"));
2278         }
2279         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2280                 
2281         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_post);
2282  
2283         /* Mailing list help */
2284         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2285         
2286         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_help);
2287
2288         /* Mailing list subscribe */
2289         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2290         
2291         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_subscribe);
2292                 
2293         /* Mailing list unsubscribe */
2294         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2295         
2296         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_unsubscribe);
2297         
2298         /* Mailing list view archive */
2299         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2300         
2301         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_archive);
2302         
2303         /* Mailing list contact owner */
2304         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2305         
2306         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_owner);
2307         
2308         return menu_nb;
2309 }
2310
2311 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2312 {
2313         GtkWidget *item, *menu;
2314         const gchar *url_pt ;
2315         gchar url_decoded[BUFFSIZE];
2316         GList *amenu, *alist;
2317         gint menu_nb = 0;
2318         
2319         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2320         
2321         /* First delete old submenu */
2322         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2323         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2324                 alist = amenu->next;
2325                 item = GTK_WIDGET (amenu->data);
2326                 gtk_widget_destroy (item);
2327                 amenu = alist;
2328         }
2329         if (list_header) {
2330                 for (url_pt = list_header; url_pt && *url_pt;) {
2331                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2332                         item = NULL;
2333                         if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2334                                 item = gtk_menu_item_new_with_label ((url_decoded));
2335                                 gtk_signal_connect (GTK_OBJECT(item), "activate",
2336                                                 GTK_SIGNAL_FUNC(mailing_list_compose), NULL);
2337                         }
2338                         else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2339                                  !g_strncasecmp (url_decoded, "https:",6)) {
2340
2341                                 item = gtk_menu_item_new_with_label ((url_decoded));
2342                                 gtk_signal_connect (GTK_OBJECT(item), "activate",
2343                                                 GTK_SIGNAL_FUNC(mailing_list_open_uri), NULL);
2344                         } 
2345                         if (item) {
2346                                 gtk_menu_append (GTK_MENU(menu), item);
2347                                 gtk_widget_show (item);
2348                                 menu_nb++;
2349                         }
2350                 }
2351         }
2352         if (menu_nb)
2353                 gtk_widget_set_sensitive (menuitem, TRUE);
2354         else
2355                 gtk_widget_set_sensitive (menuitem, FALSE);
2356                 
2357
2358         return menu_nb;
2359 }
2360
2361 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2362 {
2363         gchar tmp[BUFFSIZE];
2364         const gchar *buf;
2365         gint i = 0;
2366         buf = *buffer;
2367         
2368         if (buf == 0x00) {
2369                 url_decoded = NULL;
2370                 *buffer = NULL;
2371                 return;
2372         }
2373         /* Ignore spaces, comments  and tabs () */
2374         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2375                 if (*buf == '(')
2376                         for (;*buf != ')' && *buf != 0x00; buf++);
2377         
2378         /* First non space and non comment must be a < */
2379         if (*buf =='<' ) {
2380                 buf++;
2381                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2382                 buf++;
2383         }
2384         else  {
2385                 *buffer = NULL;
2386                 *url_decoded = NULL;
2387                 return;
2388         }
2389         
2390         tmp[i]       = 0x00;
2391         *url_decoded = NULL;
2392         *buffer = NULL;
2393         
2394         if (i == maxlen) {
2395                 return;
2396         }
2397         decode_uri (url_decoded, (const gchar *)tmp);
2398
2399         /* Prepare the work for the next url in the list */
2400         /* after the closing bracket >, ignore space, comments and tabs */
2401         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2402                 if (*buf == '(')
2403                         for (;*buf != ')' && *buf != 0x00; buf++);
2404                         
2405         if (!buf || !*buf) {
2406                 *buffer = NULL;
2407                 return;
2408         }
2409
2410         /* now first non space, non comment must be a comma */
2411         if (*buf != ',')
2412                 for (;*buf != 0x00; buf++);
2413         else
2414                 buf++;
2415         *buffer = buf;
2416 }
2417         
2418 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2419 {
2420         gchar *mailto;
2421
2422         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2423         compose_new(NULL, mailto+7, NULL);
2424 }
2425  
2426  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2427 {
2428  
2429         gchar *mailto;
2430  
2431         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2432         open_uri (mailto, prefs_common.uri_cmd);
2433
2434         
2435 void main_window_popup(MainWindow *mainwin)
2436 {
2437         gtkut_window_popup(mainwin->window);
2438
2439         switch (mainwin->type) {
2440         case SEPARATE_FOLDER:
2441                 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
2442                 break;
2443         case SEPARATE_MESSAGE:
2444                 gtkut_window_popup(mainwin->win.sep_message.messagewin);
2445                 break;
2446         case SEPARATE_BOTH:
2447                 gtkut_window_popup(mainwin->win.sep_both.folderwin);
2448                 gtkut_window_popup(mainwin->win.sep_both.messagewin);
2449                 break;
2450         default:
2451                 break;
2452         }
2453 }
2454
2455 void main_window_show(MainWindow *mainwin)
2456 {
2457         gtk_widget_show(mainwin->window);
2458         gtk_widget_show(mainwin->vbox_body);
2459
2460         gtk_widget_set_uposition(mainwin->window,
2461                                  prefs_common.mainwin_x,
2462                                  prefs_common.mainwin_y);
2463
2464         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2465                              prefs_common.folderview_width,
2466                              prefs_common.folderview_height);
2467         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2468                              prefs_common.summaryview_width,
2469                              prefs_common.summaryview_height);
2470         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2471                              prefs_common.msgview_width,
2472                              prefs_common.msgview_height);
2473
2474         if (mainwin->type & SEPARATE_FOLDER) {
2475                 GtkWidget *folderwin;
2476
2477                 folderwin = main_window_get_folder_window(mainwin);
2478                 gtk_widget_show(folderwin);
2479                 gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
2480                                          prefs_common.folderwin_y);
2481         }
2482
2483         if (mainwin->type & SEPARATE_MESSAGE) {
2484                 GtkWidget *messagewin;
2485
2486                 messagewin = main_window_get_message_window(mainwin);
2487                 gtk_widget_show(messagewin);
2488                 gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
2489                                          prefs_common.main_msgwin_y);
2490         }
2491 }
2492
2493 void main_window_hide(MainWindow *mainwin)
2494 {
2495         main_window_get_size(mainwin);
2496         main_window_get_position(mainwin);
2497
2498         gtk_widget_hide(mainwin->window);
2499         gtk_widget_hide(mainwin->vbox_body);
2500
2501         if (mainwin->type & SEPARATE_FOLDER) {
2502                 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2503         }
2504
2505         if (mainwin->type & SEPARATE_MESSAGE) {
2506                 gtk_widget_hide(mainwin->win.sep_message.messagewin);
2507         }
2508 }
2509
2510 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
2511 {
2512         GtkWidget *folderwin = NULL;
2513         GtkWidget *messagewin = NULL;
2514         GtkWidget *hpaned;
2515         GtkWidget *vpaned;
2516         GtkWidget *vbox_body = mainwin->vbox_body;
2517         GtkItemFactory *ifactory = mainwin->menu_factory;
2518         GtkWidget *menuitem;
2519         GtkItemFactory *msgview_ifactory;
2520
2521         debug_print("Setting widgets... ");
2522
2523         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2524                                     prefs_common.folderview_width,
2525                                     prefs_common.folderview_height);
2526         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2527                                     prefs_common.summaryview_width,
2528                                     prefs_common.summaryview_height);
2529         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2530                                     prefs_common.msgview_width,
2531                                     prefs_common.msgview_height);
2532
2533         /* create separated window(s) if needed */
2534         if (type & SEPARATE_FOLDER) {
2535                 static GdkGeometry folderwin_geometry;
2536                 
2537                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2538                 gtk_window_set_title(GTK_WINDOW(folderwin),
2539                                      _("Sylpheed-Claws - Folder View"));
2540
2541                 gtk_window_move(GTK_WINDOW(folderwin),
2542                                 prefs_common.folderwin_x,
2543                                 prefs_common.folderwin_y);
2544
2545                 if (!folderwin_geometry.min_height) {
2546                         folderwin_geometry.min_width = 320;
2547                         folderwin_geometry.min_height = 200;
2548                 }
2549                 gtk_window_set_geometry_hints(GTK_WINDOW(folderwin), NULL,
2550                                               &folderwin_geometry, GDK_HINT_MIN_SIZE);
2551                                 
2552                 gtk_widget_set_size_request(folderwin,
2553                                             prefs_common.folderview_width,
2554                                             prefs_common.folderview_height);
2555
2556                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
2557                                                BORDER_WIDTH);
2558
2559                 g_signal_connect(G_OBJECT(folderwin), "delete_event",
2560                                  G_CALLBACK(folder_window_close_cb),
2561                                    mainwin);
2562                 gtk_container_add(GTK_CONTAINER(folderwin),
2563                                   GTK_WIDGET_PTR(mainwin->folderview));
2564                 gtk_widget_realize(folderwin);
2565
2566                 if (prefs_common.folderview_visible)
2567                         gtk_widget_show(folderwin);
2568         }
2569
2570         if (type & SEPARATE_MESSAGE) {
2571                 static GdkGeometry msgwin_geometry;
2572                 
2573                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2574                 gtk_window_set_title(GTK_WINDOW(messagewin),
2575                                      _("Sylpheed-Claws - Message View"));
2576                                      
2577                 gtk_window_move(GTK_WINDOW(messagewin), 
2578                                 prefs_common.main_msgwin_x,
2579                                 prefs_common.main_msgwin_y);
2580
2581                 if (!msgwin_geometry.min_height) {
2582                         msgwin_geometry.min_width = 320;
2583                         msgwin_geometry.min_height = 200;
2584                 }
2585                 gtk_window_set_geometry_hints(GTK_WINDOW(messagewin), NULL,
2586                                               &msgwin_geometry, GDK_HINT_MIN_SIZE);
2587                 
2588                 gtk_widget_set_size_request(messagewin, 
2589                                             prefs_common.msgwin_width,
2590                                             prefs_common.msgwin_height);
2591
2592                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
2593                                                BORDER_WIDTH);
2594                 g_signal_connect(G_OBJECT(messagewin), "delete_event",
2595                                  G_CALLBACK(message_window_close_cb),
2596                                  mainwin);
2597                 if (messageview_is_visible(mainwin->messageview))
2598                         gtk_widget_show(messagewin);
2599         } else {
2600                 mainwin->messageview->statusbar = mainwin->statusbar;
2601                 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2602         }
2603
2604         switch (type) {
2605         case SEPARATE_NONE:
2606                 hpaned = gtk_hpaned_new();
2607                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2608                 gtk_paned_add1(GTK_PANED(hpaned),
2609                                GTK_WIDGET_PTR(mainwin->folderview));
2610                 gtk_widget_show(hpaned);
2611                 gtk_widget_queue_resize(hpaned);
2612
2613                 vpaned = gtk_vpaned_new();
2614                 if (messageview_is_visible(mainwin->messageview)) {
2615                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2616                         gtk_paned_add1(GTK_PANED(vpaned),
2617                                        GTK_WIDGET_PTR(mainwin->summaryview));
2618                 } else {
2619                         gtk_paned_add2(GTK_PANED(hpaned),
2620                                        GTK_WIDGET_PTR(mainwin->summaryview));
2621                         gtk_widget_ref(vpaned);
2622                 }
2623                 gtk_paned_add2(GTK_PANED(vpaned),
2624                                GTK_WIDGET_PTR(mainwin->messageview));
2625                 gtk_widget_show(vpaned);
2626                 gtk_widget_queue_resize(vpaned);
2627
2628                 mainwin->win.sep_none.hpaned = hpaned;
2629                 mainwin->win.sep_none.vpaned = vpaned;
2630                 
2631                 /* remove headerview if not in prefs */
2632                 headerview_set_visibility(mainwin->messageview->headerview,
2633                                           prefs_common.display_header_pane);
2634                 break;
2635         case SEPARATE_FOLDER:
2636                 vpaned = gtk_vpaned_new();
2637                 if (messageview_is_visible(mainwin->messageview)) {
2638                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
2639                                            TRUE, TRUE, 0);
2640                         gtk_paned_add1(GTK_PANED(vpaned),
2641                                        GTK_WIDGET_PTR(mainwin->summaryview));
2642                 } else {
2643                         gtk_box_pack_start(GTK_BOX(vbox_body),
2644                                            GTK_WIDGET_PTR(mainwin->summaryview),
2645                                            TRUE, TRUE, 0);
2646                         gtk_widget_ref(vpaned);
2647                 }
2648                 gtk_paned_add2(GTK_PANED(vpaned),
2649                                GTK_WIDGET_PTR(mainwin->messageview));
2650                 gtk_widget_show(vpaned);
2651                 gtk_widget_queue_resize(vpaned);
2652
2653                 mainwin->win.sep_folder.folderwin = folderwin;
2654                 mainwin->win.sep_folder.vpaned    = vpaned;
2655
2656                 /* remove headerview if not in prefs */
2657                 headerview_set_visibility(mainwin->messageview->headerview,
2658                                           prefs_common.display_header_pane);
2659                 
2660                 break;
2661         case SEPARATE_MESSAGE:
2662                 hpaned = gtk_hpaned_new();
2663                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2664                 gtk_paned_add1(GTK_PANED(hpaned),
2665                                GTK_WIDGET_PTR(mainwin->folderview));
2666                 gtk_paned_add2(GTK_PANED(hpaned),
2667                                GTK_WIDGET_PTR(mainwin->summaryview));
2668                 gtk_widget_show(hpaned);
2669                 gtk_widget_queue_resize(hpaned);
2670                 messageview_add_toolbar(mainwin->messageview, messagewin);
2671                 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2672                 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2673
2674                 mainwin->win.sep_message.messagewin = messagewin;
2675                 mainwin->win.sep_message.hpaned     = hpaned;
2676
2677                 gtk_widget_realize(messagewin);
2678                 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2679                 gtk_widget_show_all(messagewin);
2680                 toolbar_set_style(mainwin->messageview->toolbar->toolbar, 
2681                                   mainwin->messageview->handlebox, 
2682                                   prefs_common.toolbar_style);
2683
2684                 break;
2685         case SEPARATE_BOTH:
2686                 messageview_add_toolbar(mainwin->messageview, messagewin);
2687                 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2688                 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2689
2690                 gtk_box_pack_start(GTK_BOX(vbox_body),
2691                                    GTK_WIDGET_PTR(mainwin->summaryview),
2692                                    TRUE, TRUE, 0);
2693                 
2694                 mainwin->win.sep_both.folderwin = folderwin;
2695                 mainwin->win.sep_both.messagewin = messagewin;
2696                 
2697                 gtk_widget_realize(messagewin);
2698                 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2699                 gtk_widget_show_all(messagewin);
2700                 toolbar_set_style(mainwin->messageview->toolbar->toolbar, 
2701                                   mainwin->messageview->handlebox, 
2702                                   prefs_common.toolbar_style);          
2703
2704                 break;
2705         }
2706
2707         if (messageview_is_visible(mainwin->messageview))
2708                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2709                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2710         else
2711                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2712                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2713
2714         gtk_window_move(GTK_WINDOW(mainwin->window),
2715                         prefs_common.mainwin_x,
2716                         prefs_common.mainwin_y);
2717
2718         gtk_widget_queue_resize(vbox_body);
2719         gtk_widget_queue_resize(mainwin->vbox);
2720         gtk_widget_queue_resize(mainwin->window);
2721         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2722          * and mimeview icon list/ctree lose track of their visibility states */
2723         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
2724                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2725         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
2726                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2727         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2728                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2729         else 
2730                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2731
2732         mainwin->type = type;
2733
2734
2735         /* toggle menu state */
2736         menuitem = gtk_item_factory_get_item
2737                 (ifactory, "/View/Show or hide/Folder tree");
2738         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2739                                        (type & SEPARATE_FOLDER) == 0 ? TRUE :
2740                                        prefs_common.folderview_visible);
2741         gtk_widget_set_sensitive(menuitem, ((type & SEPARATE_FOLDER) != 0));
2742         menuitem = gtk_item_factory_get_item
2743                 (ifactory, "/View/Show or hide/Message view");
2744         gtk_check_menu_item_set_active
2745                 (GTK_CHECK_MENU_ITEM(menuitem),
2746                  messageview_is_visible(mainwin->messageview));
2747
2748         menuitem = gtk_item_factory_get_item
2749                 (ifactory, "/View/Separate folder tree");
2750         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2751                                        ((type & SEPARATE_FOLDER) != 0));
2752         menuitem = gtk_item_factory_get_item
2753                 (ifactory, "/View/Separate message view");
2754         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2755                                        ((type & SEPARATE_MESSAGE) != 0));
2756
2757         if (folderwin) {
2758                 g_signal_connect
2759                         (G_OBJECT(folderwin), "size_allocate",
2760                          G_CALLBACK(folder_window_size_allocate_cb),
2761                          mainwin);
2762         }
2763         if (messagewin) {
2764                 g_signal_connect
2765                         (G_OBJECT(messagewin), "size_allocate",
2766                          G_CALLBACK(message_window_size_allocate_cb),
2767                          mainwin);
2768         }
2769
2770         debug_print("done.\n");
2771 }
2772
2773 void main_window_destroy_all(void)
2774 {
2775         while (mainwin_list != NULL) {
2776                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2777                 
2778                 /* free toolbar stuff */
2779                 toolbar_clear_list(TOOLBAR_MAIN);
2780                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2781                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2782
2783                 mainwin->folderview->mainwin = NULL;
2784                 mainwin->summaryview->mainwin = NULL;
2785                 mainwin->messageview->mainwin = NULL;
2786
2787                 g_free(mainwin->toolbar);
2788                 g_free(mainwin);
2789                 
2790                 mainwin_list = g_list_remove(mainwin_list, mainwin);
2791         }
2792         g_list_free(mainwin_list);
2793         mainwin_list = NULL;
2794 }
2795
2796 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2797                                    gpointer data)
2798 {
2799         gtk_widget_set_size_request(child, 1, -1);
2800 }
2801
2802 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2803                                    gpointer data)
2804 {
2805         gtk_widget_set_size_request(child, -1, -1);
2806 }
2807
2808 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2809                                     gpointer data)
2810 {
2811         MainWindow *mainwin = (MainWindow *)data;
2812
2813         if (!event) return FALSE;
2814
2815         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2816         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2817                           widget);
2818
2819         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2820                        menu_button_position, widget,
2821                        event->button, event->time);
2822
2823         return TRUE;
2824 }
2825
2826 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2827                                  gpointer data)
2828 {
2829         MainWindow *mainwin = (MainWindow *)data;
2830
2831         if (mainwin->lock_count == 0)
2832                 app_exit_cb(data, 0, widget);
2833
2834         return TRUE;
2835 }
2836
2837 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2838                                    gpointer data)
2839 {
2840         MainWindow *mainwin = (MainWindow *)data;
2841         GtkWidget *menuitem;
2842
2843         menuitem = gtk_item_factory_get_item
2844                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
2845         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2846
2847         return TRUE;
2848 }
2849
2850 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2851                                     gpointer data)
2852 {
2853         MainWindow *mainwin = (MainWindow *)data;
2854         GtkWidget *menuitem;
2855
2856         menuitem = gtk_item_factory_get_item
2857                 (mainwin->menu_factory, "/View/Show or hide/Message view");
2858         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2859
2860         mainwin->messageview->statusbar = mainwin->statusbar;
2861         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2862
2863         return TRUE;
2864 }
2865
2866 static void main_window_size_allocate_cb(GtkWidget *widget,
2867                                          GtkAllocation *allocation,
2868                                          gpointer data)
2869 {
2870         MainWindow *mainwin = (MainWindow *)data;
2871
2872         main_window_get_size(mainwin);
2873 }
2874
2875 static void folder_window_size_allocate_cb(GtkWidget *widget,
2876                                            GtkAllocation *allocation,
2877                                            gpointer data)
2878 {
2879         MainWindow *mainwin = (MainWindow *)data;
2880
2881         main_window_get_size(mainwin);
2882 }
2883
2884 static void message_window_size_allocate_cb(GtkWidget *widget,
2885                                             GtkAllocation *allocation,
2886                                             gpointer data)
2887 {
2888         MainWindow *mainwin = (MainWindow *)data;
2889
2890         main_window_get_size(mainwin);
2891 }
2892
2893 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2894                            GtkWidget *widget)
2895 {
2896         main_window_add_mailbox(mainwin);
2897 }
2898
2899 static void update_folderview_cb(MainWindow *mainwin, guint action,
2900                                  GtkWidget *widget)
2901 {
2902         summary_show(mainwin->summaryview, NULL);
2903         folderview_check_new_all();
2904 }
2905
2906 static void foldersort_cb(MainWindow *mainwin, guint action,
2907                            GtkWidget *widget)
2908 {
2909         foldersort_open();
2910 }
2911
2912 static void import_mbox_cb(MainWindow *mainwin, guint action,
2913                            GtkWidget *widget)
2914 {
2915         /* only notify if import has failed */
2916         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
2917                 alertpanel_error(_("Mbox import has failed."));
2918         }
2919 }
2920
2921 static void export_mbox_cb(MainWindow *mainwin, guint action,
2922                            GtkWidget *widget)
2923 {
2924         /* only notify if export has failed */
2925         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
2926                 alertpanel_error(_("Export to mbox has failed."));
2927         }
2928 }
2929
2930 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
2931                                 GtkWidget *widget)
2932 {
2933         /* only notify if export has failed */
2934         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
2935                 alertpanel_error(_("Export to mbox has failed."));
2936         }
2937 }
2938
2939 static void empty_trash_cb(MainWindow *mainwin, guint action,
2940                            GtkWidget *widget)
2941 {
2942         main_window_empty_trash(mainwin, TRUE);
2943 }
2944
2945 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2946 {
2947         summary_save_as(mainwin->summaryview);
2948 }
2949
2950 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2951 {
2952         summary_print(mainwin->summaryview);
2953 }
2954
2955 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2956 {
2957         if (prefs_common.confirm_on_exit) {
2958                 if (alertpanel(_("Exit"), _("Exit Sylpheed-Claws?"),
2959                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
2960                     != G_ALERTALTERNATE)
2961                         return;
2962                 manage_window_focus_in(mainwin->window, NULL, NULL);
2963         }
2964
2965         app_will_exit(widget, mainwin);
2966 }
2967
2968 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2969 {
2970         if (action == 1)
2971                 summary_search(mainwin->summaryview);
2972         else
2973                 message_search(mainwin->messageview);
2974 }
2975
2976 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
2977 {
2978         prefs_common.show_searchbar = TRUE;
2979         summaryview_activate_quicksearch(mainwin->summaryview);
2980 }
2981
2982 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2983                              GtkWidget *widget)
2984 {
2985         gboolean active;
2986
2987         active = GTK_CHECK_MENU_ITEM(widget)->active;
2988
2989         switch (mainwin->type) {
2990         case SEPARATE_NONE:
2991         case SEPARATE_MESSAGE:
2992                 break;
2993         case SEPARATE_FOLDER:
2994                 debug_print("separate folder\n");
2995                 if (active)
2996                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2997                 else
2998                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2999                 break;
3000         case SEPARATE_BOTH:
3001                 if (active)
3002                         gtk_widget_show(mainwin->win.sep_both.folderwin);
3003                 else
3004                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
3005                 break;
3006         }
3007
3008         prefs_common.folderview_visible = active;
3009 }
3010
3011 static void toggle_message_cb(MainWindow *mainwin, guint action,
3012                               GtkWidget *widget)
3013 {
3014         gboolean active;
3015
3016         active = GTK_CHECK_MENU_ITEM(widget)->active;
3017
3018         if (active != messageview_is_visible(mainwin->messageview))
3019                 summary_toggle_view(mainwin->summaryview);
3020 }
3021
3022 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3023                               GtkWidget *widget)
3024 {
3025         toolbar_toggle(action, mainwin);
3026 }
3027
3028 void main_window_reply_cb(MainWindow *mainwin, guint action,
3029                           GtkWidget *widget)
3030 {
3031         MessageView *msgview = (MessageView*)mainwin->messageview;
3032         GSList *msginfo_list = NULL;
3033
3034         g_return_if_fail(msgview != NULL);
3035
3036         msginfo_list = summary_get_selection(mainwin->summaryview);
3037         g_return_if_fail(msginfo_list != NULL);
3038         compose_reply_from_messageview(msgview, msginfo_list, action);
3039         g_slist_free(msginfo_list);
3040 }
3041
3042
3043 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3044                                 GtkWidget *widget)
3045 {
3046         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3047                 gtk_widget_show(mainwin->hbox_stat);
3048                 prefs_common.show_statusbar = TRUE;
3049         } else {
3050                 gtk_widget_hide(mainwin->hbox_stat);
3051                 prefs_common.show_statusbar = FALSE;
3052         }
3053 }
3054
3055 static void separate_widget_cb(MainWindow *mainwin, guint action,
3056                                GtkWidget *widget)
3057 {
3058         SeparateType type;
3059
3060         if (GTK_CHECK_MENU_ITEM(widget)->active)
3061                 type = mainwin->type | action;
3062         else
3063                 type = mainwin->type & ~action;
3064
3065         main_window_separation_change(mainwin, type);
3066
3067         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
3068         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
3069 }
3070
3071 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3072                                         gboolean ask_sync)
3073 {
3074         offline_ask_sync = ask_sync;
3075         if (offline)
3076                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3077         else
3078                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3079         offline_ask_sync = TRUE;
3080 }
3081
3082 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3083 {
3084         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3085 }
3086
3087 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3088 {
3089         GList *folderlist = folder_get_list();
3090         gboolean found = FALSE;
3091
3092         /* see if there are synchronised folders */
3093         for (; folderlist; folderlist = folderlist->next) {
3094                 Folder *folder = (Folder *)folderlist->data;
3095                 if (folder_want_synchronise(folder)) {
3096                         found = TRUE;
3097                         break;
3098                 }
3099         }
3100         
3101         if (!found)
3102                 return;
3103                 
3104         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3105                         _("Do you want to synchronise your folders now?"),
3106                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3107                 return;
3108
3109         folder_synchronise(NULL);
3110 }
3111
3112 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3113 {
3114         MainWindow *mainwin;
3115         GtkItemFactory *ifactory;
3116         GtkCheckMenuItem *menuitem;
3117
3118         mainwin = (MainWindow *) data;
3119         
3120         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3121         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3122         
3123         g_return_if_fail(mainwin != NULL);
3124         g_return_if_fail(menuitem != NULL);
3125         
3126         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3127                 /* go offline */
3128                 mainwindow_check_synchronise(mainwin, TRUE);
3129                 gtk_widget_hide (mainwin->online_switch);
3130                 gtk_widget_show (mainwin->offline_switch);
3131                 menuitem->active = TRUE;
3132                 prefs_common.work_offline = TRUE;
3133                 inc_autocheck_timer_remove();           
3134         } else {
3135                 /*go online */
3136                 gtk_widget_hide (mainwin->offline_switch);
3137                 gtk_widget_show (mainwin->online_switch);
3138                 menuitem->active = FALSE;
3139                 prefs_common.work_offline = FALSE;
3140                 inc_autocheck_timer_set();
3141         }
3142 }
3143
3144 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3145                                 GtkWidget *widget)
3146 {
3147         addressbook_open(NULL);
3148 }
3149
3150 static void log_window_show_cb(MainWindow *mainwin, guint action,
3151                                GtkWidget *widget)
3152 {
3153         log_window_show(mainwin->logwin);
3154 }
3155
3156 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3157 {
3158         inc_cancel_all();
3159 }
3160
3161 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3162 {
3163         summary_move_to(mainwin->summaryview);
3164 }
3165
3166 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3167 {
3168         summary_copy_to(mainwin->summaryview);
3169 }
3170
3171 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3172 {
3173         summary_delete(mainwin->summaryview);
3174 }
3175
3176 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3177 {
3178         summary_delete_trash(mainwin->summaryview);
3179 }
3180
3181 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3182 {
3183         summary_cancel(mainwin->summaryview);
3184 }
3185
3186 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3187 {
3188         summary_open_msg(mainwin->summaryview);
3189 }
3190
3191 static void view_source_cb(MainWindow *mainwin, guint action,
3192                            GtkWidget *widget)
3193 {
3194         summary_view_source(mainwin->summaryview);
3195 }
3196
3197 static void show_all_header_cb(MainWindow *mainwin, guint action,
3198                                GtkWidget *widget)
3199 {
3200         if (mainwin->menu_lock_count) return;
3201         mainwin->summaryview->messageview->all_headers = 
3202                         GTK_CHECK_MENU_ITEM(widget)->active;
3203         summary_display_msg_selected(mainwin->summaryview,
3204                                      GTK_CHECK_MENU_ITEM(widget)->active);
3205 }
3206
3207 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3208 {
3209         summary_mark(mainwin->summaryview);
3210 }
3211
3212 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3213 {
3214         summary_unmark(mainwin->summaryview);
3215 }
3216
3217 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3218                               GtkWidget *widget)
3219 {
3220         summary_mark_as_unread(mainwin->summaryview);
3221 }
3222
3223 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3224                             GtkWidget *widget)
3225 {
3226         summary_mark_as_read(mainwin->summaryview);
3227 }
3228
3229 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3230                              GtkWidget *widget)
3231 {
3232         summary_mark_all_read(mainwin->summaryview);
3233 }
3234
3235 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3236                              GtkWidget *widget)
3237 {
3238         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3239 }
3240
3241 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3242 {
3243         summary_reedit(mainwin->summaryview);
3244 }
3245
3246 static void add_address_cb(MainWindow *mainwin, guint action,
3247                            GtkWidget *widget)
3248 {
3249         summary_add_address(mainwin->summaryview);
3250 }
3251
3252 static void set_charset_cb(MainWindow *mainwin, guint action,
3253                            GtkWidget *widget)
3254 {
3255         const gchar *str;
3256
3257         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3258                 str = conv_get_charset_str((CharSet)action);
3259                 
3260                 g_free(mainwin->messageview->forced_charset);
3261                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3262                 procmime_force_charset(str);
3263                 
3264                 summary_redisplay_msg(mainwin->summaryview);
3265                 
3266                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3267         }
3268 }
3269
3270 static void set_decode_cb(MainWindow *mainwin, guint action,
3271                            GtkWidget *widget)
3272 {
3273         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3274                 mainwin->messageview->forced_encoding = (EncodingType)action;
3275                 
3276                 summary_redisplay_msg(mainwin->summaryview);
3277                 
3278                 debug_print("forced encoding: %d\n", action);
3279         }
3280 }
3281
3282 static void hide_read_messages (MainWindow *mainwin, guint action,
3283                                 GtkWidget *widget)
3284 {
3285         if (!mainwin->summaryview->folder_item
3286             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3287                 return;
3288         summary_toggle_show_read_messages(mainwin->summaryview);
3289 }
3290
3291 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3292 {
3293         gboolean threaded = FALSE;
3294         if (mainwin->menu_lock_count) return;
3295         if (!mainwin->summaryview->folder_item) return;
3296
3297         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3298
3299         mainwin->summaryview->folder_item->threaded = threaded; 
3300
3301         mainwin->summaryview->threaded = threaded;
3302
3303         summary_show(mainwin->summaryview, 
3304                         mainwin->summaryview->folder_item);
3305 }
3306
3307 static void expand_threads_cb(MainWindow *mainwin, guint action,
3308                               GtkWidget *widget)
3309 {
3310         summary_expand_threads(mainwin->summaryview);
3311 }
3312
3313 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3314                                 GtkWidget *widget)
3315 {
3316         summary_collapse_threads(mainwin->summaryview);
3317 }
3318
3319 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3320                                 GtkWidget *widget)
3321 {
3322         prefs_summary_column_open();
3323 }
3324
3325 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3326                                 GtkWidget *widget)
3327 {
3328         prefs_folder_column_open();
3329 }
3330
3331 static void sort_summary_cb(MainWindow *mainwin, guint action,
3332                             GtkWidget *widget)
3333 {
3334         FolderItem *item = mainwin->summaryview->folder_item;
3335         GtkWidget *menuitem;
3336
3337         if (mainwin->menu_lock_count) return;
3338
3339         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3340                 menuitem = gtk_item_factory_get_item
3341                         (mainwin->menu_factory, "/View/Sort/Ascending");
3342                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3343                              GTK_CHECK_MENU_ITEM(menuitem)->active
3344                              ? SORT_ASCENDING : SORT_DESCENDING);
3345                 item->sort_key = action;
3346         }
3347 }
3348
3349 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3350                                  GtkWidget *widget)
3351 {
3352         FolderItem *item = mainwin->summaryview->folder_item;
3353
3354         if (mainwin->menu_lock_count) return;
3355
3356         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3357                 summary_sort(mainwin->summaryview,
3358                              item->sort_key, (FolderSortType)action);
3359 }
3360
3361 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3362                                   GtkWidget *widget)
3363 {
3364         summary_attract_by_subject(mainwin->summaryview);
3365 }
3366
3367 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3368                                  GtkWidget *widget)
3369 {
3370         FolderItem *item;
3371
3372         item = folderview_get_selected_item(mainwin->folderview);
3373         if (item) {
3374                 main_window_cursor_wait(mainwin);
3375                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3376
3377                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3378                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3379
3380                 STATUSBAR_POP(mainwin);
3381                 main_window_cursor_normal(mainwin);
3382         }
3383 }
3384
3385 struct DelDupsData
3386 {
3387         guint   dups;
3388         guint   folders;
3389 };
3390
3391 static void deldup_all(FolderItem *item, gpointer _data)
3392 {
3393         struct DelDupsData *data = _data;
3394         gint result;
3395         
3396         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3397         if (result >= 0) {
3398                 data->dups += result;
3399                 data->folders += 1;
3400         }
3401 }
3402
3403 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3404                                  GtkWidget *widget)
3405 {
3406         struct DelDupsData data = {0, 0};
3407
3408         folder_func_to_all_folders(deldup_all, &data);
3409         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3410                                    "Deleted %d duplicate messages in %d folders.\n",
3411                                    data.dups),
3412                           data.dups, data.folders);
3413 }
3414
3415 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3416 {
3417         summary_filter(mainwin->summaryview, (gboolean)action);
3418 }
3419
3420 static void execute_summary_cb(MainWindow *mainwin, guint action,
3421                                GtkWidget *widget)
3422 {
3423         summary_execute(mainwin->summaryview);
3424 }
3425
3426 static void update_summary_cb(MainWindow *mainwin, guint action,
3427                               GtkWidget *widget)
3428 {
3429         FolderItem *fitem;
3430         FolderView *folderview = mainwin->folderview;
3431
3432         if (!mainwin->summaryview->folder_item) return;
3433         if (!folderview->opened) return;
3434
3435         folder_update_op_count();
3436
3437         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3438                                             folderview->opened);
3439         if (!fitem) return;
3440
3441         folder_item_scan(fitem);
3442         summary_show(mainwin->summaryview, fitem);
3443 }
3444
3445 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3446 {
3447         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3448 }
3449
3450 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3451 {
3452         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3453 }
3454
3455 static void prev_unread_cb(MainWindow *mainwin, guint action,
3456                            GtkWidget *widget)
3457 {
3458         summary_select_prev_unread(mainwin->summaryview);
3459 }
3460
3461 static void next_unread_cb(MainWindow *mainwin, guint action,
3462                            GtkWidget *widget)
3463 {
3464         summary_select_next_unread(mainwin->summaryview);
3465 }
3466
3467 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3468 {
3469         summary_select_prev_new(mainwin->summaryview);
3470 }
3471
3472 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3473 {
3474         summary_select_next_new(mainwin->summaryview);
3475 }
3476
3477 static void prev_marked_cb(MainWindow *mainwin, guint action,
3478                            GtkWidget *widget)
3479 {
3480         summary_select_prev_marked(mainwin->summaryview);
3481 }
3482
3483 static void next_marked_cb(MainWindow *mainwin, guint action,
3484                            GtkWidget *widget)
3485 {
3486         summary_select_next_marked(mainwin->summaryview);
3487 }
3488
3489 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3490                             GtkWidget *widget)
3491 {
3492         summary_select_prev_labeled(mainwin->summaryview);
3493 }
3494
3495 static void next_labeled_cb(MainWindow *mainwin, guint action,
3496                             GtkWidget *widget)
3497 {
3498         summary_select_next_labeled(mainwin->summaryview);
3499 }
3500
3501 static void goto_folder_cb(MainWindow *mainwin, guint action,
3502                            GtkWidget *widget)
3503 {
3504         FolderItem *to_folder;
3505
3506         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3507
3508         if (to_folder)
3509                 folderview_select(mainwin->folderview, to_folder);
3510 }
3511
3512 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3513 {
3514         messageview_copy_clipboard(mainwin->messageview);
3515 }
3516
3517 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3518 {
3519         MessageView *msgview = mainwin->messageview;
3520
3521         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
3522                 summary_select_all(mainwin->summaryview);
3523         else if (messageview_is_visible(msgview) &&
3524                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3525                 messageview_select_all(mainwin->messageview);
3526 }
3527
3528 static void select_thread_cb(MainWindow *mainwin, guint action,
3529                              GtkWidget *widget)
3530 {
3531         summary_select_thread(mainwin->summaryview);
3532 }
3533
3534 static void create_filter_cb(MainWindow *mainwin, guint action,
3535                              GtkWidget *widget)
3536 {
3537         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3538 }
3539
3540 static void create_processing_cb(MainWindow *mainwin, guint action,
3541                              GtkWidget *widget)
3542 {
3543         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3544 }
3545
3546 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3547                                          GtkWidget *widget)
3548 {
3549         prefs_filtering_open(&pre_global_processing,
3550                              _("Processing rules to apply before folder rules"),
3551                              NULL, NULL);
3552 }
3553
3554 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3555                                           GtkWidget *widget)
3556 {
3557         prefs_filtering_open(&post_global_processing,
3558                              _("Processing rules to apply after folder rules"),
3559                              NULL, NULL);
3560 }
3561
3562 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3563                                     GtkWidget *widget)
3564 {
3565         prefs_filtering_open(&filtering_rules,
3566                              _("Filtering configuration"),
3567                              NULL, NULL);
3568 }
3569
3570 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3571                                    GtkWidget *widget)
3572 {
3573         prefs_template_open();
3574 }
3575
3576 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3577                                   GtkWidget *widget)
3578 {
3579         prefs_actions_open(mainwin);
3580 }
3581 #ifdef USE_OPENSSL
3582 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3583                                   GtkWidget *widget)
3584 {
3585         ssl_manager_open(mainwin);
3586 }
3587 #endif
3588 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3589                                   GtkWidget *widget)
3590 {
3591         if (!cur_account) {
3592                 new_account_cb(mainwin, 0, widget);
3593         } else {
3594                 account_open(cur_account);
3595         }
3596 }
3597
3598 static void new_account_cb(MainWindow *mainwin, guint action,
3599                            GtkWidget *widget)
3600 {
3601         account_edit_open();
3602         if (!compose_get_compose_list()) account_add();
3603 }
3604
3605 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3606 {
3607         FolderItem *item = NULL;
3608         cur_account = (PrefsAccount *)data;
3609         
3610         if (!mainwindow_get_mainwindow())
3611                 return;
3612         main_window_show_cur_account(mainwindow_get_mainwindow());
3613         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3614         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3615         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3616         item = folderview_get_selected_item(
3617                         mainwindow_get_mainwindow()->folderview);
3618         if (item) {
3619                 toolbar_set_compose_button
3620                         (mainwindow_get_mainwindow()->toolbar,
3621                          FOLDER_TYPE(item->folder) == F_NEWS ? 
3622                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3623         }
3624 }
3625
3626 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3627 {
3628         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3629         PrefsAccount *account = (PrefsAccount *)data;
3630
3631         inc_account_mail(mainwin, account);
3632 }
3633
3634 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3635 {
3636         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3637         PrefsAccount *account = (PrefsAccount *)data;
3638         FolderItem *item = mainwin->summaryview->folder_item;   
3639
3640         compose_new_with_folderitem(account, item);
3641 }
3642
3643 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3644 {
3645         prefs_gtk_open();
3646 }
3647
3648 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3649 {
3650         pluginwindow_create();
3651 }
3652
3653 static void manual_open_cb(MainWindow *mainwin, guint action,
3654                            GtkWidget *widget)
3655 {
3656         manual_open((ManualType)action);
3657 }
3658
3659 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3660 {
3661         legend_show();
3662 }
3663
3664 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3665 {
3666         MainWindow *mainwin = (MainWindow *)data;
3667         gchar *str;
3668
3669         if (item->path)
3670                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3671                                       LOCAL_FOLDER(folder)->rootpath,
3672                                       G_DIR_SEPARATOR,
3673                                       item->path);
3674         else
3675                 str = g_strdup_printf(_("Scanning folder %s ..."),
3676                                       LOCAL_FOLDER(folder)->rootpath);
3677
3678         STATUSBAR_PUSH(mainwin, str);
3679         STATUSBAR_POP(mainwin);
3680         g_free(str);
3681 }
3682
3683 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3684                                           gpointer data)
3685 {
3686         SummaryView *summary;
3687
3688         g_return_val_if_fail(data, FALSE);
3689         summary = ((MainWindow *)data)->summaryview;
3690         g_return_val_if_fail(summary, FALSE);
3691
3692         if (GTK_CLIST(summary->ctree)->selection && 
3693             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3694                 return FALSE;
3695
3696         return FALSE;
3697 }
3698
3699 #define BREAK_ON_MODIFIER_KEY() \
3700         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3701
3702 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3703                                     gpointer data)
3704 {
3705         MainWindow *mainwin = (MainWindow*) data;
3706         
3707         if (!mainwin || !event) 
3708                 return FALSE;
3709
3710         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3711         {
3712                 lastkey = event->keyval;
3713                 return FALSE;
3714         }
3715
3716         switch (event->keyval) {
3717         case GDK_Q:             /* Quit */
3718                 BREAK_ON_MODIFIER_KEY();
3719
3720                 app_exit_cb(mainwin, 0, NULL);
3721                 return FALSE;
3722         case GDK_space:
3723                 if (mainwin->folderview && mainwin->summaryview
3724                     && ((!mainwin->summaryview->displayed
3725                         && !mainwin->summaryview->selected) 
3726                         || (mainwin->summaryview->folder_item
3727                             && mainwin->summaryview->folder_item->total_msgs == 0))) {
3728                         g_signal_stop_emission_by_name(G_OBJECT(widget), 
3729                                        "key_press_event");
3730                         folderview_select_next_unread(mainwin->folderview);
3731                 }
3732                 break;
3733         default:
3734                 break;
3735         }
3736         return FALSE;
3737 }
3738
3739 #undef BREAK_ON_MODIFIER_KEY
3740
3741 /*
3742  * Harvest addresses for selected folder.
3743  */
3744 static void addr_harvest_cb( MainWindow *mainwin,
3745                             guint action,
3746                             GtkWidget *widget )
3747 {
3748         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
3749 }
3750
3751 /*
3752  * Harvest addresses for selected messages in summary view.
3753  */
3754 static void addr_harvest_msg_cb( MainWindow *mainwin,
3755                             guint action,
3756                             GtkWidget *widget )
3757 {
3758         summary_harvest_address( mainwin->summaryview );
3759 }
3760
3761 /*!
3762  *\brief        get a MainWindow
3763  *
3764  *\return       MainWindow * The first mainwindow in the mainwin_list
3765  */
3766 MainWindow *mainwindow_get_mainwindow(void)
3767 {
3768         if (mainwin_list && mainwin_list->data)
3769                 return (MainWindow *)(mainwin_list->data);
3770         else
3771                 return NULL;
3772 }
3773
3774 gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
3775 {
3776         ProgressData *data = (ProgressData *) source;
3777         MainWindow *mainwin = (MainWindow *) userdata;
3778
3779         switch (data->cmd) {
3780         case PROGRESS_COMMAND_START:
3781         case PROGRESS_COMMAND_STOP:
3782                 gtk_progress_bar_set_fraction
3783                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
3784                 break;
3785         case PROGRESS_COMMAND_SET_PERCENTAGE:
3786                 gtk_progress_bar_set_fraction
3787                         (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
3788                 break;          
3789         }
3790         while (gtk_events_pending()) gtk_main_iteration ();
3791
3792         return FALSE;
3793 }
3794
3795 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3796 {
3797         mainwindow_check_synchronise(mainwin, FALSE);
3798 }
3799
3800 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
3801 {
3802         summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
3803 }
3804
3805 void mainwindow_jump_to(const gchar *target)
3806 {
3807         gchar *tmp = NULL;
3808         gchar *p = NULL;
3809         FolderItem *item = NULL;
3810         gchar *msg = NULL;
3811         MainWindow *mainwin = mainwindow_get_mainwindow();
3812         
3813         if (!target)
3814                 return;
3815                 
3816         if (!mainwin) {
3817                 printf(_("not initialized\n"));
3818                 return;
3819         }
3820
3821         tmp = g_strdup(target);
3822         
3823         if ((p = strstr(tmp, "\r")) != NULL)
3824                 *p = '\0';
3825         if ((p = strstr(tmp, "\n")) != NULL)
3826                 *p = '\0';
3827
3828         if ((item = folder_find_item_from_identifier(tmp))) {
3829                 printf(_("selecting folder '%s'\n"), tmp);
3830                 folderview_select(mainwin->folderview, item);
3831                 main_window_popup(mainwin);
3832                 g_free(tmp);
3833                 return;
3834         }
3835         
3836         msg = strrchr(tmp, G_DIR_SEPARATOR);
3837         if (msg) {
3838                 *msg++ = '\0';
3839                 if ((item = folder_find_item_from_identifier(tmp))) {
3840                         printf(_("selecting folder '%s'\n"), tmp);
3841                         folderview_select(mainwin->folderview, item);
3842                 } 
3843                 if (item && msg && atoi(msg)) {
3844                         printf(_("selecting message %d\n"), atoi(msg));
3845                         summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
3846                         summary_display_msg_selected(mainwin->summaryview, FALSE);
3847                         main_window_popup(mainwin);
3848                         g_free(tmp);
3849                         return;
3850                 } 
3851         }
3852         
3853         printf("'%s' not found\n", tmp);
3854         
3855         g_free(tmp);
3856 }