2009-02-17 [colin] 3.7.0cvs67
[claws.git] / src / compose.c
index 6f4b210d333d958a1f7d1363417209981bdeaed7..8a1db79b7fc1ea7e62463b5ea7e926cc4528e99f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2009 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
 #include "privacy.h"
 #include "timing.h"
 #include "autofaces.h"
+#include "spell_entry.h"
 
 enum
 {
@@ -238,7 +239,6 @@ static void compose_reedit_set_entry                (Compose        *compose,
 
 static void compose_insert_sig                 (Compose        *compose,
                                                 gboolean        replace);
-static gchar *compose_get_signature_str                (Compose        *compose);
 static ComposeInsertResult compose_insert_file (Compose        *compose,
                                                 const gchar    *file);
 
@@ -332,8 +332,9 @@ static void compose_add_header_entry        (Compose *compose, const gchar *header, gch
 static void compose_remove_header_entries(Compose *compose);
 
 static void compose_update_priority_menu_item(Compose * compose);
-#if USE_ASPELL
+#if USE_ENCHANT
 static void compose_spell_menu_changed (void *data);
+static void compose_dict_changed       (void *data);
 #endif
 static void compose_add_field_list     ( Compose *compose,
                                          GList *listAddress );
@@ -423,6 +424,8 @@ static void compose_find_cb         (GtkAction      *action,
                                         gpointer        data);
 static void compose_toggle_autowrap_cb (GtkToggleAction *action,
                                         gpointer        data);
+static void compose_toggle_autoindent_cb(GtkToggleAction *action,
+                                        gpointer        data);
 
 static void compose_toggle_ruler_cb    (GtkToggleAction *action,
                                         gpointer        data);
@@ -503,7 +506,7 @@ static void compose_nothing_cb                 (GtkAction *action, gpointer data)
 
 }
 
-#if USE_ASPELL
+#if USE_ENCHANT
 static void compose_check_all             (GtkAction *action, gpointer data);
 static void compose_highlight_all         (GtkAction *action, gpointer data);
 static void compose_check_backwards       (GtkAction *action, gpointer data);
@@ -515,7 +518,7 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo     (MsgInfo *msginf
 
 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
                                                FolderItem *folder_item);
 #endif
@@ -538,7 +541,7 @@ static GtkActionEntry compose_entries[] =
 /* menus */
        {"Message",                     NULL, N_("_Message") },
        {"Edit",                        NULL, N_("_Edit") },
-#if USE_ASPELL
+#if USE_ENCHANT
        {"Spelling",                    NULL, N_("_Spelling") },
 #endif
        {"Options",                     NULL, N_("_Options") },
@@ -597,7 +600,7 @@ static GtkActionEntry compose_entries[] =
        {"Edit/WrapAllLines",           NULL, N_("Wrap all long _lines"), "<control><alt>L", NULL, G_CALLBACK(compose_wrap_all_cb) }, /* 1 */
        /* {"Edit/---",                 NULL, "---" }, */
        {"Edit/ExtEditor",              NULL, N_("Edit with e_xternal editor"), "<shift><control>X", NULL, G_CALLBACK(compose_ext_editor_cb) },
-#if USE_ASPELL
+#if USE_ENCHANT
 /* Spelling menu */
        {"Spelling/CheckAllSel",        NULL, N_("_Check all or check selection"), NULL, NULL, G_CALLBACK(compose_check_all) },
        {"Spelling/HighlightAll",       NULL, N_("_Highlight all misspelled words"), NULL, NULL, G_CALLBACK(compose_highlight_all) },
@@ -649,6 +652,7 @@ static GtkActionEntry compose_entries[] =
 static GtkToggleActionEntry compose_toggle_entries[] =
 {
        {"Edit/AutoWrap",               NULL, N_("Aut_o wrapping"), "<shift><control>L", NULL, G_CALLBACK(compose_toggle_autowrap_cb) }, /* TOGGLE */
+       {"Edit/AutoIndent",             NULL, N_("Auto _indent"), NULL, NULL, G_CALLBACK(compose_toggle_autoindent_cb) }, /* TOGGLE */
        {"Options/Sign",                NULL, N_("Si_gn"), NULL, NULL, G_CALLBACK(compose_toggle_sign_cb) }, /* Toggle */
        {"Options/Encrypt",             NULL, N_("_Encrypt"), NULL, NULL, G_CALLBACK(compose_toggle_encrypt_cb) }, /* Toggle */
        {"Options/RequestRetRcpt",      NULL, N_("_Request Return Receipt"), NULL, NULL, G_CALLBACK(compose_toggle_return_receipt_cb) }, /* TOGGLE */
@@ -675,21 +679,21 @@ static GtkRadioActionEntry compose_radio_prio_entries[] =
 
 static GtkRadioActionEntry compose_radio_enc_entries[] =
 {
-       ENC_ACTION(CS_AUTO, C_AUTO, "_Automatic"), /* RADIO compose_set_encoding_cb */
-       ENC_ACTION(CS_US_ASCII, C_US_ASCII, "7bit ASCII (US-ASC_II)"), /* RADIO compose_set_encoding_cb */
-       ENC_ACTION(CS_UTF_8, C_UTF_8, "Unicode (_UTF-8)"), /* RADIO compose_set_encoding_cb */
+       ENC_ACTION(CS_AUTO, C_AUTO, N_("_Automatic")), /* RADIO compose_set_encoding_cb */
+       ENC_ACTION(CS_US_ASCII, C_US_ASCII, N_("7bit ASCII (US-ASC_II)")), /* RADIO compose_set_encoding_cb */
+       ENC_ACTION(CS_UTF_8, C_UTF_8, N_("Unicode (_UTF-8)")), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Western/"CS_ISO_8859_1, C_ISO_8859_1, "ISO-8859-_1"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Western/"CS_ISO_8859_15, C_ISO_8859_15, "ISO-8859-15"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Western/"CS_WINDOWS_1252, C_WINDOWS_1252, "Windows-1252"), /* RADIO compose_set_encoding_cb */
-       ENC_ACTION(CS_ISO_8859_2, C_ISO_8859_2, "Central European (ISO-8859-_2)"), /* RADIO compose_set_encoding_cb */
+       ENC_ACTION(CS_ISO_8859_2, C_ISO_8859_2, N_("Central European (ISO-8859-_2)")), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Baltic/"CS_ISO_8859_13, C_ISO_8859_13, "ISO-8859-13"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Baltic/"CS_ISO_8859_4, C_ISO_8859_14, "ISO-8859-_4"), /* RADIO compose_set_encoding_cb */
-       ENC_ACTION(CS_ISO_8859_7, C_ISO_8859_7, "Greek (ISO-8859-_7)"), /* RADIO compose_set_encoding_cb */
+       ENC_ACTION(CS_ISO_8859_7, C_ISO_8859_7, N_("Greek (ISO-8859-_7)")), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Hebrew/"CS_ISO_8859_8, C_ISO_8859_8, "ISO-8859-_8"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Hebrew/"CS_WINDOWS_1255, C_WINDOWS_1255, "Windows-1255"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Arabic/"CS_ISO_8859_6, C_ISO_8859_6, "ISO-8859-_6"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Arabic/"CS_WINDOWS_1256, C_WINDOWS_1256, "Windows-1256"), /* RADIO compose_set_encoding_cb */
-       ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, "Turkish (ISO-8859-_9)"), /* RADIO compose_set_encoding_cb */
+       ENC_ACTION(CS_ISO_8859_9, C_ISO_8859_9, N_("Turkish (ISO-8859-_9)")), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Cyrillic/"CS_ISO_8859_5, C_ISO_8859_5, "ISO-8859-_5"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Cyrillic/"CS_KOI8_R, C_KOI8_R, "KOI8-_R"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO compose_set_encoding_cb */
@@ -884,6 +888,41 @@ Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
                cmark);                                         \
 }
 
+static void compose_set_save_to(Compose *compose, const gchar *folderidentifier)
+{
+       GtkEditable *entry;
+       if (folderidentifier) {
+               combobox_unset_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo));
+               prefs_common.compose_save_to_history = add_history(
+                               prefs_common.compose_save_to_history, folderidentifier);
+               combobox_set_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo),
+                               prefs_common.compose_save_to_history);
+       }
+
+       entry = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(compose->savemsg_combo)));
+       if (folderidentifier)
+               gtk_entry_set_text(GTK_ENTRY(entry), folderidentifier);
+       else
+               gtk_entry_set_text(GTK_ENTRY(entry), "");
+}
+
+static gchar *compose_get_save_to(Compose *compose)
+{
+       GtkEditable *entry;
+       gchar *result = NULL;
+       entry = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(compose->savemsg_combo)));
+       result = gtk_editable_get_chars(entry, 0, -1);
+       
+       if (result) {
+               combobox_unset_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo));
+               prefs_common.compose_save_to_history = add_history(
+                               prefs_common.compose_save_to_history, result);
+               combobox_set_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo),
+                               prefs_common.compose_save_to_history);
+       }
+       return result;
+}
+
 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
                             GPtrArray *attach_files, GList *listAddress )
 {
@@ -939,7 +978,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        tmp = malloc(strlen(item->prefs->compose_override_from_format)+1);
                        pref_get_unescaped_pref(tmp, item->prefs->compose_override_from_format);
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                        quote_fmt_init(dummyinfo, NULL, NULL, FALSE, compose->account, FALSE,
                                        compose->gtkaspell);
 #else
@@ -966,7 +1005,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        compose_create_tags(textview, compose);
 
        undo_block(compose->undostruct);
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
        compose_set_dictionaries_from_folder_prefs(compose, item);
 #endif
 
@@ -1031,7 +1070,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        pref_get_unescaped_pref(tmp, subject_format);
 
                        subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                        quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account, FALSE,
                                        compose->gtkaspell);
 #else
@@ -1100,7 +1139,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
                folderidentifier = folder_item_get_identifier(item);
-               gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
+               compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        }
        
@@ -1120,9 +1159,9 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 }
 
 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
-               gboolean override_pref)
+               gboolean override_pref, const gchar *system)
 {
-       gchar *privacy = NULL;
+       const gchar *privacy = NULL;
 
        g_return_if_fail(compose != NULL);
        g_return_if_fail(account != NULL);
@@ -1130,7 +1169,9 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
        if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
                return;
 
-       if (account->default_privacy_system
+       if (system)
+               privacy = system;
+       else if (account->default_privacy_system
        &&  strlen(account->default_privacy_system)) {
                privacy = account->default_privacy_system;
        } else {
@@ -1140,6 +1181,10 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
                }
        }
        if (privacy != NULL) {
+               if (system) {
+                       g_free(compose->privacy_system);
+                       compose->privacy_system = NULL;
+               }
                if (compose->privacy_system == NULL)
                        compose->privacy_system = g_strdup(privacy);
                else if (*(compose->privacy_system) == '\0') {
@@ -1151,11 +1196,13 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
        }
 }      
 
-static void compose_force_signing(Compose *compose, PrefsAccount *account)
+static void compose_force_signing(Compose *compose, PrefsAccount *account, const gchar *system)
 {
        gchar *privacy = NULL;
 
-       if (account->default_privacy_system
+       if (system)
+               privacy = system;
+       else if (account->default_privacy_system
        &&  strlen(account->default_privacy_system)) {
                privacy = account->default_privacy_system;
        } else {
@@ -1164,7 +1211,12 @@ static void compose_force_signing(Compose *compose, PrefsAccount *account)
                        privacy = (gchar *)(privacy_avail->data);
                }
        }
+
        if (privacy != NULL) {
+               if (system) {
+                       g_free(compose->privacy_system);
+                       compose->privacy_system = NULL;
+               }
                if (compose->privacy_system == NULL)
                        compose->privacy_system = g_strdup(privacy);
                compose_update_privacy_system_menu_item(compose, FALSE);
@@ -1381,6 +1433,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
        gboolean quote = FALSE;
        const gchar *qmark = NULL;
        const gchar *body_fmt = NULL;
+       gchar *s_system = NULL;
        START_TIMING("");
        g_return_val_if_fail(msginfo != NULL, NULL);
        g_return_val_if_fail(msginfo->folder != NULL, NULL);
@@ -1411,7 +1464,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
                folderidentifier = folder_item_get_identifier(msginfo->folder);
-               gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
+               compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        }
 
@@ -1434,7 +1487,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                tmp = malloc(strlen(msginfo->folder->prefs->reply_override_from_format)+1);
                pref_get_unescaped_pref(tmp, msginfo->folder->prefs->reply_override_from_format);
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(compose->replyinfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -1458,7 +1511,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
        compose_create_tags(textview, compose);
 
        undo_block(compose->undostruct);
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
 #endif
 
@@ -1498,8 +1551,14 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
        }
 
        if (MSG_IS_ENCRYPTED(compose->replyinfo->flags)) {
-               compose_force_encryption(compose, account, FALSE);
+               compose_force_encryption(compose, account, FALSE, s_system);
+       }
+
+       privacy_msginfo_get_signed_state(compose->replyinfo, &s_system);
+       if (MSG_IS_SIGNED(compose->replyinfo->flags) && account->default_sign_reply) {
+               compose_force_signing(compose, account, s_system);
        }
+       g_free(s_system);
 
        SIGNAL_BLOCK(textbuf);
        
@@ -1599,7 +1658,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
                pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -1706,7 +1765,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
                folderidentifier = folder_item_get_identifier(msginfo->folder);
-               gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
+               compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        }
 
@@ -1781,7 +1840,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                        tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
                        pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                        quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                        compose->gtkaspell);
 #else
@@ -1959,6 +2018,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        int priority = PRIORITY_NORMAL;
        MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
        gboolean autowrap = prefs_common.autowrap;
+       gboolean autoindent = prefs_common.auto_indent;
 
        g_return_val_if_fail(msginfo != NULL, NULL);
        g_return_val_if_fail(msginfo->folder != NULL, NULL);
@@ -2024,6 +2084,11 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                        param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Wrapping:")]);
                        autowrap = param;
                }
+               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
+                                            sizeof(queueheader_buf), "X-Claws-Auto-Indent:")) {
+                       param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Indent:")]);
+                       autoindent = param;
+               }
                 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
                                             sizeof(queueheader_buf), "X-Claws-Privacy-System:")) {
                         privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]);
@@ -2078,6 +2143,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        compose = compose_create(account, msginfo->folder, COMPOSE_REEDIT, batch);
 
        cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoWrap", autowrap);
+       cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoIndent", autoindent);
        compose->autowrap = autowrap;
        compose->replyinfo = replyinfo;
        compose->fwdinfo = fwdinfo;
@@ -2104,11 +2170,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
 
                /* Set message save folder */
                if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
-                       gint startpos = 0;
-
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
-                       gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
-                       gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
+                       compose_set_save_to(compose, &queueheader_buf[4]);
                }
                if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
                        gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
@@ -2139,7 +2202,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        if (MSG_IS_ENCRYPTED(msginfo->flags)) {
                fp = procmime_get_first_encrypted_text_content(msginfo);
                if (fp) {
-                       compose_force_encryption(compose, account, TRUE);
+                       compose_force_encryption(compose, account, TRUE, NULL);
                }
        } else {
                fp = procmime_get_first_text_content(msginfo);
@@ -2185,7 +2248,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                return NULL;
        }
        
-       compose->sig_str = compose_get_signature_str(compose);
+       compose->sig_str = account_get_signature_str(compose->account);
        
        return compose;
 }
@@ -2234,7 +2297,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
                folderidentifier = folder_item_get_identifier(item);
-               gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
+               compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        }
 
@@ -2436,7 +2499,7 @@ void compose_toolbar_cb(gint action, gpointer data)
        case A_ADDRBOOK:
                compose_address_cb(NULL, compose);
                break;
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
        case A_CHECK_SPELLING:
                compose_check_all(NULL, compose);
                break;
@@ -2751,7 +2814,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
        }
 
        if (qmark != NULL) {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -2773,7 +2836,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                        while (*trimmed_body == '\n')
                                trimmed_body++;
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -3185,7 +3248,7 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
        } 
 
        g_free(compose->sig_str);
-       compose->sig_str = compose_get_signature_str(compose);
+       compose->sig_str = account_get_signature_str(compose->account);
 
        cur_pos = gtk_text_iter_get_offset(&iter);
 
@@ -3216,7 +3279,8 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
        else
                gtk_text_buffer_get_iter_at_offset(buffer, &iter, 
                        compose->set_cursor_pos);
-               
+       
+       compose->set_cursor_pos = -1;
        gtk_text_buffer_place_cursor(buffer, &iter);
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                        G_CALLBACK(compose_changed_cb),
@@ -3225,58 +3289,6 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
        UNBLOCK_WRAP();
 }
 
-static gchar *compose_get_signature_str(Compose *compose)
-{
-       gchar *sig_body = NULL;
-       gchar *sig_str = NULL;
-       gchar *utf8_sig_str = NULL;
-
-       g_return_val_if_fail(compose->account != NULL, NULL);
-
-       if (!compose->account->sig_path)
-               return NULL;
-
-       if (compose->account->sig_type == SIG_FILE) {
-               if (!is_file_or_fifo_exist(compose->account->sig_path)) {
-                       g_warning("can't open signature file: %s\n",
-                                 compose->account->sig_path);
-                       return NULL;
-               }
-       }
-
-       if (compose->account->sig_type == SIG_COMMAND)
-               sig_body = get_command_output(compose->account->sig_path);
-       else {
-               gchar *tmp;
-
-               tmp = file_read_to_str(compose->account->sig_path);
-               if (!tmp)
-                       return NULL;
-               sig_body = normalize_newlines(tmp);
-               g_free(tmp);
-       }
-
-       if (compose->account->sig_sep) {
-               sig_str = g_strconcat("\n", compose->account->sig_sep, "\n", sig_body,
-                                     NULL);
-               g_free(sig_body);
-       } else
-               sig_str = g_strconcat("\n", sig_body, NULL);
-
-       if (sig_str) {
-               if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
-                       utf8_sig_str = sig_str;
-               else {
-                       utf8_sig_str = conv_codeset_strdup
-                               (sig_str, conv_get_locale_charset_str_no_utf8(),
-                                CS_INTERNAL);
-                       g_free(sig_str);
-               }
-       }
-
-       return utf8_sig_str;
-}
-
 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
 {
        GtkTextView *text;
@@ -3568,7 +3580,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                                compose_attach_append(compose, outfile, 
                                                      partname, content_type);
                        } else {
-                               compose_force_signing(compose, compose->account);
+                               compose_force_signing(compose, compose->account, NULL);
                        }
                        g_free(content_type);
                }
@@ -3856,7 +3868,7 @@ static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
                can_break = TRUE;
        }
 
-       debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
+//     debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
 
        g_free(attrs);
        g_free(str);
@@ -4101,7 +4113,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
                quote_str = compose_get_quote_str(buffer, &iter, &quote_len);
 
                if (quote_str) {
-                       debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
+//                     debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
                        if (startq_offset == -1) 
                                startq_offset = gtk_text_iter_get_offset(&iter);
                        quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
@@ -4135,7 +4147,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
                                modified = TRUE;
                                gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
                                compose->automatic_break = FALSE;
-                               if (itemized_len) {
+                               if (itemized_len && compose->autoindent) {
                                        gtk_text_buffer_insert(buffer, &break_pos, itemized_chars, -1);
                                        if (!item_continuation)
                                                gtk_text_buffer_insert(buffer, &break_pos, "  ", 2);
@@ -4145,7 +4157,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
                                modified = TRUE;
                                gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
                                compose->automatic_break = FALSE;
-                               if (itemized_len) {
+                               if (itemized_len && compose->autoindent) {
                                        gtk_text_buffer_insert(buffer, &break_pos, itemized_chars, -1);
                                        if (!item_continuation)
                                                gtk_text_buffer_insert(buffer, &break_pos, "  ", 2);
@@ -4155,7 +4167,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
                        /* remove trailing spaces */
                        cur = break_pos;
                        rem_item_len = itemized_len;
-                       while (rem_item_len-- > 0)
+                       while (compose->autoindent && rem_item_len-- > 0)
                                gtk_text_iter_backward_char(&cur);
                        gtk_text_iter_backward_char(&cur);
 
@@ -4347,11 +4359,11 @@ colorize:
                        }
                }
                if (!modified) {
-                       debug_print("not modified, out after %d lines\n", lines);
+//                     debug_print("not modified, out after %d lines\n", lines);
                        goto end;
                }
        }
-       debug_print("modified, out after %d lines\n", lines);
+//     debug_print("modified, out after %d lines\n", lines);
 end:
        g_free(itemized_chars);
        if (par_iter)
@@ -4537,7 +4549,7 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
                undo_unblock(compose->undostruct);
        }
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
        /* use account's dict info if set */
        if (compose->gtkaspell) {
                if (account->enable_default_dictionary)
@@ -5038,7 +5050,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                "X-Claws-End-Special-Headers:",                 "X-Claws-Account-Id:",
                "X-Sylpheed-Privacy",   "X-Sylpheed-Sign:",     "X-Sylpheed-Encrypt",
                "X-Sylpheed-End-Special-Headers:",              "X-Sylpheed-Account-Id:",
-               "X-Claws-Auto-Wrapping:",
+               "X-Claws-Auto-Wrapping:", "X-Claws-Auto-Indent:",
                NULL
                };
        if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
@@ -5116,6 +5128,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        MimeInfo *mimemsg, *mimetext;
        gint line;
        const gchar *src_codeset = CS_INTERNAL;
+       gchar *from_addr = NULL;
+       gchar *from_name = NULL;
 
        if (action == COMPOSE_WRITE_FOR_SEND)
                attach_parts = TRUE;
@@ -5299,12 +5313,31 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
 
        g_free(buf);
 
+       if (strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) != 0) {
+               gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
+               /* extract name and address */
+               if (strstr(spec, " <") && strstr(spec, ">")) {
+                       from_addr = g_strdup(strrchr(spec, '<')+1);
+                       *(strrchr(from_addr, '>')) = '\0';
+                       from_name = g_strdup(spec);
+                       *(strrchr(from_name, '<')) = '\0';
+               } else {
+                       from_name = NULL;
+                       from_addr = NULL;
+               }
+               g_free(spec);
+       }
        /* sign message if sending */
        if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && 
            privacy_system_can_sign(compose->privacy_system))
-               if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
+               if (!privacy_sign(compose->privacy_system, mimemsg, 
+                       compose->account, from_addr)) {
+                       g_free(from_name);
+                       g_free(from_addr);
                        return -2;
-
+       }
+       g_free(from_name);
+       g_free(from_addr);
        procmime_write_mimeinfo(mimemsg, fp);
        
        procmime_mimeinfo_free_all(mimemsg);
@@ -5595,7 +5628,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
                gchar *savefolderid;
                
-               savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
+               savefolderid = compose_get_save_to(compose);
                err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
                g_free(savefolderid);
        }
@@ -5621,6 +5654,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
        err |= (fprintf(fp, "X-Claws-Auto-Wrapping:%d\n", compose->autowrap) < 0);
+       err |= (fprintf(fp, "X-Claws-Auto-Indent:%d\n", compose->autoindent) < 0);
 
        /* end of headers */
        err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
@@ -5723,7 +5757,7 @@ static void compose_add_attachments(Compose *compose, MimeInfo *parent)
                mimepart->tmp = FALSE; /* or we destroy our attachment */
                mimepart->offset = 0;
 
-               stat(ainfo->file, &statbuf);
+               g_stat(ainfo->file, &statbuf);
                mimepart->length = statbuf.st_size;
 
                type = g_strdup(ainfo->content_type);
@@ -5744,8 +5778,10 @@ static void compose_add_attachments(Compose *compose, MimeInfo *parent)
                        mimepart->disposition = DISPOSITIONTYPE_INLINE;
                } else {
                        if (ainfo->name) {
-                               g_hash_table_insert(mimepart->typeparameters,
-                                           g_strdup("name"), g_strdup(ainfo->name));
+                               if (mimepart->type == MIMETYPE_APPLICATION && 
+                                  !strcmp2(mimepart->subtype, "octet-stream"))
+                                       g_hash_table_insert(mimepart->typeparameters,
+                                                   g_strdup("name"), g_strdup(ainfo->name));
                                g_hash_table_insert(mimepart->dispositionparameters,
                                            g_strdup("filename"), g_strdup(ainfo->name));
                                mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
@@ -6478,7 +6514,7 @@ static GtkWidget *compose_create_others(Compose *compose)
 {
        GtkWidget *table;
        GtkWidget *savemsg_checkbtn;
-       GtkWidget *savemsg_entry;
+       GtkWidget *savemsg_combo;
        GtkWidget *savemsg_select;
        
        guint rowcount = 0;
@@ -6501,16 +6537,23 @@ static GtkWidget *compose_create_others(Compose *compose)
        g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
                         G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
 
-       savemsg_entry = gtk_entry_new();
-       gtk_widget_show(savemsg_entry);
-       gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
-       gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
-       g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
+       savemsg_combo = gtk_combo_box_entry_new_text();
+       compose->savemsg_checkbtn = savemsg_checkbtn;
+       compose->savemsg_combo = savemsg_combo;
+       gtk_widget_show(savemsg_combo);
+
+       if (prefs_common.compose_save_to_history)
+               combobox_set_popdown_strings(GTK_COMBO_BOX(savemsg_combo),
+                               prefs_common.compose_save_to_history);
+
+       gtk_table_attach(GTK_TABLE(table), savemsg_combo, 1, 2, rowcount, rowcount + 1, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
+       gtk_widget_set_sensitive(GTK_WIDGET(savemsg_combo), prefs_common.savemsg);
+       g_signal_connect_after(G_OBJECT(savemsg_combo), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
        if (account_get_special_folder(compose->account, F_OUTBOX)) {
                folderidentifier = folder_item_get_identifier(account_get_special_folder
                                  (compose->account, F_OUTBOX));
-               gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
+               compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        }
 
@@ -6523,15 +6566,12 @@ static GtkWidget *compose_create_others(Compose *compose)
 
        rowcount++;
 
-       compose->savemsg_checkbtn = savemsg_checkbtn;
-       compose->savemsg_entry = savemsg_entry;
-
        return table;   
 }
 
 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose) 
 {
-       gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
+       gtk_widget_set_sensitive(GTK_WIDGET(compose->savemsg_combo),
                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
 }
 
@@ -6545,7 +6585,7 @@ static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
 
        path = folder_item_get_identifier(dest);
 
-       gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
+       compose_set_save_to(compose, path);
        g_free(path);
 }
 
@@ -6558,7 +6598,7 @@ static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
 {
        gint prev_autowrap;
        GtkTextBuffer *buffer = GTK_TEXT_VIEW(text)->buffer;
-#if USE_ASPELL
+#if USE_ENCHANT
        if (event->button == 3) {
                GtkTextIter iter;
                GtkTextIter sel_start, sel_end;
@@ -6612,7 +6652,7 @@ static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
        return FALSE;
 }
 
-#if USE_ASPELL
+#if USE_ENCHANT
 static void compose_spell_menu_changed(void *data)
 {
        Compose *compose = (Compose *)data;
@@ -6649,7 +6689,18 @@ static void compose_spell_menu_changed(void *data)
        g_slist_free(spell_menu);
 
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
-       
+       gtk_widget_show(parent_item);
+}
+
+static void compose_dict_changed(void *data)
+{
+       Compose *compose = (Compose *) data;
+
+       if(compose->gtkaspell->recheck_when_changing_dict == FALSE)
+               return;
+
+       gtkaspell_highlight_all(compose->gtkaspell);
+       claws_spell_entry_recheck_all(CLAWS_SPELL_ENTRY(compose->subject_entry));
 }
 #endif
 
@@ -6709,7 +6760,7 @@ static Compose *compose_create(PrefsAccount *account,
        GtkWidget *tmpl_menu;
        GtkActionGroup *action_group = NULL;
 
-#if USE_ASPELL
+#if USE_ENCHANT
         GtkAspell * gtkaspell = NULL;
 #endif
 
@@ -6749,7 +6800,7 @@ static Compose *compose_create(PrefsAccount *account,
                                      &geometry, GDK_HINT_MAX_SIZE);
        if (!geometry.min_width) {
                geometry.min_width = 600;
-               geometry.min_height = 480;
+               geometry.min_height = 440;
        }
        gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
                                      &geometry, GDK_HINT_MIN_SIZE);
@@ -6784,12 +6835,12 @@ static Compose *compose_create(PrefsAccount *account,
 #ifndef MAEMO
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
 #else
-       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_POPUP)
 #endif
 
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Message", "Message", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Spelling", "Spelling", GTK_UI_MANAGER_MENU)
 #endif
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Options", "Options", GTK_UI_MANAGER_MENU)
@@ -6846,12 +6897,13 @@ static Compose *compose_create(PrefsAccount *account,
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "WrapPara", "Edit/WrapPara", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "WrapAllLines", "Edit/WrapAllLines", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "AutoWrap", "Edit/AutoWrap", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "AutoIndent", "Edit/AutoIndent", GTK_UI_MANAGER_MENUITEM)
 
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "Separator3", "Edit/---", GTK_UI_MANAGER_SEPARATOR)
 
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Edit", "ExtEditor", "Edit/ExtEditor", GTK_UI_MANAGER_MENUITEM)
 
-#if USE_ASPELL
+#if USE_ENCHANT
 /* Spelling menu */
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "CheckAllSel", "Spelling/CheckAllSel", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Spelling", "HighlightAll", "Spelling/HighlightAll", GTK_UI_MANAGER_MENUITEM)
@@ -7034,7 +7086,11 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
        gtk_widget_show(label);
 
+#ifdef USE_ENCHANT
+       subject_entry = claws_spell_entry_new();
+#else
        subject_entry = gtk_entry_new();
+#endif
        gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
        g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
@@ -7201,7 +7257,7 @@ static Compose *compose_create(PrefsAccount *account,
        compose->boundary    = NULL;
 
        compose->autowrap       = prefs_common.autowrap;
-
+       compose->autoindent     = prefs_common.auto_indent;
        compose->use_signing    = FALSE;
        compose->use_encryption = FALSE;
        compose->privacy_system = NULL;
@@ -7222,13 +7278,12 @@ static Compose *compose_create(PrefsAccount *account,
        compose->exteditor_tag     = -1;
        compose->draft_timeout_tag = -2; /* inhibit auto-drafting while loading */
 
-#if USE_ASPELL
+#if USE_ENCHANT
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", FALSE);
        if (mode != COMPOSE_REDIRECT) {
                if (prefs_common.enable_aspell && prefs_common.dictionary &&
                    strcmp(prefs_common.dictionary, "")) {
-                       gtkaspell = gtkaspell_new(prefs_common.aspell_path,
-                                                 prefs_common.dictionary,
+                       gtkaspell = gtkaspell_new(prefs_common.dictionary,
                                                  prefs_common.alt_dictionary,
                                                  conv_get_locale_charset_str(),
                                                  prefs_common.misspelled_col,
@@ -7238,6 +7293,7 @@ static Compose *compose_create(PrefsAccount *account,
                                                  prefs_common.use_both_dicts,
                                                  GTK_TEXT_VIEW(text),
                                                  GTK_WINDOW(compose->window),
+                                                 compose_dict_changed,
                                                  compose_spell_menu_changed,
                                                  compose);
                        if (!gtkaspell) {
@@ -7246,25 +7302,19 @@ static Compose *compose_create(PrefsAccount *account,
                                                gtkaspell_checkers_strerror());
                                gtkaspell_checkers_reset_error();
                        } else {
-                               if (!gtkaspell_set_sug_mode(gtkaspell,
-                                               prefs_common.aspell_sugmode)) {
-                                       debug_print("Aspell: could not set "
-                                                   "suggestion mode %s\n",
-                                                   gtkaspell_checkers_strerror());
-                                       gtkaspell_checkers_reset_error();
-                               }
-
                                cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", TRUE);
                        }
                }
        }
         compose->gtkaspell = gtkaspell;
        compose_spell_menu_changed(compose);
+       claws_spell_entry_set_gtkaspell(CLAWS_SPELL_ENTRY(subject_entry), gtkaspell);
 #endif
 
        compose_select_account(compose, account, TRUE);
 
        cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoWrap", prefs_common.autowrap);
+       cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoIndent", prefs_common.auto_indent);
 
        if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
                compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
@@ -7858,7 +7908,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        }
 
        if (tmpl->from && *tmpl->from != '\0') {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -7876,7 +7926,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        }
 
        if (tmpl->to && *tmpl->to != '\0') {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -7894,7 +7944,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        }
 
        if (tmpl->cc && *tmpl->cc != '\0') {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -7912,7 +7962,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        }
 
        if (tmpl->bcc && *tmpl->bcc != '\0') {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -7931,7 +7981,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
        /* process the subject */
        if (tmpl->subject && *tmpl->subject != '\0') {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -8006,15 +8056,17 @@ static void compose_destroy(Compose *compose)
        if (addressbook_get_target_compose() == compose)
                addressbook_set_target_compose(NULL);
 
-#if USE_ASPELL
+#if USE_ENCHANT
         if (compose->gtkaspell) {
                gtkaspell_delete(compose->gtkaspell);
                compose->gtkaspell = NULL;
         }
 #endif
 
-       prefs_common.compose_width = compose->scrolledwin->allocation.width;
-       prefs_common.compose_height = compose->window->allocation.height;
+       if (!compose->batch) {
+               prefs_common.compose_width = compose->scrolledwin->allocation.width;
+               prefs_common.compose_height = compose->window->allocation.height;
+       }
 
        if (!gtk_widget_get_parent(compose->paned))
                gtk_widget_destroy(compose->paned);
@@ -8410,6 +8462,10 @@ static gboolean attach_property_key_pressed(GtkWidget *widget,
                *cancelled = TRUE;
                gtk_main_quit();
        }
+       if (event && event->keyval == GDK_Return) {
+               *cancelled = FALSE;
+               gtk_main_quit();
+       }
        return FALSE;
 }
 
@@ -8444,7 +8500,11 @@ static void compose_exec_ext_editor(Compose *compose)
 
                compose_set_ext_editor_sensitive(compose, FALSE);
 
+#ifndef G_OS_WIN32
                compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
+#else
+               compose->exteditor_ch = g_io_channel_win32_new_fd(pipe_fds[0]);
+#endif
                compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
                                                        G_IO_IN,
                                                        compose_input_cb,
@@ -8510,7 +8570,7 @@ static gint compose_exec_ext_editor_real(const gchar *file)
                g_snprintf(buf, sizeof(buf), prefs_common_get_ext_editor_cmd(), file);
        } else {
                if (prefs_common_get_ext_editor_cmd())
-                       g_warning("External editor command line is invalid: '%s'\n",
+                       g_warning("External editor command-line is invalid: '%s'\n",
                                  prefs_common_get_ext_editor_cmd());
                g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
        }
@@ -8594,6 +8654,7 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
                gtk_text_buffer_set_text(buffer, "", -1);
                compose_insert_file(compose, compose->exteditor_file);
                compose_changed_cb(NULL, compose);
+               compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
 
                if (claws_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
@@ -8762,11 +8823,11 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
        g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
                         G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
                           
-       gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
+       compose_set_save_to(compose, NULL);
        if (account_get_special_folder(compose->account, F_OUTBOX)) {
                folderidentifier = folder_item_get_identifier(account_get_special_folder
                                  (compose->account, F_OUTBOX));
-               gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
+               compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        }
 }
@@ -8827,7 +8888,7 @@ static void compose_allow_user_actions (Compose *compose, gboolean allow)
        toolbar_comp_set_sensitive(compose, allow);
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message", allow);
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit", allow);
-#if USE_ASPELL
+#if USE_ENCHANT
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", allow);
 #endif 
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options", allow);
@@ -8862,7 +8923,9 @@ static void compose_send_later_cb(GtkAction *action, gpointer data)
        gint val;
 
        inc_lock();
+       compose_allow_user_actions(compose, FALSE);
        val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
+       compose_allow_user_actions(compose, TRUE);
        inc_unlock();
 
        if (!val) {
@@ -8892,7 +8955,7 @@ static void compose_register_draft(MsgInfo *info)
 {
        gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                      DRAFTED_AT_EXIT, NULL);
-       FILE *fp = fopen(filepath, "ab");
+       FILE *fp = g_fopen(filepath, "ab");
        
        if (fp) {
                fprintf(fp, "%s\t%d\n", folder_item_get_identifier(info->folder), 
@@ -8955,7 +9018,7 @@ gboolean compose_draft (gpointer data, guint action)
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
                gchar *savefolderid;
 
-               savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
+               savefolderid = compose_get_save_to(compose);
                err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
                g_free(savefolderid);
        }
@@ -8986,6 +9049,7 @@ gboolean compose_draft (gpointer data, guint action)
        }
 
        err |= (fprintf(fp, "X-Claws-Auto-Wrapping:%d\n", compose->autowrap) < 0);
+       err |= (fprintf(fp, "X-Claws-Auto-Indent:%d\n", compose->autoindent) < 0);
 
        /* end of headers */
        err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
@@ -9138,7 +9202,7 @@ void compose_reopen_exit_drafts(void)
 {
        gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                      DRAFTED_AT_EXIT, NULL);
-       FILE *fp = fopen(filepath, "rb");
+       FILE *fp = g_fopen(filepath, "rb");
        gchar buf[1024];
        
        if (fp) {
@@ -9163,7 +9227,9 @@ void compose_reopen_exit_drafts(void)
 
 static void compose_save_cb(GtkAction *action, gpointer data)
 {
-       compose_draft(data, COMPOSE_KEEP_EDITING);
+       Compose *compose = (Compose *)data;
+       compose_draft(compose, COMPOSE_KEEP_EDITING);
+       compose->rmode = COMPOSE_REEDIT;
 }
 
 static void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_data)
@@ -9246,9 +9312,10 @@ static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
        Compose *compose = (Compose *)data;
 
        gtkut_widget_get_uposition(widget, &x, &y);
-       prefs_common.compose_x = x;
-       prefs_common.compose_y = y;
-
+       if (!compose->batch) {
+               prefs_common.compose_x = x;
+               prefs_common.compose_y = y;
+       }
        if (compose->sending || compose->updating)
                return TRUE;
        compose_close_cb(NULL, compose);
@@ -9273,6 +9340,7 @@ static void compose_close_cb(GtkAction *action, gpointer data)
 #endif
 
        if (compose->modified) {
+               gboolean reedit = (compose->rmode == COMPOSE_REEDIT);
                if (!g_mutex_trylock(compose->mutex)) {
                        /* we don't want to lock the mutex once it's available,
                         * because as the only other part of compose.c locking
@@ -9281,13 +9349,19 @@ static void compose_close_cb(GtkAction *action, gpointer data)
                        debug_print("couldn't lock mutex, probably sending\n");
                        return;
                }
-               val = alertpanel(_("Discard message"),
+               if (!reedit) {
+                       val = alertpanel(_("Discard message"),
                                 _("This message has been modified. Discard it?"),
                                 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
+               } else {
+                       val = alertpanel(_("Save changes"),
+                                _("This message has been modified. Save the latest changes?"),
+                                _("_Don't save"), _("+_Save to Drafts"), GTK_STOCK_CANCEL);
+               }
                g_mutex_unlock(compose->mutex);
                switch (val) {
                case G_ALERTDEFAULT:
-                       if (prefs_common.autosave)
+                       if (prefs_common.autosave && !reedit)
                                compose_remove_draft(compose);                  
                        break;
                case G_ALERTALTERNATE:
@@ -9424,6 +9498,8 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
                         * used for mid-click-pasting */
                        start = gtk_text_iter_get_offset(insert_place);
                        gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
+                       if (prefs_common.primary_paste_unselects)
+                               gtk_text_buffer_select_range(buffer, insert_place, insert_place);
                }
                
                if (!wrap) {
@@ -9957,6 +10033,7 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
 {
        compose->modified = TRUE;
+//     compose_beautify_paragraph(compose, NULL, TRUE);
 #ifndef GENERIC_UMPC
        compose_set_title(compose);
 #endif
@@ -9991,6 +10068,13 @@ static void compose_toggle_autowrap_cb(GtkToggleAction *action,
        compose->autowrap = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 }
 
+static void compose_toggle_autoindent_cb(GtkToggleAction *action,
+                                        gpointer        data)
+{
+       Compose *compose = (Compose *)data;
+       compose->autoindent = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+}
+
 static void compose_toggle_sign_cb(GtkToggleAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
@@ -10039,9 +10123,11 @@ static void compose_attach_drag_received_cb (GtkWidget         *widget,
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
 
-       if (gdk_atom_name(data->type) && 
-           !strcmp(gdk_atom_name(data->type), "text/uri-list")
-           && gtk_drag_get_source_widget(context) != 
+       if (((gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list"))
+#ifdef G_OS_WIN32
+        || (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "DROPFILES_DND"))
+#endif
+          ) && gtk_drag_get_source_widget(context) != 
                summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
                list = uri_list_extract_filenames((const gchar *)data->data);
                for (tmp = list; tmp != NULL; tmp = tmp->next) {
@@ -10106,11 +10192,18 @@ static void compose_insert_drag_received_cb (GtkWidget                *widget,
 
        /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
         * does not work */
+       debug_print("drop: %s (%s)\n", gdk_atom_name(data->type)?gdk_atom_name(data->type):"nul",
+               (gchar *)(data->data?data->data:"nul"));
+#ifndef G_OS_WIN32
        if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+#else
+       if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "DROPFILES_DND")) {
+#endif
                AlertValue val = G_ALERTDEFAULT;
 
                list = uri_list_extract_filenames((const gchar *)data->data);
-
+               debug_print("list: %p (%s)\n", list, 
+                       (gchar *)(data->data?data->data:"nul"));
                if (list == NULL && strstr((gchar *)(data->data), "://")) {
                        /* Assume a list of no files, and data has ://, is a remote link */
                        gchar *tmpdata = g_strstrip(g_strdup((const gchar *)data->data));
@@ -10346,9 +10439,15 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                gtk_text_buffer_delete_mark(buffer, mark);
        } else {
                if (strcmp(text, "\n") || compose->automatic_break
-               || gtk_text_iter_starts_line(iter))
+               || gtk_text_iter_starts_line(iter)) {
+                       GtkTextIter before_ins;
                        gtk_text_buffer_insert(buffer, iter, text, len);
-               else {
+                       if (!strstr(text, "\n") && gtk_text_iter_has_tag(iter, compose->no_join_tag)) {
+                               before_ins = *iter; 
+                               gtk_text_iter_backward_chars(&before_ins, len);
+                               gtk_text_buffer_remove_tag_by_name(buffer, "no_join", &before_ins, iter);
+                       }
+               } else {
                        /* check if the preceding is just whitespace or quote */
                        GtkTextIter start_line;
                        gchar *tmp = NULL, *quote = NULL;
@@ -10357,6 +10456,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                        gtk_text_iter_set_line_offset(&start_line, 0); 
                        tmp = gtk_text_buffer_get_text(buffer, &start_line, iter, FALSE);
                        g_strstrip(tmp);
+
                        if (*tmp == '\0') {
                                is_normal = 1;
                        } else {
@@ -10401,39 +10501,58 @@ static gint compose_defer_auto_save_draft(Compose *compose)
        return FALSE;
 }
 
-#if USE_ASPELL
+#if USE_ENCHANT
 static void compose_check_all(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
-       if (compose->gtkaspell)
+       if (!compose->gtkaspell)
+               return;
+               
+       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+               claws_spell_entry_check_all(
+                       CLAWS_SPELL_ENTRY(compose->subject_entry));             
+       else
                gtkaspell_check_all(compose->gtkaspell);
 }
 
 static void compose_highlight_all(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
-       if (compose->gtkaspell)
+       if (compose->gtkaspell) {
+               claws_spell_entry_recheck_all(
+                       CLAWS_SPELL_ENTRY(compose->subject_entry));
                gtkaspell_highlight_all(compose->gtkaspell);
+       }
 }
 
 static void compose_check_backwards(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
-       if (compose->gtkaspell) 
-               gtkaspell_check_backwards(compose->gtkaspell);
-       else {
+       if (!compose->gtkaspell) {
                cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", FALSE);
+               return;
        }
+
+       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+               claws_spell_entry_check_backwards(
+                       CLAWS_SPELL_ENTRY(compose->subject_entry));
+       else
+               gtkaspell_check_backwards(compose->gtkaspell);
 }
 
 static void compose_check_forwards_go(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
-       if (compose->gtkaspell) 
-               gtkaspell_check_forwards_go(compose->gtkaspell);
-       else {
+       if (!compose->gtkaspell) {
                cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", FALSE);
+               return;
        }
+
+       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+               claws_spell_entry_check_forwards_go(
+                       CLAWS_SPELL_ENTRY(compose->subject_entry));
+       else
+               gtkaspell_check_forwards_go(compose->gtkaspell);
 }
 #endif
 
@@ -10500,8 +10619,10 @@ gboolean compose_close(Compose *compose)
        }
        g_return_val_if_fail(compose, FALSE);
        gtkut_widget_get_uposition(compose->window, &x, &y);
-       prefs_common.compose_x = x;
-       prefs_common.compose_y = y;
+       if (!compose->batch) {
+               prefs_common.compose_x = x;
+               prefs_common.compose_y = y;
+       }
        g_mutex_unlock(compose->mutex);
        compose_destroy(compose);
        return FALSE;
@@ -10530,7 +10651,9 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
        GSList *new_msglist = NULL;
        MsgInfo *tmp_msginfo = NULL;
        gboolean originally_enc = FALSE;
+       gboolean originally_sig = FALSE;
        Compose *compose = NULL;
+       gchar *s_system = NULL;
 
        g_return_if_fail(msgview != NULL);
 
@@ -10548,6 +10671,9 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
                                new_msglist = g_slist_append(NULL, tmp_msginfo);
 
                                originally_enc = MSG_IS_ENCRYPTED(orig_msginfo->flags);
+                               privacy_msginfo_get_signed_state(orig_msginfo, &s_system);
+                               originally_sig = MSG_IS_SIGNED(orig_msginfo->flags);
+
                                tmp_msginfo->folder = orig_msginfo->folder;
                                tmp_msginfo->msgnum = orig_msginfo->msgnum; 
                                if (orig_msginfo->tags)
@@ -10567,9 +10693,13 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
                compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
 
        if (compose && originally_enc) {
-               compose_force_encryption(compose, compose->account, FALSE);
+               compose_force_encryption(compose, compose->account, FALSE, s_system);
        }
 
+       if (compose && originally_sig && compose->account->default_sign_reply) {
+               compose_force_signing(compose, compose->account, s_system);
+       }
+       g_free(s_system);
        g_free(body);
 }
 
@@ -10702,7 +10832,7 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
        return newmsginfo;
 }
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
 /* update compose's dictionaries from folder dict settings */
 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
                                                FolderItem *folder_item)