Fix undoing file insertion.
[claws.git] / src / compose.c
index 77370deeab0aa97db1d4039b4dca89f1910ee23f..6ddbc78fead3b926b1660ce6f961f6cc86a47acd 100644 (file)
@@ -3504,6 +3504,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        gboolean badtxt = FALSE;
        struct stat file_stat;
        int ret;
+       GString *file_contents = NULL;
 
        cm_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
 
@@ -3563,6 +3564,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
        cur_encoding = conv_get_locale_charset_str_no_utf8();
 
+       file_contents = g_string_new("");
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *str;
 
@@ -3582,10 +3584,14 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                                if (str[len] == '\r') str[len] = '\n';
                }
 
-               gtk_text_buffer_insert(buffer, &iter, str, -1);
+               file_contents = g_string_append(file_contents, str);
                g_free(str);
        }
 
+       gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1);
+       g_string_free(file_contents, TRUE);
+
+       compose_changed_cb(NULL, compose);
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                          G_CALLBACK(text_inserted),
                                          compose);
@@ -6625,9 +6631,9 @@ void compose_add_extra_header_entries(GtkListStore *model)
                        goto extra_headers_done;
                }
                while (fgets(buf, BUFFSIZE, exh) != NULL) {
-                       lastc = strlen(buf) - 1;        /* remove trailing \n */
-                       buf[lastc] = (buf[lastc] == '\n')? '\0': buf[lastc];
-                       --lastc;
+                       lastc = strlen(buf) - 1;        /* remove trailing control chars */
+                       while (lastc >= 0 && buf[lastc] != ':')
+                               buf[lastc--] = '\0';
                        if (lastc > 0 && buf[0] != '#' && buf[lastc] == ':') {
                                buf[lastc] = '\0'; /* remove trailing : for comparison */
                                if (custom_header_is_allowed(buf)) {