fix bug where the insert sig button would be effective only when auto_sig was set
[claws.git] / src / compose.c
index 7785cfa43391c8349116788772e9f815cf834c7b..729fb1850a6b9547624dca13dca574753bf688a2 100644 (file)
@@ -84,7 +84,7 @@
 #include "customheader.h"
 #include "prefs_common.h"
 #include "prefs_account.h"
-#include "prefs_actions.h"
+#include "action.h"
 #include "account.h"
 #include "filesel.h"
 #include "procheader.h"
@@ -196,11 +196,11 @@ static void compose_reply_set_entry               (Compose        *compose,
                                                 followup_and_reply_to);
 static void compose_reedit_set_entry           (Compose        *compose,
                                                 MsgInfo        *msginfo);
-static void compose_insert_sig                 (Compose        *compose);
+static void compose_insert_sig                 (Compose        *compose,
+                                                gboolean        replace);
+static gchar *compose_get_signature_str                (Compose        *compose);
 static void compose_insert_file                        (Compose        *compose,
                                                 const gchar    *file);
-static void compose_insert_command_output      (Compose        *compose,
-                                                const gchar    *cmdline);
 static void compose_attach_append              (Compose        *compose,
                                                 const gchar    *file,
                                                 const gchar    *type,
@@ -213,7 +213,8 @@ static void compose_wrap_line_all_full              (Compose        *compose,
                                                 gboolean        autowrap);
 static void compose_set_title                  (Compose        *compose);
 static void compose_select_account             (Compose        *compose,
-                                                PrefsAccount   *account);
+                                                PrefsAccount   *account,
+                                                gboolean        init);
 
 static PrefsAccount *compose_current_mail_account(void);
 /* static gint compose_send                    (Compose        *compose); */
@@ -246,7 +247,8 @@ static gint compose_write_headers           (Compose        *compose,
 static void compose_convert_header             (gchar          *dest,
                                                 gint            len,
                                                 gchar          *src,
-                                                gint            header_len);
+                                                gint            header_len,
+                                                gboolean        addr_field);
 static void compose_generate_msgid             (Compose        *compose,
                                                 gchar          *buf,
                                                 gint            len);
@@ -325,6 +327,9 @@ static void compose_attach_cb               (gpointer        data,
 static void compose_insert_file_cb     (gpointer        data,
                                         guint           action,
                                         GtkWidget      *widget);
+static void compose_insert_sig_cb      (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
 
 static void compose_close_cb           (gpointer        data,
                                         guint           action,
@@ -491,7 +496,7 @@ static GtkItemFactoryEntry compose_entries[] =
        {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
        {N_("/_File/_Attach file"),             "<control>M", compose_attach_cb,      0, NULL},
        {N_("/_File/_Insert file"),             "<control>I", compose_insert_file_cb, 0, NULL},
-       {N_("/_File/Insert si_gnature"),        "<control>G", compose_insert_sig,     0, NULL},
+       {N_("/_File/Insert si_gnature"),        "<control>G", compose_insert_sig_cb,  0, NULL},
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Close"),                   "<control>W", compose_close_cb, 0, NULL},
 
@@ -701,7 +706,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        gtk_stext_freeze(text);
 
        if (account->auto_sig)
-               compose_insert_sig(compose);
+               compose_insert_sig(compose, FALSE);
        gtk_editable_set_position(GTK_EDITABLE(text), 0);
        gtk_stext_set_point(text, 0);
 
@@ -964,7 +969,7 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        }
 
        if (account->auto_sig)
-               compose_insert_sig(compose);
+               compose_insert_sig(compose, FALSE);
 
        if (quote && prefs_common.linewrap_quote)
                compose_wrap_line_all(compose);
@@ -1074,7 +1079,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                }
 
        if (account->auto_sig)
-               compose_insert_sig(compose);
+               compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
                compose_wrap_line_all(compose);
@@ -1153,7 +1158,7 @@ Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
        }
 
        if (account->auto_sig)
-               compose_insert_sig(compose);
+               compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
                compose_wrap_line_all(compose);
@@ -1435,7 +1440,7 @@ void compose_toolbar_cb(gint action, gpointer data)
                compose_attach_cb(compose, 0, NULL);
                break;
        case A_SIG:
-               compose_insert_sig(compose);
+               compose_insert_sig(compose, FALSE);
                break;
        case A_EXTEDITOR:
                compose_ext_editor_cb(compose, 0, NULL);
@@ -1486,11 +1491,11 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
 {
        static HeaderEntry hentry[] = {{"Reply-To:",    NULL, TRUE},
-                                      {"Cc:",          NULL, FALSE},
+                                      {"Cc:",          NULL, TRUE},
                                       {"References:",  NULL, FALSE},
-                                      {"Bcc:",         NULL, FALSE},
-                                      {"Newsgroups:",  NULL, FALSE},
-                                      {"Followup-To:", NULL, FALSE},
+                                      {"Bcc:",         NULL, TRUE},
+                                      {"Newsgroups:",  NULL, TRUE},
+                                      {"Followup-To:", NULL, TRUE},
                                       {"List-Post:",   NULL, FALSE},
                                       {"X-Priority:",  NULL, FALSE},
                                       {NULL,           NULL, FALSE}};
@@ -1884,97 +1889,117 @@ static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
 #undef SET_ENTRY
 #undef SET_ADDRESS
 
-static void compose_insert_sig(Compose *compose)
+static void compose_insert_sig(Compose *compose, gboolean replace)
 {
-       static gchar *default_sigfile;
-       gchar *sigfile = NULL;
+       GtkSText *text = GTK_STEXT(compose->text);
+       gint cur_pos;
 
        g_return_if_fail(compose->account != NULL);
 
-       if (compose->account->sig_type == SIG_FILE) {
-               if (compose->account->sig_path)
-                       sigfile = compose->account->sig_path;
-               else {
-                       if (!default_sigfile)
-                               default_sigfile = g_strconcat
-                                       (get_home_dir(), G_DIR_SEPARATOR_S,
-                                        DEFAULT_SIGNATURE, NULL);
-                       sigfile = default_sigfile;
-               }
+       cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
 
-               if (!is_file_or_fifo_exist(sigfile)) {
-                       g_warning("can't open signature file: %s\n", sigfile);
-                       return;
-               }
-       }
+       gtk_stext_freeze(text);
 
-       gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
-       if (compose->account->sig_sep) {
-               gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
-                                compose->account->sig_sep, -1);
-               gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
-                               "\n", 1);
-       }
+       if (replace && compose->sig_str) {
+               gint pos;
+               gint len;
+
+               if (compose->sig_str[0] == '\0')
+                       pos = -1;
+               else
+                       pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
 
-       if (compose->account->sig_type == SIG_COMMAND) {
-               if (compose->account->sig_path)
-                       compose_insert_command_output
-                               (compose, compose->account->sig_path);
+               if (pos != -1) {
+                       len = get_mbs_len(compose->sig_str);
+                       if (len >= 0) {
+                               gtk_stext_set_point(text, pos);
+                               gtk_stext_forward_delete(text, len);
+                       } else {
+                               len = gtk_stext_get_length(text);
+                               gtk_stext_set_point(text, len);
+                       }
+               } else {
+                       len = gtk_stext_get_length(text);
+                       gtk_stext_set_point(text, len);
+               }
        } else
-               compose_insert_file(compose, sigfile);
+               gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
+
+       g_free(compose->sig_str);
+       compose->sig_str = compose_get_signature_str(compose);
+       if (!compose->sig_str || (replace && !compose->account->auto_sig))
+               compose->sig_str = g_strdup("");
+
+       gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
+
+       gtk_stext_thaw(text);
+
+       if (cur_pos > gtk_stext_get_length(text))
+               cur_pos = gtk_stext_get_length(text);
+
+       gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
+       gtk_stext_set_point(text, cur_pos);
 }
 
-static void compose_insert_file(Compose *compose, const gchar *file)
+static gchar *compose_get_signature_str(Compose *compose)
 {
-       GtkSText *text = GTK_STEXT(compose->text);
-       gchar buf[BUFFSIZE];
-       gint len;
-       FILE *fp;
+       gchar *sig_body = NULL;
+       gchar *sig_str = NULL;
 
-       g_return_if_fail(file != NULL);
+       g_return_val_if_fail(compose->account != NULL, NULL);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
-               FILE_OP_ERROR(file, "fopen");
-               return;
+       if (!compose->account->sig_path)
+               return NULL;
+
+       if (compose->account->sig_type == SIG_FILE) {
+               if (!is_file_or_fifo_exist(compose->account->sig_path)) {
+                       g_warning("can't open signature file: %s\n",
+                                 compose->account->sig_path);
+                       return NULL;
+               }
        }
 
-       gtk_stext_freeze(text);
+       if (compose->account->sig_type == SIG_COMMAND)
+               sig_body = get_command_output(compose->account->sig_path);
+       else {
+               gchar *tmp;
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               /* strip <CR> if DOS/Windows file,
-                  replace <CR> with <LF> if Macintosh file. */
-               strcrchomp(buf);
-               len = strlen(buf);
-               if (len > 0 && buf[len - 1] != '\n') {
-                       while (--len >= 0)
-                               if (buf[len] == '\r') buf[len] = '\n';
-               }
-               gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
+               tmp = file_read_to_str(compose->account->sig_path);
+               if (!tmp)
+                       return NULL;
+               sig_body = normalize_newlines(tmp);
+               g_free(tmp);
        }
 
-       gtk_stext_thaw(text);
+       if (compose->account->sig_sep) {
+               sig_str = g_strconcat(compose->account->sig_sep, "\n", sig_body,
+                                     NULL);
+               g_free(sig_body);
+       } else
+               sig_str = sig_body;
 
-       fclose(fp);
+       return sig_str;
 }
 
-static void compose_insert_command_output(Compose *compose,
-                                         const gchar *cmdline)
+static void compose_insert_file(Compose *compose, const gchar *file)
 {
        GtkSText *text = GTK_STEXT(compose->text);
        gchar buf[BUFFSIZE];
        gint len;
        FILE *fp;
 
-       g_return_if_fail(cmdline != NULL);
+       g_return_if_fail(file != NULL);
 
-       if ((fp = popen(cmdline, "r")) == NULL) {
-               FILE_OP_ERROR(cmdline, "popen");
+       if ((fp = fopen(file, "rb")) == NULL) {
+               FILE_OP_ERROR(file, "fopen");
                return;
        }
 
        gtk_stext_freeze(text);
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
+               /* strip <CR> if DOS/Windows file,
+                  replace <CR> with <LF> if Macintosh file. */
                strcrchomp(buf);
                len = strlen(buf);
                if (len > 0 && buf[len - 1] != '\n') {
@@ -1986,7 +2011,7 @@ static void compose_insert_command_output(Compose *compose,
 
        gtk_stext_thaw(text);
 
-       pclose(fp);
+       fclose(fp);
 }
 
 static void compose_attach_append(Compose *compose, const gchar *file,
@@ -2667,7 +2692,7 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                        STEXT_FREEZE();
                        gtk_stext_set_point(text, line_pos);
                        gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
-                       /* gtk_stext_compact_buffer(text); */
+                       gtk_stext_compact_buffer(text);
                        tlen++;
                        line_pos++;
                        /* for loop will increase it */
@@ -2767,7 +2792,8 @@ compose_current_mail_account(void)
        return ac;
 }
 
-static void compose_select_account(Compose *compose, PrefsAccount *account)
+static void compose_select_account(Compose *compose, PrefsAccount *account,
+                                  gboolean init)
 {
        GtkWidget *menuitem;
        GtkItemFactory *ifactory;
@@ -2852,6 +2878,9 @@ static void compose_select_account(Compose *compose, PrefsAccount *account)
                                       
        activate_gnupg_mode(compose, account);          
 #endif /* USE_GPGME */
+
+       if (!init)
+               compose_insert_sig(compose, TRUE);
 }
 
 gboolean compose_check_for_valid_recipient(Compose *compose) {
@@ -3099,7 +3128,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
                        if (str[0] != '\0') {
                                compose_convert_header
                                        (buf, sizeof(buf), str,
-                                       strlen("Resent-To") + 2);
+                                       strlen("Resent-To") + 2, TRUE);
                                if (first_address) {
                                        fprintf(fp, "Resent-To: ");
                                        first_address = FALSE;
@@ -3135,7 +3164,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        if (compose->account->name && *compose->account->name) {
                compose_convert_header
                        (buf, sizeof(buf), compose->account->name,
-                        strlen("From: "));
+                        strlen("From: "), TRUE);
                fprintf(fp, "Resent-From: %s <%s>\n",
                        buf, compose->account->address);
        } else
@@ -3148,7 +3177,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
                g_strstrip(str);
                if (*str != '\0') {
                        compose_convert_header(buf, sizeof(buf), str,
-                                              strlen("Subject: "));
+                                              strlen("Subject: "), FALSE);
                        fprintf(fp, "Subject: %s\n", buf);
                }
        }
@@ -3218,7 +3247,8 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
                                        compose_convert_header
                                                (buf, sizeof(buf),
                                                 compose->account->name,
-                                                strlen("From: "));
+                                                strlen("From: "),
+                                                FALSE);
                                        fprintf(fdest, "%s <%s>",
                                                buf,
                                                compose->account->address);
@@ -3857,7 +3887,7 @@ static void compose_write_attach(Compose *compose, FILE *fp)
                        fprintf(fp, "Content-Disposition: inline\n");
                } else {
                        compose_convert_header(filename, sizeof(filename),
-                                              ainfo->name, 12);
+                                              ainfo->name, 12, FALSE);
                        fprintf(fp, "Content-Type: %s;\n"
                                    " name=\"%s\"\n",
                                ainfo->content_type, filename);
@@ -3907,8 +3937,7 @@ static void compose_write_attach(Compose *compose, FILE *fp)
 
 #define QUOTE_IF_REQUIRED(out, str)                    \
 {                                                      \
-       if (*str != '"' && (strchr(str, ',')            \
-                       || strchr(str, '.'))) {         \
+       if (*str != '"' && strpbrk(str, ",.[]<>")) {    \
                gchar *__tmp;                           \
                gint len;                               \
                                                        \
@@ -3930,7 +3959,8 @@ static void compose_write_attach(Compose *compose, FILE *fp)
                        compose->to_list = address_list_append               \
                                (compose->to_list, str);                     \
                        compose_convert_header                               \
-                               (buf, sizeof(buf), str, strlen(header) + 2); \
+                               (buf, sizeof(buf), str, strlen(header) + 2,  \
+                                TRUE);                                      \
                        fprintf(fp, "%s: %s\n", header, buf);                \
                }                                                            \
        }                                                                    \
@@ -3972,7 +4002,7 @@ static gint compose_write_headers_from_headerlist(Compose *compose,
                        if (str[0] != '\0') {
                                compose_convert_header
                                        (buf, sizeof(buf), str,
-                                       strlen(header) + 2);
+                                       strlen(header) + 2, TRUE);
                                if (first_address) {
                                        fprintf(fp, "%s: ", header);
                                        first_address = FALSE;
@@ -4034,7 +4064,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                if (compose->account->name && *compose->account->name) {
                        compose_convert_header
                                (buf, sizeof(buf), compose->account->name,
-                                strlen("From: "));
+                                strlen("From: "), TRUE);
                        QUOTE_IF_REQUIRED(name, buf);
                        fprintf(fp, "From: %s <%s>\n",
                                name, compose->account->address);
@@ -4065,7 +4095,8 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                                        newsgroup_list_append
                                                (compose->newsgroup_list, str);
                                compose_convert_header(buf, sizeof(buf), str,
-                                                      strlen("Newsgroups: "));
+                                                      strlen("Newsgroups: "),
+                                                      TRUE);
                                fprintf(fp, "Newsgroups: %s\n", buf);
                        }
                }
@@ -4095,7 +4126,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                g_strstrip(str);
                if (*str != '\0') {
                        compose_convert_header(buf, sizeof(buf), str,
-                                              strlen("Subject: "));
+                                              strlen("Subject: "), FALSE);
                        fprintf(fp, "Subject: %s\n", buf);
                }
        }
@@ -4126,7 +4157,8 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                        remove_space(str);
                        if (*str != '\0') {
                                compose_convert_header(buf, sizeof(buf), str,
-                                                      strlen("Followup-To: "));
+                                                      strlen("Followup-To: "),
+                                                      TRUE);
                                fprintf(fp, "Followup-To: %s\n", buf);
                        }
                }
@@ -4142,7 +4174,8 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                        g_strstrip(str);
                        if (*str != '\0') {
                                compose_convert_header(buf, sizeof(buf), str,
-                                                      strlen("Reply-To: "));
+                                                      strlen("Reply-To: "),
+                                                      TRUE);
                                fprintf(fp, "Reply-To: %s\n", buf);
                        }
                }
@@ -4153,7 +4186,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
            !IS_IN_CUSTOM_HEADER("Organization")) {
                compose_convert_header(buf, sizeof(buf),
                                       compose->account->organization,
-                                      strlen("Organization: "));
+                                      strlen("Organization: "), FALSE);
                fprintf(fp, "Organization: %s\n", buf);
        }
 
@@ -4197,7 +4230,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                                compose_convert_header
                                        (buf, sizeof(buf),
                                         chdr->value ? chdr->value : "",
-                                        strlen(chdr->name) + 2);
+                                        strlen(chdr->name) + 2, FALSE);
                                fprintf(fp, "%s: %s\n", chdr->name, buf);
                        }
                }
@@ -4244,7 +4277,10 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                if (compose->return_receipt) {
                        if (compose->account->name
                            && *compose->account->name) {
-                               compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
+                               compose_convert_header(buf, sizeof(buf), 
+                                                      compose->account->name, 
+                                                      strlen("Disposition-Notification-To: "),
+                                                      TRUE);
                                fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
                        } else
                                fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
@@ -4299,7 +4335,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 #undef IS_IN_CUSTOM_HEADER
 
 static void compose_convert_header(gchar *dest, gint len, gchar *src,
-                                  gint header_len)
+                                  gint header_len, gboolean addr_field)
 {
        g_return_if_fail(src != NULL);
        g_return_if_fail(dest != NULL);
@@ -4308,7 +4344,7 @@ static void compose_convert_header(gchar *dest, gint len, gchar *src,
 
        g_strchomp(src);
 
-       conv_encode_header(dest, len, src, header_len);
+       conv_encode_header(dest, len, src, header_len, addr_field);
 }
 
 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
@@ -4965,7 +5001,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        }
 #endif
 
-       update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
+       action_update_compose_menu(ifactory, compose);
 
 
        undostruct = undo_init(text);
@@ -5022,18 +5058,19 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        compose->modified = FALSE;
 
        compose->return_receipt = FALSE;
-       compose->paste_as_quotation = FALSE;
 
        compose->to_list        = NULL;
        compose->newsgroup_list = NULL;
 
+       compose->undostruct = undostruct;
+
+       compose->sig_str = NULL;
+
        compose->exteditor_file    = NULL;
        compose->exteditor_pid     = -1;
        compose->exteditor_readdes = -1;
        compose->exteditor_tag     = -1;
 
-       compose->redirect_filename = NULL;
-       compose->undostruct = undostruct;
 #if USE_ASPELL
        menu_set_sensitive(ifactory, "/Spelling", FALSE);
        if (mode != COMPOSE_REDIRECT) {
@@ -5066,7 +5103,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        }
 #endif
 
-       compose_select_account(compose, account);
+       compose_select_account(compose, account, TRUE);
 
 #if USE_ASPELL
         compose->gtkaspell      = gtkaspell;
@@ -5088,7 +5125,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
 
        addressbook_set_target_compose(compose);
-       update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
+       action_update_compose_menu(ifactory, compose);
        
        if (mode != COMPOSE_REDIRECT)
                compose_set_template_menu(compose);
@@ -5304,7 +5341,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
                compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
 
        if (replace)
-               gtk_stext_clear(GTK_STEXT(compose->text));
+               gtkut_stext_clear(GTK_STEXT(compose->text));
 
        if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
                parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
@@ -5326,7 +5363,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
        }
 
        if (replace && parsed_str && compose->account->auto_sig)
-               compose_insert_sig(compose);
+               compose_insert_sig(compose, FALSE);
 
        if (replace && parsed_str) {
                gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
@@ -5375,6 +5412,10 @@ static void compose_destroy(Compose *compose)
 
        if (compose->redirect_filename)
                g_free(compose->redirect_filename);
+       if (compose->undostruct)
+               undo_destroy(compose->undostruct);
+
+       g_free(compose->sig_str);
 
        g_free(compose->exteditor_file);
 
@@ -6075,7 +6116,7 @@ static void account_activated(GtkMenuItem *menuitem, gpointer data)
        g_return_if_fail(ac != NULL);
 
        if (ac != compose->account)
-               compose_select_account(compose, ac);
+               compose_select_account(compose, ac, FALSE);
 }
 
 static void attach_selected(GtkCList *clist, gint row, gint column,
@@ -6294,6 +6335,14 @@ static void compose_insert_file_cb(gpointer data, guint action,
        }
 }
 
+static void compose_insert_sig_cb(gpointer data, guint action,
+                                 GtkWidget *widget)
+{
+       Compose *compose = (Compose *)data;
+
+       compose_insert_sig(compose, FALSE);
+}
+
 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
                              gpointer data)
 {
@@ -6417,10 +6466,18 @@ static void compose_paste_as_quote_cb(Compose *compose)
 {
        if (compose->focused_editable &&
            GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
-               compose->paste_as_quotation = TRUE;
+               /* let text_insert() (called directly or at a later time
+                * after the gtk_editable_paste_clipboard) know that 
+                * text is to be inserted as a quotation. implemented
+                * by using a simple refcount... */
+               gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
+                                               GTK_OBJECT(compose->focused_editable),
+                                               "paste_as_quotation"));
+               gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
+                                   "paste_as_quotation",
+                                   GINT_TO_POINTER(paste_as_quotation + 1));
                gtk_editable_paste_clipboard
                        (GTK_EDITABLE(compose->focused_editable));
-               compose->paste_as_quotation = FALSE;
        }
 }
 
@@ -6874,11 +6931,13 @@ static void text_inserted(GtkWidget *widget, const gchar *text,
                          gint length, gint *position, Compose *compose)
 {
        GtkEditable *editable = GTK_EDITABLE(widget);
+       gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
+                               (GTK_OBJECT(widget), "paste_as_quotation"));
 
        gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
                                         GTK_SIGNAL_FUNC(text_inserted),
                                         compose);
-       if (compose->paste_as_quotation) {
+       if (paste_as_quotation) {
                gchar *new_text;
                gchar *qmark;
                gint pos;
@@ -6894,6 +6953,8 @@ static void text_inserted(GtkWidget *widget, const gchar *text,
                gtk_editable_set_position(editable, pos);
                *position = pos;
                g_free(new_text);
+               gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
+                                   GINT_TO_POINTER(paste_as_quotation - 1));
        } else
                gtk_editable_insert_text(editable, text, length, position);