]> code.delx.au - gnu-emacs/blob - lisp/mail/rmailsum.el
(rmail-summary-goto-msg): Fix bug in earlier change.
[gnu-emacs] / lisp / mail / rmailsum.el
1 ;;; rmailsum.el --- make summary buffers for the mail reader
2
3 ;; Copyright (C) 1985, 1993 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: mail
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;; Extended by Bob Weiner of Motorola
27 ;; Provided all commands from rmail-mode in rmail-summary-mode and made key
28 ;; bindings in both modes wholly compatible.
29
30 ;;; Code:
31
32 ;; Entry points for making a summary buffer.
33
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)))
39
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))
44
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) "\\),")))
57
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))
70
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))
85
86 ;; rmail-summary-by-topic
87 ;; 1989 R.A. Schnitzler
88
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))
101
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") "")) )))
112
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)))
122
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") ""))))
129 \f
130 ;; General making of a summary buffer.
131
132 (defvar rmail-summary-symbol-number 0)
133
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")))
200 \f
201 ;; Low levels of generating a summary.
202
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))
218
219 (defun rmail-make-summary-line-1 (msg)
220 (goto-char (rmail-msgbeg msg))
221 (let* ((lim (save-excursion (forward-line 2) (point)))
222 pos
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))
232 ""
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))))))
277
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))
282 " "
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 "??????"))))
300 " "
301 (save-excursion
302 (if (not (re-search-forward "^From:[ \t]*" nil t))
303 " "
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))
318 nil
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"))
347 \f
348 ;; Simple motion in a summary buffer.
349
350 (defun rmail-summary-next-all (&optional number)
351 (interactive "p")
352 (forward-line (if number number 1))
353 (display-buffer rmail-buffer))
354
355 (defun rmail-summary-previous-all (&optional number)
356 (interactive "p")
357 (forward-line (- (if number number 1)))
358 (display-buffer rmail-buffer))
359
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))
376
377 (defun rmail-summary-previous-msg (&optional number)
378 (interactive "p")
379 (rmail-summary-next-msg (- (if number number 1))))
380
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)))
388
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)))
396 \f
397 ;; Delete and undelete summary commands.
398
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))))))
415
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))
421
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))
434
435 (defun rmail-summary-mark-undeleted (n)
436 (rmail-summary-mark-deleted n t))
437
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")))
444
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))))))
462
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)))
487 \f
488 ;; Rmail Summary mode is suitable only for specially formatted data.
489 (put 'rmail-summary-mode 'mode-class 'special)
490
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.
495
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.
499
500 These additional commands exist:
501
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.
504
505 Commands for sorting the summary:
506
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 (interactive)
514 (kill-all-local-variables)
515 (setq major-mode 'rmail-summary-mode)
516 (setq mode-name "RMAIL Summary")
517 (use-local-map rmail-summary-mode-map)
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 (setq revert-buffer-function 'rmail-update-summary)
529 (make-local-variable 'post-command-hook)
530 (add-hook 'post-command-hook 'rmail-summary-rmail-update)
531 (run-hooks 'rmail-summary-mode-hook))
532
533 ;; Show in Rmail the message described by the summary line that point is on,
534 ;; but only if the Rmail buffer is already visible.
535 ;; This is a post-command-hook in summary buffers.
536 (defun rmail-summary-rmail-update ()
537 (if (get-buffer-window rmail-buffer)
538 (let (buffer-read-only)
539 (save-excursion
540 ;; If at end of buffer, pretend we are on the last text line.
541 (if (eobp)
542 (forward-line -1))
543 (beginning-of-line)
544 (skip-chars-forward " ")
545 (let ((beg (point))
546 msg-num
547 (buf rmail-buffer))
548 (skip-chars-forward "0-9")
549 (setq msg-num (string-to-int (buffer-substring beg (point))))
550 (or (eq rmail-current-message msg-num)
551 (let (go-where window (owin (selected-window)))
552 (setq rmail-current-message msg-num)
553 (if (= (following-char) ?-)
554 (progn
555 (delete-char 1)
556 (insert " ")))
557 (setq window (display-buffer rmail-buffer))
558 ;; Using save-window-excursion caused the new value
559 ;; of point to get lost.
560 (unwind-protect
561 (progn
562 (select-window window)
563 (rmail-show-message msg-num))
564 (select-window owin)))))))))
565 \f
566 (defvar rmail-summary-mode-map nil)
567
568 (if rmail-summary-mode-map
569 nil
570 (setq rmail-summary-mode-map (make-keymap))
571 (suppress-keymap rmail-summary-mode-map)
572 (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label)
573 (define-key rmail-summary-mode-map "c" 'rmail-summary-continue)
574 (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward)
575 (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward)
576 (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message)
577 (define-key rmail-summary-mode-map "f" 'rmail-summary-forward)
578 (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail)
579 (define-key rmail-summary-mode-map "h" 'rmail-summary)
580 (define-key rmail-summary-mode-map "i" 'rmail-summary-input)
581 (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg)
582 (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label)
583 (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels)
584 (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
585 (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
586 (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
587 (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
588 (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
589 (define-key rmail-summary-mode-map "m" 'rmail-summary-mail)
590 (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure)
591 (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg)
592 (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all)
593 (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
594 (define-key rmail-summary-mode-map "o" 'rmail-summary-output-to-rmail-file)
595 (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output)
596 (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg)
597 (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all)
598 (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
599 (define-key rmail-summary-mode-map "q" 'rmail-summary-quit)
600 (define-key rmail-summary-mode-map "r" 'rmail-summary-reply)
601 (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save)
602 (define-key rmail-summary-mode-map "\es" 'rmail-summary-search)
603 (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header)
604 (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete)
605 (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many)
606 (define-key rmail-summary-mode-map "w" 'rmail-summary-wipe)
607 (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge)
608 (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message)
609 (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message)
610 (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message)
611 (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up)
612 (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down)
613 (define-key rmail-summary-mode-map "?" 'describe-mode)
614 (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
615 'rmail-summary-sort-by-date)
616 (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
617 'rmail-summary-sort-by-subject)
618 (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
619 'rmail-summary-sort-by-author)
620 (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
621 'rmail-summary-sort-by-recipient)
622 (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
623 'rmail-summary-sort-by-correspondent)
624 (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
625 'rmail-summary-sort-by-lines)
626 )
627 \f
628 ;;; Menu bar bindings.
629
630 (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
631
632 (define-key rmail-summary-mode-map [menu-bar classify]
633 (cons "Classify" (make-sparse-keymap "Classify")))
634
635 (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
636 '("Output (inbox)" . rmail-summary-output))
637
638 (define-key rmail-summary-mode-map [menu-bar classify output]
639 '("Output (Rmail)" . rmail-summary-output-to-rmail-file))
640
641 (define-key rmail-summary-mode-map [menu-bar classify kill-label]
642 '("Kill Label" . rmail-summary-kill-label))
643
644 (define-key rmail-summary-mode-map [menu-bar classify add-label]
645 '("Add Label" . rmail-summary-add-label))
646
647 (define-key rmail-summary-mode-map [menu-bar summary]
648 (cons "Summary" (make-sparse-keymap "Summary")))
649
650 (define-key rmail-summary-mode-map [menu-bar summary labels]
651 '("By Labels" . rmail-summary-by-labels))
652
653 (define-key rmail-summary-mode-map [menu-bar summary recipients]
654 '("By Recipients" . rmail-summary-by-recipients))
655
656 (define-key rmail-summary-mode-map [menu-bar summary topic]
657 '("By Topic" . rmail-summary-by-topic))
658
659 (define-key rmail-summary-mode-map [menu-bar summary regexp]
660 '("By Regexp" . rmail-summary-by-regexp))
661
662 (define-key rmail-summary-mode-map [menu-bar summary all]
663 '("All" . rmail-summary))
664
665 (define-key rmail-summary-mode-map [menu-bar mail]
666 (cons "Mail" (make-sparse-keymap "Mail")))
667
668 (define-key rmail-summary-mode-map [menu-bar mail continue]
669 '("Continue" . rmail-summary-continue))
670
671 (define-key rmail-summary-mode-map [menu-bar mail forward]
672 '("Forward" . rmail-summary-forward))
673
674 (define-key rmail-summary-mode-map [menu-bar mail retry]
675 '("Retry" . rmail-summary-retry-failure))
676
677 (define-key rmail-summary-mode-map [menu-bar mail reply]
678 '("Reply" . rmail-summary-reply))
679
680 (define-key rmail-summary-mode-map [menu-bar mail mail]
681 '("Mail" . rmail-summary-mail))
682
683 (define-key rmail-summary-mode-map [menu-bar delete]
684 (cons "Delete" (make-sparse-keymap "Delete")))
685
686 (define-key rmail-summary-mode-map [menu-bar delete expunge/save]
687 '("Expunge/Save" . rmail-summary-expunge-and-save))
688
689 (define-key rmail-summary-mode-map [menu-bar delete expunge]
690 '("Expunge" . rmail-summary-expunge))
691
692 (define-key rmail-summary-mode-map [menu-bar delete undelete]
693 '("Undelete" . rmail-summary-undelete))
694
695 (define-key rmail-summary-mode-map [menu-bar delete delete]
696 '("Delete" . rmail-summary-delete-forward))
697
698 (define-key rmail-summary-mode-map [menu-bar move]
699 (cons "Move" (make-sparse-keymap "Move")))
700
701 (define-key rmail-summary-mode-map [menu-bar move search-back]
702 '("Search Back" . rmail-summary-search-backward))
703
704 (define-key rmail-summary-mode-map [menu-bar move search]
705 '("Search" . rmail-summary-search))
706
707 (define-key rmail-summary-mode-map [menu-bar move previous]
708 '("Previous Nondeleted" . rmail-summary-previous-msg))
709
710 (define-key rmail-summary-mode-map [menu-bar move next]
711 '("Next Nondeleted" . rmail-summary-next-msg))
712
713 (define-key rmail-summary-mode-map [menu-bar move last]
714 '("Last" . rmail-summary-last-message))
715
716 (define-key rmail-summary-mode-map [menu-bar move first]
717 '("First" . rmail-summary-first-message))
718
719 (define-key rmail-summary-mode-map [menu-bar move previous]
720 '("Previous" . rmail-summary-previous-all))
721
722 (define-key rmail-summary-mode-map [menu-bar move next]
723 '("Next" . rmail-summary-next-all))
724 \f
725 (defvar rmail-summary-overlay nil)
726
727 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
728 (interactive "P")
729 (if (consp n) (setq n (prefix-numeric-value n)))
730 (if (eobp) (forward-line -1))
731 (beginning-of-line)
732 (let ((buf rmail-buffer)
733 (cur (point))
734 message-not-found
735 (curmsg (string-to-int
736 (buffer-substring (point)
737 (min (point-max) (+ 5 (point)))))))
738 ;; If message number N was specified, find that message's line
739 ;; or set message-not-found.
740 ;; If N wasn't specified or that message can't be found.
741 ;; set N by default.
742 (if (not n)
743 (setq n curmsg)
744 (if (< n 1)
745 (progn (message "No preceding message")
746 (setq n 1)))
747 (if (> n rmail-total-messages)
748 (progn (message "No following message")
749 (goto-char (point-max))
750 (rmail-summary-goto-msg)))
751 (goto-char (point-min))
752 (if (not (re-search-forward (concat "^ *" (int-to-string n)) nil t))
753 (progn (or nowarn (message "Message %d not found" n))
754 (setq n curmsg)
755 (setq message-not-found t)
756 (goto-char cur))))
757 (beginning-of-line)
758 (skip-chars-forward " ")
759 (skip-chars-forward "0-9")
760 (save-excursion (if (= (following-char) ?-)
761 (let ((buffer-read-only nil))
762 (delete-char 1)
763 (insert " "))))
764 ;; Make sure we have an overlay to use.
765 (or rmail-summary-overlay
766 (progn
767 (make-local-variable 'rmail-summary-overlay)
768 (setq rmail-summary-overlay (make-overlay (point) (point)))))
769 ;; If this message is in the summary, use the overlay to highlight it.
770 ;; Otherwise, don't highlight anything.
771 (if message-not-found
772 (overlay-put rmail-summary-overlay 'face nil)
773 (move-overlay rmail-summary-overlay
774 (save-excursion (beginning-of-line) (1+ (point)))
775 (save-excursion (end-of-line) (point)))
776 (overlay-put rmail-summary-overlay 'face 'highlight))
777 (beginning-of-line)
778 (if skip-rmail
779 nil
780 (let ((selwin (selected-window)))
781 (unwind-protect
782 (progn (pop-to-buffer buf)
783 (rmail-show-message n))
784 (select-window selwin))))))
785 \f
786 (defun rmail-summary-scroll-msg-up (&optional dist)
787 "Scroll other window forward."
788 (interactive "P")
789 (scroll-other-window dist))
790
791 (defun rmail-summary-scroll-msg-down (&optional dist)
792 "Scroll other window backward."
793 (interactive "P")
794 (scroll-other-window
795 (cond ((eq dist '-) nil)
796 ((null dist) '-)
797 (t (- (prefix-numeric-value dist))))))
798
799 (defun rmail-summary-beginning-of-message ()
800 "Show current message from the beginning."
801 (interactive)
802 (pop-to-buffer rmail-buffer)
803 (beginning-of-buffer)
804 (pop-to-buffer rmail-summary-buffer))
805
806 (defun rmail-summary-quit ()
807 "Quit out of Rmail and Rmail summary."
808 (interactive)
809 (rmail-summary-wipe)
810 (rmail-quit))
811
812 (defun rmail-summary-wipe ()
813 "Kill and wipe away Rmail summary, remaining within Rmail."
814 (interactive)
815 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
816 (let ((local-rmail-buffer rmail-buffer))
817 (kill-buffer (current-buffer))
818 ;; Delete window if not only one.
819 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
820 (delete-window))
821 ;; Switch windows to the rmail buffer, or switch to it in this window.
822 (pop-to-buffer local-rmail-buffer)))
823
824 (defun rmail-summary-expunge ()
825 "Actually erase all deleted messages and recompute summary headers."
826 (interactive)
827 (save-excursion
828 (set-buffer rmail-buffer)
829 (rmail-only-expunge))
830 (rmail-update-summary))
831
832 (defun rmail-summary-expunge-and-save ()
833 "Expunge and save RMAIL file."
834 (interactive)
835 (save-excursion
836 (set-buffer rmail-buffer)
837 (rmail-only-expunge))
838 (rmail-update-summary)
839 (save-excursion
840 (set-buffer rmail-buffer)
841 (save-buffer))
842 (set-buffer-modified-p nil))
843
844 (defun rmail-summary-get-new-mail ()
845 "Get new mail and recompute summary headers."
846 (interactive)
847 (let (msg)
848 (save-excursion
849 (set-buffer rmail-buffer)
850 (rmail-get-new-mail)
851 ;; Get the proper new message number.
852 (setq msg rmail-current-message))
853 ;; Make sure that message is displayed.
854 (rmail-summary-goto-msg msg)))
855
856 (defun rmail-summary-input (filename)
857 "Run Rmail on file FILENAME."
858 (interactive "FRun rmail on RMAIL file: ")
859 ;; We switch windows here, then display the other Rmail file there.
860 (pop-to-buffer rmail-buffer)
861 (rmail filename))
862
863 (defun rmail-summary-first-message ()
864 "Show first message in Rmail file from summary buffer."
865 (interactive)
866 (beginning-of-buffer))
867
868 (defun rmail-summary-last-message ()
869 "Show last message in Rmail file from summary buffer."
870 (interactive)
871 (end-of-buffer)
872 (forward-line -1))
873
874 (defvar rmail-summary-edit-map nil)
875 (if rmail-summary-edit-map
876 nil
877 (setq rmail-summary-edit-map
878 (nconc (make-sparse-keymap) text-mode-map))
879 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
880 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
881
882 (defun rmail-summary-edit-current-message ()
883 "Edit the contents of this message."
884 (interactive)
885 (pop-to-buffer rmail-buffer)
886 (rmail-edit-current-message)
887 (use-local-map rmail-summary-edit-map))
888
889 (defun rmail-summary-cease-edit ()
890 "Finish editing message, then go back to Rmail summary buffer."
891 (interactive)
892 (rmail-cease-edit)
893 (pop-to-buffer rmail-summary-buffer))
894
895 (defun rmail-summary-abort-edit ()
896 "Abort edit of current message; restore original contents.
897 Go back to summary buffer."
898 (interactive)
899 (rmail-abort-edit)
900 (pop-to-buffer rmail-summary-buffer))
901
902 (defun rmail-summary-search-backward (regexp &optional n)
903 "Show message containing next match for REGEXP.
904 Prefix argument gives repeat count; negative argument means search
905 backwards (through earlier messages).
906 Interactively, empty argument means use same regexp used last time."
907 (interactive
908 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
909 (prompt
910 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
911 regexp)
912 (if rmail-search-last-regexp
913 (setq prompt (concat prompt
914 "(default "
915 rmail-search-last-regexp
916 ") ")))
917 (setq regexp (read-string prompt))
918 (cond ((not (equal regexp ""))
919 (setq rmail-search-last-regexp regexp))
920 ((not rmail-search-last-regexp)
921 (error "No previous Rmail search string")))
922 (list rmail-search-last-regexp
923 (prefix-numeric-value current-prefix-arg))))
924 ;; Don't use save-excursion because that prevents point from moving
925 ;; properly in the summary buffer.
926 (let ((buffer (current-buffer)))
927 (unwind-protect
928 (progn
929 (set-buffer rmail-buffer)
930 (rmail-search regexp (- n)))
931 (set-buffer buffer))))
932
933 (defun rmail-summary-search (regexp &optional n)
934 "Show message containing next match for REGEXP.
935 Prefix argument gives repeat count; negative argument means search
936 backwards (through earlier messages).
937 Interactively, empty argument means use same regexp used last time."
938 (interactive
939 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
940 (prompt
941 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
942 regexp)
943 (if rmail-search-last-regexp
944 (setq prompt (concat prompt
945 "(default "
946 rmail-search-last-regexp
947 ") ")))
948 (setq regexp (read-string prompt))
949 (cond ((not (equal regexp ""))
950 (setq rmail-search-last-regexp regexp))
951 ((not rmail-search-last-regexp)
952 (error "No previous Rmail search string")))
953 (list rmail-search-last-regexp
954 (prefix-numeric-value current-prefix-arg))))
955 ;; Don't use save-excursion because that prevents point from moving
956 ;; properly in the summary buffer.
957 (let ((buffer (current-buffer)))
958 (unwind-protect
959 (progn
960 (set-buffer rmail-buffer)
961 (rmail-search regexp n))
962 (set-buffer buffer))))
963
964 (defun rmail-summary-toggle-header ()
965 "Show original message header if pruned header currently shown, or vice versa."
966 (interactive)
967 (save-excursion
968 (set-buffer rmail-buffer)
969 (rmail-toggle-header)))
970
971 (defun rmail-summary-add-label (label)
972 "Add LABEL to labels associated with current Rmail message.
973 Completion is performed over known labels when reading."
974 (interactive (list (save-excursion
975 (set-buffer rmail-buffer)
976 (rmail-read-label "Add label"))))
977 (save-excursion
978 (set-buffer rmail-buffer)
979 (rmail-add-label label)))
980
981 (defun rmail-summary-kill-label (label)
982 "Remove LABEL from labels associated with current Rmail message.
983 Completion is performed over known labels when reading."
984 (interactive (list (save-excursion
985 (set-buffer rmail-buffer)
986 (rmail-read-label "Kill label"))))
987 (save-excursion
988 (set-buffer rmail-buffer)
989 (rmail-set-label label nil)))
990 \f
991 ;;;; *** Rmail Summary Mailing Commands ***
992
993 (defun rmail-summary-mail ()
994 "Send mail in another window.
995 While composing the message, use \\[mail-yank-original] to yank the
996 original message into it."
997 (interactive)
998 (rmail-start-mail nil nil nil nil nil rmail-buffer)
999 (use-local-map (copy-keymap (current-local-map)))
1000 (define-key (current-local-map)
1001 "\C-c\C-c" 'rmail-summary-send-and-exit))
1002
1003 (defun rmail-summary-continue ()
1004 "Continue composing outgoing message previously being composed."
1005 (interactive)
1006 (rmail-start-mail t))
1007
1008 (defun rmail-summary-reply (just-sender)
1009 "Reply to the current message.
1010 Normally include CC: to all other recipients of original message;
1011 prefix argument means ignore them. While composing the reply,
1012 use \\[mail-yank-original] to yank the original message into it."
1013 (interactive "P")
1014 (set-buffer rmail-buffer)
1015 (rmail-reply just-sender)
1016 (use-local-map (copy-keymap (current-local-map)))
1017 (define-key (current-local-map)
1018 "\C-c\C-c" 'rmail-summary-send-and-exit))
1019
1020 (defun rmail-summary-retry-failure ()
1021 "Edit a mail message which is based on the contents of the current message.
1022 For a message rejected by the mail system, extract the interesting headers and
1023 the body of the original message; otherwise copy the current message."
1024 (interactive)
1025 (set-buffer rmail-buffer)
1026 (rmail-retry-failure)
1027 (use-local-map (copy-keymap (current-local-map)))
1028 (define-key (current-local-map)
1029 "\C-c\C-c" 'rmail-summary-send-and-exit))
1030
1031 (defun rmail-summary-send-and-exit ()
1032 "Send mail reply and return to summary buffer."
1033 (interactive)
1034 (mail-send-and-exit t))
1035
1036 (defun rmail-summary-forward (resend)
1037 "Forward the current message to another user.
1038 With prefix argument, \"resend\" the message instead of forwarding it;
1039 see the documentation of `rmail-resend'."
1040 (interactive "P")
1041 (save-excursion
1042 (set-buffer rmail-buffer)
1043 (rmail-forward resend)
1044 (use-local-map (copy-keymap (current-local-map)))
1045 (define-key (current-local-map)
1046 "\C-c\C-c" 'rmail-summary-send-and-exit)))
1047 \f
1048 ;; Summary output commands.
1049
1050 (defun rmail-summary-output-to-rmail-file ()
1051 "Append the current message to an Rmail file named FILE-NAME.
1052 If the file does not exist, ask if it should be created.
1053 If file is being visited, the message is appended to the Emacs
1054 buffer visiting that file."
1055 (interactive)
1056 (save-excursion
1057 (set-buffer rmail-buffer)
1058 (let ((rmail-delete-after-output nil))
1059 (call-interactively 'rmail-output-to-rmail-file)))
1060 (if rmail-delete-after-output
1061 (rmail-summary-delete-forward nil)))
1062
1063 (defun rmail-summary-output ()
1064 "Append this message to Unix mail file named FILE-NAME."
1065 (interactive)
1066 (save-excursion
1067 (set-buffer rmail-buffer)
1068 (let ((rmail-delete-after-output nil))
1069 (call-interactively 'rmail-output)))
1070 (if rmail-delete-after-output
1071 (rmail-summary-delete-forward nil)))
1072 \f
1073 ;; Sorting messages in Rmail Summary buffer.
1074
1075 (defun rmail-summary-sort-by-date (reverse)
1076 "Sort messages of current Rmail summary by date.
1077 If prefix argument REVERSE is non-nil, sort them in reverse order."
1078 (interactive "P")
1079 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1080
1081 (defun rmail-summary-sort-by-subject (reverse)
1082 "Sort messages of current Rmail summary by subject.
1083 If prefix argument REVERSE is non-nil, sort them in reverse order."
1084 (interactive "P")
1085 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1086
1087 (defun rmail-summary-sort-by-author (reverse)
1088 "Sort messages of current Rmail summary by author.
1089 If prefix argument REVERSE is non-nil, sort them in reverse order."
1090 (interactive "P")
1091 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1092
1093 (defun rmail-summary-sort-by-recipient (reverse)
1094 "Sort messages of current Rmail summary by recipient.
1095 If prefix argument REVERSE is non-nil, sort them in reverse order."
1096 (interactive "P")
1097 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1098
1099 (defun rmail-summary-sort-by-correspondent (reverse)
1100 "Sort messages of current Rmail summary by other correspondent.
1101 If prefix argument REVERSE is non-nil, sort them in reverse order."
1102 (interactive "P")
1103 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1104
1105 (defun rmail-summary-sort-by-lines (reverse)
1106 "Sort messages of current Rmail summary by lines of the message.
1107 If prefix argument REVERSE is non-nil, sort them in reverse order."
1108 (interactive "P")
1109 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1110
1111 (defun rmail-sort-from-summary (sortfun reverse)
1112 "Sort Rmail messages from Summary buffer and update it after sorting."
1113 (require 'rmailsort)
1114 (let ((selwin (selected-window)))
1115 (unwind-protect
1116 (progn (pop-to-buffer rmail-buffer)
1117 (funcall sortfun reverse))
1118 (select-window selwin))))
1119
1120 ;;; rmailsum.el ends here