1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc.
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)
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.
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.
32 (defvar rmail-summary-font-lock-keywords
33 '(("^....D.*$" . font-lock-string-face) ; Deleted.
34 ("^....-.*$" . font-lock-type-face) ; Unread.
35 ;; Neither of the below will be highlighted if either of the above are:
36 ("^....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date.
37 ("{ \\([^}]+\\),}" 1 font-lock-comment-face)) ; Labels.
38 "Additional expressions to highlight in Rmail Summary mode.")
40 ;; Entry points for making a summary buffer.
42 ;; Regenerate the contents of the summary
43 ;; using the same selection criterion as last time.
44 ;; M-x revert-buffer in a summary buffer calls this function.
45 (defun rmail-update-summary (&rest ignore)
46 (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
48 (defun rmail-summary ()
49 "Display a summary of all messages, one line per message."
51 (rmail-new-summary "All" '(rmail-summary) nil))
53 (defun rmail-summary-by-labels (labels)
54 "Display a summary of all messages with one or more LABELS.
55 LABELS should be a string containing the desired labels, separated by commas."
56 (interactive "sLabels to summarize by: ")
57 (if (string= labels "")
58 (setq labels (or rmail-last-multi-labels
59 (error "No label specified"))))
60 (setq rmail-last-multi-labels labels)
61 (rmail-new-summary (concat "labels " labels)
62 (list 'rmail-summary-by-labels labels)
63 'rmail-message-labels-p
64 (concat ", \\(" (mail-comma-list-regexp labels) "\\),")))
66 (defun rmail-summary-by-recipients (recipients &optional primary-only)
67 "Display a summary of all messages with the given RECIPIENTS.
68 Normally checks the To, From and Cc fields of headers;
69 but if PRIMARY-ONLY is non-nil (prefix arg given),
70 only look in the To and From fields.
71 RECIPIENTS is a string of regexps separated by commas."
72 (interactive "sRecipients to summarize by: \nP")
74 (concat "recipients " recipients)
75 (list 'rmail-summary-by-recipients recipients primary-only)
76 'rmail-message-recipients-p
77 (mail-comma-list-regexp recipients) primary-only))
79 (defun rmail-summary-by-regexp (regexp)
80 "Display a summary of all messages according to regexp REGEXP.
81 If the regular expression is found in the header of the message
82 \(including in the date and other lines, as well as the subject line),
83 Emacs will list the header line in the RMAIL-summary."
84 (interactive "sRegexp to summarize by: ")
85 (if (string= regexp "")
86 (setq regexp (or rmail-last-regexp
87 (error "No regexp specified."))))
88 (setq rmail-last-regexp regexp)
89 (rmail-new-summary (concat "regexp " regexp)
90 (list 'rmail-summary-by-regexp regexp)
91 'rmail-message-regexp-p
94 ;; rmail-summary-by-topic
95 ;; 1989 R.A. Schnitzler
97 (defun rmail-summary-by-topic (subject &optional whole-message)
98 "Display a summary of all messages with the given SUBJECT.
99 Normally checks the Subject field of headers;
100 but if WHOLE-MESSAGE is non-nil (prefix arg given),
101 look in the whole message.
102 SUBJECT is a string of regexps separated by commas."
103 (interactive "sTopics to summarize by: \nP")
105 (concat "about " subject)
106 (list 'rmail-summary-by-topic subject whole-message)
107 'rmail-message-subject-p
108 (mail-comma-list-regexp subject) whole-message))
110 (defun rmail-message-subject-p (msg subject &optional whole-message)
112 (goto-char (rmail-msgbeg msg))
113 (search-forward "\n*** EOOH ***\n")
116 (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
117 (goto-char (point-min))
118 (if whole-message (re-search-forward subject nil t)
119 (string-match subject (or (mail-fetch-field "Subject") "")) )))
121 (defun rmail-summary-by-senders (senders)
122 "Display a summary of all messages with the given SENDERS.
123 SENDERS is a string of names separated by commas."
124 (interactive "sSenders to summarize by: ")
126 (concat "senders " senders)
127 (list 'rmail-summary-by-senders senders)
128 'rmail-message-senders-p
129 (mail-comma-list-regexp senders)))
131 (defun rmail-message-senders-p (msg senders)
133 (goto-char (rmail-msgbeg msg))
134 (search-forward "\n*** EOOH ***\n")
135 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
136 (string-match senders (or (mail-fetch-field "From") ""))))
138 ;; General making of a summary buffer.
140 (defvar rmail-summary-symbol-number 0)
142 (defun rmail-new-summary (description redo-form function &rest args)
143 "Create a summary of selected messages.
144 DESCRIPTION makes part of the mode line of the summary buffer.
145 For each message, FUNCTION is applied to the message number and ARGS...
146 and if the result is non-nil, that message is included.
147 nil for FUNCTION means all messages."
148 (message "Computing summary lines...")
149 (let (sumbuf mesg was-in-summary)
151 ;; Go to the Rmail buffer.
152 (if (eq major-mode 'rmail-summary-mode)
154 (setq was-in-summary t)
155 (set-buffer rmail-buffer)))
156 ;; Find its summary buffer, or make one.
158 (if (and rmail-summary-buffer
159 (buffer-name rmail-summary-buffer))
161 (generate-new-buffer (concat (buffer-name) "-summary"))))
162 (setq mesg rmail-current-message)
163 ;; Filter the messages; make or get their summary lines.
164 (let ((summary-msgs ())
165 (new-summary-line-count 0))
167 (buffer-read-only nil)
168 (old-min (point-min-marker))
169 (old-max (point-max-marker)))
170 ;; Can't use save-restriction here; that doesn't work if we
171 ;; plan to modify text outside the original restriction.
174 (goto-char (point-min))
175 (while (>= rmail-total-messages msgnum)
176 (if (or (null function)
177 (apply function (cons msgnum args)))
179 (cons (cons msgnum (rmail-make-summary-line msgnum))
181 (setq msgnum (1+ msgnum)))
182 (setq summary-msgs (nreverse summary-msgs)))
183 (narrow-to-region old-min old-max))
184 ;; Temporarily, while summary buffer is unfinished,
185 ;; we "don't have" a summary.
186 (setq rmail-summary-buffer nil)
188 (let ((rbuf (current-buffer))
189 (total rmail-total-messages))
191 ;; Set up the summary buffer's contents.
192 (let ((buffer-read-only nil))
195 (princ (cdr (car summary-msgs)) sumbuf)
196 (setq summary-msgs (cdr summary-msgs)))
197 (goto-char (point-min)))
198 ;; Set up the rest of its state and local variables.
199 (setq buffer-read-only t)
201 (make-local-variable 'minor-mode-alist)
202 (setq minor-mode-alist (list '(t (concat ": " description))))
203 (setq rmail-buffer rbuf
204 rmail-summary-redo redo-form
205 rmail-total-messages total))))
206 (setq rmail-summary-buffer sumbuf))
207 ;; Now display the summary buffer and go to the right place in it.
210 ;; If there is just one window, put the summary on the top.
213 (select-window (next-window (frame-first-window)))
214 (pop-to-buffer sumbuf)
215 ;; If pop-to-buffer did not use that window, delete that
216 ;; window. (This can happen if it uses another frame.)
217 (if (not (eq sumbuf (window-buffer (frame-first-window))))
218 (delete-other-windows)))
219 (pop-to-buffer sumbuf)))
220 (rmail-summary-goto-msg mesg t t)
221 (message "Computing summary lines...done")))
223 ;; Low levels of generating a summary.
225 (defun rmail-make-summary-line (msg)
226 (let ((line (or (aref rmail-summary-vector (1- msg))
228 (setq new-summary-line-count
229 (1+ new-summary-line-count))
230 (if (zerop (% new-summary-line-count 10))
231 (message "Computing summary lines...%d"
232 new-summary-line-count))
233 (rmail-make-summary-line-1 msg)))))
234 ;; Fix up the part of the summary that says "deleted" or "unseen".
236 (if (rmail-message-deleted-p msg) ?\D
237 (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg))))
241 (defun rmail-make-summary-line-1 (msg)
242 (goto-char (rmail-msgbeg msg))
243 (let* ((lim (save-excursion (forward-line 2) (point)))
249 ; (if (save-excursion (re-search-forward ",answered," lim t))
251 ; (if (save-excursion (re-search-forward ",filed," lim t))
253 (if (progn (search-forward ",,") (eolp))
256 (buffer-substring (point)
257 (progn (end-of-line) (point)))
262 (if (looking-at "Summary-line: ")
264 (goto-char (match-end 0))
266 (buffer-substring (point)
267 (progn (forward-line 1) (point)))))))))
268 ;; Obsolete status lines lacking a # should be flushed.
270 (not (string-match "#" line))
272 (delete-region (point)
273 (progn (forward-line -1) (point)))
275 ;; If we didn't get a valid status line from the message,
276 ;; make a new one and put it in the message.
278 (let* ((case-fold-search t)
279 (next (rmail-msgend msg))
280 (beg (if (progn (goto-char (rmail-msgbeg msg))
281 (search-forward "\n*** EOOH ***\n" next t))
285 (end (progn (search-forward "\n\n" nil t) (point))))
287 (narrow-to-region beg end)
289 (setq line (rmail-make-basic-summary-line)))
290 (goto-char (rmail-msgbeg msg))
292 (insert "Summary-line: " line)))
293 (setq pos (string-match "#" line))
294 (aset rmail-summary-vector (1- msg)
295 (concat (format "%4d " msg)
296 (substring line 0 pos)
298 (substring line (1+ pos))))))
300 (defun rmail-make-basic-summary-line ()
301 (goto-char (point-min))
302 (concat (save-excursion
303 (if (not (re-search-forward "^Date:" nil t))
305 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
306 (save-excursion (end-of-line) (point)) t)
308 (string-to-int (buffer-substring
312 (match-beginning 4) (match-end 4))))
313 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
314 (save-excursion (end-of-line) (point)) t)
316 (string-to-int (buffer-substring
320 (match-beginning 2) (match-end 2))))
324 (if (not (re-search-forward "^From:[ \t]*" nil t))
326 (let* ((from (mail-strip-quoted-names
329 ;; Get all the lines of the From field
330 ;; so that we get a whole comment if there is one,
331 ;; so that mail-strip-quoted-names can discard it.
332 (let ((opoint (point)))
333 (while (progn (forward-line 1)
334 (looking-at "[ \t]")))
335 ;; Back up over newline, then trailing spaces or tabs
337 (skip-chars-backward " \t")
340 (if (string-match (concat "^"
341 (regexp-quote (user-login-name))
345 (goto-char (point-min))
346 (if (not (re-search-forward "^To:[ \t]*" nil t))
350 (mail-strip-quoted-names
354 (skip-chars-backward " \t")
356 (setq len (length from))
357 (setq mch (string-match "[@%]" from))
359 (if (or (not mch) (<= len 25))
360 (substring from (max 0 (- len 25)))
362 (setq lo (cond ((< (- mch 14) 0) 0)
366 (min len (+ lo 25))))))))
368 (if (re-search-forward "^Subject:" nil t)
369 (progn (skip-chars-forward " \t")
370 (buffer-substring (point)
373 (re-search-forward "[\n][\n]+" nil t)
374 (buffer-substring (point) (progn (end-of-line) (point))))
377 ;; Simple motion in a summary buffer.
379 (defun rmail-summary-next-all (&optional number)
381 (forward-line (if number number 1))
382 (display-buffer rmail-buffer))
384 (defun rmail-summary-previous-all (&optional number)
386 (forward-line (- (if number number 1)))
387 (display-buffer rmail-buffer))
389 (defun rmail-summary-next-msg (&optional number)
390 "Display next non-deleted msg from rmail file.
391 With optional prefix argument NUMBER, moves forward this number of non-deleted
392 messages, or backward if NUMBER is negative."
395 (and (> number 0) (end-of-line))
396 (let ((count (if (< number 0) (- number) number))
397 (search (if (> number 0) 're-search-forward 're-search-backward))
398 (non-del-msg-found nil))
399 (while (and (> count 0) (setq non-del-msg-found
400 (or (funcall search "^....[^D]" nil t)
402 (setq count (1- count))))
404 (display-buffer rmail-buffer))
406 (defun rmail-summary-previous-msg (&optional number)
408 (rmail-summary-next-msg (- (if number number 1))))
410 (defun rmail-summary-next-labeled-message (n labels)
411 "Show next message with LABEL. Defaults to last labels used.
412 With prefix argument N moves forward N messages with these labels."
413 (interactive "p\nsMove to next msg with labels: ")
415 (set-buffer rmail-buffer)
416 (rmail-next-labeled-message n labels)))
418 (defun rmail-summary-previous-labeled-message (n labels)
419 "Show previous message with LABEL. Defaults to last labels used.
420 With prefix argument N moves backward N messages with these labels."
421 (interactive "p\nsMove to previous msg with labels: ")
423 (set-buffer rmail-buffer)
424 (rmail-previous-labeled-message n labels)))
426 ;; Delete and undelete summary commands.
428 (defun rmail-summary-delete-forward (&optional backward)
429 "Delete this message and move to next nondeleted one.
430 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
431 With prefix argument, delete and move backward."
434 (rmail-summary-goto-msg)
435 (pop-to-buffer rmail-buffer)
436 (rmail-delete-message)
437 (let ((del-msg rmail-current-message))
438 (pop-to-buffer rmail-summary-buffer)
439 (rmail-summary-mark-deleted del-msg)
440 (while (and (not (if backward (bobp) (eobp)))
441 (save-excursion (beginning-of-line)
442 (looking-at " *[0-9]+D")))
443 (forward-line (if backward -1 1))))))
445 (defun rmail-summary-delete-backward ()
446 "Delete this message and move to previous nondeleted one.
447 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
449 (rmail-summary-delete-forward t))
451 (defun rmail-summary-mark-deleted (&optional n undel)
452 (and n (rmail-summary-goto-msg n t t))
454 (let ((buffer-read-only nil))
455 (skip-chars-forward " ")
456 (skip-chars-forward "[0-9]")
459 (progn (delete-char 1) (insert " ")))
464 (defun rmail-summary-mark-undeleted (n)
465 (rmail-summary-mark-deleted n t))
467 (defun rmail-summary-deleted-p (&optional n)
469 (and n (rmail-summary-goto-msg n nil t))
470 (skip-chars-forward " ")
471 (skip-chars-forward "[0-9]")
474 (defun rmail-summary-undelete (&optional arg)
475 "Undelete current message.
476 Optional prefix ARG means undelete ARG previous messages."
479 (rmail-summary-undelete-many arg)
480 (let ((buffer-read-only nil)
483 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
484 (replace-match "\\1 ")
485 (rmail-summary-goto-msg)
486 (pop-to-buffer rmail-buffer)
487 (and (rmail-message-deleted-p rmail-current-message)
488 (rmail-undelete-previous-message))
489 (pop-to-buffer rmail-summary-buffer))
490 (t (goto-char opoint))))))
492 (defun rmail-summary-undelete-many (&optional n)
493 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
496 (set-buffer rmail-buffer)
497 (let* ((init-msg (if n rmail-current-message rmail-total-messages))
498 (rmail-current-message init-msg)
499 (n (or n rmail-total-messages))
501 (while (and (> rmail-current-message 0)
503 (if (rmail-message-deleted-p rmail-current-message)
504 (progn (rmail-set-attribute "deleted" nil)
505 (setq msgs-undeled (1+ msgs-undeled))))
506 (setq rmail-current-message (1- rmail-current-message)))
507 (set-buffer rmail-summary-buffer)
508 (setq rmail-current-message init-msg msgs-undeled 0)
509 (while (and (> rmail-current-message 0)
511 (if (rmail-summary-deleted-p rmail-current-message)
512 (progn (rmail-summary-mark-undeleted rmail-current-message)
513 (setq msgs-undeled (1+ msgs-undeled))))
514 (setq rmail-current-message (1- rmail-current-message))))
515 (rmail-summary-goto-msg)))
517 ;; Rmail Summary mode is suitable only for specially formatted data.
518 (put 'rmail-summary-mode 'mode-class 'special)
520 (defun rmail-summary-mode ()
521 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
522 As commands are issued in the summary buffer, they are applied to the
523 corresponding mail messages in the rmail buffer.
525 All normal editing commands are turned off.
526 Instead, nearly all the Rmail mode commands are available,
527 though many of them move only among the messages in the summary.
529 These additional commands exist:
531 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
532 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
534 Commands for sorting the summary:
536 \\[rmail-summary-sort-by-date] Sort by date.
537 \\[rmail-summary-sort-by-subject] Sort by subject.
538 \\[rmail-summary-sort-by-author] Sort by author.
539 \\[rmail-summary-sort-by-recipient] Sort by recipient.
540 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
541 \\[rmail-summary-sort-by-lines] Sort by lines.
542 \\[rmail-summary-sort-by-keywords] Sort by keywords."
544 (kill-all-local-variables)
545 (setq major-mode 'rmail-summary-mode)
546 (setq mode-name "RMAIL Summary")
547 (setq truncate-lines t)
548 (setq buffer-read-only t)
549 (set-syntax-table text-mode-syntax-table)
550 (make-local-variable 'rmail-buffer)
551 (make-local-variable 'rmail-total-messages)
552 (make-local-variable 'rmail-current-message)
553 (setq rmail-current-message nil)
554 (make-local-variable 'rmail-summary-redo)
555 (setq rmail-summary-redo nil)
556 (make-local-variable 'revert-buffer-function)
557 (make-local-variable 'post-command-hook)
558 (make-local-variable 'font-lock-keywords)
559 (setq font-lock-keywords rmail-summary-font-lock-keywords)
560 (rmail-summary-enable)
561 (run-hooks 'rmail-summary-mode-hook))
563 ;; Summary features need to be disabled during edit mode.
564 (defun rmail-summary-disable ()
565 (use-local-map text-mode-map)
566 (remove-hook 'post-command-hook 'rmail-summary-rmail-update)
567 (setq revert-buffer-function nil))
569 (defun rmail-summary-enable ()
570 (use-local-map rmail-summary-mode-map)
571 (add-hook 'post-command-hook 'rmail-summary-rmail-update)
572 (setq revert-buffer-function 'rmail-update-summary))
574 ;; Show in Rmail the message described by the summary line that point is on,
575 ;; but only if the Rmail buffer is already visible.
576 ;; This is a post-command-hook in summary buffers.
577 (defun rmail-summary-rmail-update ()
578 (let (buffer-read-only)
580 ;; If at end of buffer, pretend we are on the last text line.
584 (skip-chars-forward " ")
585 (let ((msg-num (string-to-int (buffer-substring
587 (progn (skip-chars-forward "0-9")
589 (or (eq rmail-current-message msg-num)
590 (let ((window (get-buffer-window rmail-buffer))
591 (owin (selected-window)))
592 (setq rmail-current-message msg-num)
593 (if (= (following-char) ?-)
598 ;; Using save-window-excursion would cause the new value
599 ;; of point to get lost.
602 (select-window window)
603 (rmail-show-message msg-num))
604 (select-window owin))
605 (if (buffer-name rmail-buffer)
607 (set-buffer rmail-buffer)
608 (rmail-show-message msg-num))))))))))
610 (defvar rmail-summary-mode-map nil)
612 (if rmail-summary-mode-map
614 (setq rmail-summary-mode-map (make-keymap))
615 (suppress-keymap rmail-summary-mode-map)
616 (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label)
617 (define-key rmail-summary-mode-map "c" 'rmail-summary-continue)
618 (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward)
619 (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward)
620 (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message)
621 (define-key rmail-summary-mode-map "f" 'rmail-summary-forward)
622 (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail)
623 (define-key rmail-summary-mode-map "h" 'rmail-summary)
624 (define-key rmail-summary-mode-map "i" 'rmail-summary-input)
625 (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg)
626 (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label)
627 (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels)
628 (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
629 (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
630 (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
631 (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
632 (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
633 (define-key rmail-summary-mode-map "m" 'rmail-summary-mail)
634 (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure)
635 (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg)
636 (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all)
637 (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
638 (define-key rmail-summary-mode-map "o" 'rmail-summary-output-to-rmail-file)
639 (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output)
640 (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg)
641 (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all)
642 (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
643 (define-key rmail-summary-mode-map "q" 'rmail-summary-quit)
644 (define-key rmail-summary-mode-map "r" 'rmail-summary-reply)
645 (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save)
646 (define-key rmail-summary-mode-map "\es" 'rmail-summary-search)
647 (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header)
648 (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete)
649 (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many)
650 (define-key rmail-summary-mode-map "w" 'rmail-summary-wipe)
651 (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge)
652 (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message)
653 (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message)
654 (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message)
655 (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up)
656 (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down)
657 (define-key rmail-summary-mode-map "?" 'describe-mode)
658 (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
659 'rmail-summary-sort-by-date)
660 (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
661 'rmail-summary-sort-by-subject)
662 (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
663 'rmail-summary-sort-by-author)
664 (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
665 'rmail-summary-sort-by-recipient)
666 (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
667 'rmail-summary-sort-by-correspondent)
668 (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
669 'rmail-summary-sort-by-lines)
670 (define-key rmail-summary-mode-map "\C-c\C-s\C-k"
671 'rmail-summary-sort-by-keywords)
674 ;;; Menu bar bindings.
676 (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
678 (define-key rmail-summary-mode-map [menu-bar classify]
679 (cons "Classify" (make-sparse-keymap "Classify")))
681 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
682 '("Output (Rmail Menu)..." . rmail-summary-output-menu))
684 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
685 '("Input Rmail file (menu)..." . rmail-input-menu))
687 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
690 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
693 (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
694 '("Output (inbox)..." . rmail-summary-output))
696 (define-key rmail-summary-mode-map [menu-bar classify output]
697 '("Output (Rmail)..." . rmail-summary-output-to-rmail-file))
699 (define-key rmail-summary-mode-map [menu-bar classify kill-label]
700 '("Kill Label..." . rmail-summary-kill-label))
702 (define-key rmail-summary-mode-map [menu-bar classify add-label]
703 '("Add Label..." . rmail-summary-add-label))
705 (define-key rmail-summary-mode-map [menu-bar summary]
706 (cons "Summary" (make-sparse-keymap "Summary")))
708 (define-key rmail-summary-mode-map [menu-bar summary labels]
709 '("By Labels..." . rmail-summary-by-labels))
711 (define-key rmail-summary-mode-map [menu-bar summary recipients]
712 '("By Recipients..." . rmail-summary-by-recipients))
714 (define-key rmail-summary-mode-map [menu-bar summary topic]
715 '("By Topic..." . rmail-summary-by-topic))
717 (define-key rmail-summary-mode-map [menu-bar summary regexp]
718 '("By Regexp..." . rmail-summary-by-regexp))
720 (define-key rmail-summary-mode-map [menu-bar summary all]
721 '("All" . rmail-summary))
723 (define-key rmail-summary-mode-map [menu-bar mail]
724 (cons "Mail" (make-sparse-keymap "Mail")))
726 (define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail]
727 '("Get New Mail" . rmail-summary-get-new-mail))
729 (define-key rmail-summary-mode-map [menu-bar mail lambda]
732 (define-key rmail-summary-mode-map [menu-bar mail continue]
733 '("Continue" . rmail-summary-continue))
735 (define-key rmail-summary-mode-map [menu-bar mail resend]
736 '("Re-send..." . rmail-resend))
738 (define-key rmail-summary-mode-map [menu-bar mail forward]
739 '("Forward" . rmail-summary-forward))
741 (define-key rmail-summary-mode-map [menu-bar mail retry]
742 '("Retry" . rmail-summary-retry-failure))
744 (define-key rmail-summary-mode-map [menu-bar mail reply]
745 '("Reply" . rmail-summary-reply))
747 (define-key rmail-summary-mode-map [menu-bar mail mail]
748 '("Mail" . rmail-summary-mail))
750 (define-key rmail-summary-mode-map [menu-bar delete]
751 (cons "Delete" (make-sparse-keymap "Delete")))
753 (define-key rmail-summary-mode-map [menu-bar delete expunge/save]
754 '("Expunge/Save" . rmail-summary-expunge-and-save))
756 (define-key rmail-summary-mode-map [menu-bar delete expunge]
757 '("Expunge" . rmail-summary-expunge))
759 (define-key rmail-summary-mode-map [menu-bar delete undelete]
760 '("Undelete" . rmail-summary-undelete))
762 (define-key rmail-summary-mode-map [menu-bar delete delete]
763 '("Delete" . rmail-summary-delete-forward))
765 (define-key rmail-summary-mode-map [menu-bar move]
766 (cons "Move" (make-sparse-keymap "Move")))
768 (define-key rmail-summary-mode-map [menu-bar move search-back]
769 '("Search Back..." . rmail-summary-search-backward))
771 (define-key rmail-summary-mode-map [menu-bar move search]
772 '("Search..." . rmail-summary-search))
774 (define-key rmail-summary-mode-map [menu-bar move previous]
775 '("Previous Nondeleted" . rmail-summary-previous-msg))
777 (define-key rmail-summary-mode-map [menu-bar move next]
778 '("Next Nondeleted" . rmail-summary-next-msg))
780 (define-key rmail-summary-mode-map [menu-bar move last]
781 '("Last" . rmail-summary-last-message))
783 (define-key rmail-summary-mode-map [menu-bar move first]
784 '("First" . rmail-summary-first-message))
786 (define-key rmail-summary-mode-map [menu-bar move previous]
787 '("Previous" . rmail-summary-previous-all))
789 (define-key rmail-summary-mode-map [menu-bar move next]
790 '("Next" . rmail-summary-next-all))
792 (defvar rmail-summary-overlay nil)
794 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
796 (if (consp n) (setq n (prefix-numeric-value n)))
797 (if (eobp) (forward-line -1))
799 (let* ((obuf (current-buffer))
803 (curmsg (string-to-int
804 (buffer-substring (point)
805 (min (point-max) (+ 5 (point))))))
806 (total (save-excursion (set-buffer buf) rmail-total-messages)))
807 ;; If message number N was specified, find that message's line
808 ;; or set message-not-found.
809 ;; If N wasn't specified or that message can't be found.
814 (progn (message "No preceding message")
817 (progn (message "No following message")
818 (goto-char (point-max))
819 (rmail-summary-goto-msg)))
820 (goto-char (point-min))
821 (if (not (re-search-forward (format "^%4d[^0-9]" n) nil t))
822 (progn (or nowarn (message "Message %d not found" n))
824 (setq message-not-found t)
827 (skip-chars-forward " ")
828 (skip-chars-forward "0-9")
829 (save-excursion (if (= (following-char) ?-)
830 (let ((buffer-read-only nil))
833 ;; Make sure we have an overlay to use.
834 (or rmail-summary-overlay
836 (make-local-variable 'rmail-summary-overlay)
837 (setq rmail-summary-overlay (make-overlay (point) (point)))))
838 ;; If this message is in the summary, use the overlay to highlight it.
839 ;; Otherwise, don't highlight anything.
840 (if message-not-found
841 (overlay-put rmail-summary-overlay 'face nil)
842 (move-overlay rmail-summary-overlay
843 (save-excursion (beginning-of-line) (1+ (point)))
844 (save-excursion (end-of-line) (point)))
845 (overlay-put rmail-summary-overlay 'face 'highlight))
849 (let ((selwin (selected-window)))
851 (progn (pop-to-buffer buf)
852 (rmail-show-message n))
853 (select-window selwin)
854 ;; The actions above can alter the current buffer. Preserve it.
855 (set-buffer obuf))))))
857 (defun rmail-summary-scroll-msg-up (&optional dist)
858 "Scroll the Rmail window forward."
860 (let ((other-window-scroll-buffer rmail-buffer))
861 (if (get-buffer-window rmail-buffer)
862 (scroll-other-window dist)
863 ;; This forces rmail-buffer to be sized correctly later.
864 (display-buffer rmail-buffer)
865 (setq rmail-current-message nil))))
867 (defun rmail-summary-scroll-msg-down (&optional dist)
868 "Scroll the Rmail window backward."
870 (rmail-summary-scroll-msg-up
871 (cond ((eq dist '-) nil)
873 (t (- (prefix-numeric-value dist))))))
875 (defun rmail-summary-beginning-of-message ()
876 "Show current message from the beginning."
878 (pop-to-buffer rmail-buffer)
879 (beginning-of-buffer)
880 (pop-to-buffer rmail-summary-buffer))
882 (defun rmail-summary-quit ()
883 "Quit out of Rmail and Rmail summary."
888 (defun rmail-summary-wipe ()
889 "Kill and wipe away Rmail summary, remaining within Rmail."
891 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
892 (let ((local-rmail-buffer rmail-buffer))
893 (kill-buffer (current-buffer))
894 ;; Delete window if not only one.
895 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
897 ;; Switch windows to the rmail buffer, or switch to it in this window.
898 (pop-to-buffer local-rmail-buffer)))
900 (defun rmail-summary-expunge ()
901 "Actually erase all deleted messages and recompute summary headers."
904 (set-buffer rmail-buffer)
905 (rmail-only-expunge))
906 (rmail-update-summary))
908 (defun rmail-summary-expunge-and-save ()
909 "Expunge and save RMAIL file."
912 (set-buffer rmail-buffer)
913 (rmail-only-expunge))
914 (rmail-update-summary)
916 (set-buffer rmail-buffer)
918 (set-buffer-modified-p nil))
920 (defun rmail-summary-get-new-mail ()
921 "Get new mail and recompute summary headers."
925 (set-buffer rmail-buffer)
927 ;; Get the proper new message number.
928 (setq msg rmail-current-message))
929 ;; Make sure that message is displayed.
930 (rmail-summary-goto-msg msg)))
932 (defun rmail-summary-input (filename)
933 "Run Rmail on file FILENAME."
934 (interactive "FRun rmail on RMAIL file: ")
935 ;; We switch windows here, then display the other Rmail file there.
936 (pop-to-buffer rmail-buffer)
939 (defun rmail-summary-first-message ()
940 "Show first message in Rmail file from summary buffer."
942 (beginning-of-buffer))
944 (defun rmail-summary-last-message ()
945 "Show last message in Rmail file from summary buffer."
950 (defvar rmail-summary-edit-map nil)
951 (if rmail-summary-edit-map
953 (setq rmail-summary-edit-map
954 (nconc (make-sparse-keymap) text-mode-map))
955 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
956 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
958 (defun rmail-summary-edit-current-message ()
959 "Edit the contents of this message."
961 (pop-to-buffer rmail-buffer)
962 (rmail-edit-current-message)
963 (use-local-map rmail-summary-edit-map))
965 (defun rmail-summary-cease-edit ()
966 "Finish editing message, then go back to Rmail summary buffer."
969 (pop-to-buffer rmail-summary-buffer))
971 (defun rmail-summary-abort-edit ()
972 "Abort edit of current message; restore original contents.
973 Go back to summary buffer."
976 (pop-to-buffer rmail-summary-buffer))
978 (defun rmail-summary-search-backward (regexp &optional n)
979 "Show message containing next match for REGEXP.
980 Prefix argument gives repeat count; negative argument means search
981 backwards (through earlier messages).
982 Interactively, empty argument means use same regexp used last time."
984 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
986 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
988 (if rmail-search-last-regexp
989 (setq prompt (concat prompt
991 rmail-search-last-regexp
993 (setq regexp (read-string prompt))
994 (cond ((not (equal regexp ""))
995 (setq rmail-search-last-regexp regexp))
996 ((not rmail-search-last-regexp)
997 (error "No previous Rmail search string")))
998 (list rmail-search-last-regexp
999 (prefix-numeric-value current-prefix-arg))))
1000 ;; Don't use save-excursion because that prevents point from moving
1001 ;; properly in the summary buffer.
1002 (let ((buffer (current-buffer)))
1005 (set-buffer rmail-buffer)
1006 (rmail-search regexp (- n)))
1007 (set-buffer buffer))))
1009 (defun rmail-summary-search (regexp &optional n)
1010 "Show message containing next match for REGEXP.
1011 Prefix argument gives repeat count; negative argument means search
1012 backwards (through earlier messages).
1013 Interactively, empty argument means use same regexp used last time."
1015 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1017 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1019 (if rmail-search-last-regexp
1020 (setq prompt (concat prompt
1022 rmail-search-last-regexp
1024 (setq regexp (read-string prompt))
1025 (cond ((not (equal regexp ""))
1026 (setq rmail-search-last-regexp regexp))
1027 ((not rmail-search-last-regexp)
1028 (error "No previous Rmail search string")))
1029 (list rmail-search-last-regexp
1030 (prefix-numeric-value current-prefix-arg))))
1031 ;; Don't use save-excursion because that prevents point from moving
1032 ;; properly in the summary buffer.
1033 (let ((buffer (current-buffer)))
1036 (set-buffer rmail-buffer)
1037 (rmail-search regexp n))
1038 (set-buffer buffer))))
1040 (defun rmail-summary-toggle-header ()
1041 "Show original message header if pruned header currently shown, or vice versa."
1044 (set-buffer rmail-buffer)
1045 (rmail-toggle-header)))
1047 (defun rmail-summary-add-label (label)
1048 "Add LABEL to labels associated with current Rmail message.
1049 Completion is performed over known labels when reading."
1050 (interactive (list (save-excursion
1051 (set-buffer rmail-buffer)
1052 (rmail-read-label "Add label"))))
1054 (set-buffer rmail-buffer)
1055 (rmail-add-label label)))
1057 (defun rmail-summary-kill-label (label)
1058 "Remove LABEL from labels associated with current Rmail message.
1059 Completion is performed over known labels when reading."
1060 (interactive (list (save-excursion
1061 (set-buffer rmail-buffer)
1062 (rmail-read-label "Kill label"))))
1064 (set-buffer rmail-buffer)
1065 (rmail-set-label label nil)))
1067 ;;;; *** Rmail Summary Mailing Commands ***
1069 (defun rmail-summary-mail ()
1070 "Send mail in another window.
1071 While composing the message, use \\[mail-yank-original] to yank the
1072 original message into it."
1074 (rmail-start-mail nil nil nil nil nil rmail-buffer)
1075 (use-local-map (copy-keymap (current-local-map)))
1076 (define-key (current-local-map)
1077 "\C-c\C-c" 'rmail-summary-send-and-exit))
1079 (defun rmail-summary-continue ()
1080 "Continue composing outgoing message previously being composed."
1082 (rmail-start-mail t))
1084 (defun rmail-summary-reply (just-sender)
1085 "Reply to the current message.
1086 Normally include CC: to all other recipients of original message;
1087 prefix argument means ignore them. While composing the reply,
1088 use \\[mail-yank-original] to yank the original message into it."
1090 (set-buffer rmail-buffer)
1091 (rmail-reply just-sender)
1092 (use-local-map (copy-keymap (current-local-map)))
1093 (define-key (current-local-map)
1094 "\C-c\C-c" 'rmail-summary-send-and-exit))
1096 (defun rmail-summary-retry-failure ()
1097 "Edit a mail message which is based on the contents of the current message.
1098 For a message rejected by the mail system, extract the interesting headers and
1099 the body of the original message; otherwise copy the current message."
1101 (set-buffer rmail-buffer)
1102 (rmail-retry-failure)
1103 (use-local-map (copy-keymap (current-local-map)))
1104 (define-key (current-local-map)
1105 "\C-c\C-c" 'rmail-summary-send-and-exit))
1107 (defun rmail-summary-send-and-exit ()
1108 "Send mail reply and return to summary buffer."
1110 (mail-send-and-exit t))
1112 (defun rmail-summary-forward (resend)
1113 "Forward the current message to another user.
1114 With prefix argument, \"resend\" the message instead of forwarding it;
1115 see the documentation of `rmail-resend'."
1118 (set-buffer rmail-buffer)
1119 (rmail-forward resend)
1120 (use-local-map (copy-keymap (current-local-map)))
1121 (define-key (current-local-map)
1122 "\C-c\C-c" 'rmail-summary-send-and-exit)))
1124 ;; Summary output commands.
1126 (defun rmail-summary-output-to-rmail-file (&optional file-name)
1127 "Append the current message to an Rmail file named FILE-NAME.
1128 If the file does not exist, ask if it should be created.
1129 If file is being visited, the message is appended to the Emacs
1130 buffer visiting that file."
1133 (set-buffer rmail-buffer)
1134 (let ((rmail-delete-after-output nil))
1136 (rmail-output-to-rmail-file file-name)
1137 (call-interactively 'rmail-output-to-rmail-file))))
1138 (if rmail-delete-after-output
1139 (rmail-summary-delete-forward nil)))
1141 (defun rmail-summary-output-menu ()
1142 "Output current message to another Rmail file, chosen with a menu.
1143 Also set the default for subsequent \\[rmail-output-to-rmail-file] commands.
1144 The variables `rmail-secondary-file-directory' and
1145 `rmail-secondary-file-regexp' control which files are offered in the menu."
1148 (set-buffer rmail-buffer)
1149 (let ((rmail-delete-after-output nil))
1150 (call-interactively 'rmail-output-menu)))
1151 (if rmail-delete-after-output
1152 (rmail-summary-delete-forward nil)))
1154 (defun rmail-summary-output ()
1155 "Append this message to Unix mail file named FILE-NAME."
1158 (set-buffer rmail-buffer)
1159 (let ((rmail-delete-after-output nil))
1160 (call-interactively 'rmail-output)))
1161 (if rmail-delete-after-output
1162 (rmail-summary-delete-forward nil)))
1164 (defun rmail-summary-construct-io-menu ()
1165 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1168 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1169 (cons "Input Rmail File"
1170 (rmail-list-to-menu "Input Rmail File"
1172 'rmail-summary-input)))
1173 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1174 (cons "Output Rmail File"
1175 (rmail-list-to-menu "Output Rmail File"
1177 'rmail-summary-output-to-rmail-file)))))))
1180 ;; Sorting messages in Rmail Summary buffer.
1182 (defun rmail-summary-sort-by-date (reverse)
1183 "Sort messages of current Rmail summary by date.
1184 If prefix argument REVERSE is non-nil, sort them in reverse order."
1186 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1188 (defun rmail-summary-sort-by-subject (reverse)
1189 "Sort messages of current Rmail summary by subject.
1190 If prefix argument REVERSE is non-nil, sort them in reverse order."
1192 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1194 (defun rmail-summary-sort-by-author (reverse)
1195 "Sort messages of current Rmail summary by author.
1196 If prefix argument REVERSE is non-nil, sort them in reverse order."
1198 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1200 (defun rmail-summary-sort-by-recipient (reverse)
1201 "Sort messages of current Rmail summary by recipient.
1202 If prefix argument REVERSE is non-nil, sort them in reverse order."
1204 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1206 (defun rmail-summary-sort-by-correspondent (reverse)
1207 "Sort messages of current Rmail summary by other correspondent.
1208 If prefix argument REVERSE is non-nil, sort them in reverse order."
1210 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1212 (defun rmail-summary-sort-by-lines (reverse)
1213 "Sort messages of current Rmail summary by lines of the message.
1214 If prefix argument REVERSE is non-nil, sort them in reverse order."
1216 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1218 (defun rmail-summary-sort-by-keywords (reverse labels)
1219 "Sort messages of current Rmail summary by keywords.
1220 If prefix argument REVERSE is non-nil, sort them in reverse order.
1221 KEYWORDS is a comma-separated list of labels."
1222 (interactive "P\nsSort by labels: ")
1223 (rmail-sort-from-summary
1224 (function (lambda (reverse)
1225 (rmail-sort-by-keywords reverse labels)))
1228 (defun rmail-sort-from-summary (sortfun reverse)
1229 "Sort Rmail messages from Summary buffer and update it after sorting."
1230 (require 'rmailsort)
1231 (let ((selwin (selected-window)))
1233 (progn (pop-to-buffer rmail-buffer)
1234 (funcall sortfun reverse))
1235 (select-window selwin))))
1237 ;;; rmailsum.el ends here