--- bsd-mailx-8.1.2-0.20100314cvs.orig/edit.c
+++ bsd-mailx-8.1.2-0.20100314cvs/edit.c
@@ -30,6 +30,12 @@
  * SUCH DAMAGE.
  */
 
+#ifdef DEBIAN
+/* needed for asprintf */
+#define _GNU_SOURCE
+#include <string.h>
+#endif
+
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -106,6 +112,24 @@
 		(void)ignoresig(SIGINT, &oact, &oset);
 		fp = run_editor(setinput(mp), (off_t)mp->m_size, type, readonly);
 		if (fp != NULL) {
+			int c1, c2;
+
+			/* Check if the last empty line is still here.
+			* If no, add it.
+			* (closes Debian bug #71759)
+			*/
+			(void)fseek(fp, -2L, SEEK_END);
+			c2 = getc(fp);
+			c1 = getc(fp);
+			(void)fseek(fp, 0L, SEEK_END);
+			if (c1 != '\n') {
+				putc('\n', fp);
+				putc('\n', fp);
+			} else if (c2 != '\n') {
+				putc('\n', fp);
+			}
+			(void)fflush(fp);
+
 			(void)fseek(otf, 0L, SEEK_END);
 			size = ftell(otf);
 			mp->m_block = blockof(size);
@@ -192,7 +216,22 @@
 			edit = _PATH_VI;
 	}
 	if (editit(edit, tempname) == -1) {
-		(void)rm(tempname);
+		/* 
+		 * Don't delete the file if user has changed it
+		 * See Debian bug#148071
+		 * robert@debian.org, 2004.03.30
+		 */
+		if ( !readonly && 
+			!stat(tempname, &statb) &&
+			(modtime != statb.st_mtime)) {
+			printf(
+ 				"Saved changed message in %s\n"					
+				"Please note that this file is located in temporary\n"
+				"directory and may disappear without any notice\n",
+				tempname);
+		} else {
+			(void)rm(tempname);
+		}	
 		goto out;
 	}
 	/*
