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