2008-07-05 [colin] 3.5.0cvs12
[claws.git] / src / mainwindow.c
index 7ac43eaaae2ee6f11aa3d59da1267100a876cc0e..953fe3525e4c047c99c747a8cb99d4ed75fd5cd4 100644 (file)
@@ -1,20 +1,19 @@
 /*
- * Sylpheed -- 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 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-2008 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"
@@ -61,6 +60,7 @@
 #include "procmsg.h"
 #include "import.h"
 #include "export.h"
+#include "edittags.h"
 #include "prefs_common.h"
 #include "prefs_actions.h"
 #include "prefs_filtering.h"
 #include "foldersort.h"
 #include "icon_legend.h"
 #include "colorlabel.h"
+#include "tags.h"
 #include "textview.h"
 #include "imap.h"
 #include "socket.h"
+#include "printing.h"
 
 #define AC_LABEL_WIDTH 240
 
@@ -112,10 +114,10 @@ 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);
-
+#ifndef GENERIC_UMPC
 static void main_window_separation_change      (MainWindow     *mainwin,
                                                 LayoutType      layout_mode);
-
+#endif
 static void main_window_set_widgets            (MainWindow     *mainwin,
                                                 LayoutType      layout_mode);
 
@@ -125,11 +127,11 @@ static void toolbar_child_attached                (GtkWidget      *widget,
 static void toolbar_child_detached             (GtkWidget      *widget,
                                                 GtkWidget      *child,
                                                 gpointer        data);
-
+#ifndef GENERIC_UMPC
 static gboolean ac_label_button_pressed                (GtkWidget      *widget,
                                                 GdkEventButton *event,
                                                 gpointer        data);
-
+#endif
 static gint main_window_close_cb               (GtkWidget      *widget,
                                                 GdkEventAny    *event,
                                                 gpointer        data);
@@ -169,6 +171,12 @@ static void empty_trash_cb  (MainWindow    *mainwin,
 static void save_as_cb          (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
+static void page_setup_cb       (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
+#endif
+
 static void print_cb            (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
@@ -186,13 +194,17 @@ static void toggle_message_cb      (MainWindow    *mainwin,
 static void toggle_toolbar_cb   (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void toggle_col_headers_cb(MainWindow   *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
+#ifndef GENERIC_UMPC
 static void toggle_statusbar_cb         (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
 static void set_layout_cb       (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
-
+#endif
 static void addressbook_open_cb        (MainWindow     *mainwin,
                                 guint           action,
                                 GtkWidget      *widget);
@@ -266,6 +278,12 @@ static void ignore_thread_cb               (MainWindow     *mainwin,
 static void unignore_thread_cb         (MainWindow     *mainwin, 
                                         guint           action,
                                         GtkWidget      *widget);
+static void watch_thread_cb            (MainWindow     *mainwin, 
+                                        guint           action,
+                                        GtkWidget      *widget);
+static void unwatch_thread_cb          (MainWindow     *mainwin, 
+                                        guint           action,
+                                        GtkWidget      *widget);
 static void lock_msgs_cb               (MainWindow     *mainwin, 
                                         guint           action,
                                         GtkWidget      *widget);
@@ -328,6 +346,9 @@ static void delete_duplicated_all_cb (MainWindow    *mainwin,
 static void filter_cb           (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void process_cb          (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 static void execute_summary_cb  (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
@@ -409,6 +430,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);
@@ -424,7 +448,7 @@ static void prefs_post_processing_open_cb (MainWindow       *mainwin,
 static void prefs_filtering_open_cb    (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
-#ifdef USE_OPENSSL
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
 static void ssl_manager_open_cb        (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -437,9 +461,10 @@ static void account_selector_menu_cb        (GtkMenuItem   *menuitem,
                                          gpointer       data);
 static void account_receive_menu_cb     (GtkMenuItem   *menuitem,
                                          gpointer       data);
+#ifndef GENERIC_UMPC
 static void account_compose_menu_cb     (GtkMenuItem   *menuitem,
                                          gpointer       data);
-
+#endif
 static void prefs_open_cb      (GtkMenuItem    *menuitem,
                                 gpointer        data);
 static void plugins_open_cb    (GtkMenuItem    *menuitem,
@@ -519,6 +544,9 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
+#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
+       {N_("/_File/Page setup..."),            NULL, page_setup_cb, 0, NULL},
+#endif
        {N_("/_File/_Print..."),                "<control>P", print_cb, 0, NULL},
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
@@ -539,8 +567,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/_Message view"),
-                                               "V", toggle_message_cb, 0, "<ToggleItem>"},
        {N_("/_View/Show or hi_de/_Toolbar"),
                                                NULL, NULL, 0, "<Branch>"},
        {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
@@ -551,15 +577,24 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
        {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
                                                NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
+#ifndef GENERIC_UMPC
        {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
                                                NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
+#endif
+       {N_("/_View/Show or hi_de/_Message view"),
+                                               "V", toggle_message_cb, 0, "<ToggleItem>"},
+#ifndef GENERIC_UMPC
        {N_("/_View/Show or hi_de/Status _bar"),
                                                NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
+#endif
+       {N_("/_View/Show or hi_de/Column headers"),
+                                               NULL, toggle_col_headers_cb, 0, "<ToggleItem>"},
        {N_("/_View/Set displayed _columns"),   NULL, NULL, 0, "<Branch>"},
        {N_("/_View/Set displayed _columns/in _Folder list..."),        NULL, set_folder_display_item_cb, 0, NULL},
        {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
 
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
+#ifndef GENERIC_UMPC
        {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"},
@@ -567,15 +602,17 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {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"),
@@ -634,92 +671,91 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_View/Character _encoding"),              NULL, NULL, 0, "<Branch>"},
        {N_("/_View/Character _encoding/_Auto detect"),
         NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
-       {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"},
-       {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
+       ENC_SEPARATOR,
+
+       {N_("/_View/Character _encoding/7bit ASCII (US-ASC_II)"),
         ENC_ACTION(C_US_ASCII)},
        {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
         ENC_ACTION(C_UTF_8)},
        ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
+       {N_("/_View/Character _encoding/Western European"),NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Western European/ISO-8859-_1"),
         ENC_ACTION(C_ISO_8859_1)},
-       {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
+       {N_("/_View/Character _encoding/Western European/ISO-8859-15"),
         ENC_ACTION(C_ISO_8859_15)},
-       {N_("/_View/Character _encoding/Western European (Windows-1252)"),
+       {N_("/_View/Character _encoding/Western European/Windows-1252"),
         ENC_ACTION(C_WINDOWS_1252)},
-       ENC_SEPARATOR,
 
        {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
         ENC_ACTION(C_ISO_8859_2)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
+       {N_("/_View/Character _encoding/Baltic"),       NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Baltic/ISO-8859-13"),
         ENC_ACTION(C_ISO_8859_13)},
-       {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
+       {N_("/_View/Character _encoding/Baltic/ISO-8859-_4"),
         ENC_ACTION(C_ISO_8859_4)},
-       ENC_SEPARATOR,
 
        {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
         ENC_ACTION(C_ISO_8859_7)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
+       {N_("/_View/Character _encoding/Hebrew"),       NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Hebrew/ISO-8859-_8"),
         ENC_ACTION(C_ISO_8859_8)},
-       {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
+       {N_("/_View/Character _encoding/Hebrew/Windows-1255"),
         ENC_ACTION(C_CP1255)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
+       {N_("/_View/Character _encoding/Arabic"),       NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Arabic/ISO-8859-_6"),
         ENC_ACTION(C_ISO_8859_6)},
-       {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
+       {N_("/_View/Character _encoding/Arabic/Windows-1256"),
         ENC_ACTION(C_CP1256)},
-       ENC_SEPARATOR,
 
        {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
         ENC_ACTION(C_ISO_8859_9)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
+       {N_("/_View/Character _encoding/Cyrillic"),     NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Cyrillic/ISO-8859-_5"),
         ENC_ACTION(C_ISO_8859_5)},
-       {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
+       {N_("/_View/Character _encoding/Cyrillic/KOI8-_R"),
         ENC_ACTION(C_KOI8_R)},
-       {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
+       {N_("/_View/Character _encoding/Cyrillic/KOI8-U"),
         ENC_ACTION(C_KOI8_U)},
-       {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
+       {N_("/_View/Character _encoding/Cyrillic/Windows-1251"),
         ENC_ACTION(C_CP1251)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
+       {N_("/_View/Character _encoding/Japanese"),     NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Japanese/ISO-2022-_JP"),
         ENC_ACTION(C_ISO_2022_JP)},
-       {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
+       {N_("/_View/Character _encoding/Japanese/ISO-2022-JP-2"),
         ENC_ACTION(C_ISO_2022_JP_2)},
-       {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
+       {N_("/_View/Character _encoding/Japanese/_EUC-JP"),
         ENC_ACTION(C_EUC_JP)},
-       {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
+       {N_("/_View/Character _encoding/Japanese/_Shift__JIS"),
         ENC_ACTION(C_SHIFT_JIS)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
+       {N_("/_View/Character _encoding/Chinese"),      NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Chinese/Simplified (_GB2312)"),
         ENC_ACTION(C_GB2312)},
-       {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
+       {N_("/_View/Character _encoding/Chinese/Simplified (GBK)"),
         ENC_ACTION(C_GBK)},
-       {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
+       {N_("/_View/Character _encoding/Chinese/Traditional (_Big5)"),
         ENC_ACTION(C_BIG5)},
-       {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
+       {N_("/_View/Character _encoding/Chinese/Traditional (EUC-_TW)"),
         ENC_ACTION(C_EUC_TW)},
-       {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
+       {N_("/_View/Character _encoding/Chinese/ISO-2022-_CN"),
         ENC_ACTION(C_ISO_2022_CN)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
+       {N_("/_View/Character _encoding/Korean"),       NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Korean/EUC-_KR"),
         ENC_ACTION(C_EUC_KR)},
-       {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
+       {N_("/_View/Character _encoding/Korean/ISO-2022-KR"),
         ENC_ACTION(C_ISO_2022_KR)},
-       ENC_SEPARATOR,
 
-       {N_("/_View/Character _encoding/Thai (TIS-620)"),
+       {N_("/_View/Character _encoding/Thai"),         NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Character _encoding/Thai/TIS-620"),
         ENC_ACTION(C_TIS_620)},
-       {N_("/_View/Character _encoding/Thai (Windows-874)"),
+       {N_("/_View/Character _encoding/Thai/Windows-874"),
         ENC_ACTION(C_WINDOWS_874)},
 
 #undef ENC_SEPARATOR
@@ -801,6 +837,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {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/Watch thread"),    NULL, watch_thread_cb, 0, NULL},
+       {N_("/_Message/_Mark/Unwatch thread"),  NULL, unwatch_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},
@@ -808,6 +846,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {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},
 
@@ -825,6 +864,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, filter_cb, 0, NULL},
        {N_("/_Tools/Filter _selected messages"),
                                                NULL, filter_cb, 1, NULL},
+       {N_("/_Tools/Run folder processing rules"),
+                                               NULL, process_cb, 0, NULL},
        {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
        {N_("/_Tools/_Create filter rule/_Automatically"),
                                                NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
@@ -858,14 +899,14 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, delete_duplicated_all_cb,   0, NULL},
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
-#ifdef USE_OPENSSL
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/SSL cer_tificates..."),    
                                                NULL, ssl_manager_open_cb, 0, NULL},
 #endif
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/Filtering Log"),           NULL, filtering_debug_window_show_cb, 0, NULL},
-       {N_("/_Tools/Protocol _Log"),           "<shift><control>L", log_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"),
@@ -887,10 +928,12 @@ 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>"},
-       {N_("/_Help/_Manual"),                  NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
+       {N_("/_Help/_Manual"),                  NULL, manual_open_cb, MANUAL_MANUAL_CLAWS, NULL},
        {N_("/_Help/_Online User-contributed FAQ"),     
                                                NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
        {N_("/_Help/Icon _Legend"),             NULL, legend_open_cb, 0, NULL},
@@ -976,6 +1019,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));
@@ -998,6 +1042,117 @@ 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);
+       GHashTable *menu_allsel_table = g_hash_table_new_full(
+                                       g_direct_hash,
+                                       g_direct_equal,
+                                       NULL, NULL);
+       gint sel_len;
+       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));
+                       g_hash_table_insert(menu_allsel_table, GINT_TO_POINTER(id), GINT_TO_POINTER(0));
+               }
+       }
+
+       /* iterate all messages and set the state of the appropriate
+        * items */
+       sel_len = 0;
+       for (; sel != NULL; sel = sel->next) {
+               MsgInfo *msginfo;
+               GSList *tags = NULL;
+               gint id;
+               GtkCheckMenuItem *item;
+               msginfo = (MsgInfo *)sel->data;
+               sel_len++;
+               if (msginfo) {
+                       tags =  msginfo->tags;
+                       if (!tags)
+                               continue;
+
+                       for (; tags; tags = tags->next) {
+                               gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, tags->data));
+                               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);
+                               }
+                               num_checked++;
+                               g_hash_table_replace(menu_allsel_table, tags->data, GINT_TO_POINTER(num_checked));
+                       }
+               }
+       }
+
+       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"));
+                       gint num_checked = GPOINTER_TO_INT(g_hash_table_lookup(menu_allsel_table, GINT_TO_POINTER(id)));
+                       if (num_checked < sel_len && num_checked > 0)
+                               gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), TRUE);
+                       else
+                               gtk_check_menu_item_set_inconsistent(GTK_CHECK_MENU_ITEM(cur->data), FALSE);
+               }
+       }
+       g_slist_free(sel);
+       g_hash_table_destroy(menu_table);
+       g_hash_table_destroy(menu_allsel_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;
@@ -1058,6 +1213,103 @@ static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refr
        mainwin->colorlabel_menu = menu;
 }
 
+static void mainwindow_tags_menu_item_apply_tags_activate_cb(GtkWidget *widget,
+                                                    gpointer data)
+{
+       MainWindow *mainwin;
+
+       mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
+       g_return_if_fail(mainwin != NULL);
+
+       /* "dont_toggle" state set? */
+       if (g_object_get_data(G_OBJECT(mainwin->tags_menu),
+                               "dont_toggle"))
+               return;
+       
+       tag_apply_open(summary_get_selection(mainwin->summaryview));    
+}
+
+static gint mainwin_tag_cmp_list(gconstpointer a, gconstpointer b)
+{
+       gint id_a = GPOINTER_TO_INT(a);
+       gint id_b = GPOINTER_TO_INT(b);
+       const gchar *tag_a = tags_get_tag(id_a);
+       const gchar *tag_b = tags_get_tag(id_b);
+       
+               
+       if (tag_a == NULL)
+               return tag_b == NULL ? 0:1;
+       
+       if (tag_b == NULL)
+               return tag_a == NULL ? 0:1;
+       return g_utf8_collate(tag_a, tag_b);
+}
+
+static void mainwindow_tags_menu_create(MainWindow *mainwin, gboolean refresh)
+{
+       GtkWidget *label_menuitem;
+       GtkWidget *menu;
+       GtkWidget *item;
+       GSList *cur = tags_get_list();
+       GSList *orig = NULL;
+       gboolean existing_tags = FALSE;
+
+       cur = orig = g_slist_sort(cur, mainwin_tag_cmp_list);
+
+       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(_("Apply tags..."));
+       gtk_widget_add_accelerator(item, "activate", 
+                  mainwin->menu_factory->accel_group, 
+                  GDK_T, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
+                  GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
+       gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(mainwindow_tags_menu_item_apply_tags_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;
+}
+#ifndef GENERIC_UMPC
 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
                                    MainWindow *mainwindow)
 {
@@ -1091,7 +1343,7 @@ static gboolean warning_enter_notify(GtkWidget *widget,
        gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
        return FALSE;
 }
-
+#endif
 void mainwindow_show_error(void)
 {
        MainWindow *mainwin = mainwindow_get_mainwindow();
@@ -1103,6 +1355,206 @@ void mainwindow_clear_error(MainWindow *mainwin)
        gtk_widget_hide(mainwin->warning_btn);
 }
 
+#define BREAK_ON_MODIFIER_KEY() \
+       if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
+
+static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
+                                   gpointer data)
+{
+       MainWindow *mainwin = (MainWindow*) data;
+       
+       if (!mainwin || !event) 
+               return FALSE;
+
+       if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
+       {
+               lastkey = event->keyval;
+               return FALSE;
+       }
+
+       switch (event->keyval) {
+       case GDK_Q:             /* Quit */
+               BREAK_ON_MODIFIER_KEY();
+
+               app_exit_cb(mainwin, 0, NULL);
+               return FALSE;
+       case GDK_space:
+               if (gtk_window_is_active(GTK_WINDOW(mainwin->window))) {
+                       if (mainwin->folderview && mainwin->summaryview
+                           && ((!mainwin->summaryview->displayed
+                               && !mainwin->summaryview->selected) 
+                               || (mainwin->summaryview->folder_item
+                                   && mainwin->summaryview->folder_item->total_msgs == 0))) {
+                               g_signal_stop_emission_by_name(G_OBJECT(widget), 
+                                              "key_press_event");
+                               folderview_select_next_unread(mainwin->folderview, TRUE);
+                       }
+               }
+               break;
+#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;
+       case GDK_F7:
+               {
+                       PangoFontDescription *font_desc;
+                       int size;
+                       font_desc = pango_font_description_from_string(prefs_common.normalfont);
+                       size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
+                       if (size < 30) {
+                               size++; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
+                               g_free(prefs_common.normalfont); 
+                               prefs_common.normalfont = pango_font_description_to_string(font_desc);
+                               main_window_reflect_prefs_all();
+                       }
+                       pango_font_description_free(font_desc);
+                       font_desc = pango_font_description_from_string(prefs_common.textfont);
+                       size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
+                       if (size < 30) {
+                               size++; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
+                               g_free(prefs_common.textfont); 
+                               prefs_common.textfont = pango_font_description_to_string(font_desc);
+                               main_window_reflect_prefs_all();
+                       }
+                       pango_font_description_free(font_desc);
+               }
+               break;
+       case GDK_F8:
+               {
+                       PangoFontDescription *font_desc;
+                       int size;
+                       font_desc = pango_font_description_from_string(prefs_common.normalfont);
+                       size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
+                       if (size > 5) {
+                               size--; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
+                               g_free(prefs_common.normalfont); 
+                               prefs_common.normalfont = pango_font_description_to_string(font_desc);
+                               main_window_reflect_prefs_all();
+                       }
+                       pango_font_description_free(font_desc);
+                       font_desc = pango_font_description_from_string(prefs_common.textfont);
+                       size = pango_font_description_get_size(font_desc)/PANGO_SCALE;
+                       if (size > 5) {
+                               size--; pango_font_description_set_size(font_desc, size*PANGO_SCALE);
+                               g_free(prefs_common.textfont); 
+                               prefs_common.textfont = pango_font_description_to_string(font_desc);
+                               main_window_reflect_prefs_all();
+                       }
+                       pango_font_description_free(font_desc);
+               }
+               break;
+       case GDK_Escape:
+               if (mainwin->summaryview && 
+                   mainwin->summaryview->ext_messageview && 
+                   mainwin->summaryview->ext_messageview->window && 
+                   widget == mainwin->summaryview->ext_messageview->window) {
+                       messageview_destroy(mainwin->summaryview->ext_messageview);
+               }
+               break;
+#endif
+       default:
+               break;
+       }
+       return FALSE;
+}
+
+#undef BREAK_ON_MODIFIER_KEY
+
+#ifdef MAEMO
+void mainwindow_maemo_led_set(gboolean state) {
+       static gint last_state = -1;
+       if (last_state == state)
+               return;
+       last_state = (gint)state;
+       if (prefs_common.maemo_show_led) {
+               if(state) {
+                 execute_command_line("/usr/bin/dbus-send --system --type=method_call "
+                       "--dest=com.nokia.mce "
+                       "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_activate "
+                       "string:PatternCommunicationEvent", TRUE);
+                 execute_command_line("/usr/bin/dbus-send --system --type=method_call "
+                       "--dest=com.nokia.mce "
+                       "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_activate "
+                       "string:PatternCommunicationEmail", TRUE);
+               } else {
+                 execute_command_line("/usr/bin/dbus-send --system --type=method_call "
+                       "--dest=com.nokia.mce "
+                       "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_deactivate "
+                       "string:PatternCommunicationEvent", TRUE);
+                 execute_command_line("/usr/bin/dbus-send --system --type=method_call "
+                       "--dest=com.nokia.mce "
+                       "/com/nokia/mce/request com.nokia.mce.request.req_led_pattern_deactivate "
+                       "string:PatternCommunicationEmail", TRUE);
+               }
+       } 
+}
+
+static void led_update(FolderItem *removed_item)
+{
+       guint new, unread, unreadmarked, marked, total, replied;
+       guint forwarded, locked, ignored, watched;
+
+       folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
+                               &replied, &forwarded, &locked, &ignored,
+                               &watched);
+       if (removed_item) {
+               total -= removed_item->total_msgs;
+               new -= removed_item->new_msgs;
+               unread -= removed_item->unread_msgs;
+       }
+
+       if (new > 0)
+               mainwindow_maemo_led_set(TRUE);
+       else
+               mainwindow_maemo_led_set(FALSE);
+}
+
+static gboolean maemo_folder_item_update_hook(gpointer source, gpointer data)
+{
+       led_update(NULL);
+
+       return FALSE;
+}
+
+static gboolean maemo_folder_update_hook(gpointer source, gpointer data)
+{
+       FolderUpdateData *hookdata;
+       hookdata = source;
+       if (hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM)
+               led_update(hookdata->item);
+       else
+               led_update(NULL);
+
+       return FALSE;
+}
+
+static void main_window_install_maemo_hooks(MainWindow *mainwin)
+{
+       gint maemo_item_hook_id, maemo_folder_hook_id;
+       
+       maemo_item_hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, maemo_folder_item_update_hook, NULL);
+       if (maemo_item_hook_id == -1) {
+               goto err_out_item;
+       }
+
+       maemo_folder_hook_id = hooks_register_hook (FOLDER_UPDATE_HOOKLIST, maemo_folder_update_hook, NULL);
+       if (maemo_folder_hook_id == -1) {
+               goto err_out_folder;
+       }
+       
+       return;
+
+err_out_folder:
+       hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, maemo_item_hook_id);
+err_out_item:
+       return;
+}
+#endif
+
 MainWindow *main_window_create()
 {
        MainWindow *mainwin;
@@ -1111,6 +1563,7 @@ MainWindow *main_window_create()
        GtkWidget *menubar;
        GtkWidget *handlebox;
        GtkWidget *vbox_body;
+#ifndef GENERIC_UMPC
        GtkWidget *hbox_stat;
        GtkWidget *statusbar;
        GtkWidget *progressbar;
@@ -1119,12 +1572,12 @@ MainWindow *main_window_create()
        GtkWidget *ac_label;
        GtkWidget *online_pixmap;
        GtkWidget *offline_pixmap;
-       GtkWidget *online_switch;
-       GtkWidget *offline_switch;
        GtkTooltips *tips;
        GtkWidget *warning_icon;
        GtkWidget *warning_btn;
-
+#endif
+       GtkWidget *online_switch;
+       GtkWidget *offline_switch;
        FolderView *folderview;
        SummaryView *summaryview;
        MessageView *messageview;
@@ -1143,10 +1596,12 @@ MainWindow *main_window_create()
        mainwin = g_new0(MainWindow, 1);
 
        /* main window */
-       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow");
+       window = GTK_WIDGET(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 GENERIC_UMPC
+       prefs_common.layout_mode = SMALL_LAYOUT;
+#endif
        if (!geometry.min_height) {
                geometry.min_width = 320;
                geometry.min_height = 200;
@@ -1178,14 +1633,16 @@ MainWindow *main_window_create()
        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"));
        main_create_mailing_list_menu (mainwin, NULL); */
 
-       menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
-
        if (prefs_common.toolbar_detachable) {
                handlebox = gtk_handle_box_new();
                gtk_widget_show(handlebox);
@@ -1201,11 +1658,17 @@ MainWindow *main_window_create()
        }
        /* 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);
@@ -1216,6 +1679,7 @@ MainWindow *main_window_create()
        gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
        gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
 
+#ifndef GENERIC_UMPC
        hbox_stat = gtk_hbox_new(FALSE, 2);
        gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
 
@@ -1290,14 +1754,19 @@ MainWindow *main_window_create()
 
        gtk_widget_hide(offline_switch);
        gtk_widget_hide(warning_btn);
-
+#else
+       online_switch = gtk_button_new ();
+       offline_switch = gtk_button_new ();
+       g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
+       g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
+#endif
        /* create views */
        mainwin->folderview  = folderview  = folderview_create();
        mainwin->summaryview = summaryview = summary_create();
        mainwin->messageview = messageview = messageview_create(mainwin);
 
        /* init log instances data before creating log views */
-       set_log_title(LOG_PROTOCOL, _("Protocol log"));
+       set_log_title(LOG_PROTOCOL, _("Network log"));
        set_log_prefs(LOG_PROTOCOL,
                        &prefs_common.logwin_width,
                        &prefs_common.logwin_height);
@@ -1332,23 +1801,23 @@ MainWindow *main_window_create()
        summaryview->messageview = messageview;
        summaryview->window      = window;
 
-       messageview->statusbar   = statusbar;
        mainwin->vbox           = vbox;
        mainwin->menubar        = menubar;
        mainwin->menu_factory   = ifactory;
        mainwin->handlebox      = handlebox;
        mainwin->vbox_body      = vbox_body;
-       mainwin->hbox_stat      = hbox_stat;
+       mainwin->online_switch  = online_switch;
+       mainwin->offline_switch    = offline_switch;
+#ifndef GENERIC_UMPC
+       messageview->statusbar  = statusbar;
        mainwin->statusbar      = statusbar;
+       mainwin->hbox_stat      = hbox_stat;
        mainwin->progressbar    = progressbar;
        mainwin->statuslabel    = statuslabel;
-       mainwin->online_switch  = online_switch;
        mainwin->online_pixmap  = online_pixmap;
        mainwin->offline_pixmap = offline_pixmap;
        mainwin->ac_button      = ac_button;
        mainwin->ac_label       = ac_label;
-       mainwin->offline_switch    = offline_switch;
-       
        /* set context IDs for status bar */
        mainwin->mainwin_cid = gtk_statusbar_get_context_id
                (GTK_STATUSBAR(statusbar), "Main Window");
@@ -1358,9 +1827,20 @@ MainWindow *main_window_create()
                (GTK_STATUSBAR(statusbar), "Summary View");
        mainwin->messageview_cid = gtk_statusbar_get_context_id
                (GTK_STATUSBAR(statusbar), "Message View");
-
        messageview->statusbar_cid = mainwin->messageview_cid;
 
+#else
+       messageview->statusbar  = NULL;
+       mainwin->statusbar      = NULL;
+       mainwin->hbox_stat      = NULL;
+       /* mainwin->progressbar is set in toolbar.c */
+       mainwin->statuslabel    = NULL;
+       mainwin->online_pixmap  = NULL;
+       mainwin->offline_pixmap = NULL;
+       mainwin->ac_button      = NULL;
+       mainwin->ac_label       = NULL;
+#endif
+       
        /* allocate colors for summary view and folder view */
        summaryview->color_marked.red = summaryview->color_marked.green = 0;
        summaryview->color_marked.blue = (guint16)65535;
@@ -1429,12 +1909,17 @@ MainWindow *main_window_create()
        }
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
 
+#ifndef GENERIC_UMPC
        gtk_widget_hide(mainwin->hbox_stat);
        menuitem = gtk_item_factory_get_item
                (ifactory, "/View/Show or hide/Status bar");
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
                                       prefs_common.show_statusbar);
-       
+#endif 
+       menuitem = gtk_item_factory_get_item
+               (ifactory, "/View/Show or hide/Column headers");
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
+                                      prefs_common.show_col_headers);
        /* set account selection menu */
        ac_menu = gtk_item_factory_get_widget
                (ifactory, "/Configuration/Change current account");
@@ -1463,7 +1948,9 @@ MainWindow *main_window_create()
           menu items in different menus             */
        menu_connect_identical_items();
 
+#ifndef GENERIC_UMPC
        gtk_window_iconify(GTK_WINDOW(mainwin->window));
+#endif
 
        g_signal_connect(G_OBJECT(window), "window_state_event",
                         G_CALLBACK(mainwindow_state_event_cb), mainwin);
@@ -1483,7 +1970,7 @@ MainWindow *main_window_create()
        folderview_init(folderview);
        summary_init(summaryview);
        messageview_init(messageview);
-#ifdef USE_OPENSSL
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
        sslcertwindow_register_hook();
 #endif
        mainwin->lock_count = 0;
@@ -1498,22 +1985,17 @@ MainWindow *main_window_create()
        if (!hand_cursor)
                hand_cursor = gdk_cursor_new(GDK_HAND2);
 
-       mainwin_list = g_list_append(mainwin_list, mainwin);
-
        /* init work_offline */
        if (prefs_common.work_offline)
                online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
 
        mainwindow_colorlabel_menu_create(mainwin, FALSE);
-       
-       return mainwin;
-}
+       mainwindow_tags_menu_create(mainwin, FALSE);
 
-void main_window_destroy(MainWindow *mainwin)
-{
-       /* TODO : destroy other component */
-       messageview_destroy(mainwin->messageview);
-       mainwin->messageview = NULL;    
+#ifdef MAEMO
+       main_window_install_maemo_hooks(mainwin);
+#endif
+       return mainwin;
 }
 
 void main_window_update_actions_menu(MainWindow *mainwin)
@@ -1552,7 +2034,7 @@ void main_window_cursor_normal(MainWindow *mainwin)
 /* lock / unlock the user-interface */
 void main_window_lock(MainWindow *mainwin)
 {
-       if (mainwin->lock_count == 0)
+       if (mainwin->lock_count == 0 && mainwin->ac_button)
                gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
 
        mainwin->lock_count++;
@@ -1569,7 +2051,7 @@ void main_window_unlock(MainWindow *mainwin)
        main_window_set_menu_sensitive(mainwin);
        toolbar_main_set_sensitive(mainwin);
 
-       if (mainwin->lock_count == 0)
+       if (mainwin->lock_count == 0 && mainwin->ac_button)
                gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
 }
 
@@ -1596,8 +2078,9 @@ static gboolean reflect_prefs_timeout_cb(gpointer data)
        gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
        GList *cur;
        MainWindow *mainwin;
+#ifndef GENERIC_UMPC
        GtkWidget *pixmap;
-
+#endif
        for (cur = mainwin_list; cur != NULL; cur = cur->next) {
                mainwin = (MainWindow *)cur->data;
 
@@ -1612,7 +2095,7 @@ static gboolean reflect_prefs_timeout_cb(gpointer data)
                        compose_reflect_prefs_pixmap_theme();
                        folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
                        summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
-
+#ifndef GENERIC_UMPC
                        pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
                        gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
                                             mainwin->online_pixmap);
@@ -1625,6 +2108,8 @@ static gboolean reflect_prefs_timeout_cb(gpointer data)
                        gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
                        gtk_widget_show(pixmap);
                        mainwin->offline_pixmap = pixmap;
+#endif
+                       hooks_invoke(THEME_CHANGED_HOOKLIST, NULL);
                }
                
                headerview_set_font(mainwin->messageview->headerview);
@@ -1633,7 +2118,16 @@ static gboolean reflect_prefs_timeout_cb(gpointer data)
                textview_reflect_prefs(mainwin->messageview->mimeview->textview);
                folderview_reflect_prefs();
                summary_reflect_prefs();
+#ifndef GENERIC_UMPC
                summary_redisplay_msg(mainwin->summaryview);
+#endif
+               if (prefs_common.layout_mode == SMALL_LAYOUT) {
+                       if (mainwin->in_folder) {
+                               mainwindow_enter_folder(mainwin);
+                       } else {
+                               mainwindow_exit_folder(mainwin);
+                       }
+               }
        }
        prefs_tag = 0;
        return FALSE;
@@ -1662,10 +2156,44 @@ void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
 
 }
 
+static gint tags_tag = 0;
+static gboolean main_window_reflect_tags_changes_real(gpointer data)
+{
+       GtkMenuShell *menu;
+       GList *cur;
+       MainWindow *mainwin = (MainWindow *)data;
+
+       if (summary_is_locked(mainwin->summaryview)) {
+               tags_tag = 0;
+               return TRUE;
+       }
+       /* re-create tags submenu */
+       menu = GTK_MENU_SHELL(mainwin->tags_menu);
+       g_return_val_if_fail(menu != NULL, FALSE);
+
+       /* 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);
+       
+       tags_tag = 0;
+       return FALSE;
+}
+
+void main_window_reflect_tags_changes(MainWindow *mainwin)
+{
+       if (tags_tag == 0) {
+               tags_tag = g_timeout_add(100, main_window_reflect_tags_changes_real, 
+                                               mainwin);
+       }
+}
+
 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
 {
-       if (prefs_tag == 0 || pixmap_theme_changed) {
-               prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
+       if (prefs_tag == 0) {
+               prefs_tag = g_timeout_add(100, reflect_prefs_timeout_cb, 
                                                GINT_TO_POINTER(pixmap_theme_changed));
        }
 }
@@ -1751,6 +2279,9 @@ static void main_window_set_account_receive_menu(MainWindow *mainwin,
        for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
                ac_prefs = (PrefsAccount *)cur_ac->data;
 
+               if (ac_prefs->protocol == A_NONE)
+                       continue;
+
                menuitem = gtk_menu_item_new_with_label
                        (ac_prefs->account_name ? ac_prefs->account_name
                         : _("Untitled"));
@@ -1765,28 +2296,25 @@ 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;
 
+               if (ac_prefs->protocol == A_NONE)
+                       continue;
+
                menuitem = gtk_menu_item_new_with_label
                        (ac_prefs->account_name
                         ? ac_prefs->account_name : _("Untitled"));
@@ -1796,29 +2324,25 @@ 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 GENERIC_UMPC
+       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;
-
-       /* 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->compose_mail_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;
@@ -1832,6 +2356,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_mail_btn), menu);
+#endif
 }
 
 void main_window_set_account_menu(GList *account_list)
@@ -1878,12 +2404,14 @@ static void main_window_show_cur_account(MainWindow *mainwin)
        gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
        g_free(buf);
 
-       gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
-       gtk_widget_queue_resize(mainwin->ac_button);
+       if (mainwin->ac_label)
+               gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
+       if (mainwin->ac_button)
+               gtk_widget_queue_resize(mainwin->ac_button);
 
        g_free(ac_name);
 }
-
+#ifndef GENERIC_UMPC
 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
 {
        GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
@@ -1915,7 +2443,7 @@ static void main_window_separation_change(MainWindow *mainwin, LayoutType layout
        gtk_widget_unref(summary_wid);
        gtk_widget_unref(message_wid);
 }
-
+#endif
 void mainwindow_reset_paned(GtkPaned *paned)
 {
                gint min, max, mid;
@@ -2027,6 +2555,9 @@ void main_window_toggle_message_view(MainWindow *mainwin)
                gtk_widget_queue_resize(mainwin->vpaned);
        }
        summary_grab_focus(summaryview);
+       if (!summary_is_list(summaryview)) {
+               summary_show(summaryview, summaryview->folder_item);
+       }
 }
 
 void main_window_get_size(MainWindow *mainwin)
@@ -2051,7 +2582,8 @@ void main_window_get_size(MainWindow *mainwin)
        }
 
        allocation = &mainwin->window->allocation;
-       if (allocation->width > 1 && allocation->height > 1) {
+       if (allocation->width > 1 && allocation->height > 1 &&
+           !prefs_common.mainwin_maximised) {
                prefs_common.mainview_height = allocation->height;
                prefs_common.mainwin_width   = allocation->width;
                prefs_common.mainwin_height  = allocation->height;
@@ -2084,6 +2616,9 @@ void main_window_get_position(MainWindow *mainwin)
 {
        gint x, y;
 
+       if (prefs_common.mainwin_maximised)
+               return;
+
        gtkut_widget_get_uposition(mainwin->window, &x, &y);
 
        prefs_common.mainview_x = x;
@@ -2105,24 +2640,27 @@ void main_window_progress_off(MainWindow *mainwin)
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
 }
 
-void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
-{
-       gchar buf[32];
-
-       g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
-       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
-       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
-                               (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
-}
-
-void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
+static gboolean main_window_empty_trash(MainWindow *mainwin, gboolean confirm, gboolean for_quit)
 {
        if (confirm && procmsg_have_trashed_mails_fast()) {
-               if (alertpanel(_("Empty trash"),
+               AlertValue val;
+               
+               if (for_quit)
+                       val = alertpanel(_("Empty trash"),
                               _("Delete all messages in trash folders?"),
-                              GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
-                   != G_ALERTALTERNATE)
-                       return;
+                              GTK_STOCK_NO, "+" GTK_STOCK_YES, _("Don't quit"));
+               else
+                       val = alertpanel(_("Empty trash"),
+                              _("Delete all messages in trash folders?"),
+                              GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
+               if (val == G_ALERTALTERNATE) {
+                       debug_print("will empty trash\n");
+               } else if (val == G_ALERTDEFAULT) {
+                       debug_print("will not empty trash\n");
+                       return TRUE;
+               } else {
+                       return FALSE; /* cancel exit */
+               }
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }
 
@@ -2131,9 +2669,10 @@ void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
        if (mainwin->summaryview->folder_item &&
            mainwin->summaryview->folder_item->stype == F_TRASH)
                gtk_widget_grab_focus(mainwin->folderview->ctree);
+       return TRUE;
 }
 
-void main_window_add_mailbox(MainWindow *mainwin)
+static void main_window_add_mailbox(MainWindow *mainwin)
 {
        gchar *path;
        Folder *folder;
@@ -2173,10 +2712,11 @@ 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);
 
-       if (mainwin->lock_count == 0)
+       if (mainwin->lock_count == 0 && !claws_is_starting())
                state |= M_UNLOCKED;
        if (selection != SUMMARY_NONE)
                state |= M_MSG_EXIST;
@@ -2210,6 +2750,11 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
        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;
 
@@ -2225,6 +2770,9 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
        if (any_folder_want_synchronise())
                state |= M_WANT_SYNC;
 
+       if (item && item->prefs->processing && selection != SUMMARY_NONE)
+               state |= M_HAVE_PROCESSING;
+
        for ( ; account_list != NULL; account_list = account_list->next) {
                if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
                        state |= M_HAVE_NEWS_ACCOUNT;
@@ -2249,6 +2797,12 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
            mainwin->summaryview->copied > 0)
                state |= M_DELAY_EXEC;
 
+       if (summary_is_list(mainwin->summaryview))
+               state |= M_SUMMARY_ISLIST;
+
+       if (prefs_common.layout_mode != SMALL_LAYOUT || mainwin->in_folder)
+               state |= M_IN_MSGLIST;
+
        return state;
 }
 
@@ -2275,17 +2829,18 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/File/Synchronise folders", M_WANT_SYNC},
                {"/File/Exit"      , M_UNLOCKED},
 
-               {"/Edit/Select thread"             , M_TARGET_EXIST},
-               {"/Edit/Delete thread"             , M_TARGET_EXIST},
+               {"/Edit/Select thread"             , M_TARGET_EXIST|M_SUMMARY_ISLIST},
+               {"/Edit/Delete thread"             , M_TARGET_EXIST|M_SUMMARY_ISLIST},
                {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
+               {"/Edit/Quick search",               M_IN_MSGLIST},
 
                {"/View/Set displayed columns/in Folder list..."
-                                                  , M_UNLOCKED}, 
-               {"/View/Sort"                      , M_EXEC},
-               {"/View/Thread view"               , M_EXEC},
-               {"/View/Expand all threads"        , M_MSG_EXIST},
-               {"/View/Collapse all threads"      , M_MSG_EXIST},
-               {"/View/Hide read messages"        , M_HIDE_READ_MSG},
+                                                  , M_UNLOCKED|M_SUMMARY_ISLIST}, 
+               {"/View/Sort"                      , M_EXEC|M_SUMMARY_ISLIST},
+               {"/View/Thread view"               , M_EXEC|M_SUMMARY_ISLIST},
+               {"/View/Expand all threads"        , M_MSG_EXIST|M_SUMMARY_ISLIST},
+               {"/View/Collapse all threads"      , M_MSG_EXIST|M_SUMMARY_ISLIST},
+               {"/View/Hide read messages"        , M_HIDE_READ_MSG|M_SUMMARY_ISLIST},
                {"/View/Go to/Previous message"        , M_MSG_EXIST},
                {"/View/Go to/Next message"        , M_MSG_EXIST},
                {"/View/Go to/Previous unread message" , M_MSG_EXIST},
@@ -2307,19 +2862,20 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/Message/Receive/Cancel receiving"
                                                 , M_INC_ACTIVE},
                {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
+               {"/Message/Compose an email message", M_HAVE_ACCOUNT},
                {"/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},
-               {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
-               {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
-               {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
-               {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
+               {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
+               {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
+               {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS|M_SUMMARY_ISLIST},
+               {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
+               {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
+               {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST},
                {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
                {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
                {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
                {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
                {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
-               {"/Message/Mark"                  , M_TARGET_EXIST},
+               {"/Message/Mark"                  , M_TARGET_EXIST|M_SUMMARY_ISLIST},
                {"/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},
@@ -2327,14 +2883,16 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/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},
-               {"/Tools/Harvest addresses"            , M_MSG_EXIST},
+               {"/Tools/Harvest addresses"            , M_MSG_EXIST|M_SUMMARY_ISLIST},
                {"/Tools/Harvest addresses/from Messages..."
                                                       , M_TARGET_EXIST},
                {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
                {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
+               {"/Tools/Run folder processing rules"  , M_HAVE_PROCESSING},
                {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
                {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
                {"/Tools/List URLs..."                 , M_TARGET_EXIST},
@@ -2394,6 +2952,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:
@@ -2412,6 +2972,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;
@@ -2543,14 +3105,14 @@ static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * li
                for (url_pt = list_header; url_pt && *url_pt;) {
                        get_url_part (&url_pt, url_decoded, BUFFSIZE);
                        item = NULL;
-                       if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
+                       if (!g_ascii_strncasecmp(url_decoded, "mailto:", 7)) {
                                item = gtk_menu_item_new_with_label ((url_decoded));
                                g_signal_connect(G_OBJECT(item), "activate",
                                                 G_CALLBACK(mailing_list_compose),
                                                 NULL);
                        }
-                       else if (!g_strncasecmp (url_decoded, "http:", 5) ||
-                                !g_strncasecmp (url_decoded, "https:",6)) {
+                       else if (!g_ascii_strncasecmp(url_decoded, "http:", 5) ||
+                                !g_ascii_strncasecmp(url_decoded, "https:",6)) {
 
                                item = gtk_menu_item_new_with_label ((url_decoded));
                                g_signal_connect(G_OBJECT(item), "activate",
@@ -2647,15 +3209,25 @@ static void mailing_list_compose (GtkWidget *w, gpointer *data)
        gchar *mailto;
  
        gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
-       open_uri (mailto, prefs_common.uri_cmd);
+       open_uri (mailto, prefs_common_get_uri_cmd());
 } 
        
 void main_window_popup(MainWindow *mainwin)
 {
+       static gboolean first_start = TRUE;
+
        if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
                main_window_show(mainwin);
 
-       gtkut_window_popup(mainwin->window);
+       if (prefs_common.mainwin_maximised)
+               gtk_window_maximize(GTK_WINDOW(mainwin->window));
+
+       if (first_start) {
+               gtk_window_deiconify(GTK_WINDOW(mainwin->window));
+               first_start = FALSE;
+       } else {
+               gtkut_window_popup(mainwin->window);
+       }
        if (prefs_common.layout_mode == SMALL_LAYOUT) {
                if (mainwin->in_folder) {
                        mainwindow_enter_folder(mainwin);
@@ -2669,7 +3241,7 @@ void main_window_show(MainWindow *mainwin)
 {
        gtk_widget_show(mainwin->window);
        gtk_widget_show(mainwin->vbox_body);
-
+#ifndef GENERIC_UMPC
         gtk_widget_set_uposition(mainwin->window,
                                  prefs_common.mainwin_x,
                                  prefs_common.mainwin_y);
@@ -2683,6 +3255,7 @@ void main_window_show(MainWindow *mainwin)
        gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
                             prefs_common.msgview_width,
                             prefs_common.msgview_height);
+#endif
 }
 
 void main_window_hide(MainWindow *mainwin)
@@ -2726,9 +3299,10 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
                                    prefs_common.msgview_height);
        }
 
+#ifndef GENERIC_UMPC
        mainwin->messageview->statusbar = mainwin->statusbar;
        mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
-
+#endif
        /* clean top-most container */
        if (mainwin->hpaned) {
                if (mainwin->hpaned->parent == mainwin->vpaned)
@@ -2872,7 +3446,7 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
                gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
        if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
                gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
-       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
+       if (mainwin->messageview->mimeview->ctree_mode)
                gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
        else 
                gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
@@ -2891,6 +3465,7 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
 }
 
+#ifndef GENERIC_UMPC
        switch (prefs_common.layout_mode) {
        case NORMAL_LAYOUT:
                SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
@@ -2908,6 +3483,7 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
                SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
                break;
        }
+#endif
 #undef SET_CHECK_MENU_ACTIVE
 
        if (folderwin) {
@@ -2936,6 +3512,7 @@ void main_window_destroy_all(void)
                TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
                TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
 
+               summaryview_destroy(mainwin->summaryview);
                mainwin->folderview->mainwin = NULL;
                mainwin->summaryview->mainwin = NULL;
                mainwin->messageview->mainwin = NULL;
@@ -2960,7 +3537,7 @@ static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
 {
        gtk_widget_set_size_request(child, -1, -1);
 }
-
+#ifndef GENERIC_UMPC
 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
                                    gpointer data)
 {
@@ -2978,7 +3555,7 @@ static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event
 
        return TRUE;
 }
-
+#endif
 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
                                 gpointer data)
 {
@@ -3068,7 +3645,7 @@ static void export_list_mbox_cb(MainWindow *mainwin, guint action,
 static void empty_trash_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
-       main_window_empty_trash(mainwin, TRUE);
+       main_window_empty_trash(mainwin, TRUE, FALSE);
 }
 
 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
@@ -3081,8 +3658,26 @@ static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
        summary_print(mainwin->summaryview);
 }
 
+#if GTK_CHECK_VERSION(2,10,0) && !defined(USE_GNOMEPRINT)
+static void page_setup_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
+{
+       MainWindow *mainwindow;
+       GtkWindow *win;
+
+       mainwindow = mainwindow_get_mainwindow();
+       win = (mainwindow ? GTK_WINDOW(mainwindow->window) : NULL);
+
+       printing_page_setup(win);
+}
+#endif
+
 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
+       if (prefs_common.clean_on_exit) {
+               if (!main_window_empty_trash(mainwin, prefs_common.ask_on_clean, TRUE))
+                       return;
+       }
+
        if (prefs_common.confirm_on_exit) {
                if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
                               GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
@@ -3138,7 +3733,24 @@ static void main_window_reply_cb(MainWindow *mainwin, guint action,
        g_slist_free(msginfo_list);
 }
 
+static void toggle_col_headers_cb(MainWindow *mainwin, guint action,
+                               GtkWidget *widget)
+{
+       FolderView *folderview = mainwin->folderview;
+       SummaryView *summaryview = mainwin->summaryview;
 
+       if (GTK_CHECK_MENU_ITEM(widget)->active) {
+               gtk_clist_column_titles_show(GTK_CLIST(folderview->ctree));
+               gtk_clist_column_titles_show(GTK_CLIST(summaryview->ctree));
+               prefs_common.show_col_headers = TRUE;
+       } else {
+               gtk_clist_column_titles_hide(GTK_CLIST(folderview->ctree));
+               gtk_clist_column_titles_hide(GTK_CLIST(summaryview->ctree));
+               prefs_common.show_col_headers = FALSE;
+       }
+}
+
+#ifndef GENERIC_UMPC
 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
                                GtkWidget *widget)
 {
@@ -3184,6 +3796,7 @@ static void set_layout_cb(MainWindow *mainwin, guint action,
        summary_relayout(mainwin->summaryview); 
        summary_update_unread(mainwin->summaryview, NULL);
 }
+#endif
 
 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
                                        gboolean ask_sync)
@@ -3236,6 +3849,13 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
        MainWindow *mainwin;
        GtkItemFactory *ifactory;
        GtkCheckMenuItem *menuitem;
+       gboolean have_connectivity;
+
+#ifdef HAVE_NETWORKMANAGER
+       have_connectivity = networkmanager_is_online(NULL); 
+#else
+       have_connectivity = TRUE;
+#endif
 
        mainwin = (MainWindow *) data;
        
@@ -3246,15 +3866,19 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
        g_return_if_fail(menuitem != NULL);
        
        if (btn == GTK_BUTTON(mainwin->online_switch)) {
+#ifndef GENERIC_UMPC
                gtk_widget_hide (mainwin->online_switch);
                gtk_widget_show (mainwin->offline_switch);
+#endif
                menuitem->active = TRUE;
                inc_autocheck_timer_remove();
                        
                /* go offline */
                if (prefs_common.work_offline)
                        return;
-               mainwindow_check_synchronise(mainwin, TRUE);
+
+               if(have_connectivity)
+                       mainwindow_check_synchronise(mainwin, TRUE);
                prefs_common.work_offline = TRUE;
                imap_disconnect_all();
                hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
@@ -3262,8 +3886,10 @@ static void online_switch_clicked (GtkButton *btn, gpointer data)
                /*go online */
                if (!prefs_common.work_offline)
                        return;
+#ifndef GENERIC_UMPC
                gtk_widget_hide (mainwin->offline_switch);
                gtk_widget_show (mainwin->online_switch);
+#endif
                menuitem->active = FALSE;
                prefs_common.work_offline = FALSE;
                inc_autocheck_timer_set();
@@ -3416,6 +4042,18 @@ static void unignore_thread_cb(MainWindow *mainwin, guint action,
        summary_unignore_thread(mainwin->summaryview);
 }
 
+static void watch_thread_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_watch_thread(mainwin->summaryview);
+}
+
+static void unwatch_thread_cb(MainWindow *mainwin, guint action,
+                           GtkWidget *widget)
+{
+       summary_unwatch_thread(mainwin->summaryview);
+}
+
 static void lock_msgs_cb(MainWindow *mainwin, guint action,
                            GtkWidget *widget)
 {
@@ -3620,6 +4258,16 @@ static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
        summary_filter(mainwin->summaryview, (gboolean)action);
 }
 
+static void process_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
+{
+       FolderItem *item = mainwin->summaryview->folder_item;   
+       g_return_if_fail(item != NULL);
+
+       item->processing_pending = TRUE;
+       folder_item_apply_processing(item);     
+       item->processing_pending = FALSE;
+}
+
 static void execute_summary_cb(MainWindow *mainwin, guint action,
                               GtkWidget *widget)
 {
@@ -3718,7 +4366,7 @@ static void goto_folder_cb(MainWindow *mainwin, guint action,
 {
        FolderItem *to_folder;
 
-       to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
+       to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL, FALSE);
 
        if (to_folder)
                folderview_select(mainwin->folderview, to_folder);
@@ -3808,7 +4456,14 @@ static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
 {
        prefs_actions_open(mainwin);
 }
-#ifdef USE_OPENSSL
+
+static void prefs_tags_open_cb(MainWindow *mainwin, guint action,
+                                 GtkWidget *widget)
+{
+       GSList * list = summary_get_selected_msg_list(mainwin->summaryview);
+       tag_apply_open(list);
+}
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
                                  GtkWidget *widget)
 {
@@ -3860,16 +4515,14 @@ static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
 
        inc_account_mail(mainwin, account);
 }
-
+#ifndef GENERIC_UMPC
 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
 {
-       MainWindow *mainwin = (MainWindow *)mainwin_list->data;
        PrefsAccount *account = (PrefsAccount *)data;
-       FolderItem *item = mainwin->summaryview->folder_item;   
 
-       compose_new_with_folderitem(account, item, NULL);
+       compose_new_with_folderitem(account, NULL, NULL);
 }
-
+#endif
 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
 {
        prefs_gtk_open();
@@ -3945,6 +4598,9 @@ static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState
                if (iconified_count > 0)
                        hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
                iconified_count++;
+       } else if (!claws_is_starting()) {
+               prefs_common.mainwin_maximised = 
+                       ((state->new_window_state&GDK_WINDOW_STATE_MAXIMIZED) != 0);
        }
        if (state->new_window_state == 0)
                gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
@@ -3956,57 +4612,6 @@ gboolean mainwindow_is_obscured(void)
        return is_obscured;
 }
 
-#define BREAK_ON_MODIFIER_KEY() \
-       if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
-
-gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
-                                   gpointer data)
-{
-       MainWindow *mainwin = (MainWindow*) data;
-       
-       if (!mainwin || !event) 
-               return FALSE;
-
-       if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
-       {
-               lastkey = event->keyval;
-               return FALSE;
-       }
-
-       switch (event->keyval) {
-       case GDK_Q:             /* Quit */
-               BREAK_ON_MODIFIER_KEY();
-
-               app_exit_cb(mainwin, 0, NULL);
-               return FALSE;
-       case GDK_space:
-               if (mainwin->folderview && mainwin->summaryview
-                   && ((!mainwin->summaryview->displayed
-                       && !mainwin->summaryview->selected) 
-                       || (mainwin->summaryview->folder_item
-                           && mainwin->summaryview->folder_item->total_msgs == 0))) {
-                       g_signal_stop_emission_by_name(G_OBJECT(widget), 
-                                       "key_press_event");
-                       folderview_select_next_unread(mainwin->folderview, TRUE);
-               }
-               break;
-#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;
-       }
-       return FALSE;
-}
-
-#undef BREAK_ON_MODIFIER_KEY
-
 /*
  * Harvest addresses for selected folder.
  */
@@ -4078,16 +4683,19 @@ void mainwindow_jump_to(const gchar *target, gboolean popup)
        FolderItem *item = NULL;
        gchar *msg = NULL;
        MainWindow *mainwin = mainwindow_get_mainwindow();
-       
+       gchar *from_uri = NULL;
        if (!target)
                return;
                
        if (!mainwin) {
-               printf("not initialized\n");
+               g_print("not initialized\n");
                return;
        }
 
-       tmp = g_strdup(target);
+       if ((from_uri = g_filename_from_uri(target, NULL, NULL)) != NULL)
+               tmp = from_uri;
+       else
+               tmp = g_strdup(target);
        
        if ((p = strstr(tmp, "\r")) != NULL)
                *p = '\0';
@@ -4095,7 +4703,7 @@ void mainwindow_jump_to(const gchar *target, gboolean popup)
                *p = '\0';
 
        if ((item = folder_find_item_from_identifier(tmp))) {
-               printf("selecting folder '%s'\n", tmp);
+               g_print("selecting folder '%s'\n", tmp);
                folderview_select(mainwin->folderview, item);
                if (popup)
                        main_window_popup(mainwin);
@@ -4107,13 +4715,16 @@ void mainwindow_jump_to(const gchar *target, gboolean popup)
        if (msg) {
                *msg++ = '\0';
                if ((item = folder_find_item_from_identifier(tmp))) {
-                       printf("selecting folder '%s'\n", tmp);
+                       g_print("selecting folder '%s'\n", tmp);
+                       folderview_select(mainwin->folderview, item);
+               } else if ((item = folder_find_item_from_real_path(tmp))) {
+                       g_print("selecting folder '%s'\n", tmp);
                        folderview_select(mainwin->folderview, item);
                } else {
-                       printf("'%s' not found\n", tmp);
+                       g_print("'%s' not found\n", tmp);
                }
                if (item && msg && atoi(msg)) {
-                       printf("selecting message %d\n", atoi(msg));
+                       g_print("selecting message %d\n", atoi(msg));
                        summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
                        summary_display_msg_selected(mainwin->summaryview, FALSE);
                        if (popup)
@@ -4126,7 +4737,7 @@ void mainwindow_jump_to(const gchar *target, gboolean popup)
                        msg[strlen(msg)-1] = '\0';
                        msginfo = folder_item_get_msginfo_by_msgid(item, msg);
                        if (msginfo) {
-                               printf("selecting message %s\n", msg);
+                               g_print("selecting message %s\n", msg);
                                summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
                                summary_display_msg_selected(mainwin->summaryview, FALSE);
                                if (popup)
@@ -4135,13 +4746,13 @@ void mainwindow_jump_to(const gchar *target, gboolean popup)
                                procmsg_msginfo_free(msginfo);
                                return;
                        } else {
-                               printf("'%s' not found\n", msg);
+                               g_print("'%s' not found\n", msg);
                        }
                } else {
-                       printf("'%s' not found\n", msg);
+                       g_print("'%s' not found\n", msg);
                }
        } else {
-               printf("'%s' not found\n", tmp);
+               g_print("'%s' not found\n", tmp);
        }
        
        g_free(tmp);
@@ -4151,8 +4762,10 @@ 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));
+               gtk_widget_grab_focus(mainwin->folderview->ctree);
        }
        mainwin->in_folder = FALSE;
+       main_window_set_menu_sensitive(mainwin);
 }
 
 void mainwindow_enter_folder(MainWindow *mainwin) {
@@ -4160,6 +4773,7 @@ void mainwindow_enter_folder(MainWindow *mainwin) {
                mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
        }
        mainwin->in_folder = TRUE;
+       main_window_set_menu_sensitive(mainwin);
 }
 
 #ifdef MAEMO