make the folder's default account to be used when replying. (patch by wwp <subscript...
[claws.git] / src / compose.c
index fe12cde6d663b91160d38ca7e66381fa23636c07..3cc2043477c57096e4dbc29b59c135a0c3a2f223 100644 (file)
@@ -442,7 +442,7 @@ static GtkItemFactoryEntry compose_entries[] =
                        "<alt>X", compose_ext_editor_cb, 0, NULL},
 
        {N_("/_Message"),               NULL, NULL, 0, "<Branch>"},
-       {N_("/_Message/_Send"),         "<shift><control>S",
+       {N_("/_Message/_Send"),         "<control>Return",
                                        compose_send_cb, 0, NULL},
        {N_("/_Message/Send _later"),   "<shift><alt>S",
                                        compose_send_later_cb,  0, NULL},
@@ -526,13 +526,8 @@ Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem
        if (account->protocol != A_NNTP) {
                if (to) {
                        compose_entry_append(compose, to, COMPOSE_TO);
-                       gtk_widget_grab_focus(compose->subject_entry);
-               } else {
-                       if(item && item->prefs->enable_default_to) {
-                               compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
-                       } else {
-                               gtk_widget_grab_focus(compose->header_last->entry);
-                       }
+               } else if(item && item->prefs->enable_default_to) {
+                       compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
                }
                if (item && item->ret_rcpt) {
                        GtkItemFactory *ifactory;
@@ -543,10 +538,9 @@ Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem
        } else {
                if (to) {
                        compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
-                       gtk_widget_grab_focus(compose->subject_entry);
-               } else
-                       gtk_widget_grab_focus(compose->header_last->entry);
+               }
        }
+       gtk_widget_grab_focus(compose->subject_entry);
 
        if (prefs_common.auto_exteditor)
                compose_exec_ext_editor(compose);
@@ -609,25 +603,51 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        PrefsAccount *account;
        PrefsAccount *reply_account;
        GtkSText *text;
+       GList *cur_ac;
+       GList *account_list;
+       PrefsAccount *ac_prefs;
 
        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);
+       /* select the account set in folderitem's property (if enabled) */
+       account = NULL;
+       if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account) {
+               if (!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 == msginfo->folder->prefs->default_account) {
+                                       account = ac_prefs;
+                                       break;
+                               }
+                       }
+               }
        }
-        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);
-                }        
+       
+       /* 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);
 
@@ -641,6 +661,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);
 
@@ -1045,6 +1066,7 @@ Compose *compose_forward(PrefsAccount * account, MsgInfo *msginfo,
        else
                gtk_widget_grab_focus(compose->newsgroups_entry);
 #endif
+       gtk_widget_grab_focus(compose->header_last->entry);
 
        if (prefs_common.auto_exteditor)
                compose_exec_ext_editor(compose);
@@ -1858,6 +1880,7 @@ static void compose_insert_file(Compose *compose, const gchar *file)
 {
        GtkSText *text = GTK_STEXT(compose->text);
        gchar buf[BUFFSIZE];
+       gint len;
        FILE *fp;
 
        g_return_if_fail(file != NULL);
@@ -1869,8 +1892,20 @@ static void compose_insert_file(Compose *compose, const gchar *file)
 
        gtk_stext_freeze(text);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL)
-               gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
+               len = strlen(buf);
+               if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
+                       buf[len - 2] = '\n';
+                       buf[len - 1] = '\0';
+               } else {
+                       while (--len > 0)
+                               if (buf[len] == '\r')
+                                       buf[len] = '\n';
+               }
+
+               gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
+       }
 
        gtk_stext_thaw(text);
 
@@ -2166,29 +2201,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) {
@@ -2257,24 +2269,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);
@@ -2550,14 +2544,16 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
                gchar *header;
                gchar *entry;
                header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((compose_headerentry *)list->data)->combo)->entry));
-               entry = gtk_entry_get_text(GTK_ENTRY(((compose_headerentry *)list->data)->entry));
-               if(strlen(entry)) {
+               entry = gtk_editable_get_chars(GTK_EDITABLE(((compose_headerentry *)list->data)->entry), 0, -1);
+               g_strstrip(entry);
+               if(entry[0] != '\0') {
                        for(strptr = recipient_headers; *strptr != NULL; strptr++) {
                                if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
                                        recipient_found = TRUE;
                                }
                        }
                }
+               g_free(entry);
        }
        return recipient_found;
 }
@@ -3141,18 +3137,20 @@ static gint compose_write_headers_from_headerlist(Compose *compose,
                        str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
                        Xstrdup_a(str, str, return -1);
                        g_strstrip(str);
-                       if(list_append_func)
-                               *dest_list = list_append_func(*dest_list, str);
-                       compose_convert_header
-                               (buf, sizeof(buf), str,
-                               strlen(header) + 2);
-                       if(first_address) {
-                               fprintf(fp, "%s: ", header);
-                               first_address = FALSE;
-                       } else {
-                               fprintf(fp, ", ");
+                       if(str[0] != '\0') {
+                               if(list_append_func)
+                                       *dest_list = list_append_func(*dest_list, str);
+                               compose_convert_header
+                                       (buf, sizeof(buf), str,
+                                       strlen(header) + 2);
+                               if(first_address) {
+                                       fprintf(fp, "%s: ", header);
+                                       first_address = FALSE;
+                               } else {
+                                       fprintf(fp, ", ");
+                               }
+                               fprintf(fp, "%s", buf);
                        }
-                       fprintf(fp, "%s", buf);
                }
        }
        if(!first_address) {
@@ -4129,6 +4127,12 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                                   account->auto_replyto);
 #endif
        }
+       if (account->protocol != A_NNTP) {
+               gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
+       } else {
+               gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
+       }
+
        menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
                                       prefs_common.show_ruler);