2006-02-12 [colin] 2.0.0cvs45
[claws.git] / src / folderview.c
index 29f560d290b290fd0041c27d9e437547200a674f..026727c13deb5a5a03cdb80b5e164a8329dc91f0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkscrolledwindow.h>
@@ -37,7 +38,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include "intl.h"
 #include "main.h"
 #include "mainwindow.h"
 #include "folderview.h"
 #include "statusbar.h"
 #include "hooks.h"
 #include "folderutils.h"
-#include "common/partial_download.h"
+#include "partial_download.h"
+#include "prefs_folder_column.h"
+#include "filtering.h"
 
-typedef enum
-{
-       COL_FOLDER      = 0,
-       COL_NEW         = 1,
-       COL_UNREAD      = 2,
-       COL_TOTAL       = 3
-} FolderColumnPos;
-
-#define N_FOLDER_COLS          4
 #define COL_FOLDER_WIDTH       150
 #define COL_NUM_WIDTH          32
 
@@ -84,7 +77,7 @@ static GtkStyle *bold_style;
 static GtkStyle *bold_color_style;
 static GtkStyle *bold_tgtfold_style;
 
-static GdkBitmap *inboxxpm;
+static GdkPixmap *inboxxpm;
 static GdkBitmap *inboxxpmmask;
 static GdkPixmap *inboxhrmxpm;
 static GdkBitmap *inboxhrmxpmmask;
@@ -124,16 +117,65 @@ static GdkPixmap *queueopenxpm;
 static GdkBitmap *queueopenxpmmask;
 static GdkPixmap *queueopenhrmxpm;
 static GdkBitmap *queueopenhrmxpmmask;
+static GdkPixmap *draftsxpm;
+static GdkBitmap *draftsxpmmask;
+static GdkPixmap *draftsopenxpm;
+static GdkBitmap *draftsopenxpmmask;
+static GdkPixmap *noselectxpm;
+static GdkBitmap *noselectxpmmask;
+
+static GdkPixmap *m_inboxxpm;
+static GdkBitmap *m_inboxxpmmask;
+static GdkPixmap *m_inboxhrmxpm;
+static GdkBitmap *m_inboxhrmxpmmask;
+static GdkPixmap *m_inboxopenxpm;
+static GdkBitmap *m_inboxopenxpmmask;
+static GdkPixmap *m_inboxopenhrmxpm;
+static GdkBitmap *m_inboxopenhrmxpmmask;
+static GdkPixmap *m_outboxxpm;
+static GdkBitmap *m_outboxxpmmask;
+static GdkPixmap *m_outboxhrmxpm;
+static GdkBitmap *m_outboxhrmxpmmask;
+static GdkPixmap *m_outboxopenxpm;
+static GdkBitmap *m_outboxopenxpmmask;
+static GdkPixmap *m_outboxopenhrmxpm;
+static GdkBitmap *m_outboxopenhrmxpmmask;
+static GdkPixmap *m_folderxpm;
+static GdkBitmap *m_folderxpmmask;
+static GdkPixmap *m_folderhrmxpm;
+static GdkBitmap *m_folderhrmxpmmask;
+static GdkPixmap *m_folderopenxpm;
+static GdkBitmap *m_folderopenxpmmask;
+static GdkPixmap *m_folderopenhrmxpm;
+static GdkBitmap *m_folderopenhrmxpmmask;
+static GdkPixmap *m_trashopenxpm;
+static GdkBitmap *m_trashopenxpmmask;
+static GdkPixmap *m_trashopenhrmxpm;
+static GdkBitmap *m_trashopenhrmxpmmask;
+static GdkPixmap *m_trashxpm;
+static GdkBitmap *m_trashxpmmask;
+static GdkPixmap *m_trashhrmxpm;
+static GdkBitmap *m_trashhrmxpmmask;
+static GdkPixmap *m_queuexpm;
+static GdkBitmap *m_queuexpmmask;
+static GdkPixmap *m_queuehrmxpm;
+static GdkBitmap *m_queuehrmxpmmask;
+static GdkPixmap *m_queueopenxpm;
+static GdkBitmap *m_queueopenxpmmask;
+static GdkPixmap *m_queueopenhrmxpm;
+static GdkBitmap *m_queueopenhrmxpmmask;
+static GdkPixmap *m_draftsxpm;
+static GdkBitmap *m_draftsxpmmask;
+static GdkPixmap *m_draftsopenxpm;
+static GdkBitmap *m_draftsopenxpmmask;
+
 static GdkPixmap *newxpm;
 static GdkBitmap *newxpmmask;
 static GdkPixmap *unreadxpm;
 static GdkBitmap *unreadxpmmask;
 static GdkPixmap *readxpm;
 static GdkBitmap *readxpmmask;
-static GdkPixmap *draftsxpm;
-static GdkBitmap *draftsxpmmask;
-static GdkPixmap *draftsopenxpm;
-static GdkBitmap *draftsopenxpmmask;
+
 
 static void folderview_select_node      (FolderView    *folderview,
                                          GtkCTreeNode  *node);
@@ -236,21 +278,22 @@ GHashTable *folderview_popups;
 
 static GtkItemFactoryEntry folderview_common_popup_entries[] =
 {
-       {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
+       {N_("/Mark all re_ad"),         NULL, mark_all_read_cb, 0, NULL},
        {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
        {N_("/_Properties..."),         NULL, folderview_property_cb, 0, NULL},
-       {N_("/Pr_ocessing..."),         NULL, folderview_processing_cb, 0, NULL},
+       {N_("/Process_ing..."),         NULL, folderview_processing_cb, 0, NULL},
 };
 
 static GtkItemFactoryEntry folder_view_trash_popup_entries[] = {
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Empty trash..."),         NULL, folderview_empty_trash_cb, 0, NULL},
+       {N_("/------"),                 NULL, NULL, 0, "<Separator>"},
+       {N_("/Empty _trash..."),        NULL, folderview_empty_trash_cb, 0, NULL},
 };
 
 
 GtkTargetEntry folderview_drag_types[] =
 {
-       {"text/plain", GTK_TARGET_SAME_APP, TARGET_DUMMY}
+       {"sylpheed-claws/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY},
+       {"text/uri-list", 0, TARGET_MAIL_URI_LIST}
 };
 
 void folderview_initialize(void)
@@ -312,64 +355,111 @@ static void create_ifactories(gpointer key, gpointer value, gpointer data)
        g_hash_table_insert(folderview->popups, fpopup->klass, factory);
 }
 
-FolderView *folderview_create(void)
+static void folderview_column_set_titles(FolderView *folderview)
+{
+       GtkWidget *ctree = folderview->ctree;
+       GtkWidget *label_new;
+       GtkWidget *label_unread;
+       GtkWidget *label_total;
+       GtkWidget *hbox_new;
+       GtkWidget *hbox_unread;
+       GtkWidget *hbox_total;
+       gint *col_pos = folderview->col_pos;
+       
+       debug_print("setting titles...\n");
+       gtk_widget_realize(folderview->ctree);
+       gtk_widget_show_all(folderview->scrolledwin);
+       
+       /* CLAWS: titles for "New" and "Unread" show new & unread pixmaps
+        * instead text (text overflows making them unreadable and ugly) */
+        stock_pixmap_gdk(ctree, STOCK_PIXMAP_NEW,
+                        &newxpm, &newxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_UNREAD,
+                        &unreadxpm, &unreadxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_READ,
+                        &readxpm, &readxpmmask);
+               
+       label_new = gtk_pixmap_new(newxpm, newxpmmask);
+       label_unread = gtk_pixmap_new(unreadxpm, unreadxpmmask);
+       label_total = gtk_pixmap_new(readxpm, readxpmmask);
+
+       hbox_new = gtk_hbox_new(FALSE, 4);
+       hbox_unread = gtk_hbox_new(FALSE, 4);
+       hbox_total = gtk_hbox_new(FALSE, 4);
+
+       /* left justified */
+       gtk_box_pack_start(GTK_BOX(hbox_new), label_new, TRUE, TRUE, 0);
+       gtk_misc_set_alignment (GTK_MISC (label_new), 1, 0.5);
+       gtk_box_pack_start(GTK_BOX(hbox_unread), label_unread, TRUE, TRUE, 0);
+       gtk_misc_set_alignment (GTK_MISC (label_unread), 1, 0.5);
+       gtk_box_pack_start(GTK_BOX(hbox_total), label_total, TRUE, TRUE, 0);
+       gtk_misc_set_alignment (GTK_MISC (label_total), 1, 0.5);
+
+       gtk_widget_show_all(hbox_new);
+       gtk_widget_show_all(hbox_unread);
+       gtk_widget_show_all(hbox_total);
+
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_NEW],hbox_new);
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_UNREAD],hbox_unread);
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_TOTAL],hbox_total);
+}
+
+GtkWidget *folderview_ctree_create(FolderView *folderview)
 {
-       FolderView *folderview;
-       GtkWidget *scrolledwin;
        GtkWidget *ctree;
+       gint *col_pos;
+       FolderColumnState *col_state;
+       FolderColumnType type;
        gchar *titles[N_FOLDER_COLS];
        gint i;
+       GtkWidget *scrolledwin = folderview->scrolledwin;
 
-       debug_print("Creating folder view...\n");
-       folderview = g_new0(FolderView, 1);
+       debug_print("creating tree...\n");
+       memset(titles, 0, sizeof(titles));
 
-       titles[COL_FOLDER] = _("Folder");
-       titles[COL_NEW]    = _("New");
-       titles[COL_UNREAD] = _("Unread");
-       titles[COL_TOTAL]  = _("#");
+       col_state = prefs_folder_column_get_config();
+       memset(titles, 0, sizeof(titles));
 
-       scrolledwin = gtk_scrolled_window_new(NULL, NULL);
-       gtk_scrolled_window_set_policy
-               (GTK_SCROLLED_WINDOW(scrolledwin),
-                GTK_POLICY_AUTOMATIC,
-                prefs_common.folderview_vscrollbar_policy);
-       gtk_widget_set_size_request(scrolledwin,
-                            prefs_common.folderview_width,
-                            prefs_common.folderview_height);
+       col_pos = folderview->col_pos;
+
+       for (i = 0; i < N_FOLDER_COLS; i++) {
+               folderview->col_state[i] = col_state[i];
+               type = col_state[i].type;
+               col_pos[type] = i;
+       }
+
+       titles[col_pos[F_COL_FOLDER]] = _("Folder");
+       titles[col_pos[F_COL_NEW]]    = _("New");
+       titles[col_pos[F_COL_UNREAD]] = _("Unread");
+       titles[col_pos[F_COL_TOTAL]]  = _("#");
 
-       ctree = gtk_sctree_new_with_titles(N_FOLDER_COLS, COL_FOLDER, titles);
+       ctree = gtk_sctree_new_with_titles(N_FOLDER_COLS, col_pos[F_COL_FOLDER],
+                                          titles);
        
-       gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
        gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
-       gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_NEW,
+       gtk_clist_set_column_justification(GTK_CLIST(ctree), col_pos[F_COL_NEW],
                                           GTK_JUSTIFY_RIGHT);
-       gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_UNREAD,
+       gtk_clist_set_column_justification(GTK_CLIST(ctree),
+                                          col_pos[F_COL_UNREAD],
                                           GTK_JUSTIFY_RIGHT);
-       gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_TOTAL,
+       gtk_clist_set_column_justification(GTK_CLIST(ctree), 
+                                          col_pos[F_COL_TOTAL],
                                           GTK_JUSTIFY_RIGHT);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_FOLDER,
-                                  prefs_common.folder_col_folder);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_NEW,
-                                  prefs_common.folder_col_new);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_UNREAD,        
-                                  prefs_common.folder_col_unread);
-       gtk_clist_set_column_width(GTK_CLIST(ctree), COL_TOTAL,
-                                  prefs_common.folder_col_total);
        gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_DOTTED);
        gtk_ctree_set_expander_style(GTK_CTREE(ctree),
                                     GTK_CTREE_EXPANDER_SQUARE);
        gtk_ctree_set_indent(GTK_CTREE(ctree), CTREE_INDENT);
        gtk_clist_set_compare_func(GTK_CLIST(ctree), folderview_clist_compare);
 
-       /* create popup factories */
-       folderview->popups = g_hash_table_new(g_str_hash, g_str_equal);
-       g_hash_table_foreach(folderview_popups, create_ifactories, folderview);
-
        /* don't let title buttons take key focus */
-       for (i = 0; i < N_FOLDER_COLS; i++)
+       for (i = 0; i < N_FOLDER_COLS; i++) {
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
                                       GTK_CAN_FOCUS);
-
+               gtk_clist_set_column_width(GTK_CLIST(ctree), col_pos[i],
+                                  prefs_common.folder_col_size[i]);
+               gtk_clist_set_column_visibility
+                       (GTK_CLIST(ctree), i, col_state[i].visible);
+       }
 
        g_signal_connect(G_OBJECT(ctree), "key_press_event",
                         G_CALLBACK(folderview_key_pressed),
@@ -401,7 +491,7 @@ FolderView *folderview_create(void)
 
         /* drop callback */
        gtk_drag_dest_set(ctree, GTK_DEST_DEFAULT_ALL & ~GTK_DEST_DEFAULT_HIGHLIGHT,
-                         summary_drag_types, 1,
+                         folderview_drag_types, 2,
                          GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_DEFAULT);
        g_signal_connect(G_OBJECT(ctree), "drag_motion",
                         G_CALLBACK(folderview_drag_motion_cb),
@@ -416,7 +506,58 @@ FolderView *folderview_create(void)
                         G_CALLBACK(folderview_drag_end_cb),
                         folderview);
 
+       gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
+
+       return ctree;
+}
+
+void folderview_set_column_order(FolderView *folderview)
+{
+       GtkWidget *ctree;
+       FolderItem *item = folderview_get_selected_item(folderview);
+       GtkWidget *scrolledwin = folderview->scrolledwin;
+
+       debug_print("recreating tree...\n");
+       gtk_widget_destroy(folderview->ctree);
+
+       folderview->ctree = ctree = folderview_ctree_create(folderview);
+       gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
+                                           GTK_CLIST(ctree)->hadjustment);
+       gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolledwin),
+                                           GTK_CLIST(ctree)->vadjustment);
+       gtk_widget_show(ctree);
+       
+       folderview_set(folderview);
+       folderview_column_set_titles(folderview);
+
+       folderview_select(folderview,item);
+}
+
+FolderView *folderview_create(void)
+{
+       FolderView *folderview;
+       GtkWidget *scrolledwin;
+       GtkWidget *ctree;
+
+       debug_print("Creating folder view...\n");
+       folderview = g_new0(FolderView, 1);
+
+       scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_policy
+               (GTK_SCROLLED_WINDOW(scrolledwin),
+                GTK_POLICY_AUTOMATIC,
+                prefs_common.folderview_vscrollbar_policy);
+       gtk_widget_set_size_request(scrolledwin,
+                            prefs_common.folderview_width,
+                            prefs_common.folderview_height);
+
        folderview->scrolledwin  = scrolledwin;
+       ctree = folderview_ctree_create(folderview);
+       
+       /* create popup factories */
+       folderview->popups = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_foreach(folderview_popups, create_ifactories, folderview);
+
        folderview->ctree        = ctree;
 
        folderview->folder_update_callback_id =
@@ -425,8 +566,8 @@ FolderView *folderview_create(void)
                hooks_register_hook(FOLDER_ITEM_UPDATE_HOOKLIST, folderview_update_item_claws, (gpointer) folderview);
 
        gtk_widget_show_all(scrolledwin);
-
-       folderview->target_list = gtk_target_list_new(folderview_drag_types, 1);
+       
+       folderview->target_list = gtk_target_list_new(folderview_drag_types, 2);
        folderview_list = g_list_append(folderview_list, folderview);
 
        return folderview;
@@ -435,14 +576,8 @@ FolderView *folderview_create(void)
 void folderview_init(FolderView *folderview)
 {
        GtkWidget *ctree = folderview->ctree;
-       GtkWidget *label_new;
-       GtkWidget *label_unread;
-       GtkWidget *label_total;
-       GtkWidget *hbox_new;
-       GtkWidget *hbox_unread;
-       GtkWidget *hbox_total;
-               
-       gtk_widget_realize(ctree);
+       GdkColor gdk_color;
+
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE, &inboxxpm, &inboxxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE_HRM, &inboxhrmxpm, &inboxhrmxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_OPEN, &inboxopenxpm, &inboxopenxpmmask);
@@ -465,39 +600,30 @@ void folderview_init(FolderView *folderview)
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_OPEN_HRM, &queueopenhrmxpm, &queueopenhrmxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_DRAFTS_CLOSE, &draftsxpm, &draftsxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_DRAFTS_OPEN, &draftsopenxpm, &draftsopenxpmmask);
-
-       /* CLAWS: titles for "New" and "Unread" show new & unread pixmaps
-        * instead text (text overflows making them unreadable and ugly) */
-        stock_pixmap_gdk(ctree, STOCK_PIXMAP_NEW,
-                        &newxpm, &newxpmmask);
-       stock_pixmap_gdk(ctree, STOCK_PIXMAP_UNREAD,
-                        &unreadxpm, &unreadxpmmask);
-       stock_pixmap_gdk(ctree, STOCK_PIXMAP_READ,
-                        &readxpm, &readxpmmask);
-               
-       label_new = gtk_pixmap_new(newxpm, newxpmmask);
-       label_unread = gtk_pixmap_new(unreadxpm, unreadxpmmask);
-       label_total = gtk_pixmap_new(readxpm, readxpmmask);
-
-       hbox_new = gtk_hbox_new(FALSE, 4);
-       hbox_unread = gtk_hbox_new(FALSE, 4);
-       hbox_total = gtk_hbox_new(FALSE, 4);
-
-       /* left justified */
-       gtk_box_pack_start(GTK_BOX(hbox_new), label_new, TRUE, TRUE, 0);
-       gtk_misc_set_alignment (GTK_MISC (label_new), 1, 0.5);
-       gtk_box_pack_start(GTK_BOX(hbox_unread), label_unread, TRUE, TRUE, 0);
-       gtk_misc_set_alignment (GTK_MISC (label_unread), 1, 0.5);
-       gtk_box_pack_start(GTK_BOX(hbox_total), label_total, TRUE, TRUE, 0);
-       gtk_misc_set_alignment (GTK_MISC (label_total), 1, 0.5);
-
-       gtk_widget_show_all(hbox_new);
-       gtk_widget_show_all(hbox_unread);
-       gtk_widget_show_all(hbox_total);
-
-       gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_NEW,hbox_new);
-       gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_UNREAD,hbox_unread);
-       gtk_clist_set_column_widget(GTK_CLIST(ctree),COL_TOTAL,hbox_total);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_NOSELECT, &noselectxpm, &noselectxpmmask);
+
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE_MARK, &m_inboxxpm, &m_inboxxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_CLOSE_HRM_MARK, &m_inboxhrmxpm, &m_inboxhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_OPEN_MARK, &m_inboxopenxpm, &m_inboxopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_INBOX_OPEN_HRM_MARK, &m_inboxopenhrmxpm, &m_inboxopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_CLOSE_MARK, &m_outboxxpm, &m_outboxxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_CLOSE_HRM_MARK, &m_outboxhrmxpm, &m_outboxhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_OPEN_MARK, &m_outboxopenxpm, &m_outboxopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_OUTBOX_OPEN_HRM_MARK, &m_outboxopenhrmxpm, &m_outboxopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_CLOSE_MARK, &m_folderxpm, &m_folderxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_CLOSE_HRM_MARK, &m_folderhrmxpm, &m_folderhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_OPEN_MARK, &m_folderopenxpm, &m_folderopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DIR_OPEN_HRM_MARK, &m_folderopenhrmxpm, &m_folderopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_OPEN_MARK, &m_trashopenxpm, &m_trashopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_OPEN_HRM_MARK, &m_trashopenhrmxpm, &m_trashopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_CLOSE_MARK, &m_trashxpm, &m_trashxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_TRASH_CLOSE_HRM_MARK, &m_trashhrmxpm, &m_trashhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_CLOSE_MARK, &m_queuexpm, &m_queuexpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_CLOSE_HRM_MARK, &m_queuehrmxpm, &m_queuehrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_OPEN_MARK, &m_queueopenxpm, &m_queueopenxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_QUEUE_OPEN_HRM_MARK, &m_queueopenhrmxpm, &m_queueopenhrmxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DRAFTS_CLOSE_MARK, &m_draftsxpm, &m_draftsxpmmask);
+       stock_pixmap_gdk(ctree, STOCK_PIXMAP_DRAFTS_OPEN_MARK, &m_draftsopenxpm, &m_draftsopenxpmmask);
                        
        if (!normal_style) {
                PangoFontDescription *font_desc;
@@ -509,24 +635,20 @@ void folderview_init(FolderView *folderview)
                                        (normal_style->font_desc);
                        normal_style->font_desc = font_desc;
                }
+               gtkut_convert_int_to_gdk_color(prefs_common.color_new, &gdk_color);
                normal_color_style = gtk_style_copy(normal_style);
-               normal_color_style->fg[GTK_STATE_NORMAL] = folderview->color_new;
+               normal_color_style->fg[GTK_STATE_NORMAL] = gdk_color;
 
                gtk_widget_set_style(ctree, normal_style);
        }
 
        if (!bold_style) {
-               PangoFontDescription *font_desc;
+               gtkut_convert_int_to_gdk_color(prefs_common.color_new, &gdk_color);
                bold_style = gtk_style_copy(gtk_widget_get_style(ctree));
-               font_desc = pango_font_description_from_string(prefs_common.boldfont);
-               if (font_desc) {
-                       if (bold_style->font_desc)
-                               pango_font_description_free
-                                       (bold_style->font_desc);
-                       bold_style->font_desc = font_desc;
-               }
+               pango_font_description_set_weight
+                       (bold_style->font_desc, PANGO_WEIGHT_BOLD);
                bold_color_style = gtk_style_copy(bold_style);
-               bold_color_style->fg[GTK_STATE_NORMAL] = folderview->color_new;
+               bold_color_style->fg[GTK_STATE_NORMAL] = gdk_color;
 
                bold_tgtfold_style = gtk_style_copy(bold_style);
                bold_tgtfold_style->fg[GTK_STATE_NORMAL] = folderview->color_op;
@@ -538,6 +660,9 @@ void folderview_set(FolderView *folderview)
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        MainWindow *mainwin = folderview->mainwin;
 
+       if (!mainwin)
+               return;
+
        debug_print("Setting folder info...\n");
        STATUSBAR_PUSH(mainwin, _("Setting folder info..."));
 
@@ -585,12 +710,34 @@ static void mark_all_read_cb(FolderView *folderview, guint action,
                              GtkWidget *widget)
 {
        FolderItem *item;
-
+       AlertValue val;
+       
        item = folderview_get_selected_item(folderview);
        if (item == NULL)
                return;
 
+       if (prefs_common.ask_mark_all_read) {
+               val = alertpanel_full(_("Mark all as read"),
+                       _("Do you really want to mark all mails in this "
+                         "folder as read ?"), GTK_STOCK_NO, GTK_STOCK_YES, NULL,
+                         TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
+
+               if (val == G_ALERTDEFAULT ||
+                   val == (G_ALERTDEFAULT|G_ALERTDISABLE))
+                       return;
+               else if (val == (G_ALERTALTERNATE|G_ALERTDISABLE))
+                       prefs_common.ask_mark_all_read = FALSE;
+       }
+       
+       summary_lock(folderview->summaryview);
+       folder_item_update_freeze();
+       if (folderview->summaryview->folder_item == item)
+               gtk_clist_freeze(GTK_CLIST(folderview->summaryview->ctree));
        folderutils_mark_all_read(item);
+       if (folderview->summaryview->folder_item == item)
+               gtk_clist_thaw(GTK_CLIST(folderview->summaryview->ctree));
+       folder_item_update_thaw();
+       summary_unlock(folderview->summaryview);
 }
 
 static void folderview_select_node(FolderView *folderview, GtkCTreeNode *node)
@@ -658,6 +805,44 @@ void folderview_select_next_unread(FolderView *folderview)
                folderview_select_node(folderview, node);
 }
 
+static GtkCTreeNode *folderview_find_next_new(GtkCTree *ctree,
+                                                GtkCTreeNode *node)
+{
+       FolderItem *item;
+
+       if (node)
+               node = gtkut_ctree_node_next(ctree, node);
+       else
+               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
+
+       for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
+               item = gtk_ctree_node_get_row_data(ctree, node);
+               if (item && item->new_msgs > 0 && item->stype != F_TRASH)
+                       return node;
+       }
+
+       return NULL;
+}
+
+void folderview_select_next_new(FolderView *folderview)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       GtkCTreeNode *node = NULL;
+
+       if ((node = folderview_find_next_new(ctree, folderview->opened))
+           != NULL) {
+               folderview_select_node(folderview, node);
+               return;
+       }
+
+       if (!folderview->opened ||
+           folderview->opened == GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list))
+               return;
+       /* search again from the first node */
+       if ((node = folderview_find_next_new(ctree, NULL)) != NULL)
+               folderview_select_node(folderview, node);
+}
+
 FolderItem *folderview_get_selected_item(FolderView *folderview)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
@@ -673,15 +858,16 @@ void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row)
        FolderItem *item;
        gint new, unread, total;
        gchar *new_str, *unread_str, *total_str;
+       gint *col_pos = folderview->col_pos;
 
        if (!row) return;
 
        item = gtk_ctree_node_get_row_data(ctree, row);
        if (!item) return;
 
-       gtk_ctree_node_get_text(ctree, row, COL_NEW, &new_str);
-       gtk_ctree_node_get_text(ctree, row, COL_UNREAD, &unread_str);
-       gtk_ctree_node_get_text(ctree, row, COL_TOTAL, &total_str);
+       gtk_ctree_node_get_text(ctree, row, col_pos[F_COL_NEW], &new_str);
+       gtk_ctree_node_get_text(ctree, row, col_pos[F_COL_UNREAD], &unread_str);
+       gtk_ctree_node_get_text(ctree, row, col_pos[F_COL_TOTAL], &total_str);
        new = atoi(new_str);
        unread = atoi(unread_str);
        total = atoi(total_str);
@@ -694,7 +880,7 @@ void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row)
 void folderview_append_item(FolderItem *item)
 {
        GList *list;
-
+       
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
        if (folder_item_parent(item)) return;
@@ -703,6 +889,7 @@ void folderview_append_item(FolderItem *item)
                FolderView *folderview = (FolderView *)list->data;
                GtkCTree *ctree = GTK_CTREE(folderview->ctree);
                GtkCTreeNode *node, *child;
+               gint *col_pos = folderview->col_pos;
 
                node = gtk_ctree_find_by_row_data(ctree, NULL, 
                                                  folder_item_parent(item));
@@ -714,8 +901,8 @@ void folderview_append_item(FolderItem *item)
 
                                gtk_clist_freeze(GTK_CLIST(ctree));
 
-                               text[COL_FOLDER] = item->name;
-                               child = gtk_ctree_insert_node
+                               text[col_pos[F_COL_FOLDER]] = item->name;
+                               child = gtk_sctree_insert_node
                                        (ctree, node, NULL, text,
                                         FOLDER_SPACING,
                                         folderxpm, folderxpmmask,
@@ -767,30 +954,7 @@ static void folderview_scan_tree_func(Folder *folder, FolderItem *item,
        }
 }
 
-static GtkWidget *label_window_create(const gchar *str)
-{
-       GtkWidget *window;
-       GtkWidget *label;
-
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-       gtk_widget_set_size_request(window, 380, 60);
-       gtk_container_set_border_width(GTK_CONTAINER(window), 8);
-       gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_title(GTK_WINDOW(window), str);
-       gtk_window_set_modal(GTK_WINDOW(window), TRUE);
-       gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
-       manage_window_set_transient(GTK_WINDOW(window));
-
-       label = gtk_label_new(str);
-       gtk_container_add(GTK_CONTAINER(window), label);
-       gtk_widget_show(label);
-
-       gtk_widget_show_now(window);
-
-       return window;
-}
-
-void folderview_rescan_tree(Folder *folder)
+void folderview_rescan_tree(Folder *folder, gboolean rebuild)
 {
        GtkWidget *window;
 
@@ -798,11 +962,24 @@ void folderview_rescan_tree(Folder *folder)
 
        if (!folder->klass->scan_tree) return;
 
+       if (rebuild && 
+           alertpanel_full(_("Rebuild folder tree"), 
+                        _("Rebuilding the folder tree will remove "
+                          "local caches. Do you want to continue?"),
+                        GTK_STOCK_NO, GTK_STOCK_YES, NULL, FALSE,
+                        NULL, ALERT_WARNING, G_ALERTDEFAULT) 
+               != G_ALERTALTERNATE) {
+               return;
+       }
+
        inc_lock();
-       window = label_window_create(_("Rebuilding folder tree..."));
+       if (rebuild)
+               window = label_window_create(_("Rebuilding folder tree..."));
+       else 
+               window = label_window_create(_("Scanning folder tree..."));
 
        folder_set_ui_func(folder, folderview_scan_tree_func, NULL);
-       folder_scan_tree(folder);
+       folder_scan_tree(folder, rebuild);
        folder_set_ui_func(folder, NULL, NULL);
 
        folderview_set_all();
@@ -826,7 +1003,7 @@ gint folderview_check_new(Folder *folder)
        GtkCTreeNode *node;
        gint new_msgs = 0;
        gint former_new_msgs = 0;
-       gint former_new = 0;
+       gint former_new = 0, former_unread = 0, former_total;
 
        for (list = folderview_list; list != NULL; list = list->next) {
                folderview = (FolderView *)list->data;
@@ -834,7 +1011,6 @@ gint folderview_check_new(Folder *folder)
 
                inc_lock();
                main_window_lock(folderview->mainwin);
-               gtk_widget_set_sensitive(folderview->ctree, FALSE);
 
                for (node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
                     node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
@@ -846,17 +1022,25 @@ gint folderview_check_new(Folder *folder)
                        if (!item->prefs->newmailcheck) continue;
 
                        folderview_scan_tree_func(item->folder, item, NULL);
-                       former_new = item->new_msgs;
+                       former_new    = item->new_msgs;
+                       former_unread = item->unread_msgs;
+                       former_total  = item->total_msgs;
+
                        if (folder_item_scan(item) < 0) {
+                               summaryview_unlock(folderview->summaryview, item);
                                if (folder && !FOLDER_IS_LOCAL(folder))
                                        break;
                        }
-                       folderview_update_node(folderview, node);
+
+                       if (former_new    != item->new_msgs ||
+                           former_unread != item->unread_msgs ||
+                           former_total  != item->total_msgs)
+                               folderview_update_node(folderview, node);
+
                        new_msgs += item->new_msgs;
                        former_new_msgs += former_new;
                }
 
-               gtk_widget_set_sensitive(folderview->ctree, TRUE);
                main_window_unlock(folderview->mainwin);
                inc_unlock();
        }
@@ -899,98 +1083,160 @@ void folderview_check_new_all(void)
        inc_unlock();
 }
 
-static gboolean folderview_search_new_recursive(GtkCTree *ctree,
-                                               GtkCTreeNode *node)
+static gboolean folderview_have_new_children_sub(FolderView *folderview,
+                                                FolderItem *item,
+                                                gboolean in_sub)
 {
-       FolderItem *item;
+       GNode *node = NULL;
+       
+       if (!item || !item->folder || !item->folder->node)
+               return FALSE;
+               
+       node = item->folder->node;
+       
+       node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       node = node->children;
 
-       if (node) {
-               item = gtk_ctree_node_get_row_data(ctree, node);
-               if (item) {
-                       if (item->new_msgs > 0 ||
-                           (item->stype == F_QUEUE && item->total_msgs > 0))
+       if (in_sub &&
+           (item->new_msgs > 0 ||
+           (folder_has_parent_of_type(item, F_QUEUE) && item->total_msgs > 0))) {
+               return TRUE;
+       }
+
+       while (node != NULL) {
+               if (node && node->data) {
+                       FolderItem *next_item = (FolderItem*) node->data;
+                       node = node->next;
+                       if (folderview_have_new_children_sub(folderview, 
+                                                            next_item, TRUE))
                                return TRUE;
                }
-               node = GTK_CTREE_ROW(node)->children;
-       } else
-               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
-
-       while (node) {
-               if (folderview_search_new_recursive(ctree, node) == TRUE)
-                       return TRUE;
-               node = GTK_CTREE_ROW(node)->sibling;
        }
 
        return FALSE;
 }
 
 static gboolean folderview_have_new_children(FolderView *folderview,
-                                            GtkCTreeNode *node)
+                                            FolderItem *item)
 {
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       return folderview_have_new_children_sub(folderview, item, FALSE);
+}
 
-       if (!node)
-               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
-       if (!node)
+static gboolean folderview_have_unread_children_sub(FolderView *folderview,
+                                                   FolderItem *item, 
+                                                   gboolean in_sub)
+{
+       GNode *node = NULL;
+       
+       if (!item || !item->folder || !item->folder->node)
                return FALSE;
+       
+       node = item->folder->node;
+       
+       node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       node = node->children;
 
-       node = GTK_CTREE_ROW(node)->children;
+       if (in_sub &&
+           (item->unread_msgs > 0 ||
+           (folder_has_parent_of_type(item, F_QUEUE) && item->total_msgs > 0))) {
+               return TRUE;
+       }
 
-       while (node) {
-               if (folderview_search_new_recursive(ctree, node) == TRUE)
-                       return TRUE;
-               node = GTK_CTREE_ROW(node)->sibling;
+       while (node != NULL) {
+               if (node && node->data) {
+                       FolderItem *next_item = (FolderItem*) node->data;
+                       node = node->next;
+                       if (folderview_have_unread_children_sub(folderview, 
+                                                               next_item, 
+                                                               TRUE))
+                               return TRUE;
+               }
        }
 
        return FALSE;
 }
 
-static gboolean folderview_search_unread_recursive(GtkCTree *ctree,
-                                                  GtkCTreeNode *node)
+static gboolean folderview_have_unread_children(FolderView *folderview,
+                                               FolderItem *item)
 {
-       FolderItem *item;
+       return folderview_have_unread_children_sub(folderview, item, FALSE);
+}
 
-       if (node) {
-               item = gtk_ctree_node_get_row_data(ctree, node);
-               if (item) {
-                       if (item->unread_msgs > 0 ||
-                           (item->stype == F_QUEUE && item->total_msgs > 0))
+static gboolean folderview_have_matching_children_sub(FolderView *folderview,
+                                                     FolderItem *item,
+                                                     gboolean in_sub)
+{
+       GNode *node = NULL;
+
+       if (!item || !item->folder || !item->folder->node)
+               return FALSE;
+
+       node = item->folder->node;
+       
+       node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       node = node->children;
+
+       if (in_sub && item->search_match){
+               return TRUE;
+       }
+
+       while (node != NULL) {
+               if (node && node->data) {
+                       FolderItem *next_item = (FolderItem*) node->data;
+                       node = node->next;
+                       if (folderview_have_matching_children_sub(folderview, 
+                                                                 next_item, 
+                                                                 TRUE))
                                return TRUE;
                }
-               node = GTK_CTREE_ROW(node)->children;
-       } else
-               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
-
-       while (node) {
-               if (folderview_search_unread_recursive(ctree, node) == TRUE)
-                       return TRUE;
-               node = GTK_CTREE_ROW(node)->sibling;
        }
 
        return FALSE;
 }
 
-static gboolean folderview_have_unread_children(FolderView *folderview,
-                                               GtkCTreeNode *node)
+static gboolean folderview_have_matching_children(FolderView *folderview,
+                                                 FolderItem *item)
 {
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       return folderview_have_matching_children_sub(folderview, item, FALSE);
+}
 
-       if (!node)
-               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
-       if (!node)
+static gboolean folderview_have_marked_children_sub(FolderView *folderview,
+                                                   FolderItem *item,
+                                                   gboolean in_sub)
+{
+       GNode *node = NULL;
+       
+       if (!item || !item->folder || !item->folder->node)
                return FALSE;
+               
+       node = item->folder->node;
+       
+       node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       node = node->children;
 
-       node = GTK_CTREE_ROW(node)->children;
+       if (item->marked_msgs != 0) {
+               return TRUE;
+       }
 
-       while (node) {
-               if (folderview_search_unread_recursive(ctree, node) == TRUE)
-                       return TRUE;
-               node = GTK_CTREE_ROW(node)->sibling;
+       while (node != NULL) {
+               if (node && node->data) {
+                       FolderItem *next_item = (FolderItem*) node->data;
+                       node = node->next;
+                       if (folderview_have_marked_children_sub(folderview,
+                                                               next_item, TRUE))
+                               return TRUE;
+               }
        }
 
        return FALSE;
 }
 
+static gboolean folderview_have_marked_children(FolderView *folderview,
+                                            FolderItem *item)
+{
+       return folderview_have_marked_children_sub(folderview, item, FALSE);
+}
+
 static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
@@ -999,112 +1245,154 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        FolderItem *item;
        GdkPixmap *xpm, *openxpm;
        GdkBitmap *mask, *openmask;
+       static GdkPixmap *searchicon;
+       static GdkBitmap *searchmask;
+       gboolean mark = FALSE;
        gchar *name;
        gchar *str;
        gboolean add_unread_mark;
+       gboolean add_sub_match_mark;
        gboolean use_bold, use_color;
-
+       gint *col_pos = folderview->col_pos;
+       SpecialFolderItemType stype;
+       
        item = gtk_ctree_node_get_row_data(ctree, node);
        g_return_if_fail(item != NULL);
 
-       switch (item->stype) {
+       if (!GTK_CTREE_ROW(node)->expanded)
+               mark = folderview_have_marked_children(folderview, item);
+       else
+               mark = (item->marked_msgs != 0);
+
+       stype = item->stype;
+       if (stype == F_NORMAL) {
+               if (folder_has_parent_of_type(item, F_TRASH))
+                       stype = F_TRASH;
+               else if (folder_has_parent_of_type(item, F_DRAFT))
+                       stype = F_DRAFT;
+               else if (folder_has_parent_of_type(item, F_OUTBOX))
+                       stype = F_OUTBOX;
+               else if (folder_has_parent_of_type(item, F_QUEUE))
+                       stype = F_QUEUE;
+       }
+       switch (stype) {
        case F_INBOX:
                if (item->hide_read_msgs) {
-                       xpm = inboxhrmxpm;
-                       mask = inboxhrmxpmmask;
-                       openxpm = inboxopenhrmxpm;
-                       openmask = inboxopenhrmxpmmask;
+                       xpm = mark?m_inboxhrmxpm:inboxhrmxpm;
+                       mask = mark?m_inboxhrmxpmmask:inboxhrmxpmmask;
+                       openxpm = mark?m_inboxopenhrmxpm:inboxopenhrmxpm;
+                       openmask = mark?m_inboxopenhrmxpmmask:inboxopenhrmxpmmask;
                } else {
-                       xpm = inboxxpm;
-                       mask = inboxxpmmask;
-                       openxpm = inboxopenxpm;
-                       openmask = inboxopenxpmmask;
+                       xpm = mark?m_inboxxpm:inboxxpm;
+                       mask = mark?m_inboxxpmmask:inboxxpmmask;
+                       openxpm = mark?m_inboxopenxpm:inboxopenxpm;
+                       openmask = mark?m_inboxopenxpmmask:inboxopenxpmmask;
                }
                break;
        case F_OUTBOX:
                if (item->hide_read_msgs) {
-                       xpm = outboxhrmxpm;
-                       mask = outboxhrmxpmmask;
-                       openxpm = outboxopenhrmxpm;
-                       openmask = outboxopenhrmxpmmask;
+                       xpm = mark?m_outboxhrmxpm:outboxhrmxpm;
+                       mask = mark?m_outboxhrmxpmmask:outboxhrmxpmmask;
+                       openxpm = mark?m_outboxopenhrmxpm:outboxopenhrmxpm;
+                       openmask = mark?m_outboxopenhrmxpmmask:outboxopenhrmxpmmask;
                } else {
-                       xpm = outboxxpm;
-                       mask = outboxxpmmask;
-                       openxpm = outboxopenxpm;
-                       openmask = outboxopenxpmmask;
+                       xpm = mark?m_outboxxpm:outboxxpm;
+                       mask = mark?m_outboxxpmmask:outboxxpmmask;
+                       openxpm = mark?m_outboxopenxpm:outboxopenxpm;
+                       openmask = mark?m_outboxopenxpmmask:outboxopenxpmmask;
                }
                break;
        case F_QUEUE:
                if (item->hide_read_msgs) {
-                       xpm = queuehrmxpm;
-                       mask = queuehrmxpmmask;
-                       openxpm = queueopenhrmxpm;
-                       openmask = queueopenhrmxpmmask;
+                       xpm = mark?m_queuehrmxpm:queuehrmxpm;
+                       mask = mark?m_queuehrmxpmmask:queuehrmxpmmask;
+                       openxpm = mark?m_queueopenhrmxpm:queueopenhrmxpm;
+                       openmask = mark?m_queueopenhrmxpmmask:queueopenhrmxpmmask;
                } else {
-                       xpm = queuexpm;
-                       mask = queuexpmmask;
-                       openxpm = queueopenxpm;
-                       openmask = queueopenxpmmask;
+                       xpm = mark?m_queuexpm:queuexpm;
+                       mask = mark?m_queuexpmmask:queuexpmmask;
+                       openxpm = mark?m_queueopenxpm:queueopenxpm;
+                       openmask = mark?m_queueopenxpmmask:queueopenxpmmask;
                }
                break;
        case F_TRASH:
                if (item->hide_read_msgs) {
-                       xpm = trashhrmxpm;
-                       mask = trashhrmxpmmask;
-                       openxpm = trashopenhrmxpm;
-                       openmask = trashopenhrmxpmmask;
+                       xpm = mark?m_trashhrmxpm:trashhrmxpm;
+                       mask = mark?m_trashhrmxpmmask:trashhrmxpmmask;
+                       openxpm = mark?m_trashopenhrmxpm:trashopenhrmxpm;
+                       openmask = mark?m_trashopenhrmxpmmask:trashopenhrmxpmmask;
                } else {
-                       xpm = trashxpm;
-                       mask = trashxpmmask;
-                       openxpm = trashopenxpm;
-                       openmask = trashopenxpmmask;
+                       xpm = mark?m_trashxpm:trashxpm;
+                       mask = mark?m_trashxpmmask:trashxpmmask;
+                       openxpm = mark?m_trashopenxpm:trashopenxpm;
+                       openmask = mark?m_trashopenxpmmask:trashopenxpmmask;
                }
                break;
        case F_DRAFT:
-               xpm = draftsxpm;
-               mask = draftsxpmmask;
-               openxpm = draftsopenxpm;
-               openmask = draftsopenxpmmask;
+               xpm = mark?m_draftsxpm:draftsxpm;
+               mask = mark?m_draftsxpmmask:draftsxpmmask;
+               openxpm = mark?m_draftsopenxpm:draftsopenxpm;
+               openmask = mark?m_draftsopenxpmmask:draftsopenxpmmask;
                break;
        default:
                if (item->hide_read_msgs) {
-                       xpm = folderhrmxpm;
-                       mask = folderhrmxpmmask;
-                       openxpm = folderopenhrmxpm;
-                       openmask = folderopenhrmxpmmask;
+                       xpm = mark?m_folderhrmxpm:folderhrmxpm;
+                       mask = mark?m_folderhrmxpmmask:folderhrmxpmmask;
+                       openxpm = mark?m_folderopenhrmxpm:folderopenhrmxpm;
+                       openmask = mark?m_folderopenhrmxpmmask:folderopenhrmxpmmask;
                } else {
-                       xpm = folderxpm;
-                       mask = folderxpmmask;
-                       openxpm = folderopenxpm;
-                       openmask = folderopenxpmmask;
+                       xpm = mark?m_folderxpm:folderxpm;
+                       mask = mark?m_folderxpmmask:folderxpmmask;
+                       openxpm = mark?m_folderopenxpm:folderopenxpm;
+                       openmask = mark?m_folderopenxpmmask:folderopenxpmmask;
                }
        }
+       
+       if (item->no_select) {
+               xpm = openxpm = noselectxpm;
+               mask = openmask = noselectxpmmask;
+       }
+
        name = folder_item_get_name(item);
 
-       if (!GTK_CTREE_ROW(node)->expanded &&
-           folderview_have_unread_children(folderview, node))
-               add_unread_mark = TRUE;
-       else
+       if (!GTK_CTREE_ROW(node)->expanded) {
+               add_unread_mark = folderview_have_unread_children(
+                                       folderview, item);
+               add_sub_match_mark = folderview_have_matching_children(
+                                       folderview, item);
+       } else {
                add_unread_mark = FALSE;
+               add_sub_match_mark = FALSE;
+       }
+
+       if (item->search_match) {
+               if (!searchicon) {
+                       stock_pixmap_gdk(folderview->ctree, STOCK_PIXMAP_QUICKSEARCH,
+                        &searchicon, &searchmask);
+               }
+               xpm = openxpm = searchicon;
+               mask = openmask = searchmask;
+       }
 
-       if (item->stype == F_QUEUE && item->total_msgs > 0 &&
+       if (folder_has_parent_of_type(item, F_QUEUE) && item->total_msgs > 0 &&
            prefs_common.display_folder_unread) {
                str = g_strdup_printf("%s (%d%s)", name, item->total_msgs,
                                      add_unread_mark ? "+" : "");
-               gtk_ctree_set_node_info(ctree, node, str, FOLDER_SPACING,
+               gtk_sctree_set_node_info(ctree, node, str, FOLDER_SPACING,
                                        xpm, mask, openxpm, openmask,
                                        FALSE, GTK_CTREE_ROW(node)->expanded);
                g_free(str);
-       } else if ((item->unread_msgs > 0 || add_unread_mark) &&
-                prefs_common.display_folder_unread) {
+       } else if (((item->unread_msgs > 0 || add_unread_mark) &&
+                   prefs_common.display_folder_unread) 
+                  || add_sub_match_mark) {
 
                if (item->unread_msgs > 0)
                        str = g_strdup_printf("%s (%d%s%s)", name, item->unread_msgs,
-                                             add_unread_mark ? "+" : "", 
+                                             add_unread_mark || add_sub_match_mark ? "+" : "", 
                                              item->unreadmarked_msgs > 0 ? "!":"");
                else
                        str = g_strdup_printf("%s (+)", name);
-               gtk_ctree_set_node_info(ctree, node, str, FOLDER_SPACING,
+               gtk_sctree_set_node_info(ctree, node, str, FOLDER_SPACING,
                                        xpm, mask, openxpm, openmask,
                                        FALSE, GTK_CTREE_ROW(node)->expanded);
                g_free(str);
@@ -1112,7 +1400,7 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
                str = g_strdup_printf("%s%s", name, 
                                      item->unreadmarked_msgs > 0 ? " (!)":"");
        
-               gtk_ctree_set_node_info(ctree, node, str, FOLDER_SPACING,
+               gtk_sctree_set_node_info(ctree, node, str, FOLDER_SPACING,
                                        xpm, mask, openxpm, openmask,
                                        FALSE, GTK_CTREE_ROW(node)->expanded);
                g_free(str);
@@ -1120,57 +1408,65 @@ static void folderview_update_node(FolderView *folderview, GtkCTreeNode *node)
        g_free(name);
 
        if (!folder_item_parent(item)) {
-               gtk_ctree_node_set_text(ctree, node, COL_NEW,    "-");
-               gtk_ctree_node_set_text(ctree, node, COL_UNREAD, "-");
-               gtk_ctree_node_set_text(ctree, node, COL_TOTAL,  "-");
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_NEW],    "-");
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_UNREAD], "-");
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_TOTAL],  "-");
        } else {
-               gtk_ctree_node_set_text(ctree, node, COL_NEW,    itos(item->new_msgs));
-               gtk_ctree_node_set_text(ctree, node, COL_UNREAD, itos(item->unread_msgs));
-               gtk_ctree_node_set_text(ctree, node, COL_TOTAL,  itos(item->total_msgs));
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_NEW],    itos(item->new_msgs));
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_UNREAD], itos(item->unread_msgs));
+               gtk_ctree_node_set_text(ctree, node, col_pos[F_COL_TOTAL],  itos(item->total_msgs));
        }
 
-       if (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
-           item->stype == F_TRASH) {
+       if (folder_has_parent_of_type(item, F_OUTBOX) ||
+           folder_has_parent_of_type(item, F_DRAFT) ||
+           folder_has_parent_of_type(item, F_TRASH)) {
                use_bold = use_color = FALSE;
-       } else if (item->stype == F_QUEUE) {
+       } else if (folder_has_parent_of_type(item, F_QUEUE)) {
                /* highlight queue folder if there are any messages */
                use_bold = use_color = (item->total_msgs > 0);
        } else {
                /* if unread messages exist, print with bold font */
-               use_bold = (item->unread_msgs > 0) || add_unread_mark;
+               use_bold = (item->unread_msgs > 0|| item->new_msgs > 0) 
+                               || add_unread_mark;
                /* if new messages exist, print with colored letter */
                use_color =
                        (item->new_msgs > 0) ||
                        (add_unread_mark &&
-                        folderview_have_new_children(folderview, node));       
+                        folderview_have_new_children(folderview, item));       
        }
 
        gtk_ctree_node_set_foreground(ctree, node, NULL);
 
        if (use_bold) {
-               if (item->prefs->color > 0 && !use_color) {
-                       GdkColor gdk_color;
+               GdkColor gdk_color;
 
+               if (item->prefs->color > 0 && !use_color) {
                        gtkut_convert_int_to_gdk_color(item->prefs->color, &gdk_color);
                        color_style = gtk_style_copy(bold_style);
                        color_style->fg[GTK_STATE_NORMAL] = gdk_color;
                        style = color_style;
-               } else if (use_color)
+               } else if (use_color) {
+                       gtkut_convert_int_to_gdk_color(prefs_common.color_new, &gdk_color);
+                       bold_color_style = gtk_style_copy(bold_style);
+                       bold_color_style->fg[GTK_STATE_NORMAL] = gdk_color;
                        style = bold_color_style;
-               else
+               else
                        style = bold_style;
                if (item->op_count > 0) {
                        style = bold_tgtfold_style;
                }
        } else if (use_color) {
-               style = normal_color_style;
+               GdkColor gdk_color;
+
+               gtkut_convert_int_to_gdk_color(prefs_common.color_new, &gdk_color);
+               style = gtk_style_copy(normal_color_style);
+               style->fg[GTK_STATE_NORMAL] = gdk_color;
                gtk_ctree_node_set_foreground(ctree, node,
                                              &folderview->color_new);
        } else if (item->op_count > 0) {
                style = bold_tgtfold_style;
        } else if (item->prefs->color > 0) {
                GdkColor gdk_color;
-
                gtkut_convert_int_to_gdk_color(item->prefs->color, &gdk_color);
                color_style = gtk_style_copy(normal_style);
                color_style->fg[GTK_STATE_NORMAL] = gdk_color;
@@ -1210,13 +1506,33 @@ void folderview_update_item(FolderItem *item, gboolean update_summary)
 }
 #endif
 
+void folderview_update_search_icon(FolderItem *item, gboolean matches)
+{
+       GList *list;
+       FolderView *folderview;
+       GtkCTree *ctree;
+       GtkCTreeNode *node;
+
+       g_return_if_fail(item != NULL);
+
+       for (list = folderview_list; list != NULL; list = list->next) {
+               folderview = (FolderView *)list->data;
+               ctree = GTK_CTREE(folderview->ctree);
+
+               node = gtk_ctree_find_by_row_data(ctree, NULL, item);
+               if (node) {
+                       item->search_match = matches;
+                       folderview_update_node(folderview, node);
+               }
+       }
+}
+
 gboolean folderview_update_item_claws(gpointer source, gpointer data)
 {
        FolderItemUpdateData *update_info = (FolderItemUpdateData *)source;
        FolderView *folderview = (FolderView *)data;
        GtkCTree *ctree;
        GtkCTreeNode *node;
-
        g_return_val_if_fail(update_info != NULL, TRUE);
        g_return_val_if_fail(update_info->item != NULL, TRUE);
        g_return_val_if_fail(folderview != NULL, FALSE);
@@ -1362,11 +1678,25 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        FolderViewPopup *fpopup;
        GtkItemFactory *fpopup_factory;
        GtkWidget *popup;
+       FolderItem *special_trash = NULL;
+       PrefsAccount *ac;
 
        if (!event) return FALSE;
 
-       if (event->button == 1) {
+       if (event->button == 1 || event->button == 2) {
                folderview->open_folder = TRUE;
+
+               if (event->type == GDK_2BUTTON_PRESS) {
+                       if (clist->selection) {
+                               GtkCTreeNode *node;
+
+                               node = GTK_CTREE_NODE(clist->selection->data);
+                               if (node)
+                                       gtk_ctree_toggle_expansion(
+                                               GTK_CTREE(ctree),
+                                               node);
+                       }
+               }
                return FALSE;
        }
 
@@ -1414,11 +1744,16 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        if (fpopup->set_sensitivity != NULL)
                fpopup->set_sensitivity(fpopup_factory, item);
 
-       if (item == folder->trash &&
+       if (NULL != (ac = account_find_from_item(item)))
+               special_trash = account_get_special_folder(ac, F_TRASH);
+
+       if ((item == folder->trash || item == special_trash
+            || folder_has_parent_of_type(item, F_TRASH)) &&
            gtk_item_factory_get_item(fpopup_factory, "/Empty trash...") == NULL) {
                gtk_item_factory_create_item(fpopup_factory, &folder_view_trash_popup_entries[0], folderview, 1);
                gtk_item_factory_create_item(fpopup_factory, &folder_view_trash_popup_entries[1], folderview, 1);
-       } else if (item != folder->trash) {
+       } else if (item != folder->trash && (special_trash == NULL || item != special_trash)
+               && !folder_has_parent_of_type(item, F_TRASH)) {
                gtk_item_factory_delete_entry(fpopup_factory, &folder_view_trash_popup_entries[0]);
                gtk_item_factory_delete_entry(fpopup_factory, &folder_view_trash_popup_entries[1]);
        }
@@ -1429,10 +1764,14 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        SET_SENS("/Mark all read", item->unread_msgs >= 1);
        SET_SENS("/Search folder...", item->total_msgs >= 1 && 
                 folderview->selected == folderview->opened);
-       SET_SENS("/Properties...", TRUE);
+       SET_SENS("/Properties...", item->node->parent != NULL);
        SET_SENS("/Processing...", item->node->parent != NULL);
-       if (item == folder->trash)
-               SET_SENS("/Empty trash...", folder_item_get_msg_list(item) != NULL);
+       if (item == folder->trash || item == special_trash
+           || folder_has_parent_of_type(item, F_TRASH)) {
+               GSList *msglist = folder_item_get_msg_list(item);
+               SET_SENS("/Empty trash...", msglist != NULL);
+               procmsg_msg_list_free(msglist);
+       }
 #undef SET_SENS
 
        popup = gtk_item_factory_get_widget(fpopup_factory, fpopup->path);
@@ -1504,7 +1843,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
                folderview->open_folder = FALSE;
                return;
        }
-
+       
        if (!can_select || summary_is_locked(folderview->summaryview)) {
                gtkut_ctree_set_focus_row(ctree, folderview->opened);
                gtk_ctree_select(ctree, folderview->opened);
@@ -1514,7 +1853,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
        if (!folderview->open_folder) return;
 
        item = gtk_ctree_node_get_row_data(ctree, row);
-       if (!item) return;
+       if (!item || item->no_select) return;
 
        can_select = FALSE;
 
@@ -1527,6 +1866,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
                if (olditem) {
                        /* will be null if we just moved the previously opened folder */
                        summary_save_prefs_to_folderitem(folderview->summaryview, olditem);
+                       summary_show(folderview->summaryview, NULL);
                        folder_item_close(olditem);
                }
        }
@@ -1575,7 +1915,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
 
                return;
         }
-
+       
        main_window_cursor_normal(folderview->mainwin);
 
        /* Show messages */
@@ -1627,30 +1967,15 @@ static void folderview_popup_close(GtkMenuShell *menu_shell,
 {
        if (!folderview->opened) return;
 
-       gtkut_ctree_set_focus_row(GTK_CTREE(folderview->ctree),
-                                 folderview->opened);
        gtk_ctree_select(GTK_CTREE(folderview->ctree), folderview->opened);
 }
 
 static void folderview_col_resized(GtkCList *clist, gint column, gint width,
                                   FolderView *folderview)
 {
-       switch (column) {
-       case COL_FOLDER:
-               prefs_common.folder_col_folder = width;
-               break;
-       case COL_NEW:
-               prefs_common.folder_col_new = width;
-               break;
-       case COL_UNREAD:
-               prefs_common.folder_col_unread = width;
-               break;
-       case COL_TOTAL:
-               prefs_common.folder_col_total = width;
-               break;
-       default:
-               break;
-       }
+       FolderColumnType type = folderview->col_state[column].type;
+
+       prefs_common.folder_col_size[type] = width;
 }
 
 void folderview_create_folder_node_recursive(FolderView *folderview, FolderItem *item)
@@ -1658,7 +1983,10 @@ void folderview_create_folder_node_recursive(FolderView *folderview, FolderItem
        GNode *srcnode;
 
        folderview_create_folder_node(folderview, item);
-       
+
+       if (!item || !item->folder || !item->folder->node)
+               return;
+
        srcnode = item->folder->node;   
        srcnode = g_node_find(srcnode, G_PRE_ORDER, G_TRAVERSE_ALL, item);
        srcnode = srcnode->children;
@@ -1676,15 +2004,17 @@ void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        gchar *text[N_FOLDER_COLS] = {NULL, "0", "0", "0"};
        GtkCTreeNode *node, *parent_node;
-       
+       gint *col_pos = folderview->col_pos;
+       FolderItemUpdateData hookdata;
+
        parent_node = gtk_ctree_find_by_row_data(ctree, NULL, folder_item_parent(item));
        if (parent_node == NULL)
                return;
 
        gtk_clist_freeze(GTK_CLIST(ctree));
 
-       text[COL_FOLDER] = item->name;
-       node = gtk_ctree_insert_node(ctree, parent_node, NULL, text,
+       text[col_pos[F_COL_FOLDER]] = item->name;
+       node = gtk_sctree_insert_node(ctree, parent_node, NULL, text,
                                     FOLDER_SPACING,
                                     folderxpm, folderxpmmask,
                                     folderopenxpm, folderopenxpmmask,
@@ -1693,7 +2023,12 @@ void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
        gtk_ctree_node_set_row_data(ctree, node, item);
        if (normal_style)
                gtk_ctree_node_set_row_style(ctree, node, normal_style);
-       folderview_sort_folders(folderview, folderview->selected, item->folder);
+       folderview_sort_folders(folderview, parent_node, item->folder);
+
+       hookdata.item = item;
+       hookdata.update_flags = F_ITEM_UPDATE_NAME;
+       hookdata.msg = NULL;
+       hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &hookdata);
 
        gtk_clist_thaw(GTK_CLIST(ctree));
 }
@@ -1705,17 +2040,24 @@ static void folderview_empty_trash_cb(FolderView *folderview, guint action,
        FolderItem *item;
        GSList *mlist = NULL;
        GSList *cur = NULL;
+       FolderItem *special_trash = NULL;
+       PrefsAccount *ac;
+
        if (!folderview->selected) return;
-       
        item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
-       if (item != item->folder->trash) return;
+
+       if (NULL != (ac = account_find_from_item(item)))
+               special_trash = account_get_special_folder(ac, F_TRASH);
+
+       if (item != item->folder->trash && item != special_trash
+       &&  !folder_has_parent_of_type(item, F_TRASH)) return;
        
        if (prefs_common.ask_on_clean) {
                if (alertpanel(_("Empty trash"),
-                              _("Empty all messages in trash?"),
-                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+                              _("Delete all messages in trash?"),
+                              GTK_STOCK_CANCEL, _("+_Empty trash"), NULL) != G_ALERTALTERNATE)
                        return;
        }
        
@@ -1723,9 +2065,14 @@ static void folderview_empty_trash_cb(FolderView *folderview, guint action,
        
        for (cur = mlist ; cur != NULL ; cur = cur->next) {
                MsgInfo * msginfo = (MsgInfo *) cur->data;
-               partial_mark_for_delete(msginfo);
-               procmsg_msginfo_free(msginfo);
+               if (MSG_IS_LOCKED(msginfo->flags))
+                       continue;
+               /* is it partially received? (partial_recv isn't cached) */
+               if (msginfo->total_size != 0 && 
+                   msginfo->size != (off_t)msginfo->total_size)
+                       partial_mark_for_delete(msginfo);
        }
+       procmsg_msg_list_free(mlist);
 
        folder_item_remove_all_msg(item);
 }
@@ -1748,11 +2095,10 @@ static void folderview_property_cb(FolderView *folderview, guint action,
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       if (folder_item_parent(item) == NULL && item->folder->account)
-               account_open(item->folder->account);
-       else {
-               prefs_folder_item_open(item);
-       }
+       if (folder_item_parent(item) == NULL)
+               return;
+
+       prefs_folder_item_open(item);
 }
 
 static void folderview_recollapse_nodes(FolderView *folderview, GtkCTreeNode *node)
@@ -1790,6 +2136,23 @@ void folderview_move_folder(FolderView *folderview, FolderItem *from_folder,
 
        src_node = gtk_ctree_find_by_row_data(GTK_CTREE(folderview->ctree), NULL, from_folder);
        from_parent = folder_item_parent(from_folder);
+       
+       if (prefs_common.warn_dnd) {
+               buf = g_strdup_printf(_("Do you really want to make folder '%s' a "
+                                       "sub-folder of '%s' ?"), from_folder->name,
+                                       to_folder->name);
+               status = alertpanel_full(_("Move folder"), buf,
+                                        GTK_STOCK_NO, GTK_STOCK_YES, NULL, TRUE,
+                                        NULL, ALERT_QUESTION, G_ALERTDEFAULT);
+               g_free(buf);
+
+               if (status != G_ALERTALTERNATE
+                && status != (G_ALERTALTERNATE | G_ALERTDISABLE))
+                       return;
+               if (status & G_ALERTDISABLE)
+                       prefs_common.warn_dnd = FALSE;
+       }
+
        buf = g_strdup_printf(_("Moving %s to %s..."), from_folder->name, to_folder->name);
        STATUSBAR_PUSH(folderview->mainwin, buf);
        g_free(buf);
@@ -1810,7 +2173,7 @@ void folderview_move_folder(FolderView *folderview, FolderItem *from_folder,
 
                folderview_sort_folders(folderview, 
                        gtk_ctree_find_by_row_data(GTK_CTREE(folderview->ctree), 
-                               NULL, folder_item_parent(new_folder)), new_folder->folder);
+                               NULL, to_folder), new_folder->folder);
                folderview_select(folderview, new_folder);
        } else {
                statusbar_verbosity_set(FALSE);         
@@ -1855,6 +2218,7 @@ static void folderview_processing_cb(FolderView *folderview, guint action,
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
+       gchar *id, *title;
 
        if (!folderview->selected) return;
 
@@ -1862,8 +2226,12 @@ static void folderview_processing_cb(FolderView *folderview, guint action,
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       prefs_filtering_open(&item->prefs->processing,
-                            _("Processing configuration"), NULL, NULL);
+       id = folder_item_get_identifier(item);
+       title = g_strdup_printf (_("Processing configuration for folder %s"), id);
+       g_free (id);
+
+       prefs_filtering_open(&item->prefs->processing, title, NULL, NULL);
+       g_free (title);
 }
 
 void folderview_set_target_folder_color(gint color_op) 
@@ -1883,10 +2251,63 @@ void folderview_set_target_folder_color(gint color_op)
        }
 }
 
+static gchar *last_font = NULL;
 void folderview_reflect_prefs_pixmap_theme(FolderView *folderview)
 {
-       folderview_init(folderview);
+       /* force reinit */
+       if (last_font) 
+               g_free(last_font);
+       last_font = NULL;
+       
+}
+
+void folderview_reflect_prefs(void)
+{
+       gboolean update_font = TRUE;
+       FolderView *folderview = mainwindow_get_mainwindow()->folderview;
+       FolderItem *item = folderview_get_selected_item(folderview);
+       GtkAdjustment *pos = gtk_scrolled_window_get_vadjustment(
+                               GTK_SCROLLED_WINDOW(folderview->scrolledwin));
+       gint height = pos->value;
+
+       if (last_font && !strcmp(last_font, NORMAL_FONT))
+               update_font = FALSE;
+
+       if (last_font)
+               g_free(last_font);
+       
+       last_font = g_strdup(NORMAL_FONT);
+
+       if (update_font) {              
+               normal_style = normal_color_style = bold_style = 
+                       bold_color_style = bold_tgtfold_style = NULL;
+
+               folderview_init(folderview);
+       }
+       gtk_clist_freeze(GTK_CLIST(folderview->ctree));
+       folderview_column_set_titles(folderview);
        folderview_set_all();
+
+       g_signal_handlers_block_by_func
+               (G_OBJECT(folderview->ctree),
+                G_CALLBACK(folderview_selected), folderview);
+
+       if (item) {
+               GtkCTreeNode *node = gtk_ctree_find_by_row_data(
+                       GTK_CTREE(folderview->ctree), NULL, item);
+
+               folderview_select(folderview, item);
+               folderview->selected = node;
+       }
+
+       g_signal_handlers_unblock_by_func
+               (G_OBJECT(folderview->ctree),
+                G_CALLBACK(folderview_selected), folderview);
+
+       pos = gtk_scrolled_window_get_vadjustment(
+                               GTK_SCROLLED_WINDOW(folderview->scrolledwin));
+       gtk_adjustment_set_value(pos, height);
+       gtk_clist_thaw(GTK_CLIST(folderview->ctree));
 }
 
 static void drag_state_stop(FolderView *folderview)
@@ -1953,20 +2374,23 @@ static void folderview_drag_data_get(GtkWidget        *widget,
        FolderItem *item;
        GList *cur;
        gchar *source = NULL;
-
-       for (cur = GTK_CLIST(folderview->ctree)->selection;
-            cur != NULL; cur = cur->next) {
-               item = gtk_ctree_node_get_row_data
-                       (GTK_CTREE(folderview->ctree), 
-                        GTK_CTREE_NODE(cur->data));
-               if (item) {
-                       source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item));
-                       gtk_selection_data_set(selection_data,
-                                              selection_data->target, 8,
-                                              source, strlen(source));
-                       break;
-               } else
-                       return;
+       if (info == TARGET_DUMMY) {
+               for (cur = GTK_CLIST(folderview->ctree)->selection;
+                    cur != NULL; cur = cur->next) {
+                       item = gtk_ctree_node_get_row_data
+                               (GTK_CTREE(folderview->ctree), 
+                                GTK_CTREE_NODE(cur->data));
+                       if (item) {
+                               source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item));
+                               gtk_selection_data_set(selection_data,
+                                                      selection_data->target, 8,
+                                                      source, strlen(source));
+                               break;
+                       } else
+                               return;
+               }
+       } else {
+               g_warning("unknown info %d\n", info);
        }
 }
 
@@ -2006,14 +2430,14 @@ static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                                          FolderView     *folderview)
 {
        gint row, column;
-       FolderItem *item, *src_item = NULL;
+       FolderItem *item = NULL, *src_item = NULL;
        GtkCTreeNode *node = NULL;
        gboolean acceptable = FALSE;
-       gint height = folderview->ctree->allocation.height;
-       gint total_height = folderview->ctree->requisition.height;
        GtkAdjustment *pos = gtk_scrolled_window_get_vadjustment(
                                GTK_SCROLLED_WINDOW(folderview->scrolledwin));
-       gfloat vpos = pos->value;
+       int height = (int)pos->page_size;
+       int total_height = (int)pos->upper;
+       int vpos = (int) pos->value;
 
        if (gtk_clist_get_selection_info
                (GTK_CLIST(widget), x - 24, y - 24, &row, &column)) {
@@ -2022,7 +2446,7 @@ static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                if (y > height - 24 && height + vpos < total_height)
                        gtk_adjustment_set_value(pos, (vpos+5 > height ? height : vpos+5));
 
-               if (y < 24 && y > 0)
+               if (y < 48 && y > 0)
                        gtk_adjustment_set_value(pos, (vpos-5 < 0 ? 0 : vpos-5));
 
                node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
@@ -2045,6 +2469,13 @@ static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                            FOLDER_CLASS(item->folder)->copy_msg != NULL &&
                            FOLDER_CLASS(item->folder)->create_folder != NULL)
                                acceptable = TRUE;
+               } else {
+                       /* comes from another app */
+                       /* we are adding messages, so only accept folder items that are 
+                          no root items and can copy messages */
+                       if (item && item->folder && folder_item_parent(item) != NULL
+                           && FOLDER_CLASS(item->folder)->add_msg != NULL)
+                               acceptable = TRUE;
                }
        }
 
@@ -2063,7 +2494,8 @@ static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                                        (context->actions == GDK_ACTION_COPY ?
                                        GDK_ACTION_COPY : GDK_ACTION_MOVE) , time);
        } else {
-               gtk_ctree_select(GTK_CTREE(widget), folderview->opened);
+               if (folderview->opened)
+                       gtk_ctree_select(GTK_CTREE(widget), folderview->opened);
                gdk_drag_status(context, 0, time);
        }
 
@@ -2079,6 +2511,50 @@ static void folderview_drag_leave_cb(GtkWidget      *widget,
        gtk_ctree_select(GTK_CTREE(widget), folderview->opened);
 }
 
+static void free_info (gpointer stuff, gpointer data)
+{
+       g_free(stuff);
+}
+
+void folderview_finish_dnd(const gchar *data, GdkDragContext *drag_context,
+                          guint time, FolderItem *item)
+{
+       GList *list, *tmp;
+       GSList *msglist = NULL;
+       list = uri_list_extract_filenames(data);
+       if (!(item && item->folder && folder_item_parent(item) != NULL
+                   && FOLDER_CLASS(item->folder)->add_msg != NULL))
+       {
+               gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
+               return;
+       }       
+       if (!list) {
+               gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
+               return;
+       }
+       for (tmp = list; tmp != NULL; tmp = tmp->next) {
+               MsgFileInfo *info = NULL;
+
+               if (file_is_email((gchar *)tmp->data)) {
+                       info = g_new0(MsgFileInfo, 1);
+                       info->msginfo = NULL;
+                       info->file = (gchar *)tmp->data;
+                       msglist = g_slist_prepend(msglist, info);
+               }
+       }
+       if (msglist) {
+               msglist = g_slist_reverse(msglist);
+               folder_item_add_msgs(item, msglist, FALSE);
+               g_slist_foreach(msglist, free_info, NULL);
+               g_slist_free(msglist);
+               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+       } else {
+               gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
+       }
+       list_free_strings(list);
+       g_list_free(list);
+}
+
 static void folderview_drag_received_cb(GtkWidget        *widget,
                                        GdkDragContext   *drag_context,
                                        gint              x,
@@ -2089,66 +2565,93 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                                        FolderView       *folderview)
 {
        gint row, column;
-       FolderItem *item, *src_item;
+       FolderItem *item = NULL, *src_item;
        GtkCTreeNode *node;
 
-       drag_state_stop(folderview);
-       if ((void *)strstr(data->data, "FROM_OTHER_FOLDER") != (void *)data->data) {
-               /* comes from summaryview */
+       if (info == TARGET_DUMMY) {
+               drag_state_stop(folderview);
+               if ((void *)strstr(data->data, "FROM_OTHER_FOLDER") != (void *)data->data) {
+                       /* comes from summaryview */
+                       if (gtk_clist_get_selection_info
+                               (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0)
+                               return;
+
+                       node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
+                       item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
+                       src_item = folderview->summaryview->folder_item;
+
+                       /* re-check (due to acceptable possibly set for folder moves */
+                       if (!(item && item->folder && item->path && !item->no_select && 
+                             src_item && src_item != item && FOLDER_CLASS(item->folder)->copy_msg != NULL)) {
+                               return;
+                       }
+                       if (item && src_item) {
+                               switch (drag_context->action) {
+                               case GDK_ACTION_COPY:
+                                       summary_copy_selected_to(folderview->summaryview, item);
+                                       gtk_drag_finish(drag_context, TRUE, FALSE, time);
+                                       break;
+                               case GDK_ACTION_MOVE:
+                               case GDK_ACTION_DEFAULT:
+                               default:
+                                       if (FOLDER_CLASS(src_item->folder)->remove_msg == NULL)
+                                               summary_copy_selected_to(folderview->summaryview, item);
+                                       else
+                                               summary_move_selected_to(folderview->summaryview, item);
+                                       gtk_drag_finish(drag_context, TRUE, TRUE, time);
+                               }
+                       } else
+                               gtk_drag_finish(drag_context, FALSE, FALSE, time);
+               } else {
+                       /* comes from folderview */
+                       char *source;
+                       gboolean folder_is_normal = TRUE;
+
+                       source = data->data + 17;
+                       if (gtk_clist_get_selection_info
+                           (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0
+                           || *source == 0) {
+                               gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
+                               return;
+                       }
+                       node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
+                       item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
+                       src_item = folder_find_item_from_identifier(source);
+
+                       folder_is_normal = 
+                               src_item != NULL &&
+                               src_item->stype == F_NORMAL &&
+                               !folder_has_parent_of_type(src_item, F_OUTBOX) &&
+                               !folder_has_parent_of_type(src_item, F_DRAFT) &&
+                               !folder_has_parent_of_type(src_item, F_QUEUE) &&
+                               !folder_has_parent_of_type(src_item, F_TRASH);
+                       if (!item || item->no_select || !src_item 
+                       ||  !folder_is_normal) {
+                               gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
+                               return;
+                       }
+
+                       folderview_move_folder(folderview, src_item, item);
+                       gtk_drag_finish(drag_context, TRUE, TRUE, time);
+               }
+               folderview->nodes_to_recollapse = NULL;
+       } else if (info == TARGET_MAIL_URI_LIST) {
                if (gtk_clist_get_selection_info
                        (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0)
                        return;
 
                node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
-               item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
-               src_item = folderview->summaryview->folder_item;
-               
-               /* re-check (due to acceptable possibly set for folder moves */
-               if (!(item && item->folder && item->path &&
-                     src_item && src_item != item && FOLDER_CLASS(item->folder)->copy_msg != NULL)) {
-                       return;
-               }
-               if (item && src_item) {
-                       switch (drag_context->action) {
-                       case GDK_ACTION_COPY:
-                               summary_copy_selected_to(folderview->summaryview, item);
-                               gtk_drag_finish(drag_context, TRUE, FALSE, time);
-                               break;
-                       case GDK_ACTION_MOVE:
-                       case GDK_ACTION_DEFAULT:
-                       default:
-                               if (FOLDER_CLASS(src_item->folder)->remove_msg == NULL)
-                                       summary_copy_selected_to(folderview->summaryview, item);
-                               else
-                                       summary_move_selected_to(folderview->summaryview, item);
-                               gtk_drag_finish(drag_context, TRUE, TRUE, time);
-                       }
-               } else
-                       gtk_drag_finish(drag_context, FALSE, FALSE, time);
-       } else {
-               /* comes from folderview */
-               char *source;
-               
-               source = data->data + 17;
-               if (gtk_clist_get_selection_info
-                   (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0
-                   || *source == 0) {
+               if (!node) {
                        gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
                        return;
                }
-               node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
                item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
-               src_item = folder_find_item_from_identifier(source);
-
-               if (!item || !src_item || src_item->stype != F_NORMAL) {
+               if (!item) {
                        gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
                        return;
                }
-
-               folderview_move_folder(folderview, src_item, item);
-               gtk_drag_finish(drag_context, TRUE, TRUE, time);
+               folderview_finish_dnd(data->data, drag_context, time, item);
        }
-       folderview->nodes_to_recollapse = NULL;
 }
 
 static void folderview_drag_end_cb(GtkWidget       *widget,