add a forgotten '#if USE_GPGME ... #endif'
[claws.git] / src / compose.c
index 5805df0527c5aeaace0f21e1e534a06d45f0a099..62bf4c7dac01f34460c63a100d751007994c14fd 100644 (file)
@@ -148,6 +148,20 @@ typedef enum
        PRIORITY_LOWEST
 } PriorityLevel;
 
+#if USE_GPGME
+typedef enum
+{
+       SIG_MODE_DETACH,
+       SIG_MODE_CLEAR
+} ComposeSigMode;
+
+typedef enum
+{
+       ENC_MODE_DETACH,
+       ENC_MODE_ASCII
+} ComposeEncMode;
+#endif
+
 #define B64_LINE_SIZE          57
 #define B64_BUFFSIZE           77
 
@@ -194,6 +208,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);
@@ -427,6 +442,16 @@ static void compose_toggle_sign_cb (gpointer        data,
 static void compose_toggle_encrypt_cb  (gpointer        data,
                                         guint           action,
                                         GtkWidget      *widget);
+static void compose_set_sigmode_cb     (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
+static void compose_set_encmode_cb     (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
+static void compose_update_sigmode_menu_item(Compose * compose);
+static void compose_update_encmode_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);
@@ -476,7 +501,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);
@@ -659,7 +684,13 @@ static GtkItemFactoryEntry compose_entries[] =
 #if USE_GPGME
        {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/Si_gn"),         NULL, compose_toggle_sign_cb   , 0, "<ToggleItem>"},
+       {N_("/_Message/Sign mode"),             NULL,           NULL,   0, "<Branch>"}, 
+       {N_("/_Message/Sign mode/MIME"), NULL,  compose_set_sigmode_cb,   SIG_MODE_DETACH, "<RadioItem>"},      
+       {N_("/_Message/Sign mode/Clear"),NULL,  compose_set_sigmode_cb,   SIG_MODE_CLEAR, "/Message/Sign mode/MIME"},   
        {N_("/_Message/_Encrypt"),      NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
+       {N_("/_Message/Encrypt mode"),          NULL,           NULL,   0, "<Branch>"}, 
+       {N_("/_Message/Encrypt mode/MIME"), NULL, compose_set_encmode_cb,   ENC_MODE_DETACH, "<RadioItem>"},    
+       {N_("/_Message/Encrypt mode/ASCII"),NULL, compose_set_encmode_cb,   ENC_MODE_ASCII, "/Message/Encrypt mode/MIME"},      
 #endif /* USE_GPGME */
        {N_("/_Message/---"),           NULL,           NULL,   0, "<Separator>"},
        {N_("/_Message/_Priority"),     NULL,           NULL,   0, "<Branch>"},
@@ -724,10 +755,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);
@@ -783,14 +810,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)
@@ -817,10 +836,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,
@@ -828,12 +848,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)
@@ -891,16 +911,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;
        
@@ -919,8 +934,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);
@@ -935,7 +950,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);
        }
@@ -969,13 +984,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);
@@ -1004,7 +1019,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);
 
@@ -1032,6 +1046,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)
@@ -1039,10 +1058,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)
@@ -1097,7 +1118,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);
@@ -1148,7 +1168,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;
 
@@ -1206,8 +1226,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);
@@ -1273,6 +1295,8 @@ 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/Sign mode/", FALSE);
+       menu_set_sensitive(ifactory, "/Message/Encrypt mode/", FALSE);
 #endif
        menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
@@ -1363,97 +1387,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;
@@ -1474,26 +1459,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;
@@ -1521,7 +1486,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;
@@ -1667,7 +1648,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;
@@ -1679,28 +1661,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 {
@@ -1731,6 +1719,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) {
@@ -1742,16 +1731,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);
@@ -1806,7 +1788,10 @@ 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_sigmode_menu_item(compose);
+       compose_update_encmode_menu_item(compose);
+#endif
        compose_show_first_last_header(compose, TRUE);
 
 #if 0 /* NEW COMPOSE GUI */
@@ -2718,6 +2703,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
@@ -2734,6 +2720,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
@@ -2788,6 +2775,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 */
 }
 
@@ -2893,7 +2882,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;
 
@@ -2927,13 +2915,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;
@@ -2947,14 +2939,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);
@@ -3306,7 +3291,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
 
 #if USE_GPGME
                if (!is_draft &&
-                   compose->use_signing && !compose->account->clearsign &&
+                   compose->use_signing && !compose->sigmode &&
                    encoding == ENC_8BIT)
                        encoding = ENC_BASE64;
 #endif
@@ -3341,8 +3326,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->sigmode) {
                if (compose_clearsign_text(compose, &buf) < 0) {
                        g_warning("clearsign failed\n");
                        fclose(fp);
@@ -3414,7 +3427,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->sigmode) ||
            compose->use_encryption) {
                if (canonicalize_file_replace(file) < 0) {
                        unlink(file);
@@ -3422,7 +3435,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                }
        }
 
-       if (compose->use_signing && !compose->account->clearsign) {
+       if (compose->use_signing && !compose->sigmode) {
                GSList *key_list;
 
                if (compose_create_signers_list(compose, &key_list) < 0 ||
@@ -3433,7 +3446,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->encmode) < 0) {
                        unlink(file);
                        return -1;
                }
@@ -3534,7 +3547,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;
        
@@ -3552,8 +3564,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())) {
@@ -3566,7 +3576,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;
@@ -3642,21 +3652,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);
@@ -3805,6 +3815,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);
@@ -3917,17 +3930,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 */
@@ -3961,18 +3974,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
@@ -4507,7 +4522,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);
@@ -4626,7 +4641,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;
@@ -4649,7 +4663,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);
@@ -4789,7 +4802,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);
@@ -4818,16 +4831,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;
                }
@@ -4918,10 +4924,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;
@@ -4950,7 +4958,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,
@@ -5010,6 +5019,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);
 
@@ -5320,6 +5333,74 @@ 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_sigmode_cb(gpointer data,
+                                   guint action,
+                                   GtkWidget *widget)
+{
+       Compose *compose = (Compose *) data;
+       compose->sigmode = action;
+}
+
+static void compose_update_sigmode_menu_item(Compose * compose)
+{
+       GtkItemFactory *ifactory;
+       GtkWidget *menuitem = NULL;
+
+       ifactory = gtk_item_factory_from_widget(compose->menubar);
+       
+       switch (compose->sigmode) {
+               case SIG_MODE_DETACH:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Sign mode/MIME");
+                       break;
+               case SIG_MODE_CLEAR:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Sign mode/Clear");
+                       break;
+       }
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+
+       if (compose->use_signing == TRUE)
+               menu_set_sensitive(ifactory, "/Message/Sign mode", TRUE);       
+       else
+               menu_set_sensitive(ifactory, "/Message/Sign mode", FALSE);      
+}      
+static void compose_set_encmode_cb(gpointer data,
+                                   guint action,
+                                   GtkWidget *widget)
+{
+       Compose *compose = (Compose *) data;
+       compose->encmode = action;
+}
+
+static void compose_update_encmode_menu_item(Compose * compose)
+{
+       GtkItemFactory *ifactory;
+       GtkWidget *menuitem = NULL;
+
+       ifactory = gtk_item_factory_from_widget(compose->menubar);
+       
+       switch (compose->encmode) {
+               case ENC_MODE_DETACH:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Encrypt mode/MIME");
+                       break;
+               case ENC_MODE_ASCII:
+                       menuitem = gtk_item_factory_get_item
+                               (ifactory, "/Message/Encrypt mode/ASCII");
+                       break;
+       }
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+       
+       if (compose->use_encryption == TRUE)
+               menu_set_sensitive(ifactory, "/Message/Encrypt mode", TRUE);            
+       else
+               menu_set_sensitive(ifactory, "/Message/Encrypt mode", FALSE);
+}      
+#endif
  
 static void compose_set_template_menu(Compose *compose)
 {
@@ -5385,6 +5466,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));
@@ -5442,6 +5528,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);
@@ -6296,6 +6384,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;
@@ -6767,6 +6860,8 @@ static void compose_toggle_sign_cb(gpointer data, guint action,
                compose->use_signing = TRUE;
        else
                compose->use_signing = FALSE;
+
+       compose_update_sigmode_menu_item(compose);
 }
 
 static void compose_toggle_encrypt_cb(gpointer data, guint action,
@@ -6778,6 +6873,24 @@ static void compose_toggle_encrypt_cb(gpointer data, guint action,
                compose->use_encryption = TRUE;
        else
                compose->use_encryption = FALSE;
+               
+       compose_update_encmode_menu_item(compose);
+}
+
+static void activate_gnupg_mode (Compose *compose, PrefsAccount *account) 
+{
+       if (account->clearsign)
+               compose->sigmode = SIG_MODE_CLEAR;
+       else
+               compose->sigmode = SIG_MODE_DETACH;
+       compose_update_sigmode_menu_item(compose);
+
+       if (account->ascii_armored)
+               compose->encmode = ENC_MODE_ASCII;
+       else
+               compose->encmode = ENC_MODE_DETACH;
+
+       compose_update_encmode_menu_item(compose); 
 }
 #endif /* USE_GPGME */
 
@@ -6978,9 +7091,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)
 {
@@ -7018,7 +7128,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);
 }