Fix untranslatable concatenated strings (i.e. "Default "+"To:"),
[claws.git] / src / compose.c
index 48170ae1324197eca7dff36e0f130b1ad3838e83..fc02ba75c3f8ddc2814072955378c7c1898a2e72 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2016 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -61,7 +60,7 @@
 #include "main.h"
 #include "mainwindow.h"
 #include "compose.h"
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        #include "addressbook.h"
 #else
        #include "addressbook-dbus.h"
@@ -84,7 +83,6 @@
 #include "procmime.h"
 #include "statusbar.h"
 #include "about.h"
-#include "base64.h"
 #include "quoted-printable.h"
 #include "codeconv.h"
 #include "utils.h"
@@ -182,6 +180,23 @@ typedef enum {
 
 #define MAX_REFERENCES_LEN     999
 
+#define COMPOSE_DRAFT_TIMEOUT_UNSET -1
+#define COMPOSE_DRAFT_TIMEOUT_FORBIDDEN -2
+
+static GdkColor default_header_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor default_header_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GList *compose_list = NULL;
 static GSList *extra_headers = NULL;
 
@@ -196,7 +211,7 @@ static Compose *compose_create                      (PrefsAccount   *account,
                                                 ComposeMode     mode,
                                                 gboolean batch);
 
-static void compose_entry_mark_default_to      (Compose          *compose,
+static void compose_entry_indicate     (Compose          *compose,
                                         const gchar      *address);
 static Compose *compose_followup_and_reply_to  (MsgInfo        *msginfo,
                                         ComposeQuoteMode        quote_mode,
@@ -334,13 +349,19 @@ static gboolean attach_property_key_pressed       (GtkWidget      *widget,
 
 static void compose_exec_ext_editor            (Compose        *compose);
 #ifdef G_OS_UNIX
-static gint compose_exec_ext_editor_real       (const gchar    *file);
+static gint compose_exec_ext_editor_real       (const gchar    *file,
+                                                GdkNativeWindow socket_wid);
 static gboolean compose_ext_editor_kill                (Compose        *compose);
 static gboolean compose_input_cb               (GIOChannel     *source,
                                                 GIOCondition    condition,
                                                 gpointer        data);
 static void compose_set_ext_editor_sensitive   (Compose        *compose,
                                                 gboolean        sensitive);
+static gboolean compose_get_ext_editor_cmd_valid();
+static gboolean compose_get_ext_editor_uses_socket();
+static gboolean compose_ext_editor_plug_removed_cb
+                                               (GtkSocket      *socket,
+                                                Compose        *compose);
 #endif /* G_OS_UNIX */
 
 static void compose_undo_state_changed         (UndoMain       *undostruct,
@@ -365,7 +386,7 @@ static void compose_add_field_list  ( Compose *compose,
 
 static void compose_notebook_size_alloc (GtkNotebook *notebook,
                                         GtkAllocation *allocation,
-                                        Compose *compose);
+                                        GtkPaned *paned);
 static gboolean compose_edit_size_alloc (GtkEditable   *widget,
                                         GtkAllocation  *allocation,
                                         GtkSHRuler     *shruler);
@@ -548,7 +569,7 @@ static void compose_check_backwards    (GtkAction *action, gpointer data);
 static void compose_check_forwards_go     (GtkAction *action, gpointer data);
 #endif
 
-static PrefsAccount *compose_guess_forward_account_from_msginfo        (MsgInfo *msginfo);
+static PrefsAccount *compose_find_account      (MsgInfo *msginfo);
 
 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
 
@@ -560,6 +581,7 @@ static void compose_attach_update_label(Compose *compose);
 static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
                                     gboolean respect_default_to);
 static void compose_subject_entry_activated(GtkWidget *widget, gpointer data);
+static void from_name_activate_cb(GtkWidget *widget, gpointer data);
 
 static GtkActionEntry compose_popup_entries[] =
 {
@@ -734,6 +756,7 @@ static GtkRadioActionEntry compose_radio_enc_entries[] =
        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_MACCYR, C_MACCYR, "_Mac-Cyrillic"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Cyrillic/"CS_KOI8_U, C_KOI8_U, "KOI8-_U"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Cyrillic/"CS_WINDOWS_1251, C_WINDOWS_1251, "Windows-1251"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Japanese/"CS_ISO_2022_JP, C_ISO_2022_JP, "ISO-2022-_JP"), /* RADIO compose_set_encoding_cb */
@@ -760,8 +783,8 @@ static GtkTargetEntry compose_mime_types[] =
 
 static gboolean compose_put_existing_to_front(MsgInfo *info)
 {
-       GList *compose_list = compose_get_compose_list();
-       GList *elem = NULL;
+       const GList *compose_list = compose_get_compose_list();
+       const GList *elem = NULL;
        
        if (compose_list) {
                for (elem = compose_list; elem != NULL && elem->data != NULL; 
@@ -895,7 +918,7 @@ static void compose_create_tags(GtkTextView *text, Compose *compose)
 
        for (i = 0; i < 8; i++) {
                if (success[i] == FALSE) {
-                       g_warning("Compose: color allocation failed.\n");
+                       g_warning("Compose: color allocation failed.");
                        quote_color1 = quote_color2 = quote_color3 = 
                                quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = 
                                signature_color = uri_color = black;
@@ -1195,7 +1218,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                }
 
        }
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 
        if (attach_files) {
                GList *curr;
@@ -1203,7 +1226,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                for (curr = attach_files ; curr != NULL ; curr = curr->next) {
                        ainfo = (AttachInfo *) curr->data;
-                       compose_attach_append(compose, ainfo->file, ainfo->name,
+                       compose_attach_append(compose, ainfo->file, ainfo->file,
                                        ainfo->content_type, ainfo->charset);
                }
        }
@@ -1266,7 +1289,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        if (prefs_common.auto_exteditor)
                compose_exec_ext_editor(compose);
 
-       compose->draft_timeout_tag = -1;
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET;
+
        SCROLL_TO_CURSOR(compose);
 
        compose->modified = FALSE;
@@ -1302,11 +1326,15 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
                if (system) {
                        g_free(compose->privacy_system);
                        compose->privacy_system = NULL;
+                       g_free(compose->encdata);
+                       compose->encdata = NULL;
                }
                if (compose->privacy_system == NULL)
                        compose->privacy_system = g_strdup(privacy);
                else if (*(compose->privacy_system) == '\0') {
                        g_free(compose->privacy_system);
+                       g_free(compose->encdata);
+                       compose->encdata = NULL;
                        compose->privacy_system = g_strdup(privacy);
                }
                compose_update_privacy_system_menu_item(compose, FALSE);
@@ -1333,6 +1361,8 @@ static void compose_force_signing(Compose *compose, PrefsAccount *account, const
                if (system) {
                        g_free(compose->privacy_system);
                        compose->privacy_system = NULL;
+                       g_free(compose->encdata);
+                       compose->encdata = NULL;
                }
                if (compose->privacy_system == NULL)
                        compose->privacy_system = g_strdup(privacy);
@@ -1432,7 +1462,7 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar
                compose = compose_redirect(NULL, msginfo, FALSE);
                break;
        default:
-               g_warning("compose_reply_mode(): invalid Compose Mode: %d\n", mode);
+               g_warning("compose_reply_mode(): invalid Compose Mode: %d", mode);
        }
        
        if (compose == NULL) {
@@ -1518,7 +1548,7 @@ static void compose_extract_original_charset(Compose *compose)
                                g_strdup(procmime_mimeinfo_get_parameter(
                                                partinfo, "charset"));
                }
-               procmime_mimeinfo_free_all(mimeinfo);
+               procmime_mimeinfo_free_all(&mimeinfo);
        }
 }
 
@@ -1707,7 +1737,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
        compose_set_title(compose);
 
        compose->updating = FALSE;
-       compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
        SCROLL_TO_CURSOR(compose);
        
        if (compose->deferred_destroy) {
@@ -1740,9 +1770,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
        cm_return_val_if_fail(msginfo != NULL, NULL);
        cm_return_val_if_fail(msginfo->folder != NULL, NULL);
 
-       if (!account && 
-           !(account = compose_guess_forward_account_from_msginfo
-                               (msginfo)))
+       if (!account && !(account = compose_find_account(msginfo)))
                account = cur_account;
 
        if (!prefs_common.forward_as_attachment)
@@ -1809,7 +1837,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                quote_fmt_reset_vartable();
 
                g_free(tmp);
-               procmsg_msginfo_free(full_msginfo);
+               procmsg_msginfo_free(&full_msginfo);
        }
 
        textview = GTK_TEXT_VIEW(compose->text);
@@ -1822,7 +1850,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
                msgfile = procmsg_get_message_file(msginfo);
                if (!is_file_exist(msgfile))
-                       g_warning("%s: file not exist\n", msgfile);
+                       g_warning("%s: file does not exist", msgfile);
                else
                        compose_attach_append(compose, msgfile, msgfile,
                                              "message/rfc822", NULL);
@@ -1868,7 +1896,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                quote_fmt_reset_vartable();
                compose_attach_parts(compose, msginfo);
 
-               procmsg_msginfo_free(full_msginfo);
+               procmsg_msginfo_free(&full_msginfo);
        }
 
        SIGNAL_BLOCK(textbuf);
@@ -1910,7 +1938,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
        compose_set_title(compose);
 
        compose->updating = FALSE;
-       compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
        SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
@@ -1946,8 +1974,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
 
        /* guess account from first selected message */
        if (!account && 
-           !(account = compose_guess_forward_account_from_msginfo
-                               (msginfo_list->data)))
+           !(account = compose_find_account(msginfo_list->data)))
                account = cur_account;
 
        cm_return_val_if_fail(account != NULL, NULL);
@@ -2013,7 +2040,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                msgfile = procmsg_get_message_file((MsgInfo *)msginfo->data);
 
                if (!is_file_exist(msgfile))
-                       g_warning("%s: file not exist\n", msgfile);
+                       g_warning("%s: file does not exist", msgfile);
                else
                        compose_attach_append(compose, msgfile, msgfile,
                                "message/rfc822", NULL);
@@ -2052,13 +2079,16 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
        gtk_text_buffer_get_start_iter(textbuf, &iter);
        gtk_text_buffer_place_cursor(textbuf, &iter);
 
+       if (prefs_common.auto_exteditor)
+               compose_exec_ext_editor(compose);
+
        gtk_widget_grab_focus(compose->header_last->entry);
        undo_unblock(compose->undostruct);
        compose->modified = FALSE;
        compose_set_title(compose);
 
        compose->updating = FALSE;
-       compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
        SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
@@ -2105,6 +2135,44 @@ static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbu
        return FALSE;
 }
 
+static gboolean compose_update_folder_hook(gpointer source, gpointer data)
+{
+       FolderUpdateData *hookdata = (FolderUpdateData *)source;
+       Compose *compose = (Compose *)data;
+       FolderItem *old_item = NULL;
+       FolderItem *new_item = NULL;
+       gchar *old_id, *new_id;
+
+       if (!(hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM)
+        && !(hookdata->update_flags & FOLDER_MOVE_FOLDERITEM))
+               return FALSE;
+
+       old_item = hookdata->item;
+       new_item = hookdata->item2;
+
+       old_id = folder_item_get_identifier(old_item);
+       new_id = new_item ? folder_item_get_identifier(new_item) : g_strdup("NULL");
+
+       if (compose->targetinfo && compose->targetinfo->folder == old_item) {
+               debug_print("updating targetinfo folder: %s -> %s\n", old_id, new_id);
+               compose->targetinfo->folder = new_item;
+       }
+
+       if (compose->replyinfo && compose->replyinfo->folder == old_item) {
+               debug_print("updating replyinfo folder: %s -> %s\n", old_id, new_id);
+               compose->replyinfo->folder = new_item;
+       }
+
+       if (compose->fwdinfo && compose->fwdinfo->folder == old_item) {
+               debug_print("updating fwdinfo folder: %s -> %s\n", old_id, new_id);
+               compose->fwdinfo->folder = new_item;
+       }
+
+       g_free(old_id);
+       g_free(new_id);
+       return FALSE;
+}
+
 static void compose_colorize_signature(Compose *compose)
 {
        GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
@@ -2131,21 +2199,21 @@ static void compose_colorize_signature(Compose *compose)
                                G_CALLBACK(text_inserted),              \
                                compose);                               \
 }
-#define UNBLOCK_WRAP() {                                               \
-       compose->autowrap = prev_autowrap;                              \
-       if (compose->autowrap) {                                        \
-               gint old = compose->draft_timeout_tag;                  \
-               compose->draft_timeout_tag = -2;                        \
-               compose_wrap_all(compose);                              \
-               compose->draft_timeout_tag = old;                       \
-       }                                                               \
-                                                                       \
-       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),             \
-                               G_CALLBACK(compose_changed_cb),         \
-                               compose);                               \
-       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),             \
-                               G_CALLBACK(text_inserted),              \
-                               compose);                               \
+#define UNBLOCK_WRAP() {                                                       \
+       compose->autowrap = prev_autowrap;                                      \
+       if (compose->autowrap) {                                                \
+               gint old = compose->draft_timeout_tag;                          \
+               compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN;   \
+               compose_wrap_all(compose);                                      \
+               compose->draft_timeout_tag = old;                               \
+       }                                                                       \
+                                                                               \
+       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),                     \
+                               G_CALLBACK(compose_changed_cb),                 \
+                               compose);                                       \
+       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),                     \
+                               G_CALLBACK(text_inserted),                      \
+                               compose);                                       \
 }
 
 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
@@ -2366,7 +2434,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                fp = procmime_get_first_text_content(msginfo);
        }
        if (fp == NULL) {
-               g_warning("Can't get text part\n");
+               g_warning("Can't get text part");
        }
 
        if (fp != NULL) {
@@ -2408,7 +2476,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        compose_set_title(compose);
 
        compose->updating = FALSE;
-       compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
        SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
@@ -2518,7 +2586,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
        compose->modified = FALSE;
        compose_set_title(compose);
        compose->updating = FALSE;
-       compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */
        SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
@@ -2531,7 +2599,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
        return compose;
 }
 
-GList *compose_get_compose_list(void)
+const GList *compose_get_compose_list(void)
 {
        return compose_list;
 }
@@ -2586,6 +2654,7 @@ void compose_entry_append(Compose *compose, const gchar *address,
                        while (*tmp == ' ' || *tmp == '\t')
                                tmp++;
                        compose_add_header_entry(compose, header, tmp, pref_type);
+                       compose_entry_indicate(compose, tmp);
                        g_free(o_tmp);
                        continue;
                }
@@ -2598,50 +2667,26 @@ void compose_entry_append(Compose *compose, const gchar *address,
                while (*tmp == ' ' || *tmp == '\t')
                        tmp++;
                compose_add_header_entry(compose, header, tmp, pref_type);
+               compose_entry_indicate(compose, tmp);
                g_free(o_tmp);          
        }
 }
 
-static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
+static void compose_entry_indicate(Compose *compose, const gchar *mailto)
 {
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow;
-       static GdkColor black;
-       static gboolean yellow_initialised = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint16)0xf5, (guint16)0xf6, (guint16)0xbe };
-       static GdkColor black = { (guint32)0, (guint16)0x0, (guint16)0x0, (guint16)0x0 };
-#endif
        GSList *h_list;
        GtkEntry *entry;
                
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       if (!yellow_initialised) {
-               gdk_color_parse("#f5f6be", &yellow);
-               gdk_color_parse("#000000", &black);
-               yellow_initialised = gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &yellow, FALSE, TRUE);
-               yellow_initialised &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &black, FALSE, TRUE);
-       }
-#endif
-
        for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
                entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
                if (gtk_entry_get_text(entry) && 
                    !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       if (yellow_initialised) {
-#endif
                                gtk_widget_modify_base(
                                        GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
-                                       GTK_STATE_NORMAL, &yellow);
+                                       GTK_STATE_NORMAL, &default_header_bgcolor);
                                gtk_widget_modify_text(
                                        GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
-                                       GTK_STATE_NORMAL, &black);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       }
-#endif
+                                       GTK_STATE_NORMAL, &default_header_color);
                }
        }
 }
@@ -2657,7 +2702,7 @@ void compose_toolbar_cb(gint action, gpointer data)
        case A_SEND:
                compose_send_cb(NULL, compose);
                break;
-       case A_SENDL:
+       case A_SEND_LATER:
                compose_send_later_cb(NULL, compose);
                break;
        case A_DRAFT:
@@ -2672,6 +2717,9 @@ void compose_toolbar_cb(gint action, gpointer data)
        case A_SIG:
                compose_insert_sig(compose, FALSE);
                break;
+       case A_REP_SIG:
+               compose_insert_sig(compose, TRUE);
+               break;
        case A_EXTEDITOR:
                compose_ext_editor_cb(NULL, compose);
                break;
@@ -2911,27 +2959,29 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        if (compose->mode == COMPOSE_REEDIT) {
                if (msginfo->inreplyto && *msginfo->inreplyto)
                        compose->inreplyto = g_strdup(msginfo->inreplyto);
-               return 0;
-       }
-
-       if (msginfo->msgid && *msginfo->msgid)
-               compose->inreplyto = g_strdup(msginfo->msgid);
 
-       if (!compose->references) {
-               if (msginfo->msgid && *msginfo->msgid) {
-                       if (msginfo->inreplyto && *msginfo->inreplyto)
-                               compose->references =
-                                       g_strdup_printf("<%s>\n\t<%s>",
-                                                       msginfo->inreplyto,
-                                                       msginfo->msgid);
-                       else
+               if (msginfo->msgid && *msginfo->msgid)
+                       compose->msgid = g_strdup(msginfo->msgid);
+       } else {
+               if (msginfo->msgid && *msginfo->msgid)
+                       compose->inreplyto = g_strdup(msginfo->msgid);
+
+               if (!compose->references) {
+                       if (msginfo->msgid && *msginfo->msgid) {
+                               if (msginfo->inreplyto && *msginfo->inreplyto)
+                                       compose->references =
+                                               g_strdup_printf("<%s>\n\t<%s>",
+                                                               msginfo->inreplyto,
+                                                               msginfo->msgid);
+                               else
+                                       compose->references =
+                                               g_strconcat("<", msginfo->msgid, ">",
+                                                           NULL);
+                       } else if (msginfo->inreplyto && *msginfo->inreplyto) {
                                compose->references =
-                                       g_strconcat("<", msginfo->msgid, ">",
+                                       g_strconcat("<", msginfo->inreplyto, ">",
                                                    NULL);
-               } else if (msginfo->inreplyto && *msginfo->inreplyto) {
-                       compose->references =
-                               g_strconcat("<", msginfo->inreplyto, ">",
-                                           NULL);
+                       }
                }
        }
 
@@ -3131,7 +3181,7 @@ error:
 ok:
        SIGNAL_UNBLOCK(buffer);
 
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 
        return buf;
 }
@@ -3162,7 +3212,7 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from)
                *(strstr(left_from, "@")) = '\0';
        }
        
-       if (left_ml && left_from && right_ml && right_from
+       if (right_ml && right_from
        &&  !strncmp(left_from, left_ml, strlen(left_ml))
        &&  !strcmp(right_from, right_ml)) {
                result = TRUE;
@@ -3184,17 +3234,23 @@ static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
        if (respect_default_to && folder->prefs->enable_default_to) {
                compose_entry_append(compose, folder->prefs->default_to,
                                        COMPOSE_TO, PREF_FOLDER);
-               compose_entry_mark_default_to(compose, folder->prefs->default_to);
+               compose_entry_indicate(compose, folder->prefs->default_to);
        }
-       if (folder->prefs->enable_default_cc)
+       if (folder->prefs->enable_default_cc) {
                compose_entry_append(compose, folder->prefs->default_cc,
                                        COMPOSE_CC, PREF_FOLDER);
-       if (folder->prefs->enable_default_bcc)
+               compose_entry_indicate(compose, folder->prefs->default_cc);
+       }
+       if (folder->prefs->enable_default_bcc) {
                compose_entry_append(compose, folder->prefs->default_bcc,
                                        COMPOSE_BCC, PREF_FOLDER);
-       if (folder->prefs->enable_default_replyto)
+               compose_entry_indicate(compose, folder->prefs->default_bcc);
+       }
+       if (folder->prefs->enable_default_replyto) {
                compose_entry_append(compose, folder->prefs->default_replyto,
                                        COMPOSE_REPLYTO, PREF_FOLDER);
+               compose_entry_indicate(compose, folder->prefs->default_replyto);
+       }
 }
 
 static void compose_reply_set_subject(Compose *compose, MsgInfo *msginfo)
@@ -3273,22 +3329,28 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                        compose_entry_append(compose,
                            msginfo->folder->prefs->default_reply_to,
                            COMPOSE_TO, PREF_FOLDER);
-                       compose_entry_mark_default_to(compose,
+                       compose_entry_indicate(compose,
                                msginfo->folder->prefs->default_reply_to);
                } else {
                        gchar *tmp1 = NULL;
                        if (!msginfo->from)
                                return;
-                       Xstrdup_a(tmp1, msginfo->from, return);
-                       extract_address(tmp1);
-                       if (to_all || to_sender ||
-                           !account_find_from_address(tmp1, FALSE))
+                       if (to_sender)
+                               compose_entry_append(compose, msginfo->from,
+                                                    COMPOSE_TO, PREF_NONE);
+                       else if (to_all) {
+                               Xstrdup_a(tmp1, msginfo->from, return);
+                               extract_address(tmp1);
                                compose_entry_append(compose,
-                                (compose->replyto && !to_sender)
-                                         ? compose->replyto :
-                                         msginfo->from ? msginfo->from : "",
+                                (!account_find_from_address(tmp1, FALSE))
+                                         ? msginfo->from :
+                                         msginfo->to,
                                          COMPOSE_TO, PREF_NONE);
-                       else if (!to_all && !to_sender) {
+                               if (compose->replyto)
+                                               compose_entry_append(compose,
+                                                       compose->replyto,
+                                                       COMPOSE_CC, PREF_NONE);
+                       } else {
                                if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
                                    !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
                                    !folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
@@ -3333,6 +3395,11 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                 compose->followup_to ? compose->followup_to :
                                 compose->newsgroups ? compose->newsgroups : "",
                                 COMPOSE_NEWSGROUPS, PREF_NONE);
+
+                       compose_entry_append
+                               (compose,
+                                msginfo->cc ? msginfo->cc : "",
+                                COMPOSE_CC, PREF_NONE);
                } 
                else 
                        compose_entry_append
@@ -3528,10 +3595,10 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        gint len;
        FILE *fp;
        gboolean prev_autowrap;
-       gboolean badtxt = FALSE;
-       struct stat file_stat;
+       GStatBuf file_stat;
        int ret;
        GString *file_contents = NULL;
+       ComposeInsertResult result = COMPOSE_INSERT_SUCCESS;
 
        cm_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
 
@@ -3554,7 +3621,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                                                "in the message body. Are you sure you want to do that?"),
                                                to_human_readable(file_stat.st_size));
                        aval = alertpanel_full(_("Are you sure?"), msg, GTK_STOCK_CANCEL,
-                                       _("+_Insert"), NULL, TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
+                                       g_strconcat("+", _("_Insert"), NULL), NULL, TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
                        g_free(msg);
 
                        /* do we ask for confirmation next time? */
@@ -3597,9 +3664,17 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
                if (g_utf8_validate(buf, -1, NULL) == TRUE)
                        str = g_strdup(buf);
-               else
+               else {
+                       codeconv_set_strict(TRUE);
                        str = conv_codeset_strdup
                                (buf, cur_encoding, CS_INTERNAL);
+                       codeconv_set_strict(FALSE);
+
+                       if (!str) {
+                               result = COMPOSE_INSERT_INVALID_CHARACTER;
+                               break;
+                       }
+               }
                if (!str) continue;
 
                /* strip <CR> if DOS/Windows file,
@@ -3615,23 +3690,22 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                g_free(str);
        }
 
-       gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1);
-       g_string_free(file_contents, TRUE);
+       if (result == COMPOSE_INSERT_SUCCESS) {
+               gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1);
 
-       compose_changed_cb(NULL, compose);
-       g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
-                                         G_CALLBACK(text_inserted),
-                                         compose);
-       compose->autowrap = prev_autowrap;
-       if (compose->autowrap)
-               compose_wrap_all(compose);
+               compose_changed_cb(NULL, compose);
+               g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
+                                                 G_CALLBACK(text_inserted),
+                                                 compose);
+               compose->autowrap = prev_autowrap;
+               if (compose->autowrap)
+                       compose_wrap_all(compose);
+       }
 
+       g_string_free(file_contents, TRUE);
        fclose(fp);
 
-       if (badtxt)
-               return COMPOSE_INSERT_INVALID_CHARACTER;
-       else 
-               return COMPOSE_INSERT_SUCCESS;
+       return result;
 }
 
 static gboolean compose_attach_append(Compose *compose, const gchar *file,
@@ -3668,9 +3742,18 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                alertpanel_error("Can't get file size of %s\n", filename);
                return FALSE;
        }
-       if (size == 0) {
-               alertpanel_error(_("File %s is empty."), filename);
-               return FALSE;
+
+       /* In batch mode, we allow 0-length files to be attached no questions asked */
+       if (size == 0 && !compose->batch) {
+               gchar * msg = g_strdup_printf(_("File %s is empty."), filename);
+               AlertValue aval = alertpanel_full(_("Empty file"), msg, 
+                               GTK_STOCK_CANCEL,  g_strconcat("+", _("_Attach anyway"), NULL), NULL, FALSE,
+                               NULL, ALERT_WARNING, G_ALERTDEFAULT);
+               g_free(msg);
+
+               if (aval != G_ALERTALTERNATE) {
+                       return FALSE;
+               }
        }
        if ((fp = g_fopen(file, "rb")) == NULL) {
                alertpanel_error(_("Can't read %s."), filename);
@@ -3702,7 +3785,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
 
                        ainfo->name = g_strdup_printf(_("Message: %s"), name);
 
-                       procmsg_msginfo_free(msginfo);
+                       procmsg_msginfo_free(&msginfo);
                } else {
                        if (!g_ascii_strncasecmp(content_type, "text/", 5)) {
                                ainfo->charset = g_strdup(charset);
@@ -3798,7 +3881,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        if (!mimeinfo) return;
 
        if (mimeinfo->node->children == NULL) {
-               procmime_mimeinfo_free_all(mimeinfo);
+               procmime_mimeinfo_free_all(&mimeinfo);
                return;
        }
 
@@ -3840,7 +3923,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
 
                outfile = procmime_get_tmp_file_name(child);
                if ((err = procmime_get_part(outfile, child)) < 0)
-                       g_warning("Can't get the part of multipart message. (%s)", strerror(-err));
+                       g_warning("Can't get the part of multipart message. (%s)", g_strerror(-err));
                else {
                        gchar *content_type;
 
@@ -3868,7 +3951,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                g_free(outfile);
                NEXT_PART_NOT_CHILD(child);
        }
-       procmime_mimeinfo_free_all(mimeinfo);
+       procmime_mimeinfo_free_all(&mimeinfo);
 }
 
 #undef NEXT_PART_NOT_CHILD
@@ -4074,7 +4157,7 @@ static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
        
        if (len == 0) {
                g_free(str);
-               g_warning("compose_get_line_break_pos: len = 0!\n");
+               g_warning("compose_get_line_break_pos: len = 0!");
                return FALSE;
        }
 
@@ -4269,7 +4352,7 @@ static gboolean compose_join_next_line(Compose *compose,
                last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
                last->next = NULL; \
        } else { \
-               g_warning("alloc error scanning URIs\n"); \
+               g_warning("alloc error scanning URIs"); \
        }
 
 static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
@@ -4279,7 +4362,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
        GtkTextIter iter, break_pos, end_of_line;
        gchar *quote_str = NULL;
        gint quote_len;
-       gboolean wrap_quote = prefs_common.linewrap_quote;
+       gboolean wrap_quote = force || prefs_common.linewrap_quote;
        gboolean prev_autowrap = compose->autowrap;
        gint startq_offset = -1, noq_offset = -1;
        gint uri_start = -1, uri_stop = -1;
@@ -4298,7 +4381,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
        if (force) {
                modified = TRUE;
        }
-       if (compose->draft_timeout_tag == -2) {
+       if (compose->draft_timeout_tag == COMPOSE_DRAFT_TIMEOUT_FORBIDDEN) {
                modified = TRUE;
        }
 
@@ -4315,7 +4398,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it
        }
 
 
-       if (compose->draft_timeout_tag == -2) {
+       if (compose->draft_timeout_tag == COMPOSE_DRAFT_TIMEOUT_FORBIDDEN) {
                if (gtk_text_iter_ends_line(&iter)) {
                        while (gtk_text_iter_ends_line(&iter) &&
                               gtk_text_iter_forward_line(&iter))
@@ -4677,9 +4760,14 @@ static void compose_wrap_all_full(Compose *compose, gboolean force)
        buffer = gtk_text_view_get_buffer(text);
 
        gtk_text_buffer_get_start_iter(buffer, &iter);
+
+       undo_wrapping(compose->undostruct, TRUE);
+
        while (!gtk_text_iter_is_end(&iter) && modified)
                modified = compose_beautify_paragraph(compose, &iter, force);
 
+       undo_wrapping(compose->undostruct, FALSE);
+
 }
 
 static void compose_set_title(Compose *compose)
@@ -4743,7 +4831,7 @@ compose_current_mail_account(void)
                                                                        \
                len = strlen(str) + 3;                                  \
                if ((__tmp = alloca(len)) == NULL) {                    \
-                       g_warning("can't allocate memory\n");           \
+                       g_warning("can't allocate memory");             \
                        g_string_free(header, TRUE);                    \
                        return NULL;                                    \
                }                                                       \
@@ -4753,7 +4841,7 @@ compose_current_mail_account(void)
                gchar *__tmp;                                           \
                                                                        \
                if ((__tmp = alloca(strlen(str) + 1)) == NULL) {        \
-                       g_warning("can't allocate memory\n");           \
+                       g_warning("can't allocate memory");             \
                        g_string_free(header, TRUE);                    \
                        return NULL;                                    \
                } else                                                  \
@@ -4771,7 +4859,7 @@ compose_current_mail_account(void)
                                                                        \
                len = strlen(str) + 3;                                  \
                if ((__tmp = alloca(len)) == NULL) {                    \
-                       g_warning("can't allocate memory\n");           \
+                       g_warning("can't allocate memory");             \
                        errret;                                         \
                }                                                       \
                g_snprintf(__tmp, len, "\"%s\"", str);                  \
@@ -4780,7 +4868,7 @@ compose_current_mail_account(void)
                gchar *__tmp;                                           \
                                                                        \
                if ((__tmp = alloca(strlen(str) + 1)) == NULL) {        \
-                       g_warning("can't allocate memory\n");           \
+                       g_warning("can't allocate memory");             \
                        errret;                                         \
                } else                                                  \
                        strcpy(__tmp, str);                             \
@@ -4948,8 +5036,8 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                                gtk_widget_show_all(compose->window);
                        }
                        aval = alertpanel(_("Send"),
-                                         _("The only recipient is the default CC address. Send anyway?"),
-                                         GTK_STOCK_CANCEL, _("+_Send"), NULL);
+                                         _("The only recipient is the default Cc address. Send anyway?"),
+                                         GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -4981,7 +5069,7 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        }
                        aval = alertpanel(_("Send"),
                                          _("The only recipient is the default BCC address. Send anyway?"),
-                                         GTK_STOCK_CANCEL, _("+_Send"), NULL);
+                                         GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -5014,9 +5102,9 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                        gchar *message;
 
                        if (compose->sending)
-                               button_label = _("+_Send");
+                               button_label = g_strconcat("+", _("_Send"), NULL);
                        else
-                               button_label = _("+_Queue");
+                               button_label = g_strconcat("+", _("_Queue"), NULL);
                        message = g_strdup_printf(_("Subject is empty. %s"),
                                        compose->sending?_("Send it anyway?"):
                                        _("Queue it anyway?"));
@@ -5086,7 +5174,7 @@ gint compose_send(Compose *compose)
                        alertpanel_error(_("Could not queue message for sending:\n\n"
                                           "Signature failed: %s"), privacy_get_error());
                } else if (val == -2 && errno != 0) {
-                       alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
+                       alertpanel_error(_("Could not queue message for sending:\n\n%s."), g_strerror(errno));
                } else {
                        alertpanel_error(_("Could not queue message for sending."));
                }
@@ -5133,7 +5221,7 @@ gint compose_send(Compose *compose)
                                if (tmp) {
                                        debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
                                        folder_item_remove_msg(folder, tmp->msgnum);
-                                       procmsg_msginfo_free(tmp);
+                                       procmsg_msginfo_free(&tmp);
                                } 
                        }
                }
@@ -5149,7 +5237,7 @@ gint compose_send(Compose *compose)
                        if (tmp) {
                                debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
                                folder_item_remove_msg(folder, tmp->msgnum);
-                               procmsg_msginfo_free(tmp);
+                               procmsg_msginfo_free(&tmp);
                        }
                }
                if (!discard_window) {
@@ -5290,7 +5378,10 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        cm_return_val_if_fail(compose->account->address != NULL, -1);
 
        /* Resent-Date */
-       get_rfc822_date(buf, sizeof(buf));
+       if (prefs_common.hide_timezone)
+               get_rfc822_date_hide_tz(buf, sizeof(buf));
+       else
+               get_rfc822_date(buf, sizeof(buf));
        err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
 
        /* Resent-From */
@@ -5316,25 +5407,12 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        }
 
        /* Resent-Message-ID */
-       if (compose->account->set_domain && compose->account->domain) {
-               g_snprintf(buf, sizeof(buf), "%s", compose->account->domain); 
-       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
-               g_snprintf(buf, sizeof(buf), "%s", 
-                       strchr(compose->account->address, '@') ?
-                               strchr(compose->account->address, '@')+1 :
-                               compose->account->address);
-       } else {
-               g_snprintf(buf, sizeof(buf), "%s", "");
-       }
-
        if (compose->account->gen_msgid) {
-               gchar *addr = NULL;
-               if (compose->account->msgid_with_addr) {
-                       addr = compose->account->address;
-               }
-               generate_msgid(buf, sizeof(buf), addr);
-               err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
-               compose->msgid = g_strdup(buf);
+               gchar *addr = prefs_account_generate_msgid(compose->account);
+               err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", addr) < 0);
+               if (compose->msgid)
+                       g_free(compose->msgid);
+               compose->msgid = addr;
        } else {
                compose->msgid = NULL;
        }
@@ -5441,8 +5519,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
 {
        GtkTextBuffer *buffer;
        GtkTextIter start, end;
-       gchar *chars;
-       gchar *buf;
+       gchar *chars, *tmp_enc_file, *content;
+       gchar *buf, *msg;
        const gchar *out_codeset;
        EncodingType encoding = ENC_UNKNOWN;
        MimeInfo *mimemsg, *mimetext;
@@ -5450,10 +5528,19 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        const gchar *src_codeset = CS_INTERNAL;
        gchar *from_addr = NULL;
        gchar *from_name = NULL;
+       FolderItem *outbox;
 
-       if (action == COMPOSE_WRITE_FOR_SEND)
+       if (action == COMPOSE_WRITE_FOR_SEND) {
                attach_parts = TRUE;
 
+               /* We're sending the message, generate a Message-ID
+                * if necessary. */
+               if (compose->msgid == NULL &&
+                               compose->account->gen_msgid) {
+                       compose->msgid = prefs_account_generate_msgid(compose->account);
+               }
+       }
+
        /* create message MimeInfo */
        mimemsg = procmime_mimeinfo_new();
         mimemsg->type = MIMETYPE_MESSAGE;
@@ -5530,12 +5617,12 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
 
                if (!buf) {
                        AlertValue aval;
-                       gchar *msg;
 
                        msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
                                                "to the specified %s charset.\n"
                                                "Send it as %s?"), out_codeset, src_codeset);
-                       aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
+                       aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL,
+                                              g_strconcat("+", _("_Send"), NULL), NULL, FALSE,
                                              NULL, ALERT_ERROR, G_ALERTDEFAULT);
                        g_free(msg);
 
@@ -5555,7 +5642,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        }
        g_free(chars);
 
-       if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
+       if (prefs_common.rewrite_first_from && (encoding == ENC_8BIT || encoding == ENC_7BIT)) {
                if (!strncmp(buf, "From ", sizeof("From ")-1) ||
                    strstr(buf, "\nFrom ") != NULL) {
                        encoding = ENC_QUOTED_PRINTABLE;
@@ -5578,8 +5665,12 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
            privacy_system_can_sign(compose->privacy_system)) {
                encoding = ENC_QUOTED_PRINTABLE;
        }
-       
+
+#ifdef G_OS_WIN32
+       debug_print("main text: %Id bytes encoded as %s in %d\n",
+#else
        debug_print("main text: %zd bytes encoded as %s in %d\n",
+#endif
                strlen(buf), out_codeset, encoding);
 
        /* check for line length limit */
@@ -5587,7 +5678,6 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
            encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
            check_line_length(buf, 1000, &line) < 0) {
                AlertValue aval;
-               gchar *msg;
 
                msg = g_strdup_printf
                        (_("Line %d exceeds the line length limit (998 bytes).\n"
@@ -5659,9 +5749,57 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        }
        g_free(from_name);
        g_free(from_addr);
+
+       if (compose->use_encryption) {
+               if (compose->encdata != NULL &&
+                               strcmp(compose->encdata, "_DONT_ENCRYPT_")) {
+
+                       /* First, write an unencrypted copy and save it to outbox, if
+                        * user wants that. */
+                       if (compose->account->save_encrypted_as_clear_text) {
+                               debug_print("saving sent message unencrypted...\n");
+                               FILE *tmpfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmp_enc_file);
+                               if (tmpfp) {
+                                       fclose(tmpfp);
+
+                                       /* fp now points to a file with headers written,
+                                        * let's make a copy. */
+                                       rewind(fp);
+                                       content = file_read_stream_to_str(fp);
+
+                                       str_write_to_file(content, tmp_enc_file);
+                                       g_free(content);
+
+                                       /* Now write the unencrypted body. */
+                                       if ((tmpfp = g_fopen(tmp_enc_file, "a")) != NULL) {
+                                               procmime_write_mimeinfo(mimemsg, tmpfp);
+                                               fclose(tmpfp);
+
+                                               outbox = folder_find_item_from_identifier(compose_get_save_to(compose));
+                                               if (!outbox)
+                                                       outbox = folder_get_default_outbox();
+
+                                               procmsg_save_to_outbox(outbox, tmp_enc_file, TRUE);
+                                               claws_unlink(tmp_enc_file);
+                                       } else {
+                                               g_warning("Can't open file '%s'", tmp_enc_file);
+                                       }
+                               } else {
+                                       g_warning("couldn't get tempfile");
+                               }
+                       }
+                       if (!privacy_encrypt(compose->privacy_system, mimemsg, compose->encdata)) {
+                               debug_print("Couldn't encrypt mime structure: %s.\n",
+                                               privacy_get_error());
+                               alertpanel_error(_("Couldn't encrypt the email: %s"),
+                                               privacy_get_error());
+                       }
+               }
+       }
+
        procmime_write_mimeinfo(mimemsg, fp);
        
-       procmime_mimeinfo_free_all(mimemsg);
+       procmime_mimeinfo_free_all(&mimemsg);
 
        return 0;
 }
@@ -5682,7 +5820,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
        /* chmod for security */
        if (change_file_mode_rw(fp, file) < 0) {
                FILE_OP_ERROR(file, "chmod");
-               g_warning("can't change file mode\n");
+               g_warning("can't change file mode");
        }
 
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
@@ -5694,8 +5832,11 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
                (tmp, CS_INTERNAL, conv_get_locale_charset_str());
 
        g_free(tmp);
-       if (!chars) return -1;
-
+       if (!chars) {
+               fclose(fp);
+               claws_unlink(file);
+               return -1;
+       }
        /* write body */
        len = strlen(chars);
        if (fwrite(chars, sizeof(gchar), len, fp) != len) {
@@ -5735,7 +5876,7 @@ static gint compose_remove_reedit_target(Compose *compose, gboolean force)
             folder_has_parent_of_type(item, F_DRAFT) 
             || msginfo == compose->autosaved_draft)) {
                if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
-                       g_warning("can't remove the old message\n");
+                       g_warning("can't remove the old message");
                        return -1;
                } else {
                        debug_print("removed reedit target %d\n", msginfo->msgnum);
@@ -5772,7 +5913,7 @@ static gboolean compose_warn_encryption(Compose *compose)
                return TRUE;
 
        val = alertpanel_full(_("Encryption warning"), warning,
-                 GTK_STOCK_CANCEL, _("+C_ontinue"), NULL,
+                 GTK_STOCK_CANCEL, g_strconcat("+", _("C_ontinue"), NULL), NULL,
                  TRUE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
        if (val & G_ALERTDISABLE) {
                val &= ~G_ALERTDISABLE;
@@ -5839,7 +5980,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        tmp = g_strdup_printf("%s%cqueue.%p%08x", get_tmp_dir(),
                              G_DIR_SEPARATOR, compose, (guint) rand());
        debug_print("queuing to %s\n", tmp);
-       if ((fp = g_fopen(tmp, "wb")) == NULL) {
+       if ((fp = g_fopen(tmp, "w+b")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                g_free(tmp);
                return -2;
@@ -5847,7 +5988,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
 
        if (change_file_mode_rw(fp, tmp) < 0) {
                FILE_OP_ERROR(tmp, "chmod");
-               g_warning("can't change file mode\n");
+               g_warning("can't change file mode");
        }
 
        /* queueing variables */
@@ -5901,7 +6042,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
                err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
                if (compose->use_encryption) {
-                       gchar *encdata;
                        if (!compose_warn_encryption(compose)) {
                                fclose(fp);
                                claws_unlink(tmp);
@@ -5911,16 +6051,16 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                        if (mailac && mailac->encrypt_to_self) {
                                GSList *tmp_list = g_slist_copy(compose->to_list);
                                tmp_list = g_slist_append(tmp_list, compose->account->address);
-                               encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
+                               compose->encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
                                g_slist_free(tmp_list);
                        } else {
-                               encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
+                               compose->encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
                        }
-                       if (encdata != NULL) {
-                               if (strcmp(encdata, "_DONT_ENCRYPT_")) {
+                       if (compose->encdata != NULL) {
+                               if (strcmp(compose->encdata, "_DONT_ENCRYPT_")) {
                                        err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
                                        err |= (fprintf(fp, "X-Claws-Encrypt-Data:%s\n", 
-                                               encdata) < 0);
+                                               compose->encdata) < 0);
                                } /* else we finally dont want to encrypt */
                        } else {
                                err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
@@ -5933,7 +6073,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                                g_free(tmp);
                                return -5;
                        }
-                       g_free(encdata);
                }
        }
 
@@ -5951,17 +6090,25 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
        /* Message-ID of message replying to */
        if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
-               gchar *folderid;
-               
-               folderid = folder_item_get_identifier(compose->replyinfo->folder);
+               gchar *folderid = NULL;
+
+               if (compose->replyinfo->folder)
+                       folderid = folder_item_get_identifier(compose->replyinfo->folder);
+               if (folderid == NULL)
+                       folderid = g_strdup("NULL");
+
                err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
                g_free(folderid);
        }
        /* Message-ID of message forwarding to */
        if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
-               gchar *folderid;
+               gchar *folderid = NULL;
                
-               folderid = folder_item_get_identifier(compose->fwdinfo->folder);
+               if (compose->fwdinfo->folder)
+                       folderid = folder_item_get_identifier(compose->fwdinfo->folder);
+               if (folderid == NULL)
+                       folderid = g_strdup("NULL");
+
                err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
                g_free(folderid);
        }
@@ -5989,7 +6136,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                }
        }
        if (err == TRUE) {
-               g_warning("failed to write queue message\n");
+               g_warning("failed to write queue message");
                fclose(fp);
                claws_unlink(tmp);
                g_free(tmp);
@@ -6008,14 +6155,14 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                queue = account_get_special_folder(compose->account, F_QUEUE);
        }
        if (!queue) {
-               g_warning("can't find queue folder\n");
+               g_warning("can't find queue folder");
                claws_unlink(tmp);
                g_free(tmp);
                return -1;
        }
        folder_item_scan(queue);
        if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
-               g_warning("can't queue the message\n");
+               g_warning("can't queue the message");
                claws_unlink(tmp);
                g_free(tmp);
                return -1;
@@ -6044,7 +6191,7 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
        AttachInfo *ainfo;
        GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
        MimeInfo *mimepart;
-       struct stat statbuf;
+       GStatBuf statbuf;
        gchar *type, *subtype;
        GtkTreeModel *model;
        GtkTreeIter iter;
@@ -6068,13 +6215,14 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
                        }
                        continue;
                }
+               if (g_stat(ainfo->file, &statbuf) < 0)
+                       return -1;
+
                mimepart = procmime_mimeinfo_new();
                mimepart->content = MIMECONTENT_FILE;
                mimepart->data.filename = g_strdup(ainfo->file);
                mimepart->tmp = FALSE; /* or we destroy our attachment */
                mimepart->offset = 0;
-
-               g_stat(ainfo->file, &statbuf);
                mimepart->length = statbuf.st_size;
 
                type = g_strdup(ainfo->content_type);
@@ -6157,7 +6305,7 @@ static gchar *compose_quote_list_of_addresses(gchar *str)
                                faddr = g_strconcat(name, addr, NULL);
                                g_free(name);
                                g_free(addr);
-                               debug_print("new auto-quoted address: '%s'", faddr);
+                               debug_print("new auto-quoted address: '%s'\n", faddr);
                        }
                }
                if (result == NULL)
@@ -6307,7 +6455,10 @@ static gchar *compose_get_header(Compose *compose)
        header = g_string_sized_new(64);
 
        /* Date */
-       get_rfc822_date(buf, sizeof(buf));
+       if (prefs_common.hide_timezone)
+               get_rfc822_date_hide_tz(buf, sizeof(buf));
+       else
+               get_rfc822_date(buf, sizeof(buf));
        g_string_append_printf(header, "Date: %s\n", buf);
 
        /* From */
@@ -6353,11 +6504,22 @@ static gchar *compose_get_header(Compose *compose)
                
                g_string_append_printf(header, "From: %s <%s>\n",
                        qname, from_address);
+               if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
+                   compose->return_receipt) {
+                       compose_convert_header(compose, buf, sizeof(buf), from_name,
+                                              strlen("Disposition-Notification-To: "),
+                                              TRUE);
+                       g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, from_address);
+               }
                if (qname != name)
                        g_free(qname);
-       } else
+       } else {
                g_string_append_printf(header, "From: %s\n", from_address);
-       
+               if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
+                   compose->return_receipt)
+                       g_string_append_printf(header, "Disposition-Notification-To: %s\n", from_address);
+
+       }
        g_free(from_name);
        g_free(from_address);
 
@@ -6392,27 +6554,9 @@ static gchar *compose_get_header(Compose *compose)
        g_free(str);
 
        /* Message-ID */
-       if (compose->account->set_domain && compose->account->domain) {
-               g_snprintf(buf, sizeof(buf), "%s", compose->account->domain); 
-       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
-               g_snprintf(buf, sizeof(buf), "%s", 
-                       strchr(compose->account->address, '@') ?
-                               strchr(compose->account->address, '@')+1 :
-                               compose->account->address);
-       } else {
-               g_snprintf(buf, sizeof(buf), "%s", "");
-       }
-       
-       if (compose->account->gen_msgid) {
-               gchar *addr = NULL;
-               if (compose->account->msgid_with_addr) {
-                       addr = compose->account->address;
-               }
-               generate_msgid(buf, sizeof(buf), addr);
-               g_string_append_printf(header, "Message-ID: <%s>\n", buf);
-               compose->msgid = g_strdup(buf);
-       } else {
-               compose->msgid = NULL;
+       if (compose->msgid != NULL && strlen(compose->msgid) > 0) {
+               g_string_append_printf(header, "Message-ID: <%s>\n",
+                               compose->msgid);
        }
 
        if (compose->remove_references == FALSE) {
@@ -6450,7 +6594,8 @@ static gchar *compose_get_header(Compose *compose)
                        gtk_major_version, gtk_minor_version, gtk_micro_version,
                        TARGET_ALIAS);
        }
-       if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
+       if (compose->account->gen_xmailer &&
+           g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
                g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
                        prog_version,
                        gtk_major_version, gtk_minor_version, gtk_micro_version,
@@ -6510,21 +6655,6 @@ static gchar *compose_get_header(Compose *compose)
                                     compose->priority);
        }
 
-       /* Request Return Receipt */
-       if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
-               if (compose->return_receipt) {
-                       if (compose->account->name
-                           && *compose->account->name) {
-                               compose_convert_header(compose, buf, sizeof(buf), 
-                                                      compose->account->name, 
-                                                      strlen("Disposition-Notification-To: "),
-                                                      TRUE);
-                               g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
-                       } else
-                               g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
-               }
-       }
-
        /* get special headers */
        for (list = compose->header_list; list; list = list->next) {
                ComposeHeaderEntry *headerentry;
@@ -6654,7 +6784,7 @@ static void compose_add_to_addressbook_cb(GtkMenuItem *menuitem, gpointer user_d
        if (*address != '\0') {
                gchar *name = procheader_get_fromname(address);
                extract_address(address);
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
                addressbook_add_contact(name, address, NULL, NULL);
 #else
                debug_print("%s: %s\n", name, address);
@@ -6754,9 +6884,6 @@ static void compose_create_header_entry(Compose *compose)
        gboolean standard_header = FALSE;
        GtkListStore *model;
        GtkTreeIter iter;
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = compose->tooltips;
-#endif
        
        headerentry = g_new0(ComposeHeaderEntry, 1);
 
@@ -6791,7 +6918,11 @@ static void compose_create_header_entry(Compose *compose)
        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);
-       
+
+       /* Putting only the combobox child into focus chain of its parent causes
+        * the parent to be skipped when changing focus via Tab or Shift+Tab.
+        * This eliminates need to pres Tab twice in order to really get from the
+        * combobox to next widget. */
        GList *l = NULL;
        l = g_list_prepend(l, gtk_bin_get_child(GTK_BIN(combo)));
        gtk_container_set_focus_chain(GTK_CONTAINER(combo), l);
@@ -6800,7 +6931,7 @@ static void compose_create_header_entry(Compose *compose)
        gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1,
                        compose->header_nextrow, compose->header_nextrow+1,
                        GTK_SHRINK, GTK_FILL, 0, 0);
-       if (compose->header_last && (compose->draft_timeout_tag != -2)) {
+       if (compose->header_last && (compose->draft_timeout_tag != COMPOSE_DRAFT_TIMEOUT_FORBIDDEN)) {
                const gchar *last_header_entry = gtk_entry_get_text(
                                GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))));
                string = headers;
@@ -6825,6 +6956,10 @@ static void compose_create_header_entry(Compose *compose)
        if (header)
                gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((combo)))), header);
 
+       gtk_editable_set_editable(
+               GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((combo)))),
+               prefs_common.type_any_header);
+
        g_signal_connect_after(G_OBJECT(gtk_bin_get_child(GTK_BIN((combo)))), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
 
@@ -6970,21 +7105,14 @@ static void compose_remove_header_entries(Compose *compose)
 static GtkWidget *compose_create_header(Compose *compose) 
 {
        GtkWidget *from_optmenu_hbox;
-       GtkWidget *header_scrolledwin_main;
        GtkWidget *header_table_main;
        GtkWidget *header_scrolledwin;
        GtkWidget *header_table;
 
        /* parent with account selection and from header */
-       header_scrolledwin_main = gtk_scrolled_window_new(NULL, NULL);
-       gtk_widget_show(header_scrolledwin_main);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin_main), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-
        header_table_main = gtk_table_new(2, 2, FALSE);
        gtk_widget_show(header_table_main);
        gtk_container_set_border_width(GTK_CONTAINER(header_table_main), BORDER_WIDTH);
-       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin_main), header_table_main);
-       gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN((header_scrolledwin_main)))), GTK_SHADOW_NONE);
 
        from_optmenu_hbox = compose_account_option_menu_create(compose);
        gtk_table_attach(GTK_TABLE(header_table_main), from_optmenu_hbox,
@@ -6997,9 +7125,11 @@ static GtkWidget *compose_create_header(Compose *compose)
 
        header_table = gtk_table_new(2, 2, FALSE);
        gtk_widget_show(header_table);
-       gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
+       gtk_container_set_border_width(GTK_CONTAINER(header_table), 0);
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
-       gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN((header_scrolledwin)))), GTK_SHADOW_NONE);
+       gtk_container_set_focus_vadjustment(GTK_CONTAINER(header_table),
+                       gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(header_scrolledwin)));
+       gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN(header_scrolledwin))), GTK_SHADOW_NONE);
 
        gtk_table_attach(GTK_TABLE(header_table_main), header_scrolledwin,
                                  0, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 2);
@@ -7012,7 +7142,7 @@ static GtkWidget *compose_create_header(Compose *compose)
 
        compose->table = NULL;
 
-       return header_scrolledwin_main;
+       return header_table_main;
 }
 
 static gboolean popup_attach_button_pressed(GtkWidget *widget, gpointer data)
@@ -7301,8 +7431,9 @@ static void compose_dict_changed(void *data)
 {
        Compose *compose = (Compose *) data;
 
-       if(compose->gtkaspell && 
-                  compose->gtkaspell->recheck_when_changing_dict == FALSE)
+       if(!compose->gtkaspell)
+               return; 
+       if(compose->gtkaspell->recheck_when_changing_dict == FALSE)
                return;
 
        gtkaspell_highlight_all(compose->gtkaspell);
@@ -7372,6 +7503,11 @@ static Compose *compose_create(PrefsAccount *account,
 
        cm_return_val_if_fail(account != NULL, NULL);
 
+       gtkut_convert_int_to_gdk_color(prefs_common.default_header_bgcolor,
+                                          &default_header_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.default_header_color,
+                                          &default_header_color);
+
        debug_print("Creating compose window...\n");
        compose = g_new0(Compose, 1);
 
@@ -7382,10 +7518,6 @@ static Compose *compose_create(PrefsAccount *account,
        compose->mutex = cm_mutex_new();
        compose->set_cursor_pos = -1;
 
-#if !(GTK_CHECK_VERSION(2,12,0))
-       compose->tooltips = tips;
-#endif
-
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose");
 
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
@@ -7575,6 +7707,7 @@ static Compose *compose_create(PrefsAccount *account,
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Cyrillic", "Options/Encoding/Cyrillic", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_ISO_8859_5, "Options/Encoding/Cyrillic/"CS_ISO_8859_5, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_KOI8_R, "Options/Encoding/Cyrillic/"CS_KOI8_R, GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_MACCYR, "Options/Encoding/Cyrillic/"CS_MACCYR, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_KOI8_U, "Options/Encoding/Cyrillic/"CS_KOI8_U, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Cyrillic", CS_WINDOWS_1251, "Options/Encoding/Cyrillic/"CS_WINDOWS_1251, GTK_UI_MANAGER_MENUITEM)
 
@@ -7634,7 +7767,6 @@ static Compose *compose_create(PrefsAccount *account,
        
        /* Notebook */
        notebook = gtk_notebook_new();
-       gtk_widget_set_size_request(notebook, -1, prefs_common.compose_notebook_height);
        gtk_widget_show(notebook);
 
        /* header labels and entries */
@@ -7674,7 +7806,7 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
        gtk_widget_show(subject);
 
-       label = gtk_label_new(_("Subject:"));
+       label = gtk_label_new_with_mnemonic(_("S_ubject:"));
        gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
        gtk_widget_show(label);
 
@@ -7686,6 +7818,7 @@ static Compose *compose_create(PrefsAccount *account,
        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);
+       gtk_label_set_mnemonic_widget(GTK_LABEL(label), subject_entry);
        gtk_widget_show(subject_entry);
        compose->subject_entry = subject_entry;
        gtk_container_add(GTK_CONTAINER(subject_frame), subject);
@@ -7724,8 +7857,6 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
        
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
-       g_signal_connect(G_OBJECT(notebook), "size_allocate",
-                        G_CALLBACK(compose_notebook_size_alloc), compose);     
        g_signal_connect_after(G_OBJECT(text), "size_allocate",
                               G_CALLBACK(compose_edit_size_alloc),
                               ruler);
@@ -7762,8 +7893,12 @@ static Compose *compose_create(PrefsAccount *account,
        /* pane between attach clist and text */
        paned = gtk_vpaned_new();
        gtk_container_add(GTK_CONTAINER(vbox2), paned);
-       gtk_paned_add1(GTK_PANED(paned), notebook);
-       gtk_paned_add2(GTK_PANED(paned), edit_vbox);
+       gtk_paned_pack1(GTK_PANED(paned), notebook, FALSE, FALSE);
+       gtk_paned_pack2(GTK_PANED(paned), edit_vbox, TRUE, FALSE);
+       gtk_paned_set_position(GTK_PANED(paned), prefs_common.compose_notebook_height);
+       g_signal_connect(G_OBJECT(notebook), "size_allocate",
+                        G_CALLBACK(compose_notebook_size_alloc), paned);
+
        gtk_widget_show_all(paned);
 
 
@@ -7852,6 +7987,7 @@ static Compose *compose_create(PrefsAccount *account,
        compose->use_signing    = FALSE;
        compose->use_encryption = FALSE;
        compose->privacy_system = NULL;
+       compose->encdata        = NULL;
 
        compose->modified = FALSE;
 
@@ -7867,7 +8003,13 @@ static Compose *compose_create(PrefsAccount *account,
        compose->exteditor_file    = NULL;
        compose->exteditor_pid     = -1;
        compose->exteditor_tag     = -1;
-       compose->draft_timeout_tag = -2; /* inhibit auto-drafting while loading */
+       compose->exteditor_socket  = NULL;
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN; /* inhibit auto-drafting while loading */
+
+       compose->folder_update_callback_id =
+               hooks_register_hook(FOLDER_UPDATE_HOOKLIST,
+                               compose_update_folder_hook,
+                               (gpointer) compose);
 
 #if USE_ENCHANT
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", FALSE);
@@ -7924,7 +8066,7 @@ static Compose *compose_create(PrefsAccount *account,
                gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))),
                                prefs_common_translated_header_name("Newsgroups:"));
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_set_target_compose(compose);
 #endif 
        if (mode != COMPOSE_REDIRECT)
@@ -7969,12 +8111,10 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        GtkWidget *hbox;
        GtkWidget *optmenu;
        GtkWidget *optmenubox;
+       GtkWidget *fromlabel;
        GtkListStore *menu;
        GtkTreeIter iter;
        GtkWidget *from_name = NULL;
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = compose->tooltips;
-#endif
 
        gint num = 0, def_menu = 0;
        
@@ -7985,11 +8125,13 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
        menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
 
-       hbox = gtk_hbox_new(FALSE, 6);
+       hbox = gtk_hbox_new(FALSE, 4);
        from_name = gtk_entry_new();
        
        g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
+       g_signal_connect_after(G_OBJECT(from_name), "activate",
+                        G_CALLBACK(from_name_activate_cb), optmenu);
 
        for (; accounts != NULL; accounts = accounts->next, num++) {
                PrefsAccount *ac = (PrefsAccount *)accounts->data;
@@ -7997,7 +8139,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
 
                if (ac == compose->account) def_menu = num;
 
-               name = g_markup_printf_escaped(_("From: <i>%s</i>"),
+               name = g_markup_printf_escaped("<i>%s</i>",
                                       ac->account_name);
                
                if (ac == compose->account) {
@@ -8012,6 +8154,14 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
                                                       ac->address);
                                gtk_entry_set_text(GTK_ENTRY(from_name), from);
                        }
+                       if (cur_account != compose->account) {
+                               gtk_widget_modify_base(
+                                       GTK_WIDGET(from_name),
+                                       GTK_STATE_NORMAL, &default_header_bgcolor);
+                               gtk_widget_modify_text(
+                                       GTK_WIDGET(from_name),
+                                       GTK_STATE_NORMAL, &default_header_color);
+                       }
                }
                COMBOBOX_ADD(menu, name, ac->account_id);
                g_free(name);
@@ -8027,8 +8177,21 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
                         G_CALLBACK(compose_entry_popup_extend),
                         NULL);
 
+       fromlabel = gtk_label_new_with_mnemonic(_("_From:"));
+       gtk_label_set_mnemonic_widget(GTK_LABEL(fromlabel), from_name);
+
+       gtk_box_pack_start(GTK_BOX(hbox), fromlabel, FALSE, FALSE, 4);
        gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
+
+       /* Putting only the GtkEntry into focus chain of parent hbox causes
+        * the account selector combobox next to it to be unreachable when
+        * navigating widgets in GtkTable with up/down arrow keys.
+        * Note: gtk_widget_set_can_focus() was not enough. */
+       GList *l = NULL;
+       l = g_list_prepend(l, from_name);
+       gtk_container_set_focus_chain(GTK_CONTAINER(hbox), l);
+       g_list_free(l);
        
        CLAWS_SET_TIP(optmenubox,
                _("Account to use for this email"));
@@ -8138,6 +8301,8 @@ static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
        systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
        g_free(compose->privacy_system);
        compose->privacy_system = NULL;
+       g_free(compose->encdata);
+       compose->encdata = NULL;
        if (systemid != NULL) {
                compose->privacy_system = g_strdup(systemid);
 
@@ -8231,6 +8396,7 @@ static void compose_set_out_encoding(Compose *compose)
                case C_WINDOWS_1256: branch = "Menu/Options/Encoding/Arabic/" CS_WINDOWS_1256; break;
                case C_ISO_8859_5: branch = "Menu/Options/Encoding/Cyrillic/" CS_ISO_8859_5; break;
                case C_KOI8_R: branch = "Menu/Options/Encoding/Cyrillic/" CS_KOI8_R; break;
+               case C_MACCYR: branch = "Menu/Options/Encoding/Cyrillic/" CS_MACCYR; break;
                case C_KOI8_U: branch = "Menu/Options/Encoding/Cyrillic/" CS_KOI8_U; break;
                case C_WINDOWS_1251: branch = "Menu/Options/Encoding/Cyrillic/" CS_WINDOWS_1251; break;
                case C_ISO_2022_JP: branch = "Menu/Options/Encoding/Japanese/" CS_ISO_2022_JP; break;
@@ -8445,7 +8611,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
 
                        parsed_str = compose_quote_fmt(compose, dummyinfo,
                                                           tmpl->value, qmark, tmp, FALSE, FALSE, err_msg);
-                       procmsg_msginfo_free( dummyinfo );
+                       procmsg_msginfo_free( &dummyinfo );
 
                        g_free( tmp );
                } 
@@ -8574,6 +8740,24 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                }
        }
 
+       if (tmpl->replyto && *tmpl->replyto != '\0') {
+#ifdef USE_ENCHANT
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
+                               compose->gtkaspell);
+#else
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+               quote_fmt_scan_string(tmpl->replyto);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL) {
+                       alertpanel_error(_("Template Reply-To format error."));
+               } else {
+                       compose_entry_append(compose, buf, COMPOSE_REPLYTO, PREF_TEMPLATE);
+               }
+       }
+
        /* process the subject */
        if (tmpl->subject && *tmpl->subject != '\0') {
 #ifdef USE_ENCHANT
@@ -8593,7 +8777,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                }
        }
 
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 }
 
 static void compose_destroy(Compose *compose)
@@ -8609,6 +8793,7 @@ static void compose_destroy(Compose *compose)
                compose->deferred_destroy = TRUE;
                return;
        }
+
        /* NOTE: address_completion_end() does nothing with the window
         * however this may change. */
        address_completion_end(compose->window);
@@ -8624,9 +8809,12 @@ static void compose_destroy(Compose *compose)
 
        g_hash_table_destroy(compose->email_hashtable);
 
-       procmsg_msginfo_free(compose->targetinfo);
-       procmsg_msginfo_free(compose->replyinfo);
-       procmsg_msginfo_free(compose->fwdinfo);
+       hooks_unregister_hook(FOLDER_UPDATE_HOOKLIST,
+                       compose->folder_update_callback_id);
+
+       procmsg_msginfo_free(&(compose->targetinfo));
+       procmsg_msginfo_free(&(compose->replyinfo));
+       procmsg_msginfo_free(&(compose->fwdinfo));
 
        g_free(compose->replyto);
        g_free(compose->cc);
@@ -8652,8 +8840,9 @@ static void compose_destroy(Compose *compose)
        g_free(compose->orig_charset);
 
        g_free(compose->privacy_system);
+       g_free(compose->encdata);
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        if (addressbook_get_target_compose() == compose)
                addressbook_set_target_compose(NULL);
 #endif
@@ -8839,7 +9028,7 @@ static void compose_attach_property(GtkAction *action, gpointer data)
                gtk_widget_hide(attach_prop.window);
                gtk_window_set_modal(GTK_WINDOW(attach_prop.window), FALSE);
                
-               if (cancelled) 
+               if (cancelled)
                        break;
 
                entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
@@ -9088,12 +9277,37 @@ static void compose_exec_ext_editor(Compose *compose)
 {
 #ifdef G_OS_UNIX
        gchar *tmp;
+       GtkWidget *socket;
+       GdkNativeWindow socket_wid = 0;
        pid_t pid;
        gint pipe_fds[2];
 
        tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
                              G_DIR_SEPARATOR, compose);
 
+       if (compose_get_ext_editor_uses_socket()) {
+               /* Only allow one socket */
+               if (compose->exteditor_socket != NULL) {
+                       if (gtk_widget_is_focus(compose->exteditor_socket)) {
+                               /* Move the focus off of the socket */
+                               gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
+                       }
+                       g_free(tmp);
+                       return;
+               }
+               /* Create the receiving GtkSocket */
+               socket = gtk_socket_new ();
+               g_signal_connect (GTK_OBJECT(socket), "plug-removed",
+                                 G_CALLBACK(compose_ext_editor_plug_removed_cb),
+                                 compose);
+               gtk_box_pack_start(GTK_BOX(compose->edit_vbox), socket, TRUE, TRUE, 0);
+               gtk_widget_set_size_request(socket, prefs_common.compose_width, -1);
+               /* Realize the socket so that we can use its ID */
+               gtk_widget_realize(socket);
+               socket_wid = gtk_socket_get_id(GTK_SOCKET (socket));
+               compose->exteditor_socket = socket;
+       }
+
        if (pipe(pipe_fds) < 0) {
                perror("pipe");
                g_free(tmp);
@@ -9138,7 +9352,7 @@ static void compose_exec_ext_editor(Compose *compose)
                        _exit(1);
                }
 
-               pid_ed = compose_exec_ext_editor_real(tmp);
+               pid_ed = compose_exec_ext_editor_real(tmp, socket_wid);
                if (pid_ed < 0) {
                        fd_write_all(pipe_fds[1], "1\n", 2);
                        _exit(1);
@@ -9158,10 +9372,34 @@ static void compose_exec_ext_editor(Compose *compose)
 }
 
 #ifdef G_OS_UNIX
-static gint compose_exec_ext_editor_real(const gchar *file)
+static gboolean compose_get_ext_editor_cmd_valid()
+{
+       gboolean has_s = FALSE;
+       gboolean has_w = FALSE;
+       const gchar *p = prefs_common_get_ext_editor_cmd();
+       if (!p)
+               return FALSE;
+       while ((p = strchr(p, '%'))) {
+               p++;
+               if (*p == 's') {
+                       if (has_s)
+                               return FALSE;
+                       has_s = TRUE;
+               } else if (*p == 'w') {
+                       if (has_w)
+                               return FALSE;
+                       has_w = TRUE;
+               } else {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+static gint compose_exec_ext_editor_real(const gchar *file, GdkNativeWindow socket_wid)
 {
        gchar buf[1024];
-       gchar *p;
+       gchar *p, *s;
        gchar **cmdline;
        pid_t pid;
 
@@ -9179,13 +9417,23 @@ static gint compose_exec_ext_editor_real(const gchar *file)
        if (setpgid(0, getppid()))
                perror("setpgid");
 
-       if (prefs_common_get_ext_editor_cmd() &&
-           (p = strchr(prefs_common_get_ext_editor_cmd(), '%')) &&
-           *(p + 1) == 's' && !strchr(p + 2, '%')) {
-               g_snprintf(buf, sizeof(buf), prefs_common_get_ext_editor_cmd(), file);
+       if (compose_get_ext_editor_cmd_valid()) {
+               if (compose_get_ext_editor_uses_socket()) {
+                       p = g_strdup(prefs_common_get_ext_editor_cmd());
+                       s = strstr(p, "%w");
+                       s[1] = 'u';
+                       if (strstr(p, "%s") < s)
+                               g_snprintf(buf, sizeof(buf), p, file, socket_wid);
+                       else
+                               g_snprintf(buf, sizeof(buf), p, socket_wid, file);
+                       g_free(p);
+               } else {
+                       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'",
                                  prefs_common_get_ext_editor_cmd());
                g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
        }
@@ -9228,9 +9476,8 @@ static gboolean compose_ext_editor_kill(Compose *compose)
                        if (kill(pgid, SIGTERM) < 0) perror("kill");
                        waitpid(compose->exteditor_pid, NULL, 0);
 
-                       g_warning("Terminated process group id: %d", -pgid);
-                       g_warning("Temporary file: %s",
-                                 compose->exteditor_file);
+                       g_warning("Terminated process group id: %d. "
+                                 "Temporary file: %s", -pgid, compose->exteditor_file);
 
                        compose_set_ext_editor_sensitive(compose, TRUE);
 
@@ -9246,6 +9493,14 @@ static gboolean compose_ext_editor_kill(Compose *compose)
        return TRUE;
 }
 
+static gboolean compose_can_autosave(Compose *compose)
+{
+       if (compose->privacy_system && compose->use_encryption)
+               return prefs_common.autosave && prefs_common.autosave_encrypted;
+       else
+               return prefs_common.autosave;
+}
+
 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
                                 gpointer data)
 {
@@ -9255,7 +9510,10 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
 
        debug_print("Compose: input from monitoring process\n");
 
-       g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
+       if (g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL) != G_IO_STATUS_NORMAL) {
+               bytes_read = 0;
+               buf[0] = '\0';
+       }
 
        g_io_channel_shutdown(source, FALSE, NULL);
        g_io_channel_unref(source);
@@ -9265,22 +9523,35 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
        if (buf[0] == '0') {            /* success */
                GtkTextView *text = GTK_TEXT_VIEW(compose->text);
                GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
+               GtkTextIter start, end;
+               gchar *chars;
 
                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);
+
+               /* Check if we should save the draft or not */
+               if (compose_can_autosave(compose))
+                 compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
 
                if (claws_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
+
+               buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
+               gtk_text_buffer_get_start_iter(buffer, &start);
+               gtk_text_buffer_get_end_iter(buffer, &end);
+               chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+               if (chars && strlen(chars) > 0)
+                       compose->modified = TRUE;
+               g_free(chars);
        } else if (buf[0] == '1') {     /* failed */
-               g_warning("Couldn't exec external editor\n");
+               g_warning("Couldn't exec external editor");
                if (claws_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '2') {
-               g_warning("Couldn't write to file\n");
+               g_warning("Couldn't write to file");
        } else if (buf[0] == '3') {
-               g_warning("Pipe read failed\n");
+               g_warning("Pipe read failed");
        }
 
        compose_set_ext_editor_sensitive(compose, TRUE);
@@ -9290,23 +9561,66 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
        compose->exteditor_pid     = -1;
        compose->exteditor_ch      = NULL;
        compose->exteditor_tag     = -1;
+       if (compose->exteditor_socket) {
+               gtk_widget_destroy(compose->exteditor_socket);
+               compose->exteditor_socket = NULL;
+       }
+
 
        return FALSE;
 }
 
+static char *ext_editor_menu_entries[] = {
+       "Menu/Message/Send",
+       "Menu/Message/SendLater",
+       "Menu/Message/InsertFile",
+       "Menu/Message/InsertSig",
+       "Menu/Message/ReplaceSig",
+       "Menu/Message/Save",
+       "Menu/Message/Print",
+       "Menu/Edit",
+#if USE_ENCHANT
+       "Menu/Spelling",
+#endif
+       "Menu/Tools/ShowRuler",
+       "Menu/Tools/Actions",
+       "Menu/Help",
+       NULL
+};
+
 static void compose_set_ext_editor_sensitive(Compose *compose,
                                             gboolean sensitive)
 {
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/Send", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/SendLater", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertFile", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertSig", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/ReplaceSig", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/WrapPara", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/WrapAllLines", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/ExtEditor", sensitive);
+       int i;
 
-       gtk_widget_set_sensitive(compose->text,                       sensitive);
+       for (i = 0; ext_editor_menu_entries[i]; ++i) {
+               cm_menu_set_sensitive_full(compose->ui_manager,
+                       ext_editor_menu_entries[i], sensitive);
+       }
+
+       if (compose_get_ext_editor_uses_socket()) {
+               if (sensitive) {
+                       if (compose->exteditor_socket)
+                               gtk_widget_hide(compose->exteditor_socket);
+                       gtk_widget_show(compose->scrolledwin);
+                       if (prefs_common.show_ruler)
+                               gtk_widget_show(compose->ruler_hbox);
+                       /* Fix the focus, as it doesn't go anywhere when the
+                        * socket is hidden or destroyed */
+                       gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
+               } else {
+                       g_assert (compose->exteditor_socket != NULL);
+                       /* Fix the focus, as it doesn't go anywhere when the
+                        * edit box is hidden */
+                       if (gtk_widget_is_focus(compose->text))
+                               gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
+                       gtk_widget_hide(compose->scrolledwin);
+                       gtk_widget_hide(compose->ruler_hbox);
+                       gtk_widget_show(compose->exteditor_socket);
+               }
+       } else {
+               gtk_widget_set_sensitive(compose->text,                   sensitive);
+       }
        if (compose->toolbar->send_btn)
                gtk_widget_set_sensitive(compose->toolbar->send_btn,      sensitive);
        if (compose->toolbar->sendl_btn)
@@ -9324,6 +9638,19 @@ static void compose_set_ext_editor_sensitive(Compose *compose,
        if (compose->toolbar->linewrap_all_btn)
                gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
 }
+
+static gboolean compose_get_ext_editor_uses_socket()
+{
+       return (prefs_common_get_ext_editor_cmd() &&
+               strstr(prefs_common_get_ext_editor_cmd(), "%w"));
+}
+
+static gboolean compose_ext_editor_plug_removed_cb(GtkSocket *socket, Compose *compose)
+{
+       compose->exteditor_socket = NULL;
+       /* returning FALSE allows destruction of the socket */
+       return FALSE;
+}
 #endif /* G_OS_UNIX */
 
 /**
@@ -9387,9 +9714,9 @@ static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
 
 static void compose_notebook_size_alloc(GtkNotebook *notebook,
                                        GtkAllocation *allocation,
-                                       Compose *compose)
+                                       GtkPaned *paned)
 {
-       prefs_common.compose_notebook_height = allocation->height;
+       prefs_common.compose_notebook_height = gtk_paned_get_position(paned);
 }
 
 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
@@ -9435,17 +9762,10 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
        GtkTreeIter iter;
        GSList *list, *saved_list = NULL;
        HeaderEntryState *state;
-       GtkRcStyle *style = NULL;
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow;
-       static gboolean color_set = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint32)0xf5, (guint32)0xf6, (guint32)0xbe };
-#endif
 
        /* Get ID of active account in the combo box */
        menu = gtk_combo_box_get_model(optmenu);
-       gtk_combo_box_get_active_iter(optmenu, &iter);
+       cm_return_if_fail(gtk_combo_box_get_active_iter(optmenu, &iter));
        gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
 
        ac = account_find_from_id(account_id);
@@ -9461,26 +9781,12 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                                compose_destroy_headerentry(compose, hentry);
                                continue;
                        }
-                       
                        state = g_malloc0(sizeof(HeaderEntryState));
                        state->header = gtk_editable_get_chars(GTK_EDITABLE(
                                        gtk_bin_get_child(GTK_BIN(hentry->combo))), 0, -1);
                        state->entry = gtk_editable_get_chars(
                                        GTK_EDITABLE(hentry->entry), 0, -1);
                        state->type = hentry->type;
-                               
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       if (!color_set) {
-                               gdk_color_parse("#f5f6be", &yellow);
-                               color_set = gdk_colormap_alloc_color(
-                                                       gdk_colormap_get_system(),
-                                                       &yellow, FALSE, TRUE);
-                       }
-#endif
-                               
-                       style = gtk_widget_get_modifier_style(hentry->entry);
-                       state->entry_marked = gdk_color_equal(&yellow,
-                                               &style->base[GTK_STATE_NORMAL]);
 
                        saved_list = g_slist_append(saved_list, state);
                        compose_destroy_headerentry(compose, hentry);
@@ -9495,29 +9801,25 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                if (ac->set_autocc && ac->auto_cc)
                        compose_entry_append(compose, ac->auto_cc,
                                                COMPOSE_CC, PREF_ACCOUNT);
-
-               if (ac->set_autobcc && ac->auto_bcc) 
+               if (ac->set_autobcc && ac->auto_bcc)
                        compose_entry_append(compose, ac->auto_bcc,
                                                COMPOSE_BCC, PREF_ACCOUNT);
-       
                if (ac->set_autoreplyto && ac->auto_replyto)
                        compose_entry_append(compose, ac->auto_replyto,
                                                COMPOSE_REPLYTO, PREF_ACCOUNT);
                
                for (list = saved_list; list; list = list->next) {
                        state = (HeaderEntryState *) list->data;
-                       
+
                        compose_add_header_entry(compose, state->header,
                                                state->entry, state->type);
-                       if (state->entry_marked)
-                               compose_entry_mark_default_to(compose, state->entry);
-                       
-                       g_free(state->header);  
+
+                       g_free(state->header);
                        g_free(state->entry);
                        g_free(state);
                }
                g_slist_free(saved_list);
-               
+
                combobox_select_by_data(GTK_COMBO_BOX(compose->header_last->combo),
                                        (ac->protocol == A_NNTP) ? 
                                        COMPOSE_NEWSGROUPS : COMPOSE_TO);
@@ -9551,15 +9853,35 @@ static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
        Compose *compose = (Compose *)data;
        GtkTreeSelection *attach_selection;
        gint attach_nr_selected;
+       GtkTreePath *path;
        
        if (!event) return FALSE;
 
        if (event->button == 3) {
                attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
                attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
-                       
+
+               /* If no rows, or just one row is selected, right-click should
+                * open menu relevant to the row being right-clicked on. We
+                * achieve that by selecting the clicked row first. If more
+                * than one row is selected, we shouldn't modify the selection,
+                * as user may want to remove selected rows (attachments). */
+               if (attach_nr_selected < 2) {
+                       gtk_tree_selection_unselect_all(attach_selection);
+                       attach_nr_selected = 0;
+                       gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget),
+                                       event->x, event->y, &path, NULL, NULL, NULL);
+                       if (path != NULL) {
+                               gtk_tree_selection_select_path(attach_selection, path);
+                               gtk_tree_path_free(path);
+                               attach_nr_selected++;
+                       }
+               }
+
                cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Remove", (attach_nr_selected > 0));
-               cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Properties", (attach_nr_selected > 0));
+               /* Properties menu item makes no sense with more than one row
+                * selected, the properties dialog can only edit one attachment. */
+               cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Properties", (attach_nr_selected == 1));
                        
                gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
                               NULL, NULL, event->button, event->time);
@@ -9604,6 +9926,12 @@ static void compose_send_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
+#ifdef G_OS_UNIX
+       if (compose->exteditor_tag != -1) {
+               debug_print("ignoring send: external editor still open\n");
+               return;
+       }
+#endif
        if (prefs_common.work_offline && 
            !inc_offline_should_override(TRUE,
                _("Claws Mail needs network access in order "
@@ -9612,7 +9940,7 @@ static void compose_send_cb(GtkAction *action, gpointer data)
        
        if (compose->draft_timeout_tag >= 0) { /* CLAWS: disable draft timeout */
                g_source_remove(compose->draft_timeout_tag);
-               compose->draft_timeout_tag = -1;
+               compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET;
        }
 
        compose_send(compose);
@@ -9634,7 +9962,7 @@ static void compose_send_later_cb(GtkAction *action, gpointer data)
        } else if (val == -1) {
                alertpanel_error(_("Could not queue message."));
        } else if (val == -2) {
-               alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
+               alertpanel_error(_("Could not queue message:\n\n%s."), g_strerror(errno));
        } else if (val == -3) {
                if (privacy_peek_error())
                alertpanel_error(_("Could not queue message for sending:\n\n"
@@ -9697,7 +10025,7 @@ gboolean compose_draft (gpointer data, guint action)
                debug_print("couldn't lock mutex, probably sending\n");
                return FALSE;
        }
-       
+
        lock = TRUE;
 
        tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
@@ -9710,7 +10038,7 @@ gboolean compose_draft (gpointer data, guint action)
        /* chmod for security */
        if (change_file_mode_rw(fp, tmp) < 0) {
                FILE_OP_ERROR(tmp, "chmod");
-               g_warning("can't change file mode\n");
+               g_warning("can't change file mode");
        }
 
        /* Save draft infos */
@@ -9735,17 +10063,25 @@ gboolean compose_draft (gpointer data, guint action)
 
        /* Message-ID of message replying to */
        if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
-               gchar *folderid;
-               
-               folderid = folder_item_get_identifier(compose->replyinfo->folder);
+               gchar *folderid = NULL;
+
+               if (compose->replyinfo->folder)
+                       folderid = folder_item_get_identifier(compose->replyinfo->folder);
+               if (folderid == NULL)
+                       folderid = g_strdup("NULL");
+
                err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
                g_free(folderid);
        }
        /* Message-ID of message forwarding to */
        if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
-               gchar *folderid;
-               
-               folderid = folder_item_get_identifier(compose->fwdinfo->folder);
+               gchar *folderid = NULL;
+
+               if (compose->fwdinfo->folder)
+                       folderid = folder_item_get_identifier(compose->fwdinfo->folder);
+               if (folderid == NULL)
+                       folderid = g_strdup("NULL");
+
                err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
                g_free(folderid);
        }
@@ -9773,9 +10109,11 @@ gboolean compose_draft (gpointer data, guint action)
                goto warn_err;
        }
        
+       flag.perm_flags = MSG_NEW|MSG_UNREAD;
        if (compose->targetinfo) {
                target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
-               flag.perm_flags = target_locked?MSG_LOCKED:0;
+               if (target_locked) 
+                       flag.perm_flags |= MSG_LOCKED;
        }
        flag.tmp_flags = MSG_DRAFT;
 
@@ -9788,7 +10126,7 @@ gboolean compose_draft (gpointer data, guint action)
                }
                if (tmpinfo) {
                        msgnum = tmpinfo->msgnum;
-                       procmsg_msginfo_free(tmpinfo);
+                       procmsg_msginfo_free(&tmpinfo);
                        debug_print("got draft msgnum %d from scanning\n", msgnum);
                } else {
                        debug_print("didn't get draft msgnum after scanning\n");
@@ -9836,9 +10174,9 @@ warn_err:
        if (newmsginfo) {
                procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
                if (target_locked)
-                       procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
+                       procmsg_msginfo_set_flags(newmsginfo, MSG_NEW|MSG_UNREAD|MSG_LOCKED, MSG_DRAFT);
                else
-                       procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
+                       procmsg_msginfo_set_flags(newmsginfo, MSG_NEW|MSG_UNREAD, MSG_DRAFT);
                if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
                        procmsg_msginfo_set_flags(newmsginfo, 0,
                                                  MSG_HAS_ATTACHMENT);
@@ -9846,7 +10184,7 @@ warn_err:
                if (action == COMPOSE_DRAFT_FOR_EXIT) {
                        compose_register_draft(newmsginfo);
                }
-               procmsg_msginfo_free(newmsginfo);
+               procmsg_msginfo_free(&newmsginfo);
        }
        
        folder_item_scan(draft);
@@ -9857,7 +10195,7 @@ warn_err:
                compose_close(compose);
                return TRUE;
        } else {
-               struct stat s;
+               GStatBuf s;
                gchar *path;
 
                path = folder_item_fetch_msg(draft, msgnum);
@@ -9872,7 +10210,7 @@ warn_err:
                }
                g_free(path);
 
-               procmsg_msginfo_free(compose->targetinfo);
+               procmsg_msginfo_free(&(compose->targetinfo));
                compose->targetinfo = procmsg_msginfo_new();
                compose->targetinfo->msgnum = msgnum;
                compose->targetinfo->size = (goffset)s.st_size;
@@ -9969,7 +10307,7 @@ static void compose_attach_cb(GtkAction *action, gpointer data)
         * which unsets it (via focus_out_event callback on compose window). */
        manage_window_focus_in(compose->window, NULL, NULL);
 
-       file_list = filesel_select_multiple_files_open(_("Select file"));
+       file_list = filesel_select_multiple_files_open(_("Select file"), NULL);
 
        if (file_list) {
                compose_attach_from_list(compose, file_list, TRUE);
@@ -9983,7 +10321,7 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data)
        GList *file_list;
        gint files_inserted = 0;
 
-       file_list = filesel_select_multiple_files_open(_("Select file"));
+       file_list = filesel_select_multiple_files_open(_("Select file"), NULL);
 
        if (file_list) {
                GList *tmp;
@@ -10084,13 +10422,14 @@ static void compose_close_cb(GtkAction *action, gpointer data)
                } else {
                        val = alertpanel(_("Save changes"),
                                 _("This message has been modified. Save the latest changes?"),
-                                _("_Don't save"), _("+_Save to Drafts"), GTK_STOCK_CANCEL);
+                                _("_Don't save"), g_strconcat("+", _("_Save to Drafts"), NULL),
+                               GTK_STOCK_CANCEL);
                }
                g_mutex_unlock(compose->mutex);
                switch (val) {
                case G_ALERTDEFAULT:
-                       if (prefs_common.autosave && !reedit)
-                               compose_remove_draft(compose);                  
+                       if (compose_can_autosave(compose) && !reedit)
+                               compose_remove_draft(compose);
                        break;
                case G_ALERTALTERNATE:
                        compose_draft(data, COMPOSE_QUIT_EDITING);
@@ -10126,7 +10465,7 @@ static void compose_address_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_open(compose);
 #else
        GError* error = NULL;
@@ -10170,6 +10509,12 @@ static void compose_ext_editor_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
+#ifdef G_OS_UNIX
+       if (compose->exteditor_tag != -1) {
+               debug_print("ignoring open external editor: external editor still open\n");
+               return;
+       }
+#endif
        compose_exec_ext_editor(compose);
 }
 
@@ -10877,6 +11222,7 @@ static void compose_toggle_encrypt_cb(GtkToggleAction *action, gpointer data)
 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn) 
 {
        g_free(compose->privacy_system);
+       g_free(compose->encdata);
 
        compose->privacy_system = g_strdup(account->default_privacy_system);
        compose_update_privacy_system_menu_item(compose, warn);
@@ -10910,11 +11256,8 @@ static void compose_attach_drag_received_cb (GtkWidget         *widget,
        GdkAtom type;
 
        type = gtk_selection_data_get_data_type(data);
-       if (((gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "text/uri-list"))
-#ifdef G_OS_WIN32
-        || (gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "DROPFILES_DND"))
-#endif
-          ) && gtk_drag_get_source_widget(context) != 
+       if ((gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "text/uri-list"))
+          && gtk_drag_get_source_widget(context) !=
                summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
                list = uri_list_extract_filenames(
                        (const gchar *)gtk_selection_data_get_data(data));
@@ -10993,19 +11336,18 @@ static void compose_insert_drag_received_cb (GtkWidget                *widget,
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
        GdkAtom type;
+       guint num_files;
+       gchar *msg;
 
        /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
         * does not work */
        type = gtk_selection_data_get_data_type(data);
-#ifndef G_OS_WIN32
        if (gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "text/uri-list")) {
-#else
-       if (gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "DROPFILES_DND")) {
-#endif
                AlertValue val = G_ALERTDEFAULT;
                const gchar* ddata = (const gchar *)gtk_selection_data_get_data(data);
 
                list = uri_list_extract_filenames(ddata);
+               num_files = g_list_length(list);
                if (list == NULL && strstr(ddata, "://")) {
                        /* Assume a list of no files, and data has ://, is a remote link */
                        gchar *tmpdata = g_strstrip(g_strdup(ddata));
@@ -11021,11 +11363,18 @@ static void compose_insert_drag_received_cb (GtkWidget                *widget,
                }
                switch (prefs_common.compose_dnd_mode) {
                        case COMPOSE_DND_ASK:
-                               val = alertpanel_full(_("Insert or attach?"),
-                                        _("Do you want to insert the contents of the file(s) "
-                                          "into the message body, or attach it to the email?"),
-                                         GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
+                               msg = g_strdup_printf(
+                                               ngettext(
+                                                       "Do you want to insert the contents of the file "
+                                                       "into the message body, or attach it to the email?",
+                                                       "Do you want to insert the contents of the %d files "
+                                                       "into the message body, or attach them to the email?",
+                                                       num_files),
+                                               num_files);
+                               val = alertpanel_full(_("Insert or attach?"), msg,
+                                         GTK_STOCK_CANCEL, g_strconcat("+", _("_Insert"), NULL), _("_Attach"),
                                          TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
+                               g_free(msg);
                                break;
                        case COMPOSE_DND_INSERT:
                                val = G_ALERTALTERNATE;
@@ -11066,10 +11415,7 @@ static void compose_insert_drag_received_cb (GtkWidget         *widget,
                g_list_free(list);
                gtk_drag_finish(drag_context, TRUE, FALSE, time);
                return;
-       } else {
-               return;
        }
-       gtk_drag_finish(drag_context, TRUE, FALSE, time);
 }
 
 static void compose_header_drag_received_cb (GtkWidget         *widget,
@@ -11164,7 +11510,8 @@ static gboolean scroll_postpone(gpointer data)
 {
        Compose *compose = (Compose *)data;
 
-       cm_return_val_if_fail(!compose->batch, FALSE);
+       if (compose->batch)
+               return FALSE;
 
        GTK_EVENTS_FLUSH();
        compose_show_first_last_header(compose, FALSE);
@@ -11187,7 +11534,7 @@ static void compose_headerentry_changed_cb(GtkWidget *entry,
 
 static gboolean compose_defer_auto_save_draft(Compose *compose)
 {
-       compose->draft_timeout_tag = -1;
+       compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET;
        compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
        return FALSE;
 }
@@ -11197,7 +11544,10 @@ static void compose_show_first_last_header(Compose *compose, gboolean show_first
        GtkAdjustment *vadj;
 
        cm_return_if_fail(compose);
-       cm_return_if_fail(!compose->batch);
+
+       if(compose->batch)
+               return;
+
        cm_return_if_fail(GTK_IS_WIDGET(compose->header_table));
        cm_return_if_fail(GTK_IS_VIEWPORT(gtk_widget_get_parent(compose->header_table)));
        vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(
@@ -11306,9 +11656,9 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                                          compose);
        g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
 
-       if (prefs_common.autosave && 
+       if (compose_can_autosave(compose) && 
            gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0 &&
-           compose->draft_timeout_tag != -2 /* disabled while loading */)
+           compose->draft_timeout_tag != COMPOSE_DRAFT_TIMEOUT_FORBIDDEN /* disabled while loading */)
                compose->draft_timeout_tag = g_timeout_add
                        (500, (GSourceFunc) compose_defer_auto_save_draft, compose);
 }
@@ -11372,7 +11722,7 @@ static void compose_check_forwards_go(GtkAction *action, gpointer data)
  *\brief       Guess originating forward account from MsgInfo and several 
  *             "common preference" settings. Return NULL if no guess. 
  */
-static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
+static PrefsAccount *compose_find_account(MsgInfo *msginfo)
 {
        PrefsAccount *account = NULL;
        
@@ -11383,9 +11733,6 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
        if (msginfo->folder->prefs->enable_default_account)
                account = account_find_from_id(msginfo->folder->prefs->default_account);
                
-       if (!account) 
-               account = msginfo->folder->folder->account;
-               
        if (!account && msginfo->to && prefs_common.forward_account_autosel) {
                gchar *to;
                Xstrdup_a(to, msginfo->to, return NULL);
@@ -11412,6 +11759,9 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
                        account = account_find_from_address(buf, FALSE);
                 }
        }
+
+       if (!account)
+               account = msginfo->folder->folder->account;
        
        return account;
 }
@@ -11420,16 +11770,27 @@ gboolean compose_close(Compose *compose)
 {
        gint x, y;
 
+       cm_return_val_if_fail(compose, FALSE);
+
        if (!g_mutex_trylock(compose->mutex)) {
                /* we have to wait for the (possibly deferred by auto-save)
                 * drafting to be done, before destroying the compose under
                 * it. */
                debug_print("waiting for drafting to finish...\n");
                compose_allow_user_actions(compose, FALSE);
-               g_timeout_add (500, (GSourceFunc) compose_close, compose);
-               return FALSE;
+               if (compose->close_timeout_tag == 0) {
+                       compose->close_timeout_tag = 
+                               g_timeout_add (500, (GSourceFunc) compose_close,
+                               compose);
+               }
+               return TRUE;
        }
-       cm_return_val_if_fail(compose, FALSE);
+
+       if (compose->draft_timeout_tag >= 0) {
+               g_source_remove(compose->draft_timeout_tag);
+               compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN;
+       }
+
        gtkut_widget_get_uposition(compose->window, &x, &y);
        if (!compose->batch) {
                prefs_common.compose_x = x;
@@ -11501,7 +11862,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
 
        if (new_msglist) {
                compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
-               procmsg_msginfo_free(tmp_msginfo);
+               procmsg_msginfo_free(&tmp_msginfo);
                g_slist_free(new_msglist);
        } else
                compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
@@ -11724,6 +12085,12 @@ static void compose_subject_entry_activated(GtkWidget *widget, gpointer data)
        gtk_widget_grab_focus(compose->text);
 }
 
+static void from_name_activate_cb(GtkWidget *widget, gpointer data)
+{
+       gtk_combo_box_popup(GTK_COMBO_BOX(data));
+}
+
+
 /*
  * End of Source.
  */