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