code cleanup
[claws.git] / src / compose.c
index 8dc5dc10550389a24e384e982d1a33162a710574..79b377c0f88e423945f1addce503b45acd3768b2 100644 (file)
@@ -497,21 +497,10 @@ Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
 {
        Compose *compose;
-       GList *cur_ac;
-       GList *account_list;
-       PrefsAccount *ac_prefs;
-
-       if (item && item->prefs->enable_default_account) {
-               /* get a PrefsAccount *pointer on the wished account */
-               account_list=account_get_list();
-               for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
-                       ac_prefs = (PrefsAccount *)cur_ac->data;
-                       if (ac_prefs->account_id == item->prefs->default_account) {
-                               account = ac_prefs;
-                               break;
-                       }
-               }
-       }
+
+       if (item && item->prefs && item->prefs->enable_default_account)
+               account = account_find_from_id(item->prefs->default_account);
+
        if (!account) account = cur_account;
        g_return_val_if_fail(account != NULL, NULL);
 
@@ -607,21 +596,33 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        g_return_if_fail(msginfo != NULL);
        g_return_if_fail(msginfo->folder != NULL);
 
-       account = msginfo->folder->folder->account;
-       if (!account && msginfo->to && prefs_common.reply_account_autosel) {
-               gchar *to;
-               Xstrdup_a(to, msginfo->to, return);
-               extract_address(to);
-               account = account_find_from_address(to);
-       }
-        if(!account&& prefs_common.reply_account_autosel) {
-                       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);
-                }        
+       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)
+               account = msginfo->folder->folder->account;
+
+       /* select account by to: and cc: header if enabled */
+       if (prefs_common.reply_account_autosel) {
+               if (!account && msginfo->to) {
+                       gchar *to;
+                       Xstrdup_a(to, msginfo->to, return);
+                       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;
        g_return_if_fail(account != NULL);
 
@@ -635,6 +636,7 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                        return;
        } else
                reply_account = account;
+
        MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
        MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
 
@@ -2174,29 +2176,6 @@ compose_end:
 #undef GET_STEXT
 }
 
-/* return str length if text at start_pos matches str else return zero */
-static guint gtkstext_str_strcmp(GtkSText *text, guint start_pos,
-                                guint text_len, gchar *str) {
-       guint is_str, i, str_len;
-       gchar str_ch;
-
-       is_str = 0;
-       if (str) {
-               str_len = strlen(str);
-               is_str = 1;
-               for (i = 0; (i < str_len) && (start_pos + i < text_len); i++) {
-                       str_ch = GTK_STEXT_INDEX(text, start_pos + i);
-                       if (*(str + i) != str_ch) {
-                               break;
-                       }
-               }
-               if (i == 0 || i < str_len)
-                       is_str = 0;
-       }
-
-       return is_str ? str_len : 0;
-}
-
 /* return indent length */
 static guint get_indent_length(GtkSText *text, guint start_pos,
                               guint text_len) {
@@ -2265,24 +2244,6 @@ static gint gtkstext_strncmp(GtkSText *text, guint pos1, guint pos2, guint len,
        return i;
 }
 
-/* return true if text at pos is URL */
-static guint is_url_string(GtkSText *text, guint start_pos, guint text_len)
-{
-       guint len;
-
-       len = gtkstext_str_strcmp(text, start_pos, text_len, "ftp://");
-       if (len == 6)
-               return 1;
-       len = gtkstext_str_strcmp(text, start_pos, text_len, "http://");
-       if (len == 7)
-               return 1;
-       len = gtkstext_str_strcmp(text, start_pos, text_len, "https://");
-       if (len == 8)
-               return 1;
-
-       return 0;
-}
-
 static void compose_wrap_line_all(Compose *compose)
 {
        GtkSText *text = GTK_STEXT(compose->text);