Make sure outgoing messages have a trailing newline.
authorAndrej Kacian <ticho@claws-mail.org>
Thu, 30 Mar 2017 19:12:13 +0000 (21:12 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Thu, 30 Mar 2017 19:12:52 +0000 (21:12 +0200)
This fixes a corner case where if the last line of
a message is a quote, its last character doesn't get
displayed when viewing the copy in outbox.

src/compose.c

index b7a7f76489369b8498f0f88bc7dafa50ef295944..4e938623695c28f7637a05470b5a3631e4a8ed89 100644 (file)
@@ -5611,7 +5611,7 @@ error:
 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
 {
        GtkTextBuffer *buffer;
-       GtkTextIter start, end;
+       GtkTextIter start, end, tmp;
        gchar *chars, *tmp_enc_file, *content;
        gchar *buf, *msg;
        const gchar *out_codeset;
@@ -5643,10 +5643,20 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        mimemsg->data.mem = compose_get_header(compose);
 
        /* Create text part MimeInfo */
-       /* get all composed text */
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
-       gtk_text_buffer_get_start_iter(buffer, &start);
        gtk_text_buffer_get_end_iter(buffer, &end);
+       tmp = end;
+
+       /* We make sure that there is a newline at the end. */
+       if (gtk_text_iter_backward_char(&tmp)) {
+               chars = gtk_text_buffer_get_text(buffer, &tmp, &end, FALSE);
+               if (*chars != '\n') {
+                       gtk_text_buffer_insert(buffer, &end, "\n", 1);
+               }
+       }
+
+       /* get all composed text */
+       gtk_text_buffer_get_start_iter(buffer, &start);
        chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
 
        out_codeset = conv_get_charset_str(compose->out_encoding);