]> code.delx.au - gnu-emacs/blob - lisp/mail/rmailsum.el
Fix rmail summary commands to work with rmail-mail-new-frame.
[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 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
726 (interactive "P")
727 (if (consp n) (setq n (prefix-numeric-value n)))
728 (if (eobp) (forward-line -1))
729 (beginning-of-line)
730 (let ((buf rmail-buffer)
731 (cur (point))
732 (curmsg (string-to-int
733 (buffer-substring (point)
734 (min (point-max) (+ 5 (point)))))))
735 (if (not n)
736 (setq n curmsg)
737 (if (< n 1)
738 (progn (message "No preceding message")
739 (setq n 1)))
740 (if (> n rmail-total-messages)
741 (progn (message "No following message")
742 (goto-char (point-max))
743 (rmail-summary-goto-msg)))
744 (goto-char (point-min))
745 (if (not (re-search-forward (concat "^ *" (int-to-string n)) nil t))
746 (progn (or nowarn (message "Message %d not found" n))
747 (setq n curmsg)
748 (goto-char cur))))
749 (beginning-of-line)
750 (skip-chars-forward " ")
751 (skip-chars-forward "0-9")
752 (save-excursion (if (= (following-char) ?-)
753 (let ((buffer-read-only nil))
754 (delete-char 1)
755 (insert " "))))
756 (beginning-of-line)
757 (if skip-rmail
758 nil
759 (let ((selwin (selected-window)))
760 (unwind-protect
761 (progn (pop-to-buffer buf)
762 (rmail-show-message n))
763 (select-window selwin))))))
764 \f
765 (defun rmail-summary-scroll-msg-up (&optional dist)
766 "Scroll other window forward."
767 (interactive "P")
768 (scroll-other-window dist))
769
770 (defun rmail-summary-scroll-msg-down (&optional dist)
771 "Scroll other window backward."
772 (interactive "P")
773 (scroll-other-window
774 (cond ((eq dist '-) nil)
775 ((null dist) '-)
776 (t (- (prefix-numeric-value dist))))))
777
778 (defun rmail-summary-beginning-of-message ()
779 "Show current message from the beginning."
780 (interactive)
781 (pop-to-buffer rmail-buffer)
782 (beginning-of-buffer)
783 (pop-to-buffer rmail-summary-buffer))
784
785 (defun rmail-summary-quit ()
786 "Quit out of Rmail and Rmail summary."
787 (interactive)
788 (rmail-summary-wipe)
789 (rmail-quit))
790
791 (defun rmail-summary-wipe ()
792 "Kill and wipe away Rmail summary, remaining within Rmail."
793 (interactive)
794 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
795 (let ((local-rmail-buffer rmail-buffer))
796 (kill-buffer (current-buffer))
797 ;; Delete window if not only one.
798 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
799 (delete-window))
800 ;; Switch windows to the rmail buffer, or switch to it in this window.
801 (pop-to-buffer local-rmail-buffer)))
802
803 (defun rmail-summary-expunge ()
804 "Actually erase all deleted messages and recompute summary headers."
805 (interactive)
806 (save-excursion
807 (set-buffer rmail-buffer)
808 (rmail-only-expunge))
809 (rmail-update-summary))
810
811 (defun rmail-summary-expunge-and-save ()
812 "Expunge and save RMAIL file."
813 (interactive)
814 (save-excursion
815 (set-buffer rmail-buffer)
816 (rmail-only-expunge))
817 (rmail-update-summary)
818 (save-excursion
819 (set-buffer rmail-buffer)
820 (save-buffer)))
821
822 (defun rmail-summary-get-new-mail ()
823 "Get new mail and recompute summary headers."
824 (interactive)
825 (let (msg)
826 (save-excursion
827 (set-buffer rmail-buffer)
828 (rmail-get-new-mail)
829 ;; Get the proper new message number.
830 (setq msg rmail-current-message))
831 ;; Make sure that message is displayed.
832 (rmail-summary-goto-msg msg)))
833
834 (defun rmail-summary-input (filename)
835 "Run Rmail on file FILENAME."
836 (interactive "FRun rmail on RMAIL file: ")
837 ;; We switch windows here, then display the other Rmail file there.
838 (pop-to-buffer rmail-buffer)
839 (rmail filename))
840
841 (defun rmail-summary-first-message ()
842 "Show first message in Rmail file from summary buffer."
843 (interactive)
844 (beginning-of-buffer))
845
846 (defun rmail-summary-last-message ()
847 "Show last message in Rmail file from summary buffer."
848 (interactive)
849 (end-of-buffer)
850 (forward-line -1))
851
852 (defvar rmail-summary-edit-map nil)
853 (if rmail-summary-edit-map
854 nil
855 (setq rmail-summary-edit-map
856 (nconc (make-sparse-keymap) text-mode-map))
857 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
858 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
859
860 (defun rmail-summary-edit-current-message ()
861 "Edit the contents of this message."
862 (interactive)
863 (pop-to-buffer rmail-buffer)
864 (rmail-edit-current-message)
865 (use-local-map rmail-summary-edit-map))
866
867 (defun rmail-summary-cease-edit ()
868 "Finish editing message, then go back to Rmail summary buffer."
869 (interactive)
870 (rmail-cease-edit)
871 (pop-to-buffer rmail-summary-buffer))
872
873 (defun rmail-summary-abort-edit ()
874 "Abort edit of current message; restore original contents.
875 Go back to summary buffer."
876 (interactive)
877 (rmail-abort-edit)
878 (pop-to-buffer rmail-summary-buffer))
879
880 (defun rmail-summary-search-backward (regexp &optional n)
881 "Show message containing next match for REGEXP.
882 Prefix argument gives repeat count; negative argument means search
883 backwards (through earlier messages).
884 Interactively, empty argument means use same regexp used last time."
885 (interactive
886 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
887 (prompt
888 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
889 regexp)
890 (if rmail-search-last-regexp
891 (setq prompt (concat prompt
892 "(default "
893 rmail-search-last-regexp
894 ") ")))
895 (setq regexp (read-string prompt))
896 (cond ((not (equal regexp ""))
897 (setq rmail-search-last-regexp regexp))
898 ((not rmail-search-last-regexp)
899 (error "No previous Rmail search string")))
900 (list rmail-search-last-regexp
901 (prefix-numeric-value current-prefix-arg))))
902 ;; Don't use save-excursion because that prevents point from moving
903 ;; properly in the summary buffer.
904 (let ((buffer (current-buffer)))
905 (unwind-protect
906 (progn
907 (set-buffer rmail-buffer)
908 (rmail-search regexp (- n)))
909 (set-buffer buffer))))
910
911 (defun rmail-summary-search (regexp &optional n)
912 "Show message containing next match for REGEXP.
913 Prefix argument gives repeat count; negative argument means search
914 backwards (through earlier messages).
915 Interactively, empty argument means use same regexp used last time."
916 (interactive
917 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
918 (prompt
919 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
920 regexp)
921 (if rmail-search-last-regexp
922 (setq prompt (concat prompt
923 "(default "
924 rmail-search-last-regexp
925 ") ")))
926 (setq regexp (read-string prompt))
927 (cond ((not (equal regexp ""))
928 (setq rmail-search-last-regexp regexp))
929 ((not rmail-search-last-regexp)
930 (error "No previous Rmail search string")))
931 (list rmail-search-last-regexp
932 (prefix-numeric-value current-prefix-arg))))
933 ;; Don't use save-excursion because that prevents point from moving
934 ;; properly in the summary buffer.
935 (let ((buffer (current-buffer)))
936 (unwind-protect
937 (progn
938 (set-buffer rmail-buffer)
939 (rmail-search regexp n))
940 (set-buffer buffer))))
941
942 (defun rmail-summary-toggle-header ()
943 "Show original message header if pruned header currently shown, or vice versa."
944 (interactive)
945 (save-excursion
946 (set-buffer rmail-buffer)
947 (rmail-toggle-header)))
948
949 (defun rmail-summary-add-label (label)
950 "Add LABEL to labels associated with current Rmail message.
951 Completion is performed over known labels when reading."
952 (interactive (list (save-excursion
953 (set-buffer rmail-buffer)
954 (rmail-read-label "Add label"))))
955 (save-excursion
956 (set-buffer rmail-buffer)
957 (rmail-add-label label)))
958
959 (defun rmail-summary-kill-label (label)
960 "Remove LABEL from labels associated with current Rmail message.
961 Completion is performed over known labels when reading."
962 (interactive (list (save-excursion
963 (set-buffer rmail-buffer)
964 (rmail-read-label "Kill label"))))
965 (save-excursion
966 (set-buffer rmail-buffer)
967 (rmail-set-label label nil)))
968 \f
969 ;;;; *** Rmail Summary Mailing Commands ***
970
971 (defun rmail-summary-mail ()
972 "Send mail in another window.
973 While composing the message, use \\[mail-yank-original] to yank the
974 original message into it."
975 (interactive)
976 (rmail-start-mail nil nil nil nil nil rmail-buffer)
977 (use-local-map (copy-keymap (current-local-map)))
978 (define-key (current-local-map)
979 "\C-c\C-c" 'rmail-summary-send-and-exit))
980
981 (defun rmail-summary-continue ()
982 "Continue composing outgoing message previously being composed."
983 (interactive)
984 (rmail-start-mail t))
985
986 (defun rmail-summary-reply (just-sender)
987 "Reply to the current message.
988 Normally include CC: to all other recipients of original message;
989 prefix argument means ignore them. While composing the reply,
990 use \\[mail-yank-original] to yank the original message into it."
991 (interactive "P")
992 (set-buffer rmail-buffer)
993 (rmail-reply just-sender)
994 (use-local-map (copy-keymap (current-local-map)))
995 (define-key (current-local-map)
996 "\C-c\C-c" 'rmail-summary-send-and-exit))
997
998 (defun rmail-summary-retry-failure ()
999 "Edit a mail message which is based on the contents of the current message.
1000 For a message rejected by the mail system, extract the interesting headers and
1001 the body of the original message; otherwise copy the current message."
1002 (interactive)
1003 (set-buffer rmail-buffer)
1004 (rmail-retry-failure)
1005 (use-local-map (copy-keymap (current-local-map)))
1006 (define-key (current-local-map)
1007 "\C-c\C-c" 'rmail-summary-send-and-exit))
1008
1009 (defun rmail-summary-send-and-exit ()
1010 "Send mail reply and return to summary buffer."
1011 (interactive)
1012 (mail-send-and-exit t))
1013
1014 (defun rmail-summary-forward (resend)
1015 "Forward the current message to another user.
1016 With prefix argument, \"resend\" the message instead of forwarding it;
1017 see the documentation of `rmail-resend'."
1018 (interactive "P")
1019 (save-excursion
1020 (set-buffer rmail-buffer)
1021 (rmail-forward resend)
1022 (use-local-map (copy-keymap (current-local-map)))
1023 (define-key (current-local-map)
1024 "\C-c\C-c" 'rmail-summary-send-and-exit)))
1025 \f
1026 ;; Summary output commands.
1027
1028 (defun rmail-summary-output-to-rmail-file ()
1029 "Append the current message to an Rmail file named FILE-NAME.
1030 If the file does not exist, ask if it should be created.
1031 If file is being visited, the message is appended to the Emacs
1032 buffer visiting that file."
1033 (interactive)
1034 (save-excursion
1035 (set-buffer rmail-buffer)
1036 (let ((rmail-delete-after-output nil))
1037 (call-interactively 'rmail-output-to-rmail-file)))
1038 (if rmail-delete-after-output
1039 (rmail-summary-delete-forward nil)))
1040
1041 (defun rmail-summary-output ()
1042 "Append this message to Unix mail file named FILE-NAME."
1043 (interactive)
1044 (save-excursion
1045 (set-buffer rmail-buffer)
1046 (let ((rmail-delete-after-output nil))
1047 (call-interactively 'rmail-output)))
1048 (if rmail-delete-after-output
1049 (rmail-summary-delete-forward nil)))
1050 \f
1051 ;; Sorting messages in Rmail Summary buffer.
1052
1053 (defun rmail-summary-sort-by-date (reverse)
1054 "Sort messages of current Rmail summary by date.
1055 If prefix argument REVERSE is non-nil, sort them in reverse order."
1056 (interactive "P")
1057 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1058
1059 (defun rmail-summary-sort-by-subject (reverse)
1060 "Sort messages of current Rmail summary by subject.
1061 If prefix argument REVERSE is non-nil, sort them in reverse order."
1062 (interactive "P")
1063 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1064
1065 (defun rmail-summary-sort-by-author (reverse)
1066 "Sort messages of current Rmail summary by author.
1067 If prefix argument REVERSE is non-nil, sort them in reverse order."
1068 (interactive "P")
1069 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1070
1071 (defun rmail-summary-sort-by-recipient (reverse)
1072 "Sort messages of current Rmail summary by recipient.
1073 If prefix argument REVERSE is non-nil, sort them in reverse order."
1074 (interactive "P")
1075 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1076
1077 (defun rmail-summary-sort-by-correspondent (reverse)
1078 "Sort messages of current Rmail summary by other correspondent.
1079 If prefix argument REVERSE is non-nil, sort them in reverse order."
1080 (interactive "P")
1081 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1082
1083 (defun rmail-summary-sort-by-lines (reverse)
1084 "Sort messages of current Rmail summary by lines of the message.
1085 If prefix argument REVERSE is non-nil, sort them in reverse order."
1086 (interactive "P")
1087 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1088
1089 (defun rmail-sort-from-summary (sortfun reverse)
1090 "Sort Rmail messages from Summary buffer and update it after sorting."
1091 (require 'rmailsort)
1092 (pop-to-buffer rmail-buffer)
1093 (funcall sortfun reverse)
1094 (rmail-summary))
1095
1096 ;;; rmailsum.el ends here