931dc248a9d640ff79ef457b587306e9df246254
[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         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1355         ifactory = gtk_item_factory_from_widget(menubar);
1356
1357 /*      gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1358         main_create_mailing_list_menu (mainwin, NULL); */
1359
1360         menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1361
1362         if (prefs_common.toolbar_detachable) {
1363                 handlebox = gtk_handle_box_new();
1364                 gtk_widget_show(handlebox);
1365                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1366                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1367                                  G_CALLBACK(toolbar_child_attached), mainwin);
1368                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1369                                  G_CALLBACK(toolbar_child_detached), mainwin);
1370         } else {
1371                 handlebox = gtk_hbox_new(FALSE, 0);
1372                 gtk_widget_show(handlebox);
1373                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1374         }
1375         /* link window to mainwin->window to avoid gdk warnings */
1376         mainwin->window       = window;
1377         
1378         /* create toolbar */
1379         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1380                                           handlebox, 
1381                                           (gpointer)mainwin);
1382         toolbar_set_learn_button
1383                 (mainwin->toolbar,
1384                  LEARN_SPAM);
1385
1386         /* vbox that contains body */
1387         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1388         gtk_widget_show(vbox_body);
1389         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1390         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1391
1392         hbox_stat = gtk_hbox_new(FALSE, 2);
1393         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1394
1395         tips = gtk_tooltips_new();
1396
1397         warning_icon = gtk_image_new_from_stock
1398                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1399         warning_btn = gtk_event_box_new();
1400         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1401         
1402         mainwin->warning_btn      = warning_btn;
1403         
1404         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
1405                          G_CALLBACK(warning_icon_pressed),
1406                          (gpointer) mainwin);
1407         g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1408                          G_CALLBACK(warning_visi_notify), mainwin);
1409         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1410                          G_CALLBACK(warning_visi_notify), mainwin);
1411         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1412                          G_CALLBACK(warning_leave_notify), mainwin);
1413         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1414                          G_CALLBACK(warning_enter_notify), mainwin);
1415
1416         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1417
1418         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn, 
1419                              _("Some error(s) happened. Click here to view log."), NULL);
1420         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1421
1422         statusbar = statusbar_create();
1423         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1424
1425         progressbar = gtk_progress_bar_new();
1426         gtk_widget_set_size_request(progressbar, 120, 1);
1427         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1428
1429         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1430         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1431         online_switch = gtk_button_new ();
1432         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch, 
1433                              _("You are online. Click the icon to go offline"), NULL);
1434         offline_switch = gtk_button_new ();
1435         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch, 
1436                              _("You are offline. Click the icon to go online"),
1437                              NULL);
1438         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1439         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1440         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1441         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1442         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1443         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1444         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1445         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1446         
1447         statuslabel = gtk_label_new("");
1448         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1449
1450         ac_button = gtk_button_new();
1451         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1452                              ac_button, _("Select account"), NULL);
1453         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1454         gtk_widget_set_size_request(ac_button, -1, 0);
1455         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1456         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1457                          G_CALLBACK(ac_label_button_pressed), mainwin);
1458
1459         ac_label = gtk_label_new("");
1460         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1461
1462         gtk_widget_show_all(hbox_stat);
1463
1464         gtk_widget_hide(offline_switch);
1465         gtk_widget_hide(warning_btn);
1466
1467         /* create views */
1468         mainwin->folderview  = folderview  = folderview_create();
1469         mainwin->summaryview = summaryview = summary_create();
1470         mainwin->messageview = messageview = messageview_create(mainwin);
1471
1472         /* init log instances data before creating log views */
1473         set_log_title(LOG_PROTOCOL, _("Network log"));
1474         set_log_prefs(LOG_PROTOCOL,
1475                         &prefs_common.logwin_width,
1476                         &prefs_common.logwin_height);
1477         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1478         set_log_prefs(LOG_DEBUG_FILTERING,
1479                         &prefs_common.filtering_debugwin_width,
1480                         &prefs_common.filtering_debugwin_height);
1481
1482         /* setup log windows */
1483         mainwin->logwin = log_window_create(LOG_PROTOCOL);
1484         log_window_init(mainwin->logwin);
1485
1486         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1487         log_window_set_clipping(mainwin->logwin,
1488                                 prefs_common.cliplog,
1489                                 prefs_common.loglength);
1490
1491         log_window_init(mainwin->filtering_debugwin);
1492         log_window_set_clipping(mainwin->filtering_debugwin,
1493                                 prefs_common.filtering_debug_cliplog,
1494                                 prefs_common.filtering_debug_loglength);
1495         if (prefs_common.enable_filtering_debug)
1496                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1497         else
1498                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1499
1500         folderview->mainwin      = mainwin;
1501         folderview->summaryview  = summaryview;
1502
1503         summaryview->mainwin     = mainwin;
1504         summaryview->folderview  = folderview;
1505         summaryview->messageview = messageview;
1506         summaryview->window      = window;
1507
1508         messageview->statusbar   = statusbar;
1509         mainwin->vbox           = vbox;
1510         mainwin->menubar        = menubar;
1511         mainwin->menu_factory   = ifactory;
1512         mainwin->handlebox      = handlebox;
1513         mainwin->vbox_body      = vbox_body;
1514         mainwin->hbox_stat      = hbox_stat;
1515         mainwin->statusbar      = statusbar;
1516         mainwin->progressbar    = progressbar;
1517         mainwin->statuslabel    = statuslabel;
1518         mainwin->online_switch  = online_switch;
1519         mainwin->online_pixmap  = online_pixmap;
1520         mainwin->offline_pixmap = offline_pixmap;
1521         mainwin->ac_button      = ac_button;
1522         mainwin->ac_label       = ac_label;
1523         mainwin->offline_switch    = offline_switch;
1524         
1525         /* set context IDs for status bar */
1526         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1527                 (GTK_STATUSBAR(statusbar), "Main Window");
1528         mainwin->folderview_cid = gtk_statusbar_get_context_id
1529                 (GTK_STATUSBAR(statusbar), "Folder View");
1530         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1531                 (GTK_STATUSBAR(statusbar), "Summary View");
1532         mainwin->messageview_cid = gtk_statusbar_get_context_id
1533                 (GTK_STATUSBAR(statusbar), "Message View");
1534
1535         messageview->statusbar_cid = mainwin->messageview_cid;
1536
1537         /* allocate colors for summary view and folder view */
1538         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1539         summaryview->color_marked.blue = (guint16)65535;
1540
1541         summaryview->color_dim.red = summaryview->color_dim.green =
1542                 summaryview->color_dim.blue = COLOR_DIM;
1543
1544         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1545                                        &folderview->color_new);
1546
1547         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1548                                        &folderview->color_op);
1549
1550         summaryview->color_important.red = 0;
1551         summaryview->color_important.green = 0;
1552         summaryview->color_important.blue = (guint16)65535;
1553
1554         color[0] = summaryview->color_marked;
1555         color[1] = summaryview->color_dim;
1556         color[2] = folderview->color_new;
1557         color[3] = folderview->color_op;
1558
1559         colormap = gdk_drawable_get_colormap(window->window);
1560         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1561         for (i = 0; i < 4; i++) {
1562                 if (success[i] == FALSE)
1563                         g_warning("MainWindow: color allocation %d failed\n", i);
1564         }
1565
1566         debug_print("done.\n");
1567
1568         messageview->visible = prefs_common.msgview_visible;
1569
1570         main_window_set_widgets(mainwin, prefs_common.layout_mode);
1571
1572         g_signal_connect(G_OBJECT(window), "size_allocate",
1573                          G_CALLBACK(main_window_size_allocate_cb),
1574                          mainwin);
1575
1576         /* set menu items */
1577         menuitem = gtk_item_factory_get_item
1578                 (ifactory, "/View/Character encoding/Auto detect");
1579         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1580
1581         switch (prefs_common.toolbar_style) {
1582         case TOOLBAR_NONE:
1583                 menuitem = gtk_item_factory_get_item
1584                         (ifactory, "/View/Show or hide/Toolbar/Hide");
1585                 break;
1586         case TOOLBAR_ICON:
1587                 menuitem = gtk_item_factory_get_item
1588                         (ifactory, "/View/Show or hide/Toolbar/Icons only");
1589                 break;
1590         case TOOLBAR_TEXT:
1591                 menuitem = gtk_item_factory_get_item
1592                         (ifactory, "/View/Show or hide/Toolbar/Text only");
1593                 break;
1594         case TOOLBAR_BOTH:
1595                 menuitem = gtk_item_factory_get_item
1596                         (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1597                 break;
1598         case TOOLBAR_BOTH_HORIZ:
1599                 menuitem = gtk_item_factory_get_item
1600                         (ifactory,
1601                          "/View/Show or hide/Toolbar/Text beside icons");
1602         }
1603         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1604
1605         gtk_widget_hide(mainwin->hbox_stat);
1606         menuitem = gtk_item_factory_get_item
1607                 (ifactory, "/View/Show or hide/Status bar");
1608         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1609                                        prefs_common.show_statusbar);
1610         
1611         /* set account selection menu */
1612         ac_menu = gtk_item_factory_get_widget
1613                 (ifactory, "/Configuration/Change current account");
1614         mainwin->ac_menu = ac_menu;
1615
1616         toolbar_main_set_sensitive(mainwin);
1617
1618         /* create actions menu */
1619         main_window_update_actions_menu(mainwin);
1620
1621         main_create_mailing_list_menu (mainwin, NULL);
1622
1623         /* attach accel groups to main window */
1624 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
1625         gtk_window_add_accel_group                                      \
1626                 (GTK_WINDOW(win),                                       \
1627                  gtk_item_factory_from_widget(menu)->accel_group);      \
1628         g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1629                         "accel_activate",                               \
1630                         G_CALLBACK(main_window_accel_activate), mainwin);
1631                          
1632         
1633         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1634         
1635         /* connect the accelerators for equivalent 
1636            menu items in different menus             */
1637         menu_connect_identical_items();
1638
1639         gtk_window_iconify(GTK_WINDOW(mainwin->window));
1640
1641         g_signal_connect(G_OBJECT(window), "window_state_event",
1642                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
1643         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1644                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1645         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1646
1647         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1648             prefs_common.layout_mode == SMALL_LAYOUT) {
1649                 summary_relayout(mainwin->summaryview); 
1650         }
1651         summary_update_unread(mainwin->summaryview, NULL);
1652         
1653         gtk_widget_show(mainwin->window);
1654
1655         /* initialize views */
1656         folderview_init(folderview);
1657         summary_init(summaryview);
1658         messageview_init(messageview);
1659 #ifdef USE_OPENSSL
1660         sslcertwindow_register_hook();
1661 #endif
1662         mainwin->lock_count = 0;
1663         mainwin->menu_lock_count = 0;
1664         mainwin->cursor_count = 0;
1665
1666         mainwin->progressindicator_hook =
1667                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1668
1669         if (!watch_cursor)
1670                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1671         if (!hand_cursor)
1672                 hand_cursor = gdk_cursor_new(GDK_HAND2);
1673
1674         mainwin_list = g_list_append(mainwin_list, mainwin);
1675
1676         /* init work_offline */
1677         if (prefs_common.work_offline)
1678                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1679
1680         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1681         mainwindow_tags_menu_create(mainwin, FALSE);
1682         
1683         return mainwin;
1684 }
1685
1686 void main_window_destroy(MainWindow *mainwin)
1687 {
1688         /* TODO : destroy other component */
1689         messageview_destroy(mainwin->messageview);
1690         mainwin->messageview = NULL;    
1691 }
1692
1693 void main_window_update_actions_menu(MainWindow *mainwin)
1694 {
1695         GtkItemFactory *ifactory;
1696
1697         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1698         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1699 }
1700
1701 void main_window_cursor_wait(MainWindow *mainwin)
1702 {
1703
1704         if (mainwin->cursor_count == 0) {
1705                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1706                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1707         }
1708         
1709         mainwin->cursor_count++;
1710
1711         gdk_flush();
1712 }
1713
1714 void main_window_cursor_normal(MainWindow *mainwin)
1715 {
1716         if (mainwin->cursor_count)
1717                 mainwin->cursor_count--;
1718
1719         if (mainwin->cursor_count == 0) {
1720                 gdk_window_set_cursor(mainwin->window->window, NULL);
1721                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1722         }
1723         gdk_flush();
1724 }
1725
1726 /* lock / unlock the user-interface */
1727 void main_window_lock(MainWindow *mainwin)
1728 {
1729         if (mainwin->lock_count == 0)
1730                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1731
1732         mainwin->lock_count++;
1733
1734         main_window_set_menu_sensitive(mainwin);
1735         toolbar_main_set_sensitive(mainwin);
1736 }
1737
1738 void main_window_unlock(MainWindow *mainwin)
1739 {
1740         if (mainwin->lock_count)
1741                 mainwin->lock_count--;
1742
1743         main_window_set_menu_sensitive(mainwin);
1744         toolbar_main_set_sensitive(mainwin);
1745
1746         if (mainwin->lock_count == 0)
1747                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1748 }
1749
1750 static void main_window_menu_callback_block(MainWindow *mainwin)
1751 {
1752         mainwin->menu_lock_count++;
1753 }
1754
1755 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1756 {
1757         if (mainwin->menu_lock_count)
1758                 mainwin->menu_lock_count--;
1759 }
1760
1761 static guint prefs_tag = 0;
1762
1763 void main_window_reflect_prefs_all(void)
1764 {
1765         main_window_reflect_prefs_all_real(FALSE);
1766 }
1767
1768 static gboolean reflect_prefs_timeout_cb(gpointer data) 
1769 {
1770         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1771         GList *cur;
1772         MainWindow *mainwin;
1773         GtkWidget *pixmap;
1774
1775         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1776                 mainwin = (MainWindow *)cur->data;
1777
1778                 main_window_show_cur_account(mainwin);
1779                 main_window_set_menu_sensitive(mainwin);
1780                 toolbar_main_set_sensitive(mainwin);
1781
1782                 /* pixmap themes */
1783                 if (pixmap_theme_changed) {
1784                         toolbar_update(TOOLBAR_MAIN, mainwin);
1785                         messageview_reflect_prefs_pixmap_theme();
1786                         compose_reflect_prefs_pixmap_theme();
1787                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1788                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1789
1790                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1791                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1792                                              mainwin->online_pixmap);
1793                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1794                         gtk_widget_show(pixmap);
1795                         mainwin->online_pixmap = pixmap;
1796                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1797                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1798                                              mainwin->offline_pixmap);
1799                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1800                         gtk_widget_show(pixmap);
1801                         mainwin->offline_pixmap = pixmap;
1802                 }
1803                 
1804                 headerview_set_font(mainwin->messageview->headerview);
1805                 headerview_set_visibility(mainwin->messageview->headerview,
1806                                           prefs_common.display_header_pane);
1807                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1808                 folderview_reflect_prefs();
1809                 summary_reflect_prefs();
1810                 summary_redisplay_msg(mainwin->summaryview);
1811         }
1812         prefs_tag = 0;
1813         return FALSE;
1814 }
1815
1816 void main_window_reflect_prefs_all_now(void)
1817 {
1818         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1819 }
1820
1821 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1822 {
1823         GtkMenuShell *menu;
1824         GList *cur;
1825
1826         /* re-create colorlabel submenu */
1827         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1828         g_return_if_fail(menu != NULL);
1829
1830         /* clear items. get item pointers. */
1831         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1832                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1833         }
1834         mainwindow_colorlabel_menu_create(mainwin, TRUE);
1835         summary_reflect_prefs_custom_colors(mainwin->summaryview);
1836
1837 }
1838
1839 void main_window_reflect_tags_changes(MainWindow *mainwin)
1840 {
1841         GtkMenuShell *menu;
1842         GList *cur;
1843
1844         /* re-create tags submenu */
1845         menu = GTK_MENU_SHELL(mainwin->tags_menu);
1846         g_return_if_fail(menu != NULL);
1847
1848         /* clear items. get item pointers. */
1849         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1850                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1851         }
1852         mainwindow_tags_menu_create(mainwin, TRUE);
1853         summary_reflect_tags_changes(mainwin->summaryview);
1854
1855 }
1856
1857 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1858 {
1859         if (prefs_tag == 0 || pixmap_theme_changed) {
1860                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
1861                                                 GINT_TO_POINTER(pixmap_theme_changed));
1862         }
1863 }
1864
1865 void main_window_set_summary_column(void)
1866 {
1867         GList *cur;
1868         MainWindow *mainwin;
1869
1870         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1871                 mainwin = (MainWindow *)cur->data;
1872                 summary_set_column_order(mainwin->summaryview);
1873         }
1874 }
1875
1876 void main_window_set_folder_column(void)
1877 {
1878         GList *cur;
1879         MainWindow *mainwin;
1880
1881         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1882                 mainwin = (MainWindow *)cur->data;
1883                 folderview_set_column_order(mainwin->folderview);
1884         }
1885 }
1886
1887 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1888                                                   GList *account_list)
1889 {
1890         GList *cur_ac, *cur_item;
1891         GtkWidget *menuitem;
1892         PrefsAccount *ac_prefs;
1893
1894         /* destroy all previous menu item */
1895         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1896         while (cur_item != NULL) {
1897                 GList *next = cur_item->next;
1898                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1899                 cur_item = next;
1900         }
1901
1902         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1903                 ac_prefs = (PrefsAccount *)cur_ac->data;
1904
1905                 menuitem = gtk_menu_item_new_with_label
1906                         (ac_prefs->account_name
1907                          ? ac_prefs->account_name : _("Untitled"));
1908                 gtk_widget_show(menuitem);
1909                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1910                 g_signal_connect(G_OBJECT(menuitem), "activate",
1911                                  G_CALLBACK(account_selector_menu_cb),
1912                                  ac_prefs);
1913         }
1914 }
1915
1916 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1917                                                  GList *account_list)
1918 {
1919         GList *cur_ac, *cur_item;
1920         GtkWidget *menu;
1921         GtkWidget *menuitem;
1922         PrefsAccount *ac_prefs;
1923
1924         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1925                                            "/Message/Receive");
1926
1927         /* search for separator */
1928         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1929              cur_item = cur_item->next) {
1930                 if (GTK_BIN(cur_item->data)->child == NULL) {
1931                         cur_item = cur_item->next;
1932                         break;
1933                 }
1934         }
1935
1936         /* destroy all previous menu item */
1937         while (cur_item != NULL) {
1938                 GList *next = cur_item->next;
1939                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1940                 cur_item = next;
1941         }
1942
1943         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1944                 ac_prefs = (PrefsAccount *)cur_ac->data;
1945
1946                 menuitem = gtk_menu_item_new_with_label
1947                         (ac_prefs->account_name ? ac_prefs->account_name
1948                          : _("Untitled"));
1949                 gtk_widget_show(menuitem);
1950                 gtk_menu_append(GTK_MENU(menu), menuitem);
1951                 g_signal_connect(G_OBJECT(menuitem), "activate",
1952                                  G_CALLBACK(account_receive_menu_cb),
1953                                  ac_prefs);
1954         }
1955 }
1956
1957 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1958                                                        GList *account_list)
1959 {
1960         GList *cur_ac, *cur_item;
1961         GtkWidget *menuitem;
1962         PrefsAccount *ac_prefs;
1963         GtkWidget *menu = NULL;
1964
1965         if (mainwin->toolbar->getall_btn == NULL
1966         ||  mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1967                 return;
1968
1969         menu = mainwin->toolbar->getall_combo->menu;
1970
1971         /* destroy all previous menu item */
1972         cur_item = GTK_MENU_SHELL(menu)->children;
1973         while (cur_item != NULL) {
1974                 GList *next = cur_item->next;
1975                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1976                 cur_item = next;
1977         }
1978
1979         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1980                 ac_prefs = (PrefsAccount *)cur_ac->data;
1981
1982                 menuitem = gtk_menu_item_new_with_label
1983                         (ac_prefs->account_name
1984                          ? ac_prefs->account_name : _("Untitled"));
1985                 gtk_widget_show(menuitem);
1986                 gtk_menu_append(GTK_MENU(menu), menuitem);
1987                 g_signal_connect(G_OBJECT(menuitem), "activate",
1988                                  G_CALLBACK(account_receive_menu_cb),
1989                                  ac_prefs);
1990         }
1991 }
1992
1993 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1994                                                        GList *account_list)
1995 {
1996         GList *cur_ac, *cur_item;
1997         GtkWidget *menuitem;
1998         PrefsAccount *ac_prefs;
1999         GtkWidget *menu = NULL;
2000
2001         if (mainwin->toolbar->compose_mail_btn == NULL
2002         ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
2003                 return;
2004
2005         menu = mainwin->toolbar->compose_combo->menu;
2006
2007         /* destroy all previous menu item */
2008         cur_item = GTK_MENU_SHELL(menu)->children;
2009         while (cur_item != NULL) {
2010                 GList *next = cur_item->next;
2011                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2012                 cur_item = next;
2013         }
2014
2015         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2016                 ac_prefs = (PrefsAccount *)cur_ac->data;
2017
2018                 menuitem = gtk_menu_item_new_with_label
2019                         (ac_prefs->account_name
2020                          ? ac_prefs->account_name : _("Untitled"));
2021                 gtk_widget_show(menuitem);
2022                 gtk_menu_append(GTK_MENU(menu), menuitem);
2023                 g_signal_connect(G_OBJECT(menuitem), "activate",
2024                                  G_CALLBACK(account_compose_menu_cb),
2025                                  ac_prefs);
2026         }
2027 }
2028
2029 void main_window_set_account_menu(GList *account_list)
2030 {
2031         GList *cur;
2032         MainWindow *mainwin;
2033
2034         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2035                 mainwin = (MainWindow *)cur->data;
2036                 main_window_set_account_selector_menu(mainwin, account_list);
2037                 main_window_set_account_receive_menu(mainwin, account_list);
2038                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2039                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2040         }
2041         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2042 }
2043
2044 void main_window_set_account_menu_only_toolbar(GList *account_list)
2045 {
2046         GList *cur;
2047         MainWindow *mainwin;
2048
2049         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2050                 mainwin = (MainWindow *)cur->data;
2051                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2052                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2053         }
2054 }
2055
2056 static void main_window_show_cur_account(MainWindow *mainwin)
2057 {
2058         gchar *buf;
2059         gchar *ac_name;
2060
2061         ac_name = g_strdup(cur_account
2062                            ? (cur_account->account_name
2063                               ? cur_account->account_name : _("Untitled"))
2064                            : _("none"));
2065
2066         if (cur_account)
2067                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2068         else
2069                 buf = g_strdup(PROG_VERSION);
2070         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2071         g_free(buf);
2072
2073         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2074         gtk_widget_queue_resize(mainwin->ac_button);
2075
2076         g_free(ac_name);
2077 }
2078
2079 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2080 {
2081         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
2082         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2083         GtkWidget *message_wid = mainwin->messageview->vbox;
2084
2085         if (layout_mode == prefs_common.layout_mode) 
2086                 return;
2087
2088         debug_print("Changing window separation type from %d to %d\n",
2089                     prefs_common.layout_mode, layout_mode);
2090
2091         /* remove widgets from those containers */
2092         gtk_widget_ref(folder_wid);
2093         gtk_widget_ref(summary_wid);
2094         gtk_widget_ref(message_wid);
2095         gtkut_container_remove
2096                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2097         gtkut_container_remove
2098                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2099         gtkut_container_remove
2100                 (GTK_CONTAINER(message_wid->parent), message_wid);
2101
2102         gtk_widget_hide(mainwin->window);
2103         main_window_set_widgets(mainwin, layout_mode);
2104         gtk_widget_show(mainwin->window);
2105
2106         gtk_widget_unref(folder_wid);
2107         gtk_widget_unref(summary_wid);
2108         gtk_widget_unref(message_wid);
2109 }
2110
2111 void mainwindow_reset_paned(GtkPaned *paned)
2112 {
2113                 gint min, max, mid;
2114
2115                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2116                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2117                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2118                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2119
2120 GTK_EVENTS_FLUSH();
2121                 g_object_get (G_OBJECT(paned),
2122                                 "min-position",
2123                                 &min, NULL);
2124                 g_object_get (G_OBJECT(paned),
2125                                 "max-position",
2126                                 &max, NULL);
2127                 mid = (min+max)/2;
2128                 gtk_paned_set_position(GTK_PANED(paned), mid);
2129 }
2130
2131 static void mainwin_paned_show_first(GtkPaned *paned)
2132 {
2133                 gint max;
2134                 g_object_get (G_OBJECT(paned),
2135                                 "max-position",
2136                                 &max, NULL);
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_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2142                 gtk_paned_set_position(GTK_PANED(paned), max);
2143 }
2144
2145 static void mainwin_paned_show_last(GtkPaned *paned)
2146 {
2147                 gint min;
2148                 g_object_get (G_OBJECT(paned),
2149                                 "min-position",
2150                                 &min, NULL);
2151
2152                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2153                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2154                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2155                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2156                 gtk_paned_set_position(GTK_PANED(paned), min);
2157 }
2158
2159 void main_window_toggle_message_view(MainWindow *mainwin)
2160 {
2161         SummaryView *summaryview = mainwin->summaryview;
2162         GtkWidget *ppaned = NULL;
2163         GtkWidget *container = NULL;
2164         
2165         switch (prefs_common.layout_mode) {
2166         case NORMAL_LAYOUT:
2167         case VERTICAL_LAYOUT:
2168         case SMALL_LAYOUT:
2169                 ppaned = mainwin->vpaned;
2170                 container = mainwin->hpaned;
2171                 if (ppaned->parent != NULL) {
2172                         mainwin->messageview->visible = FALSE;
2173                         summaryview->displayed = NULL;
2174                         gtk_widget_ref(ppaned);
2175                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2176                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2177                 } else {
2178                         mainwin->messageview->visible = TRUE;
2179                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2180                         gtk_container_add(GTK_CONTAINER(container), ppaned);
2181                         gtk_widget_unref(ppaned);
2182                 }
2183                 break;
2184         case WIDE_LAYOUT:
2185                 ppaned = mainwin->hpaned;
2186                 container = mainwin->vpaned;
2187                 if (mainwin->messageview->vbox->parent != NULL) {
2188                         mainwin->messageview->visible = FALSE;
2189                         summaryview->displayed = NULL;
2190                         gtk_widget_ref(mainwin->messageview->vbox);
2191                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2192                 } else {
2193                         mainwin->messageview->visible = TRUE;
2194                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2195                         gtk_widget_unref(mainwin->messageview->vbox);
2196                 }
2197                 break;
2198         case WIDE_MSGLIST_LAYOUT:
2199                 g_warning("can't hide messageview in this wide msglist layout");
2200                 break;
2201         }
2202
2203         if (messageview_is_visible(mainwin->messageview))
2204                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2205                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2206         else
2207                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2208                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2209
2210         if (mainwin->messageview->visible == FALSE)
2211                 messageview_clear(mainwin->messageview);
2212
2213         main_window_set_menu_sensitive(mainwin);
2214
2215         prefs_common.msgview_visible = mainwin->messageview->visible;
2216
2217         if (messageview_is_visible(mainwin->messageview)) {
2218                 gtk_widget_queue_resize(mainwin->hpaned);
2219                 gtk_widget_queue_resize(mainwin->vpaned);
2220         }
2221         summary_grab_focus(summaryview);
2222 }
2223
2224 void main_window_get_size(MainWindow *mainwin)
2225 {
2226         GtkAllocation *allocation;
2227
2228         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2229                 debug_print("called after messageview "
2230                             "has been deallocated!\n");
2231                 return;
2232         }
2233
2234         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2235
2236         if (allocation->width > 1 && allocation->height > 1) {
2237                 prefs_common.summaryview_width = allocation->width;
2238
2239                 if (messageview_is_visible(mainwin->messageview))
2240                         prefs_common.summaryview_height = allocation->height;
2241
2242                 prefs_common.mainview_width = allocation->width;
2243         }
2244
2245         allocation = &mainwin->window->allocation;
2246         if (allocation->width > 1 && allocation->height > 1) {
2247                 prefs_common.mainview_height = allocation->height;
2248                 prefs_common.mainwin_width   = allocation->width;
2249                 prefs_common.mainwin_height  = allocation->height;
2250         }
2251
2252         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2253         if (allocation->width > 1 && allocation->height > 1) {
2254                 prefs_common.folderview_width  = allocation->width;
2255                 prefs_common.folderview_height = allocation->height;
2256         }
2257
2258         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2259         if (allocation->width > 1 && allocation->height > 1) {
2260                 prefs_common.msgview_width = allocation->width;
2261                 prefs_common.msgview_height = allocation->height;
2262         }
2263
2264 /*      debug_print("summaryview size: %d x %d\n",
2265                     prefs_common.summaryview_width,
2266                     prefs_common.summaryview_height);
2267         debug_print("folderview size: %d x %d\n",
2268                     prefs_common.folderview_width,
2269                     prefs_common.folderview_height);
2270         debug_print("messageview size: %d x %d\n",
2271                     prefs_common.msgview_width,
2272                     prefs_common.msgview_height); */
2273 }
2274
2275 void main_window_get_position(MainWindow *mainwin)
2276 {
2277         gint x, y;
2278
2279         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2280
2281         prefs_common.mainview_x = x;
2282         prefs_common.mainview_y = y;
2283         prefs_common.mainwin_x = x;
2284         prefs_common.mainwin_y = y;
2285
2286         debug_print("main window position: %d, %d\n", x, y);
2287 }
2288
2289 void main_window_progress_on(MainWindow *mainwin)
2290 {
2291         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2292 }
2293
2294 void main_window_progress_off(MainWindow *mainwin)
2295 {
2296         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2297         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2298 }
2299
2300 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2301 {
2302         gchar buf[32];
2303
2304         g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2305         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2306         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2307                                 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2308 }
2309
2310 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2311 {
2312         if (confirm && procmsg_have_trashed_mails_fast()) {
2313                 if (alertpanel(_("Empty trash"),
2314                                _("Delete all messages in trash folders?"),
2315                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2316                     != G_ALERTALTERNATE)
2317                         return;
2318                 manage_window_focus_in(mainwin->window, NULL, NULL);
2319         }
2320
2321         procmsg_empty_all_trash();
2322
2323         if (mainwin->summaryview->folder_item &&
2324             mainwin->summaryview->folder_item->stype == F_TRASH)
2325                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2326 }
2327
2328 void main_window_add_mailbox(MainWindow *mainwin)
2329 {
2330         gchar *path;
2331         Folder *folder;
2332
2333         path = input_dialog(_("Add mailbox"),
2334                             _("Input the location of mailbox.\n"
2335                               "If an existing mailbox is specified, it will be\n"
2336                               "scanned automatically."),
2337                             "Mail");
2338         if (!path) return;
2339         if (folder_find_from_path(path)) {
2340                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2341                 g_free(path);
2342                 return;
2343         }
2344         folder = folder_new(folder_get_class_from_string("mh"), 
2345                             !strcmp(path, "Mail") ? _("Mailbox") : 
2346                             g_path_get_basename(path), path);
2347         g_free(path);
2348
2349         if (folder->klass->create_tree(folder) < 0) {
2350                 alertpanel_error(_("Creation of the mailbox failed.\n"
2351                                    "Maybe some files already exist, or you don't have the permission to write there."));
2352                 folder_destroy(folder);
2353                 return;
2354         }
2355
2356         folder_add(folder);
2357         folder_set_ui_func(folder, scan_tree_func, mainwin);
2358         folder_scan_tree(folder, TRUE);
2359         folder_set_ui_func(folder, NULL, NULL);
2360 }
2361
2362 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2363 {
2364         SensitiveCond state = 0;
2365         SummarySelection selection;
2366         FolderItem *item = mainwin->summaryview->folder_item;
2367         GList *account_list = account_get_list();
2368         GSList *tmp;
2369         
2370         selection = summary_get_selection_type(mainwin->summaryview);
2371
2372         if (mainwin->lock_count == 0)
2373                 state |= M_UNLOCKED;
2374         if (selection != SUMMARY_NONE)
2375                 state |= M_MSG_EXIST;
2376         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2377                 state |= M_EXEC;
2378                 /*              if (item->folder->type != F_NEWS) */
2379                 state |= M_ALLOW_DELETE;
2380
2381                 if (prefs_common.immediate_exec == 0
2382                     && mainwin->lock_count == 0)
2383                         state |= M_DELAY_EXEC;
2384
2385                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2386                     || selection != SUMMARY_NONE)
2387                         state |= M_HIDE_READ_MSG;
2388         }               
2389         if (mainwin->summaryview->threaded)
2390                 state |= M_THREADED;
2391         else
2392                 state |= M_UNTHREADED;  
2393         if (selection == SUMMARY_SELECTED_SINGLE ||
2394             selection == SUMMARY_SELECTED_MULTIPLE)
2395                 state |= M_TARGET_EXIST;
2396         if (selection == SUMMARY_SELECTED_SINGLE)
2397                 state |= M_SINGLE_TARGET_EXIST;
2398         if (mainwin->summaryview->folder_item &&
2399             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2400                 state |= M_NEWS;
2401         else
2402                 state |= M_NOT_NEWS;
2403         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2404                 state |= M_ACTIONS_EXIST;
2405
2406         tmp = tags_get_list();
2407         if (tmp && g_slist_length(tmp))
2408                 state |= M_TAGS_EXIST;
2409         g_slist_free(tmp);
2410
2411         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2412                 state |= M_HAVE_QUEUED_MAILS;
2413
2414         if (selection == SUMMARY_SELECTED_SINGLE &&
2415             (item &&
2416              (folder_has_parent_of_type(item, F_DRAFT) ||
2417               folder_has_parent_of_type(item, F_OUTBOX) ||
2418               folder_has_parent_of_type(item, F_QUEUE))))
2419                 state |= M_ALLOW_REEDIT;
2420         if (cur_account)
2421                 state |= M_HAVE_ACCOUNT;
2422         
2423         if (any_folder_want_synchronise())
2424                 state |= M_WANT_SYNC;
2425
2426         for ( ; account_list != NULL; account_list = account_list->next) {
2427                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2428                         state |= M_HAVE_NEWS_ACCOUNT;
2429                         break;
2430                 }
2431         }
2432         
2433         if (procmsg_spam_can_learn() &&
2434             (mainwin->summaryview->folder_item &&
2435              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2436              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2437                 state |= M_CAN_LEARN_SPAM;
2438         }
2439
2440         if (inc_is_active())
2441                 state |= M_INC_ACTIVE;
2442         if (imap_cancel_all_enabled())
2443                 state |= M_INC_ACTIVE;
2444
2445         if (mainwin->summaryview->deleted > 0 ||
2446             mainwin->summaryview->moved > 0 ||
2447             mainwin->summaryview->copied > 0)
2448                 state |= M_DELAY_EXEC;
2449
2450         return state;
2451 }
2452
2453
2454
2455 void main_window_set_menu_sensitive(MainWindow *mainwin)
2456 {
2457         GtkItemFactory *ifactory = mainwin->menu_factory;
2458         SensitiveCond state;
2459         gboolean sensitive;
2460         GtkWidget *menu;
2461         GtkWidget *menuitem;
2462         SummaryView *summaryview;
2463         gchar *menu_path;
2464         gint i;
2465         GList *cur_item;
2466
2467         static const struct {
2468                 gchar *const entry;
2469                 SensitiveCond cond;
2470         } entry[] = {
2471                 {"/File/Save as...", M_TARGET_EXIST},
2472                 {"/File/Print..."  , M_TARGET_EXIST},
2473                 {"/File/Synchronise folders", M_WANT_SYNC},
2474                 {"/File/Exit"      , M_UNLOCKED},
2475
2476                 {"/Edit/Select thread"             , M_TARGET_EXIST},
2477                 {"/Edit/Delete thread"             , M_TARGET_EXIST},
2478                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2479
2480                 {"/View/Set displayed columns/in Folder list..."
2481                                                    , M_UNLOCKED}, 
2482                 {"/View/Sort"                      , M_EXEC},
2483                 {"/View/Thread view"               , M_EXEC},
2484                 {"/View/Expand all threads"        , M_MSG_EXIST},
2485                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2486                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2487                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2488                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2489                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2490                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2491                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2492                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2493                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2494                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2495                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2496                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2497                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2498                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2499                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2500
2501                 {"/Message/Receive/Get from current account"
2502                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2503                 {"/Message/Receive/Get from all accounts"
2504                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2505                 {"/Message/Receive/Cancel receiving"
2506                                                  , M_INC_ACTIVE},
2507                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2508                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2509                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2510                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2511                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2512                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2513                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2514                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2515                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2516                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2517                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2518                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2519                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2520                 {"/Message/Mark"                  , M_TARGET_EXIST},
2521                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2522                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2523                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2524                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2525                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2526                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2527                 {"/Message/Color label"           , M_TARGET_EXIST},
2528                 {"/Message/Tags"                  , M_TARGET_EXIST},
2529                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2530
2531                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2532                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2533                 {"/Tools/Harvest addresses/from Messages..."
2534                                                        , M_TARGET_EXIST},
2535                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2536                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2537                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2538                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2539                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2540                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2541                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2542                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2543
2544                 {"/Configuration", M_UNLOCKED},
2545                 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2546                 {"/Configuration/Create new account...", M_UNLOCKED},
2547                 {"/Configuration/Edit accounts...", M_UNLOCKED},
2548
2549                 {NULL, 0}
2550         };
2551
2552         state = main_window_get_current_state(mainwin);
2553
2554         for (i = 0; entry[i].entry != NULL; i++) {
2555                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2556                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2557         }
2558
2559         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2560
2561         /* search for separator */
2562         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2563              cur_item = cur_item->next) {
2564                 if (GTK_BIN(cur_item->data)->child == NULL) {
2565                         cur_item = cur_item->next;
2566                         break;
2567                 }
2568         }
2569
2570         for (; cur_item != NULL; cur_item = cur_item->next) {
2571                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2572                                          (M_UNLOCKED & state) != 0);
2573         }
2574
2575         main_window_menu_callback_block(mainwin);
2576
2577 #define SET_CHECK_MENU_ACTIVE(path, active) \
2578 { \
2579         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2580         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2581 }
2582
2583         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2584                               messageview_is_visible(mainwin->messageview));
2585
2586         summaryview = mainwin->summaryview;
2587         menu_path = "/View/Sort/Don't sort";
2588
2589         switch (summaryview->sort_key) {
2590         case SORT_BY_NUMBER:
2591                 menu_path = "/View/Sort/by number"; break;
2592         case SORT_BY_SIZE:
2593                 menu_path = "/View/Sort/by Size"; break;
2594         case SORT_BY_DATE:
2595                 menu_path = "/View/Sort/by Date"; break;
2596         case SORT_BY_THREAD_DATE:
2597                 menu_path = "/View/Sort/by Thread date"; break;
2598         case SORT_BY_FROM:
2599                 menu_path = "/View/Sort/by From"; break;
2600         case SORT_BY_TO:
2601                 menu_path = "/View/Sort/by To"; break;
2602         case SORT_BY_SUBJECT:
2603                 menu_path = "/View/Sort/by Subject"; break;
2604         case SORT_BY_LABEL:
2605                 menu_path = "/View/Sort/by color label"; break;
2606         case SORT_BY_MARK:
2607                 menu_path = "/View/Sort/by mark"; break;
2608         case SORT_BY_STATUS:
2609                 menu_path = "/View/Sort/by status"; break;
2610         case SORT_BY_MIME:
2611                 menu_path = "/View/Sort/by attachment"; break;
2612         case SORT_BY_SCORE:
2613                 menu_path = "/View/Sort/by score"; break;
2614         case SORT_BY_LOCKED:
2615                 menu_path = "/View/Sort/by locked"; break;
2616         case SORT_BY_TAGS:
2617                 menu_path = "/View/Sort/by tag"; break;
2618         case SORT_BY_NONE:
2619         default:
2620                 menu_path = "/View/Sort/Don't sort"; break;
2621         }
2622         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2623
2624         if (summaryview->sort_type == SORT_ASCENDING) {
2625                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2626         } else {
2627                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2628         }
2629
2630         if (summaryview->sort_key != SORT_BY_NONE) {
2631                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2632                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2633         } else {
2634                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2635                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2636         }
2637
2638         if (mainwin->messageview 
2639         &&  mainwin->messageview->mimeview
2640         &&  mainwin->messageview->mimeview->textview)
2641                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2642                               mainwin->messageview->mimeview->textview->show_all_headers);
2643         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2644         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2645         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2646         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2647         if (prefs_common.hide_quotes == 1)
2648                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2649         if (prefs_common.hide_quotes == 2)
2650                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2651         if (prefs_common.hide_quotes == 3)
2652                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2653
2654 #undef SET_CHECK_MENU_ACTIVE
2655
2656         main_window_menu_callback_unblock(mainwin);
2657 }
2658
2659 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2660 {
2661         GtkItemFactory *ifactory;
2662         gint is_menu = 0;
2663         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2664         
2665         if (msginfo) 
2666                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2667         if (is_menu)
2668                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2669                                 (ifactory,"/Message/Mailing-List"), TRUE);
2670         else
2671                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2672                                 (ifactory,"/Message/Mailing-List"), FALSE);
2673 }
2674
2675 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2676 {
2677         gint menu_nb = 0;
2678         GtkWidget *menuitem;
2679         
2680         if (!msginfo || !msginfo->extradata) {
2681                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2682                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2683                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2684                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2685                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2686                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2687                 return 0;
2688         }
2689                 
2690         /* Mailing list post */
2691         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2692                 g_free(msginfo->extradata->list_post);
2693                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2694         }
2695         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2696                 
2697         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2698  
2699         /* Mailing list help */
2700         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2701         
2702         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2703
2704         /* Mailing list subscribe */
2705         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2706         
2707         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2708                 
2709         /* Mailing list unsubscribe */
2710         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2711         
2712         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2713         
2714         /* Mailing list view archive */
2715         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2716         
2717         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2718         
2719         /* Mailing list contact owner */
2720         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2721         
2722         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2723         
2724         return menu_nb;
2725 }
2726
2727 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2728 {
2729         GtkWidget *item, *menu;
2730         const gchar *url_pt ;
2731         gchar url_decoded[BUFFSIZE];
2732         GList *amenu, *alist;
2733         gint menu_nb = 0;
2734         
2735         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2736         
2737         /* First delete old submenu */
2738         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2739         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2740                 alist = amenu->next;
2741                 item = GTK_WIDGET (amenu->data);
2742                 gtk_widget_destroy (item);
2743                 amenu = alist;
2744         }
2745         if (list_header) {
2746                 for (url_pt = list_header; url_pt && *url_pt;) {
2747                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2748                         item = NULL;
2749                         if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2750                                 item = gtk_menu_item_new_with_label ((url_decoded));
2751                                 g_signal_connect(G_OBJECT(item), "activate",
2752                                                  G_CALLBACK(mailing_list_compose),
2753                                                  NULL);
2754                         }
2755                         else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2756                                  !g_strncasecmp (url_decoded, "https:",6)) {
2757
2758                                 item = gtk_menu_item_new_with_label ((url_decoded));
2759                                 g_signal_connect(G_OBJECT(item), "activate",
2760                                                  G_CALLBACK(mailing_list_open_uri),
2761                                                  NULL);
2762                         } 
2763                         if (item) {
2764                                 gtk_menu_append (GTK_MENU(menu), item);
2765                                 gtk_widget_show (item);
2766                                 menu_nb++;
2767                         }
2768                 }
2769         }
2770         if (menu_nb)
2771                 gtk_widget_set_sensitive (menuitem, TRUE);
2772         else
2773                 gtk_widget_set_sensitive (menuitem, FALSE);
2774                 
2775
2776         return menu_nb;
2777 }
2778
2779 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2780 {
2781         gchar tmp[BUFFSIZE];
2782         const gchar *buf;
2783         gint i = 0;
2784         buf = *buffer;
2785         gboolean with_plus = TRUE;
2786
2787         if (buf == 0x00) {
2788                 *url_decoded = '\0';
2789                 *buffer = NULL;
2790                 return;
2791         }
2792         /* Ignore spaces, comments  and tabs () */
2793         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2794                 if (*buf == '(')
2795                         for (;*buf != ')' && *buf != 0x00; buf++);
2796         
2797         /* First non space and non comment must be a < */
2798         if (*buf =='<' ) {
2799                 buf++;
2800                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2801                         with_plus = FALSE;
2802                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2803                 buf++;
2804         }
2805         else  {
2806                 *buffer = NULL;
2807                 *url_decoded = '\0';
2808                 return;
2809         }
2810         
2811         tmp[i]       = 0x00;
2812         *url_decoded = '\0';
2813         *buffer = NULL;
2814         
2815         if (i == maxlen) {
2816                 return;
2817         }
2818         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2819
2820         /* Prepare the work for the next url in the list */
2821         /* after the closing bracket >, ignore space, comments and tabs */
2822         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2823                 if (*buf == '(')
2824                         for (;*buf != ')' && *buf != 0x00; buf++);
2825                         
2826         if (!buf || !*buf) {
2827                 *buffer = NULL;
2828                 return;
2829         }
2830
2831         /* now first non space, non comment must be a comma */
2832         if (*buf != ',')
2833                 for (;*buf != 0x00; buf++);
2834         else
2835                 buf++;
2836         *buffer = buf;
2837 }
2838         
2839 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2840 {
2841         gchar *mailto;
2842
2843         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2844         compose_new(NULL, mailto+7, NULL);
2845 }
2846  
2847  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2848 {
2849  
2850         gchar *mailto;
2851  
2852         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2853         open_uri (mailto, prefs_common.uri_cmd);
2854
2855         
2856 void main_window_popup(MainWindow *mainwin)
2857 {
2858         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2859                 main_window_show(mainwin);
2860
2861         gtkut_window_popup(mainwin->window);
2862         if (prefs_common.layout_mode == SMALL_LAYOUT) {
2863                 if (mainwin->in_folder) {
2864                         mainwindow_enter_folder(mainwin);
2865                 } else {
2866                         mainwindow_exit_folder(mainwin);
2867                 }
2868         }
2869 }
2870
2871 void main_window_show(MainWindow *mainwin)
2872 {
2873         gtk_widget_show(mainwin->window);
2874         gtk_widget_show(mainwin->vbox_body);
2875
2876         gtk_widget_set_uposition(mainwin->window,
2877                                  prefs_common.mainwin_x,
2878                                  prefs_common.mainwin_y);
2879
2880         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2881                              prefs_common.folderview_width,
2882                              prefs_common.folderview_height);
2883         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2884                              prefs_common.summaryview_width,
2885                              prefs_common.summaryview_height);
2886         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2887                              prefs_common.msgview_width,
2888                              prefs_common.msgview_height);
2889 }
2890
2891 void main_window_hide(MainWindow *mainwin)
2892 {
2893         main_window_get_size(mainwin);
2894         main_window_get_position(mainwin);
2895
2896         gtk_widget_hide(mainwin->window);
2897         gtk_widget_hide(mainwin->vbox_body);
2898 }
2899
2900 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2901 {
2902         GtkWidget *folderwin = NULL;
2903         GtkWidget *messagewin = NULL;
2904         GtkWidget *hpaned;
2905         GtkWidget *vpaned;
2906         GtkWidget *vbox_body = mainwin->vbox_body;
2907         GtkItemFactory *ifactory = mainwin->menu_factory;
2908         GtkWidget *menuitem;
2909         gboolean first_set = (mainwin->hpaned == NULL);
2910         debug_print("Setting widgets... ");
2911
2912         if (layout_mode == SMALL_LAYOUT && first_set) {
2913                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2914                                     prefs_common.folderview_width,
2915                                     prefs_common.folderview_height);
2916                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2917                                     0,0);
2918                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2919                                     0,0);
2920         } else {
2921                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2922                                     prefs_common.folderview_width,
2923                                     prefs_common.folderview_height);
2924                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2925                                     prefs_common.summaryview_width,
2926                                     prefs_common.summaryview_height);
2927                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2928                                     prefs_common.msgview_width,
2929                                     prefs_common.msgview_height);
2930         }
2931
2932         mainwin->messageview->statusbar = mainwin->statusbar;
2933         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2934
2935         /* clean top-most container */
2936         if (mainwin->hpaned) {
2937                 if (mainwin->hpaned->parent == mainwin->vpaned)
2938                         gtk_widget_destroy(mainwin->vpaned);
2939                 else
2940                         gtk_widget_destroy(mainwin->hpaned);
2941         }
2942
2943         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
2944                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
2945         switch (layout_mode) {
2946         case VERTICAL_LAYOUT:
2947         case NORMAL_LAYOUT:
2948         case SMALL_LAYOUT:
2949                 hpaned = gtk_hpaned_new();
2950                 if (layout_mode == VERTICAL_LAYOUT)
2951                         vpaned = gtk_hpaned_new();
2952                 else
2953                         vpaned = gtk_vpaned_new();
2954                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2955                 gtk_paned_add1(GTK_PANED(hpaned),
2956                                GTK_WIDGET_PTR(mainwin->folderview));
2957                 gtk_widget_show(hpaned);
2958                 gtk_widget_queue_resize(hpaned);
2959
2960                 if (messageview_is_visible(mainwin->messageview)) {
2961                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2962                         gtk_paned_add1(GTK_PANED(vpaned),
2963                                        GTK_WIDGET_PTR(mainwin->summaryview));
2964                 } else {
2965                         gtk_paned_add2(GTK_PANED(hpaned),
2966                                        GTK_WIDGET_PTR(mainwin->summaryview));
2967                         gtk_widget_ref(vpaned);
2968                 }
2969                 gtk_paned_add2(GTK_PANED(vpaned),
2970                                GTK_WIDGET_PTR(mainwin->messageview));
2971                 gtk_widget_show(vpaned);
2972                 if (layout_mode == SMALL_LAYOUT && first_set) {
2973                         mainwin_paned_show_first(GTK_PANED(hpaned));
2974                 }
2975                 gtk_widget_queue_resize(vpaned);
2976                 break;
2977         case WIDE_LAYOUT:
2978                 vpaned = gtk_vpaned_new();
2979                 hpaned = gtk_hpaned_new();
2980                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2981                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
2982
2983                 gtk_paned_add1(GTK_PANED(hpaned),
2984                                GTK_WIDGET_PTR(mainwin->folderview));
2985                 gtk_paned_add2(GTK_PANED(hpaned),
2986                                GTK_WIDGET_PTR(mainwin->summaryview));
2987
2988                 gtk_widget_show(hpaned);
2989                 gtk_widget_queue_resize(hpaned);
2990
2991                 if (messageview_is_visible(mainwin->messageview)) {
2992                         gtk_paned_add2(GTK_PANED(vpaned),
2993                                GTK_WIDGET_PTR(mainwin->messageview));   
2994                 } else {
2995                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2996                 }
2997                 gtk_widget_show(vpaned);
2998                 gtk_widget_queue_resize(vpaned);
2999                 break;
3000         case WIDE_MSGLIST_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
3005                 gtk_paned_add1(GTK_PANED(vpaned),
3006                                GTK_WIDGET_PTR(mainwin->summaryview));
3007                 gtk_paned_add1(GTK_PANED(hpaned),
3008                                GTK_WIDGET_PTR(mainwin->folderview));
3009
3010                 gtk_widget_show(hpaned);
3011                 gtk_widget_queue_resize(hpaned);
3012
3013                 if (messageview_is_visible(mainwin->messageview)) {
3014                         gtk_paned_add2(GTK_PANED(hpaned),
3015                                GTK_WIDGET_PTR(mainwin->messageview));   
3016                 } else {
3017                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3018                 }
3019                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3020
3021                 gtk_widget_show(vpaned);
3022                 gtk_widget_queue_resize(vpaned);
3023                 break;
3024         default:
3025                 g_warning("Unknown layout");
3026                 return;
3027         }
3028
3029         mainwin->hpaned = hpaned;
3030         mainwin->vpaned = vpaned;
3031
3032         if (layout_mode == SMALL_LAYOUT) {
3033                 if (mainwin->messageview->visible)
3034                         main_window_toggle_message_view(mainwin);
3035         } 
3036
3037         if (layout_mode == SMALL_LAYOUT && first_set) {
3038                 gtk_widget_realize(mainwin->window);
3039                 gtk_widget_realize(mainwin->folderview->ctree);
3040                 gtk_widget_realize(mainwin->summaryview->hbox);
3041                 gtk_widget_realize(mainwin->summaryview->hbox_l);
3042                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3043                                     prefs_common.folderview_width,
3044                                     prefs_common.folderview_height);
3045                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3046                                     0,0);
3047                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3048                                     0,0);
3049                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3050                                 prefs_common.mainwin_width,
3051                                 prefs_common.mainwin_height);
3052                 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3053         } 
3054         /* remove headerview if not in prefs */
3055         headerview_set_visibility(mainwin->messageview->headerview,
3056                                   prefs_common.display_header_pane);
3057
3058         if (messageview_is_visible(mainwin->messageview))
3059                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3060                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3061         else
3062                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3063                               GTK_ARROW_UP, GTK_SHADOW_OUT);
3064
3065         gtk_window_move(GTK_WINDOW(mainwin->window),
3066                         prefs_common.mainwin_x,
3067                         prefs_common.mainwin_y);
3068
3069         gtk_widget_queue_resize(vbox_body);
3070         gtk_widget_queue_resize(mainwin->vbox);
3071         gtk_widget_queue_resize(mainwin->window);
3072         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3073          * and mimeview icon list/ctree lose track of their visibility states */
3074         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
3075                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3076         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
3077                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3078         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
3079                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3080         else 
3081                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3082
3083         prefs_common.layout_mode = layout_mode;
3084
3085         menuitem = gtk_item_factory_get_item
3086                 (ifactory, "/View/Show or hide/Message view");
3087         gtk_check_menu_item_set_active
3088                 (GTK_CHECK_MENU_ITEM(menuitem),
3089                  messageview_is_visible(mainwin->messageview));
3090
3091 #define SET_CHECK_MENU_ACTIVE(path, active) \
3092 { \
3093         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3094         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3095 }
3096
3097         switch (prefs_common.layout_mode) {
3098         case NORMAL_LAYOUT:
3099                 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
3100                 break;
3101         case VERTICAL_LAYOUT:
3102                 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
3103                 break;
3104         case WIDE_LAYOUT:
3105                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
3106                 break;
3107         case WIDE_MSGLIST_LAYOUT:
3108                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
3109                 break;
3110         case SMALL_LAYOUT:
3111                 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
3112                 break;
3113         }
3114 #undef SET_CHECK_MENU_ACTIVE
3115
3116         if (folderwin) {
3117                 g_signal_connect
3118                         (G_OBJECT(folderwin), "size_allocate",
3119                          G_CALLBACK(folder_window_size_allocate_cb),
3120                          mainwin);
3121         }
3122         if (messagewin) {
3123                 g_signal_connect
3124                         (G_OBJECT(messagewin), "size_allocate",
3125                          G_CALLBACK(message_window_size_allocate_cb),
3126                          mainwin);
3127         }
3128
3129         debug_print("done.\n");
3130 }
3131
3132 void main_window_destroy_all(void)
3133 {
3134         while (mainwin_list != NULL) {
3135                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3136                 
3137                 /* free toolbar stuff */
3138                 toolbar_clear_list(TOOLBAR_MAIN);
3139                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3140                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3141
3142                 mainwin->folderview->mainwin = NULL;
3143                 mainwin->summaryview->mainwin = NULL;
3144                 mainwin->messageview->mainwin = NULL;
3145
3146                 g_free(mainwin->toolbar);
3147                 g_free(mainwin);
3148                 
3149                 mainwin_list = g_list_remove(mainwin_list, mainwin);
3150         }
3151         g_list_free(mainwin_list);
3152         mainwin_list = NULL;
3153 }
3154
3155 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3156                                    gpointer data)
3157 {
3158         gtk_widget_set_size_request(child, 1, -1);
3159 }
3160
3161 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3162                                    gpointer data)
3163 {
3164         gtk_widget_set_size_request(child, -1, -1);
3165 }
3166
3167 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3168                                     gpointer data)
3169 {
3170         MainWindow *mainwin = (MainWindow *)data;
3171
3172         if (!event) return FALSE;
3173
3174         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3175         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
3176                           widget);
3177
3178         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3179                        menu_button_position, widget,
3180                        event->button, event->time);
3181
3182         return TRUE;
3183 }
3184
3185 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3186                                  gpointer data)
3187 {
3188         MainWindow *mainwin = (MainWindow *)data;
3189         gboolean close_allowed = TRUE;
3190
3191         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3192
3193         if (close_allowed && mainwin->lock_count == 0)
3194                 app_exit_cb(data, 0, widget);
3195
3196         return TRUE;
3197 }
3198
3199 static void main_window_size_allocate_cb(GtkWidget *widget,
3200                                          GtkAllocation *allocation,
3201                                          gpointer data)
3202 {
3203         MainWindow *mainwin = (MainWindow *)data;
3204         main_window_get_size(mainwin);
3205 }
3206
3207 static void folder_window_size_allocate_cb(GtkWidget *widget,
3208                                            GtkAllocation *allocation,
3209                                            gpointer data)
3210 {
3211         MainWindow *mainwin = (MainWindow *)data;
3212
3213         main_window_get_size(mainwin);
3214 }
3215
3216 static void message_window_size_allocate_cb(GtkWidget *widget,
3217                                             GtkAllocation *allocation,
3218                                             gpointer data)
3219 {
3220         MainWindow *mainwin = (MainWindow *)data;
3221
3222         main_window_get_size(mainwin);
3223 }
3224
3225 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3226                            GtkWidget *widget)
3227 {
3228         main_window_add_mailbox(mainwin);
3229 }
3230
3231 static void update_folderview_cb(MainWindow *mainwin, guint action,
3232                                  GtkWidget *widget)
3233 {
3234         summary_show(mainwin->summaryview, NULL);
3235         folderview_check_new_all();
3236 }
3237
3238 static void foldersort_cb(MainWindow *mainwin, guint action,
3239                            GtkWidget *widget)
3240 {
3241         foldersort_open();
3242 }
3243
3244 static void import_mbox_cb(MainWindow *mainwin, guint action,
3245                            GtkWidget *widget)
3246 {
3247         /* only notify if import has failed */
3248         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3249                 alertpanel_error(_("Mbox import has failed."));
3250         }
3251 }
3252
3253 static void export_mbox_cb(MainWindow *mainwin, guint action,
3254                            GtkWidget *widget)
3255 {
3256         /* only notify if export has failed */
3257         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3258                 alertpanel_error(_("Export to mbox has failed."));
3259         }
3260 }
3261
3262 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3263                                 GtkWidget *widget)
3264 {
3265         /* only notify if export has failed */
3266         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3267                 alertpanel_error(_("Export to mbox has failed."));
3268         }
3269 }
3270
3271 static void empty_trash_cb(MainWindow *mainwin, guint action,
3272                            GtkWidget *widget)
3273 {
3274         main_window_empty_trash(mainwin, TRUE);
3275 }
3276
3277 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3278 {
3279         summary_save_as(mainwin->summaryview);
3280 }
3281
3282 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3283 {
3284         summary_print(mainwin->summaryview);
3285 }
3286
3287 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3288 {
3289         if (prefs_common.confirm_on_exit) {
3290                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3291                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
3292                     != G_ALERTALTERNATE)
3293                         return;
3294                 manage_window_focus_in(mainwin->window, NULL, NULL);
3295         }
3296
3297         app_will_exit(widget, mainwin);
3298 }
3299
3300 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3301 {
3302         if (action == 1)
3303                 summary_search(mainwin->summaryview);
3304         else
3305                 message_search(mainwin->messageview);
3306 }
3307
3308 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3309 {
3310         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3311 }
3312
3313 static void toggle_message_cb(MainWindow *mainwin, guint action,
3314                               GtkWidget *widget)
3315 {
3316         gboolean active;
3317
3318         active = GTK_CHECK_MENU_ITEM(widget)->active;
3319
3320         if (active != messageview_is_visible(mainwin->messageview))
3321                 summary_toggle_view(mainwin->summaryview);
3322 }
3323
3324 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3325                               GtkWidget *widget)
3326 {
3327         toolbar_toggle(action, mainwin);
3328 }
3329
3330 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3331                           GtkWidget *widget)
3332 {
3333         MessageView *msgview = (MessageView*)mainwin->messageview;
3334         GSList *msginfo_list = NULL;
3335
3336         g_return_if_fail(msgview != NULL);
3337
3338         msginfo_list = summary_get_selection(mainwin->summaryview);
3339         g_return_if_fail(msginfo_list != NULL);
3340         compose_reply_from_messageview(msgview, msginfo_list, action);
3341         g_slist_free(msginfo_list);
3342 }
3343
3344
3345 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3346                                 GtkWidget *widget)
3347 {
3348         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3349                 gtk_widget_show(mainwin->hbox_stat);
3350                 prefs_common.show_statusbar = TRUE;
3351         } else {
3352                 gtk_widget_hide(mainwin->hbox_stat);
3353                 prefs_common.show_statusbar = FALSE;
3354         }
3355 }
3356
3357 static void set_layout_cb(MainWindow *mainwin, guint action,
3358                                GtkWidget *widget)
3359 {
3360         LayoutType layout_mode = action;
3361         LayoutType old_layout_mode = prefs_common.layout_mode;
3362         if (mainwin->menu_lock_count) {
3363                 return;
3364         }
3365         if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3366                 return;
3367         }
3368         
3369         if (layout_mode == prefs_common.layout_mode) {
3370                 return;
3371         }
3372         
3373         if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3374                 main_window_toggle_message_view(mainwin);
3375         else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3376                 main_window_toggle_message_view(mainwin);
3377
3378         main_window_separation_change(mainwin, layout_mode);
3379         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3380         if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3381                 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3382         }
3383         if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3384                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3385                 mainwindow_exit_folder(mainwin);
3386         }
3387         summary_relayout(mainwin->summaryview); 
3388         summary_update_unread(mainwin->summaryview, NULL);
3389 }
3390
3391 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3392                                         gboolean ask_sync)
3393 {
3394         offline_ask_sync = ask_sync;
3395         if (offline)
3396                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3397         else
3398                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3399         offline_ask_sync = TRUE;
3400 }
3401
3402 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3403 {
3404         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3405 }
3406
3407 static gboolean any_folder_want_synchronise(void)
3408 {
3409         GList *folderlist = folder_get_list();
3410
3411         /* see if there are synchronised folders */
3412         for (; folderlist; folderlist = folderlist->next) {
3413                 Folder *folder = (Folder *)folderlist->data;
3414                 if (folder_want_synchronise(folder)) {
3415                         return TRUE;
3416                 }
3417         }
3418         
3419         return FALSE;
3420 }
3421
3422 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3423 {
3424         
3425         if (!any_folder_want_synchronise())
3426                 return;
3427
3428         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3429                         _("Do you want to synchronise your folders now?"),
3430                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3431                 return;
3432         
3433         if (offline_ask_sync)
3434                 folder_synchronise(NULL);
3435 }
3436
3437 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3438 {
3439         MainWindow *mainwin;
3440         GtkItemFactory *ifactory;
3441         GtkCheckMenuItem *menuitem;
3442
3443         mainwin = (MainWindow *) data;
3444         
3445         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3446         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3447         
3448         g_return_if_fail(mainwin != NULL);
3449         g_return_if_fail(menuitem != NULL);
3450         
3451         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3452                 gtk_widget_hide (mainwin->online_switch);
3453                 gtk_widget_show (mainwin->offline_switch);
3454                 menuitem->active = TRUE;
3455                 inc_autocheck_timer_remove();
3456                         
3457                 /* go offline */
3458                 if (prefs_common.work_offline)
3459                         return;
3460                 mainwindow_check_synchronise(mainwin, TRUE);
3461                 prefs_common.work_offline = TRUE;
3462                 imap_disconnect_all();
3463                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3464         } else {
3465                 /*go online */
3466                 if (!prefs_common.work_offline)
3467                         return;
3468                 gtk_widget_hide (mainwin->offline_switch);
3469                 gtk_widget_show (mainwin->online_switch);
3470                 menuitem->active = FALSE;
3471                 prefs_common.work_offline = FALSE;
3472                 inc_autocheck_timer_set();
3473                 refresh_resolvers();
3474                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3475         }
3476 }
3477
3478 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3479                                 GtkWidget *widget)
3480 {
3481         addressbook_open(NULL);
3482 }
3483
3484 static void log_window_show_cb(MainWindow *mainwin, guint action,
3485                                GtkWidget *widget)
3486 {
3487         log_window_show(mainwin->logwin);
3488 }
3489
3490 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3491                                GtkWidget *widget)
3492 {
3493         log_window_show(mainwin->filtering_debugwin);
3494 }
3495
3496 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3497 {
3498         inc_cancel_all();
3499         imap_cancel_all();
3500 }
3501
3502 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3503 {
3504         summary_move_to(mainwin->summaryview);
3505 }
3506
3507 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3508 {
3509         summary_copy_to(mainwin->summaryview);
3510 }
3511
3512 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3513 {
3514         summary_delete(mainwin->summaryview);
3515 }
3516
3517 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3518 {
3519         summary_delete_trash(mainwin->summaryview);
3520 }
3521
3522 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3523 {
3524         summary_cancel(mainwin->summaryview);
3525 }
3526
3527 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3528 {
3529         summary_open_msg(mainwin->summaryview);
3530 }
3531
3532 static void view_source_cb(MainWindow *mainwin, guint action,
3533                            GtkWidget *widget)
3534 {
3535         summary_view_source(mainwin->summaryview);
3536 }
3537
3538 static void show_all_header_cb(MainWindow *mainwin, guint action,
3539                                GtkWidget *widget)
3540 {
3541         if (mainwin->menu_lock_count) return;
3542         mainwin->summaryview->messageview->all_headers = 
3543                         GTK_CHECK_MENU_ITEM(widget)->active;
3544         summary_display_msg_selected(mainwin->summaryview,
3545                                      GTK_CHECK_MENU_ITEM(widget)->active);
3546 }
3547
3548 #define SET_CHECK_MENU_ACTIVE(path, active) \
3549 { \
3550         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3551         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3552 }
3553
3554 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3555                                GtkWidget *widget)
3556 {
3557         GtkWidget *menuitem;
3558         GtkItemFactory *ifactory = mainwin->menu_factory;
3559
3560         if (mainwin->menu_lock_count) return;
3561
3562         prefs_common.hide_quotes = 
3563                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3564
3565         mainwin->menu_lock_count++;
3566         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3567         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3568         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3569         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3570         mainwin->menu_lock_count--;
3571
3572         summary_redisplay_msg(mainwin->summaryview);
3573 }
3574
3575 #undef SET_CHECK_MENU_ACTIVE
3576 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3577 {
3578         summary_mark(mainwin->summaryview);
3579 }
3580
3581 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3582 {
3583         summary_unmark(mainwin->summaryview);
3584 }
3585
3586 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3587                               GtkWidget *widget)
3588 {
3589         summary_mark_as_unread(mainwin->summaryview);
3590 }
3591
3592 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3593                             GtkWidget *widget)
3594 {
3595         summary_mark_as_read(mainwin->summaryview);
3596 }
3597
3598 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3599                              GtkWidget *widget)
3600 {
3601         summary_mark_all_read(mainwin->summaryview);
3602 }
3603
3604 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3605                              GtkWidget *widget)
3606 {
3607         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3608 }
3609
3610 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3611                             GtkWidget *widget)
3612 {
3613         summary_ignore_thread(mainwin->summaryview);
3614 }
3615
3616 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3617                             GtkWidget *widget)
3618 {
3619         summary_unignore_thread(mainwin->summaryview);
3620 }
3621
3622 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3623                             GtkWidget *widget)
3624 {
3625         summary_msgs_lock(mainwin->summaryview);
3626 }
3627
3628 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3629                             GtkWidget *widget)
3630 {
3631         summary_msgs_unlock(mainwin->summaryview);
3632 }
3633
3634
3635 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3636 {
3637         summary_reedit(mainwin->summaryview);
3638 }
3639
3640 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3641 {
3642         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3643                 summary_display_msg_selected(mainwin->summaryview, 
3644                         mainwin->messageview->mimeview->textview->show_all_headers);
3645         }
3646         messageview_list_urls(mainwin->messageview);
3647 }
3648
3649 static void add_address_cb(MainWindow *mainwin, guint action,
3650                            GtkWidget *widget)
3651 {
3652         summary_add_address(mainwin->summaryview);
3653 }
3654
3655 static void set_charset_cb(MainWindow *mainwin, guint action,
3656                            GtkWidget *widget)
3657 {
3658         const gchar *str;
3659
3660         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3661                 str = conv_get_charset_str((CharSet)action);
3662                 
3663                 g_free(mainwin->messageview->forced_charset);
3664                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3665                 procmime_force_charset(str);
3666                 
3667                 summary_redisplay_msg(mainwin->summaryview);
3668                 
3669                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3670         }
3671 }
3672
3673 static void set_decode_cb(MainWindow *mainwin, guint action,
3674                            GtkWidget *widget)
3675 {
3676         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3677                 mainwin->messageview->forced_encoding = (EncodingType)action;
3678                 
3679                 summary_redisplay_msg(mainwin->summaryview);
3680                 
3681                 debug_print("forced encoding: %d\n", action);
3682         }
3683 }
3684
3685 static void hide_read_messages (MainWindow *mainwin, guint action,
3686                                 GtkWidget *widget)
3687 {
3688         if (!mainwin->summaryview->folder_item
3689             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3690                 return;
3691         summary_toggle_show_read_messages(mainwin->summaryview);
3692 }
3693
3694 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3695 {
3696         gboolean threaded = FALSE;
3697         if (mainwin->menu_lock_count) return;
3698         if (!mainwin->summaryview->folder_item) return;
3699
3700         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3701
3702         mainwin->summaryview->folder_item->threaded = threaded; 
3703
3704         mainwin->summaryview->threaded = threaded;
3705
3706         summary_show(mainwin->summaryview, 
3707                         mainwin->summaryview->folder_item);
3708 }
3709
3710 static void expand_threads_cb(MainWindow *mainwin, guint action,
3711                               GtkWidget *widget)
3712 {
3713         summary_expand_threads(mainwin->summaryview);
3714 }
3715
3716 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3717                                 GtkWidget *widget)
3718 {
3719         summary_collapse_threads(mainwin->summaryview);
3720 }
3721
3722 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3723                                 GtkWidget *widget)
3724 {
3725         prefs_summary_column_open();
3726 }
3727
3728 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3729                                 GtkWidget *widget)
3730 {
3731         prefs_folder_column_open();
3732 }
3733
3734 static void sort_summary_cb(MainWindow *mainwin, guint action,
3735                             GtkWidget *widget)
3736 {
3737         FolderItem *item = mainwin->summaryview->folder_item;
3738         GtkWidget *menuitem;
3739
3740         if (mainwin->menu_lock_count) return;
3741
3742         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3743                 menuitem = gtk_item_factory_get_item
3744                         (mainwin->menu_factory, "/View/Sort/Ascending");
3745                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3746                              GTK_CHECK_MENU_ITEM(menuitem)->active
3747                              ? SORT_ASCENDING : SORT_DESCENDING);
3748                 item->sort_key = action;
3749         }
3750 }
3751
3752 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3753                                  GtkWidget *widget)
3754 {
3755         FolderItem *item = mainwin->summaryview->folder_item;
3756
3757         if (mainwin->menu_lock_count) return;
3758
3759         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3760                 summary_sort(mainwin->summaryview,
3761                              item->sort_key, (FolderSortType)action);
3762 }
3763
3764 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3765                                   GtkWidget *widget)
3766 {
3767         summary_attract_by_subject(mainwin->summaryview);
3768 }
3769
3770 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3771                                  GtkWidget *widget)
3772 {
3773         FolderItem *item;
3774
3775         item = folderview_get_selected_item(mainwin->folderview);
3776         if (item) {
3777                 main_window_cursor_wait(mainwin);
3778                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3779
3780                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3781                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3782
3783                 STATUSBAR_POP(mainwin);
3784                 main_window_cursor_normal(mainwin);
3785         }
3786 }
3787
3788 struct DelDupsData
3789 {
3790         guint   dups;
3791         guint   folders;
3792 };
3793
3794 static void deldup_all(FolderItem *item, gpointer _data)
3795 {
3796         struct DelDupsData *data = _data;
3797         gint result;
3798         
3799         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3800         if (result >= 0) {
3801                 data->dups += result;
3802                 data->folders += 1;
3803         }
3804 }
3805
3806 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3807                                  GtkWidget *widget)
3808 {
3809         struct DelDupsData data = {0, 0};
3810
3811         main_window_cursor_wait(mainwin);
3812         folder_func_to_all_folders(deldup_all, &data);
3813         main_window_cursor_normal(mainwin);
3814         
3815         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3816                                    "Deleted %d duplicate messages in %d folders.\n",
3817                                    data.dups),
3818                           data.dups, data.folders);
3819 }
3820
3821 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3822 {
3823         summary_filter(mainwin->summaryview, (gboolean)action);
3824 }
3825
3826 static void execute_summary_cb(MainWindow *mainwin, guint action,
3827                                GtkWidget *widget)
3828 {
3829         summary_execute(mainwin->summaryview);
3830 }
3831
3832 static void update_summary_cb(MainWindow *mainwin, guint action,
3833                               GtkWidget *widget)
3834 {
3835         FolderItem *fitem;
3836         FolderView *folderview = mainwin->folderview;
3837
3838         if (!mainwin->summaryview->folder_item) return;
3839         if (!folderview->opened) return;
3840
3841         folder_update_op_count();
3842
3843         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3844                                             folderview->opened);
3845         if (!fitem) return;
3846
3847         folder_item_scan(fitem);
3848         summary_show(mainwin->summaryview, fitem);
3849 }
3850
3851 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3852 {
3853         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3854 }
3855
3856 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3857 {
3858         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3859 }
3860
3861 static void prev_unread_cb(MainWindow *mainwin, guint action,
3862                            GtkWidget *widget)
3863 {
3864         summary_select_prev_unread(mainwin->summaryview);
3865 }
3866
3867 static void next_unread_cb(MainWindow *mainwin, guint action,
3868                            GtkWidget *widget)
3869 {
3870         summary_select_next_unread(mainwin->summaryview);
3871 }
3872
3873 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3874 {
3875         summary_select_prev_new(mainwin->summaryview);
3876 }
3877
3878 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3879 {
3880         summary_select_next_new(mainwin->summaryview);
3881 }
3882
3883 static void prev_marked_cb(MainWindow *mainwin, guint action,
3884                            GtkWidget *widget)
3885 {
3886         summary_select_prev_marked(mainwin->summaryview);
3887 }
3888
3889 static void next_marked_cb(MainWindow *mainwin, guint action,
3890                            GtkWidget *widget)
3891 {
3892         summary_select_next_marked(mainwin->summaryview);
3893 }
3894
3895 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3896                             GtkWidget *widget)
3897 {
3898         summary_select_prev_labeled(mainwin->summaryview);
3899 }
3900
3901 static void next_labeled_cb(MainWindow *mainwin, guint action,
3902                             GtkWidget *widget)
3903 {
3904         summary_select_next_labeled(mainwin->summaryview);
3905 }
3906
3907 static void last_read_cb(MainWindow *mainwin, guint action,
3908                             GtkWidget *widget)
3909 {
3910         summary_select_last_read(mainwin->summaryview);
3911 }
3912
3913 static void parent_cb(MainWindow *mainwin, guint action,
3914                             GtkWidget *widget)
3915 {
3916         summary_select_parent(mainwin->summaryview);
3917 }
3918
3919 static void goto_folder_cb(MainWindow *mainwin, guint action,
3920                            GtkWidget *widget)
3921 {
3922         FolderItem *to_folder;
3923
3924         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3925
3926         if (to_folder)
3927                 folderview_select(mainwin->folderview, to_folder);
3928 }
3929
3930 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3931                            GtkWidget *widget)
3932 {
3933         folderview_select_next_unread(mainwin->folderview, FALSE);
3934 }
3935
3936 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3937 {
3938         messageview_copy_clipboard(mainwin->messageview);
3939 }
3940
3941 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3942 {
3943         MessageView *msgview = mainwin->messageview;
3944
3945         if (messageview_is_visible(msgview) &&
3946                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3947                 messageview_select_all(mainwin->messageview);
3948         else
3949                 summary_select_all(mainwin->summaryview);
3950 }
3951
3952 static void select_thread_cb(MainWindow *mainwin, guint action,
3953                              GtkWidget *widget)
3954 {
3955         summary_select_thread(mainwin->summaryview, FALSE);
3956 }
3957
3958 static void delete_thread_cb(MainWindow *mainwin, guint action,
3959                              GtkWidget *widget)
3960 {
3961         summary_select_thread(mainwin->summaryview, TRUE);
3962 }
3963
3964 static void create_filter_cb(MainWindow *mainwin, guint action,
3965                              GtkWidget *widget)
3966 {
3967         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3968 }
3969
3970 static void create_processing_cb(MainWindow *mainwin, guint action,
3971                              GtkWidget *widget)
3972 {
3973         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3974 }
3975
3976 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3977                                          GtkWidget *widget)
3978 {
3979         prefs_filtering_open(&pre_global_processing,
3980                              _("Processing rules to apply before folder rules"),
3981                              MANUAL_ANCHOR_PROCESSING,
3982                              NULL, NULL, FALSE);
3983 }
3984
3985 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3986                                           GtkWidget *widget)
3987 {
3988         prefs_filtering_open(&post_global_processing,
3989                              _("Processing rules to apply after folder rules"),
3990                              MANUAL_ANCHOR_PROCESSING,
3991                              NULL, NULL, FALSE);
3992 }
3993
3994 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3995                                     GtkWidget *widget)
3996 {
3997         prefs_filtering_open(&filtering_rules,
3998                              _("Filtering configuration"),
3999                              MANUAL_ANCHOR_FILTERING,
4000                              NULL, NULL, TRUE);
4001 }
4002
4003 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
4004                                    GtkWidget *widget)
4005 {
4006         prefs_template_open();
4007 }
4008
4009 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
4010                                   GtkWidget *widget)
4011 {
4012         prefs_actions_open(mainwin);
4013 }
4014
4015 static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
4016                                   GtkWidget *widget)
4017 {
4018         prefs_tags_open(mainwin);
4019 }
4020 #ifdef USE_OPENSSL
4021 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
4022                                   GtkWidget *widget)
4023 {
4024         ssl_manager_open(mainwin);
4025 }
4026 #endif
4027 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
4028                                   GtkWidget *widget)
4029 {
4030         if (!cur_account) {
4031                 new_account_cb(mainwin, 0, widget);
4032         } else {
4033                 account_open(cur_account);
4034         }
4035 }
4036
4037 static void new_account_cb(MainWindow *mainwin, guint action,
4038                            GtkWidget *widget)
4039 {
4040         account_edit_open();
4041         if (!compose_get_compose_list()) account_add();
4042 }
4043
4044 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
4045 {
4046         FolderItem *item = NULL;
4047         cur_account = (PrefsAccount *)data;
4048         
4049         if (!mainwindow_get_mainwindow())
4050                 return;
4051         main_window_show_cur_account(mainwindow_get_mainwindow());
4052         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
4053         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
4054         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
4055         item = folderview_get_selected_item(
4056                         mainwindow_get_mainwindow()->folderview);
4057         if (item) {
4058                 toolbar_set_compose_button
4059                         (mainwindow_get_mainwindow()->toolbar,
4060                          FOLDER_TYPE(item->folder) == F_NEWS ? 
4061                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
4062         }
4063 }
4064
4065 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
4066 {
4067         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4068         PrefsAccount *account = (PrefsAccount *)data;
4069
4070         inc_account_mail(mainwin, account);
4071 }
4072
4073 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
4074 {
4075         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
4076         PrefsAccount *account = (PrefsAccount *)data;
4077         FolderItem *item = mainwin->summaryview->folder_item;   
4078
4079         compose_new_with_folderitem(account, item, NULL);
4080 }
4081
4082 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
4083 {
4084         prefs_gtk_open();
4085 }
4086
4087 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
4088 {
4089         pluginwindow_create();
4090 }
4091
4092 static void manual_open_cb(MainWindow *mainwin, guint action,
4093                            GtkWidget *widget)
4094 {
4095         manual_open((ManualType)action, NULL);
4096 }
4097
4098 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
4099 {
4100         legend_show();
4101 }
4102
4103 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
4104 {
4105         MainWindow *mainwin = (MainWindow *)data;
4106         gchar *str;
4107
4108         if (item->path)
4109                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
4110                                       LOCAL_FOLDER(folder)->rootpath,
4111                                       G_DIR_SEPARATOR,
4112                                       item->path);
4113         else
4114                 str = g_strdup_printf(_("Scanning folder %s ..."),
4115                                       LOCAL_FOLDER(folder)->rootpath);
4116
4117         STATUSBAR_PUSH(mainwin, str);
4118         STATUSBAR_POP(mainwin);
4119         g_free(str);
4120 }
4121
4122 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
4123                                           gpointer data)
4124 {
4125         SummaryView *summary;
4126
4127         g_return_val_if_fail(data, FALSE);
4128         if (!g_list_find(mainwin_list, data))
4129                 return TRUE;
4130         summary = ((MainWindow *)data)->summaryview;
4131         g_return_val_if_fail(summary, FALSE);
4132
4133         if (GTK_CLIST(summary->ctree)->selection && 
4134             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
4135                 return FALSE;
4136
4137         return FALSE;
4138 }
4139
4140 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
4141                                           gpointer data)
4142 {
4143         is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
4144         return FALSE;
4145 }
4146
4147 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
4148                                           gpointer data)
4149 {
4150         if (!claws_is_starting()
4151                 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
4152                 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
4153
4154                 if (iconified_count > 0)
4155                         hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
4156                 iconified_count++;
4157         }
4158         if (state->new_window_state == 0)
4159                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
4160         return FALSE;
4161 }
4162
4163 gboolean mainwindow_is_obscured(void)
4164 {
4165         return is_obscured;
4166 }
4167
4168 #define BREAK_ON_MODIFIER_KEY() \
4169         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
4170
4171 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
4172                                     gpointer data)
4173 {
4174         MainWindow *mainwin = (MainWindow*) data;
4175         
4176         if (!mainwin || !event) 
4177                 return FALSE;
4178
4179         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
4180         {
4181                 lastkey = event->keyval;
4182                 return FALSE;
4183         }
4184
4185         switch (event->keyval) {
4186         case GDK_Q:             /* Quit */
4187                 BREAK_ON_MODIFIER_KEY();
4188
4189                 app_exit_cb(mainwin, 0, NULL);
4190                 return FALSE;
4191         case GDK_space:
4192                 if (mainwin->folderview && mainwin->summaryview
4193                     && ((!mainwin->summaryview->displayed
4194                         && !mainwin->summaryview->selected) 
4195                         || (mainwin->summaryview->folder_item
4196                             && mainwin->summaryview->folder_item->total_msgs == 0))) {
4197                         g_signal_stop_emission_by_name(G_OBJECT(widget), 
4198                                        "key_press_event");
4199                         folderview_select_next_unread(mainwin->folderview, TRUE);
4200                 }
4201                 break;
4202 #ifdef MAEMO
4203         case GDK_F6:
4204                 if (maemo_mainwindow_is_fullscreen(widget)) {
4205                         gtk_window_unfullscreen(GTK_WINDOW(widget));
4206                 } else {
4207                         gtk_window_fullscreen(GTK_WINDOW(widget));
4208                 }
4209                 break;
4210 #endif
4211         default:
4212                 break;
4213         }
4214         return FALSE;
4215 }
4216
4217 #undef BREAK_ON_MODIFIER_KEY
4218
4219 /*
4220  * Harvest addresses for selected folder.
4221  */
4222 static void addr_harvest_cb( MainWindow *mainwin,
4223                             guint action,
4224                             GtkWidget *widget )
4225 {
4226         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4227 }
4228
4229 /*
4230  * Harvest addresses for selected messages in summary view.
4231  */
4232 static void addr_harvest_msg_cb( MainWindow *mainwin,
4233                             guint action,
4234                             GtkWidget *widget )
4235 {
4236         summary_harvest_address( mainwin->summaryview );
4237 }
4238
4239 /*!
4240  *\brief        get a MainWindow
4241  *
4242  *\return       MainWindow * The first mainwindow in the mainwin_list
4243  */
4244 MainWindow *mainwindow_get_mainwindow(void)
4245 {
4246         if (mainwin_list && mainwin_list->data)
4247                 return (MainWindow *)(mainwin_list->data);
4248         else
4249                 return NULL;
4250 }
4251
4252 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4253 {
4254         ProgressData *data = (ProgressData *) source;
4255         MainWindow *mainwin = (MainWindow *) userdata;
4256
4257         switch (data->cmd) {
4258         case PROGRESS_COMMAND_START:
4259         case PROGRESS_COMMAND_STOP:
4260                 gtk_progress_bar_set_fraction
4261                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4262                 break;
4263         case PROGRESS_COMMAND_SET_PERCENTAGE:
4264                 gtk_progress_bar_set_fraction
4265                         (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4266                 break;          
4267         }
4268         while (gtk_events_pending()) gtk_main_iteration ();
4269
4270         return FALSE;
4271 }
4272
4273 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4274 {
4275         mainwindow_check_synchronise(mainwin, FALSE);
4276 }
4277
4278 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4279 {
4280         summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4281 }
4282
4283 void mainwindow_jump_to(const gchar *target, gboolean popup)
4284 {
4285         gchar *tmp = NULL;
4286         gchar *p = NULL;
4287         FolderItem *item = NULL;
4288         gchar *msg = NULL;
4289         MainWindow *mainwin = mainwindow_get_mainwindow();
4290         
4291         if (!target)
4292                 return;
4293                 
4294         if (!mainwin) {
4295                 printf("not initialized\n");
4296                 return;
4297         }
4298
4299         tmp = g_strdup(target);
4300         
4301         if ((p = strstr(tmp, "\r")) != NULL)
4302                 *p = '\0';
4303         if ((p = strstr(tmp, "\n")) != NULL)
4304                 *p = '\0';
4305
4306         if ((item = folder_find_item_from_identifier(tmp))) {
4307                 printf("selecting folder '%s'\n", tmp);
4308                 folderview_select(mainwin->folderview, item);
4309                 if (popup)
4310                         main_window_popup(mainwin);
4311                 g_free(tmp);
4312                 return;
4313         }
4314         
4315         msg = strrchr(tmp, G_DIR_SEPARATOR);
4316         if (msg) {
4317                 *msg++ = '\0';
4318                 if ((item = folder_find_item_from_identifier(tmp))) {
4319                         printf("selecting folder '%s'\n", tmp);
4320                         folderview_select(mainwin->folderview, item);
4321                 } else {
4322                         printf("'%s' not found\n", tmp);
4323                 }
4324                 if (item && msg && atoi(msg)) {
4325                         printf("selecting message %d\n", atoi(msg));
4326                         summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4327                         summary_display_msg_selected(mainwin->summaryview, FALSE);
4328                         if (popup)
4329                                 main_window_popup(mainwin);
4330                         g_free(tmp);
4331                         return;
4332                 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4333                         MsgInfo *msginfo = NULL;
4334                         msg++;
4335                         msg[strlen(msg)-1] = '\0';
4336                         msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4337                         if (msginfo) {
4338                                 printf("selecting message %s\n", msg);
4339                                 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4340                                 summary_display_msg_selected(mainwin->summaryview, FALSE);
4341                                 if (popup)
4342                                         main_window_popup(mainwin);
4343                                 g_free(tmp);
4344                                 procmsg_msginfo_free(msginfo);
4345                                 return;
4346                         } else {
4347                                 printf("'%s' not found\n", msg);
4348                         }
4349                 } else {
4350                         printf("'%s' not found\n", msg);
4351                 }
4352         } else {
4353                 printf("'%s' not found\n", tmp);
4354         }
4355         
4356         g_free(tmp);
4357 }
4358
4359 void mainwindow_exit_folder(MainWindow *mainwin) {
4360         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4361                 folderview_close_opened(mainwin->folderview);
4362                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4363         }
4364         mainwin->in_folder = FALSE;
4365 }
4366
4367 void mainwindow_enter_folder(MainWindow *mainwin) {
4368         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4369                 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4370         }
4371         mainwin->in_folder = TRUE;
4372 }
4373
4374 #ifdef MAEMO
4375 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4376 {
4377         gint w, h;
4378         gtk_window_get_size(GTK_WINDOW(widget), &w, &h); 
4379         return (w == 800);
4380 }
4381
4382 void maemo_window_full_screen_if_needed (GtkWindow *window)
4383 {
4384         if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4385                 gtk_window_fullscreen(GTK_WINDOW(window));
4386         }
4387 }
4388
4389 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4390 {
4391         g_signal_connect(G_OBJECT(window), "key_press_event",
4392                          G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());
4393 }
4394 #endif