0b3f8b1787e45c596609f8747483c299c1b62b0e
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 Hiroyuki Yamamoto
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtksignal.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkcontainer.h>
30 #include <gtk/gtkstatusbar.h>
31 #include <gtk/gtkprogressbar.h>
32 #include <gtk/gtkhpaned.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtkcheckmenuitem.h>
35 #include <gtk/gtkitemfactory.h>
36 #include <gtk/gtkeditable.h>
37 #include <gtk/gtkmenu.h>
38 #include <gtk/gtkmenuitem.h>
39 #include <gtk/gtkhandlebox.h>
40 #include <gtk/gtktoolbar.h>
41 #include <gtk/gtkbutton.h>
42 #include <string.h>
43
44 #include "intl.h"
45 #include "main.h"
46 #include "mainwindow.h"
47 #include "folderview.h"
48 #include "foldersel.h"
49 #include "summaryview.h"
50 #include "summary_search.h"
51 #include "messageview.h"
52 #include "message_search.h"
53 #include "headerview.h"
54 #include "menu.h"
55 #include "stock_pixmap.h"
56 #include "folder.h"
57 #include "inc.h"
58 #include "compose.h"
59 #include "procmsg.h"
60 #include "import.h"
61 #include "export.h"
62 #include "prefs_common.h"
63 #include "prefs_actions.h"
64 #include "prefs_filtering.h"
65 #include "prefs_scoring.h"
66 #include "prefs_account.h"
67 #include "prefs_folder_item.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_template.h"
70 #include "prefs_toolbar.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 "selective_download.h"
85 #include "ssl_manager.h"
86 #include "sslcertwindow.h"
87 #include "prefswindow.h"
88 #include "pluginwindow.h"
89
90 #define AC_LABEL_WIDTH  240
91
92 /* list of all instantiated MainWindow */
93 static GList *mainwin_list = NULL;
94
95 static GdkCursor *watch_cursor;
96
97 static void main_window_menu_callback_block     (MainWindow     *mainwin);
98 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
99
100 static void main_window_show_cur_account        (MainWindow     *mainwin);
101
102 static void main_window_set_widgets             (MainWindow     *mainwin,
103                                                  SeparateType    type);
104
105 #if 0
106 static void toolbar_account_button_pressed      (GtkWidget      *widget,
107                                                  GdkEventButton *event,
108                                                  gpointer        data);
109 #endif
110 static void ac_label_button_pressed             (GtkWidget      *widget,
111                                                  GdkEventButton *event,
112                                                  gpointer        data);
113 static void ac_menu_popup_closed                (GtkMenuShell   *menu_shell,
114                                                  gpointer        data);
115
116 static gint main_window_close_cb        (GtkWidget      *widget,
117                                          GdkEventAny    *event,
118                                          gpointer        data);
119 static gint folder_window_close_cb      (GtkWidget      *widget,
120                                          GdkEventAny    *event,
121                                          gpointer        data);
122 static gint message_window_close_cb     (GtkWidget      *widget,
123                                          GdkEventAny    *event,
124                                          gpointer        data);
125
126 static void add_mailbox_cb       (MainWindow    *mainwin,
127                                   guint          action,
128                                   GtkWidget     *widget);
129 static void add_mbox_cb          (MainWindow    *mainwin,
130                                   guint          action,
131                                   GtkWidget     *widget);
132 static void update_folderview_cb (MainWindow    *mainwin,
133                                   guint          action,
134                                   GtkWidget     *widget);
135 static void new_folder_cb        (MainWindow    *mainwin,
136                                   guint          action,
137                                   GtkWidget     *widget);
138 static void rename_folder_cb     (MainWindow    *mainwin,
139                                   guint          action,
140                                   GtkWidget     *widget);
141 static void delete_folder_cb     (MainWindow    *mainwin,
142                                   guint          action,
143                                   GtkWidget     *widget);
144 static void import_mbox_cb       (MainWindow    *mainwin,
145                                   guint          action,
146                                   GtkWidget     *widget);
147 static void export_mbox_cb       (MainWindow    *mainwin,
148                                   guint          action,
149                                   GtkWidget     *widget);
150 static void empty_trash_cb       (MainWindow    *mainwin,
151                                   guint          action,
152                                   GtkWidget     *widget);
153
154 static void save_as_cb           (MainWindow    *mainwin,
155                                   guint          action,
156                                   GtkWidget     *widget);
157 static void print_cb             (MainWindow    *mainwin,
158                                   guint          action,
159                                   GtkWidget     *widget);
160 static void app_exit_cb          (MainWindow    *mainwin,
161                                   guint          action,
162                                   GtkWidget     *widget);
163
164 static void search_cb            (MainWindow    *mainwin,
165                                   guint          action,
166                                   GtkWidget     *widget);
167
168 static void toggle_folder_cb     (MainWindow    *mainwin,
169                                   guint          action,
170                                   GtkWidget     *widget);
171 static void toggle_message_cb    (MainWindow    *mainwin,
172                                   guint          action,
173                                   GtkWidget     *widget);
174 static void toggle_toolbar_cb    (MainWindow    *mainwin,
175                                   guint          action,
176                                   GtkWidget     *widget);
177 static void toggle_statusbar_cb  (MainWindow    *mainwin,
178                                   guint          action,
179                                   GtkWidget     *widget);
180 static void separate_widget_cb   (MainWindow    *mainwin,
181                                   guint          action,
182                                   GtkWidget     *widget);
183
184 static void addressbook_open_cb (MainWindow     *mainwin,
185                                  guint           action,
186                                  GtkWidget      *widget);
187 static void log_window_show_cb  (MainWindow     *mainwin,
188                                  guint           action,
189                                  GtkWidget      *widget);
190 static void sel_download_cb          (MainWindow *mainwin, 
191                                  guint action,
192                                  GtkWidget *widget);
193 static void prefs_toolbar_cb        (MainWindow *mainwin, 
194                                  guint action,
195                                  GtkWidget *widget);
196
197
198 static void inc_cancel_cb               (MainWindow     *mainwin,
199                                          guint           action,
200                                          GtkWidget      *widget);
201
202 static void open_msg_cb                 (MainWindow     *mainwin,
203                                          guint           action,
204                                          GtkWidget      *widget);
205
206 static void view_source_cb              (MainWindow     *mainwin,
207                                          guint           action,
208                                          GtkWidget      *widget);
209
210 static void show_all_header_cb          (MainWindow     *mainwin,
211                                          guint           action,
212                                          GtkWidget      *widget);
213
214 static void reedit_cb                   (MainWindow     *mainwin,
215                                          guint           action,
216                                          GtkWidget      *widget);
217
218 static void move_to_cb                  (MainWindow     *mainwin,
219                                          guint           action,
220                                          GtkWidget      *widget);
221 static void copy_to_cb                  (MainWindow     *mainwin,
222                                          guint           action,
223                                          GtkWidget      *widget);
224 static void delete_cb                   (MainWindow     *mainwin,
225                                          guint           action,
226                                          GtkWidget      *widget);
227
228 static void cancel_cb                   (MainWindow     *mainwin,
229                                          guint           action,
230                                          GtkWidget      *widget);
231
232 static void mark_cb                     (MainWindow     *mainwin,
233                                          guint           action,
234                                          GtkWidget      *widget);
235 static void unmark_cb                   (MainWindow     *mainwin,
236                                          guint           action,
237                                          GtkWidget      *widget);
238
239 static void mark_as_unread_cb           (MainWindow     *mainwin,
240                                          guint           action,
241                                          GtkWidget      *widget);
242 static void mark_as_read_cb             (MainWindow     *mainwin,
243                                          guint           action,
244                                          GtkWidget      *widget);
245 static void mark_all_read_cb            (MainWindow     *mainwin,
246                                          guint           action,
247                                          GtkWidget      *widget);
248 static void add_address_cb              (MainWindow     *mainwin,
249                                          guint           action,
250                                          GtkWidget      *widget);
251
252 static void set_charset_cb              (MainWindow     *mainwin,
253                                          guint           action,
254                                          GtkWidget      *widget);
255
256 static void hide_read_messages   (MainWindow    *mainwin,
257                                   guint          action,
258                                   GtkWidget     *widget);
259
260 static void thread_cb            (MainWindow    *mainwin,
261                                   guint          action,
262                                   GtkWidget     *widget);
263 static void expand_threads_cb    (MainWindow    *mainwin,
264                                   guint          action,
265                                   GtkWidget     *widget);
266 static void collapse_threads_cb  (MainWindow    *mainwin,
267                                   guint          action,
268                                   GtkWidget     *widget);
269
270 static void set_display_item_cb  (MainWindow    *mainwin,
271                                   guint          action,
272                                   GtkWidget     *widget);
273 static void sort_summary_cb      (MainWindow    *mainwin,
274                                   guint          action,
275                                   GtkWidget     *widget);
276 static void sort_summary_type_cb (MainWindow    *mainwin,
277                                   guint          action,
278                                   GtkWidget     *widget);
279 static void attract_by_subject_cb(MainWindow    *mainwin,
280                                   guint          action,
281                                   GtkWidget     *widget);
282
283 static void delete_duplicated_cb (MainWindow    *mainwin,
284                                   guint          action,
285                                   GtkWidget     *widget);
286 static void filter_cb            (MainWindow    *mainwin,
287                                   guint          action,
288                                   GtkWidget     *widget);
289 static void execute_summary_cb   (MainWindow    *mainwin,
290                                   guint          action,
291                                   GtkWidget     *widget);
292 static void update_summary_cb    (MainWindow    *mainwin,
293                                   guint          action,
294                                   GtkWidget     *widget);
295
296 static void prev_cb              (MainWindow    *mainwin,
297                                   guint          action,
298                                   GtkWidget     *widget);
299 static void next_cb              (MainWindow    *mainwin,
300                                   guint          action,
301                                   GtkWidget     *widget);
302 static void next_unread_cb       (MainWindow    *mainwin,
303                                   guint          action,
304                                   GtkWidget     *widget);
305 static void prev_unread_cb       (MainWindow    *mainwin,
306                                   guint          action,
307                                   GtkWidget     *widget);
308
309 static void prev_new_cb          (MainWindow    *mainwin,
310                                   guint          action,
311                                   GtkWidget     *widget);
312 static void next_new_cb          (MainWindow    *mainwin,
313                                   guint          action,
314                                   GtkWidget     *widget);
315 static void prev_marked_cb       (MainWindow    *mainwin,
316                                   guint          action,
317                                   GtkWidget     *widget);
318 static void next_marked_cb       (MainWindow    *mainwin,
319                                   guint          action,
320                                   GtkWidget     *widget);
321 static void prev_labeled_cb      (MainWindow    *mainwin,
322                                   guint          action,
323                                   GtkWidget     *widget);
324 static void next_labeled_cb      (MainWindow    *mainwin,
325                                   guint          action,
326                                   GtkWidget     *widget);
327
328 static void goto_folder_cb       (MainWindow    *mainwin,
329                                   guint          action,
330                                   GtkWidget     *widget);
331
332 static void copy_cb              (MainWindow    *mainwin,
333                                   guint          action,
334                                   GtkWidget     *widget);
335 static void allsel_cb            (MainWindow    *mainwin,
336                                   guint          action,
337                                   GtkWidget     *widget);
338 static void select_thread_cb     (MainWindow    *mainwin,
339                                   guint          action,
340                                   GtkWidget     *widget);
341
342 static void create_filter_cb     (MainWindow    *mainwin,
343                                   guint          action,
344                                   GtkWidget     *widget);
345
346 static void prefs_common_open_cb        (MainWindow     *mainwin,
347                                          guint           action,
348                                          GtkWidget      *widget);
349 static void prefs_template_open_cb      (MainWindow     *mainwin,
350                                          guint           action,
351                                          GtkWidget      *widget);
352 static void prefs_actions_open_cb       (MainWindow     *mainwin,
353                                          guint           action,
354                                          GtkWidget      *widget);
355 static void prefs_account_open_cb       (MainWindow     *mainwin,
356                                          guint           action,
357                                          GtkWidget      *widget);
358 static void prefs_scoring_open_cb       (MainWindow     *mainwin,
359                                          guint           action,
360                                          GtkWidget      *widget);
361 static void prefs_filtering_open_cb     (MainWindow     *mainwin,
362                                          guint           action,
363                                          GtkWidget      *widget);
364 #ifdef USE_OPENSSL
365 static void ssl_manager_open_cb         (MainWindow     *mainwin,
366                                          guint           action,
367                                          GtkWidget      *widget);
368 #endif
369 static void new_account_cb       (MainWindow    *mainwin,
370                                   guint          action,
371                                   GtkWidget     *widget);
372
373 static void account_menu_cb      (GtkMenuItem   *menuitem,
374                                   gpointer       data);
375
376 static void prefs_open_cb       (GtkMenuItem    *menuitem,
377                                  gpointer        data);
378 static void plugins_open_cb     (GtkMenuItem    *menuitem,
379                                  gpointer        data);
380
381 static void online_switch_clicked(GtkButton     *btn, 
382                                   gpointer data);
383
384 static void manual_open_cb       (MainWindow    *mainwin,
385                                   guint          action,
386                                   GtkWidget     *widget);
387
388 static void scan_tree_func       (Folder        *folder,
389                                   FolderItem    *item,
390                                   gpointer       data);
391                                   
392 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
393
394 static void addr_harvest_cb      ( MainWindow  *mainwin,
395                                    guint       action,
396                                    GtkWidget   *widget );
397
398 static void addr_harvest_msg_cb  ( MainWindow  *mainwin,
399                                    guint       action,
400                                    GtkWidget   *widget );
401
402 static gboolean mainwindow_focus_in_event       (GtkWidget      *widget, 
403                                                  GdkEventFocus  *focus,
404                                                  gpointer        data);
405
406 #define  SEPARATE_ACTION 500 
407
408 static GtkItemFactoryEntry mainwin_entries[] =
409 {
410         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
411         {N_("/_File/_Add mailbox..."),          NULL, add_mailbox_cb, 0, NULL},
412         {N_("/_File/_Add mbox mailbox..."),     NULL, add_mbox_cb, 0, NULL},
413         {N_("/_File/_Check for new messages in all folders"),
414                                                 NULL, update_folderview_cb, 0, NULL},
415         {N_("/_File/_Folder"),                  NULL, NULL, 0, "<Branch>"},
416         {N_("/_File/_Folder/Create _new folder..."),
417                                                 NULL, new_folder_cb, 0, NULL},
418         {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
419         {N_("/_File/_Folder/_Delete folder"),   NULL, delete_folder_cb, 0, NULL},
420         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
421         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
422         {N_("/_File/Empty _trash"),             "<shift>D", empty_trash_cb, 0, NULL},
423         {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},                                               
424         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
425         {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
426         {N_("/_File/_Print..."),                NULL, print_cb, 0, NULL},
427         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
428         /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
429         {N_("/_File/E_xit"),                    "<control>Q", app_exit_cb, 0, NULL},
430
431         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
432         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
433         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
434         {N_("/_Edit/Select _thread"),           NULL, select_thread_cb, 0, NULL},
435         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
436         {N_("/_Edit/_Find in current message..."),
437                                                 "<control>F", search_cb, 0, NULL},
438         {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
439         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
440         {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
441         {N_("/_View/Show or hi_de/_Folder tree"),
442                                                 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
443         {N_("/_View/Show or hi_de/_Message view"),
444                                                 "V", toggle_message_cb, 0, "<ToggleItem>"},
445         {N_("/_View/Show or hi_de/_Toolbar"),
446                                                 NULL, NULL, 0, "<Branch>"},
447         {N_("/_View/Show or hi_de/_Toolbar/Icon _and text"),
448                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
449         {N_("/_View/Show or hi_de/_Toolbar/_Icon"),
450                                                 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Icon and text"},
451         {N_("/_View/Show or hi_de/_Toolbar/_Text"),
452                                                 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Icon and text"},
453         {N_("/_View/Show or hi_de/_Toolbar/_None"),
454                                                 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Icon and text"},
455         {N_("/_View/Show or hi_de/Status _bar"),
456                                                 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
457         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
458         {N_("/_View/Separate f_older tree"),    NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
459         {N_("/_View/Separate m_essage view"),   NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
460         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
461         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
462         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
463         {N_("/_View/_Sort/by s_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
464         {N_("/_View/_Sort/by _date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
465         {N_("/_View/_Sort/by _from"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
466         {N_("/_View/_Sort/by _recipient"),      NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
467         {N_("/_View/_Sort/by _subject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
468         {N_("/_View/_Sort/by _color label"),
469                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
470         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
471         {N_("/_View/_Sort/by _unread"),         NULL, sort_summary_cb, SORT_BY_UNREAD, "/View/Sort/by number"},
472         {N_("/_View/_Sort/by a_ttachment"),
473                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
474         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
475         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
476         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
477         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
478         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
479         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
480         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
481         {N_("/_View/_Sort/_Attract by subject"),
482                                                 NULL, attract_by_subject_cb, 0, NULL},
483         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
484         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
485         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
486         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
487         {N_("/_View/Set displayed _items..."),  NULL, set_display_item_cb, 0, NULL},
488
489         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
490         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
491         {N_("/_View/_Go to/_Prev message"),     "P", prev_cb, 0, NULL},
492         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
493         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
494         {N_("/_View/_Go to/P_rev unread message"),
495                                                 "<shift>P", prev_unread_cb, 0, NULL},
496         {N_("/_View/_Go to/N_ext unread message"),
497                                                 "<shift>N", next_unread_cb, 0, NULL},
498         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
499         {N_("/_View/_Go to/Prev ne_w message"), NULL, prev_new_cb, 0, NULL},
500         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
501         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
502         {N_("/_View/_Go to/Prev _marked message"),
503                                                 NULL, prev_marked_cb, 0, NULL},
504         {N_("/_View/_Go to/Next m_arked message"),
505                                                 NULL, next_marked_cb, 0, NULL},
506         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
507         {N_("/_View/_Go to/Prev _labeled message"),
508                                                 NULL, prev_labeled_cb, 0, NULL},
509         {N_("/_View/_Go to/Next la_beled message"),
510                                                 NULL, next_labeled_cb, 0, NULL},
511         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
512         {N_("/_View/_Go to/Other _folder..."),  "G", goto_folder_cb, 0, NULL},
513         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
514
515 #define CODESET_SEPARATOR \
516         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"}
517 #define CODESET_ACTION(action) \
518          NULL, set_charset_cb, action, "/View/Code set/Auto detect"
519
520         {N_("/_View/_Code set"),                NULL, NULL, 0, "<Branch>"},
521         {N_("/_View/_Code set/_Auto detect"),
522          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
523         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"},
524         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
525          CODESET_ACTION(C_US_ASCII)},
526
527 #if HAVE_LIBJCONV
528         {N_("/_View/_Code set/Unicode (_UTF-8)"),
529          CODESET_ACTION(C_UTF_8)},
530         CODESET_SEPARATOR,
531 #endif
532         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
533          CODESET_ACTION(C_ISO_8859_1)},
534         {N_("/_View/_Code set/Western European (ISO-8859-15)"),
535          CODESET_ACTION(C_ISO_8859_15)},
536         CODESET_SEPARATOR,
537 #if HAVE_LIBJCONV
538         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
539          CODESET_ACTION(C_ISO_8859_2)},
540         CODESET_SEPARATOR,
541         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
542          CODESET_ACTION(C_ISO_8859_13)},
543         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
544          CODESET_ACTION(C_ISO_8859_4)},
545         CODESET_SEPARATOR,
546         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
547          CODESET_ACTION(C_ISO_8859_7)},
548         CODESET_SEPARATOR,
549         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
550          CODESET_ACTION(C_ISO_8859_9)},
551         CODESET_SEPARATOR,
552         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
553          CODESET_ACTION(C_ISO_8859_5)},
554         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
555          CODESET_ACTION(C_KOI8_R)},
556         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
557          CODESET_ACTION(C_WINDOWS_1251)},
558         CODESET_SEPARATOR,
559 #endif
560         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
561          CODESET_ACTION(C_ISO_2022_JP)},
562 #if HAVE_LIBJCONV
563         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
564          CODESET_ACTION(C_ISO_2022_JP_2)},
565 #endif
566         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
567          CODESET_ACTION(C_EUC_JP)},
568         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
569          CODESET_ACTION(C_SHIFT_JIS)},
570 #if HAVE_LIBJCONV
571         CODESET_SEPARATOR,
572         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
573          CODESET_ACTION(C_GB2312)},
574         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
575          CODESET_ACTION(C_BIG5)},
576         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
577          CODESET_ACTION(C_EUC_TW)},
578         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
579          CODESET_ACTION(C_ISO_2022_CN)},
580         CODESET_SEPARATOR,
581         {N_("/_View/_Code set/Korean (EUC-_KR)"),
582          CODESET_ACTION(C_EUC_KR)},
583         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
584          CODESET_ACTION(C_ISO_2022_KR)},
585         CODESET_SEPARATOR,
586         {N_("/_View/_Code set/Thai (TIS-620)"),
587          CODESET_ACTION(C_TIS_620)},
588         {N_("/_View/_Code set/Thai (Windows-874)"),
589          CODESET_ACTION(C_WINDOWS_874)},
590 #endif
591
592 #undef CODESET_SEPARATOR
593 #undef CODESET_ACTION
594
595         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
596         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
597         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
598         {N_("/_View/Show all _headers"),        "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
599         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
600         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
601
602         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
603         {N_("/_Message/Get new ma_il"),         "<control>I",   inc_mail_cb, 0, NULL},
604         {N_("/_Message/Get from _all accounts"),
605                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
606         {N_("/_Message/Cancel receivin_g"),     NULL, inc_cancel_cb, 0, NULL},
607         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
608         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
609         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
610         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
611         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
612         {N_("/_Message/_Reply"),                "<control>R",   reply_cb, COMPOSE_REPLY, NULL},
613         {N_("/_Message/Repl_y to"),             NULL, NULL, 0, "<Branch>"},
614         {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
615         {N_("/_Message/Repl_y to/_sender"),     NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
616         {N_("/_Message/Repl_y to/mailing _list"),
617                                                 "<control>L", reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
618         {N_("/_Message/Follow-up and reply to"),NULL, reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
619         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
620         {N_("/_Message/_Forward"),              "<control><alt>F", reply_cb, COMPOSE_FORWARD, NULL},
621         {N_("/_Message/Redirect"),              NULL, reply_cb, COMPOSE_REDIRECT, NULL},
622         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
623         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
624         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
625         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
626         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
627         {N_("/_Message/_Delete"),               "<control>D", delete_cb,  0, NULL},
628         {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
629         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
630         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
631         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
632         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
633         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
634         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
635         {N_("/_Message/_Mark/Mark as rea_d"),
636                                                 NULL, mark_as_read_cb, 0, NULL},
637         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
638
639         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
640         {N_("/_Tools/_Selective download..."),  "<alt>S", sel_download_cb, 0, NULL},
641         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
642         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
643         {N_("/_Tools/Add sender to address boo_k"),
644                                                 NULL, add_address_cb, 0, NULL},
645         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
646         {N_("/_Tools/_Harvest addresses/from _Folder..."),
647                                                 NULL, addr_harvest_cb, 0, NULL},
648         {N_("/_Tools/_Harvest addresses/from _Messages..."),
649                                                 NULL, addr_harvest_msg_cb, 0, NULL},
650         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
651         {N_("/_Tools/_Filter messages"),                NULL, filter_cb, 0, NULL},
652         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
653         {N_("/_Tools/_Create filter rule/_Automatically"),
654                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
655         {N_("/_Tools/_Create filter rule/by _From"),
656                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
657         {N_("/_Tools/_Create filter rule/by _To"),
658                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
659         {N_("/_Tools/_Create filter rule/by _Subject"),
660                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
661         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
662         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
663         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
664         {N_("/_Tools/Delete du_plicated messages"),
665                                                 NULL, delete_duplicated_cb,   0, NULL},
666         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
667         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
668 #ifdef USE_OPENSSL
669         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
670         {N_("/_Tools/SSL certi_ficates..."),    
671                                                 NULL, ssl_manager_open_cb, 0, NULL},
672 #endif
673         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
674         {N_("/_Tools/_Log window"),             "<shift><control>L", log_window_show_cb, 0, NULL},
675
676         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
677         {N_("/_Configuration/_Common preferences..."),
678                                                 NULL, prefs_common_open_cb, 0, NULL},
679         {N_("/_Configuration/C_ustomize toolbars"),
680                                                 NULL, NULL, 0, "<Branch>"},
681         {N_("/_Configuration/C_ustomize toolbars/_Main window..."),
682                                                 NULL, prefs_toolbar_cb, TOOLBAR_MAIN, NULL},
683         {N_("/_Configuration/C_ustomize toolbars/_Compose window..."),
684                                                 NULL, prefs_toolbar_cb, TOOLBAR_COMPOSE, NULL},
685         {N_("/_Configuration/C_ustomize toolbars/M_essage view..."),
686                                                 NULL, prefs_toolbar_cb, TOOLBAR_MSGVIEW, NULL},
687         {N_("/_Configuration/_Scoring..."),
688                                                 NULL, prefs_scoring_open_cb, 0, NULL},
689         {N_("/_Configuration/_Filtering..."),
690                                                 NULL, prefs_filtering_open_cb, 0, NULL},
691         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
692         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
693         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
694         {N_("/_Configuration/_Preferences for current account..."),
695                                                 NULL, prefs_account_open_cb, 0, NULL},
696         {N_("/_Configuration/Create _new account..."),
697                                                 NULL, new_account_cb, 0, NULL},
698         {N_("/_Configuration/_Edit accounts..."),
699                                                 NULL, account_edit_open, 0, NULL},
700         {N_("/_Configuration/C_hange current account"),
701                                                 NULL, NULL, 0, "<Branch>"},
702         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
703         {N_("/_Configuration/Preferences..."),  NULL, prefs_open_cb, 0, NULL},
704         {N_("/_Configuration/Plugins..."),      NULL, plugins_open_cb, 0, NULL},
705
706         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
707         {N_("/_Help/_Manual (Local)"),          NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
708         {N_("/_Help/_Manual (Sylpheed Doc Homepage)"),
709                                                 NULL, manual_open_cb, MANUAL_MANUAL_SYLDOC, NULL},
710         {N_("/_Help/_FAQ (Local)"),             NULL, manual_open_cb, MANUAL_FAQ_LOCAL, NULL},
711         {N_("/_Help/_FAQ (Sylpheed Doc Homepage)"),
712                                                 NULL, manual_open_cb, MANUAL_FAQ_SYLDOC, NULL},
713         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
714         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
715 };
716
717 MainWindow *main_window_create(SeparateType type)
718 {
719         MainWindow *mainwin;
720         GtkWidget *window;
721         GtkWidget *vbox;
722         GtkWidget *menubar;
723         GtkWidget *handlebox;
724         GtkWidget *vbox_body;
725         GtkWidget *hbox_stat;
726         GtkWidget *statusbar;
727         GtkWidget *progressbar;
728         GtkWidget *statuslabel;
729         GtkWidget *ac_button;
730         GtkWidget *ac_label;
731         GtkWidget *online_pixmap;
732         GtkWidget *offline_pixmap;
733         GtkWidget *online_switch;
734         GtkWidget *offline_switch;
735
736         FolderView *folderview;
737         SummaryView *summaryview;
738         MessageView *messageview;
739         GdkColormap *colormap;
740         GdkColor color[4];
741         gboolean success[4];
742         GtkItemFactory *ifactory;
743         GtkWidget *ac_menu;
744         GtkWidget *menuitem;
745         gint i;
746         guint n_menu_entries;
747
748         static GdkGeometry geometry;
749
750         debug_print("Creating main window...\n");
751         mainwin = g_new0(MainWindow, 1);
752
753         /* main window */
754         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
755         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
756         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
757         gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
758
759         if (!geometry.min_height) {
760                 geometry.min_width = 320;
761                 geometry.min_height = 200;
762         }
763         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
764                                       GDK_HINT_MIN_SIZE);
765
766         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
767                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
768         MANAGE_WINDOW_SIGNALS_CONNECT(window);
769         gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
770                            GTK_SIGNAL_FUNC(mainwindow_focus_in_event),
771                            mainwin);
772         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
773                                 GTK_SIGNAL_FUNC(mainwindow_key_pressed), mainwin);
774
775         gtk_widget_realize(window);
776         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
777         
778
779         gtkut_widget_set_app_icon(window);
780
781         vbox = gtk_vbox_new(FALSE, 0);
782         gtk_widget_show(vbox);
783         gtk_container_add(GTK_CONTAINER(window), vbox);
784
785         /* menu bar */
786         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
787         menubar = menubar_create(window, mainwin_entries, 
788                                  n_menu_entries, "<Main>", mainwin);
789         gtk_widget_show(menubar);
790         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
791         ifactory = gtk_item_factory_from_widget(menubar);
792
793         menu_set_sensitive(ifactory, "/Help/Manual (Local)", manual_available(MANUAL_MANUAL_LOCAL));
794         menu_set_sensitive(ifactory, "/Help/FAQ (Local)", manual_available(MANUAL_FAQ_LOCAL));
795
796         handlebox = gtk_handle_box_new();
797         gtk_widget_show(handlebox);
798         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
799
800         /* link window to mainwin->window to avoid gdk warnings */
801         mainwin->window       = window;
802         
803         /* create toolbar */
804         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
805                                           handlebox, 
806                                           (gpointer)mainwin);
807
808         /* vbox that contains body */
809         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
810         gtk_widget_show(vbox_body);
811         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
812         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
813
814         hbox_stat = gtk_hbox_new(FALSE, 2);
815         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
816
817         statusbar = statusbar_create();
818         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
819
820         progressbar = gtk_progress_bar_new();
821         gtk_widget_set_usize(progressbar, 120, 1);
822         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
823
824         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
825         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
826         online_switch = gtk_button_new ();
827         offline_switch = gtk_button_new ();
828         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
829         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
830         gtk_signal_connect (GTK_OBJECT(online_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
831         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
832         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
833         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
834         gtk_signal_connect (GTK_OBJECT(offline_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
835         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
836         
837         statuslabel = gtk_label_new("");
838         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
839
840         ac_button = gtk_button_new();
841         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
842         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
843         gtk_widget_set_usize(ac_button, -1, 1);
844         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
845         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
846                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
847
848         ac_label = gtk_label_new("");
849         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
850
851         gtk_widget_show_all(hbox_stat);
852
853         gtk_widget_hide(offline_switch);
854         /* create views */
855         mainwin->folderview  = folderview  = folderview_create();
856         mainwin->summaryview = summaryview = summary_create();
857         mainwin->messageview = messageview = messageview_create(mainwin);
858         mainwin->logwin      = log_window_create();
859
860         folderview->mainwin      = mainwin;
861         folderview->summaryview  = summaryview;
862
863         summaryview->mainwin     = mainwin;
864         summaryview->folderview  = folderview;
865         summaryview->messageview = messageview;
866         summaryview->window      = window;
867
868         mainwin->vbox         = vbox;
869         mainwin->menubar      = menubar;
870         mainwin->menu_factory = ifactory;
871         mainwin->handlebox    = handlebox;
872         mainwin->vbox_body    = vbox_body;
873         mainwin->hbox_stat    = hbox_stat;
874         mainwin->statusbar    = statusbar;
875         mainwin->progressbar  = progressbar;
876         mainwin->statuslabel  = statuslabel;
877         mainwin->ac_button    = ac_button;
878         mainwin->ac_label     = ac_label;
879         
880         mainwin->online_switch     = online_switch;
881         mainwin->offline_switch    = offline_switch;
882         mainwin->online_pixmap     = online_pixmap;
883         mainwin->offline_pixmap    = offline_pixmap;
884         
885         /* set context IDs for status bar */
886         mainwin->mainwin_cid = gtk_statusbar_get_context_id
887                 (GTK_STATUSBAR(statusbar), "Main Window");
888         mainwin->folderview_cid = gtk_statusbar_get_context_id
889                 (GTK_STATUSBAR(statusbar), "Folder View");
890         mainwin->summaryview_cid = gtk_statusbar_get_context_id
891                 (GTK_STATUSBAR(statusbar), "Summary View");
892
893         /* allocate colors for summary view and folder view */
894         summaryview->color_marked.red = summaryview->color_marked.green = 0;
895         summaryview->color_marked.blue = (guint16)65535;
896
897         summaryview->color_dim.red = summaryview->color_dim.green =
898                 summaryview->color_dim.blue = COLOR_DIM;
899
900         folderview->color_new.red = (guint16)55000;
901         folderview->color_new.green = folderview->color_new.blue = 15000;
902
903         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
904                                        &folderview->color_op);
905
906         summaryview->color_important.red = 0;
907         summaryview->color_important.green = 0;
908         summaryview->color_important.blue = (guint16)65535;
909
910         color[0] = summaryview->color_marked;
911         color[1] = summaryview->color_dim;
912         color[2] = folderview->color_new;
913         color[3] = folderview->color_op;
914
915         colormap = gdk_window_get_colormap(window->window);
916         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
917         for (i = 0; i < 4; i++) {
918                 if (success[i] == FALSE)
919                         g_warning("MainWindow: color allocation %d failed\n", i);
920         }
921
922         debug_print("done.\n");
923
924         messageview->visible = TRUE;
925
926         main_window_set_widgets(mainwin, type);
927
928         /* set menu items */
929         menuitem = gtk_item_factory_get_item
930                 (ifactory, "/View/Code set/Auto detect");
931         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
932
933         switch (prefs_common.toolbar_style) {
934         case TOOLBAR_NONE:
935                 menuitem = gtk_item_factory_get_item
936                         (ifactory, "/View/Show or hide/Toolbar/None");
937                 break;
938         case TOOLBAR_ICON:
939                 menuitem = gtk_item_factory_get_item
940                         (ifactory, "/View/Show or hide/Toolbar/Icon");
941                 break;
942         case TOOLBAR_TEXT:
943                 menuitem = gtk_item_factory_get_item
944                         (ifactory, "/View/Show or hide/Toolbar/Text");
945                 break;
946         case TOOLBAR_BOTH:
947                 menuitem = gtk_item_factory_get_item
948                         (ifactory, "/View/Show or hide/Toolbar/Icon and text");
949         }
950         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
951
952         gtk_widget_hide(mainwin->hbox_stat);
953         menuitem = gtk_item_factory_get_item
954                 (ifactory, "/View/Show or hide/Status bar");
955         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
956                                        prefs_common.show_statusbar);
957         
958         gtk_widget_hide(GTK_WIDGET(mainwin->summaryview->hbox_search));
959         
960         if (prefs_common.show_searchbar)
961                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainwin->summaryview->toggle_search), TRUE);
962
963
964         /* set account selection menu */
965         ac_menu = gtk_item_factory_get_widget
966                 (ifactory, "/Configuration/Change current account");
967         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
968                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
969         mainwin->ac_menu = ac_menu;
970
971         toolbar_main_set_sensitive(mainwin);
972
973         /* create actions menu */
974         update_mainwin_actions_menu(ifactory, mainwin);
975
976         /* show main window */
977         gtk_widget_set_uposition(mainwin->window,
978                                  prefs_common.mainwin_x,
979                                  prefs_common.mainwin_y);
980         gtk_widget_set_usize(window, prefs_common.mainwin_width,
981                              prefs_common.mainwin_height);
982         gtk_widget_show(mainwin->window);
983
984         /* initialize views */
985         folderview_init(folderview);
986         summary_init(summaryview);
987         messageview_init(messageview);
988         log_window_init(mainwin->logwin);
989 #ifdef USE_OPENSSL
990         sslcertwindow_register_hook();
991 #endif
992         mainwin->lock_count = 0;
993         mainwin->menu_lock_count = 0;
994         mainwin->cursor_count = 0;
995
996         if (!watch_cursor)
997                 watch_cursor = gdk_cursor_new(GDK_WATCH);
998
999         mainwin_list = g_list_append(mainwin_list, mainwin);
1000
1001         /* init work_offline */
1002         if (prefs_common.work_offline)
1003                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1004
1005         return mainwin;
1006 }
1007
1008 void main_window_cursor_wait(MainWindow *mainwin)
1009 {
1010
1011         if (mainwin->cursor_count == 0)
1012                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1013
1014         mainwin->cursor_count++;
1015
1016         gdk_flush();
1017 }
1018
1019 void main_window_cursor_normal(MainWindow *mainwin)
1020 {
1021         if (mainwin->cursor_count)
1022                 mainwin->cursor_count--;
1023
1024         if (mainwin->cursor_count == 0)
1025                 gdk_window_set_cursor(mainwin->window->window, NULL);
1026
1027         gdk_flush();
1028 }
1029
1030 /* lock / unlock the user-interface */
1031 void main_window_lock(MainWindow *mainwin)
1032 {
1033         if (mainwin->lock_count == 0)
1034                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1035
1036         mainwin->lock_count++;
1037
1038         main_window_set_menu_sensitive(mainwin);
1039         toolbar_main_set_sensitive(mainwin);
1040 }
1041
1042 void main_window_unlock(MainWindow *mainwin)
1043 {
1044         if (mainwin->lock_count)
1045                 mainwin->lock_count--;
1046
1047         main_window_set_menu_sensitive(mainwin);
1048         toolbar_main_set_sensitive(mainwin);
1049
1050         if (mainwin->lock_count == 0)
1051                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1052 }
1053
1054 static void main_window_menu_callback_block(MainWindow *mainwin)
1055 {
1056         mainwin->menu_lock_count++;
1057 }
1058
1059 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1060 {
1061         if (mainwin->menu_lock_count)
1062                 mainwin->menu_lock_count--;
1063 }
1064
1065 void main_window_reflect_prefs_all(void)
1066 {
1067         main_window_reflect_prefs_all_real(FALSE);
1068 }
1069
1070 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1071 {
1072         GList *cur;
1073         MainWindow *mainwin;
1074         GtkWidget *pixmap;
1075
1076         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1077                 mainwin = (MainWindow *)cur->data;
1078
1079                 main_window_show_cur_account(mainwin);
1080                 main_window_set_menu_sensitive(mainwin);
1081                 toolbar_main_set_sensitive(mainwin);
1082
1083                 /* pixmap themes */
1084                 if (pixmap_theme_changed) {
1085                         toolbar_update(TOOLBAR_MAIN, mainwin);
1086                         messageview_reflect_prefs_pixmap_theme();
1087                         compose_reflect_prefs_pixmap_theme();
1088                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1089                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1090
1091                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
1092                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1093                                              mainwin->online_pixmap);
1094                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1095                         gtk_widget_show(pixmap);
1096                         mainwin->online_pixmap = pixmap;
1097                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
1098                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1099                                              mainwin->offline_pixmap);
1100                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1101                         gtk_widget_show(pixmap);
1102                         mainwin->offline_pixmap = pixmap;
1103                 }
1104                 
1105                 summary_redisplay_msg(mainwin->summaryview);
1106                 headerview_set_visibility(mainwin->messageview->headerview,
1107                                           prefs_common.display_header_pane);
1108         }
1109 }
1110
1111 void main_window_set_summary_column(void)
1112 {
1113         GList *cur;
1114         MainWindow *mainwin;
1115
1116         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1117                 mainwin = (MainWindow *)cur->data;
1118                 summary_set_column_order(mainwin->summaryview);
1119         }
1120 }
1121
1122 void main_window_set_account_menu(GList *account_list)
1123 {
1124         GList *cur, *cur_ac, *cur_item;
1125         GtkWidget *menuitem;
1126         MainWindow *mainwin;
1127         PrefsAccount *ac_prefs;
1128
1129         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1130                 mainwin = (MainWindow *)cur->data;
1131
1132                 /* destroy all previous menu item */
1133                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1134                 while (cur_item != NULL) {
1135                         GList *next = cur_item->next;
1136                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1137                         cur_item = next;
1138                 }
1139
1140                 for (cur_ac = account_list; cur_ac != NULL;
1141                      cur_ac = cur_ac->next) {
1142                         ac_prefs = (PrefsAccount *)cur_ac->data;
1143
1144                         menuitem = gtk_menu_item_new_with_label
1145                                 (ac_prefs->account_name
1146                                  ? ac_prefs->account_name : _("Untitled"));
1147                         gtk_widget_show(menuitem);
1148                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1149                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1150                                            GTK_SIGNAL_FUNC(account_menu_cb),
1151                                            ac_prefs);
1152                 }
1153         }
1154 }
1155
1156 static void main_window_show_cur_account(MainWindow *mainwin)
1157 {
1158         gchar *buf;
1159         gchar *ac_name;
1160
1161         ac_name = g_strdup(cur_account
1162                            ? (cur_account->account_name
1163                               ? cur_account->account_name : _("Untitled"))
1164                            : _("none"));
1165
1166         if (cur_account)
1167                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1168         else
1169                 buf = g_strdup(PROG_VERSION);
1170         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1171         g_free(buf);
1172
1173         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1174         gtk_widget_queue_resize(mainwin->ac_button);
1175
1176         g_free(ac_name);
1177 }
1178
1179 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1180 {
1181         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1182         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1183         //GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1184         GtkWidget *message_wid = mainwin->messageview->vbox;
1185
1186         debug_print("Changing window separation type from %d to %d\n",
1187                     mainwin->type, type);
1188
1189         if (mainwin->type == type) return;
1190
1191         /* remove widgets from those containers */
1192         gtk_widget_ref(folder_wid);
1193         gtk_widget_ref(summary_wid);
1194         gtk_widget_ref(message_wid);
1195         gtkut_container_remove
1196                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1197         gtkut_container_remove
1198                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1199         gtkut_container_remove
1200                 (GTK_CONTAINER(message_wid->parent), message_wid);
1201
1202         /* clean containers */
1203         switch (mainwin->type) {
1204         case SEPARATE_NONE:
1205                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1206                 break;
1207         case SEPARATE_FOLDER:
1208                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1209                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1210                 break;
1211         case SEPARATE_MESSAGE:
1212                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1213                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1214                 break;
1215         case SEPARATE_BOTH:
1216                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1217                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1218                 break;
1219         }
1220
1221         gtk_widget_hide(mainwin->window);
1222         main_window_set_widgets(mainwin, type);
1223         gtk_widget_show(mainwin->window);
1224
1225         gtk_widget_unref(folder_wid);
1226         gtk_widget_unref(summary_wid);
1227         gtk_widget_unref(message_wid);
1228 }
1229
1230 void main_window_toggle_message_view(MainWindow *mainwin)
1231 {
1232         SummaryView *summaryview = mainwin->summaryview;
1233         union CompositeWin *cwin = &mainwin->win;
1234         GtkWidget *vpaned = NULL;
1235         GtkWidget *container = NULL;
1236         GtkWidget *msgwin = NULL;
1237
1238         switch (mainwin->type) {
1239         case SEPARATE_NONE:
1240                 vpaned = cwin->sep_none.vpaned;
1241                 container = cwin->sep_none.hpaned;
1242                 break;
1243         case SEPARATE_FOLDER:
1244                 vpaned = cwin->sep_folder.vpaned;
1245                 container = mainwin->vbox_body;
1246                 break;
1247         case SEPARATE_MESSAGE:
1248                 msgwin = mainwin->win.sep_message.messagewin;
1249                 break;
1250         case SEPARATE_BOTH:
1251                 msgwin = mainwin->win.sep_both.messagewin;
1252                 break;
1253         }
1254
1255         if (msgwin) {
1256                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1257                         gtk_widget_hide(msgwin);
1258                         mainwin->messageview->visible = FALSE;
1259                         summaryview->displayed = NULL;
1260                 } else {
1261                         gtk_widget_show(msgwin);
1262                         mainwin->messageview->visible = TRUE;
1263                 }
1264         } else if (vpaned->parent != NULL) {
1265                 mainwin->messageview->visible = FALSE;
1266                 summaryview->displayed = NULL;
1267                 gtk_widget_ref(vpaned);
1268                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1269                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1270                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1271                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1272         } else {
1273                 mainwin->messageview->visible = TRUE;
1274                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1275                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1276                 gtk_widget_unref(vpaned);
1277                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1278                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1279         }
1280
1281         main_window_set_menu_sensitive(mainwin);
1282
1283         gtk_widget_grab_focus(summaryview->ctree);
1284 }
1285
1286 void main_window_get_size(MainWindow *mainwin)
1287 {
1288         GtkAllocation *allocation;
1289
1290         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1291
1292         prefs_common.summaryview_width  = allocation->width;
1293
1294         if ((mainwin->type == SEPARATE_NONE ||
1295              mainwin->type == SEPARATE_FOLDER) &&
1296             messageview_is_visible(mainwin->messageview))
1297                 prefs_common.summaryview_height = allocation->height;
1298
1299         prefs_common.mainview_width     = allocation->width;
1300
1301         allocation = &mainwin->window->allocation;
1302
1303         prefs_common.mainview_height = allocation->height;
1304         prefs_common.mainwin_width   = allocation->width;
1305         prefs_common.mainwin_height  = allocation->height;
1306
1307         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1308
1309         prefs_common.folderview_width  = allocation->width;
1310         prefs_common.folderview_height = allocation->height;
1311 }
1312
1313 void main_window_get_position(MainWindow *mainwin)
1314 {
1315         gint x, y;
1316
1317         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1318
1319         prefs_common.mainview_x = x;
1320         prefs_common.mainview_y = y;
1321         prefs_common.mainwin_x = x;
1322         prefs_common.mainwin_y = y;
1323
1324         debug_print("window position: x = %d, y = %d\n", x, y);
1325 }
1326
1327 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1328 {
1329         GList *list;
1330         guint has_trash;
1331         Folder *folder;
1332
1333         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1334                 folder = FOLDER(list->data);
1335                 if (folder && folder->trash && folder->trash->total > 0)
1336                         has_trash++;
1337         }
1338
1339         if (!has_trash) return;
1340         
1341         if (confirm) {
1342                 if (alertpanel(_("Empty trash"),
1343                                _("Empty all messages in trash?"),
1344                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1345                         return;
1346                 manage_window_focus_in(mainwin->window, NULL, NULL);
1347         }
1348
1349         procmsg_empty_trash();
1350
1351         for (list = folder_get_list(); list != NULL; list = list->next) {
1352                 folder = list->data;
1353                 if (folder && folder->trash) {
1354                         folder_update_item(folder->trash, TRUE);
1355                 }
1356         }
1357
1358         if (mainwin->summaryview->folder_item &&
1359             mainwin->summaryview->folder_item->stype == F_TRASH)
1360                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1361 }
1362
1363 void main_window_add_mailbox(MainWindow *mainwin)
1364 {
1365         gchar *path;
1366         Folder *folder;
1367
1368         path = input_dialog(_("Add mailbox"),
1369                             _("Input the location of mailbox.\n"
1370                               "If the existing mailbox is specified, it will be\n"
1371                               "scanned automatically."),
1372                             "Mail");
1373         if (!path) return;
1374         if (folder_find_from_path(path)) {
1375                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1376                 g_free(path);
1377                 return;
1378         }
1379         if (!strcmp(path, "Mail"))
1380                 folder = folder_new(F_MH, _("Mailbox"), path);
1381         else
1382                 folder = folder_new(F_MH, g_basename(path), path);
1383         g_free(path);
1384
1385         if (folder->create_tree(folder) < 0) {
1386                 alertpanel_error(_("Creation of the mailbox failed.\n"
1387                                    "Maybe some files already exist, or you don't have the permission to write there."));
1388                 folder_destroy(folder);
1389                 return;
1390         }
1391
1392         folder_add(folder);
1393         folder_set_ui_func(folder, scan_tree_func, mainwin);
1394         folder_scan_tree(folder);
1395         folder_set_ui_func(folder, NULL, NULL);
1396
1397         folderview_set(mainwin->folderview);
1398 }
1399
1400 void main_window_add_mbox(MainWindow *mainwin)
1401 {
1402         gchar *path;
1403         Folder *folder;
1404         FolderItem * item;
1405
1406         path = input_dialog(_("Add mbox mailbox"),
1407                             _("Input the location of mailbox."),
1408                             "mail");
1409
1410         if (!path) return;
1411
1412         if (folder_find_from_path(path)) {
1413                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1414                 g_free(path);
1415                 return;
1416         }
1417
1418         /*
1419         if (!strcmp(path, "Mail"))
1420                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1421                 else
1422         */
1423
1424         folder = folder_new(F_MBOX, g_basename(path), path);
1425         g_free(path);
1426
1427         if (folder->create_tree(folder) < 0) {
1428                 alertpanel_error(_("Creation of the mailbox failed."));
1429                 folder_destroy(folder);
1430                 return;
1431         }
1432
1433         folder_add(folder);
1434
1435         item = folder_item_new(folder, folder->name, NULL);
1436         item->folder = folder;
1437         folder->node = g_node_new(item);
1438
1439         folder_create_folder(item, "inbox");
1440         folder_create_folder(item, "outbox");
1441         folder_create_folder(item, "queue");
1442         folder_create_folder(item, "draft");
1443         folder_create_folder(item, "trash");
1444
1445         folderview_set(mainwin->folderview);
1446 }
1447
1448 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1449 {
1450         SensitiveCond state = 0;
1451         SummarySelection selection;
1452         FolderItem *item = mainwin->summaryview->folder_item;
1453         GList *account_list = account_get_list();
1454         
1455         selection = summary_get_selection_type(mainwin->summaryview);
1456
1457         if (mainwin->lock_count == 0)
1458                 state |= M_UNLOCKED;
1459         if (selection != SUMMARY_NONE)
1460                 state |= M_MSG_EXIST;
1461         if (item && item->path && item->parent && !item->no_select) {
1462                 state |= M_EXEC;
1463                 /*              if (item->folder->type != F_NEWS) */
1464                 state |= M_ALLOW_DELETE;
1465
1466                 if (prefs_common.immediate_exec == 0
1467                     && mainwin->lock_count == 0)
1468                         state |= M_DELAY_EXEC;
1469
1470                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1471                     || selection != SUMMARY_NONE)
1472                         state |= M_HIDE_READ_MSG;       
1473         }               
1474         if (mainwin->summaryview->threaded)
1475                 state |= M_THREADED;
1476         else
1477                 state |= M_UNTHREADED;  
1478         if (selection == SUMMARY_SELECTED_SINGLE ||
1479             selection == SUMMARY_SELECTED_MULTIPLE)
1480                 state |= M_TARGET_EXIST;
1481         if (selection == SUMMARY_SELECTED_SINGLE)
1482                 state |= M_SINGLE_TARGET_EXIST;
1483         if (mainwin->summaryview->folder_item &&
1484             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1485                 state |= M_NEWS;
1486         else
1487                 state |= M_NOT_NEWS;
1488         if (selection == SUMMARY_SELECTED_SINGLE &&
1489             (item &&
1490              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1491               item->stype == F_QUEUE)))
1492                 state |= M_ALLOW_REEDIT;
1493         if (cur_account)
1494                 state |= M_HAVE_ACCOUNT;
1495         
1496         for ( ; account_list != NULL; account_list = account_list->next) {
1497                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1498                         state |= M_HAVE_NEWS_ACCOUNT;
1499                         break;
1500                 }
1501         }
1502
1503         if (inc_is_active())
1504                 state |= M_INC_ACTIVE;
1505
1506         return state;
1507 }
1508
1509
1510
1511 void main_window_set_menu_sensitive(MainWindow *mainwin)
1512 {
1513         GtkItemFactory *ifactory = mainwin->menu_factory;
1514         SensitiveCond state;
1515         gboolean sensitive;
1516         GtkWidget *menuitem;
1517         SummaryView *summaryview;
1518         gchar *menu_path;
1519         gint i;
1520
1521         static const struct {
1522                 gchar *const entry;
1523                 SensitiveCond cond;
1524         } entry[] = {
1525                 {"/File/Add mailbox..."                       , M_UNLOCKED},
1526                 {"/File/Add mbox mailbox..."                  , M_UNLOCKED},
1527                 {"/File/Check for new messages in all folders", M_UNLOCKED},
1528                 {"/File/Folder"                               , M_UNLOCKED},
1529                 {"/File/Import mbox file..."                  , M_UNLOCKED},
1530                 {"/File/Export to mbox file..."               , M_UNLOCKED},
1531                 {"/File/Empty trash"                          , M_UNLOCKED},
1532                 {"/File/Work offline"                         , M_UNLOCKED},
1533
1534                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1535                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1536                 /* {"/File/Close"  , M_UNLOCKED}, */
1537                 {"/File/Exit"      , M_UNLOCKED},
1538
1539                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
1540
1541                 {"/View/Sort"                      , M_EXEC},
1542                 {"/View/Thread view"               , M_EXEC},
1543                 {"/View/Expand all threads"        , M_MSG_EXIST},
1544                 {"/View/Collapse all threads"      , M_MSG_EXIST},
1545                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1546                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1547                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1548                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1549                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1550                 {"/View/Go to/Prev new message"    , M_MSG_EXIST},
1551                 {"/View/Go to/Next new message"    , M_MSG_EXIST},
1552                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1553                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1554                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1555                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1556                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1557                 {"/View/Show all headers"          , M_SINGLE_TARGET_EXIST},
1558                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
1559
1560                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1561                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1562                 {"/Message/Cancel receiving"      , M_INC_ACTIVE},
1563                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1564                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1565                 {"/Message/Reply to"             , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1566                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1567                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1568                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1569                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1570                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1571                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1572                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
1573                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NEWS},
1574                 {"/Message/Mark"                  , M_TARGET_EXIST},
1575
1576                 {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
1577                 {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
1578                 {"/Tools/Harvest addresses"         , M_UNLOCKED},
1579                 {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1580                 {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1581                 {"/Tools/Actions"                   , M_TARGET_EXIST|M_UNLOCKED},
1582                 {"/Tools/Execute"                   , M_DELAY_EXEC},
1583                 {"/Tools/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1584
1585                 {"/Configuration", M_UNLOCKED},
1586
1587                 {NULL, 0}
1588         };
1589
1590         state = main_window_get_current_state(mainwin);
1591
1592         for (i = 0; entry[i].entry != NULL; i++) {
1593                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1594                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1595         }
1596
1597         main_window_menu_callback_block(mainwin);
1598
1599 #define SET_CHECK_MENU_ACTIVE(path, active) \
1600 { \
1601         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1602         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1603 }
1604
1605         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1606                               messageview_is_visible(mainwin->messageview));
1607
1608         summaryview = mainwin->summaryview;
1609         menu_path = "/View/Sort/Don't sort";
1610
1611         switch (summaryview->sort_key) {
1612         case SORT_BY_NUMBER:
1613                 menu_path = "/View/Sort/by number"; break;
1614         case SORT_BY_SIZE:
1615                 menu_path = "/View/Sort/by size"; break;
1616         case SORT_BY_DATE:
1617                 menu_path = "/View/Sort/by date"; break;
1618         case SORT_BY_FROM:
1619                 menu_path = "/View/Sort/by from"; break;
1620         case SORT_BY_TO:
1621                 menu_path = "/View/Sort/by recipient"; break;
1622         case SORT_BY_SUBJECT:
1623                 menu_path = "/View/Sort/by subject"; break;
1624         case SORT_BY_LABEL:
1625                 menu_path = "/View/Sort/by color label"; break;
1626         case SORT_BY_MARK:
1627                 menu_path = "/View/Sort/by mark"; break;
1628         case SORT_BY_UNREAD:
1629                 menu_path = "/View/Sort/by unread"; break;
1630         case SORT_BY_MIME:
1631                 menu_path = "/View/Sort/by attachment"; break;
1632         case SORT_BY_SCORE:
1633                 menu_path = "/View/Sort/by score"; break;
1634         case SORT_BY_LOCKED:
1635                 menu_path = "/View/Sort/by locked"; break;
1636         case SORT_BY_NONE:
1637         default:
1638                 menu_path = "/View/Sort/Don't sort"; break;
1639         }
1640         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1641
1642         if (summaryview->sort_type == SORT_ASCENDING) {
1643                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1644         } else {
1645                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1646         }
1647
1648         if (summaryview->sort_key != SORT_BY_NONE) {
1649                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1650                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1651         } else {
1652                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1653                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1654         }
1655
1656         SET_CHECK_MENU_ACTIVE("/View/Show all headers",
1657                               mainwin->messageview->textview->show_all_headers);
1658         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1659
1660 #undef SET_CHECK_MENU_ACTIVE
1661
1662         main_window_menu_callback_unblock(mainwin);
1663 }
1664
1665 void main_window_popup(MainWindow *mainwin)
1666 {
1667         gtkut_window_popup(mainwin->window);
1668
1669         switch (mainwin->type) {
1670         case SEPARATE_FOLDER:
1671                 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
1672                 break;
1673         case SEPARATE_MESSAGE:
1674                 gtkut_window_popup(mainwin->win.sep_message.messagewin);
1675                 break;
1676         case SEPARATE_BOTH:
1677                 gtkut_window_popup(mainwin->win.sep_both.folderwin);
1678                 gtkut_window_popup(mainwin->win.sep_both.messagewin);
1679                 break;
1680         default:
1681                 break;
1682         }
1683 }
1684
1685 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1686 {
1687         GtkWidget *folderwin = NULL;
1688         GtkWidget *messagewin = NULL;
1689         GtkWidget *hpaned;
1690         GtkWidget *vpaned;
1691         GtkWidget *vbox_body = mainwin->vbox_body;
1692         GtkItemFactory *ifactory = mainwin->menu_factory;
1693         GtkWidget *menuitem;
1694         GtkItemFactory *msgview_ifactory;
1695
1696         debug_print("Setting widgets...");
1697
1698         /* create separated window(s) if needed */
1699         if (type & SEPARATE_FOLDER) {
1700                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1701                 gtk_window_set_title(GTK_WINDOW(folderwin),
1702                                      _("Sylpheed - Folder View"));
1703                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1704                                        "folder_view", "Sylpheed");
1705                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1706                                       TRUE, TRUE, FALSE);
1707                 gtk_widget_set_usize(folderwin, -1,
1708                                      prefs_common.mainview_height);
1709                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1710                                                BORDER_WIDTH);
1711                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1712                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1713                                    mainwin);
1714         }
1715         if (type & SEPARATE_MESSAGE) {
1716                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1717                 gtk_window_set_title(GTK_WINDOW(messagewin),
1718                                      _("Sylpheed - Message View"));
1719                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1720                                        "message_view", "Sylpheed");
1721                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1722                                       TRUE, TRUE, FALSE);
1723                 gtk_widget_set_usize
1724                         (messagewin, prefs_common.mainview_width,
1725                          prefs_common.mainview_height
1726                          - prefs_common.summaryview_height
1727                          + DEFAULT_HEADERVIEW_HEIGHT);
1728                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1729                                                BORDER_WIDTH);
1730                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1731                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1732                                    mainwin);
1733         }
1734
1735         switch (type) {
1736         case SEPARATE_NONE:
1737                 hpaned = gtk_hpaned_new();
1738                 gtk_widget_show(hpaned);
1739                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1740                 gtk_paned_add1(GTK_PANED(hpaned),
1741                                GTK_WIDGET_PTR(mainwin->folderview));
1742
1743                 vpaned = gtk_vpaned_new();
1744                 if (messageview_is_visible(mainwin->messageview)) {
1745                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1746                         gtk_paned_add1(GTK_PANED(vpaned),
1747                                        GTK_WIDGET_PTR(mainwin->summaryview));
1748                 } else {
1749                         gtk_paned_add2(GTK_PANED(hpaned),
1750                                        GTK_WIDGET_PTR(mainwin->summaryview));
1751                         gtk_widget_ref(vpaned);
1752                 }
1753                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1754                                      prefs_common.summaryview_width,
1755                                      prefs_common.summaryview_height);
1756                 gtk_paned_add2(GTK_PANED(vpaned),
1757                                GTK_WIDGET_PTR(mainwin->messageview));
1758                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1759                                      prefs_common.mainview_width, -1);
1760                 gtk_widget_set_usize(mainwin->window,
1761                                      prefs_common.folderview_width +
1762                                      prefs_common.mainview_width,
1763                                      prefs_common.mainwin_height);
1764                 gtk_widget_show_all(vpaned);
1765
1766                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1767                  * lose track of its visibility state */
1768                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1769                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1770
1771                 mainwin->win.sep_none.hpaned = hpaned;
1772                 mainwin->win.sep_none.vpaned = vpaned;
1773                 
1774                 /* remove headerview if not in prefs */
1775                 headerview_set_visibility(mainwin->messageview->headerview,
1776                                           prefs_common.display_header_pane);
1777                 break;
1778         case SEPARATE_FOLDER:
1779                 vpaned = gtk_vpaned_new();
1780                 if (messageview_is_visible(mainwin->messageview)) {
1781                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1782                                            TRUE, TRUE, 0);
1783                         gtk_paned_add1(GTK_PANED(vpaned),
1784                                        GTK_WIDGET_PTR(mainwin->summaryview));
1785                 } else {
1786                         gtk_box_pack_start(GTK_BOX(vbox_body),
1787                                            GTK_WIDGET_PTR(mainwin->summaryview),
1788                                            TRUE, TRUE, 0);
1789                         gtk_widget_ref(vpaned);
1790                 }
1791                 gtk_paned_add2(GTK_PANED(vpaned),
1792                                GTK_WIDGET_PTR(mainwin->messageview));
1793                 gtk_widget_show_all(vpaned);
1794                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1795                                      prefs_common.summaryview_width,
1796                                      prefs_common.summaryview_height);
1797                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1798                                      prefs_common.mainview_width, -1);
1799                 gtk_widget_set_usize(mainwin->window,
1800                                      prefs_common.mainview_width,
1801                                      prefs_common.mainview_height);
1802
1803                 gtk_container_add(GTK_CONTAINER(folderwin),
1804                                   GTK_WIDGET_PTR(mainwin->folderview));
1805
1806                 mainwin->win.sep_folder.folderwin = folderwin;
1807                 mainwin->win.sep_folder.vpaned    = vpaned;
1808
1809                 gtk_widget_show_all(folderwin);
1810                 
1811                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1812                  * lose track of its visibility state */
1813                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1814                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1815                 
1816                 /* remove headerview if not in prefs */
1817                 headerview_set_visibility(mainwin->messageview->headerview,
1818                                           prefs_common.display_header_pane);
1819                 
1820                 break;
1821         case SEPARATE_MESSAGE:
1822                 hpaned = gtk_hpaned_new();
1823                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1824
1825                 gtk_paned_add1(GTK_PANED(hpaned),
1826                                GTK_WIDGET_PTR(mainwin->folderview));
1827                 gtk_paned_add2(GTK_PANED(hpaned),
1828                                GTK_WIDGET_PTR(mainwin->summaryview));
1829                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1830                                      prefs_common.summaryview_width,
1831                                      prefs_common.summaryview_height);
1832                 gtk_widget_set_usize(mainwin->window,
1833                                      prefs_common.folderview_width +
1834                                      prefs_common.mainview_width,
1835                                      prefs_common.mainwin_height);
1836                 gtk_widget_show_all(hpaned);
1837
1838                 messageview_add_toolbar(mainwin->messageview, messagewin);
1839                 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
1840                 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
1841
1842                 mainwin->win.sep_message.messagewin = messagewin;
1843                 mainwin->win.sep_message.hpaned     = hpaned;
1844
1845                 gtk_widget_show_all(messagewin);
1846                 
1847                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1848                  * lose track of its visibility state */
1849                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1850                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1851                 break;
1852         case SEPARATE_BOTH:
1853                 gtk_box_pack_start(GTK_BOX(vbox_body),
1854                                    GTK_WIDGET_PTR(mainwin->summaryview),
1855                                    TRUE, TRUE, 0);
1856                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1857                                      prefs_common.summaryview_width,
1858                                      prefs_common.summaryview_height);
1859                 gtk_widget_set_usize(mainwin->window,
1860                                      prefs_common.mainview_width,
1861                                      prefs_common.mainwin_height);
1862                 gtk_container_add(GTK_CONTAINER(folderwin),
1863                                   GTK_WIDGET_PTR(mainwin->folderview));
1864                 gtk_container_add(GTK_CONTAINER(messagewin),
1865                                   GTK_WIDGET_PTR(mainwin->messageview));
1866
1867                 mainwin->win.sep_both.folderwin = folderwin;
1868                 mainwin->win.sep_both.messagewin = messagewin;
1869
1870                 gtk_widget_show_all(folderwin);
1871                 gtk_widget_show_all(messagewin);
1872
1873                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1874                  * lose track of its visibility state */
1875                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1876                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1877                 break;
1878         }
1879
1880         /* rehide quick search if necessary */
1881         if (!prefs_common.show_searchbar)
1882                 gtk_widget_hide(mainwin->summaryview->hbox_search);
1883         
1884         mainwin->type = type;
1885
1886         mainwin->messageview->visible = TRUE;
1887
1888         /* toggle menu state */
1889         menuitem = gtk_item_factory_get_item
1890                 (ifactory, "/View/Show or hide/Folder tree");
1891         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1892         menuitem = gtk_item_factory_get_item
1893                 (ifactory, "/View/Show or hide/Message view");
1894         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1895
1896         menuitem = gtk_item_factory_get_item
1897                 (ifactory, "/View/Separate folder tree");
1898         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1899                                        ((type & SEPARATE_FOLDER) != 0));
1900         menuitem = gtk_item_factory_get_item
1901                 (ifactory, "/View/Separate message view");
1902         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1903                                        ((type & SEPARATE_MESSAGE) != 0));
1904
1905         debug_print("done.\n");
1906 }
1907
1908 void main_window_destroy_all(void)
1909 {
1910         while (mainwin_list != NULL) {
1911                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
1912                 
1913                 /* free toolbar stuff */
1914                 toolbar_clear_list(TOOLBAR_MAIN);
1915                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
1916                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
1917
1918                 g_free(mainwin->toolbar);
1919                 g_free(mainwin);
1920                 
1921                 mainwin_list = g_list_remove(mainwin_list, mainwin);
1922         }
1923         g_list_free(mainwin_list);
1924 }
1925
1926 #if 0
1927 static void toolbar_account_button_pressed(GtkWidget *widget,
1928                                            GdkEventButton *event,
1929                                            gpointer data)
1930 {
1931         MainWindow *mainwin = (MainWindow *)data;
1932
1933         if (!event) return;
1934         if (event->button != 3) return;
1935
1936         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1937         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1938                             widget);
1939
1940         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1941                        menu_button_position, widget,
1942                        event->button, event->time);
1943 }
1944 #endif
1945
1946 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1947                                     gpointer data)
1948 {
1949         MainWindow *mainwin = (MainWindow *)data;
1950
1951         if (!event) return;
1952
1953         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1954         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1955                             widget);
1956
1957         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1958                        menu_button_position, widget,
1959                        event->button, event->time);
1960 }
1961
1962 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
1963 {
1964         MainWindow *mainwin = (MainWindow *)data;
1965         GtkWidget *button;
1966
1967         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
1968         if (!button) return;
1969         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1970         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
1971         manage_window_focus_in(mainwin->window, NULL, NULL);
1972 }
1973
1974 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1975                                  gpointer data)
1976 {
1977         MainWindow *mainwin = (MainWindow *)data;
1978
1979         if (mainwin->lock_count == 0)
1980                 app_exit_cb(data, 0, widget);
1981
1982         return TRUE;
1983 }
1984
1985 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1986                                    gpointer data)
1987 {
1988         MainWindow *mainwin = (MainWindow *)data;
1989         GtkWidget *menuitem;
1990
1991         menuitem = gtk_item_factory_get_item
1992                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
1993         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1994
1995         return TRUE;
1996 }
1997
1998 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1999                                     gpointer data)
2000 {
2001         MainWindow *mainwin = (MainWindow *)data;
2002         GtkWidget *menuitem;
2003
2004         menuitem = gtk_item_factory_get_item
2005                 (mainwin->menu_factory, "/View/Show or hide/Message view");
2006         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2007
2008         return TRUE;
2009 }
2010
2011 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2012                            GtkWidget *widget)
2013 {
2014         main_window_add_mailbox(mainwin);
2015 }
2016
2017 static void add_mbox_cb(MainWindow *mainwin, guint action,
2018                         GtkWidget *widget)
2019 {
2020         main_window_add_mbox(mainwin);
2021 }
2022
2023 static void update_folderview_cb(MainWindow *mainwin, guint action,
2024                                  GtkWidget *widget)
2025 {
2026         summary_show(mainwin->summaryview, NULL);
2027         folderview_check_new_all();
2028 }
2029
2030 static void new_folder_cb(MainWindow *mainwin, guint action,
2031                           GtkWidget *widget)
2032 {
2033         folderview_new_folder(mainwin->folderview);
2034 }
2035
2036 static void rename_folder_cb(MainWindow *mainwin, guint action,
2037                              GtkWidget *widget)
2038 {
2039         folderview_rename_folder(mainwin->folderview);
2040 }
2041
2042 static void delete_folder_cb(MainWindow *mainwin, guint action,
2043                              GtkWidget *widget)
2044 {
2045         folderview_delete_folder(mainwin->folderview);
2046 }
2047
2048 static void import_mbox_cb(MainWindow *mainwin, guint action,
2049                            GtkWidget *widget)
2050 {
2051         import_mbox(mainwin->summaryview->folder_item);
2052 }
2053
2054 static void export_mbox_cb(MainWindow *mainwin, guint action,
2055                            GtkWidget *widget)
2056 {
2057         export_mbox(mainwin->summaryview->folder_item);
2058 }
2059
2060 static void empty_trash_cb(MainWindow *mainwin, guint action,
2061                            GtkWidget *widget)
2062 {
2063         main_window_empty_trash(mainwin, TRUE);
2064 }
2065
2066 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2067 {
2068         summary_save_as(mainwin->summaryview);
2069 }
2070
2071 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2072 {
2073         summary_print(mainwin->summaryview);
2074 }
2075
2076 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2077 {
2078         if (prefs_common.confirm_on_exit) {
2079                 if (alertpanel(_("Exit"), _("Exit this program?"),
2080                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2081                         return;
2082                 manage_window_focus_in(mainwin->window, NULL, NULL);
2083         }
2084
2085         app_will_exit(widget, mainwin);
2086 }
2087
2088 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2089 {
2090         if (action == 1)
2091                 summary_search(mainwin->summaryview);
2092         else
2093                 message_search(mainwin->messageview);
2094 }
2095
2096 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2097                              GtkWidget *widget)
2098 {
2099         gboolean active;
2100
2101         active = GTK_CHECK_MENU_ITEM(widget)->active;
2102
2103         switch (mainwin->type) {
2104         case SEPARATE_NONE:
2105         case SEPARATE_MESSAGE:
2106 #if 0
2107                 if (active)
2108                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2109                 else
2110                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2111 #endif
2112                 break;
2113         case SEPARATE_FOLDER:
2114                 debug_print("separate folder\n");
2115                 if (active)
2116                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2117                 else
2118                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2119                 break;
2120         case SEPARATE_BOTH:
2121                 if (active)
2122                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2123                 else
2124                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2125                 break;
2126         }
2127 }
2128
2129 static void toggle_message_cb(MainWindow *mainwin, guint action,
2130                               GtkWidget *widget)
2131 {
2132         gboolean active;
2133
2134         active = GTK_CHECK_MENU_ITEM(widget)->active;
2135
2136         if (active != messageview_is_visible(mainwin->messageview))
2137                 summary_toggle_view(mainwin->summaryview);
2138 }
2139
2140 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2141                               GtkWidget *widget)
2142 {
2143         toolbar_toggle(action, mainwin);
2144 }
2145
2146 /* END Toolbar Stuff */
2147
2148 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2149                                 GtkWidget *widget)
2150 {
2151         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2152                 gtk_widget_show(mainwin->hbox_stat);
2153                 prefs_common.show_statusbar = TRUE;
2154         } else {
2155                 gtk_widget_hide(mainwin->hbox_stat);
2156                 prefs_common.show_statusbar = FALSE;
2157         }
2158 }
2159
2160 static void separate_widget_cb(MainWindow *mainwin, guint action,
2161                                GtkWidget *widget)
2162 {
2163         SeparateType type;
2164
2165         if (GTK_CHECK_MENU_ITEM(widget)->active)
2166                 type = mainwin->type | action;
2167         else
2168                 type = mainwin->type & ~action;
2169
2170         main_window_separation_change(mainwin, type);
2171
2172         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2173         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2174 }
2175
2176 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline)
2177 {
2178         if (offline)
2179                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2180         else
2181                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
2182 }
2183
2184 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
2185 {
2186         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active);
2187 }
2188
2189 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2190 {
2191         MainWindow *mainwin;
2192         GtkItemFactory *ifactory;
2193         GtkCheckMenuItem *menuitem;
2194
2195         mainwin = (MainWindow *) data;
2196         
2197         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2198         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2199         
2200         g_return_if_fail(mainwin != NULL);
2201         g_return_if_fail(menuitem != NULL);
2202         
2203         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2204                 /* go offline */
2205                 gtk_widget_hide (mainwin->online_switch);
2206                 gtk_widget_show (mainwin->offline_switch);
2207                 menuitem->active = TRUE;
2208                 prefs_common.work_offline = TRUE;
2209                 inc_autocheck_timer_remove();           
2210         } else {
2211                 /*go online */
2212                 gtk_widget_hide (mainwin->offline_switch);
2213                 gtk_widget_show (mainwin->online_switch);
2214                 menuitem->active = FALSE;
2215                 prefs_common.work_offline = FALSE;
2216                 inc_autocheck_timer_set();
2217         }
2218 }
2219
2220 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2221                                 GtkWidget *widget)
2222 {
2223         addressbook_open(NULL);
2224 }
2225
2226 static void log_window_show_cb(MainWindow *mainwin, guint action,
2227                                GtkWidget *widget)
2228 {
2229         log_window_show(mainwin->logwin);
2230 }
2231
2232 static void sel_download_cb(MainWindow *mainwin, guint action,
2233                                GtkWidget *widget)
2234 {
2235         selective_download(mainwin);
2236 }
2237
2238 static void prefs_toolbar_cb(MainWindow *mainwin, guint action,
2239                              GtkWidget *widget)
2240 {
2241         prefs_toolbar_open((ToolbarType)action);
2242 }
2243
2244 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2245 {
2246         inc_cancel_all();
2247 }
2248
2249 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2250 {
2251         summary_move_to(mainwin->summaryview);
2252 }
2253
2254 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2255 {
2256         summary_copy_to(mainwin->summaryview);
2257 }
2258
2259 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2260 {
2261         summary_delete(mainwin->summaryview);
2262 }
2263
2264 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2265 {
2266         summary_cancel(mainwin->summaryview);
2267 }
2268
2269 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2270 {
2271         summary_open_msg(mainwin->summaryview);
2272 }
2273
2274 static void view_source_cb(MainWindow *mainwin, guint action,
2275                            GtkWidget *widget)
2276 {
2277         summary_view_source(mainwin->summaryview);
2278 }
2279
2280 static void show_all_header_cb(MainWindow *mainwin, guint action,
2281                                GtkWidget *widget)
2282 {
2283         if (mainwin->menu_lock_count) return;
2284         summary_display_msg_selected(mainwin->summaryview,
2285                                      GTK_CHECK_MENU_ITEM(widget)->active);
2286 }
2287
2288 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2289 {
2290         summary_reedit(mainwin->summaryview);
2291 }
2292
2293 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2294 {
2295         summary_mark(mainwin->summaryview);
2296 }
2297
2298 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2299 {
2300         summary_unmark(mainwin->summaryview);
2301 }
2302
2303 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2304                               GtkWidget *widget)
2305 {
2306         summary_mark_as_unread(mainwin->summaryview);
2307 }
2308
2309 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2310                             GtkWidget *widget)
2311 {
2312         summary_mark_as_read(mainwin->summaryview);
2313 }
2314
2315 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2316                              GtkWidget *widget)
2317 {
2318         summary_mark_all_read(mainwin->summaryview);
2319 }
2320
2321 static void add_address_cb(MainWindow *mainwin, guint action,
2322                            GtkWidget *widget)
2323 {
2324         summary_add_address(mainwin->summaryview);
2325 }
2326
2327 static void set_charset_cb(MainWindow *mainwin, guint action,
2328                            GtkWidget *widget)
2329 {
2330         const gchar *str;
2331
2332         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2333                 str = conv_get_charset_str((CharSet)action);
2334                 g_free(prefs_common.force_charset);
2335                 prefs_common.force_charset = str ? g_strdup(str) : NULL;
2336
2337                 summary_redisplay_msg(mainwin->summaryview);
2338                 
2339                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
2340         }
2341 }
2342
2343 static void hide_read_messages (MainWindow *mainwin, guint action,
2344                                 GtkWidget *widget)
2345 {
2346         if (!mainwin->summaryview->folder_item
2347             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2348                 return;
2349         summary_toggle_show_read_messages(mainwin->summaryview);
2350 }
2351
2352 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2353 {
2354         if (mainwin->menu_lock_count) return;
2355         if (!mainwin->summaryview->folder_item) return;
2356
2357         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2358                 summary_thread_build(mainwin->summaryview);
2359 /*              mainwin->summaryview->folder_item->threaded = TRUE; */
2360         } else {
2361                 summary_unthread(mainwin->summaryview);
2362 /*              mainwin->summaryview->folder_item->threaded = FALSE; */
2363         }
2364 }
2365
2366 static void expand_threads_cb(MainWindow *mainwin, guint action,
2367                               GtkWidget *widget)
2368 {
2369         summary_expand_threads(mainwin->summaryview);
2370 }
2371
2372 static void collapse_threads_cb(MainWindow *mainwin, guint action,
2373                                 GtkWidget *widget)
2374 {
2375         summary_collapse_threads(mainwin->summaryview);
2376 }
2377
2378 static void set_display_item_cb(MainWindow *mainwin, guint action,
2379                                 GtkWidget *widget)
2380 {
2381         prefs_summary_column_open();
2382 }
2383
2384 static void sort_summary_cb(MainWindow *mainwin, guint action,
2385                             GtkWidget *widget)
2386 {
2387         FolderItem *item = mainwin->summaryview->folder_item;
2388         GtkWidget *menuitem;
2389
2390         if (mainwin->menu_lock_count) return;
2391
2392         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
2393                 menuitem = gtk_item_factory_get_item
2394                         (mainwin->menu_factory, "/View/Sort/Ascending");
2395                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
2396                              GTK_CHECK_MENU_ITEM(menuitem)->active
2397                              ? SORT_ASCENDING : SORT_DESCENDING);
2398         }
2399 }
2400
2401 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
2402                                  GtkWidget *widget)
2403 {
2404         FolderItem *item = mainwin->summaryview->folder_item;
2405
2406         if (mainwin->menu_lock_count) return;
2407
2408         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
2409                 summary_sort(mainwin->summaryview,
2410                              item->sort_key, (FolderSortType)action);
2411 }
2412
2413 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2414                                   GtkWidget *widget)
2415 {
2416         summary_attract_by_subject(mainwin->summaryview);
2417 }
2418
2419 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2420                                  GtkWidget *widget)
2421 {
2422         summary_delete_duplicated(mainwin->summaryview);
2423 }
2424
2425 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2426 {
2427         summary_filter(mainwin->summaryview);
2428 }
2429
2430 static void execute_summary_cb(MainWindow *mainwin, guint action,
2431                                GtkWidget *widget)
2432 {
2433         summary_execute(mainwin->summaryview);
2434 }
2435
2436 static void update_summary_cb(MainWindow *mainwin, guint action,
2437                               GtkWidget *widget)
2438 {
2439         FolderItem *fitem;
2440         FolderView *folderview = mainwin->folderview;
2441
2442         if (!mainwin->summaryview->folder_item) return;
2443         if (!folderview->opened) return;
2444
2445         folder_update_op_count();
2446
2447         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2448                                             folderview->opened);
2449         if (!fitem) return;
2450
2451         folder_item_scan(fitem);
2452         summary_show(mainwin->summaryview, fitem);
2453 }
2454
2455 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2456 {
2457         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2458 }
2459
2460 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2461 {
2462         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2463 }
2464
2465 static void prev_unread_cb(MainWindow *mainwin, guint action,
2466                            GtkWidget *widget)
2467 {
2468         summary_select_prev_unread(mainwin->summaryview);
2469 }
2470
2471 static void next_unread_cb(MainWindow *mainwin, guint action,
2472                            GtkWidget *widget)
2473 {
2474         summary_select_next_unread(mainwin->summaryview);
2475 }
2476
2477 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2478 {
2479         summary_select_prev_new(mainwin->summaryview);
2480 }
2481
2482 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2483 {
2484         summary_select_next_new(mainwin->summaryview);
2485 }
2486
2487 static void prev_marked_cb(MainWindow *mainwin, guint action,
2488                            GtkWidget *widget)
2489 {
2490         summary_select_prev_marked(mainwin->summaryview);
2491 }
2492
2493 static void next_marked_cb(MainWindow *mainwin, guint action,
2494                            GtkWidget *widget)
2495 {
2496         summary_select_next_marked(mainwin->summaryview);
2497 }
2498
2499 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2500                             GtkWidget *widget)
2501 {
2502         summary_select_prev_labeled(mainwin->summaryview);
2503 }
2504
2505 static void next_labeled_cb(MainWindow *mainwin, guint action,
2506                             GtkWidget *widget)
2507 {
2508         summary_select_next_labeled(mainwin->summaryview);
2509 }
2510
2511 static void goto_folder_cb(MainWindow *mainwin, guint action,
2512                            GtkWidget *widget)
2513 {
2514         FolderItem *to_folder;
2515
2516         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2517
2518         if (to_folder)
2519                 folderview_select(mainwin->folderview, to_folder);
2520 }
2521
2522 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2523 {
2524         messageview_copy_clipboard(mainwin->messageview);
2525 }
2526
2527 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2528 {
2529         MessageView *msgview = mainwin->messageview;
2530
2531         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2532                 summary_select_all(mainwin->summaryview);
2533         else if (messageview_is_visible(msgview) &&
2534                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
2535                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
2536                 messageview_select_all(mainwin->messageview);
2537 }
2538
2539 static void select_thread_cb(MainWindow *mainwin, guint action,
2540                              GtkWidget *widget)
2541 {
2542         summary_select_thread(mainwin->summaryview);
2543 }
2544
2545 static void create_filter_cb(MainWindow *mainwin, guint action,
2546                              GtkWidget *widget)
2547 {
2548         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
2549 }
2550
2551 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2552                                  GtkWidget *widget)
2553 {
2554         prefs_common_open();
2555 }
2556
2557 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2558                                   GtkWidget *widget)
2559 {
2560         prefs_scoring_open(NULL);
2561 }
2562
2563 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2564                                     GtkWidget *widget)
2565 {
2566         prefs_filtering_open(NULL, NULL, NULL);
2567 }
2568
2569 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2570                                    GtkWidget *widget)
2571 {
2572         prefs_template_open();
2573 }
2574
2575 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2576                                   GtkWidget *widget)
2577 {
2578         prefs_actions_open(mainwin);
2579 }
2580 #ifdef USE_OPENSSL
2581 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
2582                                   GtkWidget *widget)
2583 {
2584         ssl_manager_open(mainwin);
2585 }
2586 #endif
2587 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2588                                   GtkWidget *widget)
2589 {
2590         if (!cur_account) {
2591                 new_account_cb(mainwin, 0, widget);
2592         } else {
2593                 account_open(cur_account);
2594         }
2595 }
2596
2597 static void new_account_cb(MainWindow *mainwin, guint action,
2598                            GtkWidget *widget)
2599 {
2600         account_edit_open();
2601         if (!compose_get_compose_list()) account_add();
2602 }
2603
2604 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2605 {
2606         cur_account = (PrefsAccount *)data;
2607         main_window_reflect_prefs_all();
2608 }
2609
2610 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
2611 {
2612         prefswindow_create();
2613 }
2614
2615 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
2616 {
2617         pluginwindow_create();
2618 }
2619
2620 static void manual_open_cb(MainWindow *mainwin, guint action,
2621                            GtkWidget *widget)
2622 {
2623         manual_open((ManualType)action);
2624 }
2625
2626 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2627 {
2628         MainWindow *mainwin = (MainWindow *)data;
2629         gchar *str;
2630
2631         if (item->path)
2632                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2633                                       LOCAL_FOLDER(folder)->rootpath,
2634                                       G_DIR_SEPARATOR,
2635                                       item->path);
2636         else
2637                 str = g_strdup_printf(_("Scanning folder %s ..."),
2638                                       LOCAL_FOLDER(folder)->rootpath);
2639
2640         STATUSBAR_PUSH(mainwin, str);
2641         STATUSBAR_POP(mainwin);
2642         g_free(str);
2643 }
2644
2645 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
2646                                           gpointer data)
2647 {
2648         SummaryView *summary;
2649
2650         g_return_val_if_fail(data, FALSE);
2651
2652         if (gtk_grab_get_current()) 
2653                 return FALSE;
2654         
2655         summary = ((MainWindow *)data)->summaryview;
2656         g_return_val_if_fail(summary, FALSE);
2657         if (summary->selected != summary->displayed)
2658                 summary_select_node(summary, summary->displayed, FALSE, TRUE);
2659         return FALSE;
2660 }
2661
2662 #define BREAK_ON_MODIFIER_KEY() \
2663         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
2664
2665 void mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
2666                                     gpointer data)
2667 {
2668         MainWindow *mainwin = (MainWindow*) data;
2669         
2670         if (!mainwin || !event) return;
2671                 
2672         switch (event->keyval) {
2673         case GDK_Q:             /* Quit */
2674                 BREAK_ON_MODIFIER_KEY();
2675
2676                 app_exit_cb(mainwin, 0, NULL);
2677                 return;
2678         case GDK_space:
2679                 if (mainwin->folderview && mainwin->summaryview
2680                     && !mainwin->summaryview->displayed) {
2681                         summary_lock(mainwin->summaryview);
2682                         folderview_select_next_unread(mainwin->folderview);
2683                         summary_unlock(mainwin->summaryview);
2684                 }
2685                 break;
2686         default:
2687                 break;
2688         }
2689 }
2690
2691 #undef BREAK_ON_MODIFIER_KEY
2692
2693 /*
2694  * Harvest addresses for selected folder.
2695  */
2696 static void addr_harvest_cb( MainWindow *mainwin,
2697                             guint action,
2698                             GtkWidget *widget )
2699 {
2700         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
2701 }
2702
2703 /*
2704  * Harvest addresses for selected messages in summary view.
2705  */
2706 static void addr_harvest_msg_cb( MainWindow *mainwin,
2707                             guint action,
2708                             GtkWidget *widget )
2709 {
2710         summary_harvest_address( mainwin->summaryview );
2711 }
2712
2713 /*
2714 * End of Source.
2715 */
2716