GNU bug report logs - #9974
23.3; Rmail "get messages" destroys all white space at the end of the last message already in the mailbox [PATCH]

Previous Next

Package: emacs;

Reported by: mark.lillibridge <at> hp.com

Date: Sun, 6 Nov 2011 19:53:02 UTC

Severity: normal

Tags: patch

Found in version 23.3

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9974 in the body.
You can then email your comments to 9974 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#9974; Package emacs. (Sun, 06 Nov 2011 19:53:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to mark.lillibridge <at> hp.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 06 Nov 2011 19:53:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mark Lillibridge <mark.lillibridge <at> hp.com>
To: bug-gnu-emacs <at> gnu.org
Cc: emacs-devel <at> gnu.org
Subject: 23.3;
	Rmail "get messages" destroys all white space at the end of the last
	message already in the mailbox [PATCH]
Date: Sun, 06 Nov 2011 11:49:20 -0800
    To reproduce, run Rmail with the main inbox ending with a message
ending with white space (e.g., several blank lines) then type 'g' when
no new messages are available.  *poof* the whitespace of the last
message vanishes.


    This bug is caused by the following code in rmail-get-new-mail:

rmail.el:1719:
	      ;; In case of brain damage caused by require-final-newline.
	      (goto-char (point-max))
	      (skip-chars-backward " \t\n")
	      (delete-region (point) (point-max))

I think this code is left over from parsing BABYL files which are
supposed end with ^_ not followed by any white space.  With mbox files,
the file is supposed to end with a blank line unless the file is empty
(i.e., zero bytes).

    My patch (below) corrects this to:

	      (goto-char (point-max))
	      ;; Make sure we are in valid mbox format (end with a
	      ;; blank line unless no messages):
	      ;;   (fixes damage caused by bug #????)
	      (unless (bobp)
		(while (not (looking-back "\n\n"))
		  (insert "\n")))

This code fixes up the damage caused by this bug, restoring the inbox to
proper mbox format.


    In the process of testing this, I found a further bug downstream in
the rmail-insert-inbox-text function:

rmail.el:2022:
	    ;; Determine if a pair of newline message separators need
	    ;; to be added to the new collection of messages.  This is
	    ;; the case for all new message collections added to a
	    ;; non-empty mail file.
	    (unless (zerop size)
	      (save-restriction
		(let ((start (point-min)))
		  (widen)
		  (unless (eq start (point-min))
		    (goto-char start)
		    (insert "\n\n")
		    (setq size (+ 2 size))))))
	    (goto-char (point-max))
	    (or (= (preceding-char) ?\n)
		(zerop size)
		(insert ?\n))

This code is bogus given that rmail-insert-inbox-text function is always
(now) called with point after a valid mbox inbox, which always ends with
"\n\n" unless it is empty.  The extra newlines added here therefore
add an extra blank line to the last message of the existing mailbox if
any.  What this code is supposed to be doing is handle slightly
malformed input.  Accordingly, I'm changing it to:

	    (goto-char (point-max))
	    ;; Paranoia: make sure read in mbox format data properly
	    ;; ends with a blank line unless it is of size 0:
	    (unless (zerop size)
	      (while (not (looking-back "\n\n"))
		(insert "\n")))


    The patch follows.  Note that this is a self-referential patch --
change the text "bug #????" to refer to the bug number assigned to this
bug by the automatic system.

- Mark

ts-rhel5 [171]% ( setenv LC_ALL C ; setenv TZ UTC0 ; diff -Naur original-rmail.el rmail.el ) 
--- original-rmail.el   2011-02-23 23:23:08.000000000 +0000
+++ rmail.el    2011-11-06 19:18:30.351376000 +0000
@@ -1716,10 +1716,13 @@
                (setq all-files (cdr all-files)))
              ;; Put them back in their original order.
              (setq files (nreverse files))
-             ;; In case of brain damage caused by require-final-newline.
              (goto-char (point-max))
-             (skip-chars-backward " \t\n")
-             (delete-region (point) (point-max))
+             ;; Make sure we are in valid mbox format (end with a
+             ;; blank line unless no messages):
+             ;;   (fixes damage caused by bug #????)
+             (unless (bobp)
+               (while (not (looking-back "\n\n"))
+                 (insert "\n")))
              (setq found (or
                           (rmail-get-new-mail-1 file-name files delete-files)
                           found))))
@@ -2019,22 +2022,12 @@
                  (rmail-unrmail-new-mail-maybe
                   tofile
                   (nth 1 (insert-file-contents tofile))))
-           ;; Determine if a pair of newline message separators need
-           ;; to be added to the new collection of messages.  This is
-           ;; the case for all new message collections added to a
-           ;; non-empty mail file.
-           (unless (zerop size)
-             (save-restriction
-               (let ((start (point-min)))
-                 (widen)
-                 (unless (eq start (point-min))
-                   (goto-char start)
-                   (insert "\n\n")
-                   (setq size (+ 2 size))))))
            (goto-char (point-max))
-           (or (= (preceding-char) ?\n)
-               (zerop size)
-               (insert ?\n))
+           ;; Paranoia: make sure read in mbox format data properly
+           ;; ends with a blank line unless it is of size 0:
+           (unless (zerop size)
+             (while (not (looking-back "\n\n"))
+               (insert "\n")))
            (if (not (and rmail-preserve-inbox (string= file tofile)))
                (setq delete-files (cons tofile delete-files)))))
       (message "")




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#9974; Package emacs. (Mon, 07 Nov 2011 02:57:02 GMT) Full text and rfc822 format available.

Message #8 received at 9974 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: mark.lillibridge <at> hp.com
Cc: 9974 <at> debbugs.gnu.org
Subject: Re: bug#9974: 23.3;
	Rmail "get messages" destroys all white space at the end of the last
	message already in the mailbox [PATCH]
Date: Mon, 07 Nov 2011 10:53:00 +0800
Mark Lillibridge <mark.lillibridge <at> hp.com> writes:

>     To reproduce, run Rmail with the main inbox ending with a message
> ending with white space (e.g., several blank lines) then type 'g' when
> no new messages are available.  *poof* the whitespace of the last
> message vanishes.

Thanks, I've committed your patch to the trunk.




bug closed, send any further explanations to 9974 <at> debbugs.gnu.org and mark.lillibridge <at> hp.com Request was from Chong Yidong <cyd <at> gnu.org> to control <at> debbugs.gnu.org. (Mon, 07 Nov 2011 02:57:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 05 Dec 2011 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 156 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.