2007-06-04 [colin] 2.9.2cvs37
[claws.git] / src / compose.c
index c5831da98c058f0bc47848c66cd18fa840ff669a..8493f011dc15495eac6654c8c4d2c06594bcf4ee 100644 (file)
 #include "message_search.h"
 #include "combobox.h"
 #include "hooks.h"
+#include "privacy.h"
 
 enum
 {
@@ -177,6 +178,13 @@ typedef enum
        COMPOSE_WRITE_FOR_STORE
 } ComposeWriteType;
 
+typedef enum
+{
+       COMPOSE_QUOTE_FORCED,
+       COMPOSE_QUOTE_CHECK,
+       COMPOSE_QUOTE_SKIP
+} ComposeQuoteMode;
+
 #define B64_LINE_SIZE          57
 #define B64_BUFFSIZE           77
 
@@ -197,14 +205,14 @@ static Compose *compose_create                    (PrefsAccount   *account,
 static void compose_entry_mark_default_to      (Compose          *compose,
                                         const gchar      *address);
 static Compose *compose_followup_and_reply_to  (MsgInfo        *msginfo,
-                                        gboolean        quote,
+                                        ComposeQuoteMode        quote_mode,
                                         gboolean        to_all,
                                         gboolean        to_sender,
                                         const gchar    *body);
 static Compose *compose_forward_multiple       (PrefsAccount   *account, 
                                         GSList         *msginfo_list);
 static Compose *compose_reply                  (MsgInfo        *msginfo,
-                                        gboolean        quote,
+                                        ComposeQuoteMode        quote_mode,
                                         gboolean        to_all,
                                         gboolean        to_ml,
                                         gboolean        to_sender,
@@ -502,8 +510,10 @@ static void text_inserted          (GtkTextBuffer  *buffer,
                                         const gchar    *text,
                                         gint            len,
                                         Compose        *compose);
-static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
-                                 gboolean to_all, gboolean to_ml,
+static Compose *compose_generic_reply(MsgInfo *msginfo,
+                                 ComposeQuoteMode quote_mode,
+                                 gboolean to_all,
+                                 gboolean to_ml,
                                  gboolean to_sender,
                                  gboolean followup_and_reply_to,
                                  const gchar *body);
@@ -970,6 +980,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        GtkTextBuffer *textbuf;
        GtkTextIter iter;
        GtkItemFactory *ifactory;
+       gchar *subject_format = NULL;
+       gchar *body_format = NULL;
 
        if (item && item->prefs && item->prefs->enable_default_account)
                account = account_find_from_id(item->prefs->default_account);
@@ -1023,11 +1035,22 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        }
        compose_add_field_list( compose, listAddress );
 
-       if (prefs_common.compose_with_format) {
+       if (item && item->prefs && item->prefs->compose_with_format) {
+               subject_format = item->prefs->compose_subject_format;
+               body_format = item->prefs->compose_body_format;
+       } else if (account->compose_with_format) {
+               subject_format = account->compose_subject_format;
+               body_format = account->compose_body_format;
+       } else if (prefs_common.compose_with_format) {
+               subject_format = prefs_common.compose_subject_format;
+               body_format = prefs_common.compose_body_format;
+       }
+
+       if (subject_format || body_format) {
                MsgInfo* dummyinfo = NULL;
 
-               if ( prefs_common.compose_subject_format
-                        && *prefs_common.compose_subject_format != '\0' )
+               if ( subject_format
+                        && *subject_format != '\0' )
                {
                        gchar *subject = NULL;
                        gchar *tmp = NULL;
@@ -1036,11 +1059,16 @@ 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(prefs_common.compose_subject_format)+1);
-                       pref_get_unescaped_pref(tmp, prefs_common.compose_subject_format);
+                       tmp = malloc(strlen(subject_format)+1);
+                       pref_get_unescaped_pref(tmp, subject_format);
 
                        subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
+#ifdef USE_ASPELL
+                       quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account,
+                                       compose->gtkaspell);
+#else
                        quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account);
+#endif
                        quote_fmt_scan_string(tmp);
                        quote_fmt_parse();
 
@@ -1055,8 +1083,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        g_free(tmp);
                }
 
-               if ( prefs_common.compose_body_format
-                        && *prefs_common.compose_body_format != '\0' )
+               if ( body_format
+                        && *body_format != '\0' )
                {
                        GtkTextView *text;
                        GtkTextBuffer *buffer;
@@ -1073,9 +1101,9 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
 
                        compose_quote_fmt(compose, dummyinfo,
-                                         prefs_common.compose_body_format,
+                                         body_format,
                                          NULL, tmp, FALSE, TRUE,
-                                                 _("New message body format error."));
+                                                 _("New message body format error at line %d."));
                        quote_fmt_reset_vartable();
 
                        g_free(tmp);
@@ -1183,56 +1211,56 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar
 
        switch (mode) {
        case COMPOSE_REPLY:
-               compose = compose_reply(msginfo, prefs_common.reply_with_quote,
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
                              FALSE, prefs_common.default_reply_list, FALSE, body);
                break;
        case COMPOSE_REPLY_WITH_QUOTE:
-               compose = compose_reply(msginfo, TRUE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED
                        FALSE, prefs_common.default_reply_list, FALSE, body);
                break;
        case COMPOSE_REPLY_WITHOUT_QUOTE:
-               compose = compose_reply(msginfo, FALSE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP
                        FALSE, prefs_common.default_reply_list, FALSE, NULL);
                break;
        case COMPOSE_REPLY_TO_SENDER:
-               compose = compose_reply(msginfo, prefs_common.reply_with_quote,
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
                              FALSE, FALSE, TRUE, body);
                break;
        case COMPOSE_FOLLOWUP_AND_REPLY_TO:
                compose = compose_followup_and_reply_to(msginfo,
-                                             prefs_common.reply_with_quote,
+                                             COMPOSE_QUOTE_CHECK,
                                              FALSE, FALSE, body);
                break;
        case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
-               compose = compose_reply(msginfo, TRUE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED
                        FALSE, FALSE, TRUE, body);
                break;
        case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
-               compose = compose_reply(msginfo, FALSE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP
                        FALSE, FALSE, TRUE, NULL);
                break;
        case COMPOSE_REPLY_TO_ALL:
-               compose = compose_reply(msginfo, prefs_common.reply_with_quote,
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
                        TRUE, FALSE, FALSE, body);
                break;
        case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
-               compose = compose_reply(msginfo, TRUE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED
                        TRUE, FALSE, FALSE, body);
                break;
        case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
-               compose = compose_reply(msginfo, FALSE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP
                        TRUE, FALSE, FALSE, NULL);
                break;
        case COMPOSE_REPLY_TO_LIST:
-               compose = compose_reply(msginfo, prefs_common.reply_with_quote,
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_CHECK,
                        FALSE, TRUE, FALSE, body);
                break;
        case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
-               compose = compose_reply(msginfo, TRUE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED
                        FALSE, TRUE, FALSE, body);
                break;
        case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
-               compose = compose_reply(msginfo, FALSE
+               compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP
                        FALSE, TRUE, FALSE, NULL);
                break;
        case COMPOSE_FORWARD:
@@ -1258,7 +1286,7 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar
                compose = compose_redirect(NULL, msginfo, FALSE);
                break;
        default:
-               g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
+               g_warning("compose_reply_mode(): invalid Compose Mode: %d\n", mode);
        }
        
        ifactory = gtk_item_factory_from_widget(compose->menubar);
@@ -1297,20 +1325,24 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar
        return compose;
 }
 
-static Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
-                  gboolean to_ml, gboolean to_sender, 
+static Compose *compose_reply(MsgInfo *msginfo,
+                                  ComposeQuoteMode quote_mode,
+                                  gboolean to_all,
+                                  gboolean to_ml,
+                                  gboolean to_sender, 
                   const gchar *body)
 {
-       return compose_generic_reply(msginfo, quote, to_all, to_ml, 
+       return compose_generic_reply(msginfo, quote_mode, to_all, to_ml, 
                              to_sender, FALSE, body);
 }
 
-static Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
+static Compose *compose_followup_and_reply_to(MsgInfo *msginfo,
+                                  ComposeQuoteMode quote_mode,
                                   gboolean to_all,
                                   gboolean to_sender,
                                   const gchar *body)
 {
-       return compose_generic_reply(msginfo, quote, to_all, FALSE, 
+       return compose_generic_reply(msginfo, quote_mode, to_all, FALSE, 
                              to_sender, TRUE, body);
 }
 
@@ -1356,7 +1388,8 @@ static void compose_extract_original_charset(Compose *compose)
                                compose);                       \
 }
 
-static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
+static Compose *compose_generic_reply(MsgInfo *msginfo,
+                                 ComposeQuoteMode quote_mode,
                                  gboolean to_all, gboolean to_ml,
                                  gboolean to_sender,
                                  gboolean followup_and_reply_to,
@@ -1365,9 +1398,11 @@ static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        GtkItemFactory *ifactory;
        Compose *compose;
        PrefsAccount *account = NULL;
-       PrefsAccount *reply_account;
        GtkTextView *textview;
        GtkTextBuffer *textbuf;
+       gboolean quote = FALSE;
+       gchar *qmark = NULL;
+       gchar *body_fmt = NULL;
 
        g_return_val_if_fail(msginfo != NULL, NULL);
        g_return_val_if_fail(msginfo->folder != NULL, NULL);
@@ -1376,17 +1411,6 @@ static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
 
        g_return_val_if_fail(account != NULL, NULL);
 
-       if (to_sender && account->protocol == A_NNTP &&
-           !followup_and_reply_to) {
-               reply_account =
-                       account_find_from_address(account->address);
-               if (!reply_account)
-                       reply_account = compose_current_mail_account();
-               if (!reply_account)
-                       return NULL;
-       } else
-               reply_account = account;
-
        compose = compose_create(account, COMPOSE_REPLY, FALSE);
 
        compose->updating = TRUE;
@@ -1426,18 +1450,34 @@ static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                compose_set_dictionaries_from_folder_prefs(compose, msginfo->folder);
 #endif
 
-       if (quote) {
-               gchar *qmark;
+       if (quote_mode == COMPOSE_QUOTE_FORCED ||
+                       (quote_mode == COMPOSE_QUOTE_CHECK && prefs_common.reply_with_quote)) {
+               /* use the reply format of folder (if enabled), or the account's one
+                  (if enabled) or fallback to the global reply format, which is always
+                  enabled (even if empty), and use the relevant quotemark */
+               quote = TRUE;
+               if (msginfo->folder && msginfo->folder->prefs &&
+                               msginfo->folder->prefs->reply_with_format) {
+                       qmark = msginfo->folder->prefs->reply_quotemark;
+                       body_fmt = msginfo->folder->prefs->reply_body_format;
+
+               } else if (account->reply_with_format) {
+                       qmark = account->reply_quotemark;
+                       body_fmt = account->reply_body_format;
 
-               if (prefs_common.quotemark && *prefs_common.quotemark)
+               } else {
                        qmark = prefs_common.quotemark;
-               else
-                       qmark = "> ";
+                       body_fmt = prefs_common.quotefmt;
+               }
+       }
 
+       if (quote) {
+               /* empty quotemark is not allowed */
+               if (qmark == NULL || *qmark == '\0')
+                       qmark = "> ";
                compose_quote_fmt(compose, compose->replyinfo,
-                                 prefs_common.quotefmt,
-                                 qmark, body, FALSE, TRUE,
-                                         _("Message reply format error."));
+                                 body_fmt, qmark, body, FALSE, TRUE,
+                                         _("Message reply format error at line %d."));
                quote_fmt_reset_vartable();
        }
        if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
@@ -1529,7 +1569,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
        if (as_attach) {
                gchar *msgfile;
 
-               msgfile = procmsg_get_message_file_path(msginfo);
+               msgfile = procmsg_get_message_file(msginfo);
                if (!is_file_exist(msgfile))
                        g_warning("%s: file not exist\n", msgfile);
                else
@@ -1538,23 +1578,38 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
                g_free(msgfile);
        } else {
-               gchar *qmark;
+               gchar *qmark = NULL;
+               gchar *body_fmt = prefs_common.fw_quotefmt;
                MsgInfo *full_msginfo;
 
                full_msginfo = procmsg_msginfo_get_full_info(msginfo);
                if (!full_msginfo)
                        full_msginfo = procmsg_msginfo_copy(msginfo);
 
-               if (prefs_common.fw_quotemark &&
-                   *prefs_common.fw_quotemark)
+               /* use the forward format of folder (if enabled), or the account's one
+                  (if enabled) or fallback to the global forward format, which is always
+                  enabled (even if empty), and use the relevant quotemark */
+               if (msginfo->folder && msginfo->folder->prefs &&
+                               msginfo->folder->prefs->forward_with_format) {
+                       qmark = msginfo->folder->prefs->forward_quotemark;
+                       body_fmt = msginfo->folder->prefs->forward_body_format;
+
+               } else if (account->forward_with_format) {
+                       qmark = account->forward_quotemark;
+                       body_fmt = account->forward_body_format;
+
+               } else {
                        qmark = prefs_common.fw_quotemark;
-               else
+                       body_fmt = prefs_common.fw_quotefmt;
+               }
+
+               /* empty quotemark is not allowed */
+               if (qmark && !*qmark)
                        qmark = "> ";
 
                compose_quote_fmt(compose, full_msginfo,
-                                 prefs_common.fw_quotefmt,
-                                 qmark, body, FALSE, TRUE,
-                                         _("Message forward format error."));
+                                 body_fmt, qmark, body, FALSE, TRUE,
+                                         _("Message forward format error at line %d."));
                quote_fmt_reset_vartable();
                compose_attach_parts(compose, msginfo);
 
@@ -1647,7 +1702,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
        
        undo_block(compose->undostruct);
        for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
-               msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
+               msgfile = procmsg_get_message_file((MsgInfo *)msginfo->data);
 
                if (!is_file_exist(msgfile))
                        g_warning("%s: file not exist\n", msgfile);
@@ -2019,7 +2074,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
 
        gtk_widget_grab_focus(compose->header_last->entry);
 
-       filename = procmsg_get_message_file_path(msginfo);
+       filename = procmsg_get_message_file(msginfo);
 
        if (filename == NULL) {
                compose->updating = FALSE;
@@ -2049,7 +2104,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
        gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
 
        compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE, FALSE,
-                                         _("Message redirect format error."));
+                                         _("Message redirect format error at line %d."));
        quote_fmt_reset_vartable();
        gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
 
@@ -2532,7 +2587,12 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
        }
 
        if (qmark != NULL) {
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+                               compose->gtkaspell);
+#else
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+#endif
                quote_fmt_scan_string(qmark);
                quote_fmt_parse();
 
@@ -2549,7 +2609,12 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                        while (*trimmed_body == '\n')
                                trimmed_body++;
 
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account,
+                               compose->gtkaspell);
+#else
                quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
+#endif
                if (need_unescape) {
                        gchar *tmp = NULL;
 
@@ -2566,7 +2631,10 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
 
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
-                       alertpanel_error(err_msg);
+                       gint line = quote_fmt_get_line();
+                       gchar *msg = g_strdup_printf(err_msg, line);
+                       alertpanel_error(msg);
+                       g_free(msg);
                        goto error;
                }
        } else
@@ -3330,9 +3398,10 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
 
                        /* if we meet a pgp signature, we don't attach it, but
                         * we force signing. */
-                       if (strcmp(content_type, "application/pgp-signature") &&
+                       if ((strcmp(content_type, "application/pgp-signature") &&
                            strcmp(content_type, "application/pkcs7-signature") &&
-                           strcmp(content_type, "application/x-pkcs7-signature")) {
+                           strcmp(content_type, "application/x-pkcs7-signature"))
+                           || compose->mode == COMPOSE_REDIRECT) {
                                partname = procmime_mimeinfo_get_parameter(child, "filename");
                                if (partname == NULL)
                                        partname = procmime_mimeinfo_get_parameter(child, "name");
@@ -4343,6 +4412,8 @@ gint compose_send(Compose *compose)
                } else if (val == -5) {
                        alertpanel_error(_("Could not queue message for sending:\n\n"
                                           "Couldn't get recipient encryption key."));
+               } else if (val == -6) {
+                       /* silent error */
                } else if (val == -3) {
                        if (privacy_peek_error())
                        alertpanel_error(_("Could not queue message for sending:\n\n"
@@ -4385,8 +4456,6 @@ gint compose_send(Compose *compose)
                g_free(msgpath);
        }
        if (!discard_window) {
-               compose->sending = FALSE;
-               compose_allow_user_actions (compose, TRUE);
                if (val != 0) {
                        if (!queued_removed)
                                folder_item_remove_msg(folder, msgnum);
@@ -4416,8 +4485,11 @@ gint compose_send(Compose *compose)
                                procmsg_msginfo_free(tmp);
                        }
                }
-               if (!discard_window)
+               if (!discard_window) {
+                       compose->sending = FALSE;
+                       compose_allow_user_actions (compose, TRUE);
                        compose_close(compose);
+               }
        } else {
                if (errstr) {
                        gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
@@ -4975,6 +5047,32 @@ gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **ms
 {
        return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
 }
+
+static gboolean compose_warn_encryption(Compose *compose)
+{
+       const gchar *warning = privacy_get_encrypt_warning(compose->privacy_system);
+       AlertValue val = G_ALERTALTERNATE;
+       
+       if (warning == NULL)
+               return TRUE;
+
+       val = alertpanel_full(_("Encryption warning"), warning,
+                 GTK_STOCK_CANCEL, _("+C_ontinue"), NULL,
+                 TRUE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
+       if (val & G_ALERTDISABLE) {
+               val &= ~G_ALERTDISABLE;
+               if (val == G_ALERTALTERNATE)
+                       privacy_inhibit_encrypt_warning(compose->privacy_system,
+                               TRUE);
+       }
+
+       if (val == G_ALERTALTERNATE) {
+               return TRUE;
+       } else {
+               return FALSE;
+       } 
+}
+
 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, 
                              gchar **msgpath, gboolean check_subject,
                              gboolean remove_reedit_target)
@@ -5095,6 +5193,13 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
                if (compose->use_encryption) {
                        gchar *encdata;
+                       if (!compose_warn_encryption(compose)) {
+                               lock = FALSE;
+                               fclose(fp);
+                               g_unlink(tmp);
+                               g_free(tmp);
+                               return -6;
+                       }
                        if (mailac && mailac->encrypt_to_self) {
                                GSList *tmp_list = g_slist_copy(compose->to_list);
                                tmp_list = g_slist_append(tmp_list, compose->account->address);
@@ -5798,13 +5903,10 @@ static void compose_create_header_entry(Compose *compose)
         headerentry->headernum = compose->header_nextrow;
 
         compose->header_nextrow++;
-       compose->header_last = headerentry;
-       
-       if (!compose->first_combo)
-               compose->first_combo = combo;
-       if (!compose->first_entry)
-               compose->first_entry = entry;
-               
+       compose->header_last = headerentry;             
+       compose->header_list =
+               g_slist_append(compose->header_list,
+                              headerentry);
 }
 
 static void compose_add_header_entry(Compose *compose, const gchar *header, gchar *text) 
@@ -5812,7 +5914,7 @@ static void compose_add_header_entry(Compose *compose, const gchar *header, gcha
        ComposeHeaderEntry *last_header;
        
        last_header = compose->header_last;
-       
+
        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
        gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
 }
@@ -5823,18 +5925,10 @@ static void compose_remove_header_entries(Compose *compose)
        for (list = compose->header_list; list; list = list->next) {
                ComposeHeaderEntry *headerentry = 
                        (ComposeHeaderEntry *)list->data;
-               if (headerentry->combo == compose->first_combo)
-                       compose->first_combo = NULL;
-               if (headerentry->entry == compose->first_entry)
-                       compose->first_entry = NULL;
                gtk_widget_destroy(headerentry->combo);
                gtk_widget_destroy(headerentry->entry);
                g_free(headerentry);
        }
-       if (compose->first_combo)
-               gtk_widget_destroy(compose->first_combo);
-       if (compose->first_entry)
-               gtk_widget_destroy(compose->first_entry);
        compose->header_last = NULL;
        g_slist_free(compose->header_list);
        compose->header_list = NULL;
@@ -7023,7 +7117,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
        gchar *qmark;
        gchar *parsed_str = NULL;
        gint cursor_pos = 0;
-       const gchar *err_msg = _("Template body format error.");
+       const gchar *err_msg = _("Template body format error at line %d.");
        if (!tmpl) return;
 
        /* process the body */
@@ -7125,7 +7219,12 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        }
 
        if (tmpl->to && *tmpl->to != '\0') {
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+                               compose->gtkaspell);
+#else
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+#endif
                quote_fmt_scan_string(tmpl->to);
                quote_fmt_parse();
 
@@ -7138,7 +7237,12 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        }
 
        if (tmpl->cc && *tmpl->cc != '\0') {
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+                               compose->gtkaspell);
+#else
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+#endif
                quote_fmt_scan_string(tmpl->cc);
                quote_fmt_parse();
 
@@ -7151,7 +7255,12 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        }
 
        if (tmpl->bcc && *tmpl->bcc != '\0') {
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+                               compose->gtkaspell);
+#else
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+#endif
                quote_fmt_scan_string(tmpl->bcc);
                quote_fmt_parse();
 
@@ -7165,7 +7274,12 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
        /* process the subject */
        if (tmpl->subject && *tmpl->subject != '\0') {
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+                               compose->gtkaspell);
+#else
                quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+#endif
                quote_fmt_scan_string(tmpl->subject);
                quote_fmt_parse();
 
@@ -8099,6 +8213,8 @@ static void compose_send_later_cb(gpointer data, guint action,
        } else if (val == -5) {
                alertpanel_error(_("Could not queue message for sending:\n\n"
                                   "Couldn't get recipient encryption key."));
+       } else if (val == -6) {
+               /* silent error */
        }
        toolbar_main_set_sensitive(mainwindow_get_mainwindow());
 }
@@ -9373,10 +9489,6 @@ static gboolean compose_headerentry_changed_cb(GtkWidget *entry,
                                    ComposeHeaderEntry *headerentry)
 {
        if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
-               headerentry->compose->header_list =
-                       g_slist_append(headerentry->compose->header_list,
-                                      headerentry);
-               
                compose_create_header_entry(headerentry->compose);
                g_signal_handlers_disconnect_matched
                        (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
@@ -9430,7 +9542,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                gtk_text_buffer_place_cursor(buffer, iter);
 
                compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE, FALSE,
-                                                 _("Quote format error."));
+                                                 _("Quote format error at line %d."));
                quote_fmt_reset_vartable();
                g_free(new_text);
                g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
@@ -9622,7 +9734,9 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
                                if (procmime_msginfo_is_encrypted(orig_msginfo)) {
                                        originally_enc = TRUE;
                                }
-                       } 
+                               tmp_msginfo->folder = orig_msginfo->folder;
+                               tmp_msginfo->msgnum = orig_msginfo->msgnum; 
+                       }
                }
        }
 
@@ -9737,7 +9851,7 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
                if ( strcasecmp(header, prefs_common_translated_header_name("To:")) == 0 ) {
                        if ( newmsginfo->to == NULL ) {
                                newmsginfo->to = g_strdup(entry);
-                       } else {
+                       } else if (entry && *entry) {
                                gchar *tmp = g_strconcat(newmsginfo->to, ", ", entry, NULL);
                                g_free(newmsginfo->to);
                                newmsginfo->to = tmp;
@@ -9746,7 +9860,7 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
                if ( strcasecmp(header, prefs_common_translated_header_name("Cc:")) == 0 ) {
                        if ( newmsginfo->cc == NULL ) {
                                newmsginfo->cc = g_strdup(entry);
-                       } else {
+                       } else if (entry && *entry) {
                                gchar *tmp = g_strconcat(newmsginfo->cc, ", ", entry, NULL);
                                g_free(newmsginfo->cc);
                                newmsginfo->cc = tmp;
@@ -9756,7 +9870,7 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
                                                prefs_common_translated_header_name("Newsgroups:")) == 0 ) {
                        if ( newmsginfo->newsgroups == NULL ) {
                                newmsginfo->newsgroups = g_strdup(entry);
-                       } else {
+                       } else if (entry && *entry) {
                                gchar *tmp = g_strconcat(newmsginfo->newsgroups, ", ", entry, NULL);
                                g_free(newmsginfo->newsgroups);
                                newmsginfo->newsgroups = tmp;