]> granicus.if.org Git - mutt/commitdiff
Fixing #1149: Truncate files used for editing messages.
authorMichael Elkins <me@sigpipe.org>
Mon, 9 Sep 2002 19:53:24 +0000 (19:53 +0000)
committerMichael Elkins <me@sigpipe.org>
Mon, 9 Sep 2002 19:53:24 +0000 (19:53 +0000)
editmsg.c

index bf9d17c40c731e24e037a0d901a54584ed14bb92..c105a48e539a49773015ae0640c9e69b592a865b 100644 (file)
--- a/editmsg.c
+++ b/editmsg.c
@@ -88,6 +88,21 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur)
   if (stat (tmp, &sb) == 0)
     mtime = sb.st_mtime;
 
+  /*
+   * 2002-09-05 me@sigpipe.org
+   * The file the user is going to edit is not a real mbox, so we need to
+   * truncate the last newline in the temp file, which is logically part of
+   * the message separator, and not the body of the message.  If we fail to
+   * remove it, the message will grow by one line each time the user edits
+   * the message.
+   */
+  if (sb.st_size != 0 && truncate (tmp, sb.st_size - 1) == -1)
+  {
+    mutt_error (_("could not truncate temporary mail folder: %s"),
+               strerror (errno));
+    goto bail;
+  }
+
   mutt_edit_file (NONULL(Editor), tmp);
 
   if ((rc = stat (tmp, &sb)) == -1)