0.8.11claws7
[claws.git] / src / account.c
index 0bf8a40ee489a2a7bf591709065acb1034e77354..68304c8b5d386a1addda5d1aab9d7d857f5af0f4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto
  *
  * 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
 #include "folderview.h"
 #include "folder.h"
 #include "account.h"
-#include "prefs.h"
+#include "prefs_gtk.h"
 #include "prefs_account.h"
+#include "prefs_folder_item.h"
 #include "compose.h"
 #include "manage_window.h"
+#include "stock_pixmap.h"
 #include "inc.h"
 #include "gtkutils.h"
 #include "utils.h"
 #include "alertpanel.h"
-
-#include "pixmaps/mark.xpm"
+#include "procheader.h"
 
 typedef enum
 {
@@ -71,6 +72,10 @@ static struct EditAccount {
 
 static GdkPixmap *markxpm;
 static GdkBitmap *markxpmmask;
+static GdkPixmap *checkboxonxpm;
+static GdkPixmap *checkboxonxpmmask;
+static GdkPixmap *checkboxoffxpm;
+static GdkPixmap *checkboxoffxpmmask;
 
 static void account_edit_create                (void);
 
@@ -82,8 +87,6 @@ static void account_down              (void);
 
 static void account_set_default                (void);
 
-static void account_set_recv_at_get_all        (void);
-
 static void account_edit_close         (void);
 static gint account_delete_event       (GtkWidget      *widget,
                                         GdkEventAny    *event,
@@ -93,6 +96,9 @@ static void account_selected          (GtkCList       *clist,
                                         gint            column,
                                         GdkEvent       *event,
                                         gpointer        data);
+static void account_row_moved          (GtkCList       *clist,
+                                        gint            source_row,
+                                        gint            dest_row);
 static void account_key_pressed                (GtkWidget      *widget,
                                         GdkEventKey    *event,
                                         gpointer        data);
@@ -111,10 +117,10 @@ void account_read_config_all(void)
        gchar buf[PREFSBUFSIZE];
        PrefsAccount *ac_prefs;
 
-       debug_print(_("Reading all config for each account...\n"));
+       debug_print("Reading all config for each account...\n");
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
-       if ((fp = fopen(rcpath, "r")) == NULL) {
+       if ((fp = fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
                g_free(rcpath);
                return;
@@ -126,7 +132,7 @@ void account_read_config_all(void)
                        strretchomp(buf);
                        memmove(buf, buf + 1, strlen(buf));
                        buf[strlen(buf) - 1] = '\0';
-                       debug_print(_("Found label: %s\n"), buf);
+                       debug_print("Found label: %s\n", buf);
                        ac_label_list = g_slist_append(ac_label_list,
                                                       g_strdup(buf));
                }
@@ -136,7 +142,7 @@ void account_read_config_all(void)
        /* read config data from file */
        cur_account = NULL;
        for (cur = ac_label_list; cur != NULL; cur = cur->next) {
-               ac_prefs = g_new0(PrefsAccount, 1);
+               ac_prefs = prefs_account_new();
                prefs_account_read_config(ac_prefs, (gchar *)cur->data);
                account_list = g_list_append(account_list, ac_prefs);
                if (ac_prefs->is_default)
@@ -164,12 +170,42 @@ void account_save_config_all(void)
        prefs_account_save_config_all(account_list);
 }
 
+/*
+ * account_find_all_from_address:
+ * @ac_list: initial list of accounts. NULL to create a new one.
+ * Accounts found in the @address will be appended to this list.
+ * @address: Email address string.
+ *
+ * Find all the mail (not news) accounts within the specified address.
+ *
+ * Return value: the original accounts list with the found accounts appended.
+ */
+GList *account_find_all_from_address(GList *ac_list, const gchar *address)
+{
+       GList *cur;
+       PrefsAccount *ac;
+
+       if (address == NULL)
+               return ac_list;
+
+       for (cur = account_list; cur != NULL; cur = cur->next) {
+               ac = (PrefsAccount *)cur->data;
+               if (ac->protocol != A_NNTP && ac->address &&
+                   strcasestr(address, ac->address) != NULL)
+                       ac_list = g_list_append(ac_list, ac);
+       }
+       return ac_list;
+}
+       
 PrefsAccount *account_find_from_smtp_server(const gchar *address,
                                            const gchar *smtp_server)
 {
        GList *cur;
        PrefsAccount *ac;
 
+       g_return_val_if_fail(address != NULL, NULL);
+       g_return_val_if_fail(smtp_server != NULL, NULL);
+
        for (cur = account_list; cur != NULL; cur = cur->next) {
                ac = (PrefsAccount *)cur->data;
                if (!strcmp2(address, ac->address) &&
@@ -193,9 +229,12 @@ PrefsAccount *account_find_from_address(const gchar *address)
        GList *cur;
        PrefsAccount *ac;
 
+       g_return_val_if_fail(address != NULL, NULL);
+
        for (cur = account_list; cur != NULL; cur = cur->next) {
                ac = (PrefsAccount *)cur->data;
-               if (ac->protocol != A_NNTP && !strcmp2(address, ac->address))
+               if (ac->protocol != A_NNTP && ac->address &&
+                   strcasestr(address, ac->address) != NULL)
                        return ac;
        }
 
@@ -216,6 +255,29 @@ PrefsAccount *account_find_from_id(gint id)
        return NULL;
 }
 
+PrefsAccount *account_find_from_item(FolderItem *item)
+{
+       PrefsAccount *ac;
+
+       g_return_val_if_fail(item != NULL, NULL);
+
+       ac = item->account;
+       if (!ac) {
+               FolderItem *cur_item = item->parent;
+               while (cur_item != NULL) {
+                       if (cur_item->account && cur_item->apply_sub) {
+                               ac = cur_item->account;
+                               break;
+                       }                               
+                       cur_item = cur_item->parent;
+               }
+       }
+       if (!ac)
+               ac = item->folder->account;
+
+       return ac;
+}
+
 void account_set_menu(void)
 {
        main_window_set_account_menu(account_list);
@@ -237,16 +299,16 @@ GList *account_get_list(void)
 
 void account_edit_open(void)
 {
-       inc_autocheck_timer_remove();
+       inc_lock();
 
        if (compose_get_compose_list()) {
                alertpanel_notice(_("Some composing windows are open.\n"
                                    "Please close all the composing windows before editing the accounts."));
-               inc_autocheck_timer_set();
+               inc_unlock();
                return;
        }
 
-       debug_print(_("Opening account edit window...\n"));
+       debug_print("Opening account edit window...\n");
 
        if (!edit_account.window)
                account_edit_create();
@@ -265,7 +327,6 @@ void account_add(void)
        PrefsAccount *ac_prefs;
 
        ac_prefs = prefs_account_open(NULL);
-       inc_autocheck_timer_remove();
 
        if (!ac_prefs) return;
 
@@ -274,19 +335,16 @@ void account_add(void)
        if (ac_prefs->is_default)
                account_set_as_default(ac_prefs);
 
-       if (ac_prefs->recv_at_getall)
-               account_set_as_recv_at_get_all(ac_prefs);
-
        account_clist_set();
 
        if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
                Folder *folder;
 
                if (ac_prefs->protocol == A_IMAP4) {
-                       folder = folder_new(F_IMAP, ac_prefs->account_name,
+                       folder = folder_new(folder_get_class_from_string("imap"), ac_prefs->account_name,
                                            ac_prefs->recv_server);
                } else {
-                       folder = folder_new(F_NEWS, ac_prefs->account_name,
+                       folder = folder_new(folder_get_class_from_string("news"), ac_prefs->account_name,
                                            ac_prefs->nntp_server);
                }
 
@@ -294,9 +352,36 @@ void account_add(void)
                ac_prefs->folder = REMOTE_FOLDER(folder);
                folder_add(folder);
                if (ac_prefs->protocol == A_IMAP4)
-                       folder->create_tree(folder);
+                       folder->class->create_tree(folder);
+               folderview_set_all();
+       }
+}
+
+void account_open(PrefsAccount *ac_prefs)
+{
+       gboolean prev_default;
+       gchar *ac_name;
+
+       g_return_if_fail(ac_prefs != NULL);
+
+       prev_default = ac_prefs->is_default;
+       Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
+                 return);
+
+       prefs_account_open(ac_prefs);
+
+       if (!prev_default && ac_prefs->is_default)
+               account_set_as_default(ac_prefs);
+
+       if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) {
+               folder_set_name(FOLDER(ac_prefs->folder),
+                               ac_prefs->account_name);
                folderview_set_all();
        }
+
+       account_save_config_all();
+       account_set_menu();
+       main_window_reflect_prefs_all();
 }
 
 void account_set_as_default(PrefsAccount *ac_prefs)
@@ -327,24 +412,6 @@ PrefsAccount *account_get_default(void)
        return NULL;
 }
 
-void account_set_as_recv_at_get_all(PrefsAccount *ac_prefs)
-{
-       PrefsAccount *ap;
-       GList *cur;
-
-       for (cur = account_list; cur != NULL; cur = cur->next) {
-               ap = (PrefsAccount *)cur->data;
-               if (ap->account_name == ac_prefs->account_name) {
-                       if (ap->recv_at_getall == 0)
-                               ap->recv_at_getall = 1;
-                       else
-                               ap->recv_at_getall = 0;
-               }
-        }
-
-}
-
-
 void account_set_missing_folder(void)
 {
        PrefsAccount *ap;
@@ -357,10 +424,10 @@ void account_set_missing_folder(void)
                        Folder *folder;
 
                        if (ap->protocol == A_IMAP4) {
-                               folder = folder_new(F_IMAP, ap->account_name,
+                               folder = folder_new(folder_get_class_from_string("imap"), ap->account_name,
                                                    ap->recv_server);
                        } else {
-                               folder = folder_new(F_NEWS, ap->account_name,
+                               folder = folder_new(folder_get_class_from_string("news"), ap->account_name,
                                                    ap->nntp_server);
                        }
 
@@ -368,15 +435,80 @@ void account_set_missing_folder(void)
                        ap->folder = REMOTE_FOLDER(folder);
                        folder_add(folder);
                        if (ap->protocol == A_IMAP4)
-                               folder->create_tree(folder);
+                               folder->class->create_tree(folder);
+               }
+       }
+}
+
+FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
+                                      SpecialFolderItemType type)
+{
+       FolderItem *item = NULL;
+
+       g_return_val_if_fail(ac_prefs != NULL, NULL);
+
+       switch (type) {
+       case F_INBOX:
+               if (ac_prefs->folder)
+                       item = FOLDER(ac_prefs->folder)->inbox;
+               if (!item)
+                       item = folder_get_default_inbox();
+               break;
+       case F_OUTBOX:
+               if (ac_prefs->set_sent_folder && ac_prefs->sent_folder) {
+                       item = folder_find_item_from_identifier
+                               (ac_prefs->sent_folder);
+               }
+               if (!item) {
+                       if (ac_prefs->folder)
+                               item = FOLDER(ac_prefs->folder)->outbox;
+                       if (!item)
+                               item = folder_get_default_outbox();
+               }
+               break;
+       case F_DRAFT:
+               if (ac_prefs->set_draft_folder && ac_prefs->draft_folder) {
+                       item = folder_find_item_from_identifier
+                               (ac_prefs->draft_folder);
                }
+               if (!item) {
+                       if (ac_prefs->folder)
+                               item = FOLDER(ac_prefs->folder)->draft;
+                       if (!item)
+                               item = folder_get_default_draft();
+               }
+               break;
+       case F_QUEUE:
+               if (ac_prefs->folder)
+                       item = FOLDER(ac_prefs->folder)->queue;
+               if (!item)
+                       item = folder_get_default_queue();
+               break;
+       case F_TRASH:
+               if (ac_prefs->set_trash_folder && ac_prefs->trash_folder) {
+                       item = folder_find_item_from_identifier
+                               (ac_prefs->trash_folder);
+               }
+               if (!item) {
+                       if (ac_prefs->folder)
+                               item = FOLDER(ac_prefs->folder)->trash;
+                       if (!item)
+                               item = folder_get_default_trash();
+               }
+               break;
+       default:
+               break;
        }
+
+       return item;
 }
 
 void account_destroy(PrefsAccount *ac_prefs)
 {
        g_return_if_fail(ac_prefs != NULL);
 
+       folder_unref_account_all(ac_prefs);
+
        prefs_account_free(ac_prefs);
        account_list = g_list_remove(account_list, ac_prefs);
 
@@ -396,6 +528,7 @@ static void account_edit_create(void)
 {
        GtkWidget *window;
        GtkWidget *vbox;
+       GtkWidget *label;
        GtkWidget *hbox;
        GtkWidget *scrolledwin;
        GtkWidget *clist;
@@ -411,12 +544,10 @@ static void account_edit_create(void)
 
        GtkWidget *default_btn;
 
-        GtkWidget *recvatgetall_btn;
-
        GtkWidget *hbbox;
        GtkWidget *close_btn;
 
-       debug_print(_("Creating account edit window...\n"));
+       debug_print("Creating account edit window...\n");
 
        window = gtk_window_new (GTK_WINDOW_DIALOG);
        gtk_widget_set_usize (window, 500, 320);
@@ -427,16 +558,24 @@ static void account_edit_create(void)
                            GTK_SIGNAL_FUNC (account_delete_event), NULL);
        gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
                            GTK_SIGNAL_FUNC (account_key_pressed), NULL);
-       gtk_signal_connect (GTK_OBJECT (window), "focus_in_event",
-                           GTK_SIGNAL_FUNC (manage_window_focus_in), NULL);
-       gtk_signal_connect (GTK_OBJECT (window), "focus_out_event",
-                           GTK_SIGNAL_FUNC (manage_window_focus_out), NULL);
+       MANAGE_WINDOW_SIGNALS_CONNECT (window);
        gtk_widget_realize(window);
 
-       vbox = gtk_vbox_new (FALSE, 12);
+       vbox = gtk_vbox_new (FALSE, 10);
        gtk_widget_show (vbox);
        gtk_container_add (GTK_CONTAINER (window), vbox);
 
+       hbox = gtk_hbox_new (FALSE, 0);
+       gtk_widget_show (hbox);
+       gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+       label = gtk_label_new
+               (_("New messages will be checked in this order. Check the boxes\n"
+                  "on the `G' column to enable message retrieval by `Get all'."));
+       gtk_widget_show (label);
+       gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
+       gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+
        hbox = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox);
        gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
@@ -459,10 +598,14 @@ static void account_edit_create(void)
        gtk_widget_show (clist);
        gtk_container_add (GTK_CONTAINER (scrolledwin), clist);
        gtk_clist_set_column_width (GTK_CLIST(clist), COL_DEFAULT , 10);
-       gtk_clist_set_column_width (GTK_CLIST(clist), COL_GETALL  , 10);
+       gtk_clist_set_column_width (GTK_CLIST(clist), COL_GETALL  , 11);
        gtk_clist_set_column_width (GTK_CLIST(clist), COL_NAME    , 100);
-       gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 70);
+       gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 100);
        gtk_clist_set_column_width (GTK_CLIST(clist), COL_SERVER  , 100);
+       gtk_clist_set_column_justification (GTK_CLIST(clist), COL_DEFAULT,
+                                           GTK_JUSTIFY_CENTER);
+       gtk_clist_set_column_justification (GTK_CLIST(clist), COL_GETALL,
+                                           GTK_JUSTIFY_CENTER);
        gtk_clist_set_selection_mode (GTK_CLIST(clist), GTK_SELECTION_BROWSE);
 
        for (i = 0; i < N_EDIT_ACCOUNT_COLS; i++)
@@ -471,6 +614,8 @@ static void account_edit_create(void)
 
        gtk_signal_connect (GTK_OBJECT (clist), "select_row",
                            GTK_SIGNAL_FUNC (account_selected), NULL);
+       gtk_signal_connect_after (GTK_OBJECT (clist), "row_move",
+                                 GTK_SIGNAL_FUNC (account_row_moved), NULL);
 
        vbox2 = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox2);
@@ -520,13 +665,7 @@ static void account_edit_create(void)
        gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
                            GTK_SIGNAL_FUNC (account_set_default), NULL);
 
-       recvatgetall_btn = gtk_button_new_with_label (_(" Enable/Disable 'Receive at Get all' "));
-       gtk_widget_show (recvatgetall_btn);
-       gtk_box_pack_start (GTK_BOX (vbox2), recvatgetall_btn, TRUE, FALSE, 0);
-       gtk_signal_connect (GTK_OBJECT(recvatgetall_btn), "clicked",
-                           GTK_SIGNAL_FUNC (account_set_recv_at_get_all), NULL);
-
-        gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
+       gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
                                NULL, NULL, NULL, NULL);
        gtk_widget_show(hbbox);
        gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
@@ -536,7 +675,11 @@ static void account_edit_create(void)
                            GTK_SIGNAL_FUNC (account_edit_close),
                            NULL);
 
-       PIXMAP_CREATE(clist, markxpm, markxpmmask, mark_xpm);
+       stock_pixmap_gdk(clist, STOCK_PIXMAP_MARK, &markxpm, &markxpmmask);
+       stock_pixmap_gdk(clist, STOCK_PIXMAP_CHECKBOX_ON,
+                        &checkboxonxpm, &checkboxonxpmmask);
+       stock_pixmap_gdk(clist, STOCK_PIXMAP_CHECKBOX_OFF,
+                        &checkboxoffxpm, &checkboxoffxpmmask);
 
        edit_account.window    = window;
        edit_account.clist     = clist;
@@ -548,30 +691,36 @@ static void account_edit_prefs(void)
        GtkCList *clist = GTK_CLIST(edit_account.clist);
        PrefsAccount *ac_prefs;
        gint row;
-       gboolean prev_default;
-       gchar *ac_name;
 
        if (!clist->selection) return;
 
        row = GPOINTER_TO_INT(clist->selection->data);
        ac_prefs = gtk_clist_get_row_data(clist, row);
-       prev_default = ac_prefs->is_default;
-       Xstrdup_a(ac_name, ac_prefs->account_name, return);
+       account_open(ac_prefs);
+       
+       account_clist_set();
+}
 
-       prefs_account_open(ac_prefs);
-       inc_autocheck_timer_remove();
+static gboolean account_delete_references_func(GNode *node, gpointer data)
+{
+       FolderItem *item;
+       gint account;
 
-       if (!prev_default && ac_prefs->is_default)
-               account_set_as_default(ac_prefs);
+       g_return_val_if_fail(node->data != NULL, FALSE);
 
-       if ((ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) &&
-           ac_prefs->folder && strcmp(ac_name, ac_prefs->account_name) != 0) {
-               folder_set_name(FOLDER(ac_prefs->folder),
-                               ac_prefs->account_name);
-               folderview_update_all();
-       }
+       item = FOLDER_ITEM(node->data);
+       account = GPOINTER_TO_INT(data);
 
-       account_clist_set();
+       if(!item->prefs) /* && item->prefs->stype == F_NORMAL */
+               return FALSE;
+       if(item->prefs->default_account != account)
+               return FALSE;
+       
+       item->prefs->enable_default_account = FALSE;
+       item->prefs->default_account = 0;
+       prefs_folder_item_save_config(item);
+
+       return FALSE;
 }
 
 static void account_delete(void)
@@ -579,7 +728,9 @@ static void account_delete(void)
        GtkCList *clist = GTK_CLIST(edit_account.clist);
        PrefsAccount *ac_prefs;
        gint row;
-
+       GList *list;
+       Folder *folder;
+       
        if (!clist->selection) return;
 
        if (alertpanel(_("Delete account"),
@@ -591,10 +742,21 @@ static void account_delete(void)
        ac_prefs = gtk_clist_get_row_data(clist, row);
        if (ac_prefs->folder) {
                folder_destroy(FOLDER(ac_prefs->folder));
-               folderview_update_all();
+               folderview_set_all();
        }
        account_destroy(ac_prefs);
        account_clist_set();
+
+       debug_print("Removing deleted account references for all the folders...\n");
+       list = folder_get_list();
+       for (; list != NULL; list = list->next) {
+               folder = FOLDER(list->data);
+               if (folder->node)  /* && folder->type == F_? */
+                       g_node_traverse(folder->node, G_PRE_ORDER,
+                               G_TRAVERSE_ALL, -1,
+                               account_delete_references_func,
+                               GINT_TO_POINTER(ac_prefs->account_id));
+       }
 }
 
 static void account_up(void)
@@ -605,10 +767,8 @@ static void account_up(void)
        if (!clist->selection) return;
 
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row > 0) {
+       if (row > 0)
                gtk_clist_row_move(clist, row, row - 1);
-               account_list_set();
-       }
 }
 
 static void account_down(void)
@@ -619,10 +779,8 @@ static void account_down(void)
        if (!clist->selection) return;
 
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row < clist->rows - 1) {
+       if (row < clist->rows - 1)
                gtk_clist_row_move(clist, row, row + 1);
-               account_list_set();
-       }
 }
 
 static void account_set_default(void)
@@ -643,23 +801,6 @@ static void account_set_default(void)
        main_window_reflect_prefs_all();
 }
 
-static void account_set_recv_at_get_all(void)
-{
-       GtkCList *clist = GTK_CLIST(edit_account.clist);
-       gint row;
-       PrefsAccount *ac_prefs;
-
-       if (!clist->selection) return;
-
-       row = GPOINTER_TO_INT(clist->selection->data);
-       ac_prefs = gtk_clist_get_row_data(clist, row);
-
-       if ((ac_prefs->protocol != A_POP3) && (ac_prefs->protocol != A_APOP)) return;
-       
-       account_set_as_recv_at_get_all(ac_prefs);
-       account_clist_set();
-}
-
 static void account_edit_close(void)
 {
        account_list_set();
@@ -676,7 +817,7 @@ static void account_edit_close(void)
 
        gtk_widget_hide(edit_account.window);
 
-       inc_autocheck_timer_set();
+       inc_unlock();
 }
 
 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
@@ -691,6 +832,25 @@ static void account_selected(GtkCList *clist, gint row, gint column,
 {
        if (event && event->type == GDK_2BUTTON_PRESS)
                account_edit_prefs();
+
+       if (column == COL_GETALL) {
+               PrefsAccount *ac;
+
+               ac = gtk_clist_get_row_data(clist, row);
+               if (ac->protocol == A_POP3 || ac->protocol == A_APOP ||
+                   ac->protocol == A_IMAP4 || ac->protocol == A_NNTP ||
+                   ac->protocol == A_LOCAL) {
+                       ac->recv_at_getall ^= TRUE;
+                       account_clist_set_row(ac, row);
+               }
+       }
+}
+
+static void account_row_moved(GtkCList *clist, gint source_row, gint dest_row)
+{
+       account_list_set();
+       if (gtk_clist_row_is_visible(clist, dest_row) != GTK_VISIBILITY_FULL)
+               gtk_clist_moveto(clist, dest_row, -1, 0.5, 0.0);
 }
 
 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
@@ -705,22 +865,32 @@ static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
 {
        GtkCList *clist = GTK_CLIST(edit_account.clist);
        gchar *text[N_EDIT_ACCOUNT_COLS];
+       gboolean has_getallbox;
+       gboolean getall;
 
-       text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
-       text[COL_GETALL] = (ac_prefs->protocol == A_POP3 ||
-                           ac_prefs->protocol == A_APOP) &&
-                           ac_prefs->recv_at_getall ? "*" : "";
-       text[COL_NAME] = ac_prefs->account_name;
-#if USE_SSL
+       text[COL_DEFAULT] = "";
+       text[COL_GETALL]  = "";
+       text[COL_NAME]    = ac_prefs->account_name;
+#if USE_OPENSSL
        text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3 ?
-                            (ac_prefs->ssl_pop ? "POP3 (SSL)" : "POP3") :
+                            (ac_prefs->ssl_pop == SSL_TUNNEL ?
+                             "POP3 (SSL)" :
+                             ac_prefs->ssl_pop == SSL_STARTTLS ?
+                             "POP3 (TLS)" : "POP3") :
                             ac_prefs->protocol == A_APOP ?
-                            (ac_prefs->ssl_pop ?
-                             "POP3 (APOP, SSL)" : "POP3 (APOP)") :
+                            (ac_prefs->ssl_pop == SSL_TUNNEL ?
+                             "POP3 (APOP, SSL)" :
+                             ac_prefs->ssl_pop == SSL_STARTTLS ?
+                             "POP3 (APOP, TLS)" : "POP3 (APOP)") :
                             ac_prefs->protocol == A_IMAP4 ?
-                            (ac_prefs->ssl_imap ? "IMAP4 (SSL)" : "IMAP4") :
-                            ac_prefs->protocol == A_LOCAL ? "Local" :
-                            ac_prefs->protocol == A_NNTP ? "NNTP"  :  "";
+                            (ac_prefs->ssl_imap == SSL_TUNNEL ?
+                             "IMAP4 (SSL)" :
+                             ac_prefs->ssl_imap == SSL_STARTTLS ?
+                             "IMAP4 (TLS)" : "IMAP4") :
+                            ac_prefs->protocol == A_NNTP ?
+                            (ac_prefs->ssl_nntp == SSL_TUNNEL ?
+                             "NNTP (SSL)" : "NNTP") :
+                            "";
 #else
        text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3" :
                             ac_prefs->protocol == A_APOP  ? "POP3 (APOP)" :
@@ -741,12 +911,22 @@ static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
                gtk_clist_set_text(clist, row, COL_SERVER, text[COL_SERVER]);
        }
 
-       if (*text[COL_DEFAULT])
+       has_getallbox = (ac_prefs->protocol == A_POP3  ||
+                        ac_prefs->protocol == A_APOP  ||
+                        ac_prefs->protocol == A_IMAP4 ||
+                        ac_prefs->protocol == A_NNTP ||
+                        ac_prefs->protocol == A_LOCAL);
+       getall = has_getallbox && ac_prefs->recv_at_getall;
+
+       if (ac_prefs->is_default)
                gtk_clist_set_pixmap(clist, row, COL_DEFAULT,
                                     markxpm, markxpmmask);
-       if (*text[COL_GETALL])
+       if (getall)
                gtk_clist_set_pixmap(clist, row, COL_GETALL,
-                                    markxpm, markxpmmask);
+                                    checkboxonxpm, checkboxonxpmmask);
+       else if (has_getallbox)
+               gtk_clist_set_pixmap(clist, row, COL_GETALL,
+                                    checkboxoffxpm, checkboxoffxpmmask);
 
        gtk_clist_set_row_data(clist, row, ac_prefs);
 
@@ -758,19 +938,15 @@ static void account_clist_set(void)
 {
        GtkCList *clist = GTK_CLIST(edit_account.clist);
        GList *cur;
-       gint prev_row;
+       gint row = -1, prev_row = -1;
 
        if (clist->selection)
                prev_row = GPOINTER_TO_INT(clist->selection->data);
-       else
-               prev_row = -1;
 
        gtk_clist_freeze(clist);
        gtk_clist_clear(clist);
 
        for (cur = account_list; cur != NULL; cur = cur->next) {
-               gint row;
-
                row = account_clist_set_row((PrefsAccount *)cur->data, -1);
                if ((PrefsAccount *)cur->data == cur_account) {
                        gtk_clist_select_row(clist, row, -1);
@@ -779,10 +955,15 @@ static void account_clist_set(void)
        }
 
        if (prev_row >= 0) {
-               gtk_clist_select_row(clist, prev_row, -1);
-               gtkut_clist_set_focus_row(clist, prev_row);
+               row = prev_row;
+               gtk_clist_select_row(clist, row, -1);
+               gtkut_clist_set_focus_row(clist, row);
        }
 
+       if (row >= 0 &&
+           gtk_clist_row_is_visible(clist, row) != GTK_VISIBILITY_FULL)
+               gtk_clist_moveto(clist, row, -1, 0.5, 0);
+
        gtk_clist_thaw(clist);
 }
 
@@ -800,3 +981,48 @@ static void account_list_set(void)
             row++)
                account_list = g_list_append(account_list, ac_prefs);
 }
+
+/*!
+ *\brief       finds the PrefsAccounts which should be used to answer a mail
+ *
+ *\param       msginfo The message to be answered
+ *\param       reply_autosel Indicates whether reply account autoselection is on
+ *
+ *\return      PrefsAccount * the correct account, NULL if not found
+ */
+PrefsAccount *account_get_reply_account(MsgInfo *msginfo, gboolean reply_autosel)
+{
+       PrefsAccount *account = NULL;
+       /* select the account set in folderitem's property (if enabled) */
+       if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
+               account = account_find_from_id(msginfo->folder->prefs->default_account);
+       
+       /* select the account for the whole folder (IMAP / NNTP) */
+       if (!account)
+               /* FIXME: this is not right, because folder may be nested. we should
+                * ascend the tree until we find a parent with proper account 
+                * information */
+               account = msginfo->folder->folder->account;
+
+       /* select account by to: and cc: header if enabled */
+       if (reply_autosel) {
+               if (!account && msginfo->to) {
+                       gchar *to;
+                       Xstrdup_a(to, msginfo->to, return NULL);
+                       extract_address(to);
+                       account = account_find_from_address(to);
+               }
+               if (!account) {
+                       gchar cc[BUFFSIZE];
+                       if (!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
+                               extract_address(cc);
+                               account = account_find_from_address(cc);
+                       }        
+               }
+       }
+
+       /* select current account */
+       if (!account) account = cur_account;
+       
+       return account;
+}