Add missing SSL settings copy when cloning accounts.
[claws.git] / src / account.c
index 25171a63405293e572378b72c600f8f2d8edf371..a8d8375f6e5b9284c1fd38ca740d612cefdf4043 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
 #include "remotefolder.h"
 #include "manual.h"
 #include "filtering.h"
+#include "prefs_actions.h"
+#include "hooks.h"
+#include "passwordstore.h"
+#include "file-utils.h"
 
 enum {
        ACCOUNT_IS_DEFAULT,
-       ACCOUNT_ENABLE_GET_ALL, 
+       ACCOUNT_ENABLE_GET_ALL,
        ACCOUNT_NAME,
        ACCOUNT_PROTOCOL,
        ACCOUNT_SERVER,
@@ -66,14 +71,13 @@ enum {
 typedef enum
 {
        COL_DEFAULT     = 0,
-       COL_GETALL      = 1,
-       COL_NAME        = 2,
-       COL_PROTOCOL    = 3,
-       COL_SERVER      = 4
+       COL_GETALL,
+       COL_NAME,
+       COL_PROTOCOL,
+       COL_SERVER,
+       N_EDIT_ACCOUNT_COLS
 } EditAccountColumnPos;
 
-# define N_EDIT_ACCOUNT_COLS   5
-
 PrefsAccount *cur_account;
 
 static GList *account_list = NULL;
@@ -106,15 +110,12 @@ static gint account_delete_event  (GtkWidget      *widget,
                                         gpointer        data);
 static void account_size_allocate_cb(GtkWidget *widget,
                                         GtkAllocation *allocation);
-#ifndef MAEMO
 static gboolean account_key_pressed    (GtkWidget      *widget,
                                         GdkEventKey    *event,
                                         gpointer        data);
-#endif
 static gboolean account_search_func_cb (GtkTreeModel *model, gint column, 
                                                const gchar *key, GtkTreeIter *iter, 
                                                gpointer search_data);
-static void account_list_view_add      (PrefsAccount   *ac_prefs);
 static void account_list_view_set      (void);
 
 static void account_list_set           (void);
@@ -127,12 +128,7 @@ typedef struct FindAccountInStore {
 
 static GtkListStore* account_create_data_store (void);
 
-static void account_list_view_insert_account_item (GtkListStore        *list_store, 
-                                                  const gchar  *account_name,
-                                                  const gchar  *protocol, 
-                                                  const gchar  *server_name,
-                                                  gboolean      is_default, 
-                                                  gboolean      is_get_all,
+static void account_list_store_insert_account_item (GtkListStore       *list_store,
                                                   PrefsAccount *account_data);
 
 static GtkWidget *account_list_view_create     (void);
@@ -160,7 +156,7 @@ static gboolean find_account_in_store               (GtkTreeModel *model,
 static void account_get_all_toggled            (GtkCellRendererToggle  *widget, 
                                                 gchar                  *path, 
                                                 GtkWidget              *list_view);
-                                                
+
 static void account_double_clicked             (GtkTreeView            *list_view,
                                                 GtkTreePath            *path,
                                                 GtkTreeViewColumn      *column,
@@ -199,30 +195,29 @@ void account_read_config_all(void)
        debug_print("Reading all config for each account...\n");
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
-       if ((fp = g_fopen(rcpath, "rb")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
+       if ((fp = claws_fopen(rcpath, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "claws_fopen");
                g_free(rcpath);
                return;
        }
        g_free(rcpath);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                if (!strncmp(buf, "[Account: ", 10)) {
                        strretchomp(buf);
-                       memmove(buf, buf + 1, strlen(buf));
+                       memmove(buf, buf + 1, sizeof(buf) - 1);
                        buf[strlen(buf) - 1] = '\0';
                        debug_print("Found label: %s\n", buf);
                        ac_label_list = g_slist_append(ac_label_list,
                                                       g_strdup(buf));
                }
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        /* read config data from file */
        cur_account = NULL;
        for (cur = ac_label_list; cur != NULL; cur = cur->next) {
-               ac_prefs = prefs_account_new();
-               prefs_account_read_config(ac_prefs, (gchar *)cur->data);
+               ac_prefs = prefs_account_new_from_config((gchar *)cur->data);
                account_list = g_list_append(account_list, ac_prefs);
                if (ac_prefs->is_default)
                        cur_account = ac_prefs;
@@ -275,7 +270,20 @@ GList *account_find_all_from_address(GList *ac_list, const gchar *address)
        }
        return ac_list;
 }
-       
+
+GList *account_find_all(void)
+{
+       GList *cur;
+       PrefsAccount *ac;
+       GList *ac_list = NULL;
+
+       for (cur = account_list; cur != NULL; cur = cur->next) {
+               ac = (PrefsAccount *)cur->data;
+               ac_list = g_list_append(ac_list, ac);
+       }
+       return ac_list;
+}
+
 PrefsAccount *account_find_from_smtp_server(const gchar *address,
                                            const gchar *smtp_server)
 {
@@ -287,8 +295,8 @@ PrefsAccount *account_find_from_smtp_server(const gchar *address,
 
        for (cur = account_list; cur != NULL; cur = cur->next) {
                ac = (PrefsAccount *)cur->data;
-               if (!strcmp2(address, ac->address) &&
-                   !strcmp2(smtp_server, ac->smtp_server))
+               if (!g_strcmp0(address, ac->address) &&
+                   !g_strcmp0(smtp_server, ac->smtp_server))
                        return ac;
        }
 
@@ -372,6 +380,18 @@ GList *account_get_list(void)
        return account_list;
 }
 
+void account_edit_focus(void)
+{
+       if (edit_account.window == NULL) {
+               return;
+       }
+       manage_window_set_transient(GTK_WINDOW(edit_account.window));
+       gtk_widget_grab_focus(edit_account.close_btn);
+       gtk_widget_show(edit_account.window);
+       gtk_window_set_modal(GTK_WINDOW(edit_account.window), TRUE);
+       manage_window_focus_in(edit_account.window, NULL, NULL);
+}
+
 void account_edit_open(gpointer a, gpointer b)
 {
        inc_lock();
@@ -381,7 +401,7 @@ void account_edit_open(gpointer a, gpointer b)
        if (compose_get_compose_list()) {
                alertpanel_error(_("Some composing windows are open.\n"
                                   "Please close all the composing "
-                                  "windows before editing the accounts."));
+                                  "windows before editing accounts."));
                inc_unlock();
                return;
        }
@@ -393,11 +413,7 @@ void account_edit_open(gpointer a, gpointer b)
 
        account_list_view_set();
 
-       manage_window_set_transient(GTK_WINDOW(edit_account.window));
-       gtk_widget_grab_focus(edit_account.close_btn);
-       gtk_widget_show(edit_account.window);
-       gtk_window_set_modal(GTK_WINDOW(edit_account.window), TRUE);
-       manage_window_focus_in(edit_account.window, NULL, NULL);
+       account_edit_focus();
 }
 
 void account_add(void)
@@ -408,6 +424,8 @@ void account_add(void)
 
        if (!ac_prefs) return;
 
+       account_edit_focus();
+
        account_list = g_list_append(account_list, ac_prefs);
 
        if (ac_prefs->is_default)
@@ -439,29 +457,48 @@ void account_add(void)
        }
 }
 
-void account_open(PrefsAccount *ac_prefs)
+void account_open(PrefsAccount *ac_prefs, gboolean called_from_acc_list)
 {
        gboolean prev_default;
-       gchar *ac_name;
+       gchar *ac_name, *old_prefix, *new_prefix;
        gboolean account_dirty = FALSE;
 
        cm_return_if_fail(ac_prefs != NULL);
 
+       if (compose_get_compose_list()) {
+               alertpanel_error(_("Some composing windows are open.\n"
+                                  "Please close all the composing "
+                                  "windows before editing accounts."));
+               return;
+       }
+
        prev_default = ac_prefs->is_default;
        Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
                  return);
 
        prefs_account_open(ac_prefs, &account_dirty);
 
+       if (called_from_acc_list)
+               account_edit_focus();
+
        if (account_dirty) {
                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) {
+               if (ac_prefs->folder && g_strcmp0(ac_name, ac_prefs->account_name) != 0) {
+                       old_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
                        folder_set_name(FOLDER(ac_prefs->folder),
                                        ac_prefs->account_name);
                        folderview_set_all();
                        folder_prefs_save_config_recursive(FOLDER(ac_prefs->folder));
+                       new_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
+
+                       account_rename_path(old_prefix, new_prefix);
+                       prefs_filtering_rename_path(old_prefix, new_prefix);
+                       prefs_actions_rename_path(old_prefix, new_prefix);
+                       
+                       g_free(old_prefix);
+                       g_free(new_prefix);
                }
 
                account_write_config_all();
@@ -558,8 +595,6 @@ void account_rename_path(const gchar *old_id, const gchar *new_id)
        }
 }
 
-#undef CHECK_CHANGE_FOLDER
-
 FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
                                       SpecialFolderItemType type)
 {
@@ -643,7 +678,6 @@ void account_destroy(PrefsAccount *ac_prefs)
 
        folder_unref_account_all(ac_prefs);
 
-       prefs_account_free(ac_prefs);
        account_list = g_list_remove(account_list, ac_prefs);
 
        if (cur_account == ac_prefs) cur_account = NULL;
@@ -701,12 +735,8 @@ static void account_edit_create(void)
        gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
        g_signal_connect (G_OBJECT (window), "delete_event",
                          G_CALLBACK (account_delete_event), NULL);
-#ifdef MAEMO
-       maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
-#else
        g_signal_connect (G_OBJECT (window), "key_press_event",
                          G_CALLBACK (account_key_pressed), NULL);
-#endif                   
        MANAGE_WINDOW_SIGNALS_CONNECT (window);
        gtk_widget_realize(window);
 
@@ -831,9 +861,6 @@ static void account_edit_create(void)
        edit_account.window    = window;
        edit_account.list_view = list_view;
        edit_account.close_btn = close_btn;
-#ifdef MAEMO
-       maemo_window_full_screen_if_needed(GTK_WINDOW(edit_account.window));
-#endif
 }
 
 static void account_edit_prefs(GtkWidget *widget, gpointer data)
@@ -843,7 +870,7 @@ static void account_edit_prefs(GtkWidget *widget, gpointer data)
        ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
        
        if (ac_prefs) {
-               account_open(ac_prefs);
+               account_open(ac_prefs, TRUE);
                account_list_view_set();
        }               
 }
@@ -917,7 +944,13 @@ static void account_clone(GtkWidget *widget, gpointer data)
        ACP_FASSIGN(ssl_imap);
        ACP_FASSIGN(ssl_nntp);
        ACP_FASSIGN(ssl_smtp);
+       ACP_FASSIGN(ssl_certs_auto_accept);
        ACP_FASSIGN(use_nonblocking_ssl);
+       ACP_FASSIGN(use_tls_sni);
+       ACP_FASSIGN(in_ssl_client_cert_file);
+       ACP_FASSIGN(in_ssl_client_cert_pass);
+       ACP_FASSIGN(out_ssl_client_cert_file);
+       ACP_FASSIGN(out_ssl_client_cert_pass);
        
        /* receive */
        ACP_FASSIGN(use_apop_auth);
@@ -933,11 +966,16 @@ static void account_clone(GtkWidget *widget, gpointer data)
        ACP_FDUP(inbox);
        ACP_FDUP(local_inbox);
        ACP_FASSIGN(max_articles);
+       ACP_FASSIGN(autochk_use_default);
+       ACP_FASSIGN(autochk_use_custom);
+       ACP_FASSIGN(autochk_itv);
+       ac_clon->autocheck_timer = 0;
 
        ACP_FASSIGN(imap_auth_type);
 
        /* send */
        ACP_FASSIGN(gen_msgid);
+       ACP_FASSIGN(gen_xmailer);
        ACP_FASSIGN(add_customhdr);
        ACP_FASSIGN(use_smtp_auth);
        ACP_FASSIGN(smtp_auth_type);
@@ -1032,12 +1070,45 @@ static void account_clone(GtkWidget *widget, gpointer data)
        ac_clon->is_default = FALSE;
        ACP_FASSIGN(folder);
 
+       ACP_FASSIGN(config_version);
+
+       ACP_FASSIGN(use_proxy);
+       ACP_FASSIGN(use_default_proxy);
+       ACP_FASSIGN(use_proxy_for_send);
+       ACP_FASSIGN(proxy_info.proxy_type);
+       ACP_FDUP(proxy_info.proxy_host);
+       ACP_FASSIGN(proxy_info.proxy_port);
+       ACP_FASSIGN(proxy_info.use_proxy_auth);
+       ACP_FDUP(proxy_info.proxy_name);
+       ACP_FDUP(proxy_info.proxy_pass);
+
        account_list = g_list_append(account_list, ac_clon);
        account_list_view_set();
 }
 #undef ACP_FDUP
 #undef ACP_FASSIGN
 
+static void account_empty_cache(PrefsAccount *ac_prefs)
+{
+       gchar *cache_dir;
+
+       cache_dir = prefs_account_cache_dir(ac_prefs, FALSE);
+       if (cache_dir == NULL)
+               return; /* no cache dir, nothing to do */
+
+       if (is_dir_exist(cache_dir) && remove_dir_recursive(cache_dir) < 0) {
+               g_warning("can't remove directory '%s'", cache_dir);
+       } else {
+               gchar *server_dir =  prefs_account_cache_dir(ac_prefs, TRUE);
+               if (g_rmdir(server_dir) == 0)
+                       debug_print("Removed empty cache server directory\n");
+               else
+                       debug_print("Cache server directory not empty: not removed\n");
+               g_free(server_dir);
+       }
+       g_free(cache_dir);
+}
+
 static void account_delete(GtkWidget *widget, gpointer data)
 {
        PrefsAccount *ac_prefs;
@@ -1045,7 +1116,7 @@ static void account_delete(GtkWidget *widget, gpointer data)
        GList *list;
        Folder *folder;
        GSList *cur;
+
        ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
        if (ac_prefs == NULL)
                return;
@@ -1055,8 +1126,8 @@ static void account_delete(GtkWidget *widget, gpointer data)
                   ac_prefs->account_name ? ac_prefs->account_name :
                   _("(Untitled)"));
        if (alertpanel_full(_("Delete account"), buf,
-                           GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, FALSE,
-                           NULL, ALERT_WARNING, G_ALERTDEFAULT) != G_ALERTALTERNATE)
+                           GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, ALERTFOCUS_FIRST, FALSE,
+                           NULL, ALERT_WARNING) != G_ALERTALTERNATE)
                return;
        account_list_dirty = TRUE;
 
@@ -1069,6 +1140,9 @@ static void account_delete(GtkWidget *widget, gpointer data)
                folder_destroy(FOLDER(ac_prefs->folder));
                folderview_set_all();
        }
+
+       inc_account_autocheck_timer_remove(ac_prefs);
+
        account_destroy(ac_prefs);
        account_list_view_set();
 
@@ -1083,6 +1157,10 @@ static void account_delete(GtkWidget *widget, gpointer data)
                                GINT_TO_POINTER(ac_prefs->account_id));
        }
 
+       gchar *uid = g_strdup_printf("%d", ac_prefs->account_id);
+       passwd_store_delete_block(PWS_ACCOUNT, uid);
+       g_free(uid);
+
        debug_print("Removing filter rules relative to this account...\n");
        for(cur = filtering_rules ; cur != NULL ;) {
                FilteringProp * prop = (FilteringProp *) cur->data;
@@ -1098,6 +1176,10 @@ static void account_delete(GtkWidget *widget, gpointer data)
                        cur = g_slist_next(cur);
                }
        }
+
+       debug_print("Removing cache directory of this account...\n");
+       account_empty_cache(ac_prefs);
+
        folder_write_list();
 }
 
@@ -1225,15 +1307,14 @@ static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
        account_edit_close(NULL, NULL);
        return TRUE;
 }
-#ifndef MAEMO
+
 static gboolean account_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                    gpointer data)
 {
-       if (event && event->keyval == GDK_Escape)
+       if (event && event->keyval == GDK_KEY_Escape)
                account_edit_close(NULL, NULL);
        return FALSE;
 }
-#endif
 
 static gboolean account_search_func_cb (GtkTreeModel *model, gint column, const gchar *key, 
                                                GtkTreeIter *iter, gpointer search_data) 
@@ -1252,55 +1333,6 @@ static gboolean account_search_func_cb (GtkTreeModel *model, gint column, const
 
        return retval;
 }
-static void account_list_view_add(PrefsAccount *ac_prefs)
-{
-       GtkTreeView *list_view = GTK_TREE_VIEW(edit_account.list_view);
-       GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
-       gchar *name, *protocol, *server;
-       gboolean has_getallbox;
-       gboolean getall;
-
-       name = ac_prefs->account_name;
-#ifdef USE_GNUTLS
-       protocol = ac_prefs->protocol == A_POP3 ?
-                 (ac_prefs->ssl_pop == SSL_TUNNEL ?
-                  "POP3 (SSL)" :
-                  ac_prefs->ssl_pop == SSL_STARTTLS ?
-                  "POP3 (TLS)" : "POP3") :
-                  ac_prefs->protocol == A_IMAP4 ?
-                 (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") :
-                  ac_prefs->protocol == A_LOCAL ? "Local" :
-                  ac_prefs->protocol == A_NONE ?  "SMTP" : "-";
-#else
-       protocol = ac_prefs->protocol == A_POP3  ? "POP3" :
-                  ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
-                  ac_prefs->protocol == A_LOCAL ? "Local" :
-                  ac_prefs->protocol == A_NNTP  ? "NNTP" :
-                  ac_prefs->protocol == A_NONE ?  "SMTP" : "-";
-#endif
-       server= ac_prefs->protocol == A_NNTP ? ac_prefs->nntp_server :
-                  ac_prefs->protocol == A_LOCAL ?  "-" :
-                  ac_prefs->protocol == A_NONE ? ac_prefs->smtp_server :
-                  ac_prefs->recv_server;
-
-       has_getallbox = (ac_prefs->protocol == A_POP3  ||
-                        ac_prefs->protocol == A_IMAP4 ||
-                        ac_prefs->protocol == A_NNTP  ||
-                        ac_prefs->protocol == A_LOCAL);
-       getall = has_getallbox && ac_prefs->recv_at_getall;
-
-       account_list_view_insert_account_item(list_store,
-                                            name, protocol, server,
-                                            ac_prefs->is_default,
-                                            getall, ac_prefs);
-       return;
-}
 
 static void account_list_view_set(void)
 {
@@ -1317,7 +1349,7 @@ static void account_list_view_set(void)
        gtk_list_store_clear(store);
        
        for (cur = account_list; cur != NULL; cur = cur->next) {
-               account_list_view_add((PrefsAccount *)cur->data);
+               account_list_store_insert_account_item(store, (PrefsAccount *)cur->data);
                if ((PrefsAccount *)cur->data == cur_account)
                        account_list_view_select_account
                                (edit_account.list_view, 
@@ -1348,7 +1380,7 @@ static void account_list_set(void)
                GtkTreeIter iter;
 
                if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
-                       g_warning("%s(%d) - no iter found???\n", __FILE__, __LINE__);                                         
+                       g_warning("%s(%d) - no iter found???", __FILE__, __LINE__);
                        continue;
                }
        
@@ -1375,41 +1407,54 @@ PrefsAccount *account_get_reply_account(MsgInfo *msginfo, gboolean reply_autosel
        /* 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);
-       
+       else if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
+                folder_has_parent_of_type(msginfo->folder, F_OUTBOX) ||
+                folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
+                       gchar *from = NULL;
+                       if (!procheader_get_header_from_msginfo
+                               (msginfo, &from, "From:")) {
+                               gchar *buf = from + strlen("From:");
+                               extract_address(buf);
+                               account = account_find_from_address(buf, FALSE);
+                       g_free(from);
+                       }
+       }
        /* select account by to: and cc: header if enabled */
        if (reply_autosel) {
                gchar * field = NULL;
                int fieldno = 0;
                for (field = msginfo->to; fieldno++ < 2; field = msginfo->cc) {
                        if (!account && field) {
-                               gchar *to = NULL;
-                               if (!strchr(field, ',')) {
-                                       Xstrdup_a(to, field, return NULL);
-                                       extract_address(to);
-                                       account = account_find_from_address(to, FALSE);
-                               } else {
-                                       gchar **split = g_strsplit(field, ",", -1);
-                                       int i = -1;
+                               gchar *f = g_strdup(field);
+                               if (f) {
+                                       gchar *cur = f;
+                                       gchar *next = NULL;
+                                       gchar *to = NULL;
                                        do {
-                                               i++;
-                                               if (!split[i])
-                                                       break;
-                                               Xstrdup_a(to, split[i], return NULL);
+                                               next = strchr_with_skip_quote(cur, '"', ',');
+                                               if (next)
+                                                       (*next) = 0;
+                                               Xstrdup_a(to, cur, return NULL);
                                                extract_address(to);
                                                account = account_find_from_address(to, FALSE);
+                                               if (next)
+                                                       cur = next + 1;
+                                               else
+                                                       break;
                                        } while (!account);
-                                       g_strfreev(split);
+                                       g_free(f);
                                }
                        }
                }
                if (!account) {
-                       gchar deliveredto[BUFFSIZE];
+                       gchar *deliveredto = NULL;
                        if (!procheader_get_header_from_msginfo
-                               (msginfo, deliveredto,sizeof deliveredto , "Delivered-To:")) { 
+                               (msginfo, &deliveredto, "Delivered-To:")) {
                                gchar *buf = deliveredto + strlen("Delivered-To:");
                                extract_address(buf);
                                account = account_find_from_address(buf, FALSE);
-                       }
+                       g_free(deliveredto);
+                       }
                }
        }
 
@@ -1447,24 +1492,54 @@ static GtkListStore* account_create_data_store(void)
  *\return      GtkTreeRowReference * A tree row reference, which is guaranteed to 
  *             stable whatever operations are performed on the list.
  */
-static void account_list_view_insert_account_item(GtkListStore *list_store, 
-                                                 const gchar *account_name,
-                                                 const gchar *protocol, 
-                                                 const gchar *server_name,
-                                                 gboolean is_default, 
-                                                 gboolean is_get_all,
-                                                 PrefsAccount *account_data)
+static void account_list_store_insert_account_item(GtkListStore *list_store,
+                                                 PrefsAccount *ac_prefs)
 {
        GtkTreeIter iter;
+       gboolean is_get_all = (ac_prefs->protocol == A_POP3 ||
+                       ac_prefs->protocol == A_IMAP4 ||
+                       ac_prefs->protocol == A_NNTP  ||
+                       ac_prefs->protocol == A_LOCAL) &&
+               ac_prefs->recv_at_getall;
+       gchar *protocol, *server;
        
+#ifdef USE_GNUTLS
+       protocol = ac_prefs->protocol == A_POP3 ?
+                 (ac_prefs->ssl_pop == SSL_TUNNEL ?
+                  "POP (SSL/TLS)" :
+                  ac_prefs->ssl_pop == SSL_STARTTLS ?
+                  "POP (STARTTLS)" : "POP") :
+                  ac_prefs->protocol == A_IMAP4 ?
+                 (ac_prefs->ssl_imap == SSL_TUNNEL ?
+                  "IMAP (SSL/TLS)" :
+                  ac_prefs->ssl_imap == SSL_STARTTLS ?
+                  "IMAP (STARTTLS)" : "IMAP") :
+                  ac_prefs->protocol == A_NNTP ?
+                 (ac_prefs->ssl_nntp == SSL_TUNNEL ?
+                  "NNTP (SSL/TLS)" : "NNTP") :
+                  ac_prefs->protocol == A_LOCAL ? "Local" :
+                  ac_prefs->protocol == A_NONE ?  "SMTP" : "-";
+#else
+       protocol = ac_prefs->protocol == A_POP3  ? "POP" :
+                  ac_prefs->protocol == A_IMAP4 ? "IMAP" :
+                  ac_prefs->protocol == A_LOCAL ? "Local" :
+                  ac_prefs->protocol == A_NNTP  ? "NNTP" :
+                  ac_prefs->protocol == A_NONE ?  "SMTP" : "-";
+#endif
+
+       server= ac_prefs->protocol == A_NNTP ? ac_prefs->nntp_server :
+                  ac_prefs->protocol == A_LOCAL ?  "-" :
+                  ac_prefs->protocol == A_NONE ? ac_prefs->smtp_server :
+                  ac_prefs->recv_server;
+
        gtk_list_store_append(list_store, &iter);
        gtk_list_store_set(list_store, &iter, 
-                          ACCOUNT_IS_DEFAULT,     is_default ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
+                          ACCOUNT_IS_DEFAULT,     ac_prefs->is_default ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
                           ACCOUNT_ENABLE_GET_ALL, is_get_all,
-                          ACCOUNT_NAME,           account_name,
+                          ACCOUNT_NAME,           ac_prefs->account_name,
                           ACCOUNT_PROTOCOL,       protocol,
-                          ACCOUNT_SERVER,         server_name,
-                          ACCOUNT_DATA,           account_data,
+                          ACCOUNT_SERVER,         server,
+                          ACCOUNT_DATA,           ac_prefs,
                           -1);
 }
 
@@ -1517,7 +1592,6 @@ static void account_create_list_view_columns(GtkWidget *list_view)
 {
        GtkTreeViewColumn *column;
        GtkCellRenderer *renderer;
-       CLAWS_TIP_DECL();
 
        renderer = gtk_cell_renderer_toggle_new();
        g_object_set(renderer, 
@@ -1525,12 +1599,12 @@ static void account_create_list_view_columns(GtkWidget *list_view)
                     "activatable", TRUE,
                      NULL);
        column = gtk_tree_view_column_new_with_attributes
-               (Q_("Accounts List Get Column Name|G"), renderer,
+               (C_("Accounts List Get Column Name", "G"), renderer,
                 "active", ACCOUNT_ENABLE_GET_ALL,
                 NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
        gtk_tree_view_column_set_alignment (column, 0.5);
-       CLAWS_SET_TIP(column->button,
+       CLAWS_SET_TIP(gtk_tree_view_column_get_widget(column),
                        _("'Get Mail' retrieves mail from the checked accounts"));
        g_signal_connect(G_OBJECT(renderer), "toggled",                      
                         G_CALLBACK(account_get_all_toggled),
@@ -1568,19 +1642,13 @@ static void account_create_list_view_columns(GtkWidget *list_view)
  */
 static gint account_list_view_get_selected_account_id(GtkWidget *list_view)
 {
-       GtkTreeSelection *selector;
-       GtkTreeModel *model;
-       GtkTreeIter iter;
        PrefsAccount *res = NULL;
 
-       selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
-       
-       if (!gtk_tree_selection_get_selected(selector, &model, &iter))
-               return -1;
-
-       gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
+       res = (PrefsAccount *)gtkut_tree_view_get_selected_pointer(
+                       GTK_TREE_VIEW(list_view), ACCOUNT_DATA,
+                       NULL, NULL, NULL);
 
-       return res->account_id;                    
+       return (res != NULL ? res->account_id : -1);
 }
 
 /*!
@@ -1606,19 +1674,12 @@ static GtkTreePath *account_list_view_get_selected_account_path(GtkWidget *list_
  */
 static PrefsAccount *account_list_view_get_selected_account(GtkWidget *list_view)
 {
-       GtkTreeSelection *selector;
-       GtkTreeModel *model;
-       GtkTreeIter iter;
-       PrefsAccount *res = NULL;
-
-       selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
-       
-       if (!gtk_tree_selection_get_selected(selector, &model, &iter))
-               return NULL;
-
-       gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
+       PrefsAccount *res =
+               (PrefsAccount *)gtkut_tree_view_get_selected_pointer(
+                       GTK_TREE_VIEW(list_view), ACCOUNT_DATA,
+                       NULL, NULL, NULL);
 
-       return res;                        
+       return res;
 }
 
 /*!
@@ -1798,23 +1859,30 @@ gchar *account_get_signature_str(PrefsAccount *account)
                return NULL;
 
        if (account->sig_type == SIG_FILE) {
-               if (!is_file_or_fifo_exist(account->sig_path)) {
-                       g_warning("can't open signature file: %s\n",
-                                 account->sig_path);
+               gchar *sig_full_path;
+               if (!g_path_is_absolute(account->sig_path)) {
+                       sig_full_path = g_build_filename(get_home_dir(), account->sig_path, NULL);
+               } else {
+                       sig_full_path = g_strdup(account->sig_path);
+               }
+
+               if (!is_file_or_fifo_exist(sig_full_path)) {
+                       g_warning("can't open signature file: '%s'", sig_full_path);
+                       g_free(sig_full_path);
                        return NULL;
                }
-       }
 
-       if (account->sig_type == SIG_COMMAND)
-               sig_body = get_command_output(account->sig_path);
-       else {
-               gchar *tmp;
+               debug_print("Reading signature from file '%s'\n", sig_full_path);
+               gchar *tmp = file_read_to_str(sig_full_path);
+               g_free(sig_full_path);
 
-               tmp = file_read_to_str(account->sig_path);
                if (!tmp)
                        return NULL;
+
                sig_body = normalize_newlines(tmp);
                g_free(tmp);
+       } else {
+               sig_body = get_command_output(account->sig_path);
        }
 
        if (account->sig_sep) {
@@ -1842,3 +1910,113 @@ PrefsAccount *account_get_cur_account (void)
 {
        return cur_account;
 }
+
+gboolean password_get(const gchar *user,
+                   const gchar *server,
+                   const gchar *protocol,
+                   guint16 port,
+                   gchar **password)
+{
+       PasswordRequest req;
+
+       /* all have to be set */
+       cm_return_val_if_fail(user != NULL, FALSE);
+       cm_return_val_if_fail(server != NULL, FALSE);
+       cm_return_val_if_fail(protocol != NULL, FALSE);
+       cm_return_val_if_fail(port != 0, FALSE);
+
+       req.user = user;
+       req.server = server;
+       req.protocol = protocol;
+       req.port = port;
+
+       if (hooks_invoke(PASSWORD_GET_HOOKLIST, &req)) {
+               *password = req.password;
+               return TRUE;
+       }
+       return FALSE;
+}
+
+static GSList *account_sigsep_list = NULL;
+
+/* create a list of unique signatures from accounts list */
+void account_sigsep_matchlist_create(void)
+{
+       GList *cur_ac = NULL;
+       PrefsAccount *ac_prefs = NULL;
+
+       if (account_sigsep_list)
+               return;
+
+       account_sigsep_list = g_slist_prepend(account_sigsep_list, g_strdup("-- "));
+       for (cur_ac = account_get_list();
+                cur_ac != NULL;
+                cur_ac = g_list_next(cur_ac)) {
+               ac_prefs = (PrefsAccount *)cur_ac->data;
+
+               if (ac_prefs->sig_sep && *ac_prefs->sig_sep != '\0') {
+                       if (!g_slist_find_custom(account_sigsep_list, ac_prefs->sig_sep,
+                                       (GCompareFunc)g_strcmp0)) {
+                               account_sigsep_list = g_slist_prepend(account_sigsep_list,
+                                               g_strdup(ac_prefs->sig_sep));
+                       }
+               }
+       }
+}
+
+/* delete the list of signatures created by account_sigsep_matchlist_create() */
+void account_sigsep_matchlist_delete(void)
+{
+       if (account_sigsep_list) {
+               slist_free_strings_full(account_sigsep_list);
+               account_sigsep_list = NULL;
+       }
+}
+
+/* match a string against all signatures in list, using the specified format */
+gboolean account_sigsep_matchlist_str_found(const gchar *str, const gchar *format)
+{
+       gchar *tmp = NULL;
+       gboolean found = FALSE;
+       GSList *item;
+
+       for (item = account_sigsep_list;
+                item != NULL && !found;
+                item = g_slist_next(item)) {
+               tmp = g_strdup_printf(format, (gchar *)item->data);
+               if (tmp) {
+                       found = (strcmp(tmp, str) == 0);
+                       g_free(tmp);
+               } else {
+                       g_warning("account_sigsep_matchlist_str_found: g_strdup_printf failed, check format '%s'",
+                               format);
+                       return FALSE;
+               }
+       }
+       return found;
+}
+
+/* match M first char of a string against all signatures in list, using the specified format */
+gboolean account_sigsep_matchlist_nchar_found(const gchar *str, const gchar *format)
+{
+       gchar *tmp = NULL;
+       gboolean found = FALSE;
+       GSList *item;
+       gint len;
+
+       for (item = account_sigsep_list;
+                item != NULL && !found;
+                item = g_slist_next(item)) {
+               tmp = g_strdup_printf(format, (gchar *)item->data);
+               if (tmp) {
+                       len = strlen(tmp);
+                       found = (strncmp(tmp, str, len) == 0);
+                       g_free(tmp);
+               } else {
+                       g_warning("account_sigsep_matchlist_nchar_found: g_strdup_printf failed, check format '%s'",
+                               format);
+                       return FALSE;
+               }
+       }
+       return found;
+}