(rmail-summary-font-lock-keywords): New variable.
[bpt/emacs.git] / lisp / mail / rmailsum.el
1 ;;; rmailsum.el --- make summary buffers for the mail reader
2
3 ;; Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: mail
7
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;; Extended by Bob Weiner of Motorola
27 ;; Provided all commands from rmail-mode in rmail-summary-mode and made key
28 ;; bindings in both modes wholly compatible.
29
30 ;;; Code:
31
32 (defvar rmail-summary-font-lock-keywords
33 '(("^....D.*$" . font-lock-string-face) ; Deleted.
34 ("^....-.*$" . font-lock-type-face) ; Unread.
35 ;; Neither of the below will be highlighted if either of the above are:
36 ("^....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date.
37 ("{ \\([^}]+\\),}" 1 font-lock-comment-face)) ; Labels.
38 "Additional expressions to highlight in Rmail Summary mode.")
39
40 ;; Entry points for making a summary buffer.
41
42 ;; Regenerate the contents of the summary
43 ;; using the same selection criterion as last time.
44 ;; M-x revert-buffer in a summary buffer calls this function.
45 (defun rmail-update-summary (&rest ignore)
46 (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
47
48 (defun rmail-summary ()
49 "Display a summary of all messages, one line per message."
50 (interactive)
51 (rmail-new-summary "All" '(rmail-summary) nil))
52
53 (defun rmail-summary-by-labels (labels)
54 "Display a summary of all messages with one or more LABELS.
55 LABELS should be a string containing the desired labels, separated by commas."
56 (interactive "sLabels to summarize by: ")
57 (if (string= labels "")
58 (setq labels (or rmail-last-multi-labels
59 (error "No label specified"))))
60 (setq rmail-last-multi-labels labels)
61 (rmail-new-summary (concat "labels " labels)
62 (list 'rmail-summary-by-labels labels)
63 'rmail-message-labels-p
64 (concat ", \\(" (mail-comma-list-regexp labels) "\\),")))
65
66 (defun rmail-summary-by-recipients (recipients &optional primary-only)
67 "Display a summary of all messages with the given RECIPIENTS.
68 Normally checks the To, From and Cc fields of headers;
69 but if PRIMARY-ONLY is non-nil (prefix arg given),
70 only look in the To and From fields.
71 RECIPIENTS is a string of regexps separated by commas."
72 (interactive "sRecipients to summarize by: \nP")
73 (rmail-new-summary
74 (concat "recipients " recipients)
75 (list 'rmail-summary-by-recipients recipients primary-only)
76 'rmail-message-recipients-p
77 (mail-comma-list-regexp recipients) primary-only))
78
79 (defun rmail-summary-by-regexp (regexp)
80 "Display a summary of all messages according to regexp REGEXP.
81 If the regular expression is found in the header of the message
82 \(including in the date and other lines, as well as the subject line),
83 Emacs will list the header line in the RMAIL-summary."
84 (interactive "sRegexp to summarize by: ")
85 (if (string= regexp "")
86 (setq regexp (or rmail-last-regexp
87 (error "No regexp specified."))))
88 (setq rmail-last-regexp regexp)
89 (rmail-new-summary (concat "regexp " regexp)
90 (list 'rmail-summary-by-regexp regexp)
91 'rmail-message-regexp-p
92 regexp))
93
94 ;; rmail-summary-by-topic
95 ;; 1989 R.A. Schnitzler
96
97 (defun rmail-summary-by-topic (subject &optional whole-message)
98 "Display a summary of all messages with the given SUBJECT.
99 Normally checks the Subject field of headers;
100 but if WHOLE-MESSAGE is non-nil (prefix arg given),
101 look in the whole message.
102 SUBJECT is a string of regexps separated by commas."
103 (interactive "sTopics to summarize by: \nP")
104 (rmail-new-summary
105 (concat "about " subject)
106 (list 'rmail-summary-by-topic subject whole-message)
107 'rmail-message-subject-p
108 (mail-comma-list-regexp subject) whole-message))
109
110 (defun rmail-message-subject-p (msg subject &optional whole-message)
111 (save-restriction
112 (goto-char (rmail-msgbeg msg))
113 (search-forward "\n*** EOOH ***\n")
114 (narrow-to-region
115 (point)
116 (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
117 (goto-char (point-min))
118 (if whole-message (re-search-forward subject nil t)
119 (string-match subject (or (mail-fetch-field "Subject") "")) )))
120
121 (defun rmail-summary-by-senders (senders)
122 "Display a summary of all messages with the given SENDERS.
123 SENDERS is a string of names separated by commas."
124 (interactive "sSenders to summarize by: ")
125 (rmail-new-summary
126 (concat "senders " senders)
127 (list 'rmail-summary-by-senders senders)
128 'rmail-message-senders-p
129 (mail-comma-list-regexp senders)))
130
131 (defun rmail-message-senders-p (msg senders)
132 (save-restriction
133 (goto-char (rmail-msgbeg msg))
134 (search-forward "\n*** EOOH ***\n")
135 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
136 (string-match senders (or (mail-fetch-field "From") ""))))
137 \f
138 ;; General making of a summary buffer.
139
140 (defvar rmail-summary-symbol-number 0)
141
142 (defun rmail-new-summary (description redo-form function &rest args)
143 "Create a summary of selected messages.
144 DESCRIPTION makes part of the mode line of the summary buffer.
145 For each message, FUNCTION is applied to the message number and ARGS...
146 and if the result is non-nil, that message is included.
147 nil for FUNCTION means all messages."
148 (message "Computing summary lines...")
149 (let (sumbuf mesg was-in-summary)
150 (save-excursion
151 ;; Go to the Rmail buffer.
152 (if (eq major-mode 'rmail-summary-mode)
153 (progn
154 (setq was-in-summary t)
155 (set-buffer rmail-buffer)))
156 ;; Find its summary buffer, or make one.
157 (setq sumbuf
158 (if (and rmail-summary-buffer
159 (buffer-name rmail-summary-buffer))
160 rmail-summary-buffer
161 (generate-new-buffer (concat (buffer-name) "-summary"))))
162 (setq mesg rmail-current-message)
163 ;; Filter the messages; make or get their summary lines.
164 (let ((summary-msgs ())
165 (new-summary-line-count 0))
166 (let ((msgnum 1)
167 (buffer-read-only nil)
168 (old-min (point-min-marker))
169 (old-max (point-max-marker)))
170 ;; Can't use save-restriction here; that doesn't work if we
171 ;; plan to modify text outside the original restriction.
172 (save-excursion
173 (widen)
174 (goto-char (point-min))
175 (while (>= rmail-total-messages msgnum)
176 (if (or (null function)
177 (apply function (cons msgnum args)))
178 (setq summary-msgs
179 (cons (cons msgnum (rmail-make-summary-line msgnum))
180 summary-msgs)))
181 (setq msgnum (1+ msgnum)))
182 (setq summary-msgs (nreverse summary-msgs)))
183 (narrow-to-region old-min old-max))
184 ;; Temporarily, while summary buffer is unfinished,
185 ;; we "don't have" a summary.
186 (setq rmail-summary-buffer nil)
187 (save-excursion
188 (let ((rbuf (current-buffer))
189 (total rmail-total-messages))
190 (set-buffer sumbuf)
191 ;; Set up the summary buffer's contents.
192 (let ((buffer-read-only nil))
193 (erase-buffer)
194 (while summary-msgs
195 (princ (cdr (car summary-msgs)) sumbuf)
196 (setq summary-msgs (cdr summary-msgs)))
197 (goto-char (point-min)))
198 ;; Set up the rest of its state and local variables.
199 (setq buffer-read-only t)
200 (rmail-summary-mode)
201 (make-local-variable 'minor-mode-alist)
202 (setq minor-mode-alist (list '(t (concat ": " description))))
203 (setq rmail-buffer rbuf
204 rmail-summary-redo redo-form
205 rmail-total-messages total))))
206 (setq rmail-summary-buffer sumbuf))
207 ;; Now display the summary buffer and go to the right place in it.
208 (or was-in-summary
209 (if (one-window-p)
210 ;; If there is just one window, put the summary on the top.
211 (progn
212 (split-window)
213 (select-window (next-window (frame-first-window)))
214 (pop-to-buffer sumbuf)
215 ;; If pop-to-buffer did not use that window, delete that
216 ;; window. (This can happen if it uses another frame.)
217 (if (not (eq sumbuf (window-buffer (frame-first-window))))
218 (delete-other-windows)))
219 (pop-to-buffer sumbuf)))
220 (rmail-summary-goto-msg mesg t t)
221 (message "Computing summary lines...done")))
222 \f
223 ;; Low levels of generating a summary.
224
225 (defun rmail-make-summary-line (msg)
226 (let ((line (or (aref rmail-summary-vector (1- msg))
227 (progn
228 (setq new-summary-line-count
229 (1+ new-summary-line-count))
230 (if (zerop (% new-summary-line-count 10))
231 (message "Computing summary lines...%d"
232 new-summary-line-count))
233 (rmail-make-summary-line-1 msg)))))
234 ;; Fix up the part of the summary that says "deleted" or "unseen".
235 (aset line 4
236 (if (rmail-message-deleted-p msg) ?\D
237 (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg))))
238 ?\- ?\ )))
239 line))
240
241 (defun rmail-make-summary-line-1 (msg)
242 (goto-char (rmail-msgbeg msg))
243 (let* ((lim (save-excursion (forward-line 2) (point)))
244 pos
245 (labels
246 (progn
247 (forward-char 3)
248 (concat
249 ; (if (save-excursion (re-search-forward ",answered," lim t))
250 ; "*" "")
251 ; (if (save-excursion (re-search-forward ",filed," lim t))
252 ; "!" "")
253 (if (progn (search-forward ",,") (eolp))
254 ""
255 (concat "{"
256 (buffer-substring (point)
257 (progn (end-of-line) (point)))
258 "} ")))))
259 (line
260 (progn
261 (forward-line 1)
262 (if (looking-at "Summary-line: ")
263 (progn
264 (goto-char (match-end 0))
265 (setq line
266 (buffer-substring (point)
267 (progn (forward-line 1) (point)))))))))
268 ;; Obsolete status lines lacking a # should be flushed.
269 (and line
270 (not (string-match "#" line))
271 (progn
272 (delete-region (point)
273 (progn (forward-line -1) (point)))
274 (setq line nil)))
275 ;; If we didn't get a valid status line from the message,
276 ;; make a new one and put it in the message.
277 (or line
278 (let* ((case-fold-search t)
279 (next (rmail-msgend msg))
280 (beg (if (progn (goto-char (rmail-msgbeg msg))
281 (search-forward "\n*** EOOH ***\n" next t))
282 (point)
283 (forward-line 1)
284 (point)))
285 (end (progn (search-forward "\n\n" nil t) (point))))
286 (save-restriction
287 (narrow-to-region beg end)
288 (goto-char beg)
289 (setq line (rmail-make-basic-summary-line)))
290 (goto-char (rmail-msgbeg msg))
291 (forward-line 2)
292 (insert "Summary-line: " line)))
293 (setq pos (string-match "#" line))
294 (aset rmail-summary-vector (1- msg)
295 (concat (format "%4d " msg)
296 (substring line 0 pos)
297 labels
298 (substring line (1+ pos))))))
299
300 (defun rmail-make-basic-summary-line ()
301 (goto-char (point-min))
302 (concat (save-excursion
303 (if (not (re-search-forward "^Date:" nil t))
304 " "
305 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
306 (save-excursion (end-of-line) (point)) t)
307 (format "%2d-%3s"
308 (string-to-int (buffer-substring
309 (match-beginning 2)
310 (match-end 2)))
311 (buffer-substring
312 (match-beginning 4) (match-end 4))))
313 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
314 (save-excursion (end-of-line) (point)) t)
315 (format "%2d-%3s"
316 (string-to-int (buffer-substring
317 (match-beginning 4)
318 (match-end 4)))
319 (buffer-substring
320 (match-beginning 2) (match-end 2))))
321 (t "??????"))))
322 " "
323 (save-excursion
324 (if (not (re-search-forward "^From:[ \t]*" nil t))
325 " "
326 (let* ((from (mail-strip-quoted-names
327 (buffer-substring
328 (1- (point))
329 ;; Get all the lines of the From field
330 ;; so that we get a whole comment if there is one,
331 ;; so that mail-strip-quoted-names can discard it.
332 (let ((opoint (point)))
333 (while (progn (forward-line 1)
334 (looking-at "[ \t]")))
335 ;; Back up over newline, then trailing spaces or tabs
336 (forward-char -1)
337 (skip-chars-backward " \t")
338 (point)))))
339 len mch lo)
340 (if (string-match (concat "^"
341 (regexp-quote (user-login-name))
342 "\\($\\|@\\)")
343 from)
344 (save-excursion
345 (goto-char (point-min))
346 (if (not (re-search-forward "^To:[ \t]*" nil t))
347 nil
348 (setq from
349 (concat "to: "
350 (mail-strip-quoted-names
351 (buffer-substring
352 (point)
353 (progn (end-of-line)
354 (skip-chars-backward " \t")
355 (point)))))))))
356 (setq len (length from))
357 (setq mch (string-match "[@%]" from))
358 (format "%25s"
359 (if (or (not mch) (<= len 25))
360 (substring from (max 0 (- len 25)))
361 (substring from
362 (setq lo (cond ((< (- mch 14) 0) 0)
363 ((< len (+ mch 11))
364 (- len 25))
365 (t (- mch 14))))
366 (min len (+ lo 25))))))))
367 " #"
368 (if (re-search-forward "^Subject:" nil t)
369 (progn (skip-chars-forward " \t")
370 (buffer-substring (point)
371 (progn (end-of-line)
372 (point))))
373 (re-search-forward "[\n][\n]+" nil t)
374 (buffer-substring (point) (progn (end-of-line) (point))))
375 "\n"))
376 \f
377 ;; Simple motion in a summary buffer.
378
379 (defun rmail-summary-next-all (&optional number)
380 (interactive "p")
381 (forward-line (if number number 1))
382 (display-buffer rmail-buffer))
383
384 (defun rmail-summary-previous-all (&optional number)
385 (interactive "p")
386 (forward-line (- (if number number 1)))
387 (display-buffer rmail-buffer))
388
389 (defun rmail-summary-next-msg (&optional number)
390 "Display next non-deleted msg from rmail file.
391 With optional prefix argument NUMBER, moves forward this number of non-deleted
392 messages, or backward if NUMBER is negative."
393 (interactive "p")
394 (forward-line 0)
395 (and (> number 0) (end-of-line))
396 (let ((count (if (< number 0) (- number) number))
397 (search (if (> number 0) 're-search-forward 're-search-backward))
398 (non-del-msg-found nil))
399 (while (and (> count 0) (setq non-del-msg-found
400 (or (funcall search "^....[^D]" nil t)
401 non-del-msg-found)))
402 (setq count (1- count))))
403 (beginning-of-line)
404 (display-buffer rmail-buffer))
405
406 (defun rmail-summary-previous-msg (&optional number)
407 (interactive "p")
408 (rmail-summary-next-msg (- (if number number 1))))
409
410 (defun rmail-summary-next-labeled-message (n labels)
411 "Show next message with LABEL. Defaults to last labels used.
412 With prefix argument N moves forward N messages with these labels."
413 (interactive "p\nsMove to next msg with labels: ")
414 (save-excursion
415 (set-buffer rmail-buffer)
416 (rmail-next-labeled-message n labels)))
417
418 (defun rmail-summary-previous-labeled-message (n labels)
419 "Show previous message with LABEL. Defaults to last labels used.
420 With prefix argument N moves backward N messages with these labels."
421 (interactive "p\nsMove to previous msg with labels: ")
422 (save-excursion
423 (set-buffer rmail-buffer)
424 (rmail-previous-labeled-message n labels)))
425 \f
426 ;; Delete and undelete summary commands.
427
428 (defun rmail-summary-delete-forward (&optional backward)
429 "Delete this message and move to next nondeleted one.
430 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
431 With prefix argument, delete and move backward."
432 (interactive "P")
433 (let (end)
434 (rmail-summary-goto-msg)
435 (pop-to-buffer rmail-buffer)
436 (rmail-delete-message)
437 (let ((del-msg rmail-current-message))
438 (pop-to-buffer rmail-summary-buffer)
439 (rmail-summary-mark-deleted del-msg)
440 (while (and (not (if backward (bobp) (eobp)))
441 (save-excursion (beginning-of-line)
442 (looking-at " *[0-9]+D")))
443 (forward-line (if backward -1 1))))))
444
445 (defun rmail-summary-delete-backward ()
446 "Delete this message and move to previous nondeleted one.
447 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
448 (interactive)
449 (rmail-summary-delete-forward t))
450
451 (defun rmail-summary-mark-deleted (&optional n undel)
452 (and n (rmail-summary-goto-msg n t t))
453 (or (eobp)
454 (let ((buffer-read-only nil))
455 (skip-chars-forward " ")
456 (skip-chars-forward "[0-9]")
457 (if undel
458 (if (looking-at "D")
459 (progn (delete-char 1) (insert " ")))
460 (delete-char 1)
461 (insert "D"))))
462 (beginning-of-line))
463
464 (defun rmail-summary-mark-undeleted (n)
465 (rmail-summary-mark-deleted n t))
466
467 (defun rmail-summary-deleted-p (&optional n)
468 (save-excursion
469 (and n (rmail-summary-goto-msg n nil t))
470 (skip-chars-forward " ")
471 (skip-chars-forward "[0-9]")
472 (looking-at "D")))
473
474 (defun rmail-summary-undelete (&optional arg)
475 "Undelete current message.
476 Optional prefix ARG means undelete ARG previous messages."
477 (interactive "p")
478 (if (/= arg 1)
479 (rmail-summary-undelete-many arg)
480 (let ((buffer-read-only nil)
481 (opoint (point)))
482 (end-of-line)
483 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
484 (replace-match "\\1 ")
485 (rmail-summary-goto-msg)
486 (pop-to-buffer rmail-buffer)
487 (and (rmail-message-deleted-p rmail-current-message)
488 (rmail-undelete-previous-message))
489 (pop-to-buffer rmail-summary-buffer))
490 (t (goto-char opoint))))))
491
492 (defun rmail-summary-undelete-many (&optional n)
493 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
494 (interactive "P")
495 (save-excursion
496 (set-buffer rmail-buffer)
497 (let* ((init-msg (if n rmail-current-message rmail-total-messages))
498 (rmail-current-message init-msg)
499 (n (or n rmail-total-messages))
500 (msgs-undeled 0))
501 (while (and (> rmail-current-message 0)
502 (< msgs-undeled n))
503 (if (rmail-message-deleted-p rmail-current-message)
504 (progn (rmail-set-attribute "deleted" nil)
505 (setq msgs-undeled (1+ msgs-undeled))))
506 (setq rmail-current-message (1- rmail-current-message)))
507 (set-buffer rmail-summary-buffer)
508 (setq rmail-current-message init-msg msgs-undeled 0)
509 (while (and (> rmail-current-message 0)
510 (< msgs-undeled n))
511 (if (rmail-summary-deleted-p rmail-current-message)
512 (progn (rmail-summary-mark-undeleted rmail-current-message)
513 (setq msgs-undeled (1+ msgs-undeled))))
514 (setq rmail-current-message (1- rmail-current-message))))
515 (rmail-summary-goto-msg)))
516 \f
517 ;; Rmail Summary mode is suitable only for specially formatted data.
518 (put 'rmail-summary-mode 'mode-class 'special)
519
520 (defun rmail-summary-mode ()
521 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
522 As commands are issued in the summary buffer, they are applied to the
523 corresponding mail messages in the rmail buffer.
524
525 All normal editing commands are turned off.
526 Instead, nearly all the Rmail mode commands are available,
527 though many of them move only among the messages in the summary.
528
529 These additional commands exist:
530
531 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
532 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
533
534 Commands for sorting the summary:
535
536 \\[rmail-summary-sort-by-date] Sort by date.
537 \\[rmail-summary-sort-by-subject] Sort by subject.
538 \\[rmail-summary-sort-by-author] Sort by author.
539 \\[rmail-summary-sort-by-recipient] Sort by recipient.
540 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
541 \\[rmail-summary-sort-by-lines] Sort by lines.
542 \\[rmail-summary-sort-by-keywords] Sort by keywords."
543 (interactive)
544 (kill-all-local-variables)
545 (setq major-mode 'rmail-summary-mode)
546 (setq mode-name "RMAIL Summary")
547 (setq truncate-lines t)
548 (setq buffer-read-only t)
549 (set-syntax-table text-mode-syntax-table)
550 (make-local-variable 'rmail-buffer)
551 (make-local-variable 'rmail-total-messages)
552 (make-local-variable 'rmail-current-message)
553 (setq rmail-current-message nil)
554 (make-local-variable 'rmail-summary-redo)
555 (setq rmail-summary-redo nil)
556 (make-local-variable 'revert-buffer-function)
557 (make-local-variable 'post-command-hook)
558 (make-local-variable 'font-lock-keywords)
559 (setq font-lock-keywords rmail-summary-font-lock-keywords)
560 (rmail-summary-enable)
561 (run-hooks 'rmail-summary-mode-hook))
562
563 ;; Summary features need to be disabled during edit mode.
564 (defun rmail-summary-disable ()
565 (use-local-map text-mode-map)
566 (remove-hook 'post-command-hook 'rmail-summary-rmail-update)
567 (setq revert-buffer-function nil))
568
569 (defun rmail-summary-enable ()
570 (use-local-map rmail-summary-mode-map)
571 (add-hook 'post-command-hook 'rmail-summary-rmail-update)
572 (setq revert-buffer-function 'rmail-update-summary))
573
574 ;; Show in Rmail the message described by the summary line that point is on,
575 ;; but only if the Rmail buffer is already visible.
576 ;; This is a post-command-hook in summary buffers.
577 (defun rmail-summary-rmail-update ()
578 (let (buffer-read-only)
579 (save-excursion
580 ;; If at end of buffer, pretend we are on the last text line.
581 (if (eobp)
582 (forward-line -1))
583 (beginning-of-line)
584 (skip-chars-forward " ")
585 (let ((msg-num (string-to-int (buffer-substring
586 (point)
587 (progn (skip-chars-forward "0-9")
588 (point))))))
589 (or (eq rmail-current-message msg-num)
590 (let ((window (get-buffer-window rmail-buffer))
591 (owin (selected-window)))
592 (setq rmail-current-message msg-num)
593 (if (= (following-char) ?-)
594 (progn
595 (delete-char 1)
596 (insert " ")))
597 (if window
598 ;; Using save-window-excursion would cause the new value
599 ;; of point to get lost.
600 (unwind-protect
601 (progn
602 (select-window window)
603 (rmail-show-message msg-num))
604 (select-window owin))
605 (if (buffer-name rmail-buffer)
606 (save-excursion
607 (set-buffer rmail-buffer)
608 (rmail-show-message msg-num))))))))))
609 \f
610 (defvar rmail-summary-mode-map nil)
611
612 (if rmail-summary-mode-map
613 nil
614 (setq rmail-summary-mode-map (make-keymap))
615 (suppress-keymap rmail-summary-mode-map)
616 (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label)
617 (define-key rmail-summary-mode-map "c" 'rmail-summary-continue)
618 (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward)
619 (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward)
620 (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message)
621 (define-key rmail-summary-mode-map "f" 'rmail-summary-forward)
622 (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail)
623 (define-key rmail-summary-mode-map "h" 'rmail-summary)
624 (define-key rmail-summary-mode-map "i" 'rmail-summary-input)
625 (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg)
626 (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label)
627 (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels)
628 (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
629 (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
630 (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
631 (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
632 (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
633 (define-key rmail-summary-mode-map "m" 'rmail-summary-mail)
634 (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure)
635 (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg)
636 (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all)
637 (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
638 (define-key rmail-summary-mode-map "o" 'rmail-summary-output-to-rmail-file)
639 (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output)
640 (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg)
641 (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all)
642 (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
643 (define-key rmail-summary-mode-map "q" 'rmail-summary-quit)
644 (define-key rmail-summary-mode-map "r" 'rmail-summary-reply)
645 (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save)
646 (define-key rmail-summary-mode-map "\es" 'rmail-summary-search)
647 (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header)
648 (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete)
649 (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many)
650 (define-key rmail-summary-mode-map "w" 'rmail-summary-wipe)
651 (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge)
652 (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message)
653 (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message)
654 (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message)
655 (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up)
656 (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down)
657 (define-key rmail-summary-mode-map "?" 'describe-mode)
658 (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
659 'rmail-summary-sort-by-date)
660 (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
661 'rmail-summary-sort-by-subject)
662 (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
663 'rmail-summary-sort-by-author)
664 (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
665 'rmail-summary-sort-by-recipient)
666 (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
667 'rmail-summary-sort-by-correspondent)
668 (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
669 'rmail-summary-sort-by-lines)
670 (define-key rmail-summary-mode-map "\C-c\C-s\C-k"
671 'rmail-summary-sort-by-keywords)
672 )
673 \f
674 ;;; Menu bar bindings.
675
676 (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
677
678 (define-key rmail-summary-mode-map [menu-bar classify]
679 (cons "Classify" (make-sparse-keymap "Classify")))
680
681 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
682 '("Output (Rmail Menu)..." . rmail-summary-output-menu))
683
684 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
685 '("Input Rmail file (menu)..." . rmail-input-menu))
686
687 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
688 '(nil))
689
690 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
691 '(nil))
692
693 (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
694 '("Output (inbox)..." . rmail-summary-output))
695
696 (define-key rmail-summary-mode-map [menu-bar classify output]
697 '("Output (Rmail)..." . rmail-summary-output-to-rmail-file))
698
699 (define-key rmail-summary-mode-map [menu-bar classify kill-label]
700 '("Kill Label..." . rmail-summary-kill-label))
701
702 (define-key rmail-summary-mode-map [menu-bar classify add-label]
703 '("Add Label..." . rmail-summary-add-label))
704
705 (define-key rmail-summary-mode-map [menu-bar summary]
706 (cons "Summary" (make-sparse-keymap "Summary")))
707
708 (define-key rmail-summary-mode-map [menu-bar summary labels]
709 '("By Labels..." . rmail-summary-by-labels))
710
711 (define-key rmail-summary-mode-map [menu-bar summary recipients]
712 '("By Recipients..." . rmail-summary-by-recipients))
713
714 (define-key rmail-summary-mode-map [menu-bar summary topic]
715 '("By Topic..." . rmail-summary-by-topic))
716
717 (define-key rmail-summary-mode-map [menu-bar summary regexp]
718 '("By Regexp..." . rmail-summary-by-regexp))
719
720 (define-key rmail-summary-mode-map [menu-bar summary all]
721 '("All" . rmail-summary))
722
723 (define-key rmail-summary-mode-map [menu-bar mail]
724 (cons "Mail" (make-sparse-keymap "Mail")))
725
726 (define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail]
727 '("Get New Mail" . rmail-summary-get-new-mail))
728
729 (define-key rmail-summary-mode-map [menu-bar mail lambda]
730 '("----"))
731
732 (define-key rmail-summary-mode-map [menu-bar mail continue]
733 '("Continue" . rmail-summary-continue))
734
735 (define-key rmail-summary-mode-map [menu-bar mail resend]
736 '("Re-send..." . rmail-resend))
737
738 (define-key rmail-summary-mode-map [menu-bar mail forward]
739 '("Forward" . rmail-summary-forward))
740
741 (define-key rmail-summary-mode-map [menu-bar mail retry]
742 '("Retry" . rmail-summary-retry-failure))
743
744 (define-key rmail-summary-mode-map [menu-bar mail reply]
745 '("Reply" . rmail-summary-reply))
746
747 (define-key rmail-summary-mode-map [menu-bar mail mail]
748 '("Mail" . rmail-summary-mail))
749
750 (define-key rmail-summary-mode-map [menu-bar delete]
751 (cons "Delete" (make-sparse-keymap "Delete")))
752
753 (define-key rmail-summary-mode-map [menu-bar delete expunge/save]
754 '("Expunge/Save" . rmail-summary-expunge-and-save))
755
756 (define-key rmail-summary-mode-map [menu-bar delete expunge]
757 '("Expunge" . rmail-summary-expunge))
758
759 (define-key rmail-summary-mode-map [menu-bar delete undelete]
760 '("Undelete" . rmail-summary-undelete))
761
762 (define-key rmail-summary-mode-map [menu-bar delete delete]
763 '("Delete" . rmail-summary-delete-forward))
764
765 (define-key rmail-summary-mode-map [menu-bar move]
766 (cons "Move" (make-sparse-keymap "Move")))
767
768 (define-key rmail-summary-mode-map [menu-bar move search-back]
769 '("Search Back..." . rmail-summary-search-backward))
770
771 (define-key rmail-summary-mode-map [menu-bar move search]
772 '("Search..." . rmail-summary-search))
773
774 (define-key rmail-summary-mode-map [menu-bar move previous]
775 '("Previous Nondeleted" . rmail-summary-previous-msg))
776
777 (define-key rmail-summary-mode-map [menu-bar move next]
778 '("Next Nondeleted" . rmail-summary-next-msg))
779
780 (define-key rmail-summary-mode-map [menu-bar move last]
781 '("Last" . rmail-summary-last-message))
782
783 (define-key rmail-summary-mode-map [menu-bar move first]
784 '("First" . rmail-summary-first-message))
785
786 (define-key rmail-summary-mode-map [menu-bar move previous]
787 '("Previous" . rmail-summary-previous-all))
788
789 (define-key rmail-summary-mode-map [menu-bar move next]
790 '("Next" . rmail-summary-next-all))
791 \f
792 (defvar rmail-summary-overlay nil)
793
794 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
795 (interactive "P")
796 (if (consp n) (setq n (prefix-numeric-value n)))
797 (if (eobp) (forward-line -1))
798 (beginning-of-line)
799 (let* ((obuf (current-buffer))
800 (buf rmail-buffer)
801 (cur (point))
802 message-not-found
803 (curmsg (string-to-int
804 (buffer-substring (point)
805 (min (point-max) (+ 5 (point))))))
806 (total (save-excursion (set-buffer buf) rmail-total-messages)))
807 ;; If message number N was specified, find that message's line
808 ;; or set message-not-found.
809 ;; If N wasn't specified or that message can't be found.
810 ;; set N by default.
811 (if (not n)
812 (setq n curmsg)
813 (if (< n 1)
814 (progn (message "No preceding message")
815 (setq n 1)))
816 (if (> n total)
817 (progn (message "No following message")
818 (goto-char (point-max))
819 (rmail-summary-goto-msg)))
820 (goto-char (point-min))
821 (if (not (re-search-forward (format "^%4d[^0-9]" n) nil t))
822 (progn (or nowarn (message "Message %d not found" n))
823 (setq n curmsg)
824 (setq message-not-found t)
825 (goto-char cur))))
826 (beginning-of-line)
827 (skip-chars-forward " ")
828 (skip-chars-forward "0-9")
829 (save-excursion (if (= (following-char) ?-)
830 (let ((buffer-read-only nil))
831 (delete-char 1)
832 (insert " "))))
833 ;; Make sure we have an overlay to use.
834 (or rmail-summary-overlay
835 (progn
836 (make-local-variable 'rmail-summary-overlay)
837 (setq rmail-summary-overlay (make-overlay (point) (point)))))
838 ;; If this message is in the summary, use the overlay to highlight it.
839 ;; Otherwise, don't highlight anything.
840 (if message-not-found
841 (overlay-put rmail-summary-overlay 'face nil)
842 (move-overlay rmail-summary-overlay
843 (save-excursion (beginning-of-line) (1+ (point)))
844 (save-excursion (end-of-line) (point)))
845 (overlay-put rmail-summary-overlay 'face 'highlight))
846 (beginning-of-line)
847 (if skip-rmail
848 nil
849 (let ((selwin (selected-window)))
850 (unwind-protect
851 (progn (pop-to-buffer buf)
852 (rmail-show-message n))
853 (select-window selwin)
854 ;; The actions above can alter the current buffer. Preserve it.
855 (set-buffer obuf))))))
856 \f
857 (defun rmail-summary-scroll-msg-up (&optional dist)
858 "Scroll the Rmail window forward."
859 (interactive "P")
860 (let ((other-window-scroll-buffer rmail-buffer))
861 (if (get-buffer-window rmail-buffer)
862 (scroll-other-window dist)
863 ;; This forces rmail-buffer to be sized correctly later.
864 (display-buffer rmail-buffer)
865 (setq rmail-current-message nil))))
866
867 (defun rmail-summary-scroll-msg-down (&optional dist)
868 "Scroll the Rmail window backward."
869 (interactive "P")
870 (rmail-summary-scroll-msg-up
871 (cond ((eq dist '-) nil)
872 ((null dist) '-)
873 (t (- (prefix-numeric-value dist))))))
874
875 (defun rmail-summary-beginning-of-message ()
876 "Show current message from the beginning."
877 (interactive)
878 (pop-to-buffer rmail-buffer)
879 (beginning-of-buffer)
880 (pop-to-buffer rmail-summary-buffer))
881
882 (defun rmail-summary-quit ()
883 "Quit out of Rmail and Rmail summary."
884 (interactive)
885 (rmail-summary-wipe)
886 (rmail-quit))
887
888 (defun rmail-summary-wipe ()
889 "Kill and wipe away Rmail summary, remaining within Rmail."
890 (interactive)
891 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
892 (let ((local-rmail-buffer rmail-buffer))
893 (kill-buffer (current-buffer))
894 ;; Delete window if not only one.
895 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
896 (delete-window))
897 ;; Switch windows to the rmail buffer, or switch to it in this window.
898 (pop-to-buffer local-rmail-buffer)))
899
900 (defun rmail-summary-expunge ()
901 "Actually erase all deleted messages and recompute summary headers."
902 (interactive)
903 (save-excursion
904 (set-buffer rmail-buffer)
905 (rmail-only-expunge))
906 (rmail-update-summary))
907
908 (defun rmail-summary-expunge-and-save ()
909 "Expunge and save RMAIL file."
910 (interactive)
911 (save-excursion
912 (set-buffer rmail-buffer)
913 (rmail-only-expunge))
914 (rmail-update-summary)
915 (save-excursion
916 (set-buffer rmail-buffer)
917 (save-buffer))
918 (set-buffer-modified-p nil))
919
920 (defun rmail-summary-get-new-mail ()
921 "Get new mail and recompute summary headers."
922 (interactive)
923 (let (msg)
924 (save-excursion
925 (set-buffer rmail-buffer)
926 (rmail-get-new-mail)
927 ;; Get the proper new message number.
928 (setq msg rmail-current-message))
929 ;; Make sure that message is displayed.
930 (rmail-summary-goto-msg msg)))
931
932 (defun rmail-summary-input (filename)
933 "Run Rmail on file FILENAME."
934 (interactive "FRun rmail on RMAIL file: ")
935 ;; We switch windows here, then display the other Rmail file there.
936 (pop-to-buffer rmail-buffer)
937 (rmail filename))
938
939 (defun rmail-summary-first-message ()
940 "Show first message in Rmail file from summary buffer."
941 (interactive)
942 (beginning-of-buffer))
943
944 (defun rmail-summary-last-message ()
945 "Show last message in Rmail file from summary buffer."
946 (interactive)
947 (end-of-buffer)
948 (forward-line -1))
949
950 (defvar rmail-summary-edit-map nil)
951 (if rmail-summary-edit-map
952 nil
953 (setq rmail-summary-edit-map
954 (nconc (make-sparse-keymap) text-mode-map))
955 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
956 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
957
958 (defun rmail-summary-edit-current-message ()
959 "Edit the contents of this message."
960 (interactive)
961 (pop-to-buffer rmail-buffer)
962 (rmail-edit-current-message)
963 (use-local-map rmail-summary-edit-map))
964
965 (defun rmail-summary-cease-edit ()
966 "Finish editing message, then go back to Rmail summary buffer."
967 (interactive)
968 (rmail-cease-edit)
969 (pop-to-buffer rmail-summary-buffer))
970
971 (defun rmail-summary-abort-edit ()
972 "Abort edit of current message; restore original contents.
973 Go back to summary buffer."
974 (interactive)
975 (rmail-abort-edit)
976 (pop-to-buffer rmail-summary-buffer))
977
978 (defun rmail-summary-search-backward (regexp &optional n)
979 "Show message containing next match for REGEXP.
980 Prefix argument gives repeat count; negative argument means search
981 backwards (through earlier messages).
982 Interactively, empty argument means use same regexp used last time."
983 (interactive
984 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
985 (prompt
986 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
987 regexp)
988 (if rmail-search-last-regexp
989 (setq prompt (concat prompt
990 "(default "
991 rmail-search-last-regexp
992 ") ")))
993 (setq regexp (read-string prompt))
994 (cond ((not (equal regexp ""))
995 (setq rmail-search-last-regexp regexp))
996 ((not rmail-search-last-regexp)
997 (error "No previous Rmail search string")))
998 (list rmail-search-last-regexp
999 (prefix-numeric-value current-prefix-arg))))
1000 ;; Don't use save-excursion because that prevents point from moving
1001 ;; properly in the summary buffer.
1002 (let ((buffer (current-buffer)))
1003 (unwind-protect
1004 (progn
1005 (set-buffer rmail-buffer)
1006 (rmail-search regexp (- n)))
1007 (set-buffer buffer))))
1008
1009 (defun rmail-summary-search (regexp &optional n)
1010 "Show message containing next match for REGEXP.
1011 Prefix argument gives repeat count; negative argument means search
1012 backwards (through earlier messages).
1013 Interactively, empty argument means use same regexp used last time."
1014 (interactive
1015 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1016 (prompt
1017 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1018 regexp)
1019 (if rmail-search-last-regexp
1020 (setq prompt (concat prompt
1021 "(default "
1022 rmail-search-last-regexp
1023 ") ")))
1024 (setq regexp (read-string prompt))
1025 (cond ((not (equal regexp ""))
1026 (setq rmail-search-last-regexp regexp))
1027 ((not rmail-search-last-regexp)
1028 (error "No previous Rmail search string")))
1029 (list rmail-search-last-regexp
1030 (prefix-numeric-value current-prefix-arg))))
1031 ;; Don't use save-excursion because that prevents point from moving
1032 ;; properly in the summary buffer.
1033 (let ((buffer (current-buffer)))
1034 (unwind-protect
1035 (progn
1036 (set-buffer rmail-buffer)
1037 (rmail-search regexp n))
1038 (set-buffer buffer))))
1039
1040 (defun rmail-summary-toggle-header ()
1041 "Show original message header if pruned header currently shown, or vice versa."
1042 (interactive)
1043 (save-excursion
1044 (set-buffer rmail-buffer)
1045 (rmail-toggle-header)))
1046
1047 (defun rmail-summary-add-label (label)
1048 "Add LABEL to labels associated with current Rmail message.
1049 Completion is performed over known labels when reading."
1050 (interactive (list (save-excursion
1051 (set-buffer rmail-buffer)
1052 (rmail-read-label "Add label"))))
1053 (save-excursion
1054 (set-buffer rmail-buffer)
1055 (rmail-add-label label)))
1056
1057 (defun rmail-summary-kill-label (label)
1058 "Remove LABEL from labels associated with current Rmail message.
1059 Completion is performed over known labels when reading."
1060 (interactive (list (save-excursion
1061 (set-buffer rmail-buffer)
1062 (rmail-read-label "Kill label"))))
1063 (save-excursion
1064 (set-buffer rmail-buffer)
1065 (rmail-set-label label nil)))
1066 \f
1067 ;;;; *** Rmail Summary Mailing Commands ***
1068
1069 (defun rmail-summary-mail ()
1070 "Send mail in another window.
1071 While composing the message, use \\[mail-yank-original] to yank the
1072 original message into it."
1073 (interactive)
1074 (rmail-start-mail nil nil nil nil nil rmail-buffer)
1075 (use-local-map (copy-keymap (current-local-map)))
1076 (define-key (current-local-map)
1077 "\C-c\C-c" 'rmail-summary-send-and-exit))
1078
1079 (defun rmail-summary-continue ()
1080 "Continue composing outgoing message previously being composed."
1081 (interactive)
1082 (rmail-start-mail t))
1083
1084 (defun rmail-summary-reply (just-sender)
1085 "Reply to the current message.
1086 Normally include CC: to all other recipients of original message;
1087 prefix argument means ignore them. While composing the reply,
1088 use \\[mail-yank-original] to yank the original message into it."
1089 (interactive "P")
1090 (set-buffer rmail-buffer)
1091 (rmail-reply just-sender)
1092 (use-local-map (copy-keymap (current-local-map)))
1093 (define-key (current-local-map)
1094 "\C-c\C-c" 'rmail-summary-send-and-exit))
1095
1096 (defun rmail-summary-retry-failure ()
1097 "Edit a mail message which is based on the contents of the current message.
1098 For a message rejected by the mail system, extract the interesting headers and
1099 the body of the original message; otherwise copy the current message."
1100 (interactive)
1101 (set-buffer rmail-buffer)
1102 (rmail-retry-failure)
1103 (use-local-map (copy-keymap (current-local-map)))
1104 (define-key (current-local-map)
1105 "\C-c\C-c" 'rmail-summary-send-and-exit))
1106
1107 (defun rmail-summary-send-and-exit ()
1108 "Send mail reply and return to summary buffer."
1109 (interactive)
1110 (mail-send-and-exit t))
1111
1112 (defun rmail-summary-forward (resend)
1113 "Forward the current message to another user.
1114 With prefix argument, \"resend\" the message instead of forwarding it;
1115 see the documentation of `rmail-resend'."
1116 (interactive "P")
1117 (save-excursion
1118 (set-buffer rmail-buffer)
1119 (rmail-forward resend)
1120 (use-local-map (copy-keymap (current-local-map)))
1121 (define-key (current-local-map)
1122 "\C-c\C-c" 'rmail-summary-send-and-exit)))
1123 \f
1124 ;; Summary output commands.
1125
1126 (defun rmail-summary-output-to-rmail-file (&optional file-name)
1127 "Append the current message to an Rmail file named FILE-NAME.
1128 If the file does not exist, ask if it should be created.
1129 If file is being visited, the message is appended to the Emacs
1130 buffer visiting that file."
1131 (interactive)
1132 (save-excursion
1133 (set-buffer rmail-buffer)
1134 (let ((rmail-delete-after-output nil))
1135 (if file-name
1136 (rmail-output-to-rmail-file file-name)
1137 (call-interactively 'rmail-output-to-rmail-file))))
1138 (if rmail-delete-after-output
1139 (rmail-summary-delete-forward nil)))
1140
1141 (defun rmail-summary-output-menu ()
1142 "Output current message to another Rmail file, chosen with a menu.
1143 Also set the default for subsequent \\[rmail-output-to-rmail-file] commands.
1144 The variables `rmail-secondary-file-directory' and
1145 `rmail-secondary-file-regexp' control which files are offered in the menu."
1146 (interactive)
1147 (save-excursion
1148 (set-buffer rmail-buffer)
1149 (let ((rmail-delete-after-output nil))
1150 (call-interactively 'rmail-output-menu)))
1151 (if rmail-delete-after-output
1152 (rmail-summary-delete-forward nil)))
1153
1154 (defun rmail-summary-output ()
1155 "Append this message to Unix mail file named FILE-NAME."
1156 (interactive)
1157 (save-excursion
1158 (set-buffer rmail-buffer)
1159 (let ((rmail-delete-after-output nil))
1160 (call-interactively 'rmail-output)))
1161 (if rmail-delete-after-output
1162 (rmail-summary-delete-forward nil)))
1163
1164 (defun rmail-summary-construct-io-menu ()
1165 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1166 (if (listp files)
1167 (progn
1168 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1169 (cons "Input Rmail File"
1170 (rmail-list-to-menu "Input Rmail File"
1171 (cdr files)
1172 'rmail-summary-input)))
1173 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1174 (cons "Output Rmail File"
1175 (rmail-list-to-menu "Output Rmail File"
1176 (cdr files)
1177 'rmail-summary-output-to-rmail-file)))))))
1178
1179 \f
1180 ;; Sorting messages in Rmail Summary buffer.
1181
1182 (defun rmail-summary-sort-by-date (reverse)
1183 "Sort messages of current Rmail summary by date.
1184 If prefix argument REVERSE is non-nil, sort them in reverse order."
1185 (interactive "P")
1186 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1187
1188 (defun rmail-summary-sort-by-subject (reverse)
1189 "Sort messages of current Rmail summary by subject.
1190 If prefix argument REVERSE is non-nil, sort them in reverse order."
1191 (interactive "P")
1192 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1193
1194 (defun rmail-summary-sort-by-author (reverse)
1195 "Sort messages of current Rmail summary by author.
1196 If prefix argument REVERSE is non-nil, sort them in reverse order."
1197 (interactive "P")
1198 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1199
1200 (defun rmail-summary-sort-by-recipient (reverse)
1201 "Sort messages of current Rmail summary by recipient.
1202 If prefix argument REVERSE is non-nil, sort them in reverse order."
1203 (interactive "P")
1204 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1205
1206 (defun rmail-summary-sort-by-correspondent (reverse)
1207 "Sort messages of current Rmail summary by other correspondent.
1208 If prefix argument REVERSE is non-nil, sort them in reverse order."
1209 (interactive "P")
1210 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1211
1212 (defun rmail-summary-sort-by-lines (reverse)
1213 "Sort messages of current Rmail summary by lines of the message.
1214 If prefix argument REVERSE is non-nil, sort them in reverse order."
1215 (interactive "P")
1216 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1217
1218 (defun rmail-summary-sort-by-keywords (reverse labels)
1219 "Sort messages of current Rmail summary by keywords.
1220 If prefix argument REVERSE is non-nil, sort them in reverse order.
1221 KEYWORDS is a comma-separated list of labels."
1222 (interactive "P\nsSort by labels: ")
1223 (rmail-sort-from-summary
1224 (function (lambda (reverse)
1225 (rmail-sort-by-keywords reverse labels)))
1226 reverse))
1227
1228 (defun rmail-sort-from-summary (sortfun reverse)
1229 "Sort Rmail messages from Summary buffer and update it after sorting."
1230 (require 'rmailsort)
1231 (let ((selwin (selected-window)))
1232 (unwind-protect
1233 (progn (pop-to-buffer rmail-buffer)
1234 (funcall sortfun reverse))
1235 (select-window selwin))))
1236
1237 ;;; rmailsum.el ends here