* src/compose.c
[claws.git] / src / compose.c
index db88f4406a83169a8d99139c251ca80a5a3bd493..8ddf544014047ebcd68b47fdabbf3abed1de7f2c 100644 (file)
 #include "template.h"
 #include "undo.h"
 #include "foldersel.h"
+#include "toolbar.h"
 
 #if USE_GPGME
 #  include "rfc2015.h"
@@ -165,6 +166,10 @@ 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 void compose_toolbar_set_sensitive       (Compose        *compose,
+                                                gboolean        sensitive);
+
 static GtkWidget *compose_account_option_menu_create
                                                (Compose        *compose);
 static void compose_set_template_menu          (Compose        *compose);
@@ -189,6 +194,7 @@ 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);
@@ -309,7 +315,11 @@ 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);
 
@@ -418,6 +428,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);
@@ -467,7 +483,7 @@ static void text_inserted           (GtkWidget      *widget,
                                         gint           *position,
                                         Compose        *compose);
 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
-                                 gboolean to_all,
+                                 gboolean to_all, gboolean to_ml,
                                  gboolean ignore_replyto,
                                  gboolean followup_and_reply_to,
                                  const gchar *body);
@@ -651,6 +667,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>"},
@@ -715,10 +733,6 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
        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);
@@ -774,14 +788,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)
@@ -808,10 +814,11 @@ Compose *compose_new_followup_and_replyto(PrefsAccount *account,
 */
 
 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
-                  gboolean ignore_replyto, const gchar *body)
+                  gboolean to_ml, gboolean ignore_replyto, 
+                  const gchar *body)
 {
-       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
-                             body);
+       compose_generic_reply(msginfo, quote, to_all, to_ml, 
+                             ignore_replyto, FALSE, body);
 }
 
 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
@@ -819,12 +826,12 @@ void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
                                   gboolean ignore_replyto,
                                   const gchar *body)
 {
-       compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
-                             body);
+       compose_generic_reply(msginfo, quote, to_all, FALSE, 
+                             ignore_replyto, TRUE, body);
 }
 
 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
-                                 gboolean to_all,
+                                 gboolean to_all, gboolean to_ml,
                                  gboolean ignore_replyto,
                                  gboolean followup_and_reply_to,
                                  const gchar *body)
@@ -882,16 +889,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;
        
@@ -910,8 +912,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, 
+                               ignore_replyto, followup_and_reply_to);
        compose_show_first_last_header(compose, TRUE);
 
        text = GTK_STEXT(compose->text);
@@ -926,7 +928,7 @@ 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);
        }
@@ -960,13 +962,13 @@ 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 (!account) 
+               account = msginfo->folder->folder->account;
        if (!account && msginfo->to && prefs_common.forward_account_autosel) {
                gchar *to;
                Xstrdup_a(to, msginfo->to, return NULL);
@@ -995,7 +997,6 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
        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);
 
@@ -1023,6 +1024,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)
@@ -1030,10 +1036,12 @@ 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)
@@ -1088,7 +1096,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);
@@ -1139,7 +1146,7 @@ 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;
 
@@ -1197,8 +1204,10 @@ void compose_reedit(MsgInfo *msginfo)
        if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
                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);
@@ -1264,15 +1273,17 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
 #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/Request Return Receipt", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
        
-       gtk_widget_set_sensitive(compose->insert_btn, FALSE);
-       gtk_widget_set_sensitive(compose->attach_btn, FALSE);
-       gtk_widget_set_sensitive(compose->sig_btn, FALSE);
-       gtk_widget_set_sensitive(compose->exteditor_btn, FALSE);
-       gtk_widget_set_sensitive(compose->linewrap_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);
+       gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
+       gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
 
         return compose;
 }
@@ -1354,97 +1365,58 @@ void compose_entry_select (Compose *compose, const gchar *mailto)
 
 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, FALSE},
+                                      {"References:",  NULL, FALSE},
+                                      {"Bcc:",         NULL, FALSE},
+                                      {"Newsgroups:",  NULL, FALSE},
+                                      {"Followup-To:", NULL, FALSE},
+                                      {"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;
@@ -1465,26 +1437,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;
@@ -1512,7 +1464,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;
@@ -1658,7 +1626,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 ignore_replyto,
                                    gboolean followup_and_reply_to)
 {
        GSList *cc_list = NULL;
@@ -1670,28 +1639,34 @@ 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 (compose->account->protocol != A_NNTP || followup_and_reply_to) {
+               if (!compose->replyto && to_ml && compose->ml_post)
+                       compose_entry_append(compose,
+                                          compose->ml_post,
+                                          COMPOSE_TO);
+               else if (!(to_all || ignore_replyto)
+                        && 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 && !ignore_replyto)
+                                ? compose->replyto
+                                : msginfo->from ? msginfo->from : "",
+                                COMPOSE_TO);
+       } else {
                if (ignore_replyto)
                        compose_entry_append
                                (compose, msginfo->from ? msginfo->from : "",
                                 COMPOSE_TO);
                else {
-                       if (compose->followup_to && !strncmp(compose->followup_to,"poster",6)) {
+                       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 {
@@ -1722,6 +1697,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) {
@@ -1733,16 +1709,9 @@ 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, msginfo->to);
        cc_list = address_list_append(cc_list, compose->cc);
 
        to_table = g_hash_table_new(g_str_hash, g_str_equal);
@@ -1797,7 +1766,9 @@ static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
        SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
 
        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 */
@@ -2036,6 +2007,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                procmime_mimeinfo_free_all(mimeinfo);
                return;
        }
+
        if (IS_FIRST_PART_TEXT(child))
                child = child->next;
 
@@ -2046,11 +2018,17 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                        child = procmime_mimeinfo_next(child);
                        continue;
                }
-
+               if(child->parent && child->parent->parent
+               && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
+               && child->mime_type == MIME_TEXT) {
+                       /* this is the main text part of a signed message */
+                       child = procmime_mimeinfo_next(child);
+                       continue;
+               }
                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."));
-               else
+               else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
                        compose_attach_append
                                (compose, outfile,
                                 child->filename ? child->filename : child->name,
@@ -2702,6 +2680,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
@@ -2718,6 +2697,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
@@ -2772,6 +2752,8 @@ 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 */
 }
 
@@ -2846,6 +2828,7 @@ gint compose_send(Compose *compose)
        gint msgnum;
        FolderItem *folder;
        gint val;
+       gchar *msgpath;
 
        if (compose_check_entries(compose, TRUE) == FALSE)
                return -1;
@@ -2856,10 +2839,12 @@ gint compose_send(Compose *compose)
                return -1;
        }
        
-       val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
+       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);
+       folder_update_item(folder, TRUE);
 
        return val;
 }
@@ -2874,7 +2859,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;
 
@@ -2908,13 +2892,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;
@@ -2928,14 +2916,7 @@ gint compose_send(Compose *compose)
        }
 
        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);
@@ -2966,7 +2947,7 @@ gint compose_send(Compose *compose)
                if (compose->mode == COMPOSE_REEDIT) {
                        compose_remove_reedit_target(compose);
                        if (compose->targetinfo)
-                               folderview_update_item
+                               folder_update_item
                                        (compose->targetinfo->folder, TRUE);
                }
                /* save message to outbox */
@@ -2979,7 +2960,7 @@ gint compose_send(Compose *compose)
                                alertpanel_error
                                        (_("Can't save the message to Sent."));
                        else
-                               folderview_update_item(outbox, TRUE);
+                               folder_update_item(outbox, TRUE);
                }
        }
 
@@ -3285,6 +3266,13 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                        out_codeset = CS_ISO_8859_1;
                encoding = procmime_get_encoding_for_charset(out_codeset);
 
+#if USE_GPGME
+               if (!is_draft &&
+                   compose->use_signing && !compose->gnupg_mode &&
+                   encoding == ENC_8BIT)
+                       encoding = ENC_BASE64;
+#endif
+
                src_codeset = conv_get_current_charset_str();
                /* if current encoding is US-ASCII, set it the same as
                   outgoing one to prevent code conversion failure */
@@ -3315,8 +3303,36 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        }
        g_free(chars);
 
+       /* Canonicalize line endings in the message text */
+       {
+               gchar *canon_buf, *out;
+               const gchar *p;
+               guint new_len = 0;
+
+               for (p = buf ; *p; ++p) {
+                       if (*p != '\r') {
+                               ++new_len;
+                               if (*p == '\n')
+                                       ++new_len;
+                       }
+               }
+
+               out = canon_buf = g_new(gchar, new_len + 1);
+               for (p = buf; *p; ++p) {
+                       if (*p != '\r') {
+                               if (*p == '\n')
+                                       *out++ = '\r';
+                               *out++ = *p;
+                       }
+               }
+               *out = '\0';
+
+               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);
@@ -3388,7 +3404,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        if (is_draft)
                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);
@@ -3396,7 +3412,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 ||
@@ -3407,7 +3423,7 @@ 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;
                }
@@ -3486,7 +3502,7 @@ void compose_remove_draft(Compose *compose)
 
        if (procmsg_msg_exist(msginfo)) {
                folder_item_remove_msg(drafts, msginfo->msgnum);
-               folderview_update_item(drafts, TRUE);
+               folder_update_item(drafts, TRUE);
        }
 
 }
@@ -3508,7 +3524,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;
        
@@ -3526,8 +3541,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())) {
@@ -3540,7 +3553,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;
@@ -3616,21 +3629,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);
@@ -3701,11 +3714,11 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                compose_remove_reedit_target(compose);
                if (compose->targetinfo &&
                    compose->targetinfo->folder != queue)
-                       folderview_update_item
+                       folder_update_item
                                (compose->targetinfo->folder, TRUE);
        }
 
-       folderview_update_item(queue, TRUE);
+       folder_update_item(queue, TRUE);
 
        if ((msgnum != NULL) && (item != NULL)) {
                *msgnum = num;
@@ -3779,6 +3792,9 @@ static void compose_write_attach(Compose *compose, FILE *fp)
                                fputc('\n', fp);
                        }
                        break;
+               default:
+                       debug_print("Tried to write attachment in unsupported encoding type\n");
+                       break;
                }
 
                fclose(attach_fp);
@@ -3891,17 +3907,17 @@ 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, "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 */
@@ -3935,18 +3951,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
@@ -4481,7 +4499,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);
@@ -4600,7 +4618,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;
@@ -4623,7 +4640,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);
@@ -4763,7 +4779,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);
@@ -4792,16 +4808,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;
                }
@@ -4892,10 +4901,12 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        compose->replyinfo  = 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;
@@ -4924,7 +4935,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 #if USE_ASPELL
        
        menu_set_sensitive(ifactory, "/Spelling", FALSE);
-        if (prefs_common.enable_aspell) {
+        if (prefs_common.enable_aspell && 
+           strcmp(prefs_common.dictionary, _("None"))) {
                gtkaspell = gtkaspell_new((const gchar*)prefs_common.dictionary,
                                          conv_get_current_charset_str(),
                                          prefs_common.misspelled_col,
@@ -4984,6 +4996,10 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        /* Priority */
        compose->priority = PRIORITY_NORMAL;
        compose_update_priority_menu_item(compose);
+       
+#if USE_GPGME
+       activate_gnupg_mode(compose, account);
+#endif 
 
        set_toolbar_style(compose);
 
@@ -4992,20 +5008,85 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        return compose;
 }
 
-static void compose_toolbar_create(Compose *compose, GtkWidget *container)
+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;
-       GtkWidget *send_btn;
-       GtkWidget *sendl_btn;
-       GtkWidget *draft_btn;
-       GtkWidget *insert_btn;
-       GtkWidget *attach_btn;
-       GtkWidget *sig_btn;
-       GtkWidget *exteditor_btn;
-       GtkWidget *linewrap_btn;
-       GtkWidget *addrbook_btn;
+       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);
@@ -5013,101 +5094,140 @@ static void compose_toolbar_create(Compose *compose, GtkWidget *container)
        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) {
 
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
-       send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                          _("Send"),
-                                          _("Send message"),
-                                          "Send",
-                                          icon_wid, toolbar_send_cb, compose);
-
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
-       sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                          _("Send later"),
-                                          _("Put into queue folder and send later"),
-                                          "Send later",
-                                          icon_wid, toolbar_send_later_cb,
-                                          compose);
+               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;
+               }
+       }
 
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
-       draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                           _("Draft"),
-                                           _("Save to draft folder"),
-                                           "Draft",
-                                           icon_wid, toolbar_draft_cb,
-                                           compose);
-
-       gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
-
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
-       insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                            _("Insert"),
-                                            _("Insert file"),
-                                            "Insert",
-                                            icon_wid, toolbar_insert_cb,
-                                            compose);
-
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
-       attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                            _("Attach"),
-                                            _("Attach file"),
-                                            "Attach",
-                                            icon_wid, toolbar_attach_cb,
-                                            compose);
-
-       gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
-
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
-       sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                         _("Signature"),
-                                         _("Insert signature"),
-                                         "Signature",
-                                         icon_wid, toolbar_sig_cb, compose);
-
-       gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
-
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
-       exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                               _("Editor"),
-                                               _("Edit with external editor"),
-                                               "Editor",
-                                               icon_wid,
-                                               toolbar_ext_editor_cb,
-                                               compose);
-
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
-       linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                              _("Linewrap"),
-                                              _("Wrap all long lines"),
-                                              "Linewrap",
-                                              icon_wid,
-                                              toolbar_linewrap_cb,
-                                              compose);
-
-       gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
-
-       icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
-       addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
-                                              _("Address"),
-                                              _("Address book"),
-                                              "Address",
-                                              icon_wid, toolbar_address_cb,
-                                              compose);
-
-       compose->toolbar       = toolbar;
-       compose->send_btn      = send_btn;
-       compose->sendl_btn     = sendl_btn;
-       compose->draft_btn     = draft_btn;
-       compose->insert_btn    = insert_btn;
-       compose->attach_btn    = attach_btn;
-       compose->sig_btn       = sig_btn;
-       compose->exteditor_btn = exteditor_btn;
-       compose->linewrap_btn  = linewrap_btn;
-       compose->addrbook_btn  = addrbook_btn;
+       compose->toolbar->toolbar = toolbar;
 
        gtk_widget_show_all(toolbar);
 }
 
+static void compose_toolbar_set_sensitive (Compose * compose, gboolean sensitive)
+{
+       GSList *items = compose->toolbar->t_action_list;
+       if (compose->toolbar->send_btn)
+               gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
+       if (compose->toolbar->sendl_btn)
+               gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
+       if (compose->toolbar->draft_btn )
+               gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
+       if (compose->toolbar->insert_btn )
+               gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
+       if (compose->toolbar->attach_btn)
+               gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
+       if (compose->toolbar->sig_btn)
+               gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
+       if (compose->toolbar->exteditor_btn)
+               gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
+       if (compose->toolbar->linewrap_btn)
+               gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
+       if (compose->toolbar->addrbook_btn)
+               gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
+       for (; items != NULL; items = g_slist_next(items)) {
+               ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
+               gtk_widget_set_sensitive(item->widget, sensitive);
+       }
+}
+
 static GtkWidget *compose_account_option_menu_create(Compose *compose)
 {
        GList *accounts;
@@ -5190,6 +5310,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)
 {
@@ -5235,9 +5390,7 @@ void compose_reflect_prefs_pixmap_theme(void)
 
        for (cur = compose_list; cur != NULL; cur = cur->next) {
                compose = (Compose *)cur->data;
-               gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
-               compose->toolbar = NULL;
-               compose_toolbar_create(compose, compose->handlebox);
+               compose_toolbar_update(compose);
                set_toolbar_style(compose);
        }
 }
@@ -5257,6 +5410,11 @@ 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));
@@ -5314,6 +5472,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);
@@ -5342,6 +5502,9 @@ 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);
+       g_free(compose->toolbar);
        g_free(compose);
 
        compose_list = g_list_remove(compose_list, compose);
@@ -5886,14 +6049,14 @@ static void compose_set_ext_editor_sensitive(Compose *compose,
        menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
                           sensitive);
 
-       gtk_widget_set_sensitive(compose->text,          sensitive);
-       gtk_widget_set_sensitive(compose->send_btn,      sensitive);
-       gtk_widget_set_sensitive(compose->sendl_btn,     sensitive);
-       gtk_widget_set_sensitive(compose->draft_btn,     sensitive);
-       gtk_widget_set_sensitive(compose->insert_btn,    sensitive);
-       gtk_widget_set_sensitive(compose->sig_btn,       sensitive);
-       gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
-       gtk_widget_set_sensitive(compose->linewrap_btn,  sensitive);
+       gtk_widget_set_sensitive(compose->text,                   sensitive);
+       gtk_widget_set_sensitive(compose->toolbar->send_btn,      sensitive);
+       gtk_widget_set_sensitive(compose->toolbar->sendl_btn,     sensitive);
+       gtk_widget_set_sensitive(compose->toolbar->draft_btn,     sensitive);
+       gtk_widget_set_sensitive(compose->toolbar->insert_btn,    sensitive);
+       gtk_widget_set_sensitive(compose->toolbar->sig_btn,       sensitive);
+       gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
+       gtk_widget_set_sensitive(compose->toolbar->linewrap_btn,  sensitive);
 }
 
 /**
@@ -6055,6 +6218,14 @@ 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;
@@ -6116,6 +6287,17 @@ 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);
+       compose_toolbar_set_sensitive(compose, allow);
+       menu_set_sensitive(ifactory, "/File", allow);
+       menu_set_sensitive(ifactory, "/Edit", 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;
@@ -6125,9 +6307,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);
 }
@@ -6142,6 +6328,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;
@@ -6180,14 +6371,14 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
                compose_remove_reedit_target(compose);
                if (compose->targetinfo &&
                    compose->targetinfo->folder != draft)
-                       folderview_update_item(compose->targetinfo->folder,
+                       folder_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);
+       folder_update_item(draft, TRUE);
        procmsg_msginfo_free(newmsginfo);
        
        lock = FALSE;
@@ -6265,7 +6456,10 @@ static void compose_insert_file_cb(gpointer data, guint action,
 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;
 }
 
@@ -6339,6 +6533,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);
 }
 
@@ -6608,6 +6804,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,
@@ -6619,6 +6817,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 */
 
@@ -6819,9 +7029,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)
 {
@@ -6859,7 +7066,7 @@ static void text_inserted(GtkWidget *widget, const gchar *text,
 
        
        if (prefs_common.autosave && 
-           EDITABLE_LENGTH(editable) % prefs_common.autosave_length == 0)
+           gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
                compose_draft_cb((gpointer)compose, 1, NULL);
 }
 
@@ -6941,15 +7148,15 @@ static void set_toolbar_style(Compose *compose)
                gtk_widget_hide(compose->handlebox);
                break;
        case TOOLBAR_ICON:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
+               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
                                      GTK_TOOLBAR_ICONS);
                break;
        case TOOLBAR_TEXT:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
+               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
                                      GTK_TOOLBAR_TEXT);
                break;
        case TOOLBAR_BOTH:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
+               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
                                      GTK_TOOLBAR_BOTH);
                break;
        }