2007-01-13 [paul] 2.7.0cvs22
[claws.git] / src / mainwindow.c
index adc43751dad47d1012b07363111844d1e2d14676..37dca7ab274abd499d3d42191fae96c3bcf0a32e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -56,6 +56,7 @@
 #include "stock_pixmap.h"
 #include "folder.h"
 #include "inc.h"
+#include "log.h"
 #include "compose.h"
 #include "procmsg.h"
 #include "import.h"
 #include "filtering.h"
 #include "folderutils.h"
 #include "foldersort.h"
+#include "icon_legend.h"
+#include "colorlabel.h"
+#include "textview.h"
+#include "imap.h"
+#include "socket.h"
 
 #define AC_LABEL_WIDTH 240
 
 /* list of all instantiated MainWindow */
 static GList *mainwin_list = NULL;
 
-static GdkCursor *watch_cursor;
+static GdkCursor *watch_cursor = NULL;
+static GdkCursor *hand_cursor = NULL;
 
 static void main_window_menu_callback_block    (MainWindow     *mainwin);
 static void main_window_menu_callback_unblock  (MainWindow     *mainwin);
@@ -107,12 +114,6 @@ static void main_window_show_cur_account   (MainWindow     *mainwin);
 static void main_window_set_widgets            (MainWindow     *mainwin,
                                                 SeparateType    type);
 
-#if 0
-static gboolean toolbar_account_button_pressed (GtkWidget      *widget,
-                                                GdkEventButton *event,
-                                                gpointer        data);
-#endif
-
 static void toolbar_child_attached             (GtkWidget      *widget,
                                                 GtkWidget      *child,
                                                 gpointer        data);
@@ -219,6 +220,10 @@ static void show_all_header_cb             (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
 
+static void hide_quotes_cb(MainWindow  *mainwin,
+                                        guint           action,
+                                        GtkWidget      *widget);
+
 static void move_to_cb                 (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -252,6 +257,22 @@ static void mark_as_read_cb                (MainWindow     *mainwin,
 static void mark_all_read_cb           (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
+static void mark_as_spam_cb            (MainWindow     *mainwin, 
+                                        guint           action,
+                                        GtkWidget      *widget);
+
+static void ignore_thread_cb           (MainWindow     *mainwin, 
+                                        guint           action,
+                                        GtkWidget      *widget);
+static void unignore_thread_cb         (MainWindow     *mainwin, 
+                                        guint           action,
+                                        GtkWidget      *widget);
+static void lock_msgs_cb               (MainWindow     *mainwin, 
+                                        guint           action,
+                                        GtkWidget      *widget);
+static void unlock_msgs_cb             (MainWindow     *mainwin, 
+                                        guint           action,
+                                        GtkWidget      *widget);
 
 static void reedit_cb                  (MainWindow     *mainwin,
                                         guint           action,
@@ -346,10 +367,19 @@ static void prev_labeled_cb        (MainWindow    *mainwin,
 static void next_labeled_cb     (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void last_read_cb        (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
+static void parent_cb           (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 
 static void goto_folder_cb      (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void goto_unread_folder_cb(MainWindow   *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 
 static void copy_cb             (MainWindow    *mainwin,
                                  guint          action,
@@ -360,6 +390,9 @@ static void allsel_cb                (MainWindow    *mainwin,
 static void select_thread_cb    (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void delete_thread_cb    (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 
 static void create_filter_cb    (MainWindow    *mainwin,
                                  guint          action,
@@ -402,6 +435,8 @@ static void account_selector_menu_cb         (GtkMenuItem   *menuitem,
                                          gpointer       data);
 static void account_receive_menu_cb     (GtkMenuItem   *menuitem,
                                          gpointer       data);
+static void account_compose_menu_cb     (GtkMenuItem   *menuitem,
+                                         gpointer       data);
 
 static void prefs_open_cb      (GtkMenuItem    *menuitem,
                                 gpointer        data);
@@ -415,6 +450,9 @@ static void manual_open_cb   (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
 
+static void legend_open_cb      (GtkMenuItem   *menuitem,
+                                 gpointer       data);
+
 static void scan_tree_func      (Folder        *folder,
                                  FolderItem    *item,
                                  gpointer       data);
@@ -440,10 +478,22 @@ void main_window_reply_cb                 (MainWindow     *mainwin,
                                                 GtkWidget      *widget);
 gboolean mainwindow_progressindicator_hook     (gpointer        source,
                                                 gpointer        userdata);
+
+static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
+                                      MsgInfo *msginfo);
+
+static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
+       
+static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
+
+static void mailing_list_compose(GtkWidget *w, gpointer *data);
+static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
 #define  SEPARATE_ACTION 500 
 static void mainwindow_quicksearch             (MainWindow     *mainwin, 
                                                 guint           action, 
                                                 GtkWidget      *widget);
+static gboolean any_folder_want_synchronise(void);
 
 static GtkItemFactoryEntry mainwin_entries[] =
 {
@@ -451,7 +501,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_File/_Add mailbox"),             NULL, NULL, 0, "<Branch>"},
        {N_("/_File/_Add mailbox/MH..."),       NULL, add_mailbox_cb, 0, NULL},
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
-       {N_("/_File/Change folder order"),      NULL, foldersort_cb,  0, NULL},
+       {N_("/_File/Change folder order..."),   NULL, foldersort_cb,  0, NULL},
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
        {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
@@ -473,6 +523,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
        {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
        {N_("/_Edit/Select _thread"),           NULL, select_thread_cb, 0, NULL},
+       {N_("/_Edit/_Delete thread"),           NULL, delete_thread_cb, 0, NULL},
        {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_Edit/_Find in current message..."),
                                                "<control>F", search_cb, 0, NULL},
@@ -486,16 +537,22 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                "V", toggle_message_cb, 0, "<ToggleItem>"},
        {N_("/_View/Show or hi_de/_Toolbar"),
                                                NULL, NULL, 0, "<Branch>"},
-       {N_("/_View/Show or hi_de/_Toolbar/Icon _and text"),
+       {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
                                                NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
-       {N_("/_View/Show or hi_de/_Toolbar/_Icon"),
-                                               NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Icon and text"},
-       {N_("/_View/Show or hi_de/_Toolbar/_Text"),
-                                               NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Icon and text"},
-       {N_("/_View/Show or hi_de/_Toolbar/_None"),
-                                               NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Icon and text"},
+       {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
+                                               NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
+       {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
+                                               NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
+       {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
+                                               NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
+       {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
+                                               NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
        {N_("/_View/Show or hi_de/Status _bar"),
                                                NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
+       {N_("/_View/Set displayed _columns"),   NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Set displayed _columns/in _Folder list..."),        NULL, set_folder_display_item_cb, 0, NULL},
+       {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
+
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/Separate f_older tree"),    NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
        {N_("/_View/Separate _message view"),   NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
@@ -526,34 +583,37 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
        {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
        {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
-       {N_("/_View/Set displayed _columns"),   NULL, NULL, 0, "<Branch>"},
-       {N_("/_View/Set displayed _columns/in _Folder list..."),        NULL, set_folder_display_item_cb, 0, NULL},
-       {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
 
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
-       {N_("/_View/_Go to/_Prev message"),     "P", prev_cb, 0, NULL},
+       {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
        {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
        {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
-       {N_("/_View/_Go to/P_rev unread message"),
+       {N_("/_View/_Go to/P_revious unread message"),
                                                "<shift>P", prev_unread_cb, 0, NULL},
        {N_("/_View/_Go to/N_ext unread message"),
                                                "<shift>N", next_unread_cb, 0, NULL},
        {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
-       {N_("/_View/_Go to/Prev ne_w message"), NULL, prev_new_cb, 0, NULL},
+       {N_("/_View/_Go to/Previous ne_w message"),     NULL, prev_new_cb, 0, NULL},
        {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
        {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
-       {N_("/_View/_Go to/Prev _marked message"),
+       {N_("/_View/_Go to/Previous _marked message"),
                                                NULL, prev_marked_cb, 0, NULL},
        {N_("/_View/_Go to/Next m_arked message"),
                                                NULL, next_marked_cb, 0, NULL},
        {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
-       {N_("/_View/_Go to/Prev _labeled message"),
+       {N_("/_View/_Go to/Previous _labeled message"),
                                                NULL, prev_labeled_cb, 0, NULL},
        {N_("/_View/_Go to/Next la_beled message"),
                                                NULL, next_labeled_cb, 0, NULL},
        {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
-       {N_("/_View/_Go to/Other _folder..."),  "G", goto_folder_cb, 0, NULL},
+       {N_("/_View/_Go to/Last read message"),
+                                               NULL, last_read_cb, 0, NULL},
+       {N_("/_View/_Go to/Parent message"),
+                                               "<control>Up", parent_cb, 0, NULL},
+       {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
+       {N_("/_View/_Go to/Next unread _folder"),       "<shift>G", goto_unread_folder_cb, 0, NULL},
+       {N_("/_View/_Go to/_Other folder..."),  "G", goto_folder_cb, 0, NULL},
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
 
 #define ENC_SEPARATOR \
@@ -599,6 +659,12 @@ static GtkItemFactoryEntry mainwin_entries[] =
         ENC_ACTION(C_CP1255)},
        ENC_SEPARATOR,
 
+       {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
+        ENC_ACTION(C_ISO_8859_6)},
+       {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
+        ENC_ACTION(C_CP1256)},
+       ENC_SEPARATOR,
+
        {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
         ENC_ACTION(C_ISO_8859_9)},
        ENC_SEPARATOR,
@@ -668,7 +734,11 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
        {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
-       {N_("/_View/Show all headers"),         "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
+       {N_("/_View/All headers"),              "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
+       {N_("/_View/Quotes"),                   NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Quotes/_Fold all"),         "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
+       {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
+       {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
 
@@ -696,6 +766,15 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Message/_Forward"),              "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
        {N_("/_Message/For_ward as attachment"),        NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
        {N_("/_Message/Redirect"),              NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
+
+       {N_("/_Message/Mailing-_List"),                 NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Post"),            NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Help"),            NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Subscribe"),       NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Unsubscribe"),     NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/View archive"),    NULL, NULL, 0, "<Branch>"},
+       {N_("/_Message/Mailing-_List/Contact owner"),   NULL, NULL, 0, "<Branch>"},
+       
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
        {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
@@ -708,9 +787,17 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
        {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
-       {N_("/_Message/_Mark/Mark as rea_d"),
-                                               NULL, mark_as_read_cb, 0, NULL},
+       {N_("/_Message/_Mark/Mark as rea_d"),   NULL, mark_as_read_cb, 0, NULL},
        {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
+       {N_("/_Message/_Mark/Ignore thread"),   NULL, ignore_thread_cb, 0, NULL},
+       {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
+       {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
+       {N_("/_Message/_Mark/Mark as _spam"),   NULL, mark_as_spam_cb, 1, NULL},
+       {N_("/_Message/_Mark/Mark as _ham"),    NULL, mark_as_spam_cb, 0, NULL},
+       {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
+       {N_("/_Message/_Mark/Lock"),            NULL, lock_msgs_cb, 0, NULL},
+       {N_("/_Message/_Mark/Unlock"),          NULL, unlock_msgs_cb, 0, NULL},
+       {N_("/_Message/Color la_bel"),          NULL, NULL,            0, NULL},
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
 
@@ -791,14 +878,15 @@ static GtkItemFactoryEntry mainwin_entries[] =
 
        {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
        {N_("/_Help/_Manual"),                  NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
-       {N_("/_Help/_FAQ"),                     NULL, manual_open_cb, MANUAL_FAQ_LOCAL, NULL},
        {N_("/_Help/_Online User-contributed FAQ"),     
                                                NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
+       {N_("/_Help/Icon _Legend"),             NULL, legend_open_cb, 0, NULL},
        {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
 };
 
 static gboolean offline_ask_sync = TRUE;
+static guint lastkey;
 
 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
                                             GObject *arg1,
@@ -812,12 +900,195 @@ static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
            mainwin->summaryview->quicksearch &&
            quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
            (mod == 0 || mod == GDK_SHIFT_MASK)) {
-               quicksearch_pass_key(mainwin->summaryview->quicksearch, value, mod);
+               quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
                return TRUE;
        }
        return FALSE;
 }
 
+#define N_COLOR_LABELS colorlabel_get_color_count()
+
+static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
+                                                         gpointer data)
+{
+       MainWindow *mainwin;
+       GtkMenuShell *menu;
+       GtkCheckMenuItem **items;
+       gint n;
+       GList *cur;
+       GSList *sel;
+
+       mainwin = (MainWindow *)data;
+       g_return_if_fail(mainwin != NULL);
+
+       sel = summary_get_selection(mainwin->summaryview);
+       if (!sel) return;
+
+       menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
+       g_return_if_fail(menu != NULL);
+
+       Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
+
+       /* NOTE: don't return prematurely because we set the "dont_toggle"
+        * state for check menu items */
+       g_object_set_data(G_OBJECT(menu), "dont_toggle",
+                         GINT_TO_POINTER(1));
+
+       /* clear items. get item pointers. */
+       for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
+               if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
+                       gtk_check_menu_item_set_active
+                               (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
+                       items[n] = GTK_CHECK_MENU_ITEM(cur->data);
+                       n++;
+               }
+       }
+
+       if (n == (N_COLOR_LABELS + 1)) {
+               /* iterate all messages and set the state of the appropriate
+                * items */
+               for (; sel != NULL; sel = sel->next) {
+                       MsgInfo *msginfo;
+                       gint clabel;
+
+                       msginfo = (MsgInfo *)sel->data;
+                       if (msginfo) {
+                               clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
+                               if (!items[clabel]->active)
+                                       gtk_check_menu_item_set_active
+                                               (items[clabel], TRUE);
+                       }
+               }
+       } else
+               g_warning("invalid number of color elements (%d)\n", n);
+
+       /* reset "dont_toggle" state */
+       g_object_set_data(G_OBJECT(menu), "dont_toggle",
+                         GINT_TO_POINTER(0));
+}
+
+static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
+                                                    gpointer data)
+{
+       guint color = GPOINTER_TO_UINT(data);
+       MainWindow *mainwin;
+
+       mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
+       g_return_if_fail(mainwin != NULL);
+
+       /* "dont_toggle" state set? */
+       if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
+                               "dont_toggle"))
+               return;
+
+       summary_set_colorlabel(mainwin->summaryview, color, NULL);
+}
+
+static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
+{
+       GtkWidget *label_menuitem;
+       GtkWidget *menu;
+       GtkWidget *item;
+       gint i;
+
+       label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
+                                                  "/Message/Color label");
+       g_signal_connect(G_OBJECT(label_menuitem), "activate",
+                        G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
+                          mainwin);
+       gtk_widget_show(label_menuitem);
+
+       menu = gtk_menu_new();
+
+       /* create sub items. for the menu item activation callback we pass the
+        * index of label_colors[] as data parameter. for the None color we
+        * pass an invalid (high) value. also we attach a data pointer so we
+        * can always get back the Mainwindow pointer. */
+
+       item = gtk_check_menu_item_new_with_label(_("None"));
+       gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
+                          GUINT_TO_POINTER(0));
+       g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
+       gtk_widget_show(item);
+
+       gtk_widget_add_accelerator(item, "activate", 
+                                  mainwin->menu_factory->accel_group, 
+                                  GDK_0, GDK_CONTROL_MASK,
+                                  GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+
+       item = gtk_menu_item_new();
+       gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       gtk_widget_show(item);
+
+       /* create pixmap/label menu items */
+       for (i = 0; i < N_COLOR_LABELS; i++) {
+               item = colorlabel_create_check_color_menu_item(
+                       i, refresh, MAINWIN_COLORMENU);
+               gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
+                                GUINT_TO_POINTER(i + 1));
+               g_object_set_data(G_OBJECT(item), "mainwin",
+                                 mainwin);
+               gtk_widget_show(item);
+               gtk_widget_add_accelerator(item, "activate", 
+                                  mainwin->menu_factory->accel_group, 
+                                  GDK_1+i, GDK_CONTROL_MASK,
+                                  GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+       }
+
+       gtk_widget_show(menu);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
+       mainwin->colorlabel_menu = menu;
+}
+
+static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
+                                   MainWindow *mainwindow)
+{
+       if (evt && evt->button == 1) {
+               log_window_show_error(mainwindow->logwin);
+               gtk_widget_hide(mainwindow->warning_btn);
+       }
+       return FALSE;
+}
+
+static gboolean warning_visi_notify(GtkWidget *widget,
+                                      GdkEventVisibility *event,
+                                      MainWindow *mainwindow)
+{
+       gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
+       return FALSE;
+}
+
+static gboolean warning_leave_notify(GtkWidget *widget,
+                                     GdkEventCrossing *event,
+                                     MainWindow *mainwindow)
+{
+       gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
+       return FALSE;
+}
+
+static gboolean warning_enter_notify(GtkWidget *widget,
+                                     GdkEventCrossing *event,
+                                     MainWindow *mainwindow)
+{
+       gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
+       return FALSE;
+}
+
+void mainwindow_show_error(void)
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       gtk_widget_show(mainwin->warning_btn);
+}
+
+void mainwindow_clear_error(MainWindow *mainwin)
+{
+       gtk_widget_hide(mainwin->warning_btn);
+}
+
 MainWindow *main_window_create(SeparateType type)
 {
        MainWindow *mainwin;
@@ -836,9 +1107,9 @@ MainWindow *main_window_create(SeparateType type)
        GtkWidget *offline_pixmap;
        GtkWidget *online_switch;
        GtkWidget *offline_switch;
-       GtkTooltips *offline_tip;
-       GtkTooltips *online_tip;
-       GtkTooltips *sel_ac_tip;
+       GtkTooltips *tips;
+       GtkWidget *warning_icon;
+       GtkWidget *warning_btn;
 
        FolderView *folderview;
        SummaryView *summaryview;
@@ -896,8 +1167,10 @@ MainWindow *main_window_create(SeparateType type)
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
        ifactory = gtk_item_factory_from_widget(menubar);
 
+/*     gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
+       main_create_mailing_list_menu (mainwin, NULL); */
+
        menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
-       menu_set_sensitive(ifactory, "/Help/FAQ", manual_available(MANUAL_FAQ_LOCAL));
 
        if (prefs_common.toolbar_detachable) {
                handlebox = gtk_handle_box_new();
@@ -919,6 +1192,9 @@ MainWindow *main_window_create(SeparateType type)
        mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
                                          handlebox, 
                                          (gpointer)mainwin);
+       toolbar_set_learn_button
+               (mainwin->toolbar,
+                LEARN_SPAM);
 
        /* vbox that contains body */
        vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
@@ -929,6 +1205,33 @@ MainWindow *main_window_create(SeparateType type)
        hbox_stat = gtk_hbox_new(FALSE, 2);
        gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
 
+       tips = gtk_tooltips_new();
+
+       warning_icon = gtk_image_new_from_stock
+                        (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
+       warning_btn = gtk_event_box_new();
+       gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
+       
+       mainwin->warning_btn      = warning_btn;
+       
+       g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
+                        G_CALLBACK(warning_icon_pressed),
+                        (gpointer) mainwin);
+       g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
+                        G_CALLBACK(warning_visi_notify), mainwin);
+       g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
+                        G_CALLBACK(warning_visi_notify), mainwin);
+       g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
+                        G_CALLBACK(warning_leave_notify), mainwin);
+       g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
+                        G_CALLBACK(warning_enter_notify), mainwin);
+
+       gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
+
+       gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn, 
+                            _("Some error(s) happened. Click here to view log."), NULL);
+       gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
+
        statusbar = statusbar_create();
        gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
 
@@ -938,13 +1241,11 @@ MainWindow *main_window_create(SeparateType type)
 
        online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
        offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
-       online_tip = gtk_tooltips_new();
        online_switch = gtk_button_new ();
-       gtk_tooltips_set_tip(GTK_TOOLTIPS(online_tip),online_switch, 
+       gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch, 
                             _("You are online. Click the icon to go offline"), NULL);
-       offline_tip = gtk_tooltips_new();
        offline_switch = gtk_button_new ();
-       gtk_tooltips_set_tip(GTK_TOOLTIPS(offline_tip),offline_switch, 
+       gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch, 
                             _("You are offline. Click the icon to go online"),
                             NULL);
        gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
@@ -959,9 +1260,8 @@ MainWindow *main_window_create(SeparateType type)
        statuslabel = gtk_label_new("");
        gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
 
-       sel_ac_tip = gtk_tooltips_new();
        ac_button = gtk_button_new();
-       gtk_tooltips_set_tip(GTK_TOOLTIPS(sel_ac_tip),
+       gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
                             ac_button, _("Select account"), NULL);
        GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
        gtk_widget_set_size_request(ac_button, -1, 0);
@@ -975,12 +1275,17 @@ MainWindow *main_window_create(SeparateType type)
        gtk_widget_show_all(hbox_stat);
 
        gtk_widget_hide(offline_switch);
+       gtk_widget_hide(warning_btn);
        /* create views */
        mainwin->folderview  = folderview  = folderview_create();
        mainwin->summaryview = summaryview = summary_create();
        mainwin->messageview = messageview = messageview_create(mainwin);
        mainwin->logwin      = log_window_create();
 
+       log_window_init(mainwin->logwin);
+       log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
+                               prefs_common.loglength);
+
        folderview->mainwin      = mainwin;
        folderview->summaryview  = summaryview;
 
@@ -1065,19 +1370,24 @@ MainWindow *main_window_create(SeparateType type)
        switch (prefs_common.toolbar_style) {
        case TOOLBAR_NONE:
                menuitem = gtk_item_factory_get_item
-                       (ifactory, "/View/Show or hide/Toolbar/None");
+                       (ifactory, "/View/Show or hide/Toolbar/Hide");
                break;
        case TOOLBAR_ICON:
                menuitem = gtk_item_factory_get_item
-                       (ifactory, "/View/Show or hide/Toolbar/Icon");
+                       (ifactory, "/View/Show or hide/Toolbar/Icons only");
                break;
        case TOOLBAR_TEXT:
                menuitem = gtk_item_factory_get_item
-                       (ifactory, "/View/Show or hide/Toolbar/Text");
+                       (ifactory, "/View/Show or hide/Toolbar/Text only");
                break;
        case TOOLBAR_BOTH:
                menuitem = gtk_item_factory_get_item
-                       (ifactory, "/View/Show or hide/Toolbar/Icon and text");
+                       (ifactory, "/View/Show or hide/Toolbar/Text below icons");
+               break;
+       case TOOLBAR_BOTH_HORIZ:
+               menuitem = gtk_item_factory_get_item
+                       (ifactory,
+                        "/View/Show or hide/Toolbar/Text beside icons");
        }
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
 
@@ -1097,6 +1407,8 @@ MainWindow *main_window_create(SeparateType type)
        /* create actions menu */
        main_window_update_actions_menu(mainwin);
 
+       main_create_mailing_list_menu (mainwin, NULL);
+
        /* attach accel groups to main window */
 #define        ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
        gtk_window_add_accel_group                                      \
@@ -1122,9 +1434,6 @@ MainWindow *main_window_create(SeparateType type)
        folderview_init(folderview);
        summary_init(summaryview);
        messageview_init(messageview);
-       log_window_init(mainwin->logwin);
-       log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
-                               prefs_common.loglength);
 #ifdef USE_OPENSSL
        sslcertwindow_register_hook();
 #endif
@@ -1137,6 +1446,8 @@ MainWindow *main_window_create(SeparateType type)
 
        if (!watch_cursor)
                watch_cursor = gdk_cursor_new(GDK_WATCH);
+       if (!hand_cursor)
+               hand_cursor = gdk_cursor_new(GDK_HAND2);
 
        mainwin_list = g_list_append(mainwin_list, mainwin);
 
@@ -1144,6 +1455,8 @@ MainWindow *main_window_create(SeparateType type)
        if (prefs_common.work_offline)
                online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
 
+       mainwindow_colorlabel_menu_create(mainwin, FALSE);
+
        return mainwin;
 }
 
@@ -1165,9 +1478,11 @@ void main_window_update_actions_menu(MainWindow *mainwin)
 void main_window_cursor_wait(MainWindow *mainwin)
 {
 
-       if (mainwin->cursor_count == 0)
+       if (mainwin->cursor_count == 0) {
                gdk_window_set_cursor(mainwin->window->window, watch_cursor);
-
+               textview_cursor_wait(mainwin->messageview->mimeview->textview);
+       }
+       
        mainwin->cursor_count++;
 
        gdk_flush();
@@ -1178,9 +1493,10 @@ void main_window_cursor_normal(MainWindow *mainwin)
        if (mainwin->cursor_count)
                mainwin->cursor_count--;
 
-       if (mainwin->cursor_count == 0)
+       if (mainwin->cursor_count == 0) {
                gdk_window_set_cursor(mainwin->window->window, NULL);
-
+               textview_cursor_normal(mainwin->messageview->mimeview->textview);
+       }
        gdk_flush();
 }
 
@@ -1274,6 +1590,29 @@ static gboolean reflect_prefs_timeout_cb(gpointer data)
        return FALSE;
 }
 
+void main_window_reflect_prefs_all_now(void)
+{
+       reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
+}
+
+void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
+{
+       GtkMenuShell *menu;
+       GList *cur;
+
+       /* re-create colorlabel submenu */
+       menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
+       g_return_if_fail(menu != NULL);
+
+       /* clear items. get item pointers. */
+       for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
+               gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
+       }
+       mainwindow_colorlabel_menu_create(mainwin, TRUE);
+       summary_reflect_prefs_custom_colors(mainwin->summaryview);
+
+}
+
 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
 {
        if (prefs_tag == 0 || pixmap_theme_changed) {
@@ -1374,6 +1713,78 @@ static void main_window_set_account_receive_menu(MainWindow *mainwin,
        }
 }
 
+static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
+                                                      GList *account_list)
+{
+       GList *cur_ac, *cur_item;
+       GtkWidget *menuitem;
+       PrefsAccount *ac_prefs;
+       GtkWidget *menu = NULL;
+
+       if (mainwin->toolbar->getall_btn == NULL
+       ||  mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
+               return;
+
+       menu = mainwin->toolbar->getall_combo->menu;
+
+       /* destroy all previous menu item */
+       cur_item = GTK_MENU_SHELL(menu)->children;
+       while (cur_item != NULL) {
+               GList *next = cur_item->next;
+               gtk_widget_destroy(GTK_WIDGET(cur_item->data));
+               cur_item = next;
+       }
+
+       for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
+               ac_prefs = (PrefsAccount *)cur_ac->data;
+
+               menuitem = gtk_menu_item_new_with_label
+                       (ac_prefs->account_name
+                        ? ac_prefs->account_name : _("Untitled"));
+               gtk_widget_show(menuitem);
+               gtk_menu_append(GTK_MENU(menu), menuitem);
+               g_signal_connect(G_OBJECT(menuitem), "activate",
+                                G_CALLBACK(account_receive_menu_cb),
+                                ac_prefs);
+       }
+}
+
+static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
+                                                      GList *account_list)
+{
+       GList *cur_ac, *cur_item;
+       GtkWidget *menuitem;
+       PrefsAccount *ac_prefs;
+       GtkWidget *menu = NULL;
+
+       if (mainwin->toolbar->compose_mail_btn == NULL
+       ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
+               return;
+
+       menu = mainwin->toolbar->compose_combo->menu;
+
+       /* destroy all previous menu item */
+       cur_item = GTK_MENU_SHELL(menu)->children;
+       while (cur_item != NULL) {
+               GList *next = cur_item->next;
+               gtk_widget_destroy(GTK_WIDGET(cur_item->data));
+               cur_item = next;
+       }
+
+       for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
+               ac_prefs = (PrefsAccount *)cur_ac->data;
+
+               menuitem = gtk_menu_item_new_with_label
+                       (ac_prefs->account_name
+                        ? ac_prefs->account_name : _("Untitled"));
+               gtk_widget_show(menuitem);
+               gtk_menu_append(GTK_MENU(menu), menuitem);
+               g_signal_connect(G_OBJECT(menuitem), "activate",
+                                G_CALLBACK(account_compose_menu_cb),
+                                ac_prefs);
+       }
+}
+
 void main_window_set_account_menu(GList *account_list)
 {
        GList *cur;
@@ -1383,6 +1794,21 @@ void main_window_set_account_menu(GList *account_list)
                mainwin = (MainWindow *)cur->data;
                main_window_set_account_selector_menu(mainwin, account_list);
                main_window_set_account_receive_menu(mainwin, account_list);
+               main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
+               main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
+       }
+       hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
+}
+
+void main_window_set_account_menu_only_toolbar(GList *account_list)
+{
+       GList *cur;
+       MainWindow *mainwin;
+
+       for (cur = mainwin_list; cur != NULL; cur = cur->next) {
+               mainwin = (MainWindow *)cur->data;
+               main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
+               main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
        }
 }
 
@@ -1545,14 +1971,14 @@ void main_window_toggle_message_view(MainWindow *mainwin)
 
        prefs_common.msgview_visible = mainwin->messageview->visible;
 
-       gtk_widget_grab_focus(summaryview->ctree);
+       summary_grab_focus(summaryview);
 }
 
 void main_window_get_size(MainWindow *mainwin)
 {
        GtkAllocation *allocation;
 
-       if (mainwin->messageview == NULL) {
+       if (mainwin_list == NULL || mainwin->messageview == NULL) {
                debug_print("called after messageview "
                            "has been deallocated!\n");
                return;
@@ -1649,8 +2075,7 @@ void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
        g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
-                               (cur == 0 && total == 0) ? 0 :
-                               (gfloat)cur / (gfloat)total);
+                               (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
 }
 
 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
@@ -1658,8 +2083,8 @@ void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
        if (confirm) {
                if (alertpanel(_("Empty trash"),
                               _("Delete all messages in trash folders?"),
-                              GTK_STOCK_YES, GTK_STOCK_NO, NULL)
-                   != G_ALERTDEFAULT)
+                              GTK_STOCK_CANCEL, _("+_Empty trash"), NULL)
+                   != G_ALERTALTERNATE)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }
@@ -1729,7 +2154,7 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
 
                if ((selection == SUMMARY_NONE && item->hide_read_msgs)
                    || selection != SUMMARY_NONE)
-                       state |= M_HIDE_READ_MSG;       
+                       state |= M_HIDE_READ_MSG;
        }               
        if (mainwin->summaryview->threaded)
                state |= M_THREADED;
@@ -1745,6 +2170,12 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
                state |= M_NEWS;
        else
                state |= M_NOT_NEWS;
+       if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
+               state |= M_ACTIONS_EXIST;
+
+       if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
+               state |= M_HAVE_QUEUED_MAILS;
+
        if (selection == SUMMARY_SELECTED_SINGLE &&
            (item &&
             (folder_has_parent_of_type(item, F_DRAFT) ||
@@ -1754,12 +2185,19 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
        if (cur_account)
                state |= M_HAVE_ACCOUNT;
        
+       if (any_folder_want_synchronise())
+               state |= M_WANT_SYNC;
+
        for ( ; account_list != NULL; account_list = account_list->next) {
                if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
                        state |= M_HAVE_NEWS_ACCOUNT;
                        break;
                }
        }
+       
+       if (procmsg_spam_can_learn()) {
+               state |= M_CAN_LEARN_SPAM;
+       }
 
        if (inc_is_active())
                state |= M_INC_ACTIVE;
@@ -1792,26 +2230,33 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
        } entry[] = {
                {"/File/Save as...", M_TARGET_EXIST},
                {"/File/Print..."  , M_TARGET_EXIST},
+               {"/File/Synchronise folders", M_WANT_SYNC},
                {"/File/Exit"      , M_UNLOCKED},
 
                {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
+               {"/Edit/Delete thread"             , M_SINGLE_TARGET_EXIST},
+               {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
 
+               {"/View/Set displayed columns/in Folder list..."
+                                                  , M_UNLOCKED}, 
                {"/View/Sort"                      , M_EXEC},
                {"/View/Thread view"               , M_EXEC},
                {"/View/Expand all threads"        , M_MSG_EXIST},
                {"/View/Collapse all threads"      , M_MSG_EXIST},
                {"/View/Hide read messages"        , M_HIDE_READ_MSG},
-               {"/View/Go to/Prev message"        , M_MSG_EXIST},
+               {"/View/Go to/Previous message"        , M_MSG_EXIST},
                {"/View/Go to/Next message"        , M_MSG_EXIST},
-               {"/View/Go to/Prev unread message" , M_MSG_EXIST},
-               {"/View/Go to/Prev new message"    , M_MSG_EXIST},
-               {"/View/Go to/Prev marked message" , M_MSG_EXIST},
-               {"/View/Go to/Next marked message" , M_MSG_EXIST},
-               {"/View/Go to/Prev labeled message", M_MSG_EXIST},
+               {"/View/Go to/Previous unread message" , M_MSG_EXIST},
+               {"/View/Go to/Previous new message"    , M_MSG_EXIST},
+               {"/View/Go to/Previous marked message" , M_MSG_EXIST},
+               {"/View/Go to/Previous labeled message", M_MSG_EXIST},
                {"/View/Go to/Next labeled message", M_MSG_EXIST},
+               {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
+               {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
                {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
-               {"/View/Show all headers"          , M_SINGLE_TARGET_EXIST},
                {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
+               {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
+               {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
 
                {"/Message/Receive/Get from current account"
                                                 , M_HAVE_ACCOUNT|M_UNLOCKED},
@@ -1819,32 +2264,38 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                                                 , M_HAVE_ACCOUNT|M_UNLOCKED},
                {"/Message/Receive/Cancel receiving"
                                                 , M_INC_ACTIVE},
-
+               {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
                {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
-               {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
-               {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
-               {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
+               {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
+               {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
+               {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
                {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
                {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
-               {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
+               {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
                {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
                {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
                {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
                {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
                {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
                {"/Message/Mark"                  , M_TARGET_EXIST},
+               {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
+               {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
+               {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
+               {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
+               {"/Message/Mark/Lock"             , M_TARGET_EXIST},
+               {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
+               {"/Message/Color label"           , M_TARGET_EXIST},
                {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
 
                {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
-               {"/Tools/Harvest addresses/from Folder..."       
-                                                      , M_MSG_EXIST},
+               {"/Tools/Harvest addresses"            , M_MSG_EXIST},
                {"/Tools/Harvest addresses/from Messages..."
-                                                      , M_MSG_EXIST|M_TARGET_EXIST},
+                                                      , M_TARGET_EXIST},
                {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
                {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
                {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
                {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
-               {"/Tools/Actions"                      , M_TARGET_EXIST},
+               {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
                {"/Tools/Execute"                      , M_DELAY_EXEC},
                {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
 
@@ -1935,17 +2386,226 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
        }
 
-       SET_CHECK_MENU_ACTIVE("/View/Show all headers",
+       if (mainwin->messageview 
+       &&  mainwin->messageview->mimeview
+       &&  mainwin->messageview->mimeview->textview)
+               SET_CHECK_MENU_ACTIVE("/View/All headers",
                              mainwin->messageview->mimeview->textview->show_all_headers);
        SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
+       if (prefs_common.hide_quotes == 1)
+               SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
+       if (prefs_common.hide_quotes == 2)
+               SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
+       if (prefs_common.hide_quotes == 3)
+               SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
 
 #undef SET_CHECK_MENU_ACTIVE
 
        main_window_menu_callback_unblock(mainwin);
 }
 
+void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
+{
+       GtkItemFactory *ifactory;
+       gint is_menu = 0;
+       ifactory = gtk_item_factory_from_widget(mainwin->menubar);
+       
+       if (msginfo) 
+               is_menu = mailing_list_create_submenu (ifactory, msginfo);
+       if (is_menu)
+               gtk_widget_set_sensitive (gtk_item_factory_get_item
+                               (ifactory,"/Message/Mailing-List"), TRUE);
+       else
+               gtk_widget_set_sensitive (gtk_item_factory_get_item
+                               (ifactory,"/Message/Mailing-List"), FALSE);
+}
+
+static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
+{
+       gint menu_nb = 0;
+       GtkWidget *menuitem;
+       
+       if (!msginfo || !msginfo->extradata) {
+               menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
+               menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
+               menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
+               menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
+               menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
+               menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
+               return 0;
+       }
+               
+       /* Mailing list post */
+       if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
+               g_free(msginfo->extradata->list_post);
+               msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
+       }
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
+               
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
+       /* Mailing list help */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
+
+       /* Mailing list subscribe */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
+               
+       /* Mailing list unsubscribe */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
+       
+       /* Mailing list view archive */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
+       
+       /* Mailing list contact owner */
+       menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
+       
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
+       
+       return menu_nb;
+}
+
+static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
+{
+       GtkWidget *item, *menu;
+       const gchar *url_pt ;
+       gchar url_decoded[BUFFSIZE];
+       GList *amenu, *alist;
+       gint menu_nb = 0;
+       
+       menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
+       
+       /* First delete old submenu */
+       /* FIXME: we can optimize this, and only change/add/delete necessary items */
+       for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
+               alist = amenu->next;
+               item = GTK_WIDGET (amenu->data);
+               gtk_widget_destroy (item);
+               amenu = alist;
+       }
+       if (list_header) {
+               for (url_pt = list_header; url_pt && *url_pt;) {
+                       get_url_part (&url_pt, url_decoded, BUFFSIZE);
+                       item = NULL;
+                       if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
+                               item = gtk_menu_item_new_with_label ((url_decoded));
+                               g_signal_connect(G_OBJECT(item), "activate",
+                                                G_CALLBACK(mailing_list_compose),
+                                                NULL);
+                       }
+                       else if (!g_strncasecmp (url_decoded, "http:", 5) ||
+                                !g_strncasecmp (url_decoded, "https:",6)) {
+
+                               item = gtk_menu_item_new_with_label ((url_decoded));
+                               g_signal_connect(G_OBJECT(item), "activate",
+                                                G_CALLBACK(mailing_list_open_uri),
+                                                NULL);
+                       } 
+                       if (item) {
+                               gtk_menu_append (GTK_MENU(menu), item);
+                               gtk_widget_show (item);
+                               menu_nb++;
+                       }
+               }
+       }
+       if (menu_nb)
+               gtk_widget_set_sensitive (menuitem, TRUE);
+       else
+               gtk_widget_set_sensitive (menuitem, FALSE);
+               
+
+       return menu_nb;
+}
+
+static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
+{
+       gchar tmp[BUFFSIZE];
+       const gchar *buf;
+       gint i = 0;
+       buf = *buffer;
+       
+       if (buf == 0x00) {
+               *url_decoded = '\0';
+               *buffer = NULL;
+               return;
+       }
+       /* Ignore spaces, comments  and tabs () */
+       for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
+               if (*buf == '(')
+                       for (;*buf != ')' && *buf != 0x00; buf++);
+       
+       /* First non space and non comment must be a < */
+       if (*buf =='<' ) {
+               buf++;
+               for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
+               buf++;
+       }
+       else  {
+               *buffer = NULL;
+               *url_decoded = '\0';
+               return;
+       }
+       
+       tmp[i]       = 0x00;
+       *url_decoded = '\0';
+       *buffer = NULL;
+       
+       if (i == maxlen) {
+               return;
+       }
+       decode_uri (url_decoded, (const gchar *)tmp);
+
+       /* Prepare the work for the next url in the list */
+       /* after the closing bracket >, ignore space, comments and tabs */
+       for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
+               if (*buf == '(')
+                       for (;*buf != ')' && *buf != 0x00; buf++);
+                       
+       if (!buf || !*buf) {
+               *buffer = NULL;
+               return;
+       }
+
+       /* now first non space, non comment must be a comma */
+       if (*buf != ',')
+               for (;*buf != 0x00; buf++);
+       else
+               buf++;
+       *buffer = buf;
+}
+       
+static void mailing_list_compose (GtkWidget *w, gpointer *data)
+{
+       gchar *mailto;
+
+       gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
+       compose_new(NULL, mailto+7, NULL);
+}
+ static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
+{
+       gchar *mailto;
+       gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
+       open_uri (mailto, prefs_common.uri_cmd);
+} 
+       
 void main_window_popup(MainWindow *mainwin)
 {
+       if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
+               main_window_show(mainwin);
+
        gtkut_window_popup(mainwin->window);
 
        switch (mainwin->type) {
@@ -2048,7 +2708,7 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                
                folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
                gtk_window_set_title(GTK_WINDOW(folderwin),
-                                    _("Sylpheed-Claws - Folder View"));
+                                    _("Claws Mail - Folder View"));
 
                gtk_window_move(GTK_WINDOW(folderwin),
                                prefs_common.folderwin_x,
@@ -2084,7 +2744,7 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                
                messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
                gtk_window_set_title(GTK_WINDOW(messagewin),
-                                    _("Sylpheed-Claws - Message View"));
+                                    _("Claws Mail - Message View"));
                                     
                gtk_window_move(GTK_WINDOW(messagewin), 
                                prefs_common.main_msgwin_x,
@@ -2193,6 +2853,10 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                                  mainwin->messageview->handlebox, 
                                  prefs_common.toolbar_style);
 
+               /* remove headerview if not in prefs */
+               headerview_set_visibility(mainwin->messageview->headerview,
+                                         prefs_common.display_header_pane);
+
                break;
        case SEPARATE_BOTH:
                messageview_add_toolbar(mainwin->messageview, messagewin);
@@ -2213,6 +2877,10 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                                  mainwin->messageview->handlebox, 
                                  prefs_common.toolbar_style);          
 
+               /* remove headerview if not in prefs */
+               headerview_set_visibility(mainwin->messageview->headerview,
+                                         prefs_common.display_header_pane);
+
                break;
        }
 
@@ -2292,36 +2960,19 @@ void main_window_destroy_all(void)
                TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
                TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
 
+               mainwin->folderview->mainwin = NULL;
+               mainwin->summaryview->mainwin = NULL;
+               mainwin->messageview->mainwin = NULL;
+
                g_free(mainwin->toolbar);
                g_free(mainwin);
                
                mainwin_list = g_list_remove(mainwin_list, mainwin);
        }
        g_list_free(mainwin_list);
+       mainwin_list = NULL;
 }
 
-#if 0
-static gboolean toolbar_account_button_pressed(GtkWidget *widget,
-                                              GdkEventButton *event,
-                                              gpointer data)
-{
-       MainWindow *mainwin = (MainWindow *)data;
-
-       if (!event) return FALSE;
-       if (event->button != 3) return FALSE;
-
-       gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
-       g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
-                         widget);
-
-       gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
-                      menu_button_position, widget,
-                      event->button, event->time);
-
-       return FALSE;
-}
-#endif
-
 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
                                   gpointer data)
 {
@@ -2441,19 +3092,28 @@ static void foldersort_cb(MainWindow *mainwin, guint action,
 static void import_mbox_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       import_mbox(mainwin->summaryview->folder_item);
+       /* only notify if import has failed */
+       if (import_mbox(mainwin->summaryview->folder_item) == -1) {
+               alertpanel_error(_("Mbox import has failed."));
+       }
 }
 
 static void export_mbox_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       export_mbox(mainwin->summaryview->folder_item);
+       /* only notify if export has failed */
+       if (export_mbox(mainwin->summaryview->folder_item) == -1) {
+               alertpanel_error(_("Export to mbox has failed."));
+       }
 }
 
 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
                                GtkWidget *widget)
 {
-       summaryview_export_mbox_list(mainwin->summaryview);
+       /* only notify if export has failed */
+       if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
+               alertpanel_error(_("Export to mbox has failed."));
+       }
 }
 
 static void empty_trash_cb(MainWindow *mainwin, guint action,
@@ -2475,9 +3135,9 @@ static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        if (prefs_common.confirm_on_exit) {
-               if (alertpanel(_("Exit"), _("Exit Sylpheed-Claws?"),
-                              GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
-                   != G_ALERTDEFAULT)
+               if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
+                              GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
+                   != G_ALERTALTERNATE)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }
@@ -2495,8 +3155,7 @@ static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 
 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
-       prefs_common.show_searchbar = TRUE;
-       summaryview_activate_quicksearch(mainwin->summaryview);
+       summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
 }
 
 static void toggle_folder_cb(MainWindow *mainwin, guint action,
@@ -2509,12 +3168,6 @@ static void toggle_folder_cb(MainWindow *mainwin, guint action,
        switch (mainwin->type) {
        case SEPARATE_NONE:
        case SEPARATE_MESSAGE:
-#if 0
-               if (active)
-                       gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
-               else
-                       gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
-#endif
                break;
        case SEPARATE_FOLDER:
                debug_print("separate folder\n");
@@ -2610,7 +3263,7 @@ static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget
        main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
 }
 
-static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
+static gboolean any_folder_want_synchronise(void)
 {
        GList *folderlist = folder_get_list();
        gboolean found = FALSE;
@@ -2619,17 +3272,23 @@ static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
        for (; folderlist; folderlist = folderlist->next) {
                Folder *folder = (Folder *)folderlist->data;
                if (folder_want_synchronise(folder)) {
-                       found = TRUE;
-                       break;
+                       return TRUE;
                }
        }
        
-       if (!found)
+       return FALSE;
+
+}
+
+static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
+{
+       
+       if (!any_folder_want_synchronise())
                return;
-               
+
        if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
                        _("Do you want to synchronise your folders now?"),
-                       GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
+                       GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
                return;
 
        folder_synchronise(NULL);
@@ -2650,20 +3309,29 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
        g_return_if_fail(menuitem != NULL);
        
        if (btn == GTK_BUTTON(mainwin->online_switch)) {
-               /* go offline */
-               mainwindow_check_synchronise(mainwin, TRUE);
                gtk_widget_hide (mainwin->online_switch);
                gtk_widget_show (mainwin->offline_switch);
                menuitem->active = TRUE;
+               inc_autocheck_timer_remove();
+                       
+               /* go offline */
+               if (prefs_common.work_offline)
+                       return;
+               mainwindow_check_synchronise(mainwin, TRUE);
                prefs_common.work_offline = TRUE;
-               inc_autocheck_timer_remove();           
+               imap_disconnect_all();
+               hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
        } else {
                /*go online */
+               if (!prefs_common.work_offline)
+                       return;
                gtk_widget_hide (mainwin->offline_switch);
                gtk_widget_show (mainwin->online_switch);
                menuitem->active = FALSE;
                prefs_common.work_offline = FALSE;
                inc_autocheck_timer_set();
+               refresh_resolvers();
+               hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
        }
 }
 
@@ -2730,6 +3398,34 @@ static void show_all_header_cb(MainWindow *mainwin, guint action,
                                     GTK_CHECK_MENU_ITEM(widget)->active);
 }
 
+#define SET_CHECK_MENU_ACTIVE(path, active) \
+{ \
+       menuitem = gtk_item_factory_get_widget(ifactory, path); \
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
+}
+
+static void hide_quotes_cb(MainWindow *mainwin, guint action,
+                              GtkWidget *widget)
+{
+       GtkWidget *menuitem;
+       GtkItemFactory *ifactory = mainwin->menu_factory;
+
+       if (mainwin->menu_lock_count) return;
+
+       prefs_common.hide_quotes = 
+                       GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
+
+       mainwin->menu_lock_count++;
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
+       SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
+       mainwin->menu_lock_count--;
+
+       summary_redisplay_msg(mainwin->summaryview);
+}
+
+#undef SET_CHECK_MENU_ACTIVE
 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        summary_mark(mainwin->summaryview);
@@ -2758,6 +3454,37 @@ static void mark_all_read_cb(MainWindow *mainwin, guint action,
        summary_mark_all_read(mainwin->summaryview);
 }
 
+static void mark_as_spam_cb(MainWindow *mainwin, guint action,
+                            GtkWidget *widget)
+{
+       summary_mark_as_spam(mainwin->summaryview, action, NULL);
+}
+
+static void ignore_thread_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_ignore_thread(mainwin->summaryview);
+}
+
+static void unignore_thread_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_unignore_thread(mainwin->summaryview);
+}
+
+static void lock_msgs_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_msgs_lock(mainwin->summaryview);
+}
+
+static void unlock_msgs_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_msgs_unlock(mainwin->summaryview);
+}
+
+
 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        summary_reedit(mainwin->summaryview);
@@ -2810,16 +3537,18 @@ static void hide_read_messages (MainWindow *mainwin, guint action,
 
 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
+       gboolean threaded = FALSE;
        if (mainwin->menu_lock_count) return;
        if (!mainwin->summaryview->folder_item) return;
 
-       if (GTK_CHECK_MENU_ITEM(widget)->active) {
-               summary_thread_build(mainwin->summaryview);
-/*             mainwin->summaryview->folder_item->threaded = TRUE; */
-       } else {
-               summary_unthread(mainwin->summaryview);
-/*             mainwin->summaryview->folder_item->threaded = FALSE; */
-       }
+       threaded = GTK_CHECK_MENU_ITEM(widget)->active;
+
+       mainwin->summaryview->folder_item->threaded = threaded; 
+
+       mainwin->summaryview->threaded = threaded;
+
+       summary_show(mainwin->summaryview, 
+                       mainwin->summaryview->folder_item);
 }
 
 static void expand_threads_cb(MainWindow *mainwin, guint action,
@@ -2923,7 +3652,10 @@ static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
 {
        struct DelDupsData data = {0, 0};
 
+       main_window_cursor_wait(mainwin);
        folder_func_to_all_folders(deldup_all, &data);
+       main_window_cursor_normal(mainwin);
+       
        alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
                                   "Deleted %d duplicate messages in %d folders.\n",
                                   data.dups),
@@ -3016,6 +3748,18 @@ static void next_labeled_cb(MainWindow *mainwin, guint action,
        summary_select_next_labeled(mainwin->summaryview);
 }
 
+static void last_read_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_select_last_read(mainwin->summaryview);
+}
+
+static void parent_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_select_parent(mainwin->summaryview);
+}
+
 static void goto_folder_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
@@ -3027,6 +3771,12 @@ static void goto_folder_cb(MainWindow *mainwin, guint action,
                folderview_select(mainwin->folderview, to_folder);
 }
 
+static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
+                          GtkWidget *widget)
+{
+       folderview_select_next_unread(mainwin->folderview, FALSE);
+}
+
 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        messageview_copy_clipboard(mainwin->messageview);
@@ -3036,17 +3786,23 @@ static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        MessageView *msgview = mainwin->messageview;
 
-       if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
-               summary_select_all(mainwin->summaryview);
-       else if (messageview_is_visible(msgview) &&
+       if (messageview_is_visible(msgview) &&
                 (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
                messageview_select_all(mainwin->messageview);
+       else
+               summary_select_all(mainwin->summaryview);
 }
 
 static void select_thread_cb(MainWindow *mainwin, guint action,
                             GtkWidget *widget)
 {
-       summary_select_thread(mainwin->summaryview);
+       summary_select_thread(mainwin->summaryview, FALSE);
+}
+
+static void delete_thread_cb(MainWindow *mainwin, guint action,
+                            GtkWidget *widget)
+{
+       summary_select_thread(mainwin->summaryview, TRUE);
 }
 
 static void create_filter_cb(MainWindow *mainwin, guint action,
@@ -3066,7 +3822,8 @@ static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_filtering_open(&pre_global_processing,
                             _("Processing rules to apply before folder rules"),
-                            NULL, NULL);
+                            MANUAL_ANCHOR_PROCESSING,
+                            NULL, NULL, FALSE);
 }
 
 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
@@ -3074,7 +3831,8 @@ static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_filtering_open(&post_global_processing,
                             _("Processing rules to apply after folder rules"),
-                            NULL, NULL);
+                            MANUAL_ANCHOR_PROCESSING,
+                            NULL, NULL, FALSE);
 }
 
 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
@@ -3082,7 +3840,8 @@ static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_filtering_open(&filtering_rules,
                             _("Filtering configuration"),
-                            NULL, NULL);
+                            MANUAL_ANCHOR_FILTERING,
+                            NULL, NULL, TRUE);
 }
 
 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
@@ -3149,6 +3908,15 @@ static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
        inc_account_mail(mainwin, account);
 }
 
+static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)mainwin_list->data;
+       PrefsAccount *account = (PrefsAccount *)data;
+       FolderItem *item = mainwin->summaryview->folder_item;   
+
+       compose_new_with_folderitem(account, item, NULL);
+}
+
 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
 {
        prefs_gtk_open();
@@ -3162,7 +3930,12 @@ static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
 static void manual_open_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       manual_open((ManualType)action);
+       manual_open((ManualType)action, NULL);
+}
+
+static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
+{
+       legend_show();
 }
 
 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
@@ -3190,6 +3963,8 @@ static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focu
        SummaryView *summary;
 
        g_return_val_if_fail(data, FALSE);
+       if (!g_list_find(mainwin_list, data))
+               return TRUE;
        summary = ((MainWindow *)data)->summaryview;
        g_return_val_if_fail(summary, FALSE);
 
@@ -3197,8 +3972,6 @@ static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focu
            g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
                return FALSE;
 
-       if (summary->selected != summary->displayed)
-               summary_select_node(summary, summary->displayed, FALSE, TRUE);
        return FALSE;
 }
 
@@ -3214,7 +3987,10 @@ gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                return FALSE;
 
        if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
+       {
+               lastkey = event->keyval;
                return FALSE;
+       }
 
        switch (event->keyval) {
        case GDK_Q:             /* Quit */
@@ -3224,10 +4000,13 @@ gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                return FALSE;
        case GDK_space:
                if (mainwin->folderview && mainwin->summaryview
-                   && !mainwin->summaryview->displayed) {
-                       summary_lock(mainwin->summaryview);
-                       folderview_select_next_unread(mainwin->folderview);
-                       summary_unlock(mainwin->summaryview);
+                   && ((!mainwin->summaryview->displayed
+                       && !mainwin->summaryview->selected) 
+                       || (mainwin->summaryview->folder_item
+                           && mainwin->summaryview->folder_item->total_msgs == 0))) {
+                       g_signal_stop_emission_by_name(G_OBJECT(widget), 
+                                       "key_press_event");
+                       folderview_select_next_unread(mainwin->folderview, TRUE);
                }
                break;
        default:
@@ -3297,7 +4076,80 @@ static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
        mainwindow_check_synchronise(mainwin, FALSE);
 }
 
-/*
-* End of Source.
-*/
+void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
+{
+       summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
+}
 
+void mainwindow_jump_to(const gchar *target)
+{
+       gchar *tmp = NULL;
+       gchar *p = NULL;
+       FolderItem *item = NULL;
+       gchar *msg = NULL;
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       
+       if (!target)
+               return;
+               
+       if (!mainwin) {
+               printf("not initialized\n");
+               return;
+       }
+
+       tmp = g_strdup(target);
+       
+       if ((p = strstr(tmp, "\r")) != NULL)
+               *p = '\0';
+       if ((p = strstr(tmp, "\n")) != NULL)
+               *p = '\0';
+
+       if ((item = folder_find_item_from_identifier(tmp))) {
+               printf("selecting folder '%s'\n", tmp);
+               folderview_select(mainwin->folderview, item);
+               main_window_popup(mainwin);
+               g_free(tmp);
+               return;
+       }
+       
+       msg = strrchr(tmp, G_DIR_SEPARATOR);
+       if (msg) {
+               *msg++ = '\0';
+               if ((item = folder_find_item_from_identifier(tmp))) {
+                       printf("selecting folder '%s'\n", tmp);
+                       folderview_select(mainwin->folderview, item);
+               } else {
+                       printf("'%s' not found\n", tmp);
+               }
+               if (item && msg && atoi(msg)) {
+                       printf("selecting message %d\n", atoi(msg));
+                       summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
+                       summary_display_msg_selected(mainwin->summaryview, FALSE);
+                       main_window_popup(mainwin);
+                       g_free(tmp);
+                       return;
+               } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
+                       MsgInfo *msginfo = NULL;
+                       msg++;
+                       msg[strlen(msg)-1] = '\0';
+                       msginfo = folder_item_get_msginfo_by_msgid(item, msg);
+                       if (msginfo) {
+                               printf("selecting message %s\n", msg);
+                               summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
+                               summary_display_msg_selected(mainwin->summaryview, FALSE);
+                               main_window_popup(mainwin);
+                               g_free(tmp);
+                               procmsg_msginfo_free(msginfo);
+                               return;
+                       } else {
+                               printf("'%s' not found\n", msg);
+                       }
+               } else {
+                       printf("'%s' not found\n", msg);
+               }
+       } else {
+               printf("'%s' not found\n", tmp);
+       }
+       
+       g_free(tmp);
+}