-;;; rmailsort.el --- Rmail: sort messages.
+;;; rmailsort.el --- Rmail: sort messages
-;; Copyright (C) 1990, 1993 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1993, 1994, 2001 Free Software Foundation, Inc.
;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
-;; Version: $Header: /gd/gnu/emacs/19.0/lisp/RCS/rmailsort.el,v 1.18 1994/03/23 21:49:16 kwzh Exp kwzh $
+;; Maintainer: FSF
;; Keywords: mail
;; This file is part of GNU Emacs.
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
;;; Code:
(require 'sort)
+;; For rmail-select-summary
+(require 'rmail)
+
(autoload 'timezone-make-date-sortable "timezone")
;; Sorting messages in Rmail buffer
+;;;###autoload
(defun rmail-sort-by-date (reverse)
"Sort messages of current Rmail file by date.
If prefix argument REVERSE is non-nil, sort them in reverse order."
(rmail-make-date-sortable
(rmail-fetch-field msg "Date"))))))
+;;;###autoload
(defun rmail-sort-by-subject (reverse)
"Sort messages of current Rmail file by subject.
If prefix argument REVERSE is non-nil, sort them in reverse order."
(substring key (match-end 0))
key))))))
+;;;###autoload
(defun rmail-sort-by-author (reverse)
"Sort messages of current Rmail file by author.
If prefix argument REVERSE is non-nil, sort them in reverse order."
(or (rmail-fetch-field msg "From")
(rmail-fetch-field msg "Sender") "")))))))
+;;;###autoload
(defun rmail-sort-by-recipient (reverse)
"Sort messages of current Rmail file by recipient.
If prefix argument REVERSE is non-nil, sort them in reverse order."
(rmail-fetch-field msg "Apparently-To") "")
))))))
+;;;###autoload
(defun rmail-sort-by-correspondent (reverse)
"Sort messages of current Rmail file by other correspondent.
If prefix argument REVERSE is non-nil, sort them in reverse order."
(setq fields (cdr fields)))
ans))
+;;;###autoload
(defun rmail-sort-by-lines (reverse)
"Sort messages of current Rmail file by number of lines.
If prefix argument REVERSE is non-nil, sort them in reverse order."
(lambda (msg)
(count-lines (rmail-msgbeg msg)
(rmail-msgend msg))))))
+
+;;;###autoload
+(defun rmail-sort-by-labels (reverse labels)
+ "Sort messages of current Rmail file by labels.
+If prefix argument REVERSE is non-nil, sort them in reverse order.
+KEYWORDS is a comma-separated list of labels."
+ (interactive "P\nsSort by labels: ")
+ (or (string-match "[^ \t]" labels)
+ (error "No labels specified"))
+ (setq labels (concat (substring labels (match-beginning 0)) ","))
+ (let (labelvec)
+ (while (string-match "[ \t]*,[ \t]*" labels)
+ (setq labelvec (cons
+ (concat ", ?\\("
+ (substring labels 0 (match-beginning 0))
+ "\\),")
+ labelvec))
+ (setq labels (substring labels (match-end 0))))
+ (setq labelvec (apply 'vector (nreverse labelvec)))
+ (rmail-sort-messages reverse
+ (function
+ (lambda (msg)
+ (let ((n 0))
+ (while (and (< n (length labelvec))
+ (not (rmail-message-labels-p
+ msg (aref labelvec n))))
+ (setq n (1+ n)))
+ n))))))
\f
;; Basic functions
"Sort messages of current Rmail 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-excursion
+ (save-current-buffer
;; If we are in a summary buffer, operate on the Rmail buffer.
(if (eq major-mode 'rmail-summary-mode)
(set-buffer rmail-buffer))
(let ((buffer-read-only nil)
+ (point-offset (- (point) (point-min)))
(predicate nil) ;< or string-lessp
(sort-lists nil))
(message "Finding sort keys...")
(msgnum 1)
(msginfo nil))
;; There's little hope that we can easily undo after that.
- (buffer-flush-undo (current-buffer))
+ (buffer-disable-undo (current-buffer))
(goto-char (rmail-msgbeg 1))
;; To force update of all markers.
(insert-before-markers ?Z)
(buffer-enable-undo)
(rmail-set-message-counters)
(rmail-show-message current-message)
+ (goto-char (+ point-offset (point-min)))
(if (rmail-summary-exists)
(rmail-select-summary
(rmail-update-summary)))))))
(provide 'rmailsort)
+;;; arch-tag: 0d90896b-0c35-46ac-b240-38be5ada2360
;;; rmailsort.el ends here