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