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