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