0.8.11claws7
[claws.git] / src / account.c
index e8b2a34f1b8a749708a04da41e54eedf009d8af7..68304c8b5d386a1addda5d1aab9d7d857f5af0f4 100644 (file)
@@ -35,7 +35,7 @@
 #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"
@@ -45,6 +45,7 @@
 #include "gtkutils.h"
 #include "utils.h"
 #include "alertpanel.h"
+#include "procheader.h"
 
 typedef enum
 {
@@ -340,10 +341,10 @@ void account_add(void)
                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);
                }
 
@@ -351,7 +352,7 @@ 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();
        }
 }
@@ -423,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);
                        }
 
@@ -434,7 +435,7 @@ 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);
                }
        }
 }
@@ -446,7 +447,14 @@ FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
 
        g_return_val_if_fail(ac_prefs != NULL, NULL);
 
-       if (type == F_OUTBOX) {
+       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);
@@ -457,7 +465,8 @@ FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
                        if (!item)
                                item = folder_get_default_outbox();
                }
-       } else if (type == F_DRAFT) {
+               break;
+       case F_DRAFT:
                if (ac_prefs->set_draft_folder && ac_prefs->draft_folder) {
                        item = folder_find_item_from_identifier
                                (ac_prefs->draft_folder);
@@ -468,12 +477,14 @@ FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
                        if (!item)
                                item = folder_get_default_draft();
                }
-       } else if (type == F_QUEUE) {
+               break;
+       case F_QUEUE:
                if (ac_prefs->folder)
                        item = FOLDER(ac_prefs->folder)->queue;
                if (!item)
                        item = folder_get_default_queue();
-       } else if (type == F_TRASH) {
+               break;
+       case F_TRASH:
                if (ac_prefs->set_trash_folder && ac_prefs->trash_folder) {
                        item = folder_find_item_from_identifier
                                (ac_prefs->trash_folder);
@@ -484,6 +495,9 @@ FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
                        if (!item)
                                item = folder_get_default_trash();
                }
+               break;
+       default:
+               break;
        }
 
        return item;
@@ -600,8 +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 (GTK_OBJECT (clist), "row_move",
-                           GTK_SIGNAL_FUNC (account_row_moved), 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);
@@ -835,10 +849,8 @@ static void account_selected(GtkCList *clist, gint row, gint column,
 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,
-                                source_row < dest_row ? 1.0 : 0.0, 0.0);
-       }
+       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,
@@ -859,7 +871,7 @@ static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
        text[COL_DEFAULT] = "";
        text[COL_GETALL]  = "";
        text[COL_NAME]    = ac_prefs->account_name;
-#if USE_SSL
+#if USE_OPENSSL
        text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3 ?
                             (ac_prefs->ssl_pop == SSL_TUNNEL ?
                              "POP3 (SSL)" :
@@ -969,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;
+}