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