emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

23.3; Rmail "get messages" destroys all white space at the end of the la


From: Mark Lillibridge
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 "")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]