2008-09-20 [colin] 3.5.0cvs118
[claws.git] / src / compose.c
index fd4af3d07b79f1ba296735cab0a2389ad95e0826..b55d6374d28b134d834b73a252e2374414fb30e9 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-2008 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
@@ -238,7 +238,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,7 +331,7 @@ 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);
 #endif
 static void compose_add_field_list     ( Compose *compose,
@@ -423,6 +422,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 +504,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 +516,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 +539,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 +598,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 +650,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 */
@@ -670,7 +672,7 @@ static GtkRadioActionEntry compose_radio_prio_entries[] =
        {"Options/Priority/High",       NULL, N_("Hi_gh"), NULL, NULL, PRIORITY_HIGH }, /* RADIO compose_set_priority_cb */
        {"Options/Priority/Normal",     NULL, N_("_Normal"), NULL, NULL, PRIORITY_NORMAL }, /* RADIO compose_set_priority_cb */
        {"Options/Priority/Low",        NULL, N_("Lo_w"), NULL, NULL, PRIORITY_LOW }, /* RADIO compose_set_priority_cb */
-       {"Options/Priority/Lowest",     NULL, N_("Lowest"), NULL, NULL, PRIORITY_LOWEST }, /* RADIO compose_set_priority_cb */
+       {"Options/Priority/Lowest",     NULL, N_("_Lowest"), NULL, NULL, PRIORITY_LOWEST }, /* RADIO compose_set_priority_cb */
 };
 
 static GtkRadioActionEntry compose_radio_enc_entries[] =
@@ -939,7 +941,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 +968,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 +1033,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
@@ -1434,7 +1436,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 +1460,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
 
@@ -1501,6 +1503,11 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                compose_force_encryption(compose, account, FALSE);
        }
 
+       privacy_msginfo_get_signed_state(compose->replyinfo);
+       if (MSG_IS_SIGNED(compose->replyinfo->flags) && account->default_sign_reply) {
+               compose_force_signing(compose, account);
+       }
+
        SIGNAL_BLOCK(textbuf);
        
        if (account->auto_sig)
@@ -1599,7 +1606,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
@@ -1781,7 +1788,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
@@ -1958,6 +1965,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        gchar *privacy_system = NULL;
        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);
@@ -2018,6 +2027,16 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                        param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
                        use_encryption = param;
                }
+               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
+                                            sizeof(queueheader_buf), "X-Claws-Auto-Wrapping:")) {
+                       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:")]);
@@ -2070,7 +2089,10 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        g_return_val_if_fail(account != NULL, NULL);
 
        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;
 
@@ -2177,7 +2199,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;
 }
@@ -2428,7 +2450,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;
@@ -2743,7 +2765,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
@@ -2765,7 +2787,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
@@ -3177,7 +3199,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);
 
@@ -3217,58 +3239,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;
@@ -3654,42 +3624,98 @@ static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
        return NULL;
 }
 
-/* return TRUE if the line is itemized */
-static gboolean compose_is_itemized(GtkTextBuffer *buffer,
+/* return >0 if the line is itemized */
+static int compose_itemized_length(GtkTextBuffer *buffer,
                                    const GtkTextIter *start)
 {
        GtkTextIter iter = *start;
        gunichar wc;
        gchar ch[6];
        gint clen;
-
+       gint len = 0;
        if (gtk_text_iter_ends_line(&iter))
-               return FALSE;
+               return 0;
 
        while (1) {
+               len++;
                wc = gtk_text_iter_get_char(&iter);
                if (!g_unichar_isspace(wc))
                        break;
                gtk_text_iter_forward_char(&iter);
                if (gtk_text_iter_ends_line(&iter))
-                       return FALSE;
+                       return 0;
        }
 
        clen = g_unichar_to_utf8(wc, ch);
        if (clen != 1)
-               return FALSE;
+               return 0;
 
        if (!strchr("*-+", ch[0]))
-               return FALSE;
+               return 0;
 
        gtk_text_iter_forward_char(&iter);
        if (gtk_text_iter_ends_line(&iter))
-               return FALSE;
+               return 0;
        wc = gtk_text_iter_get_char(&iter);
-       if (g_unichar_isspace(wc))
-               return TRUE;
+       if (g_unichar_isspace(wc)) {
+               return len+1;
+       }
+       return 0;
+}
 
-       return FALSE;
+/* return the string at the start of the itemization */
+static gchar * compose_get_itemized_chars(GtkTextBuffer *buffer,
+                                   const GtkTextIter *start)
+{
+       GtkTextIter iter = *start;
+       gunichar wc;
+       gint len = 0;
+       GString *item_chars = g_string_new("");
+       gchar *str = NULL;
+
+       if (gtk_text_iter_ends_line(&iter))
+               return NULL;
+
+       while (1) {
+               len++;
+               wc = gtk_text_iter_get_char(&iter);
+               if (!g_unichar_isspace(wc))
+                       break;
+               gtk_text_iter_forward_char(&iter);
+               if (gtk_text_iter_ends_line(&iter))
+                       break;
+               g_string_append_unichar(item_chars, wc);
+       }
+
+       str = item_chars->str;
+       g_string_free(item_chars, FALSE);
+       return str;
+}
+
+/* return the number of spaces at a line's start */
+static int compose_left_offset_length(GtkTextBuffer *buffer,
+                                   const GtkTextIter *start)
+{
+       GtkTextIter iter = *start;
+       gunichar wc;
+       gint len = 0;
+       if (gtk_text_iter_ends_line(&iter))
+               return 0;
+
+       while (1) {
+               wc = gtk_text_iter_get_char(&iter);
+               if (!g_unichar_isspace(wc))
+                       break;
+               len++;
+               gtk_text_iter_forward_char(&iter);
+               if (gtk_text_iter_ends_line(&iter))
+                       return 0;
+       }
+
+       gtk_text_iter_forward_char(&iter);
+       if (gtk_text_iter_ends_line(&iter))
+               return 0;
+       return len;
 }
 
 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
@@ -3838,7 +3864,7 @@ static gboolean compose_join_next_line(Compose *compose,
        }
 
        /* don't join itemized lines */
-       if (compose_is_itemized(buffer, &end)) {
+       if (compose_itemized_length(buffer, &end) > 0) {
                return FALSE;
        }
 
@@ -3934,6 +3960,9 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
        gboolean modified_before_remove = FALSE;
        gint lines = 0;
        gboolean start = TRUE;
+       gint itemized_len = 0, rem_item_len = 0;
+       gchar *itemized_chars = NULL;
+       gboolean item_continuation = FALSE;
 
        if (force) {
                modified = TRUE;
@@ -3972,6 +4001,17 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
                /* move to line start */
                gtk_text_iter_set_line_offset(&iter, 0);
        }
+       
+       itemized_len = compose_itemized_length(buffer, &iter);
+       
+       if (!itemized_len) {
+               itemized_len = compose_left_offset_length(buffer, &iter);
+               item_continuation = TRUE;
+       }
+
+       if (itemized_len)
+               itemized_chars = compose_get_itemized_chars(buffer, &iter);
+
        /* go until paragraph end (empty line) */
        while (start || !gtk_text_iter_ends_line(&iter)) {
                gchar *scanpos = NULL;
@@ -4052,22 +4092,35 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
                                               prefs_common.linewrap_len,
                                               quote_len)) {
                        GtkTextIter prev, next, cur;
-
                        if (prev_autowrap != FALSE || force) {
                                compose->automatic_break = TRUE;
                                modified = TRUE;
                                gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
                                compose->automatic_break = FALSE;
+                               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);
+                               }
                        } else if (quote_str && wrap_quote) {
                                compose->automatic_break = TRUE;
                                modified = TRUE;
                                gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
                                compose->automatic_break = FALSE;
+                               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);
+                               }
                        } else 
                                goto colorize;
                        /* remove trailing spaces */
                        cur = break_pos;
+                       rem_item_len = itemized_len;
+                       while (compose->autoindent && rem_item_len-- > 0)
+                               gtk_text_iter_backward_char(&cur);
                        gtk_text_iter_backward_char(&cur);
+
                        prev = next = cur;
                        while (!gtk_text_iter_starts_line(&cur)) {
                                gunichar wc;
@@ -4260,9 +4313,9 @@ colorize:
                        goto end;
                }
        }
-
        debug_print("modified, out after %d lines\n", lines);
 end:
+       g_free(itemized_chars);
        if (par_iter)
                *par_iter = iter;
        undo_wrapping(compose->undostruct, FALSE);
@@ -4446,7 +4499,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)
@@ -4482,7 +4535,7 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
        for (list = compose->header_list; list; list = list->next) {
                gchar *header;
                gchar *entry;
-               header = gtk_editable_get_chars(GTK_EDITABLE(GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
+               header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
                entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
                g_strstrip(entry);
                g_strstrip(header);
@@ -4516,7 +4569,7 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        gchar *entry;
                        gchar *header;
                        entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
-                       header = gtk_editable_get_chars(GTK_EDITABLE(GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
+                       header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
                        g_strstrip(entry);
                        g_strstrip(header);
                        if (strcmp(entry, compose->account->auto_cc)
@@ -4548,7 +4601,7 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        gchar *entry;
                        gchar *header;
                        entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
-                       header = gtk_editable_get_chars(GTK_EDITABLE(GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
+                       header = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
                        g_strstrip(entry);
                        g_strstrip(header);
                        if (strcmp(entry, compose->account->auto_bcc)
@@ -4802,7 +4855,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
        first_to_address = TRUE;
        for (list = compose->header_list; list; list = list->next) {
                headerentry = ((ComposeHeaderEntry *)list->data);
-               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child));
+               headerentryname = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo)))));
 
                if (g_utf8_collate(headerentryname, to_hdr) == 0) {
                        const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
@@ -4830,7 +4883,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
        first_cc_address = TRUE;
        for (list = compose->header_list; list; list = list->next) {
                headerentry = ((ComposeHeaderEntry *)list->data);
-               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child));
+               headerentryname = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo)))));
 
                if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
                        const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
@@ -4947,6 +5000,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-Indent:",
                NULL
                };
        if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
@@ -5528,6 +5582,9 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                g_free(folderid);
        }
 
+       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);
 
@@ -5700,7 +5757,7 @@ static void compose_add_headerfield_from_headerlist(Compose *compose,
 
        for (list = compose->header_list; list; list = list->next) {
                headerentry = ((ComposeHeaderEntry *)list->data);
-               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child));
+               headerentryname = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo)))));
 
                if (!g_utf8_collate(trans_fieldname, headerentryname)) {
                        str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
@@ -5964,7 +6021,7 @@ static gchar *compose_get_header(Compose *compose)
 
                headerentry = ((ComposeHeaderEntry *)list->data);
 
-               tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child)));
+               tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo))))));
                g_strstrip(tmp);
                if (*tmp == '\0' || strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
                        g_free(tmp);
@@ -6136,7 +6193,7 @@ static void compose_create_header_entry(Compose *compose)
                string++;
        }
        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
-       g_signal_connect(G_OBJECT(GTK_BIN(combo)->child), "grab_focus",
+       g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((combo)))), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
        gtk_widget_show(combo);
        gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1,
@@ -6144,7 +6201,7 @@ static void compose_create_header_entry(Compose *compose)
                        GTK_SHRINK, GTK_FILL, 0, 0);
        if (compose->header_last) {     
                const gchar *last_header_entry = gtk_entry_get_text(
-                               GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child));
+                               GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))));
                string = headers;
                while (*string != NULL) {
                        if (!strcmp(*string, last_header_entry))
@@ -6152,7 +6209,7 @@ static void compose_create_header_entry(Compose *compose)
                        string++;
                }
                if (standard_header)
-                       header = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child));
+                       header = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))));
        }
        if (!compose->header_last || !standard_header) {
                switch(compose->account->protocol) {
@@ -6165,9 +6222,9 @@ static void compose_create_header_entry(Compose *compose)
                }                                                                   
        }
        if (header)
-               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(combo)->child), header);
+               gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((combo)))), header);
 
-       g_signal_connect_after(G_OBJECT(GTK_BIN(combo)->child), "grab_focus",
+       g_signal_connect_after(G_OBJECT(gtk_bin_get_child(GTK_BIN((combo)))), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
 
        /* Entry field */
@@ -6222,7 +6279,7 @@ static void compose_add_header_entry(Compose *compose, const gchar *header, gcha
        
        last_header = compose->header_last;
 
-       gtk_entry_set_text(GTK_ENTRY(GTK_BIN(last_header->combo)->child), header);
+       gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((last_header->combo)))), header);
        gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
 }
 
@@ -6260,7 +6317,7 @@ static GtkWidget *compose_create_header(Compose *compose)
        gtk_widget_show(header_table);
        gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
-       gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_NONE);
+       gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN((header_scrolledwin)))), GTK_SHADOW_NONE);
        count = 0;
 
        /* option menu for selecting accounts */
@@ -6464,7 +6521,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;
@@ -6518,7 +6575,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;
@@ -6615,7 +6672,7 @@ static Compose *compose_create(PrefsAccount *account,
        GtkWidget *tmpl_menu;
        GtkActionGroup *action_group = NULL;
 
-#if USE_ASPELL
+#if USE_ENCHANT
         GtkAspell * gtkaspell = NULL;
 #endif
 
@@ -6662,7 +6719,7 @@ static Compose *compose_create(PrefsAccount *account,
 
 #ifndef GENERIC_UMPC   
        if (compose_force_window_origin)
-               gtk_widget_set_uposition(window, prefs_common.compose_x, 
+               gtk_window_move(GTK_WINDOW(window), prefs_common.compose_x, 
                                 prefs_common.compose_y);
 #endif
        g_signal_connect(G_OBJECT(window), "delete_event",
@@ -6695,7 +6752,7 @@ static Compose *compose_create(PrefsAccount *account,
 
        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)
@@ -6752,12 +6809,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)
@@ -7017,7 +7075,6 @@ static Compose *compose_create(PrefsAccount *account,
 
        /* pane between attach clist and text */
        paned = gtk_vpaned_new();
-       gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
        gtk_container_add(GTK_CONTAINER(vbox2), paned);
 #ifdef MAEMO
        if( maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window) )
@@ -7108,7 +7165,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;
@@ -7129,13 +7186,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,
@@ -7153,14 +7209,6 @@ 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);
                        }
                }
@@ -7172,6 +7220,7 @@ static Compose *compose_create(PrefsAccount *account,
        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);
@@ -7184,10 +7233,10 @@ static Compose *compose_create(PrefsAccount *account,
 
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/ReplyMode", compose->mode == COMPOSE_REPLY);
        if (account->protocol != A_NNTP)
-               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child),
+               gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))),
                                prefs_common_translated_header_name("To:"));
        else
-               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child),
+               gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))),
                                prefs_common_translated_header_name("Newsgroups:"));
 
        addressbook_set_target_compose(compose);
@@ -7315,7 +7364,6 @@ static void compose_set_priority_cb(GtkAction *action, GtkRadioAction *current,
        gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
        Compose *compose = (Compose *) data;
        if (active) {
-               printf("activated %d\n", value);
                compose->priority = value;
        }
 }
@@ -7441,7 +7489,8 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
 
                        systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
                        if (systemid != NULL) {
-                               if (strcmp(systemid, compose->privacy_system) == 0) {
+                               if (strcmp(systemid, compose->privacy_system) == 0 &&
+                                   GTK_IS_CHECK_MENU_ITEM(amenu->data)) {
                                        menuitem = GTK_WIDGET(amenu->data);
 
                                        can_sign = privacy_system_can_sign(systemid);
@@ -7449,7 +7498,8 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
                                        found = TRUE;
                                        break;
                                } 
-                       } else if (strlen(compose->privacy_system) == 0) {
+                       } else if (strlen(compose->privacy_system) == 0 && 
+                                  GTK_IS_CHECK_MENU_ITEM(amenu->data)) {
                                        menuitem = GTK_WIDGET(amenu->data);
 
                                        can_sign = FALSE;
@@ -7764,7 +7814,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
@@ -7782,7 +7832,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
@@ -7800,7 +7850,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
@@ -7818,7 +7868,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
@@ -7837,7 +7887,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
@@ -7912,15 +7962,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);
@@ -8236,7 +8288,7 @@ static void compose_attach_property_create(gboolean *cancelled)
        }
        g_list_free(strlist);
        gtk_combo_box_set_active(GTK_COMBO_BOX(mimetype_entry), 0);              
-       mimetype_entry = GTK_BIN(mimetype_entry)->child;                         
+       mimetype_entry = gtk_bin_get_child(GTK_BIN((mimetype_entry)));                   
 
        label = gtk_label_new(_("Encoding"));
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
@@ -8350,7 +8402,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,
@@ -8733,7 +8789,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);
@@ -8798,7 +8854,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), 
@@ -8891,6 +8947,9 @@ gboolean compose_draft (gpointer data, guint action)
                g_free(folderid);
        }
 
+       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);
 
@@ -9042,7 +9101,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) {
@@ -9150,9 +9209,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);
@@ -9177,6 +9237,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
@@ -9185,13 +9246,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:
@@ -9309,12 +9376,11 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
 
                if (contents == NULL)
                        return;
-
-               undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
-
+       
                /* we shouldn't delete the selection when middle-click-pasting, or we
                 * can't mid-click-paste our own selection */
                if (clip != GDK_SELECTION_PRIMARY) {
+                       undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);
                        gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
                }
                
@@ -9823,14 +9889,14 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
 #ifdef GENERIC_UMPC
        if (GTK_IS_TEXT_VIEW(widget) 
            && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->edit_vbox) {
-               gtk_widget_ref(compose->notebook);
-               gtk_widget_ref(compose->edit_vbox);
+               g_object_ref(compose->notebook);
+               g_object_ref(compose->edit_vbox);
                gtk_container_remove(GTK_CONTAINER(compose->paned), compose->notebook);
                gtk_container_remove(GTK_CONTAINER(compose->paned), compose->edit_vbox);
                gtk_paned_add1(GTK_PANED(compose->paned), compose->edit_vbox);
                gtk_paned_add2(GTK_PANED(compose->paned), compose->notebook);
-               gtk_widget_unref(compose->notebook);
-               gtk_widget_unref(compose->edit_vbox);
+               g_object_unref(compose->notebook);
+               g_object_unref(compose->edit_vbox);
                g_signal_handlers_block_by_func(G_OBJECT(widget),
                                        G_CALLBACK(compose_grab_focus_cb),
                                        compose);
@@ -9840,14 +9906,14 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
                                        compose);
        } else if (!GTK_IS_TEXT_VIEW(widget) 
                   && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->notebook) {
-               gtk_widget_ref(compose->notebook);
-               gtk_widget_ref(compose->edit_vbox);
+               g_object_ref(compose->notebook);
+               g_object_ref(compose->edit_vbox);
                gtk_container_remove(GTK_CONTAINER(compose->paned), compose->notebook);
                gtk_container_remove(GTK_CONTAINER(compose->paned), compose->edit_vbox);
                gtk_paned_add1(GTK_PANED(compose->paned), compose->notebook);
                gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
-               gtk_widget_unref(compose->notebook);
-               gtk_widget_unref(compose->edit_vbox);
+               g_object_unref(compose->notebook);
+               g_object_unref(compose->edit_vbox);
                g_signal_handlers_block_by_func(G_OBJECT(widget),
                                        G_CALLBACK(compose_grab_focus_cb),
                                        compose);
@@ -9896,6 +9962,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;
@@ -10251,9 +10324,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;
@@ -10262,6 +10341,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 {
@@ -10306,7 +10386,7 @@ 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;
@@ -10405,8 +10485,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;
@@ -10435,6 +10517,7 @@ 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;
 
        g_return_if_fail(msgview != NULL);
@@ -10453,6 +10536,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);
+                               originally_sig = MSG_IS_SIGNED(orig_msginfo->flags);
+
                                tmp_msginfo->folder = orig_msginfo->folder;
                                tmp_msginfo->msgnum = orig_msginfo->msgnum; 
                                if (orig_msginfo->tags)
@@ -10475,6 +10561,10 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
                compose_force_encryption(compose, compose->account, FALSE);
        }
 
+       if (compose && originally_sig && compose->account->default_sign_reply) {
+               compose_force_signing(compose, compose->account);
+       }
+
        g_free(body);
 }
 
@@ -10565,7 +10655,7 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
        for (list = compose->header_list; list; list = list->next) {
                gchar *header = gtk_editable_get_chars(
                                                                GTK_EDITABLE(
-                                                               GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
+                                                               gtk_bin_get_child(GTK_BIN((((ComposeHeaderEntry *)list->data)->combo)))), 0, -1);
                gchar *entry = gtk_editable_get_chars(
                                                                GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
 
@@ -10607,7 +10697,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)