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