Delete #if 0 old definitions.
[bpt/emacs.git] / lisp / mail / rmailsum.el
CommitLineData
76550a57 1;;; rmailsum.el --- make summary buffers for the mail reader
aae56ea7 2
9596811a 3;; Copyright (C) 1985, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
9750e079 4
e5167999 5;; Maintainer: FSF
d7b4d18f 6;; Keywords: mail
e5167999 7
4d4d11cc
JB
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
e5167999 12;; the Free Software Foundation; either version 2, or (at your option)
4d4d11cc
JB
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
b578f267
EN
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
4d4d11cc 24
aae56ea7
ER
25;;; Commentary:
26
d41d75fb
RS
27;; Extended by Bob Weiner of Motorola
28;; Provided all commands from rmail-mode in rmail-summary-mode and made key
29;; bindings in both modes wholly compatible.
30
aae56ea7
ER
31;;; Code:
32
6e626f7e
RS
33;; For rmail-select-summary
34(require 'rmail)
35
be2e861f 36;;;###autoload
0a01a04e
RS
37(defcustom rmail-summary-scroll-between-messages t
38 "*Non-nil means Rmail summary scroll commands move between messages."
39 :type 'boolean
40 :group 'rmail-summary)
be2e861f 41
ea7bddc4 42;;;###autoload
0a01a04e
RS
43(defcustom rmail-summary-line-count-flag t
44 "*Non-nil if Rmail summary should show the number of lines in each message."
45 :type 'boolean
46 :group 'rmail-summary)
ea7bddc4 47
1a6bc985 48(defvar rmail-summary-font-lock-keywords
be94c30c
SM
49 '(("^....D.*" . font-lock-string-face) ; Deleted.
50 ("^....-.*" . font-lock-type-face) ; Unread.
1a6bc985
RS
51 ;; Neither of the below will be highlighted if either of the above are:
52 ("^....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date.
53 ("{ \\([^}]+\\),}" 1 font-lock-comment-face)) ; Labels.
54 "Additional expressions to highlight in Rmail Summary mode.")
55
d41d75fb 56;; Entry points for making a summary buffer.
4d4d11cc 57
d41d75fb
RS
58;; Regenerate the contents of the summary
59;; using the same selection criterion as last time.
60;; M-x revert-buffer in a summary buffer calls this function.
61(defun rmail-update-summary (&rest ignore)
62 (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
4d4d11cc 63
d2288651 64;;;###autoload
4d4d11cc
JB
65(defun rmail-summary ()
66 "Display a summary of all messages, one line per message."
67 (interactive)
d41d75fb 68 (rmail-new-summary "All" '(rmail-summary) nil))
4d4d11cc 69
d2288651 70;;;###autoload
4d4d11cc
JB
71(defun rmail-summary-by-labels (labels)
72 "Display a summary of all messages with one or more LABELS.
73LABELS should be a string containing the desired labels, separated by commas."
74 (interactive "sLabels to summarize by: ")
75 (if (string= labels "")
76 (setq labels (or rmail-last-multi-labels
77 (error "No label specified"))))
78 (setq rmail-last-multi-labels labels)
79 (rmail-new-summary (concat "labels " labels)
d41d75fb 80 (list 'rmail-summary-by-labels labels)
4d4d11cc
JB
81 'rmail-message-labels-p
82 (concat ", \\(" (mail-comma-list-regexp labels) "\\),")))
83
d2288651 84;;;###autoload
4d4d11cc
JB
85(defun rmail-summary-by-recipients (recipients &optional primary-only)
86 "Display a summary of all messages with the given RECIPIENTS.
87Normally checks the To, From and Cc fields of headers;
88but if PRIMARY-ONLY is non-nil (prefix arg given),
89 only look in the To and From fields.
d41d75fb 90RECIPIENTS is a string of regexps separated by commas."
4d4d11cc
JB
91 (interactive "sRecipients to summarize by: \nP")
92 (rmail-new-summary
93 (concat "recipients " recipients)
d41d75fb 94 (list 'rmail-summary-by-recipients recipients primary-only)
4d4d11cc
JB
95 'rmail-message-recipients-p
96 (mail-comma-list-regexp recipients) primary-only))
97
d2288651 98;;;###autoload
4d4d11cc
JB
99(defun rmail-summary-by-regexp (regexp)
100 "Display a summary of all messages according to regexp REGEXP.
101If the regular expression is found in the header of the message
102\(including in the date and other lines, as well as the subject line),
103Emacs will list the header line in the RMAIL-summary."
104 (interactive "sRegexp to summarize by: ")
105 (if (string= regexp "")
106 (setq regexp (or rmail-last-regexp
d41d75fb 107 (error "No regexp specified."))))
4d4d11cc
JB
108 (setq rmail-last-regexp regexp)
109 (rmail-new-summary (concat "regexp " regexp)
d41d75fb 110 (list 'rmail-summary-by-regexp regexp)
4d4d11cc
JB
111 'rmail-message-regexp-p
112 regexp))
113
d41d75fb
RS
114;; rmail-summary-by-topic
115;; 1989 R.A. Schnitzler
116
d2288651 117;;;###autoload
d41d75fb
RS
118(defun rmail-summary-by-topic (subject &optional whole-message)
119 "Display a summary of all messages with the given SUBJECT.
120Normally checks the Subject field of headers;
121but if WHOLE-MESSAGE is non-nil (prefix arg given),
122 look in the whole message.
123SUBJECT is a string of regexps separated by commas."
124 (interactive "sTopics to summarize by: \nP")
125 (rmail-new-summary
126 (concat "about " subject)
127 (list 'rmail-summary-by-topic subject whole-message)
128 'rmail-message-subject-p
129 (mail-comma-list-regexp subject) whole-message))
130
131(defun rmail-message-subject-p (msg subject &optional whole-message)
132 (save-restriction
133 (goto-char (rmail-msgbeg msg))
10a0a250 134 (search-forward "\n*** EOOH ***\n" (rmail-msgend msg) 'move)
d41d75fb
RS
135 (narrow-to-region
136 (point)
e90b6d92 137 (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
d41d75fb
RS
138 (goto-char (point-min))
139 (if whole-message (re-search-forward subject nil t)
140 (string-match subject (or (mail-fetch-field "Subject") "")) )))
cad1e93b 141
d2288651 142;;;###autoload
cad1e93b
RS
143(defun rmail-summary-by-senders (senders)
144 "Display a summary of all messages with the given SENDERS.
145SENDERS is a string of names separated by commas."
146 (interactive "sSenders to summarize by: ")
147 (rmail-new-summary
148 (concat "senders " senders)
84fa8eb5 149 (list 'rmail-summary-by-senders senders)
cad1e93b
RS
150 'rmail-message-senders-p
151 (mail-comma-list-regexp senders)))
152
153(defun rmail-message-senders-p (msg senders)
154 (save-restriction
155 (goto-char (rmail-msgbeg msg))
156 (search-forward "\n*** EOOH ***\n")
157 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
158 (string-match senders (or (mail-fetch-field "From") ""))))
4d4d11cc 159\f
d41d75fb
RS
160;; General making of a summary buffer.
161
162(defvar rmail-summary-symbol-number 0)
163
164(defun rmail-new-summary (description redo-form function &rest args)
4d4d11cc
JB
165 "Create a summary of selected messages.
166DESCRIPTION makes part of the mode line of the summary buffer.
167For each message, FUNCTION is applied to the message number and ARGS...
168and if the result is non-nil, that message is included.
169nil for FUNCTION means all messages."
170 (message "Computing summary lines...")
d41d75fb
RS
171 (let (sumbuf mesg was-in-summary)
172 (save-excursion
173 ;; Go to the Rmail buffer.
174 (if (eq major-mode 'rmail-summary-mode)
175 (progn
176 (setq was-in-summary t)
177 (set-buffer rmail-buffer)))
178 ;; Find its summary buffer, or make one.
deb5848d
RS
179 (setq sumbuf
180 (if (and rmail-summary-buffer
181 (buffer-name rmail-summary-buffer))
182 rmail-summary-buffer
183 (generate-new-buffer (concat (buffer-name) "-summary"))))
d41d75fb 184 (setq mesg rmail-current-message)
d41d75fb
RS
185 ;; Filter the messages; make or get their summary lines.
186 (let ((summary-msgs ())
187 (new-summary-line-count 0))
188 (let ((msgnum 1)
36f41915
KH
189 (buffer-read-only nil)
190 (old-min (point-min-marker))
191 (old-max (point-max-marker)))
192 ;; Can't use save-restriction here; that doesn't work if we
193 ;; plan to modify text outside the original restriction.
194 (save-excursion
195 (widen)
196 (goto-char (point-min))
197 (while (>= rmail-total-messages msgnum)
198 (if (or (null function)
199 (apply function (cons msgnum args)))
200 (setq summary-msgs
201 (cons (cons msgnum (rmail-make-summary-line msgnum))
202 summary-msgs)))
203 (setq msgnum (1+ msgnum)))
204 (setq summary-msgs (nreverse summary-msgs)))
205 (narrow-to-region old-min old-max))
deb5848d
RS
206 ;; Temporarily, while summary buffer is unfinished,
207 ;; we "don't have" a summary.
208 (setq rmail-summary-buffer nil)
209 (save-excursion
210 (let ((rbuf (current-buffer))
db56d71e 211 (vbuf rmail-view-buffer)
deb5848d
RS
212 (total rmail-total-messages))
213 (set-buffer sumbuf)
214 ;; Set up the summary buffer's contents.
215 (let ((buffer-read-only nil))
216 (erase-buffer)
217 (while summary-msgs
218 (princ (cdr (car summary-msgs)) sumbuf)
219 (setq summary-msgs (cdr summary-msgs)))
220 (goto-char (point-min)))
221 ;; Set up the rest of its state and local variables.
222 (setq buffer-read-only t)
223 (rmail-summary-mode)
224 (make-local-variable 'minor-mode-alist)
73d8f1de 225 (setq minor-mode-alist (list (list t (concat ": " description))))
deb5848d 226 (setq rmail-buffer rbuf
db56d71e 227 rmail-view-buffer vbuf
deb5848d
RS
228 rmail-summary-redo redo-form
229 rmail-total-messages total))))
230 (setq rmail-summary-buffer sumbuf))
d41d75fb
RS
231 ;; Now display the summary buffer and go to the right place in it.
232 (or was-in-summary
6e626f7e
RS
233 (progn
234 (if (and (one-window-p)
235 pop-up-windows (not pop-up-frames))
236 ;; If there is just one window, put the summary on the top.
237 (progn
238 (split-window (selected-window) rmail-summary-window-size)
239 (select-window (next-window (frame-first-window)))
240 (pop-to-buffer sumbuf)
241 ;; If pop-to-buffer did not use that window, delete that
242 ;; window. (This can happen if it uses another frame.)
243 (if (not (eq sumbuf (window-buffer (frame-first-window))))
244 (delete-other-windows)))
245 (pop-to-buffer sumbuf))
246 (set-buffer rmail-buffer)
247 ;; This is how rmail makes the summary buffer reappear.
248 ;; We do this here to make the window the proper size.
249 (rmail-select-summary nil)
250 (set-buffer rmail-summary-buffer)))
d41d75fb 251 (rmail-summary-goto-msg mesg t t)
88aabab3 252 (rmail-summary-construct-io-menu)
d41d75fb
RS
253 (message "Computing summary lines...done")))
254\f
255;; Low levels of generating a summary.
4d4d11cc
JB
256
257(defun rmail-make-summary-line (msg)
258 (let ((line (or (aref rmail-summary-vector (1- msg))
259 (progn
260 (setq new-summary-line-count
261 (1+ new-summary-line-count))
262 (if (zerop (% new-summary-line-count 10))
263 (message "Computing summary lines...%d"
264 new-summary-line-count))
265 (rmail-make-summary-line-1 msg)))))
266 ;; Fix up the part of the summary that says "deleted" or "unseen".
267 (aset line 4
268 (if (rmail-message-deleted-p msg) ?\D
269 (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg))))
270 ?\- ?\ )))
271 line))
272
db56d71e 273;;;###autoload
0a01a04e 274(defcustom rmail-summary-line-decoder (function identity)
db56d71e
KH
275 "*Function to decode summary-line.
276
0a01a04e
RS
277By default, `identity' is set."
278 :type 'function
279 :group 'rmail-summary)
db56d71e 280
4d4d11cc
JB
281(defun rmail-make-summary-line-1 (msg)
282 (goto-char (rmail-msgbeg msg))
283 (let* ((lim (save-excursion (forward-line 2) (point)))
284 pos
285 (labels
286 (progn
287 (forward-char 3)
288 (concat
289; (if (save-excursion (re-search-forward ",answered," lim t))
290; "*" "")
291; (if (save-excursion (re-search-forward ",filed," lim t))
292; "!" "")
293 (if (progn (search-forward ",,") (eolp))
294 ""
295 (concat "{"
296 (buffer-substring (point)
297 (progn (end-of-line) (point)))
298 "} ")))))
299 (line
300 (progn
301 (forward-line 1)
302 (if (looking-at "Summary-line: ")
303 (progn
304 (goto-char (match-end 0))
305 (setq line
306 (buffer-substring (point)
307 (progn (forward-line 1) (point)))))))))
308 ;; Obsolete status lines lacking a # should be flushed.
309 (and line
310 (not (string-match "#" line))
311 (progn
312 (delete-region (point)
313 (progn (forward-line -1) (point)))
314 (setq line nil)))
315 ;; If we didn't get a valid status line from the message,
316 ;; make a new one and put it in the message.
317 (or line
318 (let* ((case-fold-search t)
319 (next (rmail-msgend msg))
320 (beg (if (progn (goto-char (rmail-msgbeg msg))
321 (search-forward "\n*** EOOH ***\n" next t))
322 (point)
323 (forward-line 1)
324 (point)))
325 (end (progn (search-forward "\n\n" nil t) (point))))
326 (save-restriction
327 (narrow-to-region beg end)
328 (goto-char beg)
329 (setq line (rmail-make-basic-summary-line)))
330 (goto-char (rmail-msgbeg msg))
331 (forward-line 2)
332 (insert "Summary-line: " line)))
333 (setq pos (string-match "#" line))
334 (aset rmail-summary-vector (1- msg)
db56d71e
KH
335 (funcall rmail-summary-line-decoder
336 (concat (format "%4d " msg)
337 (substring line 0 pos)
338 labels
339 (substring line (1+ pos)))))
340 ))
4d4d11cc
JB
341
342(defun rmail-make-basic-summary-line ()
343 (goto-char (point-min))
344 (concat (save-excursion
345 (if (not (re-search-forward "^Date:" nil t))
346 " "
347 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
348 (save-excursion (end-of-line) (point)) t)
349 (format "%2d-%3s"
350 (string-to-int (buffer-substring
351 (match-beginning 2)
352 (match-end 2)))
353 (buffer-substring
354 (match-beginning 4) (match-end 4))))
355 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
356 (save-excursion (end-of-line) (point)) t)
357 (format "%2d-%3s"
358 (string-to-int (buffer-substring
359 (match-beginning 4)
360 (match-end 4)))
361 (buffer-substring
362 (match-beginning 2) (match-end 2))))
15065a0f
MB
363 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
364 (save-excursion (end-of-line) (point)) t)
365 (format "%2s%2s%2s"
366 (buffer-substring
367 (match-beginning 2) (match-end 2))
368 (buffer-substring
369 (match-beginning 3) (match-end 3))
370 (buffer-substring
371 (match-beginning 4) (match-end 4))))
4d4d11cc
JB
372 (t "??????"))))
373 " "
374 (save-excursion
375 (if (not (re-search-forward "^From:[ \t]*" nil t))
376 " "
377 (let* ((from (mail-strip-quoted-names
378 (buffer-substring
379 (1- (point))
4f5d303b
RS
380 ;; Get all the lines of the From field
381 ;; so that we get a whole comment if there is one,
382 ;; so that mail-strip-quoted-names can discard it.
383 (let ((opoint (point)))
384 (while (progn (forward-line 1)
385 (looking-at "[ \t]")))
386 ;; Back up over newline, then trailing spaces or tabs
387 (forward-char -1)
388 (skip-chars-backward " \t")
389 (point)))))
390 len mch lo)
b55535f3 391 (if (string-match (concat "^\\("
4d4d11cc 392 (regexp-quote (user-login-name))
b55535f3 393 "\\($\\|@\\)\\|"
b9cbdf45
KH
394 (regexp-quote
395 ;; Don't lose if run from init file
396 ;; where user-mail-address is not
397 ;; set yet.
398 (or user-mail-address
399 (concat (user-login-name) "@"
400 (or mail-host-address
401 (system-name)))))
b55535f3 402 "\\>\\)")
4d4d11cc
JB
403 from)
404 (save-excursion
405 (goto-char (point-min))
406 (if (not (re-search-forward "^To:[ \t]*" nil t))
407 nil
408 (setq from
409 (concat "to: "
410 (mail-strip-quoted-names
411 (buffer-substring
412 (point)
413 (progn (end-of-line)
414 (skip-chars-backward " \t")
415 (point)))))))))
416 (setq len (length from))
417 (setq mch (string-match "[@%]" from))
418 (format "%25s"
419 (if (or (not mch) (<= len 25))
420 (substring from (max 0 (- len 25)))
421 (substring from
95412165
RS
422 (setq lo (cond ((< (- mch 14) 0) 0)
423 ((< len (+ mch 11))
4d4d11cc 424 (- len 25))
95412165 425 (t (- mch 14))))
4d4d11cc 426 (min len (+ lo 25))))))))
4f21aa66 427 (if rmail-summary-line-count-flag
ea7bddc4
RS
428 (save-excursion
429 (save-restriction
430 (widen)
431 (let ((beg (rmail-msgbeg msgnum))
432 (end (rmail-msgend msgnum))
433 lines)
434 (save-excursion
435 (goto-char beg)
436 ;; Count only lines in the reformatted header,
437 ;; if we have reformatted it.
438 (search-forward "\n*** EOOH ***\n" end t)
439 (setq lines (count-lines (point) end)))
440 (format (cond
441 ((<= lines 9) " [%d]")
442 ((<= lines 99) " [%d]")
443 ((<= lines 999) " [%3d]")
444 (t "[%d]"))
445 lines))))
446 " ")
972a769b 447 " #" ;The # is part of the format.
4d4d11cc
JB
448 (if (re-search-forward "^Subject:" nil t)
449 (progn (skip-chars-forward " \t")
450 (buffer-substring (point)
451 (progn (end-of-line)
452 (point))))
453 (re-search-forward "[\n][\n]+" nil t)
454 (buffer-substring (point) (progn (end-of-line) (point))))
455 "\n"))
d41d75fb
RS
456\f
457;; Simple motion in a summary buffer.
4d4d11cc
JB
458
459(defun rmail-summary-next-all (&optional number)
460 (interactive "p")
bb694792 461 (forward-line (if number number 1))
cc101382
RS
462 ;; It doesn't look nice to move forward past the last message line.
463 (and (eobp) (> number 0)
464 (forward-line -1))
bb694792 465 (display-buffer rmail-buffer))
4d4d11cc
JB
466
467(defun rmail-summary-previous-all (&optional number)
468 (interactive "p")
bb694792 469 (forward-line (- (if number number 1)))
cc101382
RS
470 ;; It doesn't look nice to move forward past the last message line.
471 (and (eobp) (< number 0)
472 (forward-line -1))
bb694792 473 (display-buffer rmail-buffer))
4d4d11cc
JB
474
475(defun rmail-summary-next-msg (&optional number)
d41d75fb
RS
476 "Display next non-deleted msg from rmail file.
477With optional prefix argument NUMBER, moves forward this number of non-deleted
478messages, or backward if NUMBER is negative."
4d4d11cc
JB
479 (interactive "p")
480 (forward-line 0)
b37767e7 481 (and (> number 0) (end-of-line))
4d4d11cc
JB
482 (let ((count (if (< number 0) (- number) number))
483 (search (if (> number 0) 're-search-forward 're-search-backward))
d41d75fb
RS
484 (non-del-msg-found nil))
485 (while (and (> count 0) (setq non-del-msg-found
682ac5eb 486 (or (funcall search "^....[^D]" nil t)
d41d75fb 487 non-del-msg-found)))
bb694792 488 (setq count (1- count))))
b37767e7 489 (beginning-of-line)
db56d71e
KH
490 (display-buffer rmail-view-buffer)
491 )
4d4d11cc
JB
492
493(defun rmail-summary-previous-msg (&optional number)
494 (interactive "p")
495 (rmail-summary-next-msg (- (if number number 1))))
496
d41d75fb
RS
497(defun rmail-summary-next-labeled-message (n labels)
498 "Show next message with LABEL. Defaults to last labels used.
499With prefix argument N moves forward N messages with these labels."
500 (interactive "p\nsMove to next msg with labels: ")
d69006df
KH
501 (let (msg)
502 (save-excursion
503 (set-buffer rmail-buffer)
504 (rmail-next-labeled-message n labels)
505 (setq msg rmail-current-message))
506 (rmail-summary-goto-msg msg)))
d41d75fb
RS
507
508(defun rmail-summary-previous-labeled-message (n labels)
509 "Show previous message with LABEL. Defaults to last labels used.
510With prefix argument N moves backward N messages with these labels."
511 (interactive "p\nsMove to previous msg with labels: ")
d69006df
KH
512 (let (msg)
513 (save-excursion
514 (set-buffer rmail-buffer)
515 (rmail-previous-labeled-message n labels)
516 (setq msg rmail-current-message))
517 (rmail-summary-goto-msg msg)))
71d97b56
RS
518
519(defun rmail-summary-next-same-subject (n)
520 "Go to the next message in the summary having the same subject.
521With prefix argument N, do this N times.
522If N is negative, go backwards."
523 (interactive "p")
524 (let (subject search-regexp i found
525 (forward (> n 0)))
526 (save-excursion
527 (set-buffer rmail-buffer)
528 (setq subject (mail-fetch-field "Subject"))
71d97b56
RS
529 (setq i rmail-current-message))
530 (if (string-match "Re:[ \t]*" subject)
531 (setq subject (substring subject (match-end 0))))
5be36e20
RS
532 (setq search-regexp (concat "^Subject: *\\(Re: *\\)?"
533 (regexp-quote subject)
534 "\n"))
71d97b56
RS
535 (save-excursion
536 (while (and (/= n 0)
537 (if forward
538 (not (eobp))
539 (not (bobp))))
540 (let (done)
541 (while (and (not done)
542 (if forward
543 (not (eobp))
544 (not (bobp))))
545 ;; Advance thru summary.
546 (forward-line (if forward 1 -1))
547 ;; Get msg number of this line.
548 (setq i (string-to-int
549 (buffer-substring (point)
550 (min (point-max) (+ 5 (point))))))
551 ;; See if that msg has desired subject.
552 (save-excursion
553 (set-buffer rmail-buffer)
554 (save-restriction
555 (widen)
556 (goto-char (rmail-msgbeg i))
557 (search-forward "\n*** EOOH ***\n")
558 (let ((beg (point)) end)
559 (search-forward "\n\n")
560 (setq end (point))
561 (goto-char beg)
562 (setq done (re-search-forward search-regexp end t))))))
563 (if done (setq found i)))
564 (setq n (if forward (1- n) (1+ n)))))
565 (if found
566 (rmail-summary-goto-msg found)
567 (error "No %s message with same subject"
568 (if forward "following" "previous")))))
569
570(defun rmail-summary-previous-same-subject (n)
571 "Go to the previous message in the summary having the same subject.
572With prefix argument N, do this N times.
573If N is negative, go forwards instead."
574 (interactive "p")
575 (rmail-summary-next-same-subject (- n)))
d41d75fb
RS
576\f
577;; Delete and undelete summary commands.
578
93cba994 579(defun rmail-summary-delete-forward (&optional count)
d41d75fb
RS
580 "Delete this message and move to next nondeleted one.
581Deleted messages stay in the file until the \\[rmail-expunge] command is given.
93cba994
RS
582A prefix argument serves as a repeat count;
583a negative argument means to delete and move backward."
584 (interactive "p")
ecb4dd9a 585 (unless (numberp count) (setq count 1))
93cba994
RS
586 (let (end del-msg
587 (backward (< count 0)))
588 (while (/= count 0)
589 (rmail-summary-goto-msg)
590 (with-current-buffer rmail-buffer
591 (rmail-delete-message)
592 (setq del-msg rmail-current-message))
92a38267
RS
593 (rmail-summary-mark-deleted del-msg)
594 (while (and (not (if backward (bobp) (eobp)))
94eeb96a 595 (save-excursion (beginning-of-line)
7434015f 596 (looking-at " *[0-9]+D")))
cdbea8ca
RS
597 (forward-line (if backward -1 1)))
598 ;; It looks ugly to move to the empty line at end of buffer.
599 (and (eobp) (not backward)
93cba994
RS
600 (forward-line -1))
601 (setq count
602 (if (> count 0) (1- count) (1+ count))))))
4d4d11cc 603
93cba994 604(defun rmail-summary-delete-backward (&optional count)
d41d75fb 605 "Delete this message and move to previous nondeleted one.
93cba994
RS
606Deleted messages stay in the file until the \\[rmail-expunge] command is given.
607A prefix argument serves as a repeat count;
608a negative argument means to delete and move forward."
609 (interactive "p")
610 (rmail-summary-delete-forward (- count)))
4d4d11cc 611
d41d75fb 612(defun rmail-summary-mark-deleted (&optional n undel)
85bd1ac6 613 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
fedc33f7
RS
614 (and n (rmail-summary-goto-msg n t t))
615 (or (eobp)
4fb6f90f 616 (not (overlay-get rmail-summary-overlay 'face))
fedc33f7
RS
617 (let ((buffer-read-only nil))
618 (skip-chars-forward " ")
619 (skip-chars-forward "[0-9]")
620 (if undel
621 (if (looking-at "D")
622 (progn (delete-char 1) (insert " ")))
623 (delete-char 1)
624 (insert "D"))))
d41d75fb
RS
625 (beginning-of-line))
626
627(defun rmail-summary-mark-undeleted (n)
628 (rmail-summary-mark-deleted n t))
629
630(defun rmail-summary-deleted-p (&optional n)
631 (save-excursion
632 (and n (rmail-summary-goto-msg n nil t))
633 (skip-chars-forward " ")
634 (skip-chars-forward "[0-9]")
635 (looking-at "D")))
4d4d11cc 636
d41d75fb
RS
637(defun rmail-summary-undelete (&optional arg)
638 "Undelete current message.
639Optional prefix ARG means undelete ARG previous messages."
640 (interactive "p")
641 (if (/= arg 1)
642 (rmail-summary-undelete-many arg)
5ed1243c
RS
643 (let ((buffer-read-only nil)
644 (opoint (point)))
d41d75fb
RS
645 (end-of-line)
646 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
647 (replace-match "\\1 ")
648 (rmail-summary-goto-msg)
649 (pop-to-buffer rmail-buffer)
650 (and (rmail-message-deleted-p rmail-current-message)
651 (rmail-undelete-previous-message))
5ed1243c
RS
652 (pop-to-buffer rmail-summary-buffer))
653 (t (goto-char opoint))))))
d41d75fb
RS
654
655(defun rmail-summary-undelete-many (&optional n)
656 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
657 (interactive "P")
658 (save-excursion
659 (set-buffer rmail-buffer)
660 (let* ((init-msg (if n rmail-current-message rmail-total-messages))
661 (rmail-current-message init-msg)
662 (n (or n rmail-total-messages))
663 (msgs-undeled 0))
664 (while (and (> rmail-current-message 0)
665 (< msgs-undeled n))
666 (if (rmail-message-deleted-p rmail-current-message)
667 (progn (rmail-set-attribute "deleted" nil)
668 (setq msgs-undeled (1+ msgs-undeled))))
669 (setq rmail-current-message (1- rmail-current-message)))
670 (set-buffer rmail-summary-buffer)
671 (setq rmail-current-message init-msg msgs-undeled 0)
672 (while (and (> rmail-current-message 0)
673 (< msgs-undeled n))
674 (if (rmail-summary-deleted-p rmail-current-message)
675 (progn (rmail-summary-mark-undeleted rmail-current-message)
676 (setq msgs-undeled (1+ msgs-undeled))))
677 (setq rmail-current-message (1- rmail-current-message))))
678 (rmail-summary-goto-msg)))
679\f
4d4d11cc
JB
680;; Rmail Summary mode is suitable only for specially formatted data.
681(put 'rmail-summary-mode 'mode-class 'special)
682
683(defun rmail-summary-mode ()
d41d75fb
RS
684 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
685As commands are issued in the summary buffer, they are applied to the
686corresponding mail messages in the rmail buffer.
687
688All normal editing commands are turned off.
9cd78473
RS
689Instead, nearly all the Rmail mode commands are available,
690though many of them move only among the messages in the summary.
d41d75fb 691
9cd78473
RS
692These additional commands exist:
693
694\\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
695\\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
696
697Commands for sorting the summary:
698
699\\[rmail-summary-sort-by-date] Sort by date.
700\\[rmail-summary-sort-by-subject] Sort by subject.
701\\[rmail-summary-sort-by-author] Sort by author.
702\\[rmail-summary-sort-by-recipient] Sort by recipient.
703\\[rmail-summary-sort-by-correspondent] Sort by correspondent.
ebdf372b
KH
704\\[rmail-summary-sort-by-lines] Sort by lines.
705\\[rmail-summary-sort-by-keywords] Sort by keywords."
4d4d11cc
JB
706 (interactive)
707 (kill-all-local-variables)
4d4d11cc
JB
708 (setq major-mode 'rmail-summary-mode)
709 (setq mode-name "RMAIL Summary")
4d4d11cc
JB
710 (setq truncate-lines t)
711 (setq buffer-read-only t)
712 (set-syntax-table text-mode-syntax-table)
d41d75fb 713 (make-local-variable 'rmail-buffer)
db56d71e 714 (make-local-variable 'rmail-view-buffer)
d41d75fb
RS
715 (make-local-variable 'rmail-total-messages)
716 (make-local-variable 'rmail-current-message)
717 (setq rmail-current-message nil)
718 (make-local-variable 'rmail-summary-redo)
719 (setq rmail-summary-redo nil)
720 (make-local-variable 'revert-buffer-function)
c28baa2a 721 (make-local-hook 'post-command-hook)
d16df573
SM
722 (make-local-variable 'font-lock-defaults)
723 (setq font-lock-defaults '(rmail-summary-font-lock-keywords t))
0732dfa5 724 (rmail-summary-enable)
4d4d11cc
JB
725 (run-hooks 'rmail-summary-mode-hook))
726
0732dfa5
KH
727;; Summary features need to be disabled during edit mode.
728(defun rmail-summary-disable ()
56b25713 729 (use-local-map text-mode-map)
c28baa2a 730 (remove-hook 'post-command-hook 'rmail-summary-rmail-update t)
56b25713 731 (setq revert-buffer-function nil))
0732dfa5
KH
732
733(defun rmail-summary-enable ()
56b25713 734 (use-local-map rmail-summary-mode-map)
c28baa2a 735 (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
56b25713 736 (setq revert-buffer-function 'rmail-update-summary))
0732dfa5 737
5be36e20
RS
738(defvar rmail-summary-put-back-unseen nil
739 "Used for communicating between calls to `rmail-summary-rmail-update'.
740If it moves to a message within an Incremental Search, and removes
741the `unseen' attribute from that message, it sets this flag
742so that if the next motion between messages is in the same Incremental
743Search, the `unseen' attribute is restored.")
744
bb694792
RS
745;; Show in Rmail the message described by the summary line that point is on,
746;; but only if the Rmail buffer is already visible.
d41d75fb
RS
747;; This is a post-command-hook in summary buffers.
748(defun rmail-summary-rmail-update ()
10e09db4
KH
749 (let (buffer-read-only)
750 (save-excursion
751 ;; If at end of buffer, pretend we are on the last text line.
752 (if (eobp)
753 (forward-line -1))
754 (beginning-of-line)
755 (skip-chars-forward " ")
756 (let ((msg-num (string-to-int (buffer-substring
757 (point)
758 (progn (skip-chars-forward "0-9")
759 (point))))))
5be36e20
RS
760 ;; Always leave `unseen' removed
761 ;; if we get out of isearch mode.
762 ;; Don't let a subsequent isearch restore that `unseen'.
763 (if (not isearch-mode)
764 (setq rmail-summary-put-back-unseen nil))
765
10e09db4 766 (or (eq rmail-current-message msg-num)
8efaaf11 767 (let ((window (get-buffer-window rmail-view-buffer t))
10e09db4 768 (owin (selected-window)))
5be36e20
RS
769 (if isearch-mode
770 (save-excursion
771 (set-buffer rmail-buffer)
772 ;; If we first saw the previous message in this search,
773 ;; and we have gone to a different message while searching,
774 ;; put back `unseen' on the former one.
1dbd9103 775 (if rmail-summary-put-back-unseen
c9aa3ef8
KH
776 (rmail-set-attribute "unseen" t
777 rmail-current-message))
5be36e20
RS
778 ;; Arrange to do that later, for the new current message,
779 ;; if it still has `unseen'.
780 (setq rmail-summary-put-back-unseen
781 (rmail-message-labels-p msg-num ", ?\\(unseen\\),")))
782 (setq rmail-summary-put-back-unseen nil))
783
784 ;; Go to the desired message.
10e09db4 785 (setq rmail-current-message msg-num)
5be36e20
RS
786
787 ;; Update the summary to show the message has been seen.
10e09db4
KH
788 (if (= (following-char) ?-)
789 (progn
790 (delete-char 1)
791 (insert " ")))
5be36e20 792
10e09db4
KH
793 (if window
794 ;; Using save-window-excursion would cause the new value
980d43b6
RS
795 ;; of point to get lost.
796 (unwind-protect
797 (progn
798 (select-window window)
bc454f08 799 (rmail-show-message msg-num t))
10e09db4 800 (select-window owin))
dca46072
RS
801 (if (buffer-name rmail-buffer)
802 (save-excursion
803 (set-buffer rmail-buffer)
4fb6f90f
RS
804 (rmail-show-message msg-num t))))))
805 (rmail-summary-update-highlight nil)))))
d41d75fb
RS
806\f
807(defvar rmail-summary-mode-map nil)
808
809(if rmail-summary-mode-map
810 nil
811 (setq rmail-summary-mode-map (make-keymap))
812 (suppress-keymap rmail-summary-mode-map)
4ab455e6
RS
813
814 (define-key rmail-summary-mode-map [mouse-2] 'rmail-summary-mouse-goto-message)
d41d75fb 815 (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label)
00f3d57d 816 (define-key rmail-summary-mode-map "b" 'rmail-summary-bury)
d41d75fb
RS
817 (define-key rmail-summary-mode-map "c" 'rmail-summary-continue)
818 (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward)
819 (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward)
820 (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message)
821 (define-key rmail-summary-mode-map "f" 'rmail-summary-forward)
822 (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail)
823 (define-key rmail-summary-mode-map "h" 'rmail-summary)
824 (define-key rmail-summary-mode-map "i" 'rmail-summary-input)
825 (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg)
826 (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label)
827 (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels)
828 (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
829 (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
830 (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
831 (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
832 (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
833 (define-key rmail-summary-mode-map "m" 'rmail-summary-mail)
834 (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure)
835 (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg)
d41d75fb
RS
836 (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all)
837 (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
838 (define-key rmail-summary-mode-map "o" 'rmail-summary-output-to-rmail-file)
839 (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output)
840 (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg)
d41d75fb
RS
841 (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all)
842 (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
843 (define-key rmail-summary-mode-map "q" 'rmail-summary-quit)
d5bafc55 844 (define-key rmail-summary-mode-map "Q" 'rmail-summary-wipe)
d41d75fb
RS
845 (define-key rmail-summary-mode-map "r" 'rmail-summary-reply)
846 (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save)
847 (define-key rmail-summary-mode-map "\es" 'rmail-summary-search)
848 (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header)
849 (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete)
850 (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many)
d41d75fb 851 (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge)
d5bafc55 852 (define-key rmail-summary-mode-map "w" 'rmail-summary-output-body)
d41d75fb
RS
853 (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message)
854 (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message)
855 (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message)
856 (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up)
857 (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down)
858 (define-key rmail-summary-mode-map "?" 'describe-mode)
71d97b56
RS
859 (define-key rmail-summary-mode-map "\C-c\C-n" 'rmail-summary-next-same-subject)
860 (define-key rmail-summary-mode-map "\C-c\C-p" 'rmail-summary-previous-same-subject)
e45fce03
RS
861 (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
862 'rmail-summary-sort-by-date)
863 (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
864 'rmail-summary-sort-by-subject)
865 (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
866 'rmail-summary-sort-by-author)
867 (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
868 'rmail-summary-sort-by-recipient)
869 (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
870 'rmail-summary-sort-by-correspondent)
871 (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
872 'rmail-summary-sort-by-lines)
ebdf372b
KH
873 (define-key rmail-summary-mode-map "\C-c\C-s\C-k"
874 'rmail-summary-sort-by-keywords)
d41d75fb
RS
875 )
876\f
e7a00c25
RS
877;;; Menu bar bindings.
878
879(define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
880
881(define-key rmail-summary-mode-map [menu-bar classify]
882 (cons "Classify" (make-sparse-keymap "Classify")))
883
dca46072
RS
884(define-key rmail-summary-mode-map [menu-bar classify output-menu]
885 '("Output (Rmail Menu)..." . rmail-summary-output-menu))
886
887(define-key rmail-summary-mode-map [menu-bar classify input-menu]
0e520d74 888 '("Input Rmail File (menu)..." . rmail-input-menu))
dca46072 889
aa138cb4
RS
890(define-key rmail-summary-mode-map [menu-bar classify input-menu]
891 '(nil))
892
893(define-key rmail-summary-mode-map [menu-bar classify output-menu]
894 '(nil))
895
d5bafc55
RS
896(define-key rmail-summary-mode-map [menu-bar classify output-body]
897 '("Output (body)..." . rmail-summary-output-body))
898
e7a00c25 899(define-key rmail-summary-mode-map [menu-bar classify output-inbox]
29e6129e 900 '("Output (inbox)..." . rmail-summary-output))
e7a00c25
RS
901
902(define-key rmail-summary-mode-map [menu-bar classify output]
29e6129e 903 '("Output (Rmail)..." . rmail-summary-output-to-rmail-file))
e7a00c25
RS
904
905(define-key rmail-summary-mode-map [menu-bar classify kill-label]
29e6129e 906 '("Kill Label..." . rmail-summary-kill-label))
e7a00c25
RS
907
908(define-key rmail-summary-mode-map [menu-bar classify add-label]
29e6129e 909 '("Add Label..." . rmail-summary-add-label))
e7a00c25
RS
910
911(define-key rmail-summary-mode-map [menu-bar summary]
912 (cons "Summary" (make-sparse-keymap "Summary")))
913
c1046d18
RS
914(define-key rmail-summary-mode-map [menu-bar summary senders]
915 '("By Senders..." . rmail-summary-by-senders))
916
e7a00c25 917(define-key rmail-summary-mode-map [menu-bar summary labels]
29e6129e 918 '("By Labels..." . rmail-summary-by-labels))
e7a00c25
RS
919
920(define-key rmail-summary-mode-map [menu-bar summary recipients]
29e6129e 921 '("By Recipients..." . rmail-summary-by-recipients))
e7a00c25
RS
922
923(define-key rmail-summary-mode-map [menu-bar summary topic]
29e6129e 924 '("By Topic..." . rmail-summary-by-topic))
e7a00c25
RS
925
926(define-key rmail-summary-mode-map [menu-bar summary regexp]
29e6129e 927 '("By Regexp..." . rmail-summary-by-regexp))
e7a00c25
RS
928
929(define-key rmail-summary-mode-map [menu-bar summary all]
930 '("All" . rmail-summary))
931
932(define-key rmail-summary-mode-map [menu-bar mail]
933 (cons "Mail" (make-sparse-keymap "Mail")))
934
e76bca6c 935(define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail]
b0d3522a
RS
936 '("Get New Mail" . rmail-summary-get-new-mail))
937
c0d133a6 938(define-key rmail-summary-mode-map [menu-bar mail lambda]
b0d3522a 939 '("----"))
aba6cc35 940
e7a00c25
RS
941(define-key rmail-summary-mode-map [menu-bar mail continue]
942 '("Continue" . rmail-summary-continue))
943
b0d3522a 944(define-key rmail-summary-mode-map [menu-bar mail resend]
4986bd38 945 '("Re-send..." . rmail-summary-resend))
b0d3522a 946
e7a00c25
RS
947(define-key rmail-summary-mode-map [menu-bar mail forward]
948 '("Forward" . rmail-summary-forward))
949
950(define-key rmail-summary-mode-map [menu-bar mail retry]
951 '("Retry" . rmail-summary-retry-failure))
952
953(define-key rmail-summary-mode-map [menu-bar mail reply]
954 '("Reply" . rmail-summary-reply))
955
956(define-key rmail-summary-mode-map [menu-bar mail mail]
957 '("Mail" . rmail-summary-mail))
958
959(define-key rmail-summary-mode-map [menu-bar delete]
960 (cons "Delete" (make-sparse-keymap "Delete")))
961
962(define-key rmail-summary-mode-map [menu-bar delete expunge/save]
963 '("Expunge/Save" . rmail-summary-expunge-and-save))
964
965(define-key rmail-summary-mode-map [menu-bar delete expunge]
966 '("Expunge" . rmail-summary-expunge))
967
968(define-key rmail-summary-mode-map [menu-bar delete undelete]
969 '("Undelete" . rmail-summary-undelete))
970
971(define-key rmail-summary-mode-map [menu-bar delete delete]
972 '("Delete" . rmail-summary-delete-forward))
973
974(define-key rmail-summary-mode-map [menu-bar move]
975 (cons "Move" (make-sparse-keymap "Move")))
976
977(define-key rmail-summary-mode-map [menu-bar move search-back]
29e6129e 978 '("Search Back..." . rmail-summary-search-backward))
e7a00c25
RS
979
980(define-key rmail-summary-mode-map [menu-bar move search]
29e6129e 981 '("Search..." . rmail-summary-search))
e7a00c25
RS
982
983(define-key rmail-summary-mode-map [menu-bar move previous]
984 '("Previous Nondeleted" . rmail-summary-previous-msg))
985
986(define-key rmail-summary-mode-map [menu-bar move next]
987 '("Next Nondeleted" . rmail-summary-next-msg))
988
989(define-key rmail-summary-mode-map [menu-bar move last]
990 '("Last" . rmail-summary-last-message))
991
992(define-key rmail-summary-mode-map [menu-bar move first]
993 '("First" . rmail-summary-first-message))
994
995(define-key rmail-summary-mode-map [menu-bar move previous]
996 '("Previous" . rmail-summary-previous-all))
997
998(define-key rmail-summary-mode-map [menu-bar move next]
999 '("Next" . rmail-summary-next-all))
1000\f
4197af8a 1001(defvar rmail-summary-overlay nil)
212daf13 1002(put 'rmail-summary-overlay 'permanent-local t)
4197af8a 1003
4ab455e6
RS
1004(defun rmail-summary-mouse-goto-message (event)
1005 "Select the message whose summary line you click on."
1006 (interactive "@e")
1007 (goto-char (posn-point (event-end event)))
1008 (rmail-summary-goto-msg))
85bd1ac6 1009
d41d75fb 1010(defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
4ab455e6
RS
1011 "Go to message N in the summary buffer and the Rmail buffer.
1012If N is nil, use the message corresponding to point in the summary
1013and move to that message in the Rmail buffer.
1014
1015If NOWARN, don't say anything if N is out of range.
1016If SKIP-RMAIL, don't do anything to the Rmail buffer."
4d4d11cc
JB
1017 (interactive "P")
1018 (if (consp n) (setq n (prefix-numeric-value n)))
1019 (if (eobp) (forward-line -1))
1020 (beginning-of-line)
132ad564
RS
1021 (let* ((obuf (current-buffer))
1022 (buf rmail-buffer)
1023 (cur (point))
1024 message-not-found
1025 (curmsg (string-to-int
1026 (buffer-substring (point)
1027 (min (point-max) (+ 5 (point))))))
1028 (total (save-excursion (set-buffer buf) rmail-total-messages)))
4197af8a
RS
1029 ;; If message number N was specified, find that message's line
1030 ;; or set message-not-found.
1031 ;; If N wasn't specified or that message can't be found.
1032 ;; set N by default.
4d4d11cc
JB
1033 (if (not n)
1034 (setq n curmsg)
1035 (if (< n 1)
1036 (progn (message "No preceding message")
1037 (setq n 1)))
132ad564 1038 (if (> n total)
4d4d11cc
JB
1039 (progn (message "No following message")
1040 (goto-char (point-max))
85bd1ac6 1041 (rmail-summary-goto-msg nil nowarn skip-rmail)))
4d4d11cc 1042 (goto-char (point-min))
4dc7e43b 1043 (if (not (re-search-forward (format "^%4d[^0-9]" n) nil t))
4d4d11cc
JB
1044 (progn (or nowarn (message "Message %d not found" n))
1045 (setq n curmsg)
4197af8a 1046 (setq message-not-found t)
4d4d11cc
JB
1047 (goto-char cur))))
1048 (beginning-of-line)
1049 (skip-chars-forward " ")
1050 (skip-chars-forward "0-9")
1051 (save-excursion (if (= (following-char) ?-)
1052 (let ((buffer-read-only nil))
1053 (delete-char 1)
1054 (insert " "))))
4fb6f90f 1055 (rmail-summary-update-highlight message-not-found)
4d4d11cc 1056 (beginning-of-line)
d41d75fb
RS
1057 (if skip-rmail
1058 nil
857ff384
RS
1059 (let ((selwin (selected-window)))
1060 (unwind-protect
1061 (progn (pop-to-buffer buf)
1062 (rmail-show-message n))
c7b5ca27
RS
1063 (select-window selwin)
1064 ;; The actions above can alter the current buffer. Preserve it.
1065 (set-buffer obuf))))))
4fb6f90f
RS
1066
1067;; Update the highlighted line in an rmail summary buffer.
1068;; That should be current. We highlight the line point is on.
1069;; If NOT-FOUND is non-nil, we turn off highlighting.
1070(defun rmail-summary-update-highlight (not-found)
1071 ;; Make sure we have an overlay to use.
1072 (or rmail-summary-overlay
1073 (progn
1074 (make-local-variable 'rmail-summary-overlay)
1075 (setq rmail-summary-overlay (make-overlay (point) (point)))))
1076 ;; If this message is in the summary, use the overlay to highlight it.
1077 ;; Otherwise, don't highlight anything.
1078 (if not-found
1079 (overlay-put rmail-summary-overlay 'face nil)
1080 (move-overlay rmail-summary-overlay
1081 (save-excursion (beginning-of-line)
1082 (skip-chars-forward " ")
1083 (point))
1084 (save-excursion (end-of-line) (point)))
1085 (overlay-put rmail-summary-overlay 'face 'highlight)))
d41d75fb 1086\f
4d4d11cc 1087(defun rmail-summary-scroll-msg-up (&optional dist)
3753ab6f
RS
1088 "Scroll the Rmail window forward.
1089If the Rmail window is displaying the end of a message,
1090advance to the next message."
4d4d11cc 1091 (interactive "P")
3753ab6f
RS
1092 (if (eq dist '-)
1093 (rmail-summary-scroll-msg-down nil)
db56d71e 1094 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer)))
3753ab6f
RS
1095 (if rmail-buffer-window
1096 (if (let ((rmail-summary-window (selected-window)))
1097 (select-window rmail-buffer-window)
1098 (prog1
1099 ;; Is EOB visible in the buffer?
1100 (save-excursion
1101 (let ((ht (window-height (selected-window))))
1102 (move-to-window-line (- ht 2))
1103 (end-of-line)
1104 (eobp)))
1105 (select-window rmail-summary-window)))
be2e861f
RS
1106 (if (not rmail-summary-scroll-between-messages)
1107 (error "End of buffer")
1108 (rmail-summary-next-msg (or dist 1)))
db56d71e 1109 (let ((other-window-scroll-buffer rmail-view-buffer))
3753ab6f 1110 (scroll-other-window dist)))
37eb1878
RS
1111 ;; If it isn't visible at all, show the beginning.
1112 (rmail-summary-beginning-of-message)))))
4d4d11cc
JB
1113
1114(defun rmail-summary-scroll-msg-down (&optional dist)
3753ab6f 1115 "Scroll the Rmail window backward.
37eb1878
RS
1116If the Rmail window is now displaying the beginning of a message,
1117move to the previous message."
4d4d11cc 1118 (interactive "P")
3753ab6f
RS
1119 (if (eq dist '-)
1120 (rmail-summary-scroll-msg-up nil)
1121 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1122 (if rmail-buffer-window
1123 (if (let ((rmail-summary-window (selected-window)))
1124 (select-window rmail-buffer-window)
1125 (prog1
1126 ;; Is BOB visible in the buffer?
1127 (save-excursion
1128 (move-to-window-line 0)
1129 (beginning-of-line)
1130 (bobp))
1131 (select-window rmail-summary-window)))
be2e861f
RS
1132 (if (not rmail-summary-scroll-between-messages)
1133 (error "Beginning of buffer")
1134 (rmail-summary-previous-msg (or dist 1)))
3753ab6f
RS
1135 (let ((other-window-scroll-buffer rmail-buffer))
1136 (scroll-other-window-down dist)))
37eb1878
RS
1137 ;; If it isn't visible at all, show the beginning.
1138 (rmail-summary-beginning-of-message)))))
d41d75fb
RS
1139
1140(defun rmail-summary-beginning-of-message ()
1141 "Show current message from the beginning."
1142 (interactive)
37eb1878
RS
1143 (if (and (one-window-p) (not pop-up-frames))
1144 ;; If there is just one window, put the summary on the top.
1145 (let ((buffer rmail-buffer))
1146 (split-window (selected-window) rmail-summary-window-size)
1147 (select-window (frame-first-window))
1148 (pop-to-buffer rmail-buffer)
1149 ;; If pop-to-buffer did not use that window, delete that
1150 ;; window. (This can happen if it uses another frame.)
1151 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1152 (delete-other-windows)))
1153 (pop-to-buffer rmail-buffer))
d41d75fb
RS
1154 (beginning-of-buffer)
1155 (pop-to-buffer rmail-summary-buffer))
4d4d11cc 1156
00f3d57d
RS
1157(defun rmail-summary-bury ()
1158 "Bury the Rmail buffer and the Rmail summary buffer."
1159 (interactive)
1160 (let ((buffer-to-bury (current-buffer)))
1161 (let (window)
1162 (while (setq window (get-buffer-window rmail-buffer))
1163 (set-window-buffer window (other-buffer rmail-buffer)))
1164 (bury-buffer rmail-buffer))
1165 (switch-to-buffer (other-buffer buffer-to-bury))
1166 (bury-buffer buffer-to-bury)))
1167
4d4d11cc 1168(defun rmail-summary-quit ()
d41d75fb 1169 "Quit out of Rmail and Rmail summary."
4d4d11cc 1170 (interactive)
d41d75fb 1171 (rmail-summary-wipe)
4d4d11cc
JB
1172 (rmail-quit))
1173
d41d75fb
RS
1174(defun rmail-summary-wipe ()
1175 "Kill and wipe away Rmail summary, remaining within Rmail."
4d4d11cc 1176 (interactive)
d41d75fb 1177 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
9cd78473 1178 (let ((local-rmail-buffer rmail-buffer))
d41d75fb
RS
1179 (kill-buffer (current-buffer))
1180 ;; Delete window if not only one.
1181 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1182 (delete-window))
9cd78473
RS
1183 ;; Switch windows to the rmail buffer, or switch to it in this window.
1184 (pop-to-buffer local-rmail-buffer)))
d41d75fb
RS
1185
1186(defun rmail-summary-expunge ()
1187 "Actually erase all deleted messages and recompute summary headers."
1188 (interactive)
1189 (save-excursion
1190 (set-buffer rmail-buffer)
1191 (rmail-only-expunge))
1192 (rmail-update-summary))
1193
1194(defun rmail-summary-expunge-and-save ()
1195 "Expunge and save RMAIL file."
1196 (interactive)
1197 (save-excursion
1198 (set-buffer rmail-buffer)
b37767e7
RS
1199 (rmail-only-expunge))
1200 (rmail-update-summary)
1201 (save-excursion
980d43b6 1202 (set-buffer rmail-buffer)
ccc341de
KH
1203 (save-buffer))
1204 (set-buffer-modified-p nil))
d41d75fb 1205
3198a3d5
RS
1206(defun rmail-summary-get-new-mail (&optional file-name)
1207 "Get new mail and recompute summary headers.
1208
1209Optionally you can specify the file to get new mail from. In this case,
1210the file of new mail is not changed or deleted. Noninteractively, you can
1211pass the inbox file name as an argument. Interactively, a prefix
1212argument says to read a file name and use that file as the inbox."
1213 (interactive
1214 (list (if current-prefix-arg
1215 (read-file-name "Get new mail from file: "))))
b37767e7
RS
1216 (let (msg)
1217 (save-excursion
1218 (set-buffer rmail-buffer)
3198a3d5 1219 (rmail-get-new-mail file-name)
b37767e7
RS
1220 ;; Get the proper new message number.
1221 (setq msg rmail-current-message))
1222 ;; Make sure that message is displayed.
8d908f84
RS
1223 (or (zerop msg)
1224 (rmail-summary-goto-msg msg))))
d41d75fb
RS
1225
1226(defun rmail-summary-input (filename)
1227 "Run Rmail on file FILENAME."
1228 (interactive "FRun rmail on RMAIL file: ")
b37767e7
RS
1229 ;; We switch windows here, then display the other Rmail file there.
1230 (pop-to-buffer rmail-buffer)
1231 (rmail filename))
d41d75fb
RS
1232
1233(defun rmail-summary-first-message ()
1234 "Show first message in Rmail file from summary buffer."
1235 (interactive)
1236 (beginning-of-buffer))
1237
1238(defun rmail-summary-last-message ()
1239 "Show last message in Rmail file from summary buffer."
1240 (interactive)
1241 (end-of-buffer)
1242 (forward-line -1))
1243
1244(defvar rmail-summary-edit-map nil)
1245(if rmail-summary-edit-map
1246 nil
1247 (setq rmail-summary-edit-map
ae06ea79 1248 (nconc (make-sparse-keymap) text-mode-map))
d41d75fb
RS
1249 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
1250 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
1251
1252(defun rmail-summary-edit-current-message ()
1253 "Edit the contents of this message."
1254 (interactive)
1255 (pop-to-buffer rmail-buffer)
1256 (rmail-edit-current-message)
1257 (use-local-map rmail-summary-edit-map))
1258
1259(defun rmail-summary-cease-edit ()
1260 "Finish editing message, then go back to Rmail summary buffer."
1261 (interactive)
1262 (rmail-cease-edit)
1263 (pop-to-buffer rmail-summary-buffer))
1264
1265(defun rmail-summary-abort-edit ()
1266 "Abort edit of current message; restore original contents.
1267Go back to summary buffer."
1268 (interactive)
1269 (rmail-abort-edit)
1270 (pop-to-buffer rmail-summary-buffer))
1271
e7a00c25
RS
1272(defun rmail-summary-search-backward (regexp &optional n)
1273 "Show message containing next match for REGEXP.
1274Prefix argument gives repeat count; negative argument means search
1275backwards (through earlier messages).
1276Interactively, empty argument means use same regexp used last time."
1277 (interactive
1278 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1279 (prompt
1280 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1281 regexp)
1282 (if rmail-search-last-regexp
1283 (setq prompt (concat prompt
1284 "(default "
1285 rmail-search-last-regexp
1286 ") ")))
1287 (setq regexp (read-string prompt))
1288 (cond ((not (equal regexp ""))
1289 (setq rmail-search-last-regexp regexp))
1290 ((not rmail-search-last-regexp)
1291 (error "No previous Rmail search string")))
1292 (list rmail-search-last-regexp
1293 (prefix-numeric-value current-prefix-arg))))
1294 ;; Don't use save-excursion because that prevents point from moving
1295 ;; properly in the summary buffer.
1296 (let ((buffer (current-buffer)))
1297 (unwind-protect
1298 (progn
1299 (set-buffer rmail-buffer)
1300 (rmail-search regexp (- n)))
1301 (set-buffer buffer))))
1302
d41d75fb
RS
1303(defun rmail-summary-search (regexp &optional n)
1304 "Show message containing next match for REGEXP.
1305Prefix argument gives repeat count; negative argument means search
1306backwards (through earlier messages).
1307Interactively, empty argument means use same regexp used last time."
1308 (interactive
1309 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1310 (prompt
1311 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1312 regexp)
1313 (if rmail-search-last-regexp
1314 (setq prompt (concat prompt
1315 "(default "
1316 rmail-search-last-regexp
1317 ") ")))
1318 (setq regexp (read-string prompt))
1319 (cond ((not (equal regexp ""))
1320 (setq rmail-search-last-regexp regexp))
1321 ((not rmail-search-last-regexp)
1322 (error "No previous Rmail search string")))
1323 (list rmail-search-last-regexp
1324 (prefix-numeric-value current-prefix-arg))))
e7a00c25
RS
1325 ;; Don't use save-excursion because that prevents point from moving
1326 ;; properly in the summary buffer.
1327 (let ((buffer (current-buffer)))
1328 (unwind-protect
1329 (progn
1330 (set-buffer rmail-buffer)
1331 (rmail-search regexp n))
1332 (set-buffer buffer))))
d41d75fb
RS
1333
1334(defun rmail-summary-toggle-header ()
1335 "Show original message header if pruned header currently shown, or vice versa."
1336 (interactive)
1337 (save-excursion
1338 (set-buffer rmail-buffer)
387f203c
RS
1339 (rmail-toggle-header))
1340 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1341 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1342 (let ((window (get-buffer-window rmail-buffer)))
1343 (if window
1344 ;; Using save-window-excursion would lose the new value of point.
1345 (let ((owin (selected-window)))
1346 (unwind-protect
1347 (progn
1348 (select-window window)
1349 (goto-char (point-min)))
1350 (select-window owin))))))
1351
d41d75fb
RS
1352
1353(defun rmail-summary-add-label (label)
1354 "Add LABEL to labels associated with current Rmail message.
1355Completion is performed over known labels when reading."
980d43b6
RS
1356 (interactive (list (save-excursion
1357 (set-buffer rmail-buffer)
1358 (rmail-read-label "Add label"))))
d41d75fb
RS
1359 (save-excursion
1360 (set-buffer rmail-buffer)
1361 (rmail-add-label label)))
1362
1363(defun rmail-summary-kill-label (label)
1364 "Remove LABEL from labels associated with current Rmail message.
1365Completion is performed over known labels when reading."
980d43b6
RS
1366 (interactive (list (save-excursion
1367 (set-buffer rmail-buffer)
1368 (rmail-read-label "Kill label"))))
d41d75fb
RS
1369 (save-excursion
1370 (set-buffer rmail-buffer)
1371 (rmail-set-label label nil)))
1372\f
1373;;;; *** Rmail Summary Mailing Commands ***
1374
1375(defun rmail-summary-mail ()
1376 "Send mail in another window.
1377While composing the message, use \\[mail-yank-original] to yank the
1378original message into it."
1379 (interactive)
4c11ca80
RS
1380 (let ((window (get-buffer-window rmail-buffer)))
1381 (if window
1382 (select-window window)
1383 (set-buffer rmail-buffer)))
1384 (rmail-start-mail nil nil nil nil nil (current-buffer))
d41d75fb
RS
1385 (use-local-map (copy-keymap (current-local-map)))
1386 (define-key (current-local-map)
1387 "\C-c\C-c" 'rmail-summary-send-and-exit))
1388
1389(defun rmail-summary-continue ()
1390 "Continue composing outgoing message previously being composed."
1391 (interactive)
4c11ca80
RS
1392 (let ((window (get-buffer-window rmail-buffer)))
1393 (if window
1394 (select-window window)
1395 (set-buffer rmail-buffer)))
db1d3cf7 1396 (rmail-start-mail t))
d41d75fb
RS
1397
1398(defun rmail-summary-reply (just-sender)
1399 "Reply to the current message.
1400Normally include CC: to all other recipients of original message;
db1d3cf7
KH
1401prefix argument means ignore them. While composing the reply,
1402use \\[mail-yank-original] to yank the original message into it."
d41d75fb 1403 (interactive "P")
4c11ca80
RS
1404 (let ((window (get-buffer-window rmail-buffer)))
1405 (if window
1406 (select-window window)
1407 (set-buffer rmail-buffer)))
db1d3cf7
KH
1408 (rmail-reply just-sender)
1409 (use-local-map (copy-keymap (current-local-map)))
1410 (define-key (current-local-map)
1411 "\C-c\C-c" 'rmail-summary-send-and-exit))
d41d75fb
RS
1412
1413(defun rmail-summary-retry-failure ()
1414 "Edit a mail message which is based on the contents of the current message.
1415For a message rejected by the mail system, extract the interesting headers and
1416the body of the original message; otherwise copy the current message."
1417 (interactive)
4c11ca80
RS
1418 (let ((window (get-buffer-window rmail-buffer)))
1419 (if window
1420 (select-window window)
1421 (set-buffer rmail-buffer)))
db1d3cf7
KH
1422 (rmail-retry-failure)
1423 (use-local-map (copy-keymap (current-local-map)))
1424 (define-key (current-local-map)
1425 "\C-c\C-c" 'rmail-summary-send-and-exit))
d41d75fb
RS
1426
1427(defun rmail-summary-send-and-exit ()
1428 "Send mail reply and return to summary buffer."
1429 (interactive)
1430 (mail-send-and-exit t))
1431
18e90c58
RS
1432(defun rmail-summary-forward (resend)
1433 "Forward the current message to another user.
1434With prefix argument, \"resend\" the message instead of forwarding it;
1435see the documentation of `rmail-resend'."
1436 (interactive "P")
d41d75fb 1437 (save-excursion
4c11ca80
RS
1438 (let ((window (get-buffer-window rmail-buffer)))
1439 (if window
1440 (select-window window)
1441 (set-buffer rmail-buffer)))
18e90c58 1442 (rmail-forward resend)
d41d75fb
RS
1443 (use-local-map (copy-keymap (current-local-map)))
1444 (define-key (current-local-map)
1445 "\C-c\C-c" 'rmail-summary-send-and-exit)))
4986bd38
RS
1446
1447(defun rmail-summary-resend ()
1448 "Resend current message using 'rmail-resend'."
1449 (interactive)
1450 (save-excursion
4c11ca80
RS
1451 (let ((window (get-buffer-window rmail-buffer)))
1452 (if window
1453 (select-window window)
1454 (set-buffer rmail-buffer)))
4986bd38 1455 (call-interactively 'rmail-resend)))
d41d75fb
RS
1456\f
1457;; Summary output commands.
1458
aa138cb4 1459(defun rmail-summary-output-to-rmail-file (&optional file-name)
d41d75fb
RS
1460 "Append the current message to an Rmail file named FILE-NAME.
1461If the file does not exist, ask if it should be created.
1462If file is being visited, the message is appended to the Emacs
05422245
KH
1463buffer visiting that file.
1464
1465A prefix argument N says to output N consecutive messages
1466starting with the current one. Deleted messages are skipped and don't count."
d41d75fb 1467 (interactive)
05422245
KH
1468 (with-current-buffer rmail-buffer
1469 (if file-name
1470 (rmail-output-to-rmail-file file-name)
1471 (call-interactively 'rmail-output-to-rmail-file))))
d41d75fb 1472
dca46072
RS
1473(defun rmail-summary-output-menu ()
1474 "Output current message to another Rmail file, chosen with a menu.
1475Also set the default for subsequent \\[rmail-output-to-rmail-file] commands.
1476The variables `rmail-secondary-file-directory' and
1477`rmail-secondary-file-regexp' control which files are offered in the menu."
1478 (interactive)
1479 (save-excursion
1480 (set-buffer rmail-buffer)
1481 (let ((rmail-delete-after-output nil))
1482 (call-interactively 'rmail-output-menu)))
1483 (if rmail-delete-after-output
1484 (rmail-summary-delete-forward nil)))
1485
09ec5b27
MR
1486(defun rmail-summary-output (&optional file-name)
1487 "Append this message to Unix mail file named FILE-NAME.
1488
1489A prefix argument N says to output N consecutive messages
1490starting with the current one. Deleted messages are skipped and don't count."
d41d75fb 1491 (interactive)
09ec5b27
MR
1492 (with-current-buffer rmail-buffer
1493 (if file-name
1494 (rmail-output file-name)
1495 (call-interactively 'rmail-output))))
aa138cb4
RS
1496
1497(defun rmail-summary-construct-io-menu ()
1498 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
cb4903bc 1499 (if files
aa138cb4
RS
1500 (progn
1501 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1502 (cons "Input Rmail File"
1503 (rmail-list-to-menu "Input Rmail File"
cb4903bc 1504 files
aa138cb4
RS
1505 'rmail-summary-input)))
1506 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1507 (cons "Output Rmail File"
1508 (rmail-list-to-menu "Output Rmail File"
cb4903bc
RS
1509 files
1510 'rmail-summary-output-to-rmail-file))))
1511 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1512 '("Input Rmail File" . rmail-disable-menu))
1513 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1514 '("Output Rmail File" . rmail-disable-menu)))))
aa138cb4 1515
d5bafc55
RS
1516(defun rmail-summary-output-body (&optional file-name)
1517 "Write this message body to the file FILE-NAME.
1518FILE-NAME defaults, interactively, from the Subject field of the message."
1519 (interactive)
1520 (save-excursion
1521 (set-buffer rmail-buffer)
1522 (let ((rmail-delete-after-output nil))
1523 (if file-name
1524 (rmail-output-body-to-file file-name)
1525 (call-interactively 'rmail-output-body-to-file))))
1526 (if rmail-delete-after-output
1527 (rmail-summary-delete-forward nil)))
e45fce03
RS
1528\f
1529;; Sorting messages in Rmail Summary buffer.
1530
1531(defun rmail-summary-sort-by-date (reverse)
1532 "Sort messages of current Rmail summary by date.
1533If prefix argument REVERSE is non-nil, sort them in reverse order."
1534 (interactive "P")
1535 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1536
1537(defun rmail-summary-sort-by-subject (reverse)
1538 "Sort messages of current Rmail summary by subject.
1539If prefix argument REVERSE is non-nil, sort them in reverse order."
1540 (interactive "P")
1541 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1542
1543(defun rmail-summary-sort-by-author (reverse)
1544 "Sort messages of current Rmail summary by author.
1545If prefix argument REVERSE is non-nil, sort them in reverse order."
1546 (interactive "P")
1547 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1548
1549(defun rmail-summary-sort-by-recipient (reverse)
1550 "Sort messages of current Rmail summary by recipient.
1551If prefix argument REVERSE is non-nil, sort them in reverse order."
1552 (interactive "P")
1553 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1554
1555(defun rmail-summary-sort-by-correspondent (reverse)
1556 "Sort messages of current Rmail summary by other correspondent.
1557If prefix argument REVERSE is non-nil, sort them in reverse order."
1558 (interactive "P")
1559 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1560
1561(defun rmail-summary-sort-by-lines (reverse)
1562 "Sort messages of current Rmail summary by lines of the message.
1563If prefix argument REVERSE is non-nil, sort them in reverse order."
1564 (interactive "P")
1565 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1566
ebdf372b
KH
1567(defun rmail-summary-sort-by-keywords (reverse labels)
1568 "Sort messages of current Rmail summary by keywords.
1569If prefix argument REVERSE is non-nil, sort them in reverse order.
1570KEYWORDS is a comma-separated list of labels."
1571 (interactive "P\nsSort by labels: ")
1572 (rmail-sort-from-summary
1573 (function (lambda (reverse)
1574 (rmail-sort-by-keywords reverse labels)))
1575 reverse))
1576
e45fce03
RS
1577(defun rmail-sort-from-summary (sortfun reverse)
1578 "Sort Rmail messages from Summary buffer and update it after sorting."
1579 (require 'rmailsort)
2a527e48
KH
1580 (let ((selwin (selected-window)))
1581 (unwind-protect
1582 (progn (pop-to-buffer rmail-buffer)
1583 (funcall sortfun reverse))
1584 (select-window selwin))))
c88ab9ce
ER
1585
1586;;; rmailsum.el ends here