fix detection of account in --compose and --compose-from-file where the From value...
[claws.git] / src / compose.c
index 56b990d1973ee1b5ed38c79d9884bf40a0d3c743..c88d9b2809bd8de4b8a550c1858ba7b284cee076 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2012 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
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
 #include "main.h"
 #include "mainwindow.h"
 #include "compose.h"
-#include "addressbook.h"
+#ifndef USE_NEW_ADDRBOOK
+       #include "addressbook.h"
+#else
+       #include "addressbook-dbus.h"
+       #include "addressadd.h"
+#endif
 #include "folderview.h"
 #include "procmsg.h"
 #include "menu.h"
 #include "codeconv.h"
 #include "utils.h"
 #include "gtkutils.h"
+#include "gtkshruler.h"
 #include "socket.h"
 #include "alertpanel.h"
 #include "manage_window.h"
-#include "gtkshruler.h"
 #include "folder.h"
+#include "folder_item_prefs.h"
 #include "addr_compl.h"
 #include "quote_fmt.h"
 #include "undo.h"
@@ -107,8 +114,9 @@ enum
        COL_MIMETYPE = 0,
        COL_SIZE     = 1,
        COL_NAME     = 2,
-       COL_DATA     = 3,
-       COL_AUTODATA = 4,
+       COL_CHARSET  = 3,
+       COL_DATA     = 4,
+       COL_AUTODATA = 5,
        N_COL_COLUMNS
 };
 
@@ -175,11 +183,12 @@ typedef enum {
 #define MAX_REFERENCES_LEN     999
 
 static GList *compose_list = NULL;
+static GSList *extra_headers = NULL;
 
 static Compose *compose_generic_new                    (PrefsAccount   *account,
                                                 const gchar    *to,
                                                 FolderItem     *item,
-                                                GPtrArray      *attach_files,
+                                                GList          *attach_files,
                                                 GList          *listAddress );
 
 static Compose *compose_create                 (PrefsAccount   *account,
@@ -219,6 +228,9 @@ static MailField compose_entries_set                (Compose        *compose,
                                                 ComposeEntryType to_type);
 static gint compose_parse_header               (Compose        *compose,
                                                 MsgInfo        *msginfo);
+static gint compose_parse_manual_headers       (Compose        *compose,
+                                                MsgInfo        *msginfo,
+                                                HeaderEntry    *entries);
 static gchar *compose_parse_references         (const gchar    *ref,
                                                 const gchar    *msgid);
 
@@ -249,7 +261,8 @@ static ComposeInsertResult compose_insert_file      (Compose        *compose,
 static gboolean compose_attach_append          (Compose        *compose,
                                                 const gchar    *file,
                                                 const gchar    *type,
-                                                const gchar    *content_type);
+                                                const gchar    *content_type,
+                                                const gchar    *charset);
 static void compose_attach_parts               (Compose        *compose,
                                                 MsgInfo        *msginfo);
 
@@ -289,6 +302,7 @@ static gint compose_queue_sub                       (Compose        *compose,
 static int compose_add_attachments             (Compose        *compose,
                                                 MimeInfo       *parent);
 static gchar *compose_get_header               (Compose        *compose);
+static gchar *compose_get_manual_headers_info  (Compose        *compose);
 
 static void compose_convert_header             (Compose        *compose,
                                                 gchar          *dest,
@@ -349,6 +363,9 @@ static void compose_add_field_list  ( Compose *compose,
 
 /* callback functions */
 
+static void compose_notebook_size_alloc (GtkNotebook *notebook,
+                                        GtkAllocation *allocation,
+                                        Compose *compose);
 static gboolean compose_edit_size_alloc (GtkEditable   *widget,
                                         GtkAllocation  *allocation,
                                         GtkSHRuler     *shruler);
@@ -379,6 +396,8 @@ static void compose_insert_sig_cb   (GtkAction      *action,
 
 static void compose_close_cb           (GtkAction      *action,
                                         gpointer        data);
+static void compose_print_cb           (GtkAction      *action,
+                                        gpointer        data);
 
 static void compose_set_encoding_cb    (GtkAction      *action, GtkRadioAction *current, gpointer data);
 
@@ -485,6 +504,10 @@ static gboolean compose_drag_drop      (GtkWidget *widget,
                                             GdkDragContext *drag_context,
                                             gint x, gint y,
                                             guint time, gpointer user_data);
+static gboolean completion_set_focus_to_subject
+                                       (GtkWidget    *widget,
+                                        GdkEventKey  *event,
+                                        Compose      *user_data);
 
 static void text_inserted              (GtkTextBuffer  *buffer,
                                         GtkTextIter    *iter,
@@ -499,7 +522,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                                  gboolean followup_and_reply_to,
                                  const gchar *body);
 
-static gboolean compose_headerentry_changed_cb    (GtkWidget          *entry,
+static void compose_headerentry_changed_cb        (GtkWidget          *entry,
                                            ComposeHeaderEntry *headerentry);
 static gboolean compose_headerentry_key_press_event_cb(GtkWidget              *entry,
                                            GdkEventKey        *event,
@@ -523,7 +546,6 @@ static void compose_check_backwards    (GtkAction *action, gpointer data);
 static void compose_check_forwards_go     (GtkAction *action, gpointer data);
 #endif
 
-static gint compose_defer_auto_save_draft      (Compose        *compose);
 static PrefsAccount *compose_guess_forward_account_from_msginfo        (MsgInfo *msginfo);
 
 static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
@@ -533,6 +555,9 @@ static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
                                                FolderItem *folder_item);
 #endif
 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 GtkActionEntry compose_popup_entries[] =
 {
@@ -566,6 +591,8 @@ static GtkActionEntry compose_entries[] =
        /* {"Message/---",              NULL, "---" }, */
        {"Message/Save",                NULL, N_("_Save"), "<control>S", NULL, G_CALLBACK(compose_save_cb) }, /*COMPOSE_KEEP_EDITING*/
        /* {"Message/---",              NULL, "---" }, */
+       {"Message/Print",               NULL, N_("_Print"), NULL, NULL, G_CALLBACK(compose_print_cb) },
+       /* {"Message/---",              NULL, "---" }, */
        {"Message/Close",               NULL, N_("_Close"), "<control>W", NULL, G_CALLBACK(compose_close_cb) },
 
 /* Edit menu */
@@ -577,10 +604,10 @@ static GtkActionEntry compose_entries[] =
        {"Edit/Copy",                   NULL, N_("_Copy"), "<control>C", NULL, G_CALLBACK(compose_copy_cb) },
        {"Edit/Paste",                  NULL, N_("_Paste"), "<control>V", NULL, G_CALLBACK(compose_paste_cb) },
 
-       {"Edit/SpecialPaste",           NULL, N_("Special paste") },
-       {"Edit/SpecialPaste/AsQuotation",       NULL, N_("as _quotation"), NULL, NULL, G_CALLBACK(compose_paste_as_quote_cb) },
-       {"Edit/SpecialPaste/Wrapped",   NULL, N_("_wrapped"), NULL, NULL, G_CALLBACK(compose_paste_wrap_cb) },
-       {"Edit/SpecialPaste/Unwrapped", NULL, N_("_unwrapped"), NULL, NULL, G_CALLBACK(compose_paste_no_wrap_cb) },
+       {"Edit/SpecialPaste",           NULL, N_("_Special paste") },
+       {"Edit/SpecialPaste/AsQuotation",       NULL, N_("As _quotation"), NULL, NULL, G_CALLBACK(compose_paste_as_quote_cb) },
+       {"Edit/SpecialPaste/Wrapped",   NULL, N_("_Wrapped"), NULL, NULL, G_CALLBACK(compose_paste_wrap_cb) },
+       {"Edit/SpecialPaste/Unwrapped", NULL, N_("_Unwrapped"), NULL, NULL, G_CALLBACK(compose_paste_no_wrap_cb) },
 
        {"Edit/SelectAll",              NULL, N_("Select _all"), "<control>A", NULL, G_CALLBACK(compose_allsel_cb) },
 
@@ -710,6 +737,7 @@ static GtkRadioActionEntry compose_radio_enc_entries[] =
        ENC_ACTION("Japanese/"CS_ISO_2022_JP_2, C_ISO_2022_JP_2, "ISO-2022-JP-_2"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Japanese/"CS_EUC_JP, C_EUC_JP, "_EUC-JP"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Japanese/"CS_SHIFT_JIS, C_SHIFT_JIS, "_Shift-JIS"), /* RADIO compose_set_encoding_cb */
+       ENC_ACTION("Chinese/"CS_GB18030, C_GB18030, "_GB18030"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Chinese/"CS_GB2312, C_GB2312, "_GB2312"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Chinese/"CS_GBK, C_GBK, "GB_K"), /* RADIO compose_set_encoding_cb */
        ENC_ACTION("Chinese/"CS_BIG5, C_BIG5, "_Big5-JP"), /* RADIO compose_set_encoding_cb */
@@ -782,10 +810,12 @@ static void compose_create_tags(GtkTextView *text, Compose *compose)
 {
        GtkTextBuffer *buffer;
        GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
+#if !GTK_CHECK_VERSION(2, 24, 0)
        GdkColormap *cmap;
-       GdkColor color[8];
        gboolean success[8];
        int i;
+       GdkColor color[8];
+#endif
 
        buffer = gtk_text_view_get_buffer(text);
 
@@ -847,6 +877,7 @@ static void compose_create_tags(GtkTextView *text, Compose *compose)
        compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
        compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
 
+#if !GTK_CHECK_VERSION(2, 24, 0)
        color[0] = quote_color1;
        color[1] = quote_color2;
        color[2] = quote_color3;
@@ -855,24 +886,23 @@ static void compose_create_tags(GtkTextView *text, Compose *compose)
        color[5] = quote_bgcolor3;
        color[6] = signature_color;
        color[7] = uri_color;
-       cmap = gdk_drawable_get_colormap(compose->window->window);
+
+       cmap = gdk_drawable_get_colormap(gtk_widget_get_window(compose->window));
        gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
 
        for (i = 0; i < 8; i++) {
                if (success[i] == FALSE) {
-                       GtkStyle *style;
-
                        g_warning("Compose: color allocation failed.\n");
-                       style = gtk_widget_get_style(GTK_WIDGET(text));
                        quote_color1 = quote_color2 = quote_color3 = 
                                quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = 
                                signature_color = uri_color = black;
                }
        }
+#endif
 }
 
 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
-                    GPtrArray *attach_files)
+                    GList *attach_files)
 {
        return compose_generic_new(account, mailto, NULL, attach_files, NULL);
 }
@@ -932,7 +962,7 @@ static gchar *compose_get_save_to(Compose *compose)
 }
 
 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
-                            GPtrArray *attach_files, GList *listAddress )
+                            GList *attach_files, GList *listAddress )
 {
        Compose *compose;
        GtkTextView *textview;
@@ -943,18 +973,26 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        gchar *mailto_from = NULL;
        PrefsAccount *mailto_account = NULL;
        MsgInfo* dummyinfo = NULL;
+       gint cursor_pos = -1;
        MailField mfield = NO_FIELD_PRESENT;
        gchar* buf;
        GtkTextMark *mark;
 
        /* check if mailto defines a from */
        if (mailto && *mailto != '\0') {
-               scan_mailto_url(mailto, &mailto_from, NULL, NULL, NULL, NULL, NULL, NULL);
+               scan_mailto_url(mailto, &mailto_from, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
                /* mailto defines a from, check if we can get account prefs from it,
                   if not, the account prefs will be guessed using other ways, but we'll keep
                   the from anyway */
-               if (mailto_from)
+               if (mailto_from) {
                        mailto_account = account_find_from_address(mailto_from, TRUE);
+                       if (mailto_account == NULL) {
+                               gchar *tmp_from;
+                               Xstrdup_a(tmp_from, mailto_from, return NULL);
+                               extract_address(tmp_from);
+                               mailto_account = account_find_from_address(tmp_from, TRUE);
+                       }
+               }
                if (mailto_account)
                        account = mailto_account;
        }
@@ -986,7 +1024,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        dummyinfo = compose_msginfo_new_from_compose(compose);
 
                        /* decode \-escape sequences in the internal representation of the quote format */
-                       tmp = malloc(strlen(item->prefs->compose_override_from_format)+1);
+                       tmp = g_malloc(strlen(item->prefs->compose_override_from_format)+1);
                        pref_get_unescaped_pref(tmp, item->prefs->compose_override_from_format);
 
 #ifdef USE_ENCHANT
@@ -1029,24 +1067,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                if (mailto && *mailto != '\0') {
                        mfield = compose_entries_set(compose, mailto, COMPOSE_TO);
 
-               } else if (item && item->prefs) {
-                       if (item->prefs->enable_default_bcc) {
-                               compose_entry_append(compose, item->prefs->default_bcc,
-                                               COMPOSE_BCC, PREF_FOLDER);
-                       }
-                       if (item->prefs->enable_default_cc) {
-                               compose_entry_append(compose, item->prefs->default_cc,
-                                               COMPOSE_CC, PREF_FOLDER);
-                       }
-                       if (item->prefs->enable_default_replyto) {
-                               compose_entry_append(compose, item->prefs->default_replyto,
-                                               COMPOSE_REPLYTO, PREF_FOLDER);
-                       }
-                       if (item->prefs->enable_default_to) {
-                               compose_entry_append(compose, item->prefs->default_to,
-                                               COMPOSE_TO, PREF_FOLDER);
-                               compose_entry_mark_default_to(compose, item->prefs->default_to);
-                       }
+               } else {
+                       compose_set_folder_prefs(compose, item, TRUE);
                }
                if (item && item->ret_rcpt) {
                        cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", TRUE);
@@ -1059,6 +1081,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                                mfield = compose_entries_set(compose, mailto, COMPOSE_TO);
                } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
                        compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS, PREF_FOLDER);
+                       mfield = TO_FIELD_PRESENT;
                }
                /*
                 * CLAWS: just don't allow return receipt request, even if the user
@@ -1092,7 +1115,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                                dummyinfo = compose_msginfo_new_from_compose(compose);
 
                        /* decode \-escape sequences in the internal representation of the quote format */
-                       tmp = malloc(strlen(subject_format)+1);
+                       tmp = g_malloc(strlen(subject_format)+1);
                        pref_get_unescaped_pref(tmp, subject_format);
 
                        subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
@@ -1144,7 +1167,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                        g_free(tmp);
 #ifdef USE_ENCHANT
-                       if (compose->gtkaspell->check_while_typing)
+                       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
                                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
                        mfield = BODY_FIELD_PRESENT;
@@ -1154,12 +1177,13 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        procmsg_msginfo_free( dummyinfo );
 
        if (attach_files) {
-               gint i;
-               gchar *file;
+               GList *curr;
+               AttachInfo *ainfo;
 
-               for (i = 0; i < attach_files->len; i++) {
-                       file = g_ptr_array_index(attach_files, i);
-                       compose_attach_append(compose, file, file, NULL);
+               for (curr = attach_files ; curr != NULL ; curr = curr->next) {
+                       ainfo = (AttachInfo *) curr->data;
+                       compose_attach_append(compose, ainfo->file, ainfo->name,
+                                       ainfo->content_type, ainfo->charset);
                }
        }
 
@@ -1178,20 +1202,24 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        /* Place cursor according to provided input (mfield) */
        switch (mfield) { 
                case NO_FIELD_PRESENT:
-                       gtk_widget_grab_focus(compose->header_last->entry);
+                       if (compose->header_last)
+                               gtk_widget_grab_focus(compose->header_last->entry);
                        break;
                case TO_FIELD_PRESENT:
                        buf = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
-                       /*
-                        * buf will always contain an allocated string,
-                        * either empty or populated with some text
-                        */
-                       gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);     
+                       if (buf) {
+                               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
+                               g_free(buf);
+                       }
                        gtk_widget_grab_focus(compose->subject_entry);
                        break;
                case SUBJECT_FIELD_PRESENT:
                        textview = GTK_TEXT_VIEW(compose->text);
+                       if (!textview)
+                               break;
                        textbuf = gtk_text_view_get_buffer(textview);
+                       if (!textbuf)
+                               break;
                        mark = gtk_text_buffer_get_insert(textbuf);
                        gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
                        gtk_text_buffer_insert(textbuf, &iter, "", -1);
@@ -1204,7 +1232,11 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                     * is therefore created before placing the cursor
                     */
                case BODY_FIELD_PRESENT:
-                       gtk_widget_grab_focus(compose->text);
+                       cursor_pos = quote_fmt_get_cursor_pos();
+                       if (cursor_pos == -1)
+                               gtk_widget_grab_focus(compose->header_last->entry);
+                       else
+                               gtk_widget_grab_focus(compose->text);
                        break;
        }
 
@@ -1218,6 +1250,9 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
        compose->modified = FALSE;
        compose_set_title(compose);
+
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
         return compose;
 }
 
@@ -1302,6 +1337,7 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar
 
        switch (mode) {
        case COMPOSE_REPLY:
+       case COMPOSE_REPLY_TO_ADDRESS:
                compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
                              FALSE, prefs_common.default_reply_list, FALSE, body);
                break;
@@ -1413,6 +1449,9 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar
                debug_print("reply mode List\n");
                cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/ReplyMode/List", TRUE);
                break;
+       case COMPOSE_REPLY_TO_ADDRESS:
+               cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/ReplyMode", FALSE);
+               break;
        default:
                break;
        }
@@ -1424,7 +1463,7 @@ static Compose *compose_reply(MsgInfo *msginfo,
                                   gboolean to_all,
                                   gboolean to_ml,
                                   gboolean to_sender, 
-                  const gchar *body)
+                                  const gchar *body)
 {
        return compose_generic_reply(msginfo, quote_mode, to_all, to_ml, 
                              to_sender, FALSE, body);
@@ -1547,7 +1586,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                gchar *buf = NULL;
 
                /* decode \-escape sequences in the internal representation of the quote format */
-               tmp = malloc(strlen(msginfo->folder->prefs->reply_override_from_format)+1);
+               tmp = g_malloc(strlen(msginfo->folder->prefs->reply_override_from_format)+1);
                pref_get_unescaped_pref(tmp, msginfo->folder->prefs->reply_override_from_format);
 
 #ifdef USE_ENCHANT
@@ -1575,7 +1614,8 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
 
        undo_block(compose->undostruct);
 #ifdef USE_ENCHANT
-               compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
+       compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
+       gtkaspell_block_check(compose->gtkaspell);
 #endif
 
        if (quote_mode == COMPOSE_QUOTE_FORCED ||
@@ -1611,10 +1651,6 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                                          _("The body of the \"Reply\" template has an error at line %d."));
                compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                quote_fmt_reset_vartable();
-#ifdef USE_ENCHANT
-               if (compose->gtkaspell->check_while_typing)
-                       gtkaspell_highlight_all(compose->gtkaspell);
-#endif
        }
 
        if (MSG_IS_ENCRYPTED(compose->replyinfo->flags)) {
@@ -1634,6 +1670,11 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
 
        compose_wrap_all(compose);
 
+#ifdef USE_ENCHANT
+       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
+               gtkaspell_highlight_all(compose->gtkaspell);
+       gtkaspell_unblock_check(compose->gtkaspell);
+#endif
        SIGNAL_UNBLOCK(textbuf);
        
        gtk_widget_grab_focus(compose->text);
@@ -1655,6 +1696,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                return NULL;
        }
        END_TIMING();
+
        return compose;
 }
 
@@ -1673,7 +1715,8 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
        Compose *compose;
        GtkTextView *textview;
        GtkTextBuffer *textbuf;
-       GtkTextIter iter;
+       gint cursor_pos = -1;
+       ComposeMode mode;
 
        cm_return_val_if_fail(msginfo != NULL, NULL);
        cm_return_val_if_fail(msginfo->folder != NULL, NULL);
@@ -1683,7 +1726,11 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                                (msginfo)))
                account = cur_account;
 
-       compose = compose_create(account, msginfo->folder, COMPOSE_FORWARD, batch);
+       if (!prefs_common.forward_as_attachment)
+               mode = COMPOSE_FORWARD_INLINE;
+       else
+               mode = COMPOSE_FORWARD;
+       compose = compose_create(account, msginfo->folder, mode, batch);
 
        compose->updating = TRUE;
        compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
@@ -1722,10 +1769,11 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                        full_msginfo = procmsg_msginfo_copy(msginfo);
 
                /* decode \-escape sequences in the internal representation of the quote format */
-               tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
+               tmp = g_malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
                pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
 
 #ifdef USE_ENCHANT
+               gtkaspell_block_check(compose->gtkaspell);
                quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
@@ -1758,7 +1806,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                        g_warning("%s: file not exist\n", msgfile);
                else
                        compose_attach_append(compose, msgfile, msgfile,
-                                             "message/rfc822");
+                                             "message/rfc822", NULL);
 
                g_free(msgfile);
        } else {
@@ -1766,11 +1814,6 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                const gchar *body_fmt = NULL;
                MsgInfo *full_msginfo;
 
-               if (prefs_common.fw_quotefmt && *prefs_common.fw_quotefmt)
-                       body_fmt = gettext(prefs_common.fw_quotefmt);
-               else
-                       body_fmt = "";
-       
                full_msginfo = procmsg_msginfo_get_full_info(msginfo);
                if (!full_msginfo)
                        full_msginfo = procmsg_msginfo_copy(msginfo);
@@ -1807,10 +1850,6 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                compose_attach_parts(compose, msginfo);
 
                procmsg_msginfo_free(full_msginfo);
-#ifdef USE_ENCHANT
-               if (compose->gtkaspell->check_while_typing)
-                       gtkaspell_highlight_all(compose->gtkaspell);
-#endif
        }
 
        SIGNAL_BLOCK(textbuf);
@@ -1820,12 +1859,18 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
        compose_wrap_all(compose);
 
+#ifdef USE_ENCHANT
+       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
+               gtkaspell_highlight_all(compose->gtkaspell);
+       gtkaspell_unblock_check(compose->gtkaspell);
+#endif
        SIGNAL_UNBLOCK(textbuf);
        
-       gtk_text_buffer_get_start_iter(textbuf, &iter);
-       gtk_text_buffer_place_cursor(textbuf, &iter);
-
-       gtk_widget_grab_focus(compose->header_last->entry);
+       cursor_pos = quote_fmt_get_cursor_pos();
+       if (cursor_pos == -1)
+               gtk_widget_grab_focus(compose->header_last->entry);
+       else
+               gtk_widget_grab_focus(compose->text);
 
        if (!no_extedit && prefs_common.auto_exteditor)
                compose_exec_ext_editor(compose);
@@ -1854,6 +1899,8 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
         return compose;
 }
 
@@ -1915,7 +1962,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                        gchar *buf = NULL;
 
                        /* decode \-escape sequences in the internal representation of the quote format */
-                       tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
+                       tmp = g_malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
                        pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
 
 #ifdef USE_ENCHANT
@@ -1950,7 +1997,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                        g_warning("%s: file not exist\n", msgfile);
                else
                        compose_attach_append(compose, msgfile, msgfile,
-                               "message/rfc822");
+                               "message/rfc822", NULL);
                g_free(msgfile);
        }
        
@@ -2000,6 +2047,8 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2097,6 +2146,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        MsgInfo *replyinfo = NULL, *fwdinfo = NULL;
        gboolean autowrap = prefs_common.autowrap;
        gboolean autoindent = prefs_common.auto_indent;
+       HeaderEntry *manual_headers = NULL;
 
        cm_return_val_if_fail(msginfo != NULL, NULL);
        cm_return_val_if_fail(msginfo->folder != NULL, NULL);
@@ -2106,7 +2156,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        }
 
         if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
-           folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
+           folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
+           folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
                gchar queueheader_buf[BUFFSIZE];
                gint id, param;
 
@@ -2202,6 +2253,15 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                        }
                        g_strfreev(tokens);
                }
+               /* Get manual headers */
+               if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "X-Claws-Manual-Headers:")) {
+                       gchar *listmh = g_strdup(&queueheader_buf[strlen("X-Claws-Manual-Headers:")]);
+                       if (*listmh != '\0') {
+                               debug_print("Got manual headers: %s\n", listmh);
+                               manual_headers = procheader_entries_from_str(listmh);
+                       }
+                       g_free(listmh);
+               }
        } else {
                account = msginfo->folder->folder->account;
        }
@@ -2243,7 +2303,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        compose_extract_original_charset(compose);
 
         if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
-           folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
+           folder_has_parent_of_type(msginfo->folder, F_DRAFT) ||
+           folder_has_parent_of_type(msginfo->folder, F_OUTBOX)) {
                gchar queueheader_buf[BUFFSIZE];
 
                /* Set message save folder */
@@ -2290,8 +2351,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        }
 
        if (fp != NULL) {
-               gboolean prev_autowrap = compose->autowrap;
-               GtkTextBuffer *buffer = textbuf;
+               gboolean prev_autowrap;
+               GtkTextBuffer *buffer;
                BLOCK_WRAP();
                while (fgets(buf, sizeof(buf), fp) != NULL) {
                        strcrchomp(buf);
@@ -2309,6 +2370,16 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                                        G_CALLBACK(compose_changed_cb),
                                        compose);
 
+       if (manual_headers != NULL) {
+               if (compose_parse_manual_headers(compose, msginfo, manual_headers) < 0) {
+                       procheader_entries_free(manual_headers);
+                       compose->updating = FALSE;
+                       compose_destroy(compose);
+                       return NULL;
+               }
+               procheader_entries_free(manual_headers);
+       }
+
        gtk_widget_grab_focus(compose->text);
 
         if (prefs_common.auto_exteditor) {
@@ -2328,6 +2399,8 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
        
        compose->sig_str = account_get_signature_str(compose->account);
        
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2433,6 +2506,8 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
        
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2465,6 +2540,9 @@ void compose_entry_append(Compose *compose, const gchar *address,
        case COMPOSE_FOLLOWUPTO:
                header = N_( "Followup-To:");
                break;
+       case COMPOSE_INREPLYTO:
+               header = N_( "In-Reply-To:");
+               break;
        case COMPOSE_TO:
        default:
                header = N_("To:");
@@ -2497,8 +2575,6 @@ void compose_entry_append(Compose *compose, const gchar *address,
                gchar *tmp = g_strdup(begin);
                gchar *o_tmp = tmp;
                tmp[cur-begin]='\0';
-               cur++;
-               begin = cur;
                while (*tmp == ' ' || *tmp == '\t')
                        tmp++;
                compose_add_header_entry(compose, header, tmp, pref_type);
@@ -2508,12 +2584,18 @@ void compose_entry_append(Compose *compose, const gchar *address,
 
 static void compose_entry_mark_default_to(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);
@@ -2522,19 +2604,24 @@ static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
                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_widget_modify_text(
                                        GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
                                        GTK_STATE_NORMAL, &black);
+#if !GTK_CHECK_VERSION(3, 0, 0)
                        }
+#endif
                }
        }
 }
@@ -2597,10 +2684,11 @@ static MailField compose_entries_set(Compose *compose, const gchar *mailto, Comp
        gchar *temp = NULL;
        gsize  len = 0;
        gchar **attach = NULL;
+       gchar *inreplyto = NULL;
        MailField mfield = NO_FIELD_PRESENT;
 
        /* get mailto parts but skip from */
-       scan_mailto_url(mailto, NULL, &to, &cc, &bcc, &subject, &body, &attach);
+       scan_mailto_url(mailto, NULL, &to, &cc, &bcc, &subject, &body, &attach, &inreplyto);
 
        if (to) {
                compose_entry_append(compose, to, to_type, PREF_MAILTO);
@@ -2653,7 +2741,7 @@ static MailField compose_entries_set(Compose *compose, const gchar *mailto, Comp
                while (attach[i] != NULL) {
                        gchar *utf8_filename = conv_filename_to_utf8(attach[i]);
                        if (utf8_filename) {
-                               if (compose_attach_append(compose, attach[i], utf8_filename, NULL)) {
+                               if (compose_attach_append(compose, attach[i], utf8_filename, NULL, NULL)) {
                                        gchar *tmp = g_strdup_printf("%s%s\n",
                                                        warn_files?warn_files:"",
                                                        utf8_filename);
@@ -2674,12 +2762,16 @@ static MailField compose_entries_set(Compose *compose, const gchar *mailto, Comp
                        g_free(warn_files);
                }
        }
+       if (inreplyto)
+               compose_entry_append(compose, inreplyto, COMPOSE_INREPLYTO, PREF_MAILTO);
+
        g_free(to);
        g_free(cc);
        g_free(bcc);
        g_free(subject);
        g_free(body);
        g_strfreev(attach);
+       g_free(inreplyto);
        
        return mfield;
 }
@@ -2720,13 +2812,13 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                if (hentry[H_REPLY_TO].body[0] != '\0') {
                        compose->replyto =
                                conv_unmime_header(hentry[H_REPLY_TO].body,
-                                                  NULL);
+                                                  NULL, TRUE);
                }
                g_free(hentry[H_REPLY_TO].body);
                hentry[H_REPLY_TO].body = NULL;
        }
        if (hentry[H_CC].body != NULL) {
-               compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
+               compose->cc = conv_unmime_header(hentry[H_CC].body, NULL, TRUE);
                g_free(hentry[H_CC].body);
                hentry[H_CC].body = NULL;
        }
@@ -2743,7 +2835,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        if (hentry[H_BCC].body != NULL) {
                if (compose->mode == COMPOSE_REEDIT)
                        compose->bcc =
-                               conv_unmime_header(hentry[H_BCC].body, NULL);
+                               conv_unmime_header(hentry[H_BCC].body, NULL, TRUE);
                g_free(hentry[H_BCC].body);
                hentry[H_BCC].body = NULL;
        }
@@ -2755,7 +2847,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
                        compose->followup_to =
                                conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
-                                                  NULL);
+                                                  NULL, TRUE);
                }
                g_free(hentry[H_FOLLOWUP_TO].body);
                hentry[H_FOLLOWUP_TO].body = NULL;
@@ -2768,7 +2860,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                        start = strstr(hentry[H_LIST_POST].body, "mailto:");
                        
                        scan_mailto_url(start ? start : hentry[H_LIST_POST].body,
-                                       NULL, &to, NULL, NULL, NULL, NULL, NULL);
+                                       NULL, &to, NULL, NULL, NULL, NULL, NULL, NULL);
 
                        if (to) {
                                g_free(compose->ml_post);
@@ -2826,6 +2918,33 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        return 0;
 }
 
+static gint compose_parse_manual_headers(Compose *compose, MsgInfo *msginfo, HeaderEntry *entries)
+{
+       FILE *fp;
+       HeaderEntry *he;
+
+       cm_return_val_if_fail(msginfo != NULL, -1);
+
+       if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
+       procheader_get_header_fields(fp, entries);
+       fclose(fp);
+
+       he = entries;
+       while (he != NULL && he->name != NULL) {
+               GtkTreeIter iter;
+               GtkListStore *model = NULL;
+
+               debug_print("Adding manual header: %s with value %s\n", he->name, he->body);
+               model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(compose->header_last->combo)));
+               COMBOBOX_ADD(model, he->name, COMPOSE_TO);
+               gtk_combo_box_set_active_iter(GTK_COMBO_BOX(compose->header_last->combo), &iter);
+               gtk_entry_set_text(GTK_ENTRY(compose->header_last->entry), he->body);
+               ++he;
+       }
+
+       return 0;
+}
+
 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
 {
        GSList *ref_id_list, *cur;
@@ -2852,8 +2971,7 @@ static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
                                ref_id_list = g_slist_remove
                                        (ref_id_list, ref_id_list->next->data);
                        } else {
-                               slist_free_strings(ref_id_list);
-                               g_slist_free(ref_id_list);
+                               slist_free_strings_full(ref_id_list);
                                return NULL;
                        }
                } else
@@ -2867,8 +2985,7 @@ static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
                g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
        }
 
-       slist_free_strings(ref_id_list);
-       g_slist_free(ref_id_list);
+       slist_free_strings_full(ref_id_list);
 
        new_ref_str = new_ref->str;
        g_string_free(new_ref, FALSE);
@@ -2934,7 +3051,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                        gchar *tmp = NULL;
 
                        /* decode \-escape sequences in the internal representation of the quote format */
-                       tmp = malloc(strlen(fmt)+1);
+                       tmp = g_malloc(strlen(fmt)+1);
                        pref_get_unescaped_pref(tmp, fmt);
                        quote_fmt_scan_string(tmp);
                        quote_fmt_parse();
@@ -3036,6 +3153,52 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from)
        return result;
 }
 
+static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
+                                    gboolean respect_default_to)
+{
+       if (!compose)
+               return;
+       if (!folder || !folder->prefs)
+               return;
+
+       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);
+       }
+       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_append(compose, folder->prefs->default_bcc,
+                                       COMPOSE_BCC, PREF_FOLDER);
+       if (folder->prefs->enable_default_replyto)
+               compose_entry_append(compose, folder->prefs->default_replyto,
+                                       COMPOSE_REPLYTO, PREF_FOLDER);
+}
+
+static void compose_reply_set_subject(Compose *compose, MsgInfo *msginfo)
+{
+       gchar *buf, *buf2;
+       gchar *p;
+       
+       if (!compose || !msginfo)
+               return;
+
+       if (msginfo->subject && *msginfo->subject) {
+               buf = p = g_strdup(msginfo->subject);
+               p += subject_get_prefix_length(p);
+               memmove(buf, p, strlen(p) + 1);
+
+               buf2 = g_strdup_printf("Re: %s", buf);
+               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
+
+               g_free(buf2);
+               g_free(buf);
+       } else
+               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
+}
+
 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                    gboolean to_all, gboolean to_ml,
                                    gboolean to_sender,
@@ -3045,6 +3208,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        GSList *cur;
        gchar *from = NULL;
        gchar *replyto = NULL;
+       gchar *ac_email = NULL;
 
        gboolean reply_to_ml = FALSE;
        gboolean default_reply_to = FALSE;
@@ -3058,20 +3222,8 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                msginfo->folder->prefs->enable_default_reply_to;
 
        if (compose->account->protocol != A_NNTP) {
-               if (msginfo && msginfo->folder && msginfo->folder->prefs) {
-                       if (msginfo->folder->prefs->enable_default_replyto) {
-                               compose_entry_append(compose, msginfo->folder->prefs->default_replyto,
-                                                       COMPOSE_REPLYTO, PREF_FOLDER);
-                       }
-                       if (msginfo->folder->prefs->enable_default_bcc) {
-                               compose_entry_append(compose, msginfo->folder->prefs->default_bcc,
-                                                       COMPOSE_BCC, PREF_FOLDER);
-                       }
-                       if (msginfo->folder->prefs->enable_default_cc) {
-                               compose_entry_append(compose, msginfo->folder->prefs->default_cc,
-                                                       COMPOSE_CC, PREF_FOLDER);
-                       }
-               }
+               compose_set_folder_prefs(compose, msginfo->folder, FALSE);
+
                if (reply_to_ml && !default_reply_to) {
                        
                        gboolean is_subscr = is_subscription(compose->ml_post,
@@ -3169,22 +3321,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                 compose->newsgroups ? compose->newsgroups : "",
                                 COMPOSE_NEWSGROUPS, PREF_NONE);
        }
-
-       if (msginfo->subject && *msginfo->subject) {
-               gchar *buf, *buf2;
-               gchar *p;
-
-               buf = p = g_strdup(msginfo->subject);
-               p += subject_get_prefix_length(p);
-               memmove(buf, p, strlen(p) + 1);
-
-               buf2 = g_strdup_printf("Re: %s", buf);
-               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
-
-               g_free(buf2);
-               g_free(buf);
-       } else
-               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
+       compose_reply_set_subject(compose, msginfo);
 
        if (to_ml && compose->ml_post) return;
        if (!to_all || compose->account->protocol == A_NNTP) return;
@@ -3207,13 +3344,26 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        cc_list = address_list_append_with_comments(cc_list, msginfo->to);
        cc_list = address_list_append_with_comments(cc_list, compose->cc);
 
+       ac_email = g_utf8_strdown(compose->account->address, -1);
+
        if (cc_list) {
-               for (cur = cc_list; cur != NULL; cur = cur->next)
-                       compose_entry_append(compose, (gchar *)cur->data,
-                                            COMPOSE_CC, PREF_NONE);
-               slist_free_strings(cc_list);
-               g_slist_free(cc_list);
+               for (cur = cc_list; cur != NULL; cur = cur->next) {
+                       gchar *addr = g_utf8_strdown(cur->data, -1);
+                       extract_address(addr);
+               
+                       if (strcmp(ac_email, addr))
+                               compose_entry_append(compose, (gchar *)cur->data,
+                                                    COMPOSE_CC, PREF_NONE);
+                       else
+                               debug_print("Cc address same as compose account's, ignoring\n");
+
+                       g_free(addr);
+               }
+               
+               slist_free_strings_full(cc_list);
        }
+       
+       g_free(ac_email);
 }
 
 #define SET_ENTRY(entry, str) \
@@ -3361,6 +3511,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        gboolean badtxt = FALSE;
        struct stat file_stat;
        int ret;
+       GString *file_contents = NULL;
 
        cm_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
 
@@ -3420,6 +3571,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
        cur_encoding = conv_get_locale_charset_str_no_utf8();
 
+       file_contents = g_string_new("");
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *str;
 
@@ -3439,10 +3591,14 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                                if (str[len] == '\r') str[len] = '\n';
                }
 
-               gtk_text_buffer_insert(buffer, &iter, str, -1);
+               file_contents = g_string_append(file_contents, str);
                g_free(str);
        }
 
+       gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1);
+       g_string_free(file_contents, TRUE);
+
+       compose_changed_cb(NULL, compose);
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                          G_CALLBACK(text_inserted),
                                          compose);
@@ -3460,7 +3616,8 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
 static gboolean compose_attach_append(Compose *compose, const gchar *file,
                                  const gchar *filename,
-                                 const gchar *content_type)
+                                 const gchar *content_type,
+                                 const gchar *charset)
 {
        AttachInfo *ainfo;
        GtkTreeIter iter;
@@ -3478,8 +3635,8 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                if (file_from_uri && is_file_exist(file_from_uri)) {
                        result = compose_attach_append(
                                                compose, file_from_uri,
-                                               filename,
-                                               content_type);
+                                               filename, content_type,
+                                               charset);
                }
                g_free(file_from_uri);
                if (result)
@@ -3527,10 +3684,12 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
 
                        procmsg_msginfo_free(msginfo);
                } else {
-                       if (!g_ascii_strncasecmp(content_type, "text", 4))
+                       if (!g_ascii_strncasecmp(content_type, "text/", 5)) {
+                               ainfo->charset = g_strdup(charset);
                                ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
-                       else
+                       } else {
                                ainfo->encoding = ENC_BASE64;
+                       }
                        name = g_path_get_basename(filename ? filename : file);
                        ainfo->name = g_strdup(name);
                }
@@ -3541,7 +3700,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                        ainfo->content_type =
                                g_strdup("application/octet-stream");
                        ainfo->encoding = ENC_BASE64;
-               } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
+               } else if (!g_ascii_strncasecmp(ainfo->content_type, "text/", 5))
                        ainfo->encoding =
                                procmime_get_encoding_for_text_file(file, &has_binary);
                else
@@ -3560,6 +3719,8 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
        if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
                g_free(ainfo->content_type);
                ainfo->content_type = g_strdup("application/octet-stream");
+               g_free(ainfo->charset);
+               ainfo->charset = NULL;
        }
 
        ainfo->size = (goffset)size;
@@ -3573,6 +3734,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                           COL_MIMETYPE, ainfo->content_type,
                           COL_SIZE, size_text,
                           COL_NAME, ainfo->name,
+                          COL_CHARSET, ainfo->charset,
                           COL_DATA, ainfo,
                           COL_AUTODATA, auto_ainfo,
                           -1);
@@ -3676,7 +3838,8 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                                if (partname == NULL)
                                        partname = "";
                                compose_attach_append(compose, outfile, 
-                                                     partname, content_type);
+                                                     partname, content_type,
+                                                     procmime_mimeinfo_get_parameter(child, "charset"));
                        } else {
                                compose_force_signing(compose, compose->account, NULL);
                        }
@@ -4469,7 +4632,7 @@ end:
                *par_iter = iter;
        undo_wrapping(compose->undostruct, FALSE);
        compose->autowrap = prev_autowrap;
-       
+
        return modified;
 }
 
@@ -4609,20 +4772,15 @@ compose_current_mail_account(void)
 static void compose_select_account(Compose *compose, PrefsAccount *account,
                                   gboolean init)
 {
-       gchar *from = NULL, *email, *header;
+       gchar *from = NULL, *header = NULL;
        ComposeHeaderEntry *header_entry;
+#if GTK_CHECK_VERSION(2, 24, 0)
+       GtkTreeIter iter;
+#endif
 
        cm_return_if_fail(account != NULL);
 
-       email = g_utf8_strdown(compose->account->address, -1);
-       g_hash_table_remove(compose->email_hashtable, email);
-       g_free(email);
-
        compose->account = account;
-       g_hash_table_insert(compose->email_hashtable,
-                           g_utf8_strdown(account->address, -1),
-                           GUINT_TO_POINTER(1)); 
-
        if (account->name && *account->name) {
                gchar *buf;
                QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
@@ -4657,7 +4815,13 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
        }
        
        header_entry = (ComposeHeaderEntry *) compose->header_list->data;
+#if !GTK_CHECK_VERSION(2, 24, 0)
        header = gtk_combo_box_get_active_text(GTK_COMBO_BOX(header_entry->combo));
+#else
+       if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(header_entry->combo), &iter))
+               gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(
+                       header_entry->combo)), &iter, COMBOBOX_TEXT, &header, -1);
+#endif
        
        if (header && !strlen(gtk_entry_get_text(GTK_ENTRY(header_entry->entry)))) {
                if (account->protocol == A_NNTP) {
@@ -4699,12 +4863,10 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
        gchar **strptr;
 
        /* free to and newsgroup list */
-        slist_free_strings(compose->to_list);
-       g_slist_free(compose->to_list);
+        slist_free_strings_full(compose->to_list);
        compose->to_list = NULL;
                        
-       slist_free_strings(compose->newsgroup_list);
-        g_slist_free(compose->newsgroup_list);
+       slist_free_strings_full(compose->newsgroup_list);
         compose->newsgroup_list = NULL;
 
        /* search header entries for to and newsgroup entries */
@@ -4925,10 +5087,10 @@ gint compose_send(Compose *compose)
        }
        if (msgpath == NULL) {
                msgpath = folder_item_fetch_msg(folder, msgnum);
-               val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum, &queued_removed);
+               val = procmsg_send_message_queue_with_lock(msgpath, &errstr, folder, msgnum, &queued_removed);
                g_free(msgpath);
        } else {
-               val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum, &queued_removed);
+               val = procmsg_send_message_queue_with_lock(msgpath, &errstr, folder, msgnum, &queued_removed);
                claws_unlink(msgpath);
                g_free(msgpath);
        }
@@ -5607,17 +5769,13 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        FILE *fp;
        GSList *cur;
        gint num;
-        static gboolean lock = FALSE;
        PrefsAccount *mailac = NULL, *newsac = NULL;
        gboolean err = FALSE;
 
        debug_print("queueing message...\n");
        cm_return_val_if_fail(compose->account != NULL, -1);
 
-        lock = TRUE;
-       
        if (compose_check_entries(compose, check_subject) == FALSE) {
-                lock = FALSE;
                if (compose->batch) {
                        gtk_widget_show_all(compose->window);
                }
@@ -5626,7 +5784,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
 
        if (!compose->to_list && !compose->newsgroup_list) {
                g_warning("can't get recipient list.");
-               lock = FALSE;
                 return -1;
         }
 
@@ -5636,7 +5793,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                else if (cur_account && cur_account->protocol != A_NNTP)
                        mailac = cur_account;
                else if (!(mailac = compose_current_mail_account())) {
-                       lock = FALSE;
                        alertpanel_error(_("No account for sending mails available!"));
                        return -1;
                }
@@ -5646,7 +5802,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                 if (compose->account->protocol == A_NNTP)
                         newsac = compose->account;
                 else {
-                       lock = FALSE;
                        alertpanel_error(_("Selected account isn't NNTP: Posting is impossible."));
                        return -1;
                }                       
@@ -5659,7 +5814,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                g_free(tmp);
-               lock = FALSE;
                return -2;
        }
 
@@ -5721,7 +5875,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                if (compose->use_encryption) {
                        gchar *encdata;
                        if (!compose_warn_encryption(compose)) {
-                               lock = FALSE;
                                fclose(fp);
                                claws_unlink(tmp);
                                g_free(tmp);
@@ -5745,7 +5898,8 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                                err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
                                /* and if encdata was null, it means there's been a problem in 
                                 * key selection */
-                               lock = FALSE;
+                               if (err == TRUE)
+                                       g_warning("failed to write queue message");
                                fclose(fp);
                                claws_unlink(tmp);
                                g_free(tmp);
@@ -5792,7 +5946,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
 
        if (compose->redirect_filename != NULL) {
                if (compose_redirect_write_to_file(compose, fp) < 0) {
-                       lock = FALSE;
                        fclose(fp);
                        claws_unlink(tmp);
                        g_free(tmp);
@@ -5801,7 +5954,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        } else {
                gint result = 0;
                if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
-                       lock = FALSE;
                        fclose(fp);
                        claws_unlink(tmp);
                        g_free(tmp);
@@ -5813,14 +5965,12 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                fclose(fp);
                claws_unlink(tmp);
                g_free(tmp);
-               lock = FALSE;
                return -2;
        }
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
                claws_unlink(tmp);
                g_free(tmp);
-               lock = FALSE;
                return -2;
        }
 
@@ -5833,7 +5983,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                g_warning("can't find queue folder\n");
                claws_unlink(tmp);
                g_free(tmp);
-               lock = FALSE;
                return -1;
        }
        folder_item_scan(queue);
@@ -5841,7 +5990,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                g_warning("can't queue the message\n");
                claws_unlink(tmp);
                g_free(tmp);
-               lock = FALSE;
                return -1;
        }
        
@@ -5917,24 +6065,40 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
                if (mimepart->type == MIMETYPE_MESSAGE && 
                    !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
                        mimepart->disposition = DISPOSITIONTYPE_INLINE;
-               } else {
-                       if (ainfo->name) {
-                               if (mimepart->type == MIMETYPE_APPLICATION && 
-                                  !strcmp2(mimepart->subtype, "octet-stream"))
-                                       g_hash_table_insert(mimepart->typeparameters,
-                                                   g_strdup("name"), g_strdup(ainfo->name));
-                               g_hash_table_insert(mimepart->dispositionparameters,
-                                           g_strdup("filename"), g_strdup(ainfo->name));
+               } else if (mimepart->type == MIMETYPE_TEXT) {
+                       if (!ainfo->name && g_ascii_strcasecmp(mimepart->subtype, "plain")) {
+                               /* Text parts with no name come from multipart/alternative
+                               * forwards. Make sure the recipient won't look at the 
+                               * original HTML part by mistake. */
                                mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
+                               ainfo->name = g_strdup_printf(_("Original %s part"),
+                                                               mimepart->subtype);
                        }
-               }
-
-               if (compose->use_signing) {
+                       if (ainfo->charset)
+                               g_hash_table_insert(mimepart->typeparameters,
+                                                   g_strdup("charset"), g_strdup(ainfo->charset));
+               }
+               if (ainfo->name && mimepart->type != MIMETYPE_MESSAGE) {
+                       if (mimepart->type == MIMETYPE_APPLICATION && 
+                          !strcmp2(mimepart->subtype, "octet-stream"))
+                               g_hash_table_insert(mimepart->typeparameters,
+                                               g_strdup("name"), g_strdup(ainfo->name));
+                       g_hash_table_insert(mimepart->dispositionparameters,
+                                       g_strdup("filename"), g_strdup(ainfo->name));
+                       mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
+               }
+
+               if (mimepart->type == MIMETYPE_MESSAGE
+                   || mimepart->type == MIMETYPE_MULTIPART)
+                       ainfo->encoding = ENC_BINARY;
+               else if (compose->use_signing) {
                        if (ainfo->encoding == ENC_7BIT)
                                ainfo->encoding = ENC_QUOTED_PRINTABLE;
                        else if (ainfo->encoding == ENC_8BIT)
                                ainfo->encoding = ENC_BASE64;
                }
+
+               
                
                procmime_encode_content(mimepart, ainfo->encoding);
 
@@ -6004,6 +6168,55 @@ static void compose_add_headerfield_from_headerlist(Compose *compose,
        return;
 }
 
+static gchar *compose_get_manual_headers_info(Compose *compose)
+{
+       GString *sh_header = g_string_new(" ");
+       GSList *list;
+       gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
+
+       for (list = compose->header_list; list; list = list->next) {
+               ComposeHeaderEntry *headerentry;
+               gchar *tmp;
+               gchar *headername;
+               gchar *headername_wcolon;
+               const gchar *headername_trans;
+               gchar **string;
+               gboolean standard_header = FALSE;
+
+               headerentry = ((ComposeHeaderEntry *)list->data);
+
+               tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo))))));
+               g_strstrip(tmp);
+               if (*tmp == '\0' || strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
+                       g_free(tmp);
+                       continue;
+               }
+
+               if (!strstr(tmp, ":")) {
+                       headername_wcolon = g_strconcat(tmp, ":", NULL);
+                       headername = g_strdup(tmp);
+               } else {
+                       headername_wcolon = g_strdup(tmp);
+                       headername = g_strdup(strtok(tmp, ":"));
+               }
+               g_free(tmp);
+               
+               string = std_headers;
+               while (*string != NULL) {
+                       headername_trans = prefs_common_translated_header_name(*string);
+                       if (!strcmp(headername_trans, headername_wcolon))
+                               standard_header = TRUE;
+                       string++;
+               }
+               if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
+                       g_string_append_printf(sh_header, "%s ", headername);
+               g_free(headername);
+               g_free(headername_wcolon);
+       }
+       g_string_truncate(sh_header, strlen(sh_header->str) - 1); /* remove last space */
+       return g_string_free(sh_header, FALSE);
+}
+
 static gchar *compose_get_header(Compose *compose)
 {
        gchar buf[BUFFSIZE];
@@ -6082,7 +6295,12 @@ static gchar *compose_get_header(Compose *compose)
        compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
 
        /* Bcc */
-       compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
+       /* 
+        * If this account is a NNTP account remove Bcc header from 
+        * message body since it otherwise will be publicly shown
+        */
+       if (compose->account->protocol != A_NNTP)
+               compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
 
        /* Subject */
        str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
@@ -6148,7 +6366,8 @@ static gchar *compose_get_header(Compose *compose)
        }
 
        /* Program version and system info */
-       if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
+       if (compose->account->gen_xmailer &&
+           g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
            !compose->newsgroup_list) {
                g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
                        prog_version,
@@ -6170,10 +6389,12 @@ static gchar *compose_get_header(Compose *compose)
                     cur = cur->next) {
                        CustomHeader *chdr = (CustomHeader *)cur->data;
 
-                       if (custom_header_is_allowed(chdr->name)) {
+                       if (custom_header_is_allowed(chdr->name)
+                           && chdr->value != NULL
+                           && *(chdr->value) != '\0') {
                                compose_convert_header
                                        (compose, buf, sizeof(buf),
-                                        chdr->value ? chdr->value : "",
+                                        chdr->value,
                                         strlen(chdr->name) + 2, FALSE);
                                g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
                        }
@@ -6357,7 +6578,14 @@ 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
                addressbook_add_contact(name, address, NULL, NULL);
+#else
+               debug_print("%s: %s\n", name, address);
+               if (addressadd_selection(name, address, NULL, NULL)) {
+                       debug_print( "addressbook_add_contact - added\n" );
+               }
+#endif
        }
        g_free(address);
 }
@@ -6388,6 +6616,54 @@ static void compose_entry_popup_extend(GtkEntry *entry, GtkMenu *menu, gpointer
        gtk_widget_show(menuitem);
 }
 
+void compose_add_extra_header(gchar *header, GtkListStore *model)
+{
+       GtkTreeIter iter;
+       if (strcmp(header, "")) {
+               COMBOBOX_ADD(model, header, COMPOSE_TO);
+       }
+}
+
+void compose_add_extra_header_entries(GtkListStore *model)
+{
+       FILE *exh;
+       gchar *exhrc;
+       gchar buf[BUFFSIZE];
+       gint lastc;
+
+       if (extra_headers == NULL) {
+               exhrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "extraheaderrc", NULL);
+               if ((exh = g_fopen(exhrc, "rb")) == NULL) {
+                       debug_print("extra headers file not found\n");
+                       goto extra_headers_done;
+               }
+               while (fgets(buf, BUFFSIZE, exh) != NULL) {
+                       lastc = strlen(buf) - 1;        /* remove trailing control chars */
+                       while (lastc >= 0 && buf[lastc] != ':')
+                               buf[lastc--] = '\0';
+                       if (lastc > 0 && buf[0] != '#' && buf[lastc] == ':') {
+                               buf[lastc] = '\0'; /* remove trailing : for comparison */
+                               if (custom_header_is_allowed(buf)) {
+                                       buf[lastc] = ':';
+                                       extra_headers = g_slist_prepend(extra_headers, g_strdup(buf));
+                               }
+                               else
+                                       g_message("disallowed extra header line: %s\n", buf);
+                       }
+                       else {
+                               if (buf[0] != '#')
+                                       g_message("invalid extra header line: %s\n", buf);
+                       }
+               }
+               fclose(exh);
+extra_headers_done:
+               g_free(exhrc);
+               extra_headers = g_slist_prepend(extra_headers, g_strdup("")); /* end of list */
+               extra_headers = g_slist_reverse(extra_headers);
+       }
+       g_slist_foreach(extra_headers, (GFunc)compose_add_extra_header, (gpointer)model);
+}
+
 static void compose_create_header_entry(Compose *compose) 
 {
        gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
@@ -6408,9 +6684,11 @@ static void compose_create_header_entry(Compose *compose)
        
        headerentry = g_new0(ComposeHeaderEntry, 1);
 
-       /* Combo box */
+       /* Combo box model */
        model = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
+#if !GTK_CHECK_VERSION(2, 24, 0)
        combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
+#endif
        COMBOBOX_ADD(model, prefs_common_translated_header_name("To:"),
                        COMPOSE_TO);
        COMBOBOX_ADD(model, prefs_common_translated_header_name("Cc:"),
@@ -6423,11 +6701,26 @@ static void compose_create_header_entry(Compose *compose)
                        COMPOSE_REPLYTO);
        COMBOBOX_ADD(model, prefs_common_translated_header_name("Followup-To:"),
                        COMPOSE_FOLLOWUPTO);
+       compose_add_extra_header_entries(model);
 
+       /* Combo box */
+#if GTK_CHECK_VERSION(2, 24, 0)
+       combo = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(model));
+       GtkCellRenderer *cell = gtk_cell_renderer_text_new();
+       gtk_cell_renderer_set_alignment(cell, 0.0, 0.5);
+       gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
+       gtk_combo_box_set_entry_text_column(combo, 0);
+#endif
        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
-       g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((combo)))), "grab_focus",
+       g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN(combo))), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
        gtk_widget_show(combo);
+       
+       GList *l = NULL;
+       l = g_list_prepend(l, gtk_bin_get_child(GTK_BIN(combo)));
+       gtk_container_set_focus_chain(GTK_CONTAINER(combo), l);
+       g_list_free(l);
+
        gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1,
                        compose->header_nextrow, compose->header_nextrow+1,
                        GTK_SHRINK, GTK_FILL, 0, 0);
@@ -6460,13 +6753,9 @@ static void compose_create_header_entry(Compose *compose)
                         G_CALLBACK(compose_grab_focus_cb), compose);
 
        /* Entry field with cleanup button */
-#if GTK_CHECK_VERSION(2, 8, 0)
        button = gtk_button_new();
        gtk_button_set_image(GTK_BUTTON(button),
                         gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
-#else
-       button = gtk_button_new_with_label(_("Clear"));
-#endif
        gtk_widget_show(button);
        CLAWS_SET_TIP(button,
                _("Delete entry contents"));
@@ -6531,12 +6820,21 @@ static void compose_add_header_entry(Compose *compose, const gchar *header,
 {
        ComposeHeaderEntry *last_header = compose->header_last;
        gchar *tmp = g_strdup(text), *email;
-       
+       gboolean replyto_hdr;
+       
+       replyto_hdr = (!strcasecmp(header,
+                               prefs_common_translated_header_name("Reply-To:")) ||
+                       !strcasecmp(header,
+                               prefs_common_translated_header_name("Followup-To:")) ||
+                       !strcasecmp(header,
+                               prefs_common_translated_header_name("In-Reply-To:")));
+               
        extract_address(tmp);
        email = g_utf8_strdown(tmp, -1);
        
-       if (!(!strcmp(header, "To:") && !strcasecmp(compose->account->address, email))
-           && g_hash_table_lookup(compose->email_hashtable, email) != NULL) {
+       if (replyto_hdr == FALSE &&
+           g_hash_table_lookup(compose->email_hashtable, email) != NULL)
+       {
                debug_print("Ignoring duplicate address - %s %s, pref_type: %d\n",
                                header, text, (gint) pref_type);
                g_free(email);
@@ -6544,12 +6842,20 @@ static void compose_add_header_entry(Compose *compose, const gchar *header,
                return;
        }
        
-       combobox_select_by_text(GTK_COMBO_BOX(last_header->combo), header);
+       if (!strcasecmp(header, prefs_common_translated_header_name("In-Reply-To:")))
+               gtk_entry_set_text(GTK_ENTRY(
+                       gtk_bin_get_child(GTK_BIN(last_header->combo))), header);
+       else
+               combobox_select_by_text(GTK_COMBO_BOX(last_header->combo), header);
        gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
        last_header->type = pref_type;
 
-       g_hash_table_insert(compose->email_hashtable, email,
-                               GUINT_TO_POINTER(1));
+       if (replyto_hdr == FALSE)
+               g_hash_table_insert(compose->email_hashtable, email,
+                                   GUINT_TO_POINTER(1));
+       else
+               g_free(email);
+       
        g_free(tmp);
 }
 
@@ -6588,12 +6894,27 @@ 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;
 
-       gint count = 0;
+       /* 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 labels and entries */
+       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,
+                                 0, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
+
+       /* child with header labels and entries */
        header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_widget_show(header_scrolledwin);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
@@ -6603,23 +6924,19 @@ static GtkWidget *compose_create_header(Compose *compose)
        gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
        gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN((header_scrolledwin)))), GTK_SHADOW_NONE);
-       count = 0;
 
-       /* option menu for selecting accounts */
-       from_optmenu_hbox = compose_account_option_menu_create(compose);
-       gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
-                                 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
-       count++;
+       gtk_table_attach(GTK_TABLE(header_table_main), header_scrolledwin,
+                                 0, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 2);
 
        compose->header_table = header_table;
        compose->header_list = NULL;
-       compose->header_nextrow = count;
+       compose->header_nextrow = 0;
 
        compose_create_header_entry(compose);
 
-       compose->table            = NULL;
+       compose->table = NULL;
 
-       return header_scrolledwin ;
+       return header_scrolledwin_main;
 }
 
 static gboolean popup_attach_button_pressed(GtkWidget *widget, gpointer data)
@@ -6654,6 +6971,7 @@ static GtkWidget *compose_create_attach(Compose *compose)
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
+                                  G_TYPE_STRING,
                                   G_TYPE_POINTER,
                                   G_TYPE_AUTO_POINTER,
                                   -1);
@@ -6749,7 +7067,11 @@ static GtkWidget *compose_create_others(Compose *compose)
        g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
                         G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
 
+#if !GTK_CHECK_VERSION(2, 24, 0)
        savemsg_combo = gtk_combo_box_entry_new_text();
+#else
+       savemsg_combo = gtk_combo_box_text_new_with_entry();
+#endif
        compose->savemsg_checkbtn = savemsg_checkbtn;
        compose->savemsg_combo = savemsg_combo;
        gtk_widget_show(savemsg_combo);
@@ -6776,8 +7098,6 @@ static GtkWidget *compose_create_others(Compose *compose)
                         G_CALLBACK(compose_savemsg_select_cb),
                         compose);
 
-       rowcount++;
-
        return table;   
 }
 
@@ -6809,7 +7129,7 @@ static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
                                        Compose *compose)
 {
        gint prev_autowrap;
-       GtkTextBuffer *buffer = GTK_TEXT_VIEW(text)->buffer;
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
 #if USE_ENCHANT
        if (event->button == 3) {
                GtkTextIter iter;
@@ -6908,7 +7228,8 @@ static void compose_dict_changed(void *data)
 {
        Compose *compose = (Compose *) data;
 
-       if(compose->gtkaspell->recheck_when_changing_dict == FALSE)
+       if(compose->gtkaspell && 
+                  compose->gtkaspell->recheck_when_changing_dict == FALSE)
                return;
 
        gtkaspell_highlight_all(compose->gtkaspell);
@@ -6963,11 +7284,9 @@ static Compose *compose_create(PrefsAccount *account,
        GtkWidget *text;
        GtkTextBuffer *buffer;
        GtkClipboard *clipboard;
-       CLAWS_TIP_DECL();
 
        UndoMain *undostruct;
 
-       gchar *titles[N_ATTACH_COLS];
        GtkWidget *popupmenu;
        GtkWidget *tmpl_menu;
        GtkActionGroup *action_group = NULL;
@@ -6983,15 +7302,11 @@ static Compose *compose_create(PrefsAccount *account,
        debug_print("Creating compose window...\n");
        compose = g_new0(Compose, 1);
 
-       titles[COL_MIMETYPE] = _("MIME type");
-       titles[COL_SIZE]     = _("Size");
-       titles[COL_NAME]     = _("Name");
-
        compose->batch = batch;
        compose->account = account;
        compose->folder = folder;
        
-       compose->mutex = g_mutex_new();
+       compose->mutex = cm_mutex_new();
        compose->set_cursor_pos = -1;
 
 #if !(GTK_CHECK_VERSION(2,12,0))
@@ -7001,7 +7316,8 @@ static Compose *compose_create(PrefsAccount *account,
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose");
 
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
-       gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
+       gtk_widget_set_size_request(window, prefs_common.compose_width,
+                                       prefs_common.compose_height);
 
        if (!geometry.max_width) {
                geometry.max_width = gdk_screen_width();
@@ -7069,6 +7385,8 @@ static Compose *compose_create(PrefsAccount *account,
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Separator2", "Message/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Save", "Message/Save", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Separator3", "Message/---", GTK_UI_MANAGER_SEPARATOR)
+       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Print", "Message/Print", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Separator4", "Message/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Message", "Close", "Message/Close", GTK_UI_MANAGER_MENUITEM)
 
 /* Edit menu */
@@ -7197,6 +7515,7 @@ static Compose *compose_create(PrefsAccount *account,
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Japanese", CS_SHIFT_JIS, "Options/Encoding/Japanese/"CS_SHIFT_JIS, GTK_UI_MANAGER_MENUITEM)
 
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding", "Chinese", "Options/Encoding/Chinese", GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_GB18030, "Options/Encoding/Chinese/"CS_GB18030, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_GB2312, "Options/Encoding/Chinese/"CS_GB2312, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_GBK, "Options/Encoding/Chinese/"CS_GBK, GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Encoding/Chinese", CS_BIG5, "Options/Encoding/Chinese/"CS_BIG5, GTK_UI_MANAGER_MENUITEM)
@@ -7254,7 +7573,7 @@ static Compose *compose_create(PrefsAccount *account,
        
        /* Notebook */
        notebook = gtk_notebook_new();
-       gtk_widget_set_size_request(notebook, -1, 130);
+       gtk_widget_set_size_request(notebook, -1, prefs_common.compose_notebook_height);
        gtk_widget_show(notebook);
 
        /* header labels and entries */
@@ -7318,8 +7637,8 @@ static Compose *compose_create(PrefsAccount *account,
        ruler_hbox = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
 
-       ruler = gtk_shruler_new();
-       gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
+       ruler = gtk_shruler_new(GTK_ORIENTATION_HORIZONTAL);
+       gtk_shruler_set_range(GTK_SHRULER(ruler), 0.0, 100.0, 1.0);
        gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
                           BORDER_WIDTH);
 
@@ -7331,9 +7650,12 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
                                            GTK_SHADOW_IN);
        gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
-       gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
 
        text = gtk_text_view_new();
+       if (prefs_common.show_compose_margin) {
+               gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
+               gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
+       }
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
        gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
@@ -7341,7 +7663,8 @@ 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);
@@ -7363,7 +7686,9 @@ static Compose *compose_create(PrefsAccount *account,
                         G_CALLBACK(compose_popup_menu), compose);
 #endif
        g_signal_connect(G_OBJECT(subject_entry), "changed",
-                        G_CALLBACK(compose_changed_cb), compose);
+                       G_CALLBACK(compose_changed_cb), compose);
+       g_signal_connect(G_OBJECT(subject_entry), "activate",
+                       G_CALLBACK(compose_subject_entry_activated), compose);
 
        /* drag and drop */
        gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 
@@ -7375,6 +7700,9 @@ static Compose *compose_create(PrefsAccount *account,
        g_signal_connect(G_OBJECT(text), "drag-drop",
                         G_CALLBACK(compose_drag_drop),
                         compose);
+       g_signal_connect(G_OBJECT(text), "key-press-event",
+                        G_CALLBACK(completion_set_focus_to_subject),
+                        compose);
        gtk_widget_show_all(vbox);
 
        /* pane between attach clist and text */
@@ -7521,7 +7849,7 @@ static Compose *compose_create(PrefsAccount *account,
                        }
                }
        }
-        compose->gtkaspell = gtkaspell;
+       compose->gtkaspell = gtkaspell;
        compose_spell_menu_changed(compose);
        claws_spell_entry_set_gtkaspell(CLAWS_SPELL_ENTRY(subject_entry), gtkaspell);
 #endif
@@ -7548,8 +7876,9 @@ 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
        addressbook_set_target_compose(compose);
-       
+#endif 
        if (mode != COMPOSE_REDIRECT)
                compose_set_template_menu(compose);
        else {
@@ -7662,6 +7991,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        CLAWS_SET_TIP(from_name,
                _("Sender address to be used"));
 
+       compose->account_combo = optmenu;
        compose->from_name = from_name;
        
        return hbox;
@@ -7758,7 +8088,7 @@ static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
 
        cm_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
 
-       if (!GTK_CHECK_MENU_ITEM(widget)->active)
+       if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
                return;
 
        systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
@@ -7781,7 +8111,7 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
 {
        static gchar *branch_path = "/Menu/Options/PrivacySystem";
        GtkWidget *menuitem = NULL;
-       GList *amenu;
+       GList *children, *amenu;
        gboolean can_sign = FALSE, can_encrypt = FALSE;
        gboolean found = FALSE;
 
@@ -7791,11 +8121,10 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
                                gtk_ui_manager_get_widget(compose->ui_manager, branch_path)));
                cm_return_if_fail(menuitem != NULL);
 
-               amenu = GTK_MENU_SHELL(menuitem)->children;
+               children = gtk_container_get_children(GTK_CONTAINER(GTK_MENU_SHELL(menuitem)));
+               amenu = children;
                menuitem = NULL;
                while (amenu != NULL) {
-                       GList *alist = amenu->next;
-
                        systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
                        if (systemid != NULL) {
                                if (strcmp(systemid, compose->privacy_system) == 0 &&
@@ -7817,8 +8146,9 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
                                        break;
                        }
 
-                       amenu = alist;
+                       amenu = amenu->next;
                }
+               g_list_free(children);
                if (menuitem != NULL)
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
                
@@ -7863,6 +8193,7 @@ static void compose_set_out_encoding(Compose *compose)
                case C_ISO_2022_JP_2: branch = "Menu/Options/Encoding/Japanese/" CS_ISO_2022_JP_2; break;
                case C_EUC_JP: branch = "Menu/Options/Encoding/Japanese/" CS_EUC_JP; break;
                case C_SHIFT_JIS: branch = "Menu/Options/Encoding/Japanese/" CS_SHIFT_JIS; break;
+               case C_GB18030: branch = "Menu/Options/Encoding/Chinese/" CS_GB18030; break;
                case C_GB2312: branch = "Menu/Options/Encoding/Chinese/" CS_GB2312; break;
                case C_GBK: branch = "Menu/Options/Encoding/Chinese/" CS_GBK; break;
                case C_BIG5: branch = "Menu/Options/Encoding/Chinese/" CS_BIG5; break;
@@ -8107,7 +8438,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
        compose_changed_cb(NULL, compose);
 
 #ifdef USE_ENCHANT
-       if (compose->gtkaspell->check_while_typing)
+       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -8223,6 +8554,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
 static void compose_destroy(Compose *compose)
 {
+       GtkAllocation allocation;
        GtkTextBuffer *buffer;
        GtkClipboard *clipboard;
 
@@ -8237,12 +8569,14 @@ static void compose_destroy(Compose *compose)
         * however this may change. */
        address_completion_end(compose->window);
 
-       slist_free_strings(compose->to_list);
-       g_slist_free(compose->to_list);
-       slist_free_strings(compose->newsgroup_list);
-       g_slist_free(compose->newsgroup_list);
-       slist_free_strings(compose->header_list);
-       g_slist_free(compose->header_list);
+       slist_free_strings_full(compose->to_list);
+       slist_free_strings_full(compose->newsgroup_list);
+       slist_free_strings_full(compose->header_list);
+
+       slist_free_strings_full(extra_headers);
+       extra_headers = NULL;
+
+       compose->header_list = compose->newsgroup_list = compose->to_list = NULL;
 
        g_hash_table_destroy(compose->email_hashtable);
 
@@ -8275,9 +8609,10 @@ static void compose_destroy(Compose *compose)
 
        g_free(compose->privacy_system);
 
+#ifndef USE_NEW_ADDRBOOK
        if (addressbook_get_target_compose() == compose)
                addressbook_set_target_compose(NULL);
-
+#endif
 #if USE_ENCHANT
         if (compose->gtkaspell) {
                gtkaspell_delete(compose->gtkaspell);
@@ -8286,8 +8621,9 @@ static void compose_destroy(Compose *compose)
 #endif
 
        if (!compose->batch) {
-               prefs_common.compose_width = compose->scrolledwin->allocation.width;
-               prefs_common.compose_height = compose->window->allocation.height;
+               gtk_widget_get_allocation(compose->window, &allocation);
+               prefs_common.compose_width = allocation.width;
+               prefs_common.compose_height = allocation.height;
        }
 
        if (!gtk_widget_get_parent(compose->paned))
@@ -8301,7 +8637,7 @@ static void compose_destroy(Compose *compose)
        gtk_widget_destroy(compose->window);
        toolbar_destroy(compose->toolbar);
        g_free(compose->toolbar);
-       g_mutex_free(compose->mutex);
+       cm_mutex_free(compose->mutex);
        g_free(compose);
 }
 
@@ -8310,6 +8646,7 @@ static void compose_attach_info_free(AttachInfo *ainfo)
        g_free(ainfo->file);
        g_free(ainfo->content_type);
        g_free(ainfo->name);
+       g_free(ainfo->charset);
        g_free(ainfo);
 }
 
@@ -8429,7 +8766,8 @@ static void compose_attach_property(GtkAction *action, gpointer data)
        gtk_window_set_modal(GTK_WINDOW(attach_prop.window), TRUE);
        gtk_widget_grab_focus(attach_prop.ok_btn);
        gtk_widget_show(attach_prop.window);
-       manage_window_set_transient(GTK_WINDOW(attach_prop.window));
+       gtk_window_set_transient_for(GTK_WINDOW(attach_prop.window),
+                       GTK_WINDOW(compose->window));
 
        optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
        if (ainfo->encoding == ENC_UNKNOWN)
@@ -8514,6 +8852,7 @@ static void compose_attach_property(GtkAction *action, gpointer data)
                                   COL_MIMETYPE, ainfo->content_type,
                                   COL_SIZE, text,
                                   COL_NAME, ainfo->name,
+                                  COL_CHARSET, ainfo->charset,
                                   -1);
                
                break;
@@ -8578,7 +8917,11 @@ static void compose_attach_property_create(gboolean *cancelled)
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1), 
                         GTK_FILL, 0, 0, 0); 
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); 
+#if !GTK_CHECK_VERSION(2, 24, 0)
        mimetype_entry = gtk_combo_box_entry_new_text(); 
+#else
+       mimetype_entry = gtk_combo_box_text_new_with_entry();
+#endif
        gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1), 
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
                         
@@ -8600,7 +8943,11 @@ static void compose_attach_property_create(gboolean *cancelled)
 
        for (mime_type_list = strlist; mime_type_list != NULL; 
                mime_type_list = mime_type_list->next) {
+#if !GTK_CHECK_VERSION(2, 24, 0)
                gtk_combo_box_append_text(GTK_COMBO_BOX(mimetype_entry), mime_type_list->data);
+#else
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mimetype_entry), mime_type_list->data);
+#endif
                g_free(mime_type_list->data);
        }
        g_list_free(strlist);
@@ -8681,11 +9028,11 @@ static gboolean attach_property_key_pressed(GtkWidget *widget,
                                            GdkEventKey *event,
                                            gboolean *cancelled)
 {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                *cancelled = TRUE;
                gtk_main_quit();
        }
-       if (event && event->keyval == GDK_Return) {
+       if (event && event->keyval == GDK_KEY_Return) {
                *cancelled = FALSE;
                gtk_main_quit();
                return TRUE;
@@ -8862,7 +9209,7 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
        Compose *compose = (Compose *)data;
        gsize bytes_read;
 
-       debug_print(_("Compose: input from monitoring process\n"));
+       debug_print("Compose: input from monitoring process\n");
 
        g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
 
@@ -8993,6 +9340,13 @@ static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
 
 /* callback functions */
 
+static void compose_notebook_size_alloc(GtkNotebook *notebook,
+                                       GtkAllocation *allocation,
+                                       Compose *compose)
+{
+       prefs_common.compose_notebook_height = allocation->height;
+}
+
 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
  * includes "non-client" (windows-izm) in calculation, so this calculation
  * may not be accurate.
@@ -9011,16 +9365,15 @@ static gboolean compose_edit_size_alloc(GtkEditable *widget,
                        (allocation->width - allocation->x) / char_width;
 
                /* got the maximum */
-               gtk_ruler_set_range(GTK_RULER(shruler),
-                                   0.0, line_width_in_chars, 0,
-                                   /*line_width_in_chars*/ char_width);
+               gtk_shruler_set_range(GTK_SHRULER(shruler),
+                                   0.0, line_width_in_chars, 0);
        }
 
        return TRUE;
 }
 
 typedef struct {
-       ComposeEntryType        header;
+       gchar                   *header;
        gchar                   *entry;
        ComposePrefType         type;
        gboolean                entry_marked;
@@ -9038,8 +9391,12 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
        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);
@@ -9061,18 +9418,20 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                        }
                        
                        state = g_malloc0(sizeof(HeaderEntryState));
-                       state->header = combobox_get_active_data(
-                                       GTK_COMBO_BOX(hentry->combo));
+                       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,
@@ -9103,12 +9462,14 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                for (list = saved_list; list; list = list->next) {
                        state = (HeaderEntryState *) list->data;
                        
-                       compose_entry_append(compose, state->entry,
-                                               state->header, state->type);
+                       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->entry);
+                       g_free(state);
                }
                g_slist_free(saved_list);
                
@@ -9152,14 +9513,8 @@ static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
                attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
                attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
                        
-               if (attach_nr_selected > 0)
-               {
-                       cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Remove", TRUE);
-                       cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Properties", TRUE);
-               } else {
-                       cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Remove", FALSE);
-                       cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Properties", FALSE);
-               }
+               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));
                        
                gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
                               NULL, NULL, event->button, event->time);
@@ -9177,7 +9532,7 @@ static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
        if (!event) return FALSE;
 
        switch (event->keyval) {
-       case GDK_Delete:
+       case GDK_KEY_Delete:
                compose_attach_remove_selected(NULL, compose);
                break;
        }
@@ -9203,7 +9558,7 @@ static void compose_allow_user_actions (Compose *compose, gboolean allow)
 static void compose_send_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
-       
+
        if (prefs_common.work_offline && 
            !inc_offline_should_override(TRUE,
                _("Claws Mail needs network access in order "
@@ -9272,6 +9627,7 @@ gboolean compose_draft (gpointer data, guint action)
        Compose *compose = (Compose *)data;
        FolderItem *draft;
        gchar *tmp;
+       gchar *sheaders;
        gint msgnum;
        MsgFlags flag = {0, 0};
        static gboolean lock = FALSE;
@@ -9352,6 +9708,10 @@ gboolean compose_draft (gpointer data, guint action)
        err |= (fprintf(fp, "X-Claws-Auto-Wrapping:%d\n", compose->autowrap) < 0);
        err |= (fprintf(fp, "X-Claws-Auto-Indent:%d\n", compose->autoindent) < 0);
 
+       sheaders = compose_get_manual_headers_info(compose);
+       err |= (fprintf(fp, "X-Claws-Manual-Headers:%s\n", sheaders) < 0);
+       g_free(sheaders);
+
        /* end of headers */
        err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
 
@@ -9541,7 +9901,7 @@ void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_
                for ( tmp = file_list; tmp; tmp = tmp->next) {
                        gchar *file = (gchar *) tmp->data;
                        gchar *utf8_filename = conv_filename_to_utf8(file);
-                       compose_attach_append(compose, file, utf8_filename, NULL);
+                       compose_attach_append(compose, file, utf8_filename, NULL, NULL);
                        compose_changed_cb(NULL, compose);
                        if (free_data) {
                        g_free(file);
@@ -9560,6 +9920,10 @@ static void compose_attach_cb(GtkAction *action, gpointer data)
        if (compose->redirect_filename != NULL)
                return;
 
+       /* Set focus_window properly, in case we were called via popup menu,
+        * 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"));
 
        if (file_list) {
@@ -9604,7 +9968,8 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data)
        }
 
 #ifdef USE_ENCHANT     
-       if (files_inserted > 0 && compose->gtkaspell->check_while_typing)
+       if (files_inserted > 0 && compose->gtkaspell && 
+                   compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -9686,6 +10051,15 @@ static void compose_close_cb(GtkAction *action, gpointer data)
        compose_close(compose);
 }
 
+static void compose_print_cb(GtkAction *action, gpointer data)
+{
+       Compose *compose = (Compose *) data;
+
+       compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
+       if (compose->targetinfo)
+               messageview_print(compose->targetinfo, FALSE, -1, -1, 0);
+}
+
 static void compose_set_encoding_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
 {
        gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current));
@@ -9700,7 +10074,17 @@ static void compose_address_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
+#ifndef USE_NEW_ADDRBOOK
        addressbook_open(compose);
+#else
+       GError* error = NULL;
+       addressbook_connect_signals(compose);
+       addressbook_dbus_open(TRUE, &error);
+       if (error) {
+               g_warning("%s", error->message);
+               g_error_free(error);
+       }
+#endif
 }
 
 static void about_show_cb(GtkAction *action, gpointer data)
@@ -9718,7 +10102,7 @@ static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
        tmpl = g_object_get_data(G_OBJECT(widget), "template");
        cm_return_if_fail(tmpl != NULL);
 
-       msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
+       msg = g_strdup_printf(_("Do you want to apply the template '%s'?"),
                              tmpl->name);
        val = alertpanel(_("Apply template"), msg,
                         _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
@@ -9856,7 +10240,7 @@ static void compose_cut_cb(GtkAction *action, gpointer data)
        Compose *compose = (Compose *)data;
        if (compose->focused_editable 
 #ifndef GENERIC_UMPC
-           && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
+           && gtk_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_cut_clipboard(compose->focused_editable);
@@ -9867,7 +10251,7 @@ static void compose_copy_cb(GtkAction *action, gpointer data)
        Compose *compose = (Compose *)data;
        if (compose->focused_editable 
 #ifndef GENERIC_UMPC
-           && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
+           && gtk_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_copy_clipboard(compose->focused_editable);
@@ -9880,15 +10264,22 @@ static void compose_paste_cb(GtkAction *action, gpointer data)
        GtkTextBuffer *buffer;
        BLOCK_WRAP();
        if (compose->focused_editable &&
-           GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
+#ifndef GENERIC_UMPC
+           gtk_widget_has_focus(compose->focused_editable)
+#endif
+               )
                entry_paste_clipboard(compose, compose->focused_editable, 
                                prefs_common.linewrap_pastes,
                                GDK_SELECTION_CLIPBOARD, NULL);
        UNBLOCK_WRAP();
 
 #ifdef USE_ENCHANT
-       if (GTK_WIDGET_HAS_FOCUS(compose->text) &&
-           compose->gtkaspell->check_while_typing)
+       if (
+#ifndef GENERIC_UMPC
+               gtk_widget_has_focus(compose->text) &&
+#endif
+           compose->gtkaspell && 
+            compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -9899,7 +10290,7 @@ static void compose_paste_as_quote_cb(GtkAction *action, gpointer data)
        gint wrap_quote = prefs_common.linewrap_quote;
        if (compose->focused_editable 
 #ifndef GENERIC_UMPC
-           && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
+           && gtk_widget_has_focus(compose->focused_editable)
 #endif
            ) {
                /* let text_insert() (called directly or at a later time
@@ -9928,7 +10319,7 @@ static void compose_paste_no_wrap_cb(GtkAction *action, gpointer data)
        BLOCK_WRAP();
        if (compose->focused_editable 
 #ifndef GENERIC_UMPC
-           && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
+           && gtk_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_paste_clipboard(compose, compose->focused_editable, FALSE,
@@ -9936,8 +10327,12 @@ static void compose_paste_no_wrap_cb(GtkAction *action, gpointer data)
        UNBLOCK_WRAP();
 
 #ifdef USE_ENCHANT
-       if (GTK_WIDGET_HAS_FOCUS(compose->text) &&
-           compose->gtkaspell->check_while_typing)
+       if (
+#ifndef GENERIC_UMPC
+               gtk_widget_has_focus(compose->text) &&
+#endif
+           compose->gtkaspell && 
+            compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -9950,7 +10345,7 @@ static void compose_paste_wrap_cb(GtkAction *action, gpointer data)
        BLOCK_WRAP();
        if (compose->focused_editable 
 #ifndef GENERIC_UMPC
-           && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
+           && gtk_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_paste_clipboard(compose, compose->focused_editable, TRUE,
@@ -9958,8 +10353,12 @@ static void compose_paste_wrap_cb(GtkAction *action, gpointer data)
        UNBLOCK_WRAP();
 
 #ifdef USE_ENCHANT
-       if (GTK_WIDGET_HAS_FOCUS(compose->text) &&
-           compose->gtkaspell->check_while_typing)
+       if (
+#ifndef GENERIC_UMPC
+               gtk_widget_has_focus(compose->text) &&
+#endif
+           compose->gtkaspell &&
+            compose->gtkaspell->check_while_typing)
                gtkaspell_highlight_all(compose->gtkaspell);
 #endif
 }
@@ -9969,7 +10368,7 @@ static void compose_allsel_cb(GtkAction *action, gpointer data)
        Compose *compose = (Compose *)data;
        if (compose->focused_editable 
 #ifndef GENERIC_UMPC
-           && GTK_WIDGET_HAS_FOCUS(compose->focused_editable)
+           && gtk_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_allsel(compose->focused_editable);
@@ -10044,14 +10443,12 @@ static void textview_move_backward_word (GtkTextView *text)
        GtkTextBuffer *buffer;
        GtkTextMark *mark;
        GtkTextIter ins;
-       gint count;
 
        cm_return_if_fail(GTK_IS_TEXT_VIEW(text));
 
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
        mark = gtk_text_buffer_get_insert(buffer);
        gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
-       count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
        if (gtk_text_iter_backward_word_starts(&ins, 1))
                gtk_text_buffer_place_cursor(buffer, &ins);
 }
@@ -10273,7 +10670,7 @@ static void compose_advanced_action_cb(GtkAction *gaction, gpointer data)
                {textview_delete_to_line_end}
        };
 
-       if (!GTK_WIDGET_HAS_FOCUS(text)) return;
+       if (!gtk_widget_has_focus(GTK_WIDGET(text))) return;
 
        if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
            action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
@@ -10286,6 +10683,8 @@ static void compose_advanced_action_cb(GtkAction *gaction, gpointer data)
 
 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
 {
+       GtkAllocation allocation;
+       GtkWidget *parent;
        gchar *str = NULL;
        
        if (GTK_IS_EDITABLE(widget)) {
@@ -10293,24 +10692,29 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
                gtk_editable_set_position(GTK_EDITABLE(widget), 
                        strlen(str));
                g_free(str);
-               if (widget->parent && widget->parent->parent
-                && widget->parent->parent->parent) {
-                       if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
-                               gint y = widget->allocation.y;
-                               gint height = widget->allocation.height;
+               if ((parent = gtk_widget_get_parent(widget))
+                && (parent = gtk_widget_get_parent(parent))
+                && (parent = gtk_widget_get_parent(parent))) {
+                       if (GTK_IS_SCROLLED_WINDOW(parent)) {
+                               gtk_widget_get_allocation(widget, &allocation);
+                               gint y = allocation.y;
+                               gint height = allocation.height;
                                GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
-                                       (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
+                                       (GTK_SCROLLED_WINDOW(parent));
 
-                               if (y < (int)shown->value) {
-                                       gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
+                               gfloat value = gtk_adjustment_get_value(shown);
+                               gfloat upper = gtk_adjustment_get_upper(shown);
+                               gfloat page_size = gtk_adjustment_get_page_size(shown);
+                               if (y < (int)value) {
+                                       gtk_adjustment_set_value(shown, y - 1);
                                }
-                               if (y + height > (int)shown->value + (int)shown->page_size) {
-                                       if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
-                                               gtk_adjustment_set_value(GTK_ADJUSTMENT(shown)
-                                                       y + height - (int)shown->page_size - 1);
+                               if ((y + height) > ((int)value + (int)page_size)) {
+                                       if ((y - height - 1) < ((int)upper - (int)page_size)) {
+                                               gtk_adjustment_set_value(shown
+                                                       y + height - (int)page_size - 1);
                                        } else {
-                                               gtk_adjustment_set_value(GTK_ADJUSTMENT(shown)
-                                                       (int)shown->upper - (int)shown->page_size - 1);
+                                               gtk_adjustment_set_value(shown
+                                                       (int)upper - (int)page_size - 1);
                                        }
                                }
                        }
@@ -10451,19 +10855,22 @@ static void compose_attach_drag_received_cb (GtkWidget                *widget,
 {
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
+       GdkAtom type;
 
-       if (((gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list"))
+       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(data->type) && !strcmp(gdk_atom_name(data->type), "DROPFILES_DND"))
+        || (gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "DROPFILES_DND"))
 #endif
           ) && gtk_drag_get_source_widget(context) != 
                summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
-               list = uri_list_extract_filenames((const gchar *)data->data);
+               list = uri_list_extract_filenames(
+                       (const gchar *)gtk_selection_data_get_data(data));
                for (tmp = list; tmp != NULL; tmp = tmp->next) {
                        gchar *utf8_filename = conv_filename_to_utf8((const gchar *)tmp->data);
                        compose_attach_append
                                (compose, (const gchar *)tmp->data,
-                                utf8_filename, NULL);
+                                utf8_filename, NULL, NULL);
                        g_free(utf8_filename);
                }
                if (list) compose_changed_cb(NULL, compose);
@@ -10489,7 +10896,7 @@ static void compose_attach_drag_received_cb (GtkWidget          *widget,
                                        TRUE, TRUE);
                        if (file) {
                                compose_attach_append(compose, (const gchar *)file, 
-                                       (const gchar *)file, "message/rfc822");
+                                       (const gchar *)file, "message/rfc822", NULL);
                                g_free(file);
                        }
                }
@@ -10507,6 +10914,21 @@ static gboolean compose_drag_drop(GtkWidget *widget,
        return TRUE;                                     
 }
 
+static gboolean completion_set_focus_to_subject
+                                       (GtkWidget    *widget,
+                                        GdkEventKey  *event,
+                                        Compose      *compose)
+{
+       cm_return_val_if_fail(compose != NULL, FALSE);
+
+       /* make backtab move to subject field */
+       if(event->keyval == GDK_KEY_ISO_Left_Tab) {
+               gtk_widget_grab_focus(compose->subject_entry);
+               return TRUE;
+       }
+       return FALSE;
+}
+
 static void compose_insert_drag_received_cb (GtkWidget         *widget,
                                             GdkDragContext     *drag_context,
                                             gint                x,
@@ -10518,20 +10940,23 @@ static void compose_insert_drag_received_cb (GtkWidget                *widget,
 {
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
+       GdkAtom type;
 
        /* 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(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+       if (gdk_atom_name(type) && !strcmp(gdk_atom_name(type), "text/uri-list")) {
 #else
-       if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "DROPFILES_DND")) {
+       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((const gchar *)data->data);
-               if (list == NULL && strstr((gchar *)(data->data), "://")) {
+               list = uri_list_extract_filenames(ddata);
+               if (list == NULL && strstr(ddata, "://")) {
                        /* Assume a list of no files, and data has ://, is a remote link */
-                       gchar *tmpdata = g_strstrip(g_strdup((const gchar *)data->data));
+                       gchar *tmpdata = g_strstrip(g_strdup(ddata));
                        gchar *tmpfile = get_tmp_file();
                        str_write_to_file(tmpdata, tmpfile);
                        g_free(tmpdata);  
@@ -10590,16 +11015,6 @@ static void compose_insert_drag_received_cb (GtkWidget         *widget,
                gtk_drag_finish(drag_context, TRUE, FALSE, time);
                return;
        } else {
-#if GTK_CHECK_VERSION(2, 8, 0)
-               /* do nothing, handled by GTK */
-#else
-               gchar *tmpfile = get_tmp_file();
-               str_write_to_file((const gchar *)data->data, tmpfile);
-               compose_insert_file(compose, tmpfile);
-               claws_unlink(tmpfile);
-               g_free(tmpfile);
-               gtk_drag_finish(drag_context, TRUE, FALSE, time);
-#endif
                return;
        }
        gtk_drag_finish(drag_context, TRUE, FALSE, time);
@@ -10615,7 +11030,7 @@ static void compose_header_drag_received_cb (GtkWidget          *widget,
                                             gpointer            user_data)
 {
        GtkEditable *entry = (GtkEditable *)user_data;
-       gchar *email = (gchar *)data->data;
+       const gchar *email = (const gchar *)gtk_selection_data_get_data(data);
 
        /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
         * does not work */
@@ -10624,8 +11039,7 @@ static void compose_header_drag_received_cb (GtkWidget          *widget,
                gchar *decoded=g_new(gchar, strlen(email));
                int start = 0;
 
-               email += strlen("mailto:");
-               decode_uri(decoded, email); /* will fit */
+               decode_uri(decoded, email + strlen("mailto:")); /* will fit */
                gtk_editable_delete_text(entry, 0, -1);
                gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
                gtk_drag_finish(drag_context, TRUE, FALSE, time);
@@ -10669,7 +11083,7 @@ static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
        if ((g_slist_length(headerentry->compose->header_list) > 0) &&
            ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
            !(event->state & GDK_MODIFIER_MASK) &&
-           (event->keyval == GDK_BackSpace) &&
+           (event->keyval == GDK_KEY_BackSpace) &&
            (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
                gtk_container_remove
                        (GTK_CONTAINER(headerentry->compose->header_table),
@@ -10681,7 +11095,7 @@ static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
                        g_slist_remove(headerentry->compose->header_list,
                                       headerentry);
                g_free(headerentry);
-       } else  if (event->keyval == GDK_Tab) {
+       } else  if (event->keyval == GDK_KEY_Tab) {
                if (headerentry->compose->header_last == headerentry) {
                        /* Override default next focus, and give it to subject_entry
                         * instead of notebook tabs
@@ -10694,7 +11108,18 @@ static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
        return FALSE;
 }
 
-static gboolean compose_headerentry_changed_cb(GtkWidget *entry,
+static gboolean scroll_postpone(gpointer data)
+{
+       Compose *compose = (Compose *)data;
+
+       cm_return_val_if_fail(!compose->batch, FALSE);
+
+       GTK_EVENTS_FLUSH();
+       compose_show_first_last_header(compose, FALSE);
+       return FALSE;
+}
+
+static void compose_headerentry_changed_cb(GtkWidget *entry,
                                    ComposeHeaderEntry *headerentry)
 {
        if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
@@ -10702,12 +11127,16 @@ static gboolean compose_headerentry_changed_cb(GtkWidget *entry,
                g_signal_handlers_disconnect_matched
                        (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
                         0, 0, NULL, NULL, headerentry);
-               
-               /* Automatically scroll down */
-               GTK_EVENTS_FLUSH();
-               compose_show_first_last_header(headerentry->compose, FALSE);
-               
+
+               if (!headerentry->compose->batch)
+                       g_timeout_add(0, scroll_postpone, headerentry->compose);
        }
+}
+
+static gboolean compose_defer_auto_save_draft(Compose *compose)
+{
+       compose->draft_timeout_tag = -1;
+       compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
        return FALSE;
 }
 
@@ -10716,10 +11145,15 @@ 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);
        cm_return_if_fail(GTK_IS_WIDGET(compose->header_table));
-       cm_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
-       vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
-       gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : (vadj->upper - vadj->page_size)));
+       cm_return_if_fail(GTK_IS_VIEWPORT(gtk_widget_get_parent(compose->header_table)));
+       vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(
+                               gtk_widget_get_parent(compose->header_table)));
+       gtk_adjustment_set_value(vadj, (show_first ?
+                               gtk_adjustment_get_lower(vadj) :
+                               (gtk_adjustment_get_upper(vadj) -
+                               gtk_adjustment_get_page_size(vadj))));
        gtk_adjustment_changed(vadj);
 }
 
@@ -10824,13 +11258,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
            gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0 &&
            compose->draft_timeout_tag != -2 /* disabled while loading */)
                compose->draft_timeout_tag = g_timeout_add
-                       (500, (GtkFunction) compose_defer_auto_save_draft, compose);
-}
-static gint compose_defer_auto_save_draft(Compose *compose)
-{
-       compose->draft_timeout_tag = -1;
-       compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
-       return FALSE;
+                       (500, (GSourceFunc) compose_defer_auto_save_draft, compose);
 }
 
 #if USE_ENCHANT
@@ -10840,7 +11268,7 @@ static void compose_check_all(GtkAction *action, gpointer data)
        if (!compose->gtkaspell)
                return;
                
-       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+       if (gtk_widget_has_focus(compose->subject_entry))
                claws_spell_entry_check_all(
                        CLAWS_SPELL_ENTRY(compose->subject_entry));             
        else
@@ -10865,7 +11293,7 @@ static void compose_check_backwards(GtkAction *action, gpointer data)
                return;
        }
 
-       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+       if (gtk_widget_has_focus(compose->subject_entry))
                claws_spell_entry_check_backwards(
                        CLAWS_SPELL_ENTRY(compose->subject_entry));
        else
@@ -10880,7 +11308,7 @@ static void compose_check_forwards_go(GtkAction *action, gpointer data)
                return;
        }
 
-       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+       if (gtk_widget_has_focus(compose->subject_entry))
                claws_spell_entry_check_forwards_go(
                        CLAWS_SPELL_ENTRY(compose->subject_entry));
        else
@@ -11035,6 +11463,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
        }
        g_free(s_system);
        g_free(body);
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
 }
 
 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list, 
@@ -11072,6 +11501,51 @@ void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
        }
 }
 
+void compose_check_for_email_account(Compose *compose)
+{
+       PrefsAccount *ac = NULL, *curr = NULL;
+       GList *list;
+       
+       if (!compose)
+               return;
+
+       if (compose->account && compose->account->protocol == A_NNTP) {
+               ac = account_get_cur_account();
+               if (ac->protocol == A_NNTP) {
+                       list = account_get_list();
+                       
+                       for( ; list != NULL ; list = g_list_next(list)) {
+                               curr = (PrefsAccount *) list->data;
+                               if (curr->protocol != A_NNTP) {
+                                       ac = curr;
+                                       break;
+                               }
+                       }
+               }
+               combobox_select_by_data(GTK_COMBO_BOX(compose->account_combo),
+                                       ac->account_id); 
+       }
+}
+
+void compose_reply_to_address(MessageView *msgview, MsgInfo *msginfo, 
+                               const gchar *address)
+{
+       GSList *msginfo_list = NULL;
+       gchar *body =  messageview_get_selection(msgview);
+       Compose *compose;
+       
+       msginfo_list = g_slist_prepend(msginfo_list, msginfo);
+       
+       compose = compose_reply_mode(COMPOSE_REPLY_TO_ADDRESS, msginfo_list, body);
+       compose_check_for_email_account(compose);
+       compose_set_folder_prefs(compose, msginfo->folder, FALSE);
+       compose_entry_append(compose, address, COMPOSE_TO, PREF_NONE);
+       compose_reply_set_subject(compose, msginfo);
+
+       g_free(body);
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+}
+
 void compose_set_position(Compose *compose, gint pos)
 {
        GtkTextView *text = GTK_TEXT_VIEW(compose->text);
@@ -11189,6 +11663,15 @@ static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
 }
 #endif
 
+static void compose_subject_entry_activated(GtkWidget *widget, gpointer data)
+{
+       Compose *compose = (Compose *)data;
+
+       cm_return_if_fail(compose != NULL);
+
+       gtk_widget_grab_focus(compose->text);
+}
+
 /*
  * End of Source.
  */