2007-07-15 [colin] 2.10.0cvs28
[claws.git] / src / mainwindow.c
index cb869535fc0b601dc5a810ff8fff3a12d4d24d3b..6fa82e6cec9708625dff4aac483678b9b82ef63c 100644 (file)
@@ -1,20 +1,19 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+   Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+   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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "defs.h"
 #include "stock_pixmap.h"
 #include "folder.h"
 #include "inc.h"
+#include "log.h"
 #include "compose.h"
 #include "procmsg.h"
 #include "import.h"
 #include "export.h"
+#include "edittags.h"
 #include "prefs_common.h"
 #include "prefs_actions.h"
 #include "prefs_filtering.h"
@@ -93,6 +94,7 @@
 #include "foldersort.h"
 #include "icon_legend.h"
 #include "colorlabel.h"
+#include "tags.h"
 #include "textview.h"
 #include "imap.h"
 #include "socket.h"
 static GList *mainwin_list = NULL;
 
 static GdkCursor *watch_cursor = NULL;
+static GdkCursor *hand_cursor = NULL;
+
+static gint iconified_count = 0;
 
 static void main_window_menu_callback_block    (MainWindow     *mainwin);
 static void main_window_menu_callback_unblock  (MainWindow     *mainwin);
 
 static void main_window_show_cur_account       (MainWindow     *mainwin);
 
+static void main_window_separation_change      (MainWindow     *mainwin,
+                                                LayoutType      layout_mode);
+
 static void main_window_set_widgets            (MainWindow     *mainwin,
-                                                SeparateType    type);
+                                                LayoutType      layout_mode);
 
 static void toolbar_child_attached             (GtkWidget      *widget,
                                                 GtkWidget      *child,
@@ -126,12 +134,6 @@ static gboolean ac_label_button_pressed            (GtkWidget      *widget,
 static gint main_window_close_cb               (GtkWidget      *widget,
                                                 GdkEventAny    *event,
                                                 gpointer        data);
-static gint folder_window_close_cb             (GtkWidget      *widget,
-                                                GdkEventAny    *event,
-                                                gpointer        data);
-static gint message_window_close_cb            (GtkWidget      *widget,
-                                                GdkEventAny    *event,
-                                                gpointer        data);
 
 static void main_window_size_allocate_cb       (GtkWidget      *widget,
                                                 GtkAllocation  *allocation,
@@ -179,9 +181,6 @@ static void search_cb                (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
 
-static void toggle_folder_cb    (MainWindow    *mainwin,
-                                 guint          action,
-                                 GtkWidget     *widget);
 static void toggle_message_cb   (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
@@ -191,16 +190,20 @@ static void toggle_toolbar_cb      (MainWindow    *mainwin,
 static void toggle_statusbar_cb         (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
-static void separate_widget_cb  (MainWindow    *mainwin,
+#ifndef MAEMO
+static void set_layout_cb       (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
-
+#endif
 static void addressbook_open_cb        (MainWindow     *mainwin,
                                 guint           action,
                                 GtkWidget      *widget);
 static void log_window_show_cb (MainWindow     *mainwin,
                                 guint           action,
                                 GtkWidget      *widget);
+static void filtering_debug_window_show_cb     (MainWindow     *mainwin,
+                                guint           action,
+                                GtkWidget      *widget);
 
 static void inc_cancel_cb              (MainWindow     *mainwin,
                                         guint           action,
@@ -259,6 +262,19 @@ 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,
                                         GtkWidget      *widget);
@@ -375,6 +391,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,
@@ -382,6 +401,9 @@ static void create_filter_cb         (MainWindow    *mainwin,
 static void create_processing_cb (MainWindow   *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void open_urls_cb        (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 
 static void prefs_template_open_cb     (MainWindow     *mainwin,
                                         guint           action,
@@ -389,6 +411,9 @@ static void prefs_template_open_cb  (MainWindow     *mainwin,
 static void prefs_actions_open_cb      (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
+static void prefs_tags_open_cb         (MainWindow     *mainwin,
+                                        guint           action,
+                                        GtkWidget      *widget);
 static void prefs_account_open_cb      (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -455,10 +480,16 @@ static void sync_cb                ( MainWindow *mainwin,
 static gboolean mainwindow_focus_in_event      (GtkWidget      *widget, 
                                                 GdkEventFocus  *focus,
                                                 gpointer        data);
-void main_window_reply_cb                      (MainWindow     *mainwin, 
+static gboolean mainwindow_visibility_event_cb (GtkWidget      *widget, 
+                                                GdkEventVisibility     *state,
+                                                gpointer        data);
+static gboolean mainwindow_state_event_cb      (GtkWidget      *widget, 
+                                                GdkEventWindowState    *state,
+                                                gpointer        data);
+static void main_window_reply_cb                       (MainWindow     *mainwin, 
                                                 guint           action,
                                                 GtkWidget      *widget);
-gboolean mainwindow_progressindicator_hook     (gpointer        source,
+static gboolean mainwindow_progressindicator_hook      (gpointer        source,
                                                 gpointer        userdata);
 
 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
@@ -475,6 +506,7 @@ static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
 static void mainwindow_quicksearch             (MainWindow     *mainwin, 
                                                 guint           action, 
                                                 GtkWidget      *widget);
+static gboolean any_folder_want_synchronise(void);
 
 static GtkItemFactoryEntry mainwin_entries[] =
 {
@@ -504,6 +536,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},
@@ -511,8 +544,6 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Edit/_Quick search"),            "slash", mainwindow_quicksearch, 0, NULL},
        {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
        {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
-       {N_("/_View/Show or hi_de/_Folder tree"),
-                                               NULL, toggle_folder_cb, 0, "<ToggleItem>"},
        {N_("/_View/Show or hi_de/_Message view"),
                                                "V", toggle_message_cb, 0, "<ToggleItem>"},
        {N_("/_View/Show or hi_de/_Toolbar"),
@@ -534,18 +565,25 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {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>"},
+#ifndef MAEMO
+       {N_("/_View/La_yout"),                  NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Layout/_Standard"),         NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
+       {N_("/_View/Layout/_Three columns"),    NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
+       {N_("/_View/Layout/_Wide message"),     NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
+       {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
+       {N_("/_View/Layout/S_mall screen"),     NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
+#endif
        {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
        {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
        {N_("/_View/_Sort/by S_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
        {N_("/_View/_Sort/by _Date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
+       {N_("/_View/_Sort/by Thread date"),     NULL, sort_summary_cb, SORT_BY_THREAD_DATE, "/View/Sort/by number"},
        {N_("/_View/_Sort/by _From"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
        {N_("/_View/_Sort/by _To"),             NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
        {N_("/_View/_Sort/by S_ubject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
-       {N_("/_View/_Sort/by _color label"),
-                                               NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
+       {N_("/_View/_Sort/by _color label"),    NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
+       {N_("/_View/_Sort/by tag"),             NULL, sort_summary_cb, SORT_BY_TAGS, "/View/Sort/by number"},
        {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
        {N_("/_View/_Sort/by _status"),         NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
        {N_("/_View/_Sort/by a_ttachment"),
@@ -714,7 +752,7 @@ 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>"},
@@ -769,10 +807,16 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {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 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/T_ags"),                 NULL, NULL,            0, NULL},
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
 
@@ -809,6 +853,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Tools/C_reate processing rule/by _Subject"),
                                                NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
+       {N_("/_Tools/List _URLs..."),           "<shift><control>U", open_urls_cb, 0, NULL},
+       {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/Ch_eck for new messages in all folders"),
@@ -827,7 +873,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, ssl_manager_open_cb, 0, NULL},
 #endif
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
-       {N_("/_Tools/_Log window"),             "<shift><control>L", log_window_show_cb, 0, NULL},
+       {N_("/_Tools/Filtering Log"),           NULL, filtering_debug_window_show_cb, 0, NULL},
+       {N_("/_Tools/Network _Log"),            "<shift><control>L", log_window_show_cb, 0, NULL},
 
        {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
        {N_("/_Configuration/C_hange current account"),
@@ -849,6 +896,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, prefs_filtering_open_cb, 0, NULL},
        {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
        {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
+       {N_("/_Configuration/Tag_s..."),        NULL, prefs_tags_open_cb, 0, NULL},
+       {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
        {N_("/_Configuration/Plu_gins..."),     NULL, plugins_open_cb, 0, NULL},
 
        {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
@@ -862,6 +911,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
 
 static gboolean offline_ask_sync = TRUE;
 static guint lastkey;
+static gboolean is_obscured = FALSE;
 
 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
                                             GObject *arg1,
@@ -890,12 +940,13 @@ static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_i
        GtkMenuShell *menu;
        GtkCheckMenuItem **items;
        gint n;
-       GList *cur, *sel;
+       GList *cur;
+       GSList *sel;
 
        mainwin = (MainWindow *)data;
        g_return_if_fail(mainwin != NULL);
 
-       sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
+       sel = summary_get_selection(mainwin->summaryview);
        if (!sel) return;
 
        menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
@@ -925,9 +976,7 @@ static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_i
                        MsgInfo *msginfo;
                        gint clabel;
 
-                       msginfo = gtk_ctree_node_get_row_data
-                               (GTK_CTREE(mainwin->summaryview->ctree),
-                                GTK_CTREE_NODE(sel->data));
+                       msginfo = (MsgInfo *)sel->data;
                        if (msginfo) {
                                clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
                                if (!items[clabel]->active)
@@ -938,6 +987,7 @@ static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_i
        } else
                g_warning("invalid number of color elements (%d)\n", n);
 
+       g_slist_free(sel);
        /* reset "dont_toggle" state */
        g_object_set_data(G_OBJECT(menu), "dont_toggle",
                          GINT_TO_POINTER(0));
@@ -960,6 +1010,94 @@ static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
        summary_set_colorlabel(mainwin->summaryview, color, NULL);
 }
 
+static void mainwindow_tags_menu_item_activate_item_cb(GtkMenuItem *menu_item,
+                                                         gpointer data)
+{
+       MainWindow *mainwin;
+       GtkMenuShell *menu;
+       GList *cur;
+       GSList *sel;
+       GHashTable *menu_table = g_hash_table_new_full(
+                                       g_direct_hash,
+                                       g_direct_equal,
+                                       NULL, NULL);
+
+       mainwin = (MainWindow *)data;
+       g_return_if_fail(mainwin != NULL);
+
+       sel = summary_get_selection(mainwin->summaryview);
+       if (!sel) return;
+
+       menu = GTK_MENU_SHELL(mainwin->tags_menu);
+       g_return_if_fail(menu != NULL);
+
+       /* 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 (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
+               if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
+                       gint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cur->data),
+                               "tag_id"));
+                       gtk_check_menu_item_set_active
+                               (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
+                               
+                       g_hash_table_insert(menu_table, GINT_TO_POINTER(id), GTK_CHECK_MENU_ITEM(cur->data));
+               }
+       }
+
+       /* iterate all messages and set the state of the appropriate
+        * items */
+       for (; sel != NULL; sel = sel->next) {
+               MsgInfo *msginfo;
+               GSList *tags = NULL;
+               gint id;
+               GtkCheckMenuItem *item;
+               msginfo = (MsgInfo *)sel->data;
+               if (msginfo) {
+                       tags =  msginfo->tags;
+                       if (!tags)
+                               continue;
+
+                       for (; tags; tags = tags->next) {
+                               id = GPOINTER_TO_INT(tags->data);
+                               item = g_hash_table_lookup(menu_table, GINT_TO_POINTER(tags->data));
+                               if (item && !item->active)
+                                       gtk_check_menu_item_set_active
+                                               (item, TRUE);
+                       }
+               }
+       }
+
+       g_slist_free(sel);
+       g_hash_table_destroy(menu_table);
+       /* reset "dont_toggle" state */
+       g_object_set_data(G_OBJECT(menu), "dont_toggle",
+                         GINT_TO_POINTER(0));
+}
+
+static void mainwindow_tags_menu_item_activate_cb(GtkWidget *widget,
+                                                    gpointer data)
+{
+       gint id = GPOINTER_TO_INT(data);
+       gboolean set = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
+       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->tags_menu),
+                               "dont_toggle"))
+               return;
+
+       if (!set)
+               id = -id;
+       summary_set_tag(mainwin->summaryview, id, NULL);
+}
+
 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
 {
        GtkWidget *label_menuitem;
@@ -1009,19 +1147,139 @@ static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refr
                g_object_set_data(G_OBJECT(item), "mainwin",
                                  mainwin);
                gtk_widget_show(item);
-               gtk_widget_add_accelerator(item, "activate", 
+               if (i < 9)
+                       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 void mainwindow_tags_menu_item_new_tag_activate_cb(GtkWidget *widget,
+                                                    gpointer data)
+{
+       MainWindow *mainwin;
+       gint id;
+       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->tags_menu),
+                               "dont_toggle"))
+               return;
+       
+       id = prefs_tags_create_new(mainwin);
+       if (id != -1) {
+               summary_set_tag(mainwin->summaryview, id, NULL);
+               main_window_reflect_tags_changes(mainwindow_get_mainwindow());
+       }
+}
+
+static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
+{
+       GtkWidget *label_menuitem;
+       GtkWidget *menu;
+       GtkWidget *item;
+       GSList *cur = tags_get_list();
+       GSList *orig = cur;
+       gboolean existing_tags = FALSE;
+
+       label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
+                                                  "/Message/Tags");
+       g_signal_connect(G_OBJECT(label_menuitem), "activate",
+                        G_CALLBACK(mainwindow_tags_menu_item_activate_item_cb),
+                          mainwin);
+
+       gtk_widget_show(label_menuitem);
+
+       menu = gtk_menu_new();
+
+       /* create tags menu items */
+       for (; cur; cur = cur->next) {
+               gint id = GPOINTER_TO_INT(cur->data);
+               const gchar *tag = tags_get_tag(id);
+
+               item = gtk_check_menu_item_new_with_label(tag);
+               gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(mainwindow_tags_menu_item_activate_cb),
+                                GINT_TO_POINTER(id));
+               g_object_set_data(G_OBJECT(item), "mainwin",
+                                 mainwin);
+               g_object_set_data(G_OBJECT(item), "tag_id",
+                                 GINT_TO_POINTER(id));
+               gtk_widget_show(item);
+               existing_tags = TRUE;
+       }
+       if (existing_tags) {
+               /* separator */
+               item = gtk_menu_item_new();
+               gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+               gtk_widget_show(item);
+       }
+       item = gtk_menu_item_new_with_label(_("New tag..."));
+       gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(mainwindow_tags_menu_item_new_tag_activate_cb),
+                        NULL);
+       g_object_set_data(G_OBJECT(item), "mainwin",
+                         mainwin);
+       gtk_widget_show(item);
+       g_slist_free(orig);
+       gtk_widget_show(menu);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
+       mainwin->tags_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 *main_window_create()
 {
        MainWindow *mainwin;
        GtkWidget *window;
@@ -1039,9 +1297,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;
@@ -1061,10 +1319,12 @@ MainWindow *main_window_create(SeparateType type)
        mainwin = g_new0(MainWindow, 1);
 
        /* main window */
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow");
        gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
-
+#ifdef MAEMO
+       prefs_common.layout_mode = SMALL_LAYOUT;
+#endif
        if (!geometry.min_height) {
                geometry.min_width = 320;
                geometry.min_height = 200;
@@ -1096,7 +1356,11 @@ MainWindow *main_window_create(SeparateType type)
        menubar = menubar_create(window, mainwin_entries, 
                                 n_menu_entries, "<Main>", mainwin);
        gtk_widget_show(menubar);
+
+#ifndef MAEMO
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
+#endif
+
        ifactory = gtk_item_factory_from_widget(menubar);
 
 /*     gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
@@ -1119,11 +1383,17 @@ MainWindow *main_window_create(SeparateType type)
        }
        /* link window to mainwin->window to avoid gdk warnings */
        mainwin->window       = window;
+       mainwin_list = g_list_append(mainwin_list, mainwin);
        
-       /* create toolbar */
+#ifdef MAEMO
+       mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
+                                         window, 
+                                         (gpointer)mainwin);
+#else
        mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
                                          handlebox, 
                                          (gpointer)mainwin);
+#endif
        toolbar_set_learn_button
                (mainwin->toolbar,
                 LEARN_SPAM);
@@ -1137,22 +1407,48 @@ 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);
 
+#ifndef MAEMO
        progressbar = gtk_progress_bar_new();
        gtk_widget_set_size_request(progressbar, 120, 1);
        gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
-
+#endif
        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);
@@ -1167,9 +1463,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);
@@ -1183,11 +1478,40 @@ 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();
+
+       /* init log instances data before creating log views */
+       set_log_title(LOG_PROTOCOL, _("Network log"));
+       set_log_prefs(LOG_PROTOCOL,
+                       &prefs_common.logwin_width,
+                       &prefs_common.logwin_height);
+       set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
+       set_log_prefs(LOG_DEBUG_FILTERING,
+                       &prefs_common.filtering_debugwin_width,
+                       &prefs_common.filtering_debugwin_height);
+
+       /* setup log windows */
+       mainwin->logwin = log_window_create(LOG_PROTOCOL);
+       log_window_init(mainwin->logwin);
+
+       mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
+       log_window_set_clipping(mainwin->logwin,
+                               prefs_common.cliplog,
+                               prefs_common.loglength);
+
+       log_window_init(mainwin->filtering_debugwin);
+       log_window_set_clipping(mainwin->filtering_debugwin,
+                               prefs_common.filtering_debug_cliplog,
+                               prefs_common.filtering_debug_loglength);
+       if (prefs_common.enable_filtering_debug)
+               log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
+       else
+               log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
 
        folderview->mainwin      = mainwin;
        folderview->summaryview  = summaryview;
@@ -1205,7 +1529,9 @@ MainWindow *main_window_create(SeparateType type)
        mainwin->vbox_body      = vbox_body;
        mainwin->hbox_stat      = hbox_stat;
        mainwin->statusbar      = statusbar;
+#ifndef MAEMO
        mainwin->progressbar    = progressbar;
+#endif
        mainwin->statuslabel    = statuslabel;
        mainwin->online_switch  = online_switch;
        mainwin->online_pixmap  = online_pixmap;
@@ -1259,7 +1585,7 @@ MainWindow *main_window_create(SeparateType type)
 
        messageview->visible = prefs_common.msgview_visible;
 
-       main_window_set_widgets(mainwin, type);
+       main_window_set_widgets(mainwin, prefs_common.layout_mode);
 
        g_signal_connect(G_OBJECT(window), "size_allocate",
                         G_CALLBACK(main_window_size_allocate_cb),
@@ -1328,18 +1654,28 @@ MainWindow *main_window_create(SeparateType type)
           menu items in different menus             */
        menu_connect_identical_items();
 
-
+#ifndef MAEMO
        gtk_window_iconify(GTK_WINDOW(mainwin->window));
+#endif
+
+       g_signal_connect(G_OBJECT(window), "window_state_event",
+                        G_CALLBACK(mainwindow_state_event_cb), mainwin);
+       g_signal_connect(G_OBJECT(window), "visibility_notify_event",
+                        G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
+       gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
 
+       if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
+           prefs_common.layout_mode == SMALL_LAYOUT) {
+               summary_relayout(mainwin->summaryview); 
+       }
+       summary_update_unread(mainwin->summaryview, NULL);
+       
        gtk_widget_show(mainwin->window);
 
        /* initialize views */
        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
@@ -1352,15 +1688,16 @@ MainWindow *main_window_create(SeparateType type)
 
        if (!watch_cursor)
                watch_cursor = gdk_cursor_new(GDK_WATCH);
-
-       mainwin_list = g_list_append(mainwin_list, mainwin);
+       if (!hand_cursor)
+               hand_cursor = gdk_cursor_new(GDK_HAND2);
 
        /* init work_offline */
        if (prefs_common.work_offline)
                online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
 
        mainwindow_colorlabel_menu_create(mainwin, FALSE);
-
+       mainwindow_tags_menu_create(mainwin, FALSE);
+       
        return mainwin;
 }
 
@@ -1517,6 +1854,24 @@ void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
 
 }
 
+void main_window_reflect_tags_changes(MainWindow *mainwin)
+{
+       GtkMenuShell *menu;
+       GList *cur;
+
+       /* re-create tags submenu */
+       menu = GTK_MENU_SHELL(mainwin->tags_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_tags_menu_create(mainwin, TRUE);
+       summary_reflect_tags_changes(mainwin->summaryview);
+
+}
+
 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
 {
        if (prefs_tag == 0 || pixmap_theme_changed) {
@@ -1620,24 +1975,18 @@ 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;
+       GList *cur_ac;
        GtkWidget *menuitem;
        PrefsAccount *ac_prefs;
        GtkWidget *menu = NULL;
 
-       if (mainwin->toolbar->getall_btn == NULL
-       ||  mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
+       if (mainwin->toolbar->getall_btn == 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;
-       }
+       menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn));
+       if (menu)
+               gtk_widget_destroy(menu);
+       menu = gtk_menu_new();
 
        for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
                ac_prefs = (PrefsAccount *)cur_ac->data;
@@ -1651,29 +2000,43 @@ static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
                                 G_CALLBACK(account_receive_menu_cb),
                                 ac_prefs);
        }
+       gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->getall_btn), menu);
 }
 
 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
                                                       GList *account_list)
 {
-       GList *cur_ac, *cur_item;
+#ifndef MAEMO
+       GList *cur_ac;
        GtkWidget *menuitem;
        PrefsAccount *ac_prefs;
        GtkWidget *menu = NULL;
 
-       if (mainwin->toolbar->compose_mail_btn == NULL
-       ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
+       if (mainwin->toolbar->compose_mail_btn == NULL) /* button doesn't exist */
                return;
 
-       menu = mainwin->toolbar->compose_combo->menu;
+       menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn));
+       if (menu)
+               gtk_widget_destroy(menu);
+       menu = gtk_menu_new();
 
-       /* 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);
        }
+       gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_mail_btn), menu);
+       menu = gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_news_btn));
+       if (menu)
+               gtk_widget_destroy(menu);
+       menu = gtk_menu_new();
 
        for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
                ac_prefs = (PrefsAccount *)cur_ac->data;
@@ -1687,6 +2050,8 @@ static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
                                 G_CALLBACK(account_compose_menu_cb),
                                 ac_prefs);
        }
+       gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(mainwin->toolbar->compose_news_btn), menu);
+#endif
 }
 
 void main_window_set_account_menu(GList *account_list)
@@ -1701,6 +2066,7 @@ void main_window_set_account_menu(GList *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)
@@ -1738,41 +2104,17 @@ static void main_window_show_cur_account(MainWindow *mainwin)
        g_free(ac_name);
 }
 
-GtkWidget *main_window_get_folder_window(MainWindow *mainwin)
-{
-       switch (mainwin->type) {
-       case SEPARATE_FOLDER:
-               return mainwin->win.sep_folder.folderwin;
-       case SEPARATE_BOTH:
-               return mainwin->win.sep_both.folderwin;
-       default:
-               return NULL;
-       }
-}
-
-GtkWidget *main_window_get_message_window(MainWindow *mainwin)
-{
-       switch (mainwin->type) {
-       case SEPARATE_MESSAGE:
-               return mainwin->win.sep_message.messagewin;
-       case SEPARATE_BOTH:
-               return mainwin->win.sep_both.messagewin;
-       default:
-               return NULL;
-       }
-}
-
-void main_window_separation_change(MainWindow *mainwin, SeparateType type)
+static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
 {
        GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
        GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
-       /* GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview); */
        GtkWidget *message_wid = mainwin->messageview->vbox;
 
-       debug_print("Changing window separation type from %d to %d\n",
-                   mainwin->type, type);
+       if (layout_mode == prefs_common.layout_mode) 
+               return;
 
-       if (mainwin->type == type) return;
+       debug_print("Changing window separation type from %d to %d\n",
+                   prefs_common.layout_mode, layout_mode);
 
        /* remove widgets from those containers */
        gtk_widget_ref(folder_wid);
@@ -1785,27 +2127,8 @@ void main_window_separation_change(MainWindow *mainwin, SeparateType type)
        gtkut_container_remove
                (GTK_CONTAINER(message_wid->parent), message_wid);
 
-       /* clean containers */
-       switch (mainwin->type) {
-       case SEPARATE_NONE:
-               gtk_widget_destroy(mainwin->win.sep_none.hpaned);
-               break;
-       case SEPARATE_FOLDER:
-               gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
-               gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
-               break;
-       case SEPARATE_MESSAGE:
-               gtk_widget_destroy(mainwin->win.sep_message.hpaned);
-               gtk_widget_destroy(mainwin->win.sep_message.messagewin);
-               break;
-       case SEPARATE_BOTH:
-               gtk_widget_destroy(mainwin->win.sep_both.messagewin);
-               gtk_widget_destroy(mainwin->win.sep_both.folderwin);
-               break;
-       }
-
        gtk_widget_hide(mainwin->window);
-       main_window_set_widgets(mainwin, type);
+       main_window_set_widgets(mainwin, layout_mode);
        gtk_widget_show(mainwin->window);
 
        gtk_widget_unref(folder_wid);
@@ -1813,51 +2136,96 @@ void main_window_separation_change(MainWindow *mainwin, SeparateType type)
        gtk_widget_unref(message_wid);
 }
 
-void main_window_toggle_message_view(MainWindow *mainwin)
+void mainwindow_reset_paned(GtkPaned *paned)
 {
-       SummaryView *summaryview = mainwin->summaryview;
-       union CompositeWin *cwin = &mainwin->win;
-       GtkWidget *vpaned = NULL;
-       GtkWidget *container = NULL;
-       GtkWidget *msgwin = NULL;
+               gint min, max, mid;
 
-       switch (mainwin->type) {
-       case SEPARATE_NONE:
-               vpaned = cwin->sep_none.vpaned;
-               container = cwin->sep_none.hpaned;
-               break;
-       case SEPARATE_FOLDER:
-               vpaned = cwin->sep_folder.vpaned;
-               container = mainwin->vbox_body;
-               break;
-       case SEPARATE_MESSAGE:
-               msgwin = mainwin->win.sep_message.messagewin;
-               break;
-       case SEPARATE_BOTH:
-               msgwin = mainwin->win.sep_both.messagewin;
-               break;
-       }
+               if (gtk_paned_get_child1(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
+               if (gtk_paned_get_child2(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
+
+GTK_EVENTS_FLUSH();
+               g_object_get (G_OBJECT(paned),
+                               "min-position",
+                               &min, NULL);
+               g_object_get (G_OBJECT(paned),
+                               "max-position",
+                               &max, NULL);
+               mid = (min+max)/2;
+               gtk_paned_set_position(GTK_PANED(paned), mid);
+}
+
+static void mainwin_paned_show_first(GtkPaned *paned)
+{
+               gint max;
+               g_object_get (G_OBJECT(paned),
+                               "max-position",
+                               &max, NULL);
+
+               if (gtk_paned_get_child1(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
+               if (gtk_paned_get_child2(GTK_PANED(paned)))
+                       gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
+               gtk_paned_set_position(GTK_PANED(paned), max);
+}
+
+static void mainwin_paned_show_last(GtkPaned *paned)
+{
+               gint min;
+               g_object_get (G_OBJECT(paned),
+                               "min-position",
+                               &min, NULL);
+
+               if (gtk_paned_get_child1(GTK_PANED(paned)))
+                       gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
+               if (gtk_paned_get_child2(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
+               gtk_paned_set_position(GTK_PANED(paned), min);
+}
 
-       if (msgwin) {
-               if (GTK_WIDGET_VISIBLE(msgwin)) {
-                       gtk_widget_hide(msgwin);
+void main_window_toggle_message_view(MainWindow *mainwin)
+{
+       SummaryView *summaryview = mainwin->summaryview;
+       GtkWidget *ppaned = NULL;
+       GtkWidget *container = NULL;
+       
+       switch (prefs_common.layout_mode) {
+       case NORMAL_LAYOUT:
+       case VERTICAL_LAYOUT:
+       case SMALL_LAYOUT:
+               ppaned = mainwin->vpaned;
+               container = mainwin->hpaned;
+               if (ppaned->parent != NULL) {
                        mainwin->messageview->visible = FALSE;
                        summaryview->displayed = NULL;
+                       gtk_widget_ref(ppaned);
+                       gtkut_container_remove(GTK_CONTAINER(container), ppaned);
+                       gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
                } else {
-                       gtk_widget_show(msgwin);
                        mainwin->messageview->visible = TRUE;
+                       gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
+                       gtk_container_add(GTK_CONTAINER(container), ppaned);
+                       gtk_widget_unref(ppaned);
                }
-       } else if (vpaned->parent != NULL) {
-               mainwin->messageview->visible = FALSE;
-               summaryview->displayed = NULL;
-               gtk_widget_ref(vpaned);
-               gtkut_container_remove(GTK_CONTAINER(container), vpaned);
-               gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
-       } else {
-               mainwin->messageview->visible = TRUE;
-               gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
-               gtk_container_add(GTK_CONTAINER(container), vpaned);
-               gtk_widget_unref(vpaned);
+               break;
+       case WIDE_LAYOUT:
+               ppaned = mainwin->hpaned;
+               container = mainwin->vpaned;
+               if (mainwin->messageview->vbox->parent != NULL) {
+                       mainwin->messageview->visible = FALSE;
+                       summaryview->displayed = NULL;
+                       gtk_widget_ref(mainwin->messageview->vbox);
+                       gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
+               } else {
+                       mainwin->messageview->visible = TRUE;
+                       gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
+                       gtk_widget_unref(mainwin->messageview->vbox);
+               }
+               break;
+       case WIDE_MSGLIST_LAYOUT:
+               g_warning("can't hide messageview in this wide msglist layout");
+               break;
        }
 
        if (messageview_is_visible(mainwin->messageview))
@@ -1874,7 +2242,11 @@ void main_window_toggle_message_view(MainWindow *mainwin)
 
        prefs_common.msgview_visible = mainwin->messageview->visible;
 
-       gtk_widget_grab_focus(summaryview->ctree);
+       if (messageview_is_visible(mainwin->messageview)) {
+               gtk_widget_queue_resize(mainwin->hpaned);
+               gtk_widget_queue_resize(mainwin->vpaned);
+       }
+       summary_grab_focus(summaryview);
 }
 
 void main_window_get_size(MainWindow *mainwin)
@@ -1892,9 +2264,7 @@ void main_window_get_size(MainWindow *mainwin)
        if (allocation->width > 1 && allocation->height > 1) {
                prefs_common.summaryview_width = allocation->width;
 
-               if ((mainwin->type == SEPARATE_NONE ||
-                    mainwin->type == SEPARATE_FOLDER) &&
-                   messageview_is_visible(mainwin->messageview))
+               if (messageview_is_visible(mainwin->messageview))
                        prefs_common.summaryview_height = allocation->height;
 
                prefs_common.mainview_width = allocation->width;
@@ -1933,7 +2303,6 @@ void main_window_get_size(MainWindow *mainwin)
 void main_window_get_position(MainWindow *mainwin)
 {
        gint x, y;
-       GtkWidget *window;
 
        gtkut_widget_get_uposition(mainwin->window, &x, &y);
 
@@ -1943,21 +2312,6 @@ void main_window_get_position(MainWindow *mainwin)
        prefs_common.mainwin_y = y;
 
        debug_print("main window position: %d, %d\n", x, y);
-
-       window = main_window_get_folder_window(mainwin);
-       if (window) {
-               gtkut_widget_get_uposition(window, &x, &y);
-               prefs_common.folderwin_x = x;
-               prefs_common.folderwin_y = y;
-               debug_print("folder window position: %d, %d\n", x, y);
-       }
-       window = main_window_get_message_window(mainwin);
-       if (window) {
-               gtkut_widget_get_uposition(window, &x, &y);
-               prefs_common.main_msgwin_x = x;
-               prefs_common.main_msgwin_y = y;
-               debug_print("message window position: %d, %d\n", x, y);
-       }
 }
 
 void main_window_progress_on(MainWindow *mainwin)
@@ -1983,10 +2337,10 @@ void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
 
 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
 {
-       if (confirm) {
+       if (confirm && procmsg_have_trashed_mails_fast()) {
                if (alertpanel(_("Empty trash"),
                               _("Delete all messages in trash folders?"),
-                              GTK_STOCK_CANCEL, _("+_Empty trash"), NULL)
+                              GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
                    != G_ALERTALTERNATE)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
@@ -2006,7 +2360,7 @@ void main_window_add_mailbox(MainWindow *mainwin)
 
        path = input_dialog(_("Add mailbox"),
                            _("Input the location of mailbox.\n"
-                             "If the existing mailbox is specified, it will be\n"
+                             "If an existing mailbox is specified, it will be\n"
                              "scanned automatically."),
                            "Mail");
        if (!path) return;
@@ -2039,6 +2393,7 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
        SummarySelection selection;
        FolderItem *item = mainwin->summaryview->folder_item;
        GList *account_list = account_get_list();
+       GSList *tmp;
        
        selection = summary_get_selection_type(mainwin->summaryview);
 
@@ -2057,7 +2412,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;
@@ -2073,6 +2428,17 @@ 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;
+
+       tmp = tags_get_list();
+       if (tmp && g_slist_length(tmp))
+               state |= M_TAGS_EXIST;
+       g_slist_free(tmp);
+
+       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) ||
@@ -2082,6 +2448,9 @@ 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;
@@ -2089,12 +2458,17 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
                }
        }
        
-       if (procmsg_spam_can_learn()) {
+       if (procmsg_spam_can_learn() &&
+           (mainwin->summaryview->folder_item &&
+            mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
+            mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
                state |= M_CAN_LEARN_SPAM;
        }
 
        if (inc_is_active())
                state |= M_INC_ACTIVE;
+       if (imap_cancel_all_enabled())
+               state |= M_INC_ACTIVE;
 
        if (mainwin->summaryview->deleted > 0 ||
            mainwin->summaryview->moved > 0 ||
@@ -2124,10 +2498,15 @@ 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/Select thread"             , M_TARGET_EXIST},
+               {"/Edit/Delete thread"             , M_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},
@@ -2143,9 +2522,9 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/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/Quotes"                    , 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},
@@ -2153,7 +2532,7 @@ 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_TARGET_EXIST},
                {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
@@ -2169,7 +2548,12 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/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/Tags"                  , M_TARGET_EXIST},
                {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
 
                {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
@@ -2180,11 +2564,15 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/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/List URLs..."                 , 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},
 
                {"/Configuration", M_UNLOCKED},
+               {"/Configuration/Preferences for current account...", M_UNLOCKED},
+               {"/Configuration/Create new account...", M_UNLOCKED},
+               {"/Configuration/Edit accounts...", M_UNLOCKED},
 
                {NULL, 0}
        };
@@ -2233,6 +2621,8 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                menu_path = "/View/Sort/by Size"; break;
        case SORT_BY_DATE:
                menu_path = "/View/Sort/by Date"; break;
+       case SORT_BY_THREAD_DATE:
+               menu_path = "/View/Sort/by Thread date"; break;
        case SORT_BY_FROM:
                menu_path = "/View/Sort/by From"; break;
        case SORT_BY_TO:
@@ -2251,6 +2641,8 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                menu_path = "/View/Sort/by score"; break;
        case SORT_BY_LOCKED:
                menu_path = "/View/Sort/by locked"; break;
+       case SORT_BY_TAGS:
+               menu_path = "/View/Sort/by tag"; break;
        case SORT_BY_NONE:
        default:
                menu_path = "/View/Sort/Don't sort"; break;
@@ -2274,9 +2666,12 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
        if (mainwin->messageview 
        &&  mainwin->messageview->mimeview
        &&  mainwin->messageview->mimeview->textview)
-               SET_CHECK_MENU_ACTIVE("/View/Show all headers",
+               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)
@@ -2309,39 +2704,50 @@ static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msgi
 {
        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 (msginfo && !strcmp2 (msginfo->list_post, "NO")) {
-               msginfo->list_post = g_strdup (_("No posting allowed"));
+       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->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->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->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->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->list_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->list_owner);
+       menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
        
        return menu_nb;
 }
@@ -2370,15 +2776,17 @@ static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * li
                        item = NULL;
                        if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
                                item = gtk_menu_item_new_with_label ((url_decoded));
-                               gtk_signal_connect (GTK_OBJECT(item), "activate",
-                                               GTK_SIGNAL_FUNC(mailing_list_compose), NULL);
+                               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));
-                               gtk_signal_connect (GTK_OBJECT(item), "activate",
-                                               GTK_SIGNAL_FUNC(mailing_list_open_uri), NULL);
+                               g_signal_connect(G_OBJECT(item), "activate",
+                                                G_CALLBACK(mailing_list_open_uri),
+                                                NULL);
                        } 
                        if (item) {
                                gtk_menu_append (GTK_MENU(menu), item);
@@ -2402,7 +2810,8 @@ static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
        const gchar *buf;
        gint i = 0;
        buf = *buffer;
-       
+       gboolean with_plus = TRUE;
+
        if (buf == 0x00) {
                *url_decoded = '\0';
                *buffer = NULL;
@@ -2416,6 +2825,8 @@ static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
        /* First non space and non comment must be a < */
        if (*buf =='<' ) {
                buf++;
+               if (!strncmp(buf, "mailto:", strlen("mailto:")))
+                       with_plus = FALSE;
                for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
                buf++;
        }
@@ -2432,7 +2843,7 @@ static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
        if (i == maxlen) {
                return;
        }
-       decode_uri (url_decoded, (const gchar *)tmp);
+       decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
 
        /* Prepare the work for the next url in the list */
        /* after the closing bracket >, ignore space, comments and tabs */
@@ -2472,21 +2883,16 @@ static void mailing_list_compose (GtkWidget *w, gpointer *data)
        
 void main_window_popup(MainWindow *mainwin)
 {
-       gtkut_window_popup(mainwin->window);
+       if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
+               main_window_show(mainwin);
 
-       switch (mainwin->type) {
-       case SEPARATE_FOLDER:
-               gtkut_window_popup(mainwin->win.sep_folder.folderwin);
-               break;
-       case SEPARATE_MESSAGE:
-               gtkut_window_popup(mainwin->win.sep_message.messagewin);
-               break;
-       case SEPARATE_BOTH:
-               gtkut_window_popup(mainwin->win.sep_both.folderwin);
-               gtkut_window_popup(mainwin->win.sep_both.messagewin);
-               break;
-       default:
-               break;
+       gtkut_window_popup(mainwin->window);
+       if (prefs_common.layout_mode == SMALL_LAYOUT) {
+               if (mainwin->in_folder) {
+                       mainwindow_enter_folder(mainwin);
+               } else {
+                       mainwindow_exit_folder(mainwin);
+               }
        }
 }
 
@@ -2508,24 +2914,6 @@ void main_window_show(MainWindow *mainwin)
        gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
                             prefs_common.msgview_width,
                             prefs_common.msgview_height);
-
-       if (mainwin->type & SEPARATE_FOLDER) {
-               GtkWidget *folderwin;
-
-               folderwin = main_window_get_folder_window(mainwin);
-               gtk_widget_show(folderwin);
-               gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
-                                         prefs_common.folderwin_y);
-       }
-
-       if (mainwin->type & SEPARATE_MESSAGE) {
-               GtkWidget *messagewin;
-
-               messagewin = main_window_get_message_window(mainwin);
-               gtk_widget_show(messagewin);
-               gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
-                                         prefs_common.main_msgwin_y);
-       }
 }
 
 void main_window_hide(MainWindow *mainwin)
@@ -2535,17 +2923,9 @@ void main_window_hide(MainWindow *mainwin)
 
        gtk_widget_hide(mainwin->window);
        gtk_widget_hide(mainwin->vbox_body);
-
-       if (mainwin->type & SEPARATE_FOLDER) {
-               gtk_widget_hide(mainwin->win.sep_folder.folderwin);
-       }
-
-       if (mainwin->type & SEPARATE_MESSAGE) {
-               gtk_widget_hide(mainwin->win.sep_message.messagewin);
-       }
 }
 
-static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
+static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
 {
        GtkWidget *folderwin = NULL;
        GtkWidget *messagewin = NULL;
@@ -2554,101 +2934,57 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
        GtkWidget *vbox_body = mainwin->vbox_body;
        GtkItemFactory *ifactory = mainwin->menu_factory;
        GtkWidget *menuitem;
-       GtkItemFactory *msgview_ifactory;
-
+       gboolean first_set = (mainwin->hpaned == NULL);
        debug_print("Setting widgets... ");
 
-       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
+       if (layout_mode == SMALL_LAYOUT && first_set) {
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
                                    prefs_common.folderview_width,
                                    prefs_common.folderview_height);
-       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
+                                   0,0);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
+                                   0,0);
+       } else {
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
+                                   prefs_common.folderview_width,
+                                   prefs_common.folderview_height);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
                                    prefs_common.summaryview_width,
                                    prefs_common.summaryview_height);
-       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
                                    prefs_common.msgview_width,
                                    prefs_common.msgview_height);
-
-       /* create separated window(s) if needed */
-       if (type & SEPARATE_FOLDER) {
-               static GdkGeometry folderwin_geometry;
-               
-               folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-               gtk_window_set_title(GTK_WINDOW(folderwin),
-                                    _("Sylpheed-Claws - Folder View"));
-
-               gtk_window_move(GTK_WINDOW(folderwin),
-                               prefs_common.folderwin_x,
-                               prefs_common.folderwin_y);
-
-               if (!folderwin_geometry.min_height) {
-                       folderwin_geometry.min_width = 320;
-                       folderwin_geometry.min_height = 200;
-               }
-               gtk_window_set_geometry_hints(GTK_WINDOW(folderwin), NULL,
-                                             &folderwin_geometry, GDK_HINT_MIN_SIZE);
-                               
-               gtk_widget_set_size_request(folderwin,
-                                           prefs_common.folderview_width,
-                                           prefs_common.folderview_height);
-
-               gtk_container_set_border_width(GTK_CONTAINER(folderwin),
-                                              BORDER_WIDTH);
-
-               g_signal_connect(G_OBJECT(folderwin), "delete_event",
-                                G_CALLBACK(folder_window_close_cb),
-                                  mainwin);
-               gtk_container_add(GTK_CONTAINER(folderwin),
-                                 GTK_WIDGET_PTR(mainwin->folderview));
-               gtk_widget_realize(folderwin);
-
-               if (prefs_common.folderview_visible)
-                       gtk_widget_show(folderwin);
        }
 
-       if (type & SEPARATE_MESSAGE) {
-               static GdkGeometry msgwin_geometry;
-               
-               messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-               gtk_window_set_title(GTK_WINDOW(messagewin),
-                                    _("Sylpheed-Claws - Message View"));
-                                    
-               gtk_window_move(GTK_WINDOW(messagewin), 
-                               prefs_common.main_msgwin_x,
-                               prefs_common.main_msgwin_y);
-
-               if (!msgwin_geometry.min_height) {
-                       msgwin_geometry.min_width = 320;
-                       msgwin_geometry.min_height = 200;
-               }
-               gtk_window_set_geometry_hints(GTK_WINDOW(messagewin), NULL,
-                                             &msgwin_geometry, GDK_HINT_MIN_SIZE);
-               
-               gtk_widget_set_size_request(messagewin, 
-                                           prefs_common.msgwin_width,
-                                           prefs_common.msgwin_height);
-
-               gtk_container_set_border_width(GTK_CONTAINER(messagewin),
-                                              BORDER_WIDTH);
-               g_signal_connect(G_OBJECT(messagewin), "delete_event",
-                                G_CALLBACK(message_window_close_cb),
-                                mainwin);
-               if (messageview_is_visible(mainwin->messageview))
-                       gtk_widget_show(messagewin);
-       } else {
-               mainwin->messageview->statusbar = mainwin->statusbar;
-               mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
+       mainwin->messageview->statusbar = mainwin->statusbar;
+       mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
+
+       /* clean top-most container */
+       if (mainwin->hpaned) {
+               if (mainwin->hpaned->parent == mainwin->vpaned)
+                       gtk_widget_destroy(mainwin->vpaned);
+               else
+                       gtk_widget_destroy(mainwin->hpaned);
        }
 
-       switch (type) {
-       case SEPARATE_NONE:
+       menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
+               (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
+       switch (layout_mode) {
+       case VERTICAL_LAYOUT:
+       case NORMAL_LAYOUT:
+       case SMALL_LAYOUT:
                hpaned = gtk_hpaned_new();
+               if (layout_mode == VERTICAL_LAYOUT)
+                       vpaned = gtk_hpaned_new();
+               else
+                       vpaned = gtk_vpaned_new();
                gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
                gtk_paned_add1(GTK_PANED(hpaned),
                               GTK_WIDGET_PTR(mainwin->folderview));
                gtk_widget_show(hpaned);
                gtk_widget_queue_resize(hpaned);
 
-               vpaned = gtk_vpaned_new();
                if (messageview_is_visible(mainwin->messageview)) {
                        gtk_paned_add2(GTK_PANED(hpaned), vpaned);
                        gtk_paned_add1(GTK_PANED(vpaned),
@@ -2661,94 +2997,91 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                gtk_paned_add2(GTK_PANED(vpaned),
                               GTK_WIDGET_PTR(mainwin->messageview));
                gtk_widget_show(vpaned);
+               if (layout_mode == SMALL_LAYOUT && first_set) {
+                       mainwin_paned_show_first(GTK_PANED(hpaned));
+               }
                gtk_widget_queue_resize(vpaned);
-
-               mainwin->win.sep_none.hpaned = hpaned;
-               mainwin->win.sep_none.vpaned = vpaned;
-               
-               /* remove headerview if not in prefs */
-               headerview_set_visibility(mainwin->messageview->headerview,
-                                         prefs_common.display_header_pane);
                break;
-       case SEPARATE_FOLDER:
+       case WIDE_LAYOUT:
                vpaned = gtk_vpaned_new();
+               hpaned = gtk_hpaned_new();
+               gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
+               gtk_paned_add1(GTK_PANED(vpaned), hpaned);
+
+               gtk_paned_add1(GTK_PANED(hpaned),
+                              GTK_WIDGET_PTR(mainwin->folderview));
+               gtk_paned_add2(GTK_PANED(hpaned),
+                              GTK_WIDGET_PTR(mainwin->summaryview));
+
+               gtk_widget_show(hpaned);
+               gtk_widget_queue_resize(hpaned);
+
                if (messageview_is_visible(mainwin->messageview)) {
-                       gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
-                                          TRUE, TRUE, 0);
-                       gtk_paned_add1(GTK_PANED(vpaned),
-                                      GTK_WIDGET_PTR(mainwin->summaryview));
+                       gtk_paned_add2(GTK_PANED(vpaned),
+                              GTK_WIDGET_PTR(mainwin->messageview));   
                } else {
-                       gtk_box_pack_start(GTK_BOX(vbox_body),
-                                          GTK_WIDGET_PTR(mainwin->summaryview),
-                                          TRUE, TRUE, 0);
-                       gtk_widget_ref(vpaned);
+                       gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
                }
-               gtk_paned_add2(GTK_PANED(vpaned),
-                              GTK_WIDGET_PTR(mainwin->messageview));
                gtk_widget_show(vpaned);
                gtk_widget_queue_resize(vpaned);
-
-               mainwin->win.sep_folder.folderwin = folderwin;
-               mainwin->win.sep_folder.vpaned    = vpaned;
-
-               /* remove headerview if not in prefs */
-               headerview_set_visibility(mainwin->messageview->headerview,
-                                         prefs_common.display_header_pane);
-               
                break;
-       case SEPARATE_MESSAGE:
+       case WIDE_MSGLIST_LAYOUT:
+               vpaned = gtk_vpaned_new();
                hpaned = gtk_hpaned_new();
-               gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
+               gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
+
+               gtk_paned_add1(GTK_PANED(vpaned),
+                              GTK_WIDGET_PTR(mainwin->summaryview));
                gtk_paned_add1(GTK_PANED(hpaned),
                               GTK_WIDGET_PTR(mainwin->folderview));
-               gtk_paned_add2(GTK_PANED(hpaned),
-                              GTK_WIDGET_PTR(mainwin->summaryview));
+
                gtk_widget_show(hpaned);
                gtk_widget_queue_resize(hpaned);
-               messageview_add_toolbar(mainwin->messageview, messagewin);
-               msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
-               menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
 
-               mainwin->win.sep_message.messagewin = messagewin;
-               mainwin->win.sep_message.hpaned     = hpaned;
+               if (messageview_is_visible(mainwin->messageview)) {
+                       gtk_paned_add2(GTK_PANED(hpaned),
+                              GTK_WIDGET_PTR(mainwin->messageview));   
+               } else {
+                       gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
+               }
+               gtk_paned_add2(GTK_PANED(vpaned), hpaned);
 
-               gtk_widget_realize(messagewin);
-               gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
-               gtk_widget_show_all(messagewin);
-               toolbar_set_style(mainwin->messageview->toolbar->toolbar, 
-                                 mainwin->messageview->handlebox, 
-                                 prefs_common.toolbar_style);
+               gtk_widget_show(vpaned);
+               gtk_widget_queue_resize(vpaned);
+               break;
+       default:
+               g_warning("Unknown layout");
+               return;
+       }
 
-               /* remove headerview if not in prefs */
-               headerview_set_visibility(mainwin->messageview->headerview,
-                                         prefs_common.display_header_pane);
+       mainwin->hpaned = hpaned;
+       mainwin->vpaned = vpaned;
 
-               break;
-       case SEPARATE_BOTH:
-               messageview_add_toolbar(mainwin->messageview, messagewin);
-               msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
-               menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
-
-               gtk_box_pack_start(GTK_BOX(vbox_body),
-                                  GTK_WIDGET_PTR(mainwin->summaryview),
-                                  TRUE, TRUE, 0);
-               
-               mainwin->win.sep_both.folderwin = folderwin;
-               mainwin->win.sep_both.messagewin = messagewin;
-               
-               gtk_widget_realize(messagewin);
-               gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
-               gtk_widget_show_all(messagewin);
-               toolbar_set_style(mainwin->messageview->toolbar->toolbar, 
-                                 mainwin->messageview->handlebox, 
-                                 prefs_common.toolbar_style);          
-
-               /* remove headerview if not in prefs */
-               headerview_set_visibility(mainwin->messageview->headerview,
-                                         prefs_common.display_header_pane);
+       if (layout_mode == SMALL_LAYOUT) {
+               if (mainwin->messageview->visible)
+                       main_window_toggle_message_view(mainwin);
+       } 
 
-               break;
-       }
+       if (layout_mode == SMALL_LAYOUT && first_set) {
+               gtk_widget_realize(mainwin->window);
+               gtk_widget_realize(mainwin->folderview->ctree);
+               gtk_widget_realize(mainwin->summaryview->hbox);
+               gtk_widget_realize(mainwin->summaryview->hbox_l);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
+                                   prefs_common.folderview_width,
+                                   prefs_common.folderview_height);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
+                                   0,0);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
+                                   0,0);
+               gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
+                               prefs_common.mainwin_width,
+                               prefs_common.mainwin_height);
+               gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
+       } 
+       /* remove headerview if not in prefs */
+       headerview_set_visibility(mainwin->messageview->headerview,
+                                 prefs_common.display_header_pane);
 
        if (messageview_is_visible(mainwin->messageview))
                gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
@@ -2775,30 +3108,40 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
        else 
                gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
 
-       mainwin->type = type;
-
+       prefs_common.layout_mode = layout_mode;
 
-       /* toggle menu state */
-       menuitem = gtk_item_factory_get_item
-               (ifactory, "/View/Show or hide/Folder tree");
-       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
-                                      (type & SEPARATE_FOLDER) == 0 ? TRUE :
-                                      prefs_common.folderview_visible);
-       gtk_widget_set_sensitive(menuitem, ((type & SEPARATE_FOLDER) != 0));
        menuitem = gtk_item_factory_get_item
                (ifactory, "/View/Show or hide/Message view");
        gtk_check_menu_item_set_active
                (GTK_CHECK_MENU_ITEM(menuitem),
                 messageview_is_visible(mainwin->messageview));
 
-       menuitem = gtk_item_factory_get_item
-               (ifactory, "/View/Separate folder tree");
-       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
-                                      ((type & SEPARATE_FOLDER) != 0));
-       menuitem = gtk_item_factory_get_item
-               (ifactory, "/View/Separate message view");
-       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
-                                      ((type & SEPARATE_MESSAGE) != 0));
+#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); \
+}
+
+#ifndef MAEMO
+       switch (prefs_common.layout_mode) {
+       case NORMAL_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
+               break;
+       case VERTICAL_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
+               break;
+       case WIDE_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
+               break;
+       case WIDE_MSGLIST_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
+               break;
+       case SMALL_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
+               break;
+       }
+#endif
+#undef SET_CHECK_MENU_ACTIVE
 
        if (folderwin) {
                g_signal_connect
@@ -2873,38 +3216,12 @@ static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
                                 gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
+       gboolean close_allowed = TRUE;
 
-       if (mainwin->lock_count == 0)
-               app_exit_cb(data, 0, widget);
-
-       return TRUE;
-}
-
-static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
-                                  gpointer data)
-{
-       MainWindow *mainwin = (MainWindow *)data;
-       GtkWidget *menuitem;
-
-       menuitem = gtk_item_factory_get_item
-               (mainwin->menu_factory, "/View/Show or hide/Folder tree");
-       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
-
-       return TRUE;
-}
-
-static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
-                                   gpointer data)
-{
-       MainWindow *mainwin = (MainWindow *)data;
-       GtkWidget *menuitem;
-
-       menuitem = gtk_item_factory_get_item
-               (mainwin->menu_factory, "/View/Show or hide/Message view");
-       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
+       hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
 
-       mainwin->messageview->statusbar = mainwin->statusbar;
-       mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
+       if (close_allowed && mainwin->lock_count == 0)
+               app_exit_cb(data, 0, widget);
 
        return TRUE;
 }
@@ -2914,7 +3231,6 @@ static void main_window_size_allocate_cb(GtkWidget *widget,
                                         gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
-
        main_window_get_size(mainwin);
 }
 
@@ -3001,7 +3317,7 @@ 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?"),
+               if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
                               GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
                    != G_ALERTALTERNATE)
                        return;
@@ -3021,37 +3337,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);
-}
-
-static void toggle_folder_cb(MainWindow *mainwin, guint action,
-                            GtkWidget *widget)
-{
-       gboolean active;
-
-       active = GTK_CHECK_MENU_ITEM(widget)->active;
-
-       switch (mainwin->type) {
-       case SEPARATE_NONE:
-       case SEPARATE_MESSAGE:
-               break;
-       case SEPARATE_FOLDER:
-               debug_print("separate folder\n");
-               if (active)
-                       gtk_widget_show(mainwin->win.sep_folder.folderwin);
-               else
-                       gtk_widget_hide(mainwin->win.sep_folder.folderwin);
-               break;
-       case SEPARATE_BOTH:
-               if (active)
-                       gtk_widget_show(mainwin->win.sep_both.folderwin);
-               else
-                       gtk_widget_hide(mainwin->win.sep_both.folderwin);
-               break;
-       }
-
-       prefs_common.folderview_visible = active;
+       summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
 }
 
 static void toggle_message_cb(MainWindow *mainwin, guint action,
@@ -3071,7 +3357,7 @@ static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
        toolbar_toggle(action, mainwin);
 }
 
-void main_window_reply_cb(MainWindow *mainwin, guint action,
+static void main_window_reply_cb(MainWindow *mainwin, guint action,
                          GtkWidget *widget)
 {
        MessageView *msgview = (MessageView*)mainwin->messageview;
@@ -3098,21 +3384,41 @@ static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
        }
 }
 
-static void separate_widget_cb(MainWindow *mainwin, guint action,
+#ifndef MAEMO
+static void set_layout_cb(MainWindow *mainwin, guint action,
                               GtkWidget *widget)
 {
-       SeparateType type;
-
-       if (GTK_CHECK_MENU_ITEM(widget)->active)
-               type = mainwin->type | action;
-       else
-               type = mainwin->type & ~action;
-
-       main_window_separation_change(mainwin, type);
-
-       prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
-       prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
+       LayoutType layout_mode = action;
+       LayoutType old_layout_mode = prefs_common.layout_mode;
+       if (mainwin->menu_lock_count) {
+               return;
+       }
+       if (!GTK_CHECK_MENU_ITEM(widget)->active) {
+               return;
+       }
+       
+       if (layout_mode == prefs_common.layout_mode) {
+               return;
+       }
+       
+       if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
+               main_window_toggle_message_view(mainwin);
+       else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
+               main_window_toggle_message_view(mainwin);
+
+       main_window_separation_change(mainwin, layout_mode);
+       mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
+       if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
+               mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
+       }
+       if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
+               mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
+               mainwindow_exit_folder(mainwin);
+       }
+       summary_relayout(mainwin->summaryview); 
+       summary_update_unread(mainwin->summaryview, NULL);
 }
+#endif
 
 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
                                        gboolean ask_sync)
@@ -3130,29 +3436,34 @@ 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;
 
        /* see if there are synchronised folders */
        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_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
                return;
-
-       folder_synchronise(NULL);
+       
+       if (offline_ask_sync)
+               folder_synchronise(NULL);
 }
 
 static void online_switch_clicked (GtkButton *btn, gpointer data) 
@@ -3178,9 +3489,10 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
                /* go offline */
                if (prefs_common.work_offline)
                        return;
-               prefs_common.work_offline = TRUE;
                mainwindow_check_synchronise(mainwin, TRUE);
+               prefs_common.work_offline = TRUE;
                imap_disconnect_all();
+               hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
        } else {
                /*go online */
                if (!prefs_common.work_offline)
@@ -3191,6 +3503,7 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
                prefs_common.work_offline = FALSE;
                inc_autocheck_timer_set();
                refresh_resolvers();
+               hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
        }
 }
 
@@ -3206,9 +3519,16 @@ static void log_window_show_cb(MainWindow *mainwin, guint action,
        log_window_show(mainwin->logwin);
 }
 
+static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
+                              GtkWidget *widget)
+{
+       log_window_show(mainwin->filtering_debugwin);
+}
+
 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        inc_cancel_all();
+       imap_cancel_all();
 }
 
 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
@@ -3281,8 +3601,7 @@ static void hide_quotes_cb(MainWindow *mainwin, guint action,
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
        mainwin->menu_lock_count--;
 
-       summary_display_msg_selected(mainwin->summaryview,
-                       mainwin->summaryview->messageview->all_headers);
+       summary_redisplay_msg(mainwin->summaryview);
 }
 
 #undef SET_CHECK_MENU_ACTIVE
@@ -3320,11 +3639,45 @@ static void mark_as_spam_cb(MainWindow *mainwin, guint action,
        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);
 }
 
+static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
+{
+       if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
+               summary_display_msg_selected(mainwin->summaryview, 
+                       mainwin->messageview->mimeview->textview->show_all_headers);
+       }
+       messageview_list_urls(mainwin->messageview);
+}
+
 static void add_address_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
@@ -3487,7 +3840,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),
@@ -3606,7 +3962,7 @@ static void goto_folder_cb(MainWindow *mainwin, guint action,
 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       folderview_select_next_unread(mainwin->folderview);
+       folderview_select_next_unread(mainwin->folderview, FALSE);
 }
 
 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
@@ -3628,7 +3984,13 @@ static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 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,
@@ -3681,6 +4043,12 @@ static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_actions_open(mainwin);
 }
+
+static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
+                                 GtkWidget *widget)
+{
+       prefs_tags_open(mainwin);
+}
 #ifdef USE_OPENSSL
 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
                                  GtkWidget *widget)
@@ -3740,7 +4108,7 @@ static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
        PrefsAccount *account = (PrefsAccount *)data;
        FolderItem *item = mainwin->summaryview->folder_item;   
 
-       compose_new_with_folderitem(account, item);
+       compose_new_with_folderitem(account, item, NULL);
 }
 
 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
@@ -3801,6 +4169,34 @@ static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focu
        return FALSE;
 }
 
+static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
+                                         gpointer data)
+{
+       is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
+       return FALSE;
+}
+
+static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
+                                         gpointer data)
+{
+       if (!claws_is_starting()
+               && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
+               && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
+
+               if (iconified_count > 0)
+                       hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
+               iconified_count++;
+       }
+       if (state->new_window_state == 0)
+               gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
+       return FALSE;
+}
+
+gboolean mainwindow_is_obscured(void)
+{
+       return is_obscured;
+}
+
 #define BREAK_ON_MODIFIER_KEY() \
        if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
 
@@ -3832,9 +4228,18 @@ gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                            && 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);
+                       folderview_select_next_unread(mainwin->folderview, TRUE);
                }
                break;
+#ifdef MAEMO
+       case GDK_F6:
+               if (maemo_mainwindow_is_fullscreen(widget)) {
+                       gtk_window_unfullscreen(GTK_WINDOW(widget));
+                } else {
+                       gtk_window_fullscreen(GTK_WINDOW(widget));
+                }
+               break;
+#endif
        default:
                break;
        }
@@ -3876,7 +4281,7 @@ MainWindow *mainwindow_get_mainwindow(void)
                return NULL;
 }
 
-gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
+static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
 {
        ProgressData *data = (ProgressData *) source;
        MainWindow *mainwin = (MainWindow *) userdata;
@@ -3907,7 +4312,7 @@ void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
        summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
 }
 
-void mainwindow_jump_to(const gchar *target)
+void mainwindow_jump_to(const gchar *target, gboolean popup)
 {
        gchar *tmp = NULL;
        gchar *p = NULL;
@@ -3919,7 +4324,7 @@ void mainwindow_jump_to(const gchar *target)
                return;
                
        if (!mainwin) {
-               printf(_("not initialized\n"));
+               printf("not initialized\n");
                return;
        }
 
@@ -3931,9 +4336,10 @@ void mainwindow_jump_to(const gchar *target)
                *p = '\0';
 
        if ((item = folder_find_item_from_identifier(tmp))) {
-               printf(_("selecting folder '%s'\n"), tmp);
+               printf("selecting folder '%s'\n", tmp);
                folderview_select(mainwin->folderview, item);
-               main_window_popup(mainwin);
+               if (popup)
+                       main_window_popup(mainwin);
                g_free(tmp);
                return;
        }
@@ -3942,20 +4348,79 @@ void mainwindow_jump_to(const gchar *target)
        if (msg) {
                *msg++ = '\0';
                if ((item = folder_find_item_from_identifier(tmp))) {
-                       printf(_("selecting folder '%s'\n"), 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));
+                       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);
+                       if (popup)
+                               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);
+                               if (popup)
+                                       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);
        }
        
-       printf("'%s' not found\n", tmp);
-       
        g_free(tmp);
 }
+
+void mainwindow_exit_folder(MainWindow *mainwin) {
+       if (prefs_common.layout_mode == SMALL_LAYOUT) {
+               folderview_close_opened(mainwin->folderview);
+               mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
+       }
+       mainwin->in_folder = FALSE;
+}
+
+void mainwindow_enter_folder(MainWindow *mainwin) {
+       if (prefs_common.layout_mode == SMALL_LAYOUT) {
+               mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
+       }
+       mainwin->in_folder = TRUE;
+}
+
+#ifdef MAEMO
+gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
+{
+       gint w, h;
+       gtk_window_get_size(GTK_WINDOW(widget), &w, &h); 
+       return (w == 800);
+}
+
+void maemo_window_full_screen_if_needed (GtkWindow *window)
+{
+       if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
+               gtk_window_fullscreen(GTK_WINDOW(window));
+       }
+}
+
+void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
+{
+       g_signal_connect(G_OBJECT(window), "key_press_event",
+                        G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());
+}
+#endif