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