sync with 0.8.11cvs22
[claws.git] / src / compose.c
index 201f04a3f3c38967fca038f50535ba553b1da5f4..fabcffa09cf8a48ecd287a71fec0cbd81a78d2e9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -78,7 +78,7 @@
 #include "procmsg.h"
 #include "menu.h"
 #include "stock_pixmap.h"
-#include "send.h"
+#include "send_message.h"
 #include "imap.h"
 #include "news.h"
 #include "customheader.h"
@@ -92,6 +92,7 @@
 #include "statusbar.h"
 #include "about.h"
 #include "base64.h"
+#include "quoted-printable.h"
 #include "codeconv.h"
 #include "utils.h"
 #include "gtkutils.h"
@@ -164,9 +165,6 @@ Compose *compose_generic_new                        (PrefsAccount   *account,
 
 static Compose *compose_create                 (PrefsAccount   *account,
                                                 ComposeMode     mode);
-static void compose_toolbar_create             (Compose        *compose,
-                                                GtkWidget      *container);
-static void compose_toolbar_update              (Compose        *compose);
 
 static GtkWidget *compose_account_option_menu_create
                                                (Compose        *compose);
@@ -192,12 +190,15 @@ static gchar *compose_quote_fmt                   (Compose        *compose,
 static void compose_reply_set_entry            (Compose        *compose,
                                                 MsgInfo        *msginfo,
                                                 gboolean        to_all,
+                                                gboolean        to_ml,
                                                 gboolean        to_sender,
                                                 gboolean
                                                 followup_and_reply_to);
 static void compose_reedit_set_entry           (Compose        *compose,
                                                 MsgInfo        *msginfo);
-static void compose_insert_sig                 (Compose        *compose);
+static void compose_insert_sig                 (Compose        *compose,
+                                                gboolean        replace);
+static gchar *compose_get_signature_str                (Compose        *compose);
 static void compose_insert_file                        (Compose        *compose,
                                                 const gchar    *file);
 static void compose_attach_append              (Compose        *compose,
@@ -212,7 +213,8 @@ static void compose_wrap_line_all_full              (Compose        *compose,
                                                 gboolean        autowrap);
 static void compose_set_title                  (Compose        *compose);
 static void compose_select_account             (Compose        *compose,
-                                                PrefsAccount   *account);
+                                                PrefsAccount   *account,
+                                                gboolean        init);
 
 static PrefsAccount *compose_current_mail_account(void);
 /* static gint compose_send                    (Compose        *compose); */
@@ -293,33 +295,8 @@ static void compose_update_priority_menu_item(Compose * compose);
 static gboolean compose_edit_size_alloc (GtkEditable   *widget,
                                         GtkAllocation  *allocation,
                                         GtkSHRuler     *shruler);
-
-static void toolbar_send_cb            (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_send_later_cb      (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_draft_cb           (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_insert_cb          (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_attach_cb          (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_sig_cb             (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_ext_editor_cb      (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_linewrap_cb                (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_address_cb         (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_actions_execute_cb  (GtkWidget      *widget,
-                                        gpointer        data);
-static void toolbar_compose_buttons_cb  (GtkWidget      *widget, 
-
-                                        ToolbarItem    *t_item);
 static void account_activated          (GtkMenuItem    *menuitem,
                                         gpointer        data);
-
 static void attach_selected            (GtkCList       *clist,
                                         gint            row,
                                         gint            column,
@@ -349,6 +326,9 @@ static void compose_attach_cb               (gpointer        data,
 static void compose_insert_file_cb     (gpointer        data,
                                         guint           action,
                                         GtkWidget      *widget);
+static void compose_insert_sig_cb      (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
 
 static void compose_close_cb           (gpointer        data,
                                         guint           action,
@@ -425,6 +405,12 @@ static void compose_toggle_sign_cb (gpointer        data,
 static void compose_toggle_encrypt_cb  (gpointer        data,
                                         guint           action,
                                         GtkWidget      *widget);
+static void compose_set_gnupg_mode_cb  (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
+static void compose_update_gnupg_mode_menu_item(Compose * compose);
+static void activate_gnupg_mode        (Compose *compose, 
+                                        PrefsAccount *account);
 #endif
 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
                                             GtkWidget *widget);
@@ -474,8 +460,8 @@ static void text_inserted           (GtkWidget      *widget,
                                         gint           *position,
                                         Compose        *compose);
 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
-                                 gboolean to_all,
-                                 gboolean ignore_replyto,
+                                 gboolean to_all, gboolean to_ml,
+                                 gboolean to_sender,
                                  gboolean followup_and_reply_to,
                                  const gchar *body);
 
@@ -501,7 +487,7 @@ static GtkItemFactoryEntry compose_popup_entries[] =
        {N_("/_Add..."),        NULL, compose_attach_cb, 0, NULL},
        {N_("/_Remove"),        NULL, compose_attach_remove_selected, 0, NULL},
        {N_("/---"),            NULL, NULL, 0, "<Separator>"},
-       {N_("/_Property..."),   NULL, compose_attach_property, 0, NULL}
+       {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
 };
 
 static GtkItemFactoryEntry compose_entries[] =
@@ -509,7 +495,7 @@ static GtkItemFactoryEntry compose_entries[] =
        {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
        {N_("/_File/_Attach file"),             "<control>M", compose_attach_cb,      0, NULL},
        {N_("/_File/_Insert file"),             "<control>I", compose_insert_file_cb, 0, NULL},
-       {N_("/_File/Insert si_gnature"),        "<control>G", compose_insert_sig,     0, NULL},
+       {N_("/_File/Insert si_gnature"),        "<control>G", compose_insert_sig_cb,  0, NULL},
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Close"),                   "<control>W", compose_close_cb, 0, NULL},
 
@@ -658,6 +644,8 @@ static GtkItemFactoryEntry compose_entries[] =
        {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/Si_gn"),         NULL, compose_toggle_sign_cb   , 0, "<ToggleItem>"},
        {N_("/_Message/_Encrypt"),      NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
+       {N_("/_Message/Mode/MIME"),             NULL, compose_set_gnupg_mode_cb,   GNUPG_MODE_DETACH, "<RadioItem>"},   
+       {N_("/_Message/Mode/Inline"),   NULL, compose_set_gnupg_mode_cb,   GNUPG_MODE_INLINE, "/Message/Mode/MIME"},    
 #endif /* USE_GPGME */
        {N_("/_Message/---"),           NULL,           NULL,   0, "<Separator>"},
        {N_("/_Message/_Priority"),     NULL,           NULL,   0, "<Branch>"},
@@ -711,21 +699,18 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        ifactory = gtk_item_factory_from_widget(compose->menubar);
 
        compose->replyinfo = NULL;
+       compose->fwdinfo   = NULL;
 
        text = GTK_STEXT(compose->text);
        gtk_stext_freeze(text);
 
-       if (prefs_common.auto_sig)
-               compose_insert_sig(compose);
+       if (account->auto_sig)
+               compose_insert_sig(compose, FALSE);
        gtk_editable_set_position(GTK_EDITABLE(text), 0);
        gtk_stext_set_point(text, 0);
 
        gtk_stext_thaw(text);
 
-       /* workaround for initial XIM problem */
-       gtk_widget_grab_focus(compose->text);
-       gtkut_widget_wait_for_draw(compose->text);
-
        if (account->protocol != A_NNTP) {
                if (mailto && *mailto != '\0') {
                        compose_entries_set(compose, mailto);
@@ -781,14 +766,6 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
         return compose;
 }
 
-#define CHANGE_FLAGS(msginfo) \
-{ \
-if (msginfo->folder->folder->change_flags != NULL) \
-msginfo->folder->folder->change_flags(msginfo->folder->folder, \
-                                     msginfo->folder, \
-                                     msginfo); \
-}
-
 /*
 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
                                           const gchar *followupto, gchar * to)
@@ -814,70 +791,127 @@ Compose *compose_new_followup_and_replyto(PrefsAccount *account,
 }
 */
 
+void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
+{
+       MsgInfo *msginfo;
+       guint list_len;
+
+       g_return_if_fail(msginfo_list != NULL);
+
+       msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
+       g_return_if_fail(msginfo != NULL);
+
+       list_len = g_slist_length(msginfo_list);
+
+       switch (mode) {
+       case COMPOSE_REPLY:
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             FALSE, prefs_common.default_reply_list, FALSE, body);
+               break;
+       case COMPOSE_REPLY_WITH_QUOTE:
+               compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
+               break;
+       case COMPOSE_REPLY_WITHOUT_QUOTE:
+               compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
+               break;
+       case COMPOSE_REPLY_TO_SENDER:
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             FALSE, FALSE, TRUE, body);
+               break;
+       case COMPOSE_FOLLOWUP_AND_REPLY_TO:
+               compose_followup_and_reply_to(msginfo,
+                                             prefs_common.reply_with_quote,
+                                             FALSE, FALSE, body);
+               break;
+       case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
+               compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
+               break;
+       case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
+               compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
+               break;
+       case COMPOSE_REPLY_TO_ALL:
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             TRUE, FALSE, FALSE, body);
+               break;
+       case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
+               compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
+               break;
+       case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
+               compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
+               break;
+       case COMPOSE_REPLY_TO_LIST:
+               compose_reply(msginfo, prefs_common.reply_with_quote,
+                             FALSE, TRUE, FALSE, body);
+               break;
+       case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
+               compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
+               break;
+       case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
+               compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
+               break;
+       case COMPOSE_FORWARD:
+               if (prefs_common.forward_as_attachment) {
+                       compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
+                       return;
+               } else {
+                       compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
+                       return;
+               }
+               break;
+       case COMPOSE_FORWARD_INLINE:
+               /* check if we reply to more than one Message */
+               if (list_len == 1) {
+                       compose_forward(NULL, msginfo, FALSE, body);
+                       break;
+               } 
+               /* more messages FALL THROUGH */
+       case COMPOSE_FORWARD_AS_ATTACH:
+               compose_forward_multiple(NULL, msginfo_list);
+               break;
+       case COMPOSE_REDIRECT:
+               compose_redirect(NULL, msginfo);
+               break;
+       default:
+               g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
+       }
+}
+
 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
-                  gboolean ignore_replyto, const gchar *body)
+                  gboolean to_ml, gboolean to_sender, 
+                  const gchar *body)
 {
-       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
-                             body);
+       compose_generic_reply(msginfo, quote, to_all, to_ml, 
+                             to_sender, FALSE, body);
 }
 
 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
                                   gboolean to_all,
-                                  gboolean ignore_replyto,
+                                  gboolean to_sender,
                                   const gchar *body)
 {
-       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
-                             body);
+       compose_generic_reply(msginfo, quote, to_all, FALSE, 
+                             to_sender, TRUE, body);
 }
 
 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
-                                 gboolean to_all,
-                                 gboolean ignore_replyto,
+                                 gboolean to_all, gboolean to_ml,
+                                 gboolean to_sender,
                                  gboolean followup_and_reply_to,
                                  const gchar *body)
 {
        Compose *compose;
-       PrefsAccount *account;
+       PrefsAccount *account = NULL;
        PrefsAccount *reply_account;
        GtkSText *text;
 
        g_return_if_fail(msginfo != NULL);
        g_return_if_fail(msginfo->folder != NULL);
 
-       account = NULL;
-       /* select the account set in folderitem's property (if enabled) */
-       if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
-               account = account_find_from_id(msginfo->folder->prefs->default_account);
+       account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
        
-       /* select the account for the whole folder (IMAP / NNTP) */
-       if (!account)
-               /* FIXME: this is not right, because folder may be nested. we should
-                * ascend the tree until we find a parent with proper account 
-                * information */
-               account = msginfo->folder->folder->account;
-
-       /* select account by to: and cc: header if enabled */
-       if (prefs_common.reply_account_autosel) {
-               if (!account && msginfo->to) {
-                       gchar *to;
-                       Xstrdup_a(to, msginfo->to, return);
-                       extract_address(to);
-                       account = account_find_from_address(to);
-               }
-               if (!account) {
-                       gchar cc[BUFFSIZE];
-                       if (!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
-                               extract_address(cc);
-                               account = account_find_from_address(cc);
-                       }        
-               }
-       }
-
-       /* select current account */
-       if (!account) account = cur_account;
        g_return_if_fail(account != NULL);
 
-       if (ignore_replyto && account->protocol == A_NNTP &&
+       if (to_sender && account->protocol == A_NNTP &&
            !followup_and_reply_to) {
                reply_account =
                        account_find_from_address(account->address);
@@ -889,16 +923,11 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                reply_account = account;
 
        compose = compose_create(account, COMPOSE_REPLY);
-       compose->replyinfo = procmsg_msginfo_new_ref(msginfo);
 
-#if 0 /* NEW COMPOSE GUI */
-       if (followup_and_reply_to) {
-               gtk_widget_show(compose->to_hbox);
-               gtk_widget_show(compose->to_entry);
-               gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
-               compose->use_to = TRUE;
-       }
-#endif
+       compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
+       if (!compose->replyinfo)
+               compose->replyinfo = procmsg_msginfo_copy(msginfo);
+
        if (msginfo->folder && msginfo->folder->ret_rcpt) {
                GtkItemFactory *ifactory;
        
@@ -917,8 +946,8 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        }
 
        if (compose_parse_header(compose, msginfo) < 0) return;
-       compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
-                               followup_and_reply_to);
+       compose_reply_set_entry(compose, msginfo, to_all, to_ml, 
+                               to_sender, followup_and_reply_to);
        compose_show_first_last_header(compose, TRUE);
 
        text = GTK_STEXT(compose->text);
@@ -933,13 +962,13 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                else
                        qmark = "> ";
 
-               quote_str = compose_quote_fmt(compose, msginfo,
+               quote_str = compose_quote_fmt(compose, compose->replyinfo,
                                              prefs_common.quotefmt,
                                              qmark, body);
        }
 
-       if (prefs_common.auto_sig)
-               compose_insert_sig(compose);
+       if (account->auto_sig)
+               compose_insert_sig(compose, FALSE);
 
        if (quote && prefs_common.linewrap_quote)
                compose_wrap_line_all(compose);
@@ -954,8 +983,6 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                compose_exec_ext_editor(compose);
 }
 
-static void set_toolbar_style(Compose *compose);
-
 #define INSERT_FW_HEADER(var, hdr) \
 if (msginfo->var && *msginfo->var) { \
        gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
@@ -967,13 +994,15 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                         gboolean as_attach, const gchar *body)
 {
        Compose *compose;
-       /*      PrefsAccount *account; */
        GtkSText *text;
 
        g_return_val_if_fail(msginfo != NULL, NULL);
        g_return_val_if_fail(msginfo->folder != NULL, NULL);
 
-       account = msginfo->folder->folder->account;
+       if (msginfo->folder->prefs->enable_default_account)
+               account = account_find_from_id(msginfo->folder->prefs->default_account);
+       if (!account) 
+               account = msginfo->folder->folder->account;
        if (!account && msginfo->to && prefs_common.forward_account_autosel) {
                gchar *to;
                Xstrdup_a(to, msginfo->to, return NULL);
@@ -998,14 +1027,12 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
        }
        g_return_val_if_fail(account != NULL, NULL);
 
-       MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
-       MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
-       if (MSG_IS_IMAP(msginfo->flags))
-               imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
-       CHANGE_FLAGS(msginfo);
-
        compose = compose_create(account, COMPOSE_FORWARD);
 
+       compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
+       if (!compose->fwdinfo)
+               compose->fwdinfo = procmsg_msginfo_copy(msginfo);
+
        if (msginfo->subject && *msginfo->subject) {
                gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
                gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
@@ -1021,7 +1048,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
                        msgfile = procmsg_get_message_file_path(msginfo);
                        if (!is_file_exist(msgfile))
-                               g_warning(_("%s: file not exist\n"), msgfile);
+                               g_warning("%s: file not exist\n", msgfile);
                        else
                                compose_attach_append(compose, msgfile, msgfile,
                                                      "message/rfc822");
@@ -1030,6 +1057,11 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                } else {
                        gchar *qmark;
                        gchar *quote_str;
+                       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)
@@ -1037,14 +1069,16 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                        else
                                qmark = "> ";
 
-                       quote_str = compose_quote_fmt(compose, msginfo,
+                       quote_str = compose_quote_fmt(compose, full_msginfo,
                                                      prefs_common.fw_quotefmt,
                                                      qmark, body);
                        compose_attach_parts(compose, msginfo);
+
+                       procmsg_msginfo_free(full_msginfo);
                }
 
-       if (prefs_common.auto_sig)
-               compose_insert_sig(compose);
+       if (account->auto_sig)
+               compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
                compose_wrap_line_all(compose);
@@ -1063,6 +1097,16 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
        if (prefs_common.auto_exteditor)
                compose_exec_ext_editor(compose);
+       
+       /*save folder*/
+       if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
+               gchar *folderidentifier;
+
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
+               folderidentifier = folder_item_get_identifier(msginfo->folder);
+               gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
+               g_free(folderidentifier);
+       }
 
         return compose;
 }
@@ -1095,7 +1139,6 @@ Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
        for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
                MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
                MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
-               CHANGE_FLAGS(((MsgInfo *)msginfo->data));
        }
 
        compose = compose_create(account, COMPOSE_FORWARD);
@@ -1106,15 +1149,15 @@ Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
        for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
                msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
                if (!is_file_exist(msgfile))
-                       g_warning(_("%s: file not exist\n"), msgfile);
+                       g_warning("%s: file not exist\n", msgfile);
                else
                        compose_attach_append(compose, msgfile, msgfile,
                                "message/rfc822");
                g_free(msgfile);
        }
 
-       if (prefs_common.auto_sig)
-               compose_insert_sig(compose);
+       if (account->auto_sig)
+               compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
                compose_wrap_line_all(compose);
@@ -1146,12 +1189,17 @@ void compose_reedit(MsgInfo *msginfo)
        g_return_if_fail(msginfo != NULL);
        g_return_if_fail(msginfo->folder != NULL);
 
-        if (msginfo->folder->stype == F_QUEUE) {
+        if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
                gchar queueheader_buf[BUFFSIZE];
                gint id;
 
                /* Select Account from queue headers */
                if (!get_header_from_msginfo(msginfo, queueheader_buf, 
+                                            sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
+                       id = atoi(&queueheader_buf[22]);
+                       account = account_find_from_id(id);
+               }
+               if (!account && !get_header_from_msginfo(msginfo, queueheader_buf, 
                                             sizeof(queueheader_buf), "NAID:")) {
                        id = atoi(&queueheader_buf[5]);
                        account = account_find_from_id(id);
@@ -1202,10 +1250,12 @@ void compose_reedit(MsgInfo *msginfo)
        gtk_stext_freeze(text);
 
        if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
-               g_warning(_("Can't get text part\n"));
+               g_warning("Can't get text part\n");
        else {
-               while (fgets(buf, sizeof(buf), fp) != NULL)
+               while (fgets(buf, sizeof(buf), fp) != NULL) {
+                       strcrchomp(buf);
                        gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
+               }
                fclose(fp);
        }
        compose_attach_parts(compose, msginfo);
@@ -1233,6 +1283,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        ifactory = gtk_item_factory_from_widget(compose->menubar);
 
        compose->replyinfo = NULL;
+       compose->fwdinfo = NULL;
 
        compose_show_first_last_header(compose, TRUE);
 
@@ -1243,6 +1294,8 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
                return NULL;
 
        compose->redirect_filename = filename;
+       
+       compose_attach_parts(compose, msginfo);
 
        if (msginfo->subject)
                gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
@@ -1263,18 +1316,21 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
        menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
        menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
-       menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
-       menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
-       menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
-       menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
-       menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
+       menu_set_sensitive(ifactory, "/Edit", FALSE);
+       menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
+       menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
 #if USE_GPGME
        menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
        menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
+       menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
+       menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
 #endif
+       menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
        menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
-       menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
+       menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
+       menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
        
+       gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
        gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
        gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
        gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
@@ -1359,99 +1415,100 @@ void compose_entry_select (Compose *compose, const gchar *mailto)
        }
 }
 
+void compose_toolbar_cb(gint action, gpointer data)
+{
+       ToolbarItem *toolbar_item = (ToolbarItem*)data;
+       Compose *compose = (Compose*)toolbar_item->parent;
+       
+       g_return_if_fail(compose != NULL);
+
+       switch(action) {
+       case A_SEND:
+               compose_send_cb(compose, 0, NULL);
+               break;
+       case A_SENDL:
+               compose_send_later_cb(compose, 0, NULL);
+               break;
+       case A_DRAFT:
+               compose_draft_cb(compose, 0, NULL);
+               break;
+       case A_INSERT:
+               compose_insert_file_cb(compose, 0, NULL);
+               break;
+       case A_ATTACH:
+               compose_attach_cb(compose, 0, NULL);
+               break;
+       case A_SIG:
+               compose_insert_sig(compose, FALSE);
+               break;
+       case A_EXTEDITOR:
+               compose_ext_editor_cb(compose, 0, NULL);
+               break;
+       case A_LINEWRAP:
+               compose_wrap_line(compose);
+               break;
+       case A_ADDRBOOK:
+               compose_address_cb(compose, 0, NULL);
+               break;
+       default:
+               break;
+       }
+}
+
 static void compose_entries_set(Compose *compose, const gchar *mailto)
 {
-       gchar *subject = NULL;
        gchar *to = NULL;
        gchar *cc = NULL;
        gchar *bcc = NULL;
+       gchar *subject = NULL;
        gchar *body = NULL;
-       gchar *p;
-       gchar *tmp_mailto;
-
-       Xstrdup_a(tmp_mailto, mailto, return);
 
-       to = tmp_mailto;
-
-       p = strchr(tmp_mailto, '?');
-       if (p) {
-               *p = '\0';
-               p++;
-       }
-
-       while (p) {
-               gchar *field, *value;
-
-               field = p;
-
-               p = strchr(p, '=');
-               if (!p) break;
-               *p = '\0';
-               p++;
-
-               value = p;
-
-               p = strchr(p, '&');
-               if (p) {
-                       *p = '\0';
-                       p++;
-               }
-
-               if (*value == '\0') continue;
-
-               if (!g_strcasecmp(field, "subject")) {
-                       Xalloca(subject, strlen(value) + 1, return);
-                       decode_uri(subject, value);
-               } else if (!g_strcasecmp(field, "cc")) {
-                       cc = value;
-               } else if (!g_strcasecmp(field, "bcc")) {
-                       bcc = value;
-               } else if (!g_strcasecmp(field, "body")) {
-                       Xalloca(body, strlen(value) + 1, return);
-                       decode_uri(body, value);
-               }
-       }
+       scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
 
        if (to)
                compose_entry_append(compose, to, COMPOSE_TO);
-       if (subject)
-               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
        if (cc)
                compose_entry_append(compose, cc, COMPOSE_CC);
        if (bcc)
                compose_entry_append(compose, bcc, COMPOSE_BCC);
+       if (subject)
+               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
        if (body) {
                gtk_stext_insert(GTK_STEXT(compose->text),
                                NULL, NULL, NULL, body, -1);
                gtk_stext_insert(GTK_STEXT(compose->text),
                                NULL, NULL, NULL, "\n", 1);
        }
+
+       g_free(to);
+       g_free(cc);
+       g_free(bcc);
+       g_free(subject);
+       g_free(body);
 }
 
 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
 {
-       static HeaderEntry hentry[] = {{"Reply-To:",       NULL, TRUE},
-                                      {"Cc:",             NULL, FALSE},
-                                      {"References:",     NULL, FALSE},
-                                      {"Bcc:",            NULL, FALSE},
-                                      {"Newsgroups:",     NULL, FALSE},
-                                      {"Followup-To:",    NULL, FALSE},
-                                      {"X-Mailing-List:", NULL, FALSE},
-                                      {"X-BeenThere:",    NULL, FALSE},
-                                      {"X-Priority:",     NULL, FALSE},
-                                      {NULL,              NULL, FALSE}};
+       static HeaderEntry hentry[] = {{"Reply-To:",    NULL, TRUE},
+                                      {"Cc:",          NULL, TRUE},
+                                      {"References:",  NULL, FALSE},
+                                      {"Bcc:",         NULL, TRUE},
+                                      {"Newsgroups:",  NULL, TRUE},
+                                      {"Followup-To:", NULL, TRUE},
+                                      {"List-Post:",   NULL, FALSE},
+                                      {"X-Priority:",  NULL, FALSE},
+                                      {NULL,           NULL, FALSE}};
 
        enum
        {
-               H_REPLY_TO       = 0,
-               H_CC             = 1,
-               H_REFERENCES     = 2,
-               H_BCC            = 3,
-               H_NEWSGROUPS     = 4,
-               H_FOLLOWUP_TO    = 5,
-               H_X_MAILING_LIST = 6,
-               H_X_BEENTHERE    = 7,
-               H_X_PRIORITY     = 8
+               H_REPLY_TO      = 0,
+               H_CC            = 1,
+               H_REFERENCES    = 2,
+               H_BCC           = 3,
+               H_NEWSGROUPS    = 4,
+               H_FOLLOWUP_TO   = 5,
+               H_LIST_POST     = 6,
+               H_X_PRIORITY    = 7
        };
 
        FILE *fp;
@@ -1472,26 +1529,6 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                compose->cc = hentry[H_CC].body;
                hentry[H_CC].body = NULL;
        }
-       if (hentry[H_X_MAILING_LIST].body != NULL) {
-               /* this is good enough to parse debian-devel */
-               gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
-               g_return_val_if_fail(buf != NULL, -1 );
-               if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
-                       compose->mailinglist = g_strdup(buf);
-               g_free(buf);
-               g_free(hentry[H_X_MAILING_LIST].body);
-               hentry[H_X_MAILING_LIST].body = NULL ;
-       }
-       if (hentry[H_X_BEENTHERE].body != NULL) {
-               /* this is good enough to parse the sylpheed-claws lists */
-               gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
-               g_return_val_if_fail(buf != NULL, -1 );
-               if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
-                       compose->mailinglist = g_strdup(buf);
-               g_free(buf);
-               g_free(hentry[H_X_BEENTHERE].body);
-               hentry[H_X_BEENTHERE].body = NULL ;
-       }
        if (hentry[H_REFERENCES].body != NULL) {
                if (compose->mode == COMPOSE_REEDIT)
                        compose->references = hentry[H_REFERENCES].body;
@@ -1511,6 +1548,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                hentry[H_BCC].body = NULL;
        }
        if (hentry[H_NEWSGROUPS].body != NULL) {
+               conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
                compose->newsgroups = hentry[H_NEWSGROUPS].body;
                hentry[H_NEWSGROUPS].body = NULL;
        }
@@ -1519,7 +1557,23 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                compose->followup_to = hentry[H_FOLLOWUP_TO].body;
                hentry[H_FOLLOWUP_TO].body = NULL;
        }
+       if (hentry[H_LIST_POST].body != NULL) {
+               gchar *to = NULL;
+
+               extract_address(hentry[H_LIST_POST].body);
+               if (hentry[H_LIST_POST].body[0] != '\0') {
+                       scan_mailto_url(hentry[H_LIST_POST].body,
+                                       &to, NULL, NULL, NULL, NULL);
+                       if (to) {
+                               g_free(compose->ml_post);
+                               compose->ml_post = to;
+                       }
+               }
+               g_free(hentry[H_LIST_POST].body);
+               hentry[H_LIST_POST].body = NULL;
+       }
 
+       /* CLAWS - X-Priority */
        if (compose->mode == COMPOSE_REEDIT)
                if (hentry[H_X_PRIORITY].body != NULL) {
                        gint priority;
@@ -1618,7 +1672,8 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
        gchar *buf;
        gchar *p, *lastp;
        gint len;
-
+       gchar *trimmed_body = body;
+       
        if (!msginfo)
                msginfo = &dummyinfo;
 
@@ -1635,7 +1690,11 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
        }
 
        if (fmt && *fmt != '\0') {
-               quote_fmt_init(msginfo, quote_str, body);
+               while (trimmed_body && strlen(trimmed_body) > 1
+                       && trimmed_body[0]=='\n')
+                       *trimmed_body++;
+
+               quote_fmt_init(msginfo, quote_str, trimmed_body);
                quote_fmt_scan_string(fmt);
                quote_fmt_parse();
 
@@ -1665,7 +1724,8 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
 }
 
 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
-                                   gboolean to_all, gboolean ignore_replyto,
+                                   gboolean to_all, gboolean to_ml,
+                                   gboolean to_sender,
                                    gboolean followup_and_reply_to)
 {
        GSList *cc_list = NULL;
@@ -1677,39 +1737,52 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        g_return_if_fail(compose->account != NULL);
        g_return_if_fail(msginfo != NULL);
 
-       if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
-               compose_entry_append(compose,
-                                   ((compose->replyto && !ignore_replyto)
-                                    ? compose->replyto
-                                    : (compose->mailinglist && !ignore_replyto)
-                                    ? compose->mailinglist
-                                    : msginfo->from ? msginfo->from : ""),
-                                    COMPOSE_TO);
-
-       if (compose->account->protocol == A_NNTP) {
-               if (ignore_replyto)
+       if (compose->account->protocol != A_NNTP) {
+               if (!compose->replyto && to_ml && compose->ml_post
+                   && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
+                       compose_entry_append(compose,
+                                          compose->ml_post,
+                                          COMPOSE_TO);
+               else if (!(to_all || to_sender)
+                        && msginfo->folder
+                        && msginfo->folder->prefs->enable_default_reply_to) {
+                       compose_entry_append(compose,
+                           msginfo->folder->prefs->default_reply_to,
+                           COMPOSE_TO);
+               } else
+                       compose_entry_append(compose,
+                                (compose->replyto && !to_sender)
+                                 ? compose->replyto :
+                                 msginfo->from ? msginfo->from : "",
+                                 COMPOSE_TO);
+       } else {
+               if (to_sender || (compose->followup_to && 
+                       !strncmp(compose->followup_to, "poster", 6)))
                        compose_entry_append
-                               (compose, msginfo->from ? msginfo->from : "",
+                               (compose, 
+                                (compose->replyto ? compose->replyto :
+                                       msginfo->from ? msginfo->from : ""),
                                 COMPOSE_TO);
-               else {
-                       if (compose->followup_to && !strncmp(compose->followup_to,"poster",6)) {
-                               compose_entry_append
-                                       (compose,
-                                       ((compose->replyto && !ignore_replyto)
-                                       ? compose->replyto
-                                       : (compose->mailinglist && !ignore_replyto)
-                                       ? compose->mailinglist
-                                       : msginfo->from ? msginfo->from : ""),
-                                       COMPOSE_TO);                            
-                       } else {
-                               compose_entry_append
-                                       (compose,
-                                        compose->followup_to ? compose->followup_to
-                                        : compose->newsgroups ? compose->newsgroups
-                                        : "",
-                                        COMPOSE_NEWSGROUPS);
-                       }
-               }
+                                
+               else if (followup_and_reply_to || to_all) {
+                       compose_entry_append
+                               (compose,
+                                (compose->replyto ? compose->replyto :
+                                msginfo->from ? msginfo->from : ""),
+                                COMPOSE_TO);                           
+               
+                       compose_entry_append
+                               (compose,
+                                compose->followup_to ? compose->followup_to :
+                                compose->newsgroups ? compose->newsgroups : "",
+                                COMPOSE_NEWSGROUPS);
+               } 
+               else 
+                       compose_entry_append
+                               (compose,
+                                compose->followup_to ? compose->followup_to :
+                                compose->newsgroups ? compose->newsgroups : "",
+                                COMPOSE_NEWSGROUPS);
        }
 
        if (msginfo->subject && *msginfo->subject) {
@@ -1729,6 +1802,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
        } else
                gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
 
+       if (to_ml && compose->ml_post) return;
        if (!to_all || compose->account->protocol == A_NNTP) return;
 
        if (compose->replyto) {
@@ -1740,36 +1814,34 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                extract_address(from);
        }
 
-       if (compose->mailinglist && from) {
-               cc_list = address_list_append(cc_list, from);
-       }
-
        if (replyto && from)
-               cc_list = address_list_append(cc_list, from);
-
-       if (!compose->mailinglist)
-               cc_list = address_list_append(cc_list, msginfo->to);
-
-       cc_list = address_list_append(cc_list, compose->cc);
+               cc_list = address_list_append_with_comments(cc_list, from);
+       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, replyto, GINT_TO_POINTER(1));
+               g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
        if (compose->account)
-               g_hash_table_insert(to_table, compose->account->address,
+               g_hash_table_insert(to_table, g_strdup(compose->account->address),
                                    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_strdup(cur->data);
+               extract_address(addr);
 
-               if (g_hash_table_lookup(to_table, cur->data) != NULL)
+               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, cur->data, cur);
+                       g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
 
                cur = next;
        }
+       hash_free_strings(to_table);
        g_hash_table_destroy(to_table);
 
        if (cc_list) {
@@ -1802,105 +1874,114 @@ static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
        SET_ADDRESS(COMPOSE_CC, compose->cc);
        SET_ADDRESS(COMPOSE_BCC, compose->bcc);
        SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
+       SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
+       SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
 
        compose_update_priority_menu_item(compose);
-
+#if USE_GPGME  
+       compose_update_gnupg_mode_menu_item(compose);
+#endif
        compose_show_first_last_header(compose, TRUE);
 
-#if 0 /* NEW COMPOSE GUI */
-       if (compose->bcc) {
-               GtkItemFactory *ifactory;
-               GtkWidget *menuitem;
-
-               ifactory = gtk_item_factory_from_widget(compose->menubar);
-               menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
-               gtk_check_menu_item_set_active
-                       (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
-       }
-       if (compose->replyto) {
-               GtkItemFactory *ifactory;
-               GtkWidget *menuitem;
-
-               ifactory = gtk_item_factory_from_widget(compose->menubar);
-               menuitem = gtk_item_factory_get_item
-                       (ifactory, "/View/Reply to");
-               gtk_check_menu_item_set_active
-                       (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
-       }
-#endif
 }
 
 #undef SET_ENTRY
 #undef SET_ADDRESS
 
-static void compose_exec_sig(Compose *compose, gchar *sigfile)
+static void compose_insert_sig(Compose *compose, gboolean replace)
 {
-       FILE  *sigprg;
-       gchar  *buf;
-       size_t buf_len = 128;
-       if (strlen(sigfile) < 2)
-         return;
-       sigprg = popen(sigfile+1, "r");
-       if (sigprg) {
+       GtkSText *text = GTK_STEXT(compose->text);
+       gint cur_pos;
 
-               buf = g_malloc(buf_len);
+       g_return_if_fail(compose->account != NULL);
 
-               if (!buf) {
-                       gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
-                       "Unable to insert signature (malloc failed)\n", -1);
+       cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
 
-                       pclose(sigprg);
-                       return;
-               }
+       gtk_stext_freeze(text);
+
+       if (replace && compose->sig_str) {
+               gchar *tmp;
+               gint pos;
+               gint len;
+
+               if (compose->account->sig_sep)
+                       tmp = g_strconcat(compose->account->sig_sep, "\n",
+                                         compose->sig_str, NULL);
+               else
+                       tmp = g_strdup(compose->sig_str);
 
-               while (!feof(sigprg)) {
-                       bzero(buf, buf_len);
-                       fread(buf, buf_len-1, 1, sigprg);
-                       gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
+               pos = gtkut_stext_find(text, 0, tmp, TRUE);
+               if (pos != -1) {
+                       gtk_stext_set_point(text, pos);
+                       len = get_wcs_len(tmp);
+                       gtk_stext_forward_delete(text, len);
+               } else {
+                       len = gtk_stext_get_length(text);
+                       gtk_stext_set_point(text, len);
                }
 
-               g_free(buf);
-               pclose(sigprg);
-       }
-       else
-       {
-               gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
-               "Can't exec file: ", -1);
-               gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
-               sigfile+1, -1);
+               g_free(tmp);
+       } else
+               gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
+
+       if (compose->account->sig_sep) {
+               gtk_stext_insert(text, NULL, NULL, NULL, 
+                                compose->account->sig_sep, -1);
+               gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
        }
+
+       g_free(compose->sig_str);
+       compose->sig_str = compose_get_signature_str(compose);
+
+       gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
+
+       gtk_stext_thaw(text);
+
+       if (cur_pos > gtk_stext_get_length(text))
+               cur_pos = gtk_stext_get_length(text);
+
+       gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
+       gtk_stext_set_point(text, cur_pos);
 }
 
-static void compose_insert_sig(Compose *compose)
+static gchar *compose_get_signature_str(Compose *compose)
 {
-       gchar *sigfile;
+       static gchar *default_sigfile;
+       gchar *sig_file = NULL;
+       gchar *sig_str = NULL;
 
-       if (compose->account && compose->account->sig_path)
-               sigfile = g_strdup(compose->account->sig_path);
-       else
-               sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
-                                     DEFAULT_SIGNATURE, NULL);
+       g_return_val_if_fail(compose->account != NULL, NULL);
 
-       if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
-               g_free(sigfile);
-               return;
+       if (compose->account->sig_type == SIG_FILE) {
+               if (compose->account->sig_path)
+                       sig_file = compose->account->sig_path;
+               else {
+                       if (!default_sigfile)
+                               default_sigfile = g_strconcat
+                                       (get_home_dir(), G_DIR_SEPARATOR_S,
+                                        DEFAULT_SIGNATURE, NULL);
+                       sig_file = default_sigfile;
+               }
+
+               if (!is_file_or_fifo_exist(sig_file)) {
+                       g_warning("can't open signature file: %s\n", sig_file);
+                       return NULL;
+               }
        }
 
-       gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
-       if (prefs_common.sig_sep) {
-               gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
-                               prefs_common.sig_sep, -1);
-               gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
-                               "\n", 1);
+       if (compose->account->sig_type == SIG_COMMAND) {
+               if (compose->account->sig_path)
+                       sig_str = get_command_output
+                               (compose->account->sig_path);
+       } else {
+               gchar *tmp;
+
+               tmp = file_read_to_str(sig_file);
+               sig_str = normalize_newlines(tmp);
+               g_free(tmp);
        }
 
-       if (sigfile[0] == '|')
-               compose_exec_sig(compose, sigfile);
-       else
-               compose_insert_file(compose, sigfile);
-       g_free(sigfile);
+       return sig_str;
 }
 
 static void compose_insert_file(Compose *compose, const gchar *file)
@@ -1947,11 +2028,11 @@ static void compose_attach_append(Compose *compose, const gchar *file,
        gint row;
 
        if (!is_file_exist(file)) {
-               g_warning(_("File %s doesn't exist\n"), file);
+               g_warning("File %s doesn't exist\n", file);
                return;
        }
        if ((size = get_file_size(file)) < 0) {
-               g_warning(_("Can't get file size of %s\n"), file);
+               g_warning("Can't get file size of %s\n", file);
                return;
        }
        if (size == 0) {
@@ -1982,7 +2063,10 @@ static void compose_attach_append(Compose *compose, const gchar *file,
        if (content_type) {
                ainfo->content_type = g_strdup(content_type);
                if (!strcasecmp(content_type, "message/rfc822")) {
-                       ainfo->encoding = ENC_7BIT;
+                       if (procmime_get_encoding_for_file(file) == ENC_7BIT)
+                               ainfo->encoding = ENC_7BIT;
+                       else
+                               ainfo->encoding = ENC_8BIT;
                        ainfo->name = g_strdup_printf
                                (_("Message: %s"),
                                 g_basename(filename ? filename : file));
@@ -2063,7 +2147,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                }
                outfile = procmime_get_tmp_file_name(child);
                if (procmime_get_part(outfile, infile, child) < 0)
-                       g_warning(_("Can't get the part of multipart message."));
+                       g_warning("Can't get the part of multipart message.");
                else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
                        compose_attach_append
                                (compose, outfile,
@@ -2089,6 +2173,10 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        }                                                                    \
 }
 
+#define DISP_WIDTH(len) \
+       ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
+        (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
+
 #define INDENT_CHARS   ">|#"
 #define SPACE_CHARS    " \t"
 
@@ -2216,7 +2304,7 @@ static void compose_wrap_line(Compose *compose)
                        line_len = cur_len + ch_len;
                }
 
-               if (cur_len + ch_len > prefs_common.linewrap_len &&
+               if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
                    line_len > 0) {
                        gint tlen = ch_len;
 
@@ -2237,16 +2325,16 @@ static void compose_wrap_line(Compose *compose)
                        p_end++;
                        cur_pos++;
                        line_pos++;
-                       cur_len = cur_len - line_len + ch_len;
+                       cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
                        line_len = 0;
                        continue;
                }
 
                if (ch_len > 1) {
                        line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
+                       line_len = cur_len + DISP_WIDTH(ch_len);
                }
-               cur_len += ch_len;
+               cur_len += DISP_WIDTH(ch_len);
        }
 
 compose_end:
@@ -2471,7 +2559,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
 
                        /* skip delete if it is continuous URL */
                        if (do_delete && (line_pos - p_pos <= i_len) &&
-                           gtkut_stext_is_uri_string(text, line_pos, tlen))
+                           gtk_stext_is_uri_string(text, line_pos, tlen))
                                do_delete = FALSE;
 
 #ifdef WRAP_DEBUG
@@ -2490,7 +2578,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                                   indent string, delete them */
                                if (i_len) {
                                        guint ilen;
-                                       ilen =  gtkut_stext_str_compare_n
+                                       ilen =  gtk_stext_str_compare_n
                                                (text, cur_pos, p_pos, i_len,
                                                 tlen);
                                        if (ilen) {
@@ -2520,6 +2608,14 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                                g_print("after delete l_pos=");
                                dump_text(text, line_pos, tlen, 1);
 #endif
+                               /* move beginning of line if we are on LF */
+                               GET_CHAR(line_pos, cb, clen);
+                               if (clen == 1 && *cb == '\n')
+                                       line_pos++;
+#ifdef WRAP_DEBUG
+                               g_print("new line_pos=%d\n", line_pos);
+#endif
+
                                continue;
                        }
 
@@ -2543,7 +2639,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                }
 
                /* are we over wrapping length set in preferences ? */
-               if (cur_len + ch_len > linewrap_len) {
+               if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
                        gint clen;
 
 #ifdef WRAP_DEBUG
@@ -2553,7 +2649,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
 #endif
                        /* force wrapping if it is one long word but not URL */
                        if (line_pos - p_pos <= i_len)
-                               if (!gtkut_stext_is_uri_string
+                               if (!gtk_stext_is_uri_string
                                    (text, line_pos, tlen))
                                        line_pos = cur_pos - 1;
 #ifdef WRAP_DEBUG
@@ -2565,7 +2661,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                        /* if next character is space delete it */
                        if (clen == 1 && isspace(*cbuf)) {
                                if (p_pos + i_len != line_pos ||
-                                   !gtkut_stext_is_uri_string
+                                   !gtk_stext_is_uri_string
                                        (text, line_pos, tlen)) {
                                        STEXT_FREEZE();
                                        /* workaround for correct cursor
@@ -2587,7 +2683,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
 
                        /* if it is URL at beginning of line don't wrap */
                        if (p_pos + i_len == line_pos &&
-                           gtkut_stext_is_uri_string(text, line_pos, tlen)) {
+                           gtk_stext_is_uri_string(text, line_pos, tlen)) {
 #ifdef WRAP_DEBUG
                                g_print("found URL at ");
                                dump_text(text, line_pos, tlen, 1);
@@ -2620,7 +2716,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                        /* should we insert quotation ? */
                        if (linewrap_quote && i_len) {
                                /* only if line is not already quoted  */
-                               if (!gtkut_stext_str_compare
+                               if (!gtk_stext_str_compare
                                        (text, line_pos, tlen, qfmt)) {
                                        guint ins_len;
 
@@ -2641,10 +2737,10 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
 
                if (ch_len > 1) {
                        line_pos = cur_pos + 1;
-                       line_len = cur_len + ch_len;
+                       line_len = cur_len + DISP_WIDTH(ch_len);
                }
                /* advance to next character in buffer */
-               cur_len += ch_len;
+               cur_len += DISP_WIDTH(ch_len);
        }
 
        if (frozen)
@@ -2699,7 +2795,8 @@ compose_current_mail_account(void)
        return ac;
 }
 
-static void compose_select_account(Compose *compose, PrefsAccount *account)
+static void compose_select_account(Compose *compose, PrefsAccount *account,
+                                  gboolean init)
 {
        GtkWidget *menuitem;
        GtkItemFactory *ifactory;
@@ -2716,6 +2813,7 @@ static void compose_select_account(Compose *compose, PrefsAccount *account)
                gtk_widget_show(compose->newsgroups_hbox);
                gtk_widget_show(compose->newsgroups_entry);
                gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
+               compose->use_newsgroups = TRUE;
 
                menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
                gtk_check_menu_item_set_active
@@ -2732,6 +2830,7 @@ static void compose_select_account(Compose *compose, PrefsAccount *account)
                gtk_widget_hide(compose->newsgroups_entry);
                gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
                gtk_widget_queue_resize(compose->table_vbox);
+               compose->use_newsgroups = FALSE;
 
                menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
                gtk_check_menu_item_set_active
@@ -2748,30 +2847,23 @@ static void compose_select_account(Compose *compose, PrefsAccount *account)
                gtk_widget_set_sensitive(menuitem, FALSE);
        }
 
-       if (account->set_autocc && account->auto_cc &&
-           compose->mode != COMPOSE_REEDIT) {
-               gtk_entry_set_text
-                       (GTK_ENTRY(compose->cc_entry), account->auto_cc);
-               menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
-               gtk_check_menu_item_set_active
-                       (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+       if (account->set_autocc) {
+               compose_entry_show(compose, COMPOSE_ENTRY_CC);
+               if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
+                       compose_entry_set(compose, account->auto_cc,
+                                         COMPOSE_ENTRY_CC);
        }
        if (account->set_autobcc) {
-               menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
-               gtk_check_menu_item_set_active
-                       (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+               compose_entry_show(compose, COMPOSE_ENTRY_BCC);
                if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
-                       gtk_entry_set_text(GTK_ENTRY(compose->bcc_entry),
-                                          account->auto_bcc);
+                       compose_entry_set(compose, account->auto_bcc,
+                                         COMPOSE_ENTRY_BCC);
        }
        if (account->set_autoreplyto) {
-               menuitem = gtk_item_factory_get_item(ifactory,
-                                                    "/View/Reply to");
-               gtk_check_menu_item_set_active
-                       (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+               compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
                if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
-                       gtk_entry_set_text(GTK_ENTRY(compose->reply_entry),
-                                          account->auto_replyto);
+                       compose_entry_set(compose, account->auto_replyto,
+                                         COMPOSE_ENTRY_REPLY_TO);
        }
 
        menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
@@ -2786,7 +2878,12 @@ static void compose_select_account(Compose *compose, PrefsAccount *account)
        menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
                                       account->default_encrypt);
+                                      
+       activate_gnupg_mode(compose, account);          
 #endif /* USE_GPGME */
+
+       if (!init && account->auto_sig)
+               compose_insert_sig(compose, TRUE);
 }
 
 gboolean compose_check_for_valid_recipient(Compose *compose) {
@@ -2870,13 +2967,17 @@ gint compose_send(Compose *compose)
                alertpanel_error(_("Could not queue message for sending"));
                return -1;
        }
+
+       if (msgnum == 0) {
+               alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
+               return 0;
+       }
        
        msgpath = folder_item_fetch_msg(folder, msgnum);
        val = procmsg_send_message_queue(msgpath);
        g_free(msgpath);
 
        folder_item_remove_msg(folder, msgnum);
-       folderview_update_item(folder, TRUE);
 
        return val;
 }
@@ -2891,7 +2992,6 @@ gint compose_send(Compose *compose)
        if (lock) return 1;
 
        g_return_val_if_fail(compose->account != NULL, -1);
-       g_return_val_if_fail(compose->orig_account != NULL, -1);
 
        lock = TRUE;
 
@@ -2913,7 +3013,7 @@ gint compose_send(Compose *compose)
        }
 
        if (!compose->to_list && !compose->newsgroup_list) {
-               g_warning(_("can't get recipient list."));
+               g_warning("can't get recipient list.");
                unlink(tmp);
                lock = FALSE;
                return -1;
@@ -2925,13 +3025,17 @@ gint compose_send(Compose *compose)
 #if 0 /* NEW COMPOSE GUI */
                if (compose->account->protocol != A_NNTP)
                        ac = compose->account;
-               else if (compose->orig_account->protocol != A_NNTP)
-                       ac = compose->orig_account;
-               else if (cur_account && cur_account->protocol != A_NNTP)
-                       ac = cur_account;
                else {
-                       ac = compose_current_mail_account();
+                       ac = account_find_from_address(compose->account->address);
                        if (!ac) {
+                               if (cur_account && cur_account->protocol != A_NNTP)
+                                       ac = cur_account;
+                               else
+                                       ac = account_get_default();
+                       }
+                       if (!ac || ac->protocol == A_NNTP) {
+                               alertpanel_error(_("Account for sending mail is not specified.\n"
+                                                  "Please select a mail account before sending."));
                                unlink(tmp);
                                lock = FALSE;
                                return -1;
@@ -2941,18 +3045,10 @@ gint compose_send(Compose *compose)
                ac = compose->account;
 
                ok = send_message(tmp, ac, compose->to_list);
-               statusbar_pop_all();
        }
 
        if (ok == 0 && compose->newsgroup_list) {
-               Folder *folder;
-
-               if (compose->account->protocol == A_NNTP)
-                       folder = FOLDER(compose->account->folder);
-               else
-                       folder = FOLDER(compose->orig_account->folder);
-
-               ok = news_post(folder, tmp);
+               ok = news_post(FOLDER(compose->account->folder), tmp);
                if (ok < 0) {
                        alertpanel_error(_("Error occurred while posting the message to %s ."),
                                         compose->account->nntp_server);
@@ -2978,13 +3074,10 @@ gint compose_send(Compose *compose)
                                        alertpanel_error(_("Can't queue the message."));
                        }
                } else
-                       alertpanel_error(_("Error occurred while sending the message."));
+                       alertpanel_error_log(_("Error occurred while sending the message."));
        } else {
                if (compose->mode == COMPOSE_REEDIT) {
                        compose_remove_reedit_target(compose);
-                       if (compose->targetinfo)
-                               folderview_update_item
-                                       (compose->targetinfo->folder, TRUE);
                }
                /* save message to outbox */
                if (prefs_common.savemsg) {
@@ -2995,8 +3088,6 @@ gint compose_send(Compose *compose)
                        if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
                                alertpanel_error
                                        (_("Can't save the message to Sent."));
-                       else
-                               folderview_update_item(outbox, TRUE);
                }
        }
 
@@ -3130,7 +3221,7 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
        /* chmod for security */
        if (change_file_mode_rw(fdest, file) < 0) {
                FILE_OP_ERROR(file, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
@@ -3246,8 +3337,7 @@ static gint compose_clearsign_text(Compose *compose, gchar **text)
                return -1;
        }
 
-       if (canonicalize_file_replace(tmp_file) < 0 ||
-           compose_create_signers_list(compose, &key_list) < 0 ||
+       if (compose_create_signers_list(compose, &key_list) < 0 ||
            rfc2015_clearsign(tmp_file, key_list) < 0) {
                unlink(tmp_file);
                g_free(tmp_file);
@@ -3272,6 +3362,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        size_t len;
        gchar *chars;
        gchar *buf;
+       gchar *canon_buf;
        const gchar *out_codeset;
        EncodingType encoding;
 
@@ -3283,7 +3374,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        /* chmod for security */
        if (change_file_mode_rw(fp, file) < 0) {
                FILE_OP_ERROR(file, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        /* get all composed text */
@@ -3300,11 +3391,19 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                out_codeset = conv_get_outgoing_charset_str();
                if (!strcasecmp(out_codeset, CS_US_ASCII))
                        out_codeset = CS_ISO_8859_1;
-               encoding = procmime_get_encoding_for_charset(out_codeset);
+
+               if (prefs_common.encoding_method == CTE_BASE64)
+                       encoding = ENC_BASE64;
+               else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
+                       encoding = ENC_QUOTED_PRINTABLE;
+               else if (prefs_common.encoding_method == CTE_8BIT)
+                       encoding = ENC_8BIT;
+               else
+                       encoding = procmime_get_encoding_for_charset(out_codeset);
 
 #if USE_GPGME
                if (!is_draft &&
-                   compose->use_signing && !compose->account->clearsign &&
+                   compose->use_signing && !compose->gnupg_mode &&
                    encoding == ENC_8BIT)
                        encoding = ENC_BASE64;
 #endif
@@ -3321,11 +3420,15 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
                if (!buf) {
                        AlertValue aval;
+                       gchar *msg;
 
+                       msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
+                                               "%s to %s.\n"
+                                               "Send it anyway?"), src_codeset, out_codeset);
                        aval = alertpanel
-                               (_("Error"),
-                                _("Can't convert the character encoding of the message.\n"
-                                  "Send it anyway?"), _("Yes"), _("+No"), NULL);
+                               (_("Error"), msg, _("Yes"), _("+No"), NULL);
+                       g_free(msg);
+
                        if (aval != G_ALERTDEFAULT) {
                                g_free(chars);
                                fclose(fp);
@@ -3333,14 +3436,19 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                                return -1;
                        } else {
                                buf = chars;
+                               out_codeset = src_codeset;
                                chars = NULL;
                        }
                }
        }
        g_free(chars);
 
+       canon_buf = canonicalize_str(buf);
+       g_free(buf);
+       buf = canon_buf;
+
 #if USE_GPGME
-       if (!is_draft && compose->use_signing && compose->account->clearsign) {
+       if (!is_draft && compose->use_signing && compose->gnupg_mode) {
                if (compose_clearsign_text(compose, &buf) < 0) {
                        g_warning("clearsign failed\n");
                        fclose(fp);
@@ -3354,7 +3462,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        /* write headers */
        if (compose_write_headers
                (compose, fp, out_codeset, encoding, is_draft) < 0) {
-               g_warning(_("can't write headers\n"));
+               g_warning("can't write headers\n");
                fclose(fp);
                /* unlink(file); */
                g_free(buf);
@@ -3390,6 +3498,22 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                        fputs(outbuf, fp);
                        fputc('\n', fp);
                }
+       } else if (encoding == ENC_QUOTED_PRINTABLE) {
+               gchar *outbuf;
+               size_t outlen;
+
+               outbuf = g_malloc(len * 4);
+               qp_encode_line(outbuf, buf);
+               outlen = strlen(outbuf);
+               if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
+                       FILE_OP_ERROR(file, "fwrite");
+                       fclose(fp);
+                       unlink(file);
+                       g_free(outbuf);
+                       g_free(buf);
+                       return -1;
+               }
+               g_free(outbuf);
        } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
                FILE_OP_ERROR(file, "fwrite");
                fclose(fp);
@@ -3409,10 +3533,12 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        }
 
 #if USE_GPGME
-       if (is_draft)
+       if (is_draft) {
+               uncanonicalize_file_replace(file);
                return 0;
+       }
 
-       if ((compose->use_signing && !compose->account->clearsign) ||
+       if ((compose->use_signing && !compose->gnupg_mode) ||
            compose->use_encryption) {
                if (canonicalize_file_replace(file) < 0) {
                        unlink(file);
@@ -3420,7 +3546,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                }
        }
 
-       if (compose->use_signing && !compose->account->clearsign) {
+       if (compose->use_signing && !compose->gnupg_mode) {
                GSList *key_list;
 
                if (compose_create_signers_list(compose, &key_list) < 0 ||
@@ -3431,13 +3557,15 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        }
        if (compose->use_encryption) {
                if (rfc2015_encrypt(file, compose->to_list,
-                                   compose->account->ascii_armored) < 0) {
+                                   compose->gnupg_mode) < 0) {
                        unlink(file);
                        return -1;
                }
        }
 #endif /* USE_GPGME */
 
+       uncanonicalize_file_replace(file);
+
        return 0;
 }
 
@@ -3455,7 +3583,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
        /* chmod for security */
        if (change_file_mode_rw(fp, file) < 0) {
                FILE_OP_ERROR(file, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
@@ -3492,9 +3620,10 @@ static gint compose_remove_reedit_target(Compose *compose)
        g_return_val_if_fail(item != NULL, -1);
 
        if (procmsg_msg_exist(msginfo) &&
-           (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
+           (item->stype == F_DRAFT || item->stype == F_QUEUE 
+            || msginfo == compose->autosaved_draft)) {
                if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
-                       g_warning(_("can't remove the old message\n"));
+                       g_warning("can't remove the old message\n");
                        return -1;
                }
        }
@@ -3510,7 +3639,6 @@ void compose_remove_draft(Compose *compose)
 
        if (procmsg_msg_exist(msginfo)) {
                folder_item_remove_msg(drafts, msginfo->msgnum);
-               folderview_update_item(drafts, TRUE);
        }
 
 }
@@ -3532,7 +3660,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        
        debug_print("queueing message...\n");
        g_return_val_if_fail(compose->account != NULL, -1);
-        g_return_val_if_fail(compose->orig_account != NULL, -1);
 
         lock = TRUE;
        
@@ -3542,7 +3669,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
        if (!compose->to_list && !compose->newsgroup_list) {
-               g_warning(_("can't get recipient list."));
+               g_warning("can't get recipient list.");
                lock = FALSE;
                 return -1;
         }
@@ -3550,8 +3677,6 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        if (compose->to_list) {
                if (compose->account->protocol != A_NNTP)
                        mailac = compose->account;
-               else if (compose->orig_account->protocol != A_NNTP)
-                       mailac = compose->orig_account;
                else if (cur_account && cur_account->protocol != A_NNTP)
                        mailac = cur_account;
                else if (!(mailac = compose_current_mail_account())) {
@@ -3564,7 +3689,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        if (compose->newsgroup_list) {
                 if (compose->account->protocol == A_NNTP)
                         newsac = compose->account;
-                else if (!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
+                else if (!newsac->protocol != A_NNTP) {
                        lock = FALSE;
                        alertpanel_error(_("No account for posting news available!"));
                        return -1;
@@ -3612,7 +3737,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
        if (change_file_mode_rw(fp, tmp) < 0) {
                FILE_OP_ERROR(tmp, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        /* queueing variables */
@@ -3640,21 +3765,21 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                fprintf(fp, "NSV:\n");
        fprintf(fp, "SSH:\n");
        /* write recepient list */
-       fprintf(fp, "R:");
        if (compose->to_list) {
-               fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
-               for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
+               fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
+               for (cur = compose->to_list->next; cur != NULL;
+                    cur = cur->next)
                        fprintf(fp, ",<%s>", (gchar *)cur->data);
+               fprintf(fp, "\n");
        }
-       fprintf(fp, "\n");
        /* write newsgroup list */
-       fprintf(fp, "NG:");
        if (compose->newsgroup_list) {
+               fprintf(fp, "NG:");
                fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
                for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
                        fprintf(fp, ",%s", (gchar *)cur->data);
+               fprintf(fp, "\n");
        }
-       fprintf(fp, "\n");
        /* Sylpheed account IDs */
        if (mailac) {
                fprintf(fp, "MAID:%d\n", mailac->account_id);
@@ -3678,6 +3803,14 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
                g_free(folderid);
        }
+       /* Message-ID of message forwarding to */
+       if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
+               gchar *folderid;
+               
+               folderid = folder_item_get_identifier(compose->fwdinfo->folder);
+               fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
+               g_free(folderid);
+       }
        fprintf(fp, "\n");
 
        while (fgets(buf, sizeof(buf), src_fp) != NULL) {
@@ -3704,14 +3837,14 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
 
        queue = account_get_special_folder(compose->account, F_QUEUE);
        if (!queue) {
-               g_warning(_("can't find queue folder\n"));
+               g_warning("can't find queue folder\n");
                unlink(tmp);
                g_free(tmp);
                return -1;
        }
        folder_item_scan(queue);
        if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
-               g_warning(_("can't queue the message\n"));
+               g_warning("can't queue the message\n");
                unlink(tmp);
                g_free(tmp);
                return -1;
@@ -3723,14 +3856,8 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
 
        if (compose->mode == COMPOSE_REEDIT) {
                compose_remove_reedit_target(compose);
-               if (compose->targetinfo &&
-                   compose->targetinfo->folder != queue)
-                       folderview_update_item
-                               (compose->targetinfo->folder, TRUE);
        }
 
-       folderview_update_item(queue, TRUE);
-
        if ((msgnum != NULL) && (item != NULL)) {
                *msgnum = num;
                *item = queue;
@@ -3750,11 +3877,8 @@ static void compose_write_attach(Compose *compose, FILE *fp)
 
        for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
             row++) {
-               gchar buf[BUFFSIZE];
-               gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
-
                if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
-                       g_warning(_("Can't open file %s\n"), ainfo->file);
+                       g_warning("Can't open file %s\n", ainfo->file);
                        continue;
                }
 
@@ -3764,8 +3888,8 @@ static void compose_write_attach(Compose *compose, FILE *fp)
                        fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
                        fprintf(fp, "Content-Disposition: inline\n");
                } else {
-                       conv_encode_header(filename, sizeof(filename),
-                                          ainfo->name, 12);
+                       compose_convert_header(filename, sizeof(filename),
+                                              ainfo->name, 12);
                        fprintf(fp, "Content-Type: %s;\n"
                                    " name=\"%s\"\n",
                                ainfo->content_type, filename);
@@ -3776,19 +3900,8 @@ static void compose_write_attach(Compose *compose, FILE *fp)
                fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
                        procmime_get_encoding_str(ainfo->encoding));
 
-               switch (ainfo->encoding) {
-
-               case ENC_7BIT:
-               case ENC_8BIT:
-                       /* if (ainfo->encoding == ENC_7BIT) { */
-
-                       while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
-                               strcrchomp(buf);
-                               fputs(buf, fp);
-                       }
-                       break;
-                       /* } else { */
-               case ENC_BASE64:
+               if (ainfo->encoding == ENC_BASE64) {
+                       gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
 
                        while ((len = fread(inbuf, sizeof(gchar),
                                            B64_LINE_SIZE, attach_fp))
@@ -3802,7 +3915,20 @@ static void compose_write_attach(Compose *compose, FILE *fp)
                                fputs(outbuf, fp);
                                fputc('\n', fp);
                        }
-                       break;
+               } else if (ainfo->encoding == ENC_QUOTED_PRINTABLE) {
+                       gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
+
+                       while (fgets(inbuf, sizeof(inbuf), attach_fp) != NULL) {
+                               qp_encode_line(outbuf, inbuf);
+                               fputs(outbuf, fp);
+                       }
+               } else {
+                       gchar buf[BUFFSIZE];
+
+                       while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
+                               strcrchomp(buf);
+                               fputs(buf, fp);
+                       }
                }
 
                fclose(attach_fp);
@@ -3915,17 +4041,18 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
        g_return_val_if_fail(compose->account != NULL, -1);
        g_return_val_if_fail(compose->account->address != NULL, -1);
 
-       /* Save copy folder */
+       /* Save draft infos */
        if (is_draft) {
+               fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
+               fprintf(fp, "S:%s\n", compose->account->address);
                if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
                        gchar *savefolderid;
 
                        savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
-                       fprintf(fp, "SCF:%s\n\n", savefolderid);
+                       fprintf(fp, "SCF:%s\n", savefolderid);
                        g_free(savefolderid);
-               } else {
-                       fprintf(fp, " \n\n");
                }
+               fprintf(fp, "\n");
        }
 
        /* Date */
@@ -3959,18 +4086,20 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
        /* Newsgroups */
        compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
 #if 0 /* NEW COMPOSE GUI */
-       str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
-       if (*str != '\0') {
-               Xstrdup_a(str, str, return -1);
-               g_strstrip(str);
-               remove_space(str);
+       if (compose->use_newsgroups) {
+               str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
                if (*str != '\0') {
-                       compose->newsgroup_list =
-                               newsgroup_list_append(compose->newsgroup_list,
-                                                     str);
-                       compose_convert_header(buf, sizeof(buf), str,
-                                              strlen("Newsgroups: "));
-                       fprintf(fp, "Newsgroups: %s\n", buf);
+                       Xstrdup_a(str, str, return -1);
+                       g_strstrip(str);
+                       remove_space(str);
+                       if (*str != '\0') {
+                               compose->newsgroup_list =
+                                       newsgroup_list_append
+                                               (compose->newsgroup_list, str);
+                               compose_convert_header(buf, sizeof(buf), str,
+                                                      strlen("Newsgroups: "));
+                               fprintf(fp, "Newsgroups: %s\n", buf);
+                       }
                }
        }
 #endif
@@ -4062,7 +4191,8 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 
        /* Program version and system info */
        /* uname(&utsbuf); */
-       if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
+       if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
+           !compose->newsgroup_list) {
                fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
                        prog_version,
                        gtk_major_version, gtk_minor_version, gtk_micro_version,
@@ -4208,14 +4338,9 @@ static void compose_convert_header(gchar *dest, gint len, gchar *src,
 
        if (len < 1) return;
 
-       remove_return(src);
+       g_strchomp(src);
 
-       if (is_ascii_str(src)) {
-               strncpy2(dest, src, len);
-               dest[len - 1] = '\0';
-               return;
-       } else
-               conv_encode_header(dest, len, src, header_len);
+       conv_encode_header(dest, len, src, header_len);
 }
 
 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
@@ -4256,7 +4381,7 @@ static void compose_create_header_entry(Compose *compose)
        GtkWidget *combo;
        GtkWidget *entry;
        GList *combo_list = NULL;
-       gchar **string, *header;
+       gchar **string, *header = NULL;
        ComposeHeaderEntry *headerentry;
        gboolean standard_header = FALSE;
 
@@ -4266,8 +4391,8 @@ static void compose_create_header_entry(Compose *compose)
        combo = gtk_combo_new();
        string = headers; 
        while(*string != NULL) {
-           combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
-           string++;
+               combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
+               string++;
        }
        gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
        g_list_free(combo_list);
@@ -4295,7 +4420,8 @@ static void compose_create_header_entry(Compose *compose)
                                break;
                }                                                                   
        }
-       gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
+       if (header)
+               gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
 
        /* Entry field */
        entry = gtk_entry_new(); 
@@ -4505,7 +4631,7 @@ GtkWidget *compose_create_attach(Compose *compose)
        /* drag and drop */
        gtk_drag_dest_set(attach_clist,
                          GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
-                         GDK_ACTION_COPY);
+                         GDK_ACTION_COPY | GDK_ACTION_MOVE);
        gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
                           GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
                           compose);
@@ -4624,7 +4750,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        GdkColormap *cmap;
        GdkColor color[1];
        gboolean success[1];
-       GdkFont   *font;
        GtkWidget *popupmenu;
        GtkItemFactory *popupfactory;
        GtkItemFactory *ifactory;
@@ -4647,7 +4772,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        titles[COL_NAME]     = _("Name");
 
        compose->account = account;
-       compose->orig_account = account;
 
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
@@ -4681,7 +4805,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        handlebox = gtk_handle_box_new();
        gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
 
-       compose_toolbar_create(compose, handlebox);
+       compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
+                                         (gpointer)compose);
 
        vbox2 = gtk_vbox_new(FALSE, 2);
        gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
@@ -4787,7 +4912,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        /* drag and drop */
        gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
-                         GDK_ACTION_COPY);
+                         GDK_ACTION_COPY | GDK_ACTION_MOVE);
        gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
                           GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
                           compose);
@@ -4816,16 +4941,9 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                new_style = gtk_style_copy(style);
 
        if (prefs_common.textfont) {
-               if (MB_CUR_MAX == 1) {
-                       gchar *fontstr, *p;
+               GdkFont *font;
 
-                       Xstrdup_a(fontstr, prefs_common.textfont, );
-                       if (fontstr && (p = strchr(fontstr, ',')) != NULL)
-                               *p = '\0';
-                       font = gdk_font_load(fontstr);
-               } else
-                       font = gdk_fontset_load(prefs_common.textfont);
-               if (font) {
+               if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
                        gdk_font_unref(new_style->font);
                        new_style->font = font;
                }
@@ -4914,12 +5032,15 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        compose->targetinfo = NULL;
        compose->replyinfo  = NULL;
+       compose->fwdinfo    = NULL;
 
        compose->replyto     = NULL;
-       compose->mailinglist = NULL;
        compose->cc          = NULL;
        compose->bcc         = NULL;
        compose->followup_to = NULL;
+
+       compose->ml_post     = NULL;
+
        compose->inreplyto   = NULL;
        compose->references  = NULL;
        compose->msgid       = NULL;
@@ -4938,44 +5059,48 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        compose->to_list        = NULL;
        compose->newsgroup_list = NULL;
 
+       compose->undostruct = undostruct;
+
+       compose->sig_str = NULL;
+
        compose->exteditor_file    = NULL;
        compose->exteditor_pid     = -1;
        compose->exteditor_readdes = -1;
        compose->exteditor_tag     = -1;
 
-       compose->redirect_filename = NULL;
-       compose->undostruct = undostruct;
 #if USE_ASPELL
-       
        menu_set_sensitive(ifactory, "/Spelling", FALSE);
-        if (prefs_common.enable_aspell) {
-               gtkaspell = gtkaspell_new((const gchar*)prefs_common.dictionary,
-                                         conv_get_current_charset_str(),
-                                         prefs_common.misspelled_col,
-                                         prefs_common.check_while_typing,
-                                         prefs_common.use_alternate,
-                                         GTK_STEXT(text));
-               if (!gtkaspell) {
-                       alertpanel_error(_("Spell checker could not be started.\n%s"), gtkaspellcheckers->error_message);
-                       gtkaspell_checkers_reset_error();
-               } else {
+       if (mode != COMPOSE_REDIRECT) {
+               if (prefs_common.enable_aspell && prefs_common.dictionary &&
+                   strcmp(prefs_common.dictionary, _("None"))) {
+                       gtkaspell = gtkaspell_new((const gchar*)prefs_common.dictionary,
+                                                 conv_get_current_charset_str(),
+                                                 prefs_common.misspelled_col,
+                                                 prefs_common.check_while_typing,
+                                                 prefs_common.use_alternate,
+                                                 GTK_STEXT(text));
+                       if (!gtkaspell) {
+                               alertpanel_error(_("Spell checker could not be started.\n%s"), gtkaspellcheckers->error_message);
+                               gtkaspell_checkers_reset_error();
+                       } else {
 
-                       GtkWidget *menuitem;
+                               GtkWidget *menuitem;
 
-                       if (!gtkaspell_set_sug_mode(gtkaspell, prefs_common.aspell_sugmode)) {
-                               debug_print("Aspell: could not set suggestion mode %s\n",
-                                   gtkaspellcheckers->error_message);
-                               gtkaspell_checkers_reset_error();
-                       }
+                               if (!gtkaspell_set_sug_mode(gtkaspell, prefs_common.aspell_sugmode)) {
+                                       debug_print("Aspell: could not set suggestion mode %s\n",
+                                       gtkaspellcheckers->error_message);
+                                       gtkaspell_checkers_reset_error();
+                               }
 
-                       menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
-                       gtkaspell_populate_submenu(gtkaspell, menuitem);
-                       menu_set_sensitive(ifactory, "/Spelling", TRUE);
-                       }
-        }
+                               menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
+                               gtkaspell_populate_submenu(gtkaspell, menuitem);
+                               menu_set_sensitive(ifactory, "/Spelling", TRUE);
+                               }
+               }
+       }
 #endif
 
-       compose_select_account(compose, account);
+       compose_select_account(compose, account, TRUE);
 
 #if USE_ASPELL
         compose->gtkaspell      = gtkaspell;
@@ -4998,7 +5123,14 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        addressbook_set_target_compose(compose);
        update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
-       compose_set_template_menu(compose);
+       
+       if (mode != COMPOSE_REDIRECT)
+               compose_set_template_menu(compose);
+       else {
+               GtkWidget *menuitem;
+               menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
+               menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
+       }
 
        compose_list = g_list_append(compose_list, compose);
 
@@ -5008,207 +5140,16 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        /* Priority */
        compose->priority = PRIORITY_NORMAL;
        compose_update_priority_menu_item(compose);
-
-       set_toolbar_style(compose);
-
+       
+#if USE_GPGME
+       activate_gnupg_mode(compose, account);
+#endif 
+       toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
        gtk_widget_show(window);
        
        return compose;
 }
 
-static void toolbar_compose_buttons_cb(GtkWidget   *widget, 
-                                      ToolbarItem *t_item)
-{
-       struct {
-               gint   index;
-               void (*func)(GtkWidget *widget, gpointer data);
-       } compose_action[] = {
-               { A_SEND,        toolbar_send_cb            },
-               { A_SENDL,       toolbar_send_later_cb      },
-               { A_DRAFT,       toolbar_draft_cb           },
-               { A_INSERT,      toolbar_insert_cb          },
-               { A_ATTACH,      toolbar_attach_cb          },
-               { A_SIG,         toolbar_sig_cb             },
-               { A_EXTEDITOR,   toolbar_ext_editor_cb      },
-               { A_LINEWRAP,    toolbar_linewrap_cb        },
-               { A_ADDRBOOK,    toolbar_address_cb         },
-               { A_SYL_ACTIONS, toolbar_actions_execute_cb }};
-
-
-       gint num_items = sizeof(compose_action)/sizeof(compose_action[0]);
-       gint i;
-       debug_print("_buttons: index: %i \n", t_item->index);
-       for (i = 0; i < num_items; i++) {
-               
-               if (compose_action[i].index == t_item->index) {
-                       Compose *compose = (Compose*)t_item->parent;
-                       debug_print("_buttons: compose: %p toolbar: %p\n", compose, compose->toolbar);                  compose_action[i].func(widget, compose);
-                       break;
-               }
-       }
-}
-
-static void compose_toolbar_update(Compose *compose)
-{
-       gtk_container_remove(GTK_CONTAINER(compose->handlebox), 
-                            GTK_WIDGET(compose->toolbar->toolbar));
-       
-       compose->toolbar->toolbar       = NULL;
-       compose->toolbar->send_btn      = NULL;
-       compose->toolbar->sendl_btn     = NULL;
-       compose->toolbar->draft_btn     = NULL;
-       compose->toolbar->insert_btn    = NULL;
-       compose->toolbar->attach_btn    = NULL;
-       compose->toolbar->sig_btn       = NULL; 
-       compose->toolbar->exteditor_btn = NULL; 
-       compose->toolbar->linewrap_btn  = NULL; 
-       compose->toolbar->addrbook_btn  = NULL; 
-
-       TOOLBAR_DESTROY_ITEMS(compose->toolbar->t_item_list);   
-       TOOLBAR_DESTROY_ACTIONS(compose->toolbar->t_action_list);
-       compose_toolbar_create(compose, compose->handlebox);    
-}
-
-static void compose_toolbar_create(Compose   *compose, 
-                                  GtkWidget *container)
-{
-       ToolbarItem *toolbar_item;
-
-       GtkWidget *toolbar;
-       GtkWidget *icon_wid  = NULL;
-       GtkWidget *item;
-       GtkTooltips *toolbar_tips;
-       ToolbarSylpheedActions *t_action_item;
-       GSList *cur;
-       GSList *toolbar_list;
-       GList *elem;
-       toolbar_tips = gtk_tooltips_new();
-       
-       toolbar_read_config_file(TOOLBAR_COMPOSE);
-       toolbar_list = toolbar_get_list(TOOLBAR_COMPOSE);
-
-       compose->toolbar = g_new0(ComposeToolbar, 1); 
-       
-       for (elem = compose_list; elem != NULL; elem = elem->next) {
-               Compose *c = (Compose*)elem->data;
-               debug_print("toolbar_create: compose: %p toolbar: %p\n", 
-                           c, c->toolbar);
-       }
-       
-       toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
-                                 GTK_TOOLBAR_BOTH);
-       gtk_container_add(GTK_CONTAINER(container), toolbar);
-       gtk_container_set_border_width(GTK_CONTAINER(container), 2);
-       gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
-       gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
-                                   GTK_TOOLBAR_SPACE_LINE);
-       
-       for (cur = toolbar_list; cur != NULL; cur = cur->next) {
-
-               if (g_strcasecmp(((ToolbarItem*)cur->data)->file, SEPARATOR) == 0) {
-                       gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
-                       continue;
-               }
-               
-               toolbar_item = g_new0(ToolbarItem, 1); 
-               toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
-               toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
-               toolbar_item->index = ((ToolbarItem*)cur->data)->index;
-
-               toolbar_item->parent = (gpointer)compose;
-
-               /* collect toolbar items in list to keep track */
-               compose->toolbar->t_item_list = g_slist_append(compose->toolbar->t_item_list, 
-                                                             toolbar_item);
-
-               icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
-               item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                               toolbar_item->text,
-                                               (""),
-                                               (""),
-                                               icon_wid, toolbar_compose_buttons_cb, 
-                                               toolbar_item);
-               
-               switch (toolbar_item->index) {
-               case A_SEND:
-                       compose->toolbar->send_btn = item;
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->send_btn, 
-                                            _("Send Message"), NULL);
-                       break;
-               case A_SENDL:
-                       compose->toolbar->sendl_btn = item;
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->sendl_btn,
-                                            _("Put into queue folder and send later"), NULL);
-                       break;
-               case A_DRAFT:
-                       compose->toolbar->draft_btn = item; 
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->draft_btn,
-                                            _("Save to draft folder"), NULL);
-                       break;
-               case A_INSERT:
-                       compose->toolbar->insert_btn = item; 
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->insert_btn,
-                                            _("Insert file"), NULL);
-                       break;
-               case A_ATTACH:
-                       compose->toolbar->attach_btn = item;
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->attach_btn,
-                                            _("Attach file"), NULL);
-                       break;
-               case A_SIG:
-                       compose->toolbar->sig_btn = item;
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->sig_btn,
-                                            _("Insert signature"), NULL);
-                       break;
-               case A_EXTEDITOR:
-                       compose->toolbar->exteditor_btn = item;
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->exteditor_btn,
-                                            _("Edit with external editor"), NULL);
-                       break;
-               case A_LINEWRAP:
-                       compose->toolbar->linewrap_btn = item;
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->linewrap_btn,
-                                            _("Wrap all long lines"), NULL);
-                       break;
-               case A_ADDRBOOK:
-                       compose->toolbar->addrbook_btn = item;
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            compose->toolbar->addrbook_btn,
-                                            _("Address book"), NULL);
-                       break;
-               case A_SYL_ACTIONS:
-                       t_action_item = g_new0(ToolbarSylpheedActions, 1);
-                       t_action_item->widget = item;
-                       t_action_item->name   = g_strdup(toolbar_item->text);
-
-                       compose->toolbar->t_action_list = 
-                               g_slist_append(compose->toolbar->t_action_list,
-                                              t_action_item);
-
-                       gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
-                                            item,
-                                            t_action_item->name, NULL);
-
-                       gtk_widget_show(item);
-                       break;
-               default:
-                       break;
-               }
-       }
-
-       compose->toolbar->toolbar = toolbar;
-
-       gtk_widget_show_all(toolbar);
-}
-
 static GtkWidget *compose_account_option_menu_create(Compose *compose)
 {
        GList *accounts;
@@ -5239,7 +5180,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
                else
                        name = g_strdup_printf("%s: %s",
                                               ac->account_name, ac->address);
-               MENUITEM_ADD(menu, menuitem, name, ac);
+               MENUITEM_ADD(menu, menuitem, name, ac->account_id);
                g_free(name);
                gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
                                   GTK_SIGNAL_FUNC(account_activated),
@@ -5291,6 +5232,41 @@ static void compose_update_priority_menu_item(Compose * compose)
        }
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
 }      
+
+#if USE_GPGME 
+static void compose_set_gnupg_mode_cb(gpointer data,
+                                   guint action,
+                                   GtkWidget *widget)
+{
+       Compose *compose = (Compose *) data;
+       compose->gnupg_mode = action;
+}
+
+static void compose_update_gnupg_mode_menu_item(Compose * compose)
+{
+       GtkItemFactory *ifactory;
+       GtkWidget *menuitem = NULL;
+
+       ifactory = gtk_item_factory_from_widget(compose->menubar);
+       
+       switch (compose->gnupg_mode) {
+               case GNUPG_MODE_DETACH:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Mode/MIME");
+                       break;
+               case GNUPG_MODE_INLINE:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Mode/Inline");
+                       break;
+       }
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+       
+       if (compose->use_encryption == TRUE || compose->use_signing == TRUE)
+               menu_set_sensitive(ifactory, "/Message/Mode", TRUE);
+       else 
+               menu_set_sensitive(ifactory, "/Message/Mode", FALSE);
+}      
+#endif
  
 static void compose_set_template_menu(Compose *compose)
 {
@@ -5336,8 +5312,7 @@ void compose_reflect_prefs_pixmap_theme(void)
 
        for (cur = compose_list; cur != NULL; cur = cur->next) {
                compose = (Compose *)cur->data;
-               compose_toolbar_update(compose);
-               set_toolbar_style(compose);
+               toolbar_update(TOOLBAR_COMPOSE, compose);
        }
 }
 
@@ -5356,11 +5331,16 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
                                   tmpl->subject);
        if (tmpl->to && *tmpl->to != '\0')
                compose_entry_append(compose, tmpl->to, COMPOSE_TO);
+       if (tmpl->cc && *tmpl->cc != '\0')
+               compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
+
+       if (tmpl->bcc && *tmpl->bcc != '\0')
+               compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
 
        if (replace)
-               gtk_stext_clear(GTK_STEXT(compose->text));
+               gtkut_stext_clear(GTK_STEXT(compose->text));
 
-       if (compose->replyinfo == NULL) {
+       if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
                parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
                                               NULL, NULL);
        } else {
@@ -5369,12 +5349,18 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
                else
                        qmark = "> ";
 
-               parsed_str = compose_quote_fmt(compose, compose->replyinfo,
-                                              tmpl->value, qmark, NULL);
+               if (compose->replyinfo != NULL)
+                       parsed_str = compose_quote_fmt(compose, compose->replyinfo,
+                                                      tmpl->value, qmark, NULL);
+               else if (compose->fwdinfo != NULL)
+                       parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
+                                                      tmpl->value, qmark, NULL);
+               else
+                       parsed_str = NULL;
        }
 
-       if (replace && parsed_str && prefs_common.auto_sig)
-               compose_insert_sig(compose);
+       if (replace && parsed_str && compose->account->auto_sig)
+               compose_insert_sig(compose, FALSE);
 
        if (replace && parsed_str) {
                gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
@@ -5406,6 +5392,7 @@ static void compose_destroy(Compose *compose)
 
        procmsg_msginfo_free(compose->targetinfo);
        procmsg_msginfo_free(compose->replyinfo);
+       procmsg_msginfo_free(compose->fwdinfo);
 
        g_free(compose->replyto);
        g_free(compose->cc);
@@ -5413,6 +5400,8 @@ static void compose_destroy(Compose *compose)
        g_free(compose->newsgroups);
        g_free(compose->followup_to);
 
+       g_free(compose->ml_post);
+
        g_free(compose->inreplyto);
        g_free(compose->references);
        g_free(compose->msgid);
@@ -5420,6 +5409,10 @@ static void compose_destroy(Compose *compose)
 
        if (compose->redirect_filename)
                g_free(compose->redirect_filename);
+       if (compose->undostruct)
+               undo_destroy(compose->undostruct);
+
+       g_free(compose->sig_str);
 
        g_free(compose->exteditor_file);
 
@@ -5441,8 +5434,7 @@ static void compose_destroy(Compose *compose)
 
        gtk_widget_destroy(compose->paned);
 
-       TOOLBAR_DESTROY_ITEMS(compose->toolbar->t_item_list);
-       TOOLBAR_DESTROY_ACTIONS(compose->toolbar->t_action_list);
+       toolbar_destroy(compose->toolbar);
        g_free(compose->toolbar);
        g_free(compose);
 
@@ -5504,9 +5496,11 @@ static void compose_attach_property(Compose *compose)
 
        optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
        if (ainfo->encoding == ENC_UNKNOWN)
-               gtk_option_menu_set_history(optmenu, ENC_BASE64);
+               menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
+                                   GINT_TO_POINTER(ENC_BASE64));
        else
-               gtk_option_menu_set_history(optmenu, ainfo->encoding);
+               menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
+                                   GINT_TO_POINTER(ainfo->encoding));
 
        gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
                           ainfo->content_type ? ainfo->content_type : "");
@@ -5627,7 +5621,7 @@ static void compose_attach_property_create(gboolean *cancelled)
        window = gtk_window_new(GTK_WINDOW_DIALOG);
        gtk_widget_set_usize(window, 480, -1);
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
-       gtk_window_set_title(GTK_WINDOW(window), _("Property"));
+       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);
        gtk_signal_connect(GTK_OBJECT(window), "delete_event",
@@ -5695,8 +5689,10 @@ static void compose_attach_property_create(gboolean *cancelled)
 #if 0
        gtk_widget_set_sensitive(menuitem, FALSE);
 #endif
-       MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
-       gtk_widget_set_sensitive(menuitem, FALSE);
+       MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
+                    ENC_QUOTED_PRINTABLE);
+       gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
+
        MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
 
        gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
@@ -5803,20 +5799,20 @@ static void compose_exec_ext_editor(Compose *compose)
                close(pipe_fds[0]);
 
                if (compose_write_body_to_file(compose, tmp) < 0) {
-                       fd_write(pipe_fds[1], "2\n", 2);
+                       fd_write_all(pipe_fds[1], "2\n", 2);
                        _exit(1);
                }
 
                pid_ed = compose_exec_ext_editor_real(tmp);
                if (pid_ed < 0) {
-                       fd_write(pipe_fds[1], "1\n", 2);
+                       fd_write_all(pipe_fds[1], "1\n", 2);
                        _exit(1);
                }
 
                /* wait until editor is terminated */
                waitpid(pid_ed, NULL, 0);
 
-               fd_write(pipe_fds[1], "0\n", 2);
+               fd_write_all(pipe_fds[1], "0\n", 2);
 
                close(pipe_fds[1]);
                _exit(0);
@@ -5853,7 +5849,7 @@ static gint compose_exec_ext_editor_real(const gchar *file)
                g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
        } else {
                if (prefs_common.ext_editor_cmd)
-                       g_warning(_("External editor command line is invalid: `%s'\n"),
+                       g_warning("External editor command line is invalid: `%s'\n",
                                  prefs_common.ext_editor_cmd);
                g_snprintf(buf, sizeof(buf), def_cmd, file);
        }
@@ -5892,8 +5888,8 @@ static gboolean compose_ext_editor_kill(Compose *compose)
                        if (kill(pgid, SIGTERM) < 0) perror("kill");
                        waitpid(compose->exteditor_pid, NULL, 0);
 
-                       g_warning(_("Terminated process group id: %d"), -pgid);
-                       g_warning(_("Temporary file: %s"),
+                       g_warning("Terminated process group id: %d", -pgid);
+                       g_warning("Temporary file: %s",
                                  compose->exteditor_file);
 
                        compose_set_ext_editor_sensitive(compose, TRUE);
@@ -5950,13 +5946,13 @@ static void compose_input_cb(gpointer data, gint source,
                if (unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '1') {     /* failed */
-               g_warning(_("Couldn't exec external editor\n"));
+               g_warning("Couldn't exec external editor\n");
                if (unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '2') {
-               g_warning(_("Couldn't write to file\n"));
+               g_warning("Couldn't write to file\n");
        } else if (buf[0] == '3') {
-               g_warning(_("Pipe read failed\n"));
+               g_warning("Pipe read failed\n");
        }
 
        close(source);
@@ -6106,76 +6102,18 @@ static gboolean compose_edit_size_alloc(GtkEditable *widget,
        return TRUE;
 }
 
-static void toolbar_send_cb(GtkWidget *widget, gpointer data)
-{
-       compose_send_cb(data, 0, NULL);
-}
-
-static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
-{
-       compose_send_later_cb(data, 0, NULL);
-}
-
-static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
-{
-       compose_draft_cb(data, 0, NULL);
-}
-
-static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
-{
-       compose_insert_file_cb(data, 0, NULL);
-}
-
-static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
-{
-       compose_attach_cb(data, 0, NULL);
-}
-
-static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
-{
-       Compose *compose = (Compose *)data;
-
-       compose_insert_sig(compose);
-}
-
-static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
-{
-       Compose *compose = (Compose *)data;
-
-       compose_exec_ext_editor(compose);
-}
-
-static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
-{
-       Compose *compose = (Compose *)data;
-
-       compose_wrap_line(compose);
-}
-
-static void toolbar_address_cb(GtkWidget *widget, gpointer data)
-{
-       compose_address_cb(data, 0, NULL);
-}
-
-static void toolbar_actions_execute_cb(GtkWidget *widget,
-                                      gpointer   data)
-{
-       Compose *compose = (Compose*)data;
-
-       toolbar_action_execute(widget, compose->toolbar->t_action_list, data, TOOLBAR_COMPOSE);
-}
-
 static void account_activated(GtkMenuItem *menuitem, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
        PrefsAccount *ac;
 
-       ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
+       ac = account_find_from_id(
+               GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
        g_return_if_fail(ac != NULL);
 
        if (ac != compose->account)
-               compose_select_account(compose, ac);
+               compose_select_account(compose, ac, FALSE);
 }
 
 static void attach_selected(GtkCList *clist, gint row, gint column,
@@ -6226,6 +6164,18 @@ static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
        }
 }
 
+static void compose_allow_user_actions (Compose *compose, gboolean allow)
+{
+       GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
+       toolbar_comp_set_sensitive(compose, allow);
+       menu_set_sensitive(ifactory, "/File", allow);
+       menu_set_sensitive(ifactory, "/Edit", allow);
+       menu_set_sensitive(ifactory, "/Spelling", allow);
+       menu_set_sensitive(ifactory, "/Message", allow);
+       menu_set_sensitive(ifactory, "/Tools", allow);
+       menu_set_sensitive(ifactory, "/Help", allow);
+}
+
 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
 {
        Compose *compose = (Compose *)data;
@@ -6235,9 +6185,13 @@ static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
                if (alertpanel(_("Offline warning"), 
                               _("You're working offline. Override?"),
                               _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
-               return;
-
+                       return;
+       
+       compose_allow_user_actions (compose, FALSE);
+       compose->sending = TRUE;
        val = compose_send(compose);
+       compose_allow_user_actions (compose, TRUE);
+       compose->sending = FALSE;
 
        if (val == 0) gtk_widget_destroy(compose->window);
 }
@@ -6252,6 +6206,11 @@ static void compose_send_later_cb(gpointer data, guint action,
        if (!val) gtk_widget_destroy(compose->window);
 }
 
+void compose_draft (gpointer data) 
+{
+       compose_draft_cb(data, 0, NULL);        
+}
+
 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 {
        Compose *compose = (Compose *)data;
@@ -6288,21 +6247,18 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
        if (compose->mode == COMPOSE_REEDIT) {
                compose_remove_reedit_target(compose);
-               if (compose->targetinfo &&
-                   compose->targetinfo->folder != draft)
-                       folderview_update_item(compose->targetinfo->folder,
-                                              TRUE);
        }
 
-       newmsginfo = folder_item_fetch_msginfo(draft, msgnum);
-       procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
-       MSG_SET_TMP_FLAGS(newmsginfo->flags, MSG_DRAFT);
-       folderview_update_item(draft, TRUE);
-       procmsg_msginfo_free(newmsginfo);
+       newmsginfo = folder_item_get_msginfo(draft, msgnum);
+       if (newmsginfo) {
+               procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
+               procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
+               procmsg_msginfo_free(newmsginfo);
+       }
        
        lock = FALSE;
 
-       /* 0: quit editing  1: keep editing */
+       /* 0: quit editing  1: keep editing  2: keep editing (autosave) */
        if (action == 0)
                gtk_widget_destroy(compose->window);
        else {
@@ -6326,6 +6282,10 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                compose->targetinfo->mtime = s.st_mtime;
                compose->targetinfo->folder = draft;
                compose->mode = COMPOSE_REEDIT;
+               
+               if (action == 2) {
+                       compose->autosaved_draft = compose->targetinfo;
+               }
        }
 }
 
@@ -6372,10 +6332,21 @@ static void compose_insert_file_cb(gpointer data, guint action,
        }
 }
 
+static void compose_insert_sig_cb(gpointer data, guint action,
+                                 GtkWidget *widget)
+{
+       Compose *compose = (Compose *)data;
+
+       compose_insert_sig(compose, FALSE);
+}
+
 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
                              gpointer data)
 {
-       compose_close_cb(data, 0, NULL);
+       Compose *compose = (Compose *)data;
+       if (compose->sending)
+               return TRUE;
+       compose_close_cb(compose, 0, NULL);
        return TRUE;
 }
 
@@ -6449,6 +6420,8 @@ static void compose_ext_editor_cb(gpointer data, guint action,
 
 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
 {
+       if (compose->sending)
+               return;
        compose_destroy(compose);
 }
 
@@ -6718,6 +6691,8 @@ static void compose_toggle_sign_cb(gpointer data, guint action,
                compose->use_signing = TRUE;
        else
                compose->use_signing = FALSE;
+
+       compose_update_gnupg_mode_menu_item(compose);
 }
 
 static void compose_toggle_encrypt_cb(gpointer data, guint action,
@@ -6729,6 +6704,18 @@ static void compose_toggle_encrypt_cb(gpointer data, guint action,
                compose->use_encryption = TRUE;
        else
                compose->use_encryption = FALSE;
+               
+       compose_update_gnupg_mode_menu_item(compose);
+}
+
+static void activate_gnupg_mode (Compose *compose, PrefsAccount *account) 
+{
+       if (account->default_gnupg_mode)
+               compose->gnupg_mode = GNUPG_MODE_INLINE;
+       else
+               compose->gnupg_mode = GNUPG_MODE_DETACH;
+               
+       compose_update_gnupg_mode_menu_item(compose);
 }
 #endif /* USE_GPGME */
 
@@ -6929,9 +6916,6 @@ static void text_activated(GtkWidget *widget, Compose *compose)
        compose_send_control_enter(compose);
 }
 
-#define EDITABLE_LENGTH(x) \
-       strlen(gtk_editable_get_chars(x,0,-1))
-
 static void text_inserted(GtkWidget *widget, const gchar *text,
                          gint length, gint *position, Compose *compose)
 {
@@ -6969,8 +6953,8 @@ static void text_inserted(GtkWidget *widget, const gchar *text,
 
        
        if (prefs_common.autosave && 
-           EDITABLE_LENGTH(editable) % prefs_common.autosave_length == 0)
-               compose_draft_cb((gpointer)compose, 1, NULL);
+           gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
+               compose_draft_cb((gpointer)compose, 2, NULL);
 }
 
 static gboolean compose_send_control_enter(Compose *compose)
@@ -6995,8 +6979,11 @@ static gboolean compose_send_control_enter(Compose *compose)
        ifactory = gtk_item_factory_from_widget(compose->menubar);
        send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
        list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
+       if (!list)
+               return FALSE;
+
        accel = (GtkAccelEntry *)list->data;
-       if (accel->accelerator_key == kev->keyval &&
+       if (accel && accel->accelerator_key == kev->keyval &&
            (accel->accelerator_mods & ~ignored_mods) ==
            (kev->state & ~ignored_mods)) {
                compose_send_cb(compose, 0, NULL);
@@ -7044,28 +7031,3 @@ static void compose_check_forwards_go(Compose *compose)
 }
 #endif
 
-static void set_toolbar_style(Compose *compose)
-{
-       switch (prefs_common.toolbar_style) {
-       case TOOLBAR_NONE:
-               gtk_widget_hide(compose->handlebox);
-               break;
-       case TOOLBAR_ICON:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
-                                     GTK_TOOLBAR_ICONS);
-               break;
-       case TOOLBAR_TEXT:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
-                                     GTK_TOOLBAR_TEXT);
-               break;
-       case TOOLBAR_BOTH:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
-                                     GTK_TOOLBAR_BOTH);
-               break;
-       }
-       
-       if (prefs_common.toolbar_style != TOOLBAR_NONE) {
-               gtk_widget_show(compose->handlebox);
-               gtk_widget_queue_resize(compose->handlebox);
-       }
-}