2010-02-08 [mir] 3.7.5cvs10
[claws.git] / src / compose.c
index d023b0dc3db8aac94f8908a2a17ea73283d9e564..2e5d7510c2db063918935ecd54a72d5a53803dee 100644 (file)
@@ -162,6 +162,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
 
@@ -205,12 +212,9 @@ static GtkWidget *compose_account_option_menu_create
                                                (Compose        *compose);
 static void compose_set_out_encoding           (Compose        *compose);
 static void compose_set_template_menu          (Compose        *compose);
-static void compose_template_apply             (Compose        *compose,
-                                                Template       *tmpl,
-                                                gboolean        replace);
 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,
@@ -297,6 +301,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);
@@ -328,7 +335,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);
@@ -526,8 +534,6 @@ static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
 #endif
 static void compose_attach_update_label(Compose *compose);
 
-static void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_data);
-
 static GtkActionEntry compose_popup_entries[] =
 {
        {"Compose",                     NULL, "Compose" },
@@ -937,10 +943,13 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        gchar *mailto_from = NULL;
        PrefsAccount *mailto_account = NULL;
        MsgInfo* dummyinfo = NULL;
+       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 */
@@ -1018,20 +1027,24 @@ 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);
+                               compose_entry_append(compose, item->prefs->default_bcc,
+                                               COMPOSE_BCC, PREF_FOLDER);
                        }
                        if (item->prefs->enable_default_cc) {
-                               compose_entry_append(compose, item->prefs->default_cc, COMPOSE_CC);
+                               compose_entry_append(compose, item->prefs->default_cc,
+                                               COMPOSE_CC, PREF_FOLDER);
                        }
                        if (item->prefs->enable_default_replyto) {
-                               compose_entry_append(compose, item->prefs->default_replyto, COMPOSE_REPLYTO);
+                               compose_entry_append(compose, item->prefs->default_replyto,
+                                               COMPOSE_REPLYTO, PREF_FOLDER);
                        }
                        if (item->prefs->enable_default_to) {
-                               compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
+                               compose_entry_append(compose, item->prefs->default_to,
+                                               COMPOSE_TO, PREF_FOLDER);
                                compose_entry_mark_default_to(compose, item->prefs->default_to);
                        }
                }
@@ -1041,11 +1054,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
@@ -1102,6 +1116,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                        g_free(subject);
                        g_free(tmp);
+                       mfield = SUBJECT_FIELD_PRESENT;
                }
 
                if ( body_format
@@ -1129,6 +1144,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;
                }
 
        }
@@ -1155,8 +1175,43 @@ 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:
+                       gtk_widget_grab_focus(compose->text);
+                       break;
+       }
 
        undo_unblock(compose->undostruct);
 
@@ -1168,6 +1223,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;
 }
 
@@ -1561,6 +1619,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)) {
@@ -1601,6 +1663,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                return NULL;
        }
        END_TIMING();
+
        return compose;
 }
 
@@ -1753,6 +1816,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);
@@ -1796,6 +1863,8 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
         return compose;
 }
 
@@ -1942,6 +2011,8 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                return NULL;
        }
 
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2048,7 +2119,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;
 
@@ -2185,7 +2257,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 */
@@ -2270,6 +2343,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;
 }
 
@@ -2375,6 +2450,8 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
                return NULL;
        }
        
+       hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
+
        return compose;
 }
 
@@ -2384,7 +2461,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;
@@ -2407,6 +2484,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:");
@@ -2429,7 +2509,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;
                }
@@ -2443,7 +2523,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);          
        }
 }
@@ -2529,7 +2609,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;
@@ -2539,16 +2619,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);
@@ -2557,6 +2641,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);
@@ -2582,6 +2667,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) {
@@ -2611,12 +2697,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)
@@ -2696,12 +2788,15 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                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;
@@ -2968,22 +3063,6 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from)
        return result;
 }
 
-static gboolean same_address(const gchar *addr1, const gchar *addr2)
-{
-       gchar *my_addr1, *my_addr2;
-       
-       if (!addr1 || !addr2)
-               return FALSE;
-
-       Xstrdup_a(my_addr1, addr1, return FALSE);
-       Xstrdup_a(my_addr2, addr2, return FALSE);
-       
-       extract_address(my_addr1);
-       extract_address(my_addr2);
-       
-       return !strcasecmp(my_addr1, my_addr2);
-}
-
 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                    gboolean to_all, gboolean to_ml,
                                    gboolean to_sender,
@@ -2993,7 +3072,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;
@@ -3009,13 +3088,16 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        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);
+                               compose_entry_append(compose, msginfo->folder->prefs->default_replyto,
+                                                       COMPOSE_REPLYTO, PREF_FOLDER);
                        }
                        if (msginfo->folder->prefs->enable_default_bcc) {
-                               compose_entry_append(compose, msginfo->folder->prefs->default_bcc, COMPOSE_BCC);
+                               compose_entry_append(compose, msginfo->folder->prefs->default_bcc,
+                                                       COMPOSE_BCC, PREF_FOLDER);
                        }
                        if (msginfo->folder->prefs->enable_default_cc) {
-                               compose_entry_append(compose, msginfo->folder->prefs->default_cc, COMPOSE_CC);
+                               compose_entry_append(compose, msginfo->folder->prefs->default_cc,
+                                                       COMPOSE_CC, PREF_FOLDER);
                        }
                }
                if (reply_to_ml && !default_reply_to) {
@@ -3026,28 +3108,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 {
@@ -3062,7 +3143,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) &&
@@ -3070,20 +3151,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);
                                }
                        }
                }
@@ -3094,27 +3175,27 @@ 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) {
@@ -3154,39 +3235,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) \
@@ -3198,7 +3267,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)
@@ -3213,6 +3282,7 @@ static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
        SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
        SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
        SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
+       SET_ADDRESS(COMPOSE_INREPLYTO, compose->inreplyto);
 
        compose_update_priority_menu_item(compose);
        compose_update_privacy_system_menu_item(compose, FALSE);
@@ -3332,9 +3402,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;
@@ -4549,7 +4658,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);
@@ -4644,13 +4752,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;
                                }
@@ -5065,7 +5173,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 {
@@ -6005,7 +6117,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);
@@ -6033,7 +6150,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 {
@@ -6319,6 +6440,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
@@ -6326,13 +6449,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);
@@ -6369,9 +6500,13 @@ 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"));
@@ -6422,6 +6557,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;             
@@ -6430,28 +6566,68 @@ 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 = g_str_has_suffix(header, "-To:");
        
-       last_header = compose->header_last;
-
-       gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((last_header->combo)))), header);
+       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 (!strcmp(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;
@@ -6782,7 +6958,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);
@@ -7330,6 +7507,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;
@@ -7392,7 +7572,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
@@ -7403,13 +7583,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)
@@ -7571,13 +7751,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);
@@ -7976,6 +8156,11 @@ static 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)
@@ -8025,7 +8210,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);
                }
        }
 
@@ -8043,7 +8228,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);
                }
        }
 
@@ -8061,7 +8246,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);
                }
        }
 
@@ -8110,6 +8295,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);
@@ -8290,6 +8479,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));
@@ -8318,6 +8508,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;
@@ -8421,7 +8612,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);
@@ -8551,6 +8741,7 @@ static gboolean attach_property_key_pressed(GtkWidget *widget,
        if (event && event->keyval == GDK_Return) {
                *cancelled = FALSE;
                gtk_main_quit();
+               return TRUE;
        }
        return FALSE;
 }
@@ -8881,6 +9072,13 @@ static gboolean compose_edit_size_alloc(GtkEditable *widget,
        return TRUE;
 }
 
+typedef struct {
+       ComposeEntryType        header;
+       gchar                   *entry;
+       ComposePrefType         type;
+       gboolean                entry_marked;
+} HeaderEntryState;
+
 static void account_activated(GtkComboBox *optmenu, gpointer data)
 {
        Compose *compose = (Compose *)data;
@@ -8890,6 +9088,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);
@@ -8899,9 +9102,74 @@ 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 = combobox_get_active_data(
+                                       GTK_COMBO_BOX(hentry->combo));
+                       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_entry_append(compose, state->entry,
+                                               state->header, state->type);
+                       if (state->entry_marked)
+                               compose_entry_mark_default_to(compose, state->entry);
+                               
+                       g_free(state->entry);
+               }
+               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);
@@ -8988,7 +9256,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 "
@@ -9318,7 +9586,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;
@@ -9357,6 +9625,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"));
 
@@ -9368,20 +9637,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)
@@ -9660,6 +9939,13 @@ static void compose_paste_cb(GtkAction *action, gpointer data)
                                prefs_common.linewrap_pastes,
                                GDK_SELECTION_CLIPBOARD, NULL);
        UNBLOCK_WRAP();
+
+#ifdef USE_ENCHANT
+       if (GTK_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)
@@ -9703,6 +9989,13 @@ static void compose_paste_no_wrap_cb(GtkAction *action, gpointer data)
                entry_paste_clipboard(compose, compose->focused_editable, FALSE,
                        GDK_SELECTION_CLIPBOARD, NULL);
        UNBLOCK_WRAP();
+
+#ifdef USE_ENCHANT
+       if (GTK_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)
@@ -9719,6 +10012,13 @@ static void compose_paste_wrap_cb(GtkAction *action, gpointer data)
                entry_paste_clipboard(compose, compose->focused_editable, TRUE,
                        GDK_SELECTION_CLIPBOARD, NULL);
        UNBLOCK_WRAP();
+
+#ifdef USE_ENCHANT
+       if (GTK_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)
@@ -10461,6 +10761,7 @@ static gboolean compose_headerentry_changed_cb(GtkWidget *entry,
                         0, 0, NULL, NULL, headerentry);
                
                /* Automatically scroll down */
+               GTK_EVENTS_FLUSH();
                compose_show_first_last_header(headerentry->compose, FALSE);
                
        }
@@ -10474,9 +10775,8 @@ static void compose_show_first_last_header(Compose *compose, gboolean show_first
        cm_return_if_fail(compose);
        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));
+       gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : (vadj->upper - vadj->page_size)));
        gtk_adjustment_changed(vadj);
 }
 
@@ -10728,7 +11028,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 );
        }
 }
@@ -10792,6 +11092,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,