changeset 100220:29cfa704a5e2

Sync with pmailsort.el. (pmail-sort-messages): Insert two newlines at the end of the message if they do not exist.
author Chong Yidong <cyd@stupidchicken.com>
date Thu, 04 Dec 2008 22:48:57 +0000
parents 36b7680e6d87
children 20326e3d1912
files lisp/mail/pmailsort.el
diffstat 1 files changed, 18 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mail/pmailsort.el	Thu Dec 04 22:47:37 2008 +0000
+++ b/lisp/mail/pmailsort.el	Thu Dec 04 22:48:57 2008 +0000
@@ -29,7 +29,8 @@
 (eval-when-compile
   (require 'mail-utils)
   (require 'sort)
-  (require 'pmail))
+  (require 'pmail)
+  (require 'pmailhdr))
 
 (autoload 'timezone-make-date-sortable "timezone")
 
@@ -121,8 +122,8 @@
   (pmail-sort-messages reverse
 		       (function
 			(lambda (msg)
-			  (count-lines (pmail-desc-get-start msg)
-				       (pmail-desc-get-end msg))))))
+			  (count-lines (pmail-msgbeg msg)
+				       (pmail-msgend msg))))))
 
 ;;;###autoload
 (defun pmail-sort-by-labels (reverse labels)
@@ -158,10 +159,8 @@
   "Sort messages of current Pmail file.
 If 1st argument REVERSE is non-nil, sort them in reverse order.
 2nd argument KEYFUN is called with a message number, and should return a key."
-  (save-current-buffer
-    ;; If we are in a summary buffer, operate on the Pmail buffer.
-    (if (eq major-mode 'pmail-summary-mode)
-	(set-buffer pmail-buffer))
+  (pmail-swap-buffers-maybe)
+  (with-current-buffer pmail-buffer
     (let ((buffer-read-only nil)
 	  (point-offset (- (point) (point-min)))
 	  (predicate nil)			;< or string-lessp
@@ -173,8 +172,8 @@
 	  (setq sort-lists
 		(cons (list (funcall keyfun msgnum) ;Make sorting key
 			    (eq pmail-current-message msgnum) ;True if current
-			    (pmail-desc-get-start msgnum)
-			    (pmail-desc-get-end msgnum))
+			    (aref pmail-message-vector msgnum)
+			    (aref pmail-message-vector (1+ msgnum)))
 		      sort-lists))
 	  (if (zerop (% msgnum 10))
 	      (message "Finding sort keys...%d" msgnum))
@@ -198,21 +197,22 @@
 	    (msginfo nil))
 	;; There's little hope that we can easily undo after that.
 	(buffer-disable-undo (current-buffer))
-	(goto-char (pmail-desc-get-start 1))
+	(goto-char (pmail-msgbeg 1))
 	;; To force update of all markers.
 	(insert-before-markers ?Z)
 	(backward-char 1)
 	;; Now reorder messages.
-	(while sort-lists
-	  (setq msginfo (car sort-lists))
+	(dolist (msginfo sort-lists)
 	  ;; Swap two messages.
 	  (insert-buffer-substring
 	   (current-buffer) (nth 2 msginfo) (nth 3 msginfo))
-	  (delete-region  (nth 2 msginfo) (nth 3 msginfo))
+	  ;; The last message may not have \n\n after it.
+	  (unless (eq (char-before) ?\n)
+	    (insert "\n\n"))
+	  (delete-region (nth 2 msginfo) (nth 3 msginfo))
 	  ;; Is current message?
 	  (if (nth 1 msginfo)
 	      (setq current-message msgnum))
-	  (setq sort-lists (cdr sort-lists))
 	  (if (zerop (% msgnum 10))
 	      (message "Reordering messages...%d" msgnum))
 	  (setq msgnum (1+ msgnum)))
@@ -220,22 +220,18 @@
 	(delete-char 1)
 	(setq quit-flag nil)
 	(buffer-enable-undo)
-        (goto-char (point-min))
-	(pmail-initialize-messages)
+	(pmail-set-message-counters)
 	(pmail-show-message current-message)
+	(goto-char (+ point-offset (point-min)))
 	(if (pmail-summary-exists)
-	    (pmail-select-summary
-	     (pmail-update-summary)))))))
+	    (pmail-select-summary (pmail-update-summary)))))))
 
-;; mbox: ready
 (defun pmail-fetch-field (msg field)
   "Return the value of the header FIELD of MSG.
 Arguments are MSG and FIELD."
   (save-restriction
     (widen)
-    (narrow-to-region
-     (pmail-desc-get-start msg)
-     (pmail-desc-get-end msg))
+    (narrow-to-region (pmail-msgbeg msg) (pmail-msgend msg))
     (pmail-header-get-header field)))
 
 (defun pmail-make-date-sortable (date)