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