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