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