2011-10-07 [colin] 3.7.10cvs21
[claws.git] / src / compose.c
index 0a445fd2502f32cfb8df1406474ebd17b6f403ea..f228edbee4b2e3c344a2b6707619eeee84c798d7 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-2011 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
@@ -86,7 +86,9 @@
 #include "socket.h"
 #include "alertpanel.h"
 #include "manage_window.h"
+#if !GTK_CHECK_VERSION(3, 0, 0)
 #include "gtkshruler.h"
+#endif
 #include "folder.h"
 #include "addr_compl.h"
 #include "quote_fmt.h"
@@ -107,8 +109,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
 };
 
@@ -162,6 +165,13 @@ typedef enum
        COMPOSE_QUOTE_SKIP
 } ComposeQuoteMode;
 
+typedef enum {
+    TO_FIELD_PRESENT,
+    SUBJECT_FIELD_PRESENT,
+    BODY_FIELD_PRESENT,
+    NO_FIELD_PRESENT
+} MailField;
+
 #define B64_LINE_SIZE          57
 #define B64_BUFFSIZE           77
 
@@ -207,7 +217,7 @@ static void compose_set_out_encoding                (Compose        *compose);
 static void compose_set_template_menu          (Compose        *compose);
 static void compose_destroy                    (Compose        *compose);
 
-static void compose_entries_set                        (Compose        *compose,
+static MailField compose_entries_set           (Compose        *compose,
                                                 const gchar    *mailto,
                                                 ComposeEntryType to_type);
 static gint compose_parse_header               (Compose        *compose,
@@ -242,7 +252,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);
 
@@ -294,6 +305,9 @@ static void compose_attach_info_free                (AttachInfo     *ainfo);
 static void compose_attach_remove_selected     (GtkAction      *action,
                                                 gpointer        data);
 
+static void compose_template_apply             (Compose        *compose,
+                                                Template       *tmpl,
+                                                gboolean        replace);
 static void compose_attach_property            (GtkAction      *action,
                                                 gpointer        data);
 static void compose_attach_property_create     (gboolean       *cancelled);
@@ -325,7 +339,8 @@ static void compose_undo_state_changed              (UndoMain       *undostruct,
                                                 gpointer        data);
 
 static void compose_create_header_entry        (Compose *compose);
-static void compose_add_header_entry   (Compose *compose, const gchar *header, gchar *text);
+static void compose_add_header_entry   (Compose *compose, const gchar *header,
+                                        gchar *text, ComposePrefType pref_type);
 static void compose_remove_header_entries(Compose *compose);
 
 static void compose_update_priority_menu_item(Compose * compose);
@@ -338,9 +353,11 @@ static void compose_add_field_list ( Compose *compose,
 
 /* callback functions */
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
 static gboolean compose_edit_size_alloc (GtkEditable   *widget,
                                         GtkAllocation  *allocation,
                                         GtkSHRuler     *shruler);
+#endif
 static void account_activated          (GtkComboBox *optmenu,
                                         gpointer        data);
 static void attach_selected            (GtkTreeView    *tree_view, 
@@ -424,8 +441,10 @@ static void compose_toggle_autowrap_cb     (GtkToggleAction *action,
 static void compose_toggle_autoindent_cb(GtkToggleAction *action,
                                         gpointer        data);
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
 static void compose_toggle_ruler_cb    (GtkToggleAction *action,
                                         gpointer        data);
+#endif
 static void compose_toggle_sign_cb     (GtkToggleAction *action,
                                         gpointer        data);
 static void compose_toggle_encrypt_cb  (GtkToggleAction *action,
@@ -488,7 +507,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,
@@ -512,7 +531,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);
@@ -522,8 +540,8 @@ 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_attach_from_list(Compose *compose, GList *file_list, gboolean free_data);
+static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
+                                    gboolean respect_default_to);
 
 static GtkActionEntry compose_popup_entries[] =
 {
@@ -656,7 +674,9 @@ static GtkToggleActionEntry compose_toggle_entries[] =
        {"Options/Encrypt",             NULL, N_("_Encrypt"), NULL, NULL, G_CALLBACK(compose_toggle_encrypt_cb) }, /* Toggle */
        {"Options/RequestRetRcpt",      NULL, N_("_Request Return Receipt"), NULL, NULL, G_CALLBACK(compose_toggle_return_receipt_cb) }, /* TOGGLE */
        {"Options/RemoveReferences",    NULL, N_("Remo_ve references"), NULL, NULL, G_CALLBACK(compose_toggle_remove_refs_cb) }, /* TOGGLE */
+#if !GTK_CHECK_VERSION(3, 0, 0)
        {"Tools/ShowRuler",             NULL, N_("Show _ruler"), NULL, NULL, G_CALLBACK(compose_toggle_ruler_cb) }, /* Toggle */
+#endif
 };
 
 static GtkRadioActionEntry compose_radio_rm_entries[] =
@@ -701,6 +721,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 */
@@ -773,9 +794,11 @@ 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(3, 0, 0)
        GdkColormap *cmap;
-       GdkColor color[8];
        gboolean success[8];
+#endif
+       GdkColor color[8];
        int i;
 
        buffer = gtk_text_view_get_buffer(text);
@@ -846,7 +869,8 @@ 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);
+#if !GTK_CHECK_VERSION(3, 0, 0)
+       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++) {
@@ -860,6 +884,7 @@ static void compose_create_tags(GtkTextView *text, Compose *compose)
                                signature_color = uri_color = black;
                }
        }
+#endif
 }
 
 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
@@ -934,10 +959,14 @@ 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 */
@@ -974,7 +1003,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
@@ -1015,22 +1044,10 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
        if (account->protocol != A_NNTP) {
                if (mailto && *mailto != '\0') {
-                       compose_entries_set(compose, mailto, COMPOSE_TO);
+                       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);
-                       }
-                       if (item->prefs->enable_default_cc) {
-                               compose_entry_append(compose, item->prefs->default_cc, COMPOSE_CC);
-                       }
-                       if (item->prefs->enable_default_replyto) {
-                               compose_entry_append(compose, item->prefs->default_replyto, COMPOSE_REPLYTO);
-                       }
-                       if (item->prefs->enable_default_to) {
-                               compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
-                               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);
@@ -1038,11 +1055,12 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        } else {
                if (mailto && *mailto != '\0') {
                        if (!strchr(mailto, '@'))
-                               compose_entries_set(compose, mailto, COMPOSE_NEWSGROUPS);
+                               mfield = compose_entries_set(compose, mailto, COMPOSE_NEWSGROUPS);
                        else
-                               compose_entries_set(compose, mailto, COMPOSE_TO);
+                               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);
+                       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
@@ -1076,7 +1094,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);
@@ -1099,6 +1117,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                        g_free(subject);
                        g_free(tmp);
+                       mfield = SUBJECT_FIELD_PRESENT;
                }
 
                if ( body_format
@@ -1126,6 +1145,11 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        quote_fmt_reset_vartable();
 
                        g_free(tmp);
+#ifdef USE_ENCHANT
+                       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
+                               gtkaspell_highlight_all(compose->gtkaspell);
+#endif
+                       mfield = BODY_FIELD_PRESENT;
                }
 
        }
@@ -1137,7 +1161,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                for (i = 0; i < attach_files->len; i++) {
                        file = g_ptr_array_index(attach_files, i);
-                       compose_attach_append(compose, file, file, NULL);
+                       compose_attach_append(compose, file, file, NULL, NULL);
                }
        }
 
@@ -1152,8 +1176,47 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        }
-       
-       gtk_widget_grab_focus(compose->header_last->entry);
+
+       /* Place cursor according to provided input (mfield) */
+       switch (mfield) { 
+               case NO_FIELD_PRESENT:
+                       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);
+                       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);
+                   /* 
+                    * SUBJECT_FIELD_PRESENT and BODY_FIELD_PRESENT
+                    * only defers where it comes to the variable body
+                    * is not null. If no body is present compose->text
+                    * will be null in which case you cannot place the
+                    * cursor inside the component so. An empty component
+                    * is therefore created before placing the cursor
+                    */
+               case BODY_FIELD_PRESENT:
+                       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;
+       }
 
        undo_unblock(compose->undostruct);
 
@@ -1165,6 +1228,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;
 }
 
@@ -1249,6 +1315,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;
@@ -1360,6 +1427,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;
        }
@@ -1371,7 +1441,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);
@@ -1494,7 +1564,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
@@ -1558,6 +1628,10 @@ 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 && compose->gtkaspell->check_while_typing)
+                       gtkaspell_highlight_all(compose->gtkaspell);
+#endif
        }
 
        if (MSG_IS_ENCRYPTED(compose->replyinfo->flags)) {
@@ -1598,6 +1672,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                return NULL;
        }
        END_TIMING();
+
        return compose;
 }
 
@@ -1616,7 +1691,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);
@@ -1626,7 +1702,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);
@@ -1665,7 +1745,7 @@ 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
@@ -1701,7 +1781,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 {
@@ -1750,6 +1830,10 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                compose_attach_parts(compose, msginfo);
 
                procmsg_msginfo_free(full_msginfo);
+#ifdef USE_ENCHANT
+               if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
+                       gtkaspell_highlight_all(compose->gtkaspell);
+#endif
        }
 
        SIGNAL_BLOCK(textbuf);
@@ -1761,10 +1845,11 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
        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);
@@ -1793,6 +1878,8 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
         return compose;
 }
 
@@ -1854,7 +1941,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
@@ -1889,7 +1976,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);
        }
        
@@ -1939,6 +2026,8 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2045,7 +2134,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;
 
@@ -2182,7 +2272,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 */
@@ -2267,6 +2358,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;
 }
 
@@ -2343,7 +2436,9 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertSig", FALSE);
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit", FALSE);
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options", FALSE);
+#if !GTK_CHECK_VERSION(3, 0, 0)
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools/ShowRuler", FALSE);
+#endif
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools/Actions", FALSE);
        
        if (compose->toolbar->draft_btn)
@@ -2372,6 +2467,8 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
        
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2381,7 +2478,7 @@ GList *compose_get_compose_list(void)
 }
 
 void compose_entry_append(Compose *compose, const gchar *address,
-                         ComposeEntryType type)
+                         ComposeEntryType type, ComposePrefType pref_type)
 {
        const gchar *header;
        gchar *cur, *begin;
@@ -2404,6 +2501,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:");
@@ -2426,7 +2526,7 @@ void compose_entry_append(Compose *compose, const gchar *address,
                        begin = cur;
                        while (*tmp == ' ' || *tmp == '\t')
                                tmp++;
-                       compose_add_header_entry(compose, header, tmp);
+                       compose_add_header_entry(compose, header, tmp, pref_type);
                        g_free(o_tmp);
                        continue;
                }
@@ -2440,19 +2540,25 @@ void compose_entry_append(Compose *compose, const gchar *address,
                begin = cur;
                while (*tmp == ' ' || *tmp == '\t')
                        tmp++;
-               compose_add_header_entry(compose, header, tmp);
+               compose_add_header_entry(compose, header, tmp, pref_type);
                g_free(o_tmp);          
        }
 }
 
 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);
@@ -2461,19 +2567,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
                }
        }
 }
@@ -2526,7 +2637,7 @@ void compose_toolbar_cb(gint action, gpointer data)
        }
 }
 
-static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEntryType to_type)
+static MailField compose_entries_set(Compose *compose, const gchar *mailto, ComposeEntryType to_type)
 {
        gchar *to = NULL;
        gchar *cc = NULL;
@@ -2536,16 +2647,20 @@ static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEn
        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);
+       if (to) {
+               compose_entry_append(compose, to, to_type, PREF_MAILTO);
+               mfield = TO_FIELD_PRESENT;
+       }
        if (cc)
-               compose_entry_append(compose, cc, COMPOSE_CC);
+               compose_entry_append(compose, cc, COMPOSE_CC, PREF_MAILTO);
        if (bcc)
-               compose_entry_append(compose, bcc, COMPOSE_BCC);
+               compose_entry_append(compose, bcc, COMPOSE_BCC, PREF_MAILTO);
        if (subject) {
                if (!g_utf8_validate (subject, -1, NULL)) {
                        temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
@@ -2554,6 +2669,7 @@ static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEn
                } else {
                        gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
                }
+               mfield = SUBJECT_FIELD_PRESENT;
        }
        if (body) {
                GtkTextView *text = GTK_TEXT_VIEW(compose->text);
@@ -2579,6 +2695,7 @@ static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEn
                compose->autowrap = prev_autowrap;
                if (compose->autowrap)
                        compose_wrap_all(compose);
+               mfield = BODY_FIELD_PRESENT;
        }
 
        if (attach) {
@@ -2587,7 +2704,7 @@ static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEn
                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);
@@ -2608,12 +2725,18 @@ static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEn
                        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;
 }
 
 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
@@ -2652,13 +2775,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;
        }
@@ -2675,7 +2798,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;
        }
@@ -2687,18 +2810,21 @@ 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;
        }
        if (hentry[H_LIST_POST].body != NULL) {
-               gchar *to = NULL;
+               gchar *to = NULL, *start = NULL;
 
                extract_address(hentry[H_LIST_POST].body);
                if (hentry[H_LIST_POST].body[0] != '\0') {
-                       scan_mailto_url(hentry[H_LIST_POST].body,
-                                       NULL, &to, NULL, NULL, NULL, NULL, NULL);
+                       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);
+
                        if (to) {
                                g_free(compose->ml_post);
                                compose->ml_post = to;
@@ -2863,7 +2989,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();
@@ -2965,20 +3091,50 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from)
        return result;
 }
 
-static gboolean same_address(const gchar *addr1, const gchar *addr2)
+static void compose_set_folder_prefs(Compose *compose, FolderItem *folder,
+                                    gboolean respect_default_to)
 {
-       gchar *my_addr1, *my_addr2;
-       
-       if (!addr1 || !addr2)
-               return FALSE;
+       if (!compose)
+               return;
+       if (!folder || !folder->prefs)
+               return;
 
-       Xstrdup_a(my_addr1, addr1, return FALSE);
-       Xstrdup_a(my_addr2, addr2, return FALSE);
-       
-       extract_address(my_addr1);
-       extract_address(my_addr2);
+       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;
        
-       return !strcasecmp(my_addr1, my_addr2);
+       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,
@@ -2990,7 +3146,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        GSList *cur;
        gchar *from = NULL;
        gchar *replyto = NULL;
-       GHashTable *to_table;
+       gchar *ac_email = NULL;
 
        gboolean reply_to_ml = FALSE;
        gboolean default_reply_to = FALSE;
@@ -3004,17 +3160,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);
-                       }
-                       if (msginfo->folder->prefs->enable_default_bcc) {
-                               compose_entry_append(compose, msginfo->folder->prefs->default_bcc, COMPOSE_BCC);
-                       }
-                       if (msginfo->folder->prefs->enable_default_cc) {
-                               compose_entry_append(compose, msginfo->folder->prefs->default_cc, COMPOSE_CC);
-                       }
-               }
+               compose_set_folder_prefs(compose, msginfo->folder, FALSE);
+
                if (reply_to_ml && !default_reply_to) {
                        
                        gboolean is_subscr = is_subscription(compose->ml_post,
@@ -3023,28 +3170,27 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                /* normal answer to ml post with a reply-to */
                                compose_entry_append(compose,
                                           compose->ml_post,
-                                          COMPOSE_TO);
-                               if (compose->replyto
-                               &&  !same_address(compose->ml_post, compose->replyto))
+                                          COMPOSE_TO, PREF_ML);
+                               if (compose->replyto)
                                        compose_entry_append(compose,
                                                compose->replyto,
-                                               COMPOSE_CC);
+                                               COMPOSE_CC, PREF_ML);
                        } else {
                                /* answer to subscription confirmation */
                                if (compose->replyto)
                                        compose_entry_append(compose,
                                                compose->replyto,
-                                               COMPOSE_TO);
+                                               COMPOSE_TO, PREF_ML);
                                else if (msginfo->from)
                                        compose_entry_append(compose,
                                                msginfo->from,
-                                               COMPOSE_TO);
+                                               COMPOSE_TO, PREF_ML);
                        }
                }
                else if (!(to_all || to_sender) && default_reply_to) {
                        compose_entry_append(compose,
                            msginfo->folder->prefs->default_reply_to,
-                           COMPOSE_TO);
+                           COMPOSE_TO, PREF_FOLDER);
                        compose_entry_mark_default_to(compose,
                                msginfo->folder->prefs->default_reply_to);
                } else {
@@ -3059,7 +3205,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                 (compose->replyto && !to_sender)
                                          ? compose->replyto :
                                          msginfo->from ? msginfo->from : "",
-                                         COMPOSE_TO);
+                                         COMPOSE_TO, PREF_NONE);
                        else if (!to_all && !to_sender) {
                                if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
                                    !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
@@ -3067,20 +3213,20 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                        if (compose->replyto) {
                                                compose_entry_append(compose,
                                                        compose->replyto,
-                                                       COMPOSE_TO);
+                                                       COMPOSE_TO, PREF_NONE);
                                        } else {
                                                compose_entry_append(compose,
                                                          msginfo->from ? msginfo->from : "",
-                                                         COMPOSE_TO);
+                                                         COMPOSE_TO, PREF_NONE);
                                        }
                                } else {
                                        /* replying to own mail, use original recp */
                                        compose_entry_append(compose,
                                                  msginfo->to ? msginfo->to : "",
-                                                 COMPOSE_TO);
+                                                 COMPOSE_TO, PREF_NONE);
                                        compose_entry_append(compose,
                                                  msginfo->cc ? msginfo->cc : "",
-                                                 COMPOSE_CC);
+                                                 COMPOSE_CC, PREF_NONE);
                                }
                        }
                }
@@ -3091,44 +3237,29 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                (compose, 
                                 (compose->replyto ? compose->replyto :
                                        msginfo->from ? msginfo->from : ""),
-                                COMPOSE_TO);
+                                COMPOSE_TO, PREF_NONE);
                                 
                else if (followup_and_reply_to || to_all) {
                        compose_entry_append
                                (compose,
                                 (compose->replyto ? compose->replyto :
                                 msginfo->from ? msginfo->from : ""),
-                                COMPOSE_TO);                           
+                                COMPOSE_TO, PREF_NONE);                                
                
                        compose_entry_append
                                (compose,
                                 compose->followup_to ? compose->followup_to :
                                 compose->newsgroups ? compose->newsgroups : "",
-                                COMPOSE_NEWSGROUPS);
+                                COMPOSE_NEWSGROUPS, PREF_NONE);
                } 
                else 
                        compose_entry_append
                                (compose,
                                 compose->followup_to ? compose->followup_to :
                                 compose->newsgroups ? 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;
@@ -3151,39 +3282,27 @@ 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);
 
-       to_table = g_hash_table_new(g_str_hash, g_str_equal);
-       if (replyto)
-               g_hash_table_insert(to_table, g_utf8_strdown(replyto, -1), GINT_TO_POINTER(1));
-       if (compose->account) {
-               g_hash_table_insert(to_table, g_utf8_strdown(compose->account->address, -1),
-                                   GINT_TO_POINTER(1));
-       }
-       /* remove address on To: and that of current account */
-       for (cur = cc_list; cur != NULL; ) {
-               GSList *next = cur->next;
-               gchar *addr;
-
-               addr = g_utf8_strdown(cur->data, -1);
-               extract_address(addr);
-
-               if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
-                       cc_list = g_slist_remove(cc_list, cur->data);
-               else
-                       g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
-
-               cur = next;
-       }
-       hash_free_strings(to_table);
-       g_hash_table_destroy(to_table);
+       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);
+               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(cc_list);
                g_slist_free(cc_list);
        }
-
+       
+       g_free(ac_email);
 }
 
 #define SET_ENTRY(entry, str) \
@@ -3195,7 +3314,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
 #define SET_ADDRESS(type, str) \
 { \
        if (str && *str) \
-               compose_entry_append(compose, str, type); \
+               compose_entry_append(compose, str, type, PREF_NONE); \
 }
 
 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
@@ -3329,9 +3448,48 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        FILE *fp;
        gboolean prev_autowrap;
        gboolean badtxt = FALSE;
+       struct stat file_stat;
+       int ret;
 
        cm_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
 
+       /* get the size of the file we are about to insert */
+       ret = g_stat(file, &file_stat);
+       if (ret != 0) {
+               gchar *shortfile = g_path_get_basename(file);
+               alertpanel_error(_("Could not get size of file '%s'."), shortfile);
+               g_free(shortfile);
+               return COMPOSE_INSERT_NO_FILE;
+       } else if (prefs_common.warn_large_insert == TRUE) {
+
+               /* ask user for confirmation if the file is large */
+               if (prefs_common.warn_large_insert_size < 0 ||
+                   file_stat.st_size > (prefs_common.warn_large_insert_size * 1024)) {
+                       AlertValue aval;
+                       gchar *msg;
+
+                       msg = g_strdup_printf(_("You are about to insert a file of %s "
+                                               "in the message body. Are you sure you want to do that?"),
+                                               to_human_readable(file_stat.st_size));
+                       aval = alertpanel_full(_("Are you sure?"), msg, GTK_STOCK_CANCEL,
+                                       _("+_Insert"), NULL, TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
+                       g_free(msg);
+
+                       /* do we ask for confirmation next time? */
+                       if (aval & G_ALERTDISABLE) {
+                               /* no confirmation next time, disable feature in preferences */
+                               aval &= ~G_ALERTDISABLE;
+                               prefs_common.warn_large_insert = FALSE;
+                       }
+
+                       /* abort file insertion if user canceled action */
+                       if (aval != G_ALERTALTERNATE) {
+                               return COMPOSE_INSERT_NO_FILE;
+                       }
+               }
+       }
+
+
        if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return COMPOSE_INSERT_READ_ERROR;
@@ -3391,7 +3549,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;
@@ -3409,8 +3568,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)
@@ -3458,10 +3617,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);
                }
@@ -3472,7 +3633,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
@@ -3491,6 +3652,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;
@@ -3504,6 +3667,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);
@@ -3607,7 +3771,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);
                        }
@@ -4546,7 +4711,6 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
        cm_return_if_fail(account != NULL);
 
        compose->account = account;
-
        if (account->name && *account->name) {
                gchar *buf;
                QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
@@ -4641,13 +4805,13 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
                g_strstrip(header);
                if (entry[0] != '\0') {
                        for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
-                               if (!strcmp(header, prefs_common_translated_header_name(*strptr))) {
+                               if (!g_ascii_strcasecmp(header, prefs_common_translated_header_name(*strptr))) {
                                        compose->to_list = address_list_append(compose->to_list, entry);
                                        recipient_found = TRUE;
                                }
                        }
                        for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
-                               if (!strcmp(header, prefs_common_translated_header_name(*strptr))) {
+                               if (!g_ascii_strcasecmp(header, prefs_common_translated_header_name(*strptr))) {
                                        compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
                                        recipient_found = TRUE;
                                }
@@ -5062,7 +5226,11 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        }
 
        if (compose->account->gen_msgid) {
-               generate_msgid(buf, sizeof(buf));
+               gchar *addr = NULL;
+               if (compose->account->msgid_with_addr) {
+                       addr = compose->account->address;
+               }
+               generate_msgid(buf, sizeof(buf), addr);
                err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
                compose->msgid = g_strdup(buf);
        } else {
@@ -5837,24 +6005,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 && compose->mode == COMPOSE_FORWARD_INLINE) {
+                               /* 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);
 
@@ -6002,7 +6186,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);
@@ -6030,7 +6219,11 @@ static gchar *compose_get_header(Compose *compose)
        }
        
        if (compose->account->gen_msgid) {
-               generate_msgid(buf, sizeof(buf));
+               gchar *addr = NULL;
+               if (compose->account->msgid_with_addr) {
+                       addr = compose->account->address;
+               }
+               generate_msgid(buf, sizeof(buf), addr);
                g_string_append_printf(header, "Message-ID: <%s>\n", buf);
                compose->msgid = g_strdup(buf);
        } else {
@@ -6064,7 +6257,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,
@@ -6086,10 +6280,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);
                        }
@@ -6316,6 +6512,8 @@ static void compose_create_header_entry(Compose *compose)
        const gchar *header = NULL;
        ComposeHeaderEntry *headerentry;
        gboolean standard_header = FALSE;
+       GtkListStore *model;
+       GtkTreeIter iter;
 #if !(GTK_CHECK_VERSION(2,12,0))
        GtkTooltips *tips = compose->tooltips;
 #endif
@@ -6323,13 +6521,21 @@ static void compose_create_header_entry(Compose *compose)
        headerentry = g_new0(ComposeHeaderEntry, 1);
 
        /* Combo box */
-       combo = gtk_combo_box_entry_new_text();
-       string = headers; 
-       while(*string != NULL) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo),
-                       (gchar*)prefs_common_translated_header_name(*string));
-               string++;
-       }
+       model = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
+       combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
+       COMBOBOX_ADD(model, prefs_common_translated_header_name("To:"),
+                       COMPOSE_TO);
+       COMBOBOX_ADD(model, prefs_common_translated_header_name("Cc:"),
+                       COMPOSE_CC);
+       COMBOBOX_ADD(model, prefs_common_translated_header_name("Bcc:"),
+                       COMPOSE_BCC);
+       COMBOBOX_ADD(model, prefs_common_translated_header_name("Newsgroups:"),
+                       COMPOSE_NEWSGROUPS);                    
+       COMBOBOX_ADD(model, prefs_common_translated_header_name("Reply-To:"),
+                       COMPOSE_REPLYTO);
+       COMBOBOX_ADD(model, prefs_common_translated_header_name("Followup-To:"),
+                       COMPOSE_FOLLOWUPTO);
+
        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_CALLBACK(compose_grab_focus_cb), compose);
@@ -6366,13 +6572,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"));
@@ -6423,6 +6625,7 @@ static void compose_create_header_entry(Compose *compose)
         headerentry->button = button;
         headerentry->hbox = hbox;
         headerentry->headernum = compose->header_nextrow;
+        headerentry->type = PREF_NONE;
 
         compose->header_nextrow++;
        compose->header_last = headerentry;             
@@ -6431,28 +6634,75 @@ static void compose_create_header_entry(Compose *compose)
                               headerentry);
 }
 
-static void compose_add_header_entry(Compose *compose, const gchar *header, gchar *text) 
+static void compose_add_header_entry(Compose *compose, const gchar *header,
+                               gchar *text, ComposePrefType pref_type) 
 {
-       ComposeHeaderEntry *last_header;
+       ComposeHeaderEntry *last_header = compose->header_last;
+       gchar *tmp = g_strdup(text), *email;
+       gboolean replyto_hdr;
        
-       last_header = compose->header_last;
-
-       gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((last_header->combo)))), header);
+       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 (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);
+               g_free(tmp);
+               return;
+       }
+       
+       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;
+
+       if (replyto_hdr == FALSE)
+               g_hash_table_insert(compose->email_hashtable, email,
+                                   GUINT_TO_POINTER(1));
+       else
+               g_free(email);
+       
+       g_free(tmp);
+}
+
+static void compose_destroy_headerentry(Compose *compose, 
+                                       ComposeHeaderEntry *headerentry)
+{
+       gchar *text = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
+       gchar *email;
+
+       extract_address(text);
+       email = g_utf8_strdown(text, -1);
+       g_hash_table_remove(compose->email_hashtable, email);
+       g_free(text);
+       g_free(email);
+       
+       gtk_widget_destroy(headerentry->combo);
+       gtk_widget_destroy(headerentry->entry);
+       gtk_widget_destroy(headerentry->button);
+       gtk_widget_destroy(headerentry->hbox);
+       g_free(headerentry);
 }
 
 static void compose_remove_header_entries(Compose *compose) 
 {
        GSList *list;
-       for (list = compose->header_list; list; list = list->next) {
-               ComposeHeaderEntry *headerentry = 
-                       (ComposeHeaderEntry *)list->data;
-               gtk_widget_destroy(headerentry->combo);
-               gtk_widget_destroy(headerentry->entry);
-               gtk_widget_destroy(headerentry->button);
-               gtk_widget_destroy(headerentry->hbox);
-               g_free(headerentry);
-       }
+       for (list = compose->header_list; list; list = list->next)
+               compose_destroy_headerentry(compose, (ComposeHeaderEntry *)list->data);
+
        compose->header_last = NULL;
        g_slist_free(compose->header_list);
        compose->header_list = NULL;
@@ -6529,6 +6779,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);
@@ -6684,7 +6935,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;
@@ -6783,7 +7034,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);
@@ -6832,8 +7084,10 @@ static Compose *compose_create(PrefsAccount *account,
        GtkWidget *paned;
 
        GtkWidget *edit_vbox;
+#if !GTK_CHECK_VERSION(3, 0, 0)
        GtkWidget *ruler_hbox;
        GtkWidget *ruler;
+#endif
        GtkWidget *scrolledwin;
        GtkWidget *text;
        GtkTextBuffer *buffer;
@@ -6861,6 +7115,7 @@ static Compose *compose_create(PrefsAccount *account,
        titles[COL_MIMETYPE] = _("MIME type");
        titles[COL_SIZE]     = _("Size");
        titles[COL_NAME]     = _("Name");
+       titles[COL_CHARSET]  = _("Charset");
 
        compose->batch = batch;
        compose->account = account;
@@ -7072,6 +7327,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)
@@ -7087,7 +7343,9 @@ static Compose *compose_create(PrefsAccount *account,
 /* phew. */
 
 /* Tools menu */
+#if !GTK_CHECK_VERSION(3, 0, 0)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools", "ShowRuler", "Tools/ShowRuler", GTK_UI_MANAGER_MENUITEM)
+#endif
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools", "AddressBook", "Tools/AddressBook", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools", "Template", "Tools/Template", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Tools/Template", "PlaceHolder", "Tools/Template/PlaceHolder", GTK_UI_MANAGER_MENUITEM)
@@ -7189,6 +7447,7 @@ static Compose *compose_create(PrefsAccount *account,
 
        gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
        /* ruler */
        ruler_hbox = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
@@ -7197,6 +7456,7 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
        gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
                           BORDER_WIDTH);
+#endif
 
        /* text widget */
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
@@ -7209,6 +7469,10 @@ static Compose *compose_create(PrefsAccount *account,
        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);
@@ -7216,10 +7480,11 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
        
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
-
+#if !GTK_CHECK_VERSION(3, 0, 0)
        g_signal_connect_after(G_OBJECT(text), "size_allocate",
                               G_CALLBACK(compose_edit_size_alloc),
                               ruler);
+#endif
        g_signal_connect(G_OBJECT(buffer), "changed",
                         G_CALLBACK(compose_changed_cb), compose);
        g_signal_connect(G_OBJECT(text), "grab_focus",
@@ -7313,8 +7578,10 @@ static Compose *compose_create(PrefsAccount *account,
 
        compose->notebook      = notebook;
        compose->edit_vbox     = edit_vbox;
+#if !GTK_CHECK_VERSION(3, 0, 0)
        compose->ruler_hbox    = ruler_hbox;
        compose->ruler         = ruler;
+#endif
        compose->scrolledwin   = scrolledwin;
        compose->text          = text;
 
@@ -7331,6 +7598,9 @@ static Compose *compose_create(PrefsAccount *account,
        compose->replyinfo  = NULL;
        compose->fwdinfo    = NULL;
 
+       compose->email_hashtable = g_hash_table_new_full(g_str_hash,
+                               g_str_equal, (GDestroyNotify) g_free, NULL);
+       
        compose->replyto     = NULL;
        compose->cc          = NULL;
        compose->bcc         = NULL;
@@ -7393,7 +7663,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
@@ -7404,13 +7674,13 @@ static Compose *compose_create(PrefsAccount *account,
        cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoIndent", prefs_common.auto_indent);
 
        if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
-               compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
+               compose_entry_append(compose, account->auto_cc, COMPOSE_CC, PREF_ACCOUNT);
 
        if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT) 
-               compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
+               compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC, PREF_ACCOUNT);
        
        if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
-               compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
+               compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO, PREF_ACCOUNT);
 
        cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/ReplyMode", compose->mode == COMPOSE_REPLY);
        if (account->protocol != A_NNTP)
@@ -7430,10 +7700,12 @@ static Compose *compose_create(PrefsAccount *account,
 
        compose_list = g_list_append(compose_list, compose);
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
        if (!prefs_common.show_ruler)
                gtk_widget_hide(ruler_hbox);
                
        cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Tools/ShowRuler", prefs_common.show_ruler);
+#endif
 
        /* Priority */
        compose->priority = PRIORITY_NORMAL;
@@ -7534,6 +7806,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;
@@ -7572,13 +7845,13 @@ static void compose_reply_change_mode(Compose *compose,
        compose_remove_header_entries(compose);
        compose_reply_set_entry(compose, compose->replyinfo, all, ml, sender, followup);
        if (compose->account->set_autocc && compose->account->auto_cc)
-               compose_entry_append(compose, compose->account->auto_cc, COMPOSE_CC);
+               compose_entry_append(compose, compose->account->auto_cc, COMPOSE_CC, PREF_ACCOUNT);
 
        if (compose->account->set_autobcc && compose->account->auto_bcc) 
-               compose_entry_append(compose, compose->account->auto_bcc, COMPOSE_BCC);
+               compose_entry_append(compose, compose->account->auto_bcc, COMPOSE_BCC, PREF_ACCOUNT);
        
        if (compose->account->set_autoreplyto && compose->account->auto_replyto)
-               compose_entry_append(compose, compose->account->auto_replyto, COMPOSE_REPLYTO);
+               compose_entry_append(compose, compose->account->auto_replyto, COMPOSE_REPLYTO, PREF_ACCOUNT);
        compose_show_first_last_header(compose, TRUE);
        compose->modified = was_modified;
        compose_set_title(compose);
@@ -7630,7 +7903,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");
@@ -7653,7 +7926,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;
 
@@ -7663,11 +7936,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 &&
@@ -7689,8 +7961,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);
                
@@ -7735,6 +8008,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;
@@ -7885,7 +8159,7 @@ static const gchar *compose_quote_char_from_context(Compose *compose)
        return qmark;
 }
 
-void compose_template_apply(Compose *compose, Template *tmpl,
+static void compose_template_apply(Compose *compose, Template *tmpl,
                                   gboolean replace)
 {
        GtkTextView *text;
@@ -7977,6 +8251,11 @@ void compose_template_apply(Compose *compose, Template *tmpl,
        compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
        quote_fmt_reset_vartable();
        compose_changed_cb(NULL, compose);
+
+#ifdef USE_ENCHANT
+       if (compose->gtkaspell && compose->gtkaspell->check_while_typing)
+               gtkaspell_highlight_all(compose->gtkaspell);
+#endif
 }
 
 static void compose_template_apply_fields(Compose *compose, Template *tmpl)
@@ -8026,7 +8305,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                if (buf == NULL) {
                        alertpanel_error(_("Template To format error."));
                } else {
-                       compose_entry_append(compose, buf, COMPOSE_TO);
+                       compose_entry_append(compose, buf, COMPOSE_TO, PREF_TEMPLATE);
                }
        }
 
@@ -8044,7 +8323,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                if (buf == NULL) {
                        alertpanel_error(_("Template Cc format error."));
                } else {
-                       compose_entry_append(compose, buf, COMPOSE_CC);
+                       compose_entry_append(compose, buf, COMPOSE_CC, PREF_TEMPLATE);
                }
        }
 
@@ -8062,7 +8341,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                if (buf == NULL) {
                        alertpanel_error(_("Template Bcc format error."));
                } else {
-                       compose_entry_append(compose, buf, COMPOSE_BCC);
+                       compose_entry_append(compose, buf, COMPOSE_BCC, PREF_TEMPLATE);
                }
        }
 
@@ -8090,6 +8369,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
 static void compose_destroy(Compose *compose)
 {
+       GtkAllocation allocation;
        GtkTextBuffer *buffer;
        GtkClipboard *clipboard;
 
@@ -8111,6 +8391,10 @@ static void compose_destroy(Compose *compose)
        slist_free_strings(compose->header_list);
        g_slist_free(compose->header_list);
 
+       compose->header_list = compose->newsgroup_list = compose->to_list = NULL;
+
+       g_hash_table_destroy(compose->email_hashtable);
+
        procmsg_msginfo_free(compose->targetinfo);
        procmsg_msginfo_free(compose->replyinfo);
        procmsg_msginfo_free(compose->fwdinfo);
@@ -8151,8 +8435,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->scrolledwin, &allocation);
+               prefs_common.compose_width = allocation.width;
+               prefs_common.compose_height = allocation.height;
        }
 
        if (!gtk_widget_get_parent(compose->paned))
@@ -8175,6 +8460,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);
 }
 
@@ -8291,6 +8577,7 @@ static void compose_attach_property(GtkAction *action, gpointer data)
 
        if (!attach_prop.window)
                compose_attach_property_create(&cancelled);
+       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));
@@ -8319,6 +8606,7 @@ static void compose_attach_property(GtkAction *action, gpointer data)
                gtk_main();
 
                gtk_widget_hide(attach_prop.window);
+               gtk_window_set_modal(GTK_WINDOW(attach_prop.window), FALSE);
                
                if (cancelled) 
                        break;
@@ -8377,6 +8665,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;
@@ -8422,7 +8711,6 @@ static void compose_attach_property_create(gboolean *cancelled)
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
        gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_modal(GTK_WINDOW(window), TRUE);
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(attach_property_delete_event),
                         cancelled);
@@ -8545,11 +8833,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;
@@ -8726,7 +9014,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);
 
@@ -8861,6 +9149,7 @@ static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
  * includes "non-client" (windows-izm) in calculation, so this calculation
  * may not be accurate.
  */
+#if !GTK_CHECK_VERSION(3, 0, 0)
 static gboolean compose_edit_size_alloc(GtkEditable *widget,
                                        GtkAllocation *allocation,
                                        GtkSHRuler *shruler)
@@ -8882,6 +9171,14 @@ static gboolean compose_edit_size_alloc(GtkEditable *widget,
 
        return TRUE;
 }
+#endif
+
+typedef struct {
+       gchar                   *header;
+       gchar                   *entry;
+       ComposePrefType         type;
+       gboolean                entry_marked;
+} HeaderEntryState;
 
 static void account_activated(GtkComboBox *optmenu, gpointer data)
 {
@@ -8892,6 +9189,11 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
        gint account_id = 0;
        GtkTreeModel *menu;
        GtkTreeIter iter;
+       GSList *list, *saved_list = NULL;
+       HeaderEntryState *state;
+       GtkRcStyle *style = NULL;
+       static GdkColor yellow;
+       static gboolean color_set = FALSE;
 
        /* Get ID of active account in the combo box */
        menu = gtk_combo_box_get_model(optmenu);
@@ -8901,9 +9203,76 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
        ac = account_find_from_id(account_id);
        cm_return_if_fail(ac != NULL);
 
-       if (ac != compose->account)
+       if (ac != compose->account) {
                compose_select_account(compose, ac, FALSE);
 
+               for (list = compose->header_list; list; list = list->next) {
+                       ComposeHeaderEntry *hentry=(ComposeHeaderEntry *)list->data;
+                       
+                       if (hentry->type == PREF_ACCOUNT || !list->next) {
+                               compose_destroy_headerentry(compose, hentry);
+                               continue;
+                       }
+                       
+                       state = g_malloc0(sizeof(HeaderEntryState));
+                       state->header = gtk_editable_get_chars(GTK_EDITABLE(
+                                       gtk_bin_get_child(GTK_BIN(hentry->combo))), 0, -1);
+                       state->entry = gtk_editable_get_chars(
+                                       GTK_EDITABLE(hentry->entry), 0, -1);
+                       state->type = hentry->type;
+                               
+                       if (!color_set) {
+                               gdk_color_parse("#f5f6be", &yellow);
+                               color_set = gdk_colormap_alloc_color(
+                                                       gdk_colormap_get_system(),
+                                                       &yellow, FALSE, TRUE);
+                       }
+                               
+                       style = gtk_widget_get_modifier_style(hentry->entry);
+                       state->entry_marked = gdk_color_equal(&yellow,
+                                               &style->base[GTK_STATE_NORMAL]);
+
+                       saved_list = g_slist_append(saved_list, state);
+                       compose_destroy_headerentry(compose, hentry);
+               }
+
+               compose->header_last = NULL;
+               g_slist_free(compose->header_list);
+               compose->header_list = NULL;
+               compose->header_nextrow = 1;
+               compose_create_header_entry(compose);
+               
+               if (ac->set_autocc && ac->auto_cc)
+                       compose_entry_append(compose, ac->auto_cc,
+                                               COMPOSE_CC, PREF_ACCOUNT);
+
+               if (ac->set_autobcc && ac->auto_bcc) 
+                       compose_entry_append(compose, ac->auto_bcc,
+                                               COMPOSE_BCC, PREF_ACCOUNT);
+       
+               if (ac->set_autoreplyto && ac->auto_replyto)
+                       compose_entry_append(compose, ac->auto_replyto,
+                                               COMPOSE_REPLYTO, PREF_ACCOUNT);
+               
+               for (list = saved_list; list; list = list->next) {
+                       state = (HeaderEntryState *) list->data;
+                       
+                       compose_add_header_entry(compose, state->header,
+                                               state->entry, state->type);
+                       if (state->entry_marked)
+                               compose_entry_mark_default_to(compose, state->entry);
+                       
+                       g_free(state->header);  
+                       g_free(state->entry);
+                       g_free(state);
+               }
+               g_slist_free(saved_list);
+               
+               combobox_select_by_data(GTK_COMBO_BOX(compose->header_last->combo),
+                                       (ac->protocol == A_NNTP) ? 
+                                       COMPOSE_NEWSGROUPS : COMPOSE_TO);
+       }
+
        /* Set message save folder */
        if (account_get_special_folder(compose->account, F_OUTBOX)) {
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
@@ -8964,7 +9333,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;
        }
@@ -8990,7 +9359,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 "
@@ -9320,7 +9689,7 @@ static void compose_save_cb(GtkAction *action, gpointer data)
        compose->rmode = COMPOSE_REEDIT;
 }
 
-static void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_data)
+void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_data)
 {
        if (compose && file_list) {
                GList *tmp;
@@ -9328,7 +9697,7 @@ static void compose_attach_from_list(Compose *compose, GList *file_list, gboolea
                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);
@@ -9359,6 +9728,7 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
        GList *file_list;
+       gint files_inserted = 0;
 
        file_list = filesel_select_multiple_files_open(_("Select file"));
 
@@ -9370,20 +9740,30 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data)
                        gchar *filedup = g_strdup(file);
                        gchar *shortfile = g_path_get_basename(filedup);
                        ComposeInsertResult res;
-
+                       /* insert the file if the file is short or if the user confirmed that
+                          he/she wants to insert the large file */
                        res = compose_insert_file(compose, file);
                        if (res == COMPOSE_INSERT_READ_ERROR) {
                                alertpanel_error(_("File '%s' could not be read."), shortfile);
                        } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
                                alertpanel_error(_("File '%s' contained invalid characters\n"
-                                                  "for the current encoding, insertion may be incorrect."), shortfile);
-                       }
+                                                       "for the current encoding, insertion may be incorrect."),
+                                                       shortfile);
+                       } else if (res == COMPOSE_INSERT_SUCCESS)
+                               files_inserted++;
+
                        g_free(shortfile);
                        g_free(filedup);
                        g_free(file);
                }
                g_list_free(file_list);
        }
+
+#ifdef USE_ENCHANT     
+       if (files_inserted > 0 && compose->gtkaspell && 
+                   compose->gtkaspell->check_while_typing)
+               gtkaspell_highlight_all(compose->gtkaspell);
+#endif
 }
 
 static void compose_insert_sig_cb(GtkAction *action, gpointer data)
@@ -9633,7 +10013,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)
+           && gtkut_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_cut_clipboard(compose->focused_editable);
@@ -9644,7 +10024,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)
+           && gtkut_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_copy_clipboard(compose->focused_editable);
@@ -9657,11 +10037,18 @@ static void compose_paste_cb(GtkAction *action, gpointer data)
        GtkTextBuffer *buffer;
        BLOCK_WRAP();
        if (compose->focused_editable &&
-           GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
+           gtkut_widget_has_focus(compose->focused_editable))
                entry_paste_clipboard(compose, compose->focused_editable, 
                                prefs_common.linewrap_pastes,
                                GDK_SELECTION_CLIPBOARD, NULL);
        UNBLOCK_WRAP();
+
+#ifdef USE_ENCHANT
+       if (gtkut_widget_has_focus(compose->text) &&
+           compose->gtkaspell && 
+            compose->gtkaspell->check_while_typing)
+               gtkaspell_highlight_all(compose->gtkaspell);
+#endif
 }
 
 static void compose_paste_as_quote_cb(GtkAction *action, gpointer data)
@@ -9670,7 +10057,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)
+           && gtkut_widget_has_focus(compose->focused_editable)
 #endif
            ) {
                /* let text_insert() (called directly or at a later time
@@ -9699,12 +10086,19 @@ 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)
+           && gtkut_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_paste_clipboard(compose, compose->focused_editable, FALSE,
                        GDK_SELECTION_CLIPBOARD, NULL);
        UNBLOCK_WRAP();
+
+#ifdef USE_ENCHANT
+       if (gtkut_widget_has_focus(compose->text) &&
+           compose->gtkaspell && 
+            compose->gtkaspell->check_while_typing)
+               gtkaspell_highlight_all(compose->gtkaspell);
+#endif
 }
 
 static void compose_paste_wrap_cb(GtkAction *action, gpointer data)
@@ -9715,12 +10109,19 @@ 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)
+           && gtkut_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_paste_clipboard(compose, compose->focused_editable, TRUE,
                        GDK_SELECTION_CLIPBOARD, NULL);
        UNBLOCK_WRAP();
+
+#ifdef USE_ENCHANT
+       if (gtkut_widget_has_focus(compose->text) &&
+           compose->gtkaspell &&
+            compose->gtkaspell->check_while_typing)
+               gtkaspell_highlight_all(compose->gtkaspell);
+#endif
 }
 
 static void compose_allsel_cb(GtkAction *action, gpointer data)
@@ -9728,7 +10129,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)
+           && gtkut_widget_has_focus(compose->focused_editable)
 #endif
            )
                entry_allsel(compose->focused_editable);
@@ -10032,7 +10433,7 @@ static void compose_advanced_action_cb(GtkAction *gaction, gpointer data)
                {textview_delete_to_line_end}
        };
 
-       if (!GTK_WIDGET_HAS_FOCUS(text)) return;
+       if (!gtkut_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) {
@@ -10045,6 +10446,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)) {
@@ -10052,24 +10455,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);
                                        }
                                }
                        }
@@ -10185,6 +10593,7 @@ static void activate_privacy_system(Compose *compose, PrefsAccount *account, gbo
        compose_update_privacy_system_menu_item(compose, warn);
 }
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
 static void compose_toggle_ruler_cb(GtkToggleAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
@@ -10198,6 +10607,7 @@ static void compose_toggle_ruler_cb(GtkToggleAction *action, gpointer data)
                prefs_common.show_ruler = FALSE;
        }
 }
+#endif
 
 static void compose_attach_drag_received_cb (GtkWidget         *widget,
                                             GdkDragContext     *context,
@@ -10210,19 +10620,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);
@@ -10248,7 +10661,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);
                        }
                }
@@ -10277,20 +10690,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);  
@@ -10349,16 +10765,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);
@@ -10374,7 +10780,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 */
@@ -10383,8 +10789,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);
@@ -10428,7 +10833,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),
@@ -10440,7 +10845,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
@@ -10453,7 +10858,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) {
@@ -10461,11 +10877,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 */
-               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;
 }
 
@@ -10474,11 +10895,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));
+       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);
 }
 
@@ -10583,13 +11008,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
@@ -10599,7 +11018,7 @@ static void compose_check_all(GtkAction *action, gpointer data)
        if (!compose->gtkaspell)
                return;
                
-       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+       if (gtkut_widget_has_focus(compose->subject_entry))
                claws_spell_entry_check_all(
                        CLAWS_SPELL_ENTRY(compose->subject_entry));             
        else
@@ -10624,7 +11043,7 @@ static void compose_check_backwards(GtkAction *action, gpointer data)
                return;
        }
 
-       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+       if (gtkut_widget_has_focus(compose->subject_entry))
                claws_spell_entry_check_backwards(
                        CLAWS_SPELL_ENTRY(compose->subject_entry));
        else
@@ -10639,7 +11058,7 @@ static void compose_check_forwards_go(GtkAction *action, gpointer data)
                return;
        }
 
-       if (GTK_WIDGET_HAS_FOCUS(compose->subject_entry))
+       if (gtkut_widget_has_focus(compose->subject_entry))
                claws_spell_entry_check_forwards_go(
                        CLAWS_SPELL_ENTRY(compose->subject_entry));
        else
@@ -10730,7 +11149,7 @@ static void compose_add_field_list( Compose *compose, GList *listAddress ) {
        node = listAddress;
        while( node ) {
                addr = ( gchar * ) node->data;
-               compose_entry_append( compose, addr, COMPOSE_TO );
+               compose_entry_append( compose, addr, COMPOSE_TO, PREF_NONE );
                node = g_list_next( node );
        }
 }
@@ -10794,6 +11213,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, 
@@ -10831,6 +11251,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);