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