1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; Extended by Bob Weiner of Motorola
29 ;; Provided all commands from rmail-mode in rmail-summary-mode and made key
30 ;; bindings in both modes wholly compatible.
36 ;; For rmail-select-summary
40 (defcustom rmail-summary-scroll-between-messages t
41 "*Non-nil means Rmail summary scroll commands move between messages."
43 :group
'rmail-summary
)
46 (defcustom rmail-summary-line-count-flag t
47 "*Non-nil means Rmail summary should show the number of lines in each message."
49 :group
'rmail-summary
)
51 (defvar rmail-summary-font-lock-keywords
52 '(("^.....D.*" . font-lock-string-face
) ; Deleted.
53 ("^.....-.*" . font-lock-type-face
) ; Unread.
54 ;; Neither of the below will be highlighted if either of the above are:
55 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face
) ; Date.
56 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face
)) ; Labels.
57 "Additional expressions to highlight in Rmail Summary mode.")
59 (defvar rmail-summary-redo
60 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
62 (defvar rmail-summary-overlay nil
)
63 (put 'rmail-summary-overlay
'permanent-local t
)
65 (defvar rmail-summary-mode-map nil
)
67 ;; Entry points for making a summary buffer.
69 ;; Regenerate the contents of the summary
70 ;; using the same selection criterion as last time.
71 ;; M-x revert-buffer in a summary buffer calls this function.
72 (defun rmail-update-summary (&rest ignore
)
73 (apply (car rmail-summary-redo
) (cdr rmail-summary-redo
)))
76 (defun rmail-summary ()
77 "Display a summary of all messages, one line per message."
79 (rmail-new-summary "All" '(rmail-summary) nil
))
82 (defun rmail-summary-by-labels (labels)
83 "Display a summary of all messages with one or more LABELS.
84 LABELS should be a string containing the desired labels, separated by commas."
85 (interactive "sLabels to summarize by: ")
86 (if (string= labels
"")
87 (setq labels
(or rmail-last-multi-labels
88 (error "No label specified"))))
89 (setq rmail-last-multi-labels labels
)
90 (rmail-new-summary (concat "labels " labels
)
91 (list 'rmail-summary-by-labels labels
)
92 'rmail-message-labels-p
93 (concat ", \\(" (mail-comma-list-regexp labels
) "\\),")))
96 (defun rmail-summary-by-recipients (recipients &optional primary-only
)
97 "Display a summary of all messages with the given RECIPIENTS.
98 Normally checks the To, From and Cc fields of headers;
99 but if PRIMARY-ONLY is non-nil (prefix arg given),
100 only look in the To and From fields.
101 RECIPIENTS is a string of regexps separated by commas."
102 (interactive "sRecipients to summarize by: \nP")
104 (concat "recipients " recipients
)
105 (list 'rmail-summary-by-recipients recipients primary-only
)
106 'rmail-message-recipients-p
107 (mail-comma-list-regexp recipients
) primary-only
))
110 (defun rmail-summary-by-regexp (regexp)
111 "Display a summary of all messages according to regexp REGEXP.
112 If the regular expression is found in the header of the message
113 \(including in the date and other lines, as well as the subject line),
114 Emacs will list the header line in the RMAIL-summary."
115 (interactive "sRegexp to summarize by: ")
116 (if (string= regexp
"")
117 (setq regexp
(or rmail-last-regexp
118 (error "No regexp specified"))))
119 (setq rmail-last-regexp regexp
)
120 (rmail-new-summary (concat "regexp " regexp
)
121 (list 'rmail-summary-by-regexp regexp
)
122 'rmail-message-regexp-p
125 ;; rmail-summary-by-topic
126 ;; 1989 R.A. Schnitzler
129 (defun rmail-summary-by-topic (subject &optional whole-message
)
130 "Display a summary of all messages with the given SUBJECT.
131 Normally checks the Subject field of headers;
132 but if WHOLE-MESSAGE is non-nil (prefix arg given),
133 look in the whole message.
134 SUBJECT is a string of regexps separated by commas."
135 (interactive "sTopics to summarize by: \nP")
137 (concat "about " subject
)
138 (list 'rmail-summary-by-topic subject whole-message
)
139 'rmail-message-subject-p
140 (mail-comma-list-regexp subject
) whole-message
))
142 (defun rmail-message-subject-p (msg subject
&optional whole-message
)
144 (goto-char (rmail-msgbeg msg
))
145 (search-forward "\n*** EOOH ***\n" (rmail-msgend msg
) 'move
)
148 (progn (search-forward (if whole-message
"\^_" "\n\n")) (point)))
149 (goto-char (point-min))
150 (if whole-message
(re-search-forward subject nil t
)
151 (string-match subject
(let ((subj (mail-fetch-field "Subject")))
153 (funcall rmail-summary-line-decoder subj
)
157 (defun rmail-summary-by-senders (senders)
158 "Display a summary of all messages with the given SENDERS.
159 SENDERS is a string of names separated by commas."
160 (interactive "sSenders to summarize by: ")
162 (concat "senders " senders
)
163 (list 'rmail-summary-by-senders senders
)
164 'rmail-message-senders-p
165 (mail-comma-list-regexp senders
)))
167 (defun rmail-message-senders-p (msg senders
)
169 (goto-char (rmail-msgbeg msg
))
170 (search-forward "\n*** EOOH ***\n")
171 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
172 (string-match senders
(or (mail-fetch-field "From") ""))))
174 ;; General making of a summary buffer.
176 (defvar rmail-summary-symbol-number
0)
178 (defvar rmail-new-summary-line-count
)
180 (defun rmail-new-summary (description redo-form function
&rest args
)
181 "Create a summary of selected messages.
182 DESCRIPTION makes part of the mode line of the summary buffer.
183 For each message, FUNCTION is applied to the message number and ARGS...
184 and if the result is non-nil, that message is included.
185 nil for FUNCTION means all messages."
186 (message "Computing summary lines...")
187 (let (sumbuf mesg was-in-summary
)
189 ;; Go to the Rmail buffer.
190 (if (eq major-mode
'rmail-summary-mode
)
191 (setq was-in-summary t
))
192 (set-buffer rmail-buffer
)
193 ;; Find its summary buffer, or make one.
195 (if (and rmail-summary-buffer
196 (buffer-name rmail-summary-buffer
))
198 (generate-new-buffer (concat (buffer-name) "-summary"))))
199 (setq mesg rmail-current-message
)
200 ;; Filter the messages; make or get their summary lines.
201 (let ((summary-msgs ())
202 (rmail-new-summary-line-count 0))
204 (buffer-read-only nil
)
205 (old-min (point-min-marker))
206 (old-max (point-max-marker)))
207 ;; Can't use save-restriction here; that doesn't work if we
208 ;; plan to modify text outside the original restriction.
211 (goto-char (point-min))
212 (while (>= rmail-total-messages msgnum
)
213 (if (or (null function
)
214 (apply function
(cons msgnum args
)))
216 (cons (cons msgnum
(rmail-make-summary-line msgnum
))
218 (setq msgnum
(1+ msgnum
)))
219 (setq summary-msgs
(nreverse summary-msgs
)))
220 (narrow-to-region old-min old-max
))
221 ;; Temporarily, while summary buffer is unfinished,
222 ;; we "don't have" a summary.
223 (setq rmail-summary-buffer nil
)
224 (if rmail-enable-mime
225 (with-current-buffer rmail-view-buffer
226 (setq rmail-summary-buffer nil
)))
228 (let ((rbuf (current-buffer))
229 (vbuf rmail-view-buffer
)
230 (total rmail-total-messages
))
232 ;; Set up the summary buffer's contents.
233 (let ((buffer-read-only nil
))
236 (princ (cdr (car summary-msgs
)) sumbuf
)
237 (setq summary-msgs
(cdr summary-msgs
)))
238 (goto-char (point-min)))
239 ;; Set up the rest of its state and local variables.
240 (setq buffer-read-only t
)
242 (make-local-variable 'minor-mode-alist
)
243 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
244 (setq rmail-buffer rbuf
245 rmail-view-buffer vbuf
246 rmail-summary-redo redo-form
247 rmail-total-messages total
))))
248 (setq rmail-summary-buffer sumbuf
))
249 ;; Now display the summary buffer and go to the right place in it.
252 (if (and (one-window-p)
253 pop-up-windows
(not pop-up-frames
))
254 ;; If there is just one window, put the summary on the top.
256 (split-window (selected-window) rmail-summary-window-size
)
257 (select-window (next-window (frame-first-window)))
258 (pop-to-buffer sumbuf
)
259 ;; If pop-to-buffer did not use that window, delete that
260 ;; window. (This can happen if it uses another frame.)
261 (if (not (eq sumbuf
(window-buffer (frame-first-window))))
262 (delete-other-windows)))
263 (pop-to-buffer sumbuf
))
264 (set-buffer rmail-buffer
)
265 ;; This is how rmail makes the summary buffer reappear.
266 ;; We do this here to make the window the proper size.
267 (rmail-select-summary nil
)
268 (set-buffer rmail-summary-buffer
)))
269 (rmail-summary-goto-msg mesg t t
)
270 (rmail-summary-construct-io-menu)
271 (message "Computing summary lines...done")))
273 ;; Low levels of generating a summary.
275 (defun rmail-make-summary-line (msg)
276 (let ((line (or (aref rmail-summary-vector
(1- msg
))
278 (setq rmail-new-summary-line-count
279 (1+ rmail-new-summary-line-count
))
280 (if (zerop (% rmail-new-summary-line-count
10))
281 (message "Computing summary lines...%d"
282 rmail-new-summary-line-count
))
283 (rmail-make-summary-line-1 msg
)))))
284 ;; Fix up the part of the summary that says "deleted" or "unseen".
286 (if (rmail-message-deleted-p msg
) ?\D
287 (if (= ?
0 (char-after (+ 3 (rmail-msgbeg msg
))))
292 (defcustom rmail-summary-line-decoder
(function identity
)
293 "*Function to decode summary-line.
295 By default, `identity' is set."
297 :group
'rmail-summary
)
299 (defun rmail-make-summary-line-1 (msg)
300 (goto-char (rmail-msgbeg msg
))
301 (let* ((lim (save-excursion (forward-line 2) (point)))
307 ; (if (save-excursion (re-search-forward ",answered," lim t))
309 ; (if (save-excursion (re-search-forward ",filed," lim t))
311 (if (progn (search-forward ",,") (eolp))
314 (buffer-substring (point)
324 (if (looking-at "Summary-line: ")
326 (goto-char (match-end 0))
328 (buffer-substring (point)
329 (progn (forward-line 1) (point)))))))))
330 ;; Obsolete status lines lacking a # should be flushed.
332 (not (string-match "#" line
))
334 (delete-region (point)
335 (progn (forward-line -
1) (point)))
337 ;; If we didn't get a valid status line from the message,
338 ;; make a new one and put it in the message.
340 (let* ((case-fold-search t
)
341 (next (rmail-msgend msg
))
342 (beg (if (progn (goto-char (rmail-msgbeg msg
))
343 (search-forward "\n*** EOOH ***\n" next t
))
347 (end (progn (search-forward "\n\n" nil t
) (point))))
349 (narrow-to-region beg end
)
351 (setq line
(rmail-make-basic-summary-line)))
352 (goto-char (rmail-msgbeg msg
))
354 (insert "Summary-line: " line
)))
355 (setq pos
(string-match "#" line
))
356 (aset rmail-summary-vector
(1- msg
)
357 (funcall rmail-summary-line-decoder
358 (concat (format "%5d " msg
)
359 (substring line
0 pos
)
361 (substring line
(1+ pos
)))))
365 (defcustom rmail-user-mail-address-regexp nil
366 "*Regexp matching user mail addresses.
367 If non-nil, this variable is used to identify the correspondent
368 when receiving new mail. If it matches the address of the sender,
369 the recipient is taken as correspondent of a mail.
370 If nil \(default value\), your `user-login-name' and `user-mail-address'
371 are used to exclude yourself as correspondent.
373 Usually you don't have to set this variable, except if you collect mails
374 sent by you under different user names.
375 Then it should be a regexp matching your mail addresses.
377 Setting this variable has an effect only before reading a mail."
378 :type
'(choice (const :tag
"None" nil
) regexp
)
379 :group
'rmail-retrieve
382 (defun rmail-make-basic-summary-line ()
383 (goto-char (point-min))
384 (concat (save-excursion
385 (if (not (re-search-forward "^Date:" nil t
))
387 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
388 (save-excursion (end-of-line) (point)) t
)
390 (string-to-number (buffer-substring
394 (match-beginning 4) (match-end 4))))
395 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
396 (save-excursion (end-of-line) (point)) t
)
398 (string-to-number (buffer-substring
402 (match-beginning 2) (match-end 2))))
403 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
404 (save-excursion (end-of-line) (point)) t
)
407 (match-beginning 2) (match-end 2))
409 (match-beginning 3) (match-end 3))
411 (match-beginning 4) (match-end 4))))
415 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
416 (mail-strip-quoted-names
419 ;; Get all the lines of the From field
420 ;; so that we get a whole comment if there is one,
421 ;; so that mail-strip-quoted-names can discard it.
422 (let ((opoint (point)))
423 (while (progn (forward-line 1)
424 (looking-at "[ \t]")))
425 ;; Back up over newline, then trailing spaces or tabs
427 (skip-chars-backward " \t")
432 (or rmail-user-mail-address-regexp
434 (regexp-quote (user-login-name))
437 ;; Don't lose if run from init file
438 ;; where user-mail-address is not
440 (or user-mail-address
441 (concat (user-login-name) "@"
442 (or mail-host-address
446 ;; No From field, or it's this user.
448 (goto-char (point-min))
449 (if (not (re-search-forward "^To:[ \t]*" nil t
))
453 (mail-strip-quoted-names
457 (skip-chars-backward " \t")
461 (setq len
(length from
))
462 (setq mch
(string-match "[@%]" from
))
464 (if (or (not mch
) (<= len
25))
465 (substring from
(max 0 (- len
25)))
467 (setq lo
(cond ((< (- mch
14) 0) 0)
471 (min len
(+ lo
25))))))))
472 (if rmail-summary-line-count-flag
476 (let ((beg (rmail-msgbeg msgnum
))
477 (end (rmail-msgend msgnum
))
481 ;; Count only lines in the reformatted header,
482 ;; if we have reformatted it.
483 (search-forward "\n*** EOOH ***\n" end t
)
484 (setq lines
(count-lines (point) end
)))
486 ((<= lines
9) " [%d]")
487 ((<= lines
99) " [%d]")
488 ((<= lines
999) " [%3d]")
492 " #" ;The # is part of the format.
493 (if (re-search-forward "^Subject:" nil t
)
494 (progn (skip-chars-forward " \t")
495 (buffer-substring (point)
498 (re-search-forward "[\n][\n]+" nil t
)
499 (buffer-substring (point) (progn (end-of-line) (point))))
502 ;; Simple motion in a summary buffer.
504 (defun rmail-summary-next-all (&optional number
)
506 (forward-line (if number number
1))
507 ;; It doesn't look nice to move forward past the last message line.
508 (and (eobp) (> number
0)
510 (display-buffer rmail-buffer
))
512 (defun rmail-summary-previous-all (&optional number
)
514 (forward-line (- (if number number
1)))
515 ;; It doesn't look nice to move forward past the last message line.
516 (and (eobp) (< number
0)
518 (display-buffer rmail-buffer
))
520 (defun rmail-summary-next-msg (&optional number
)
521 "Display next non-deleted msg from rmail file.
522 With optional prefix argument NUMBER, moves forward this number of non-deleted
523 messages, or backward if NUMBER is negative."
526 (and (> number
0) (end-of-line))
527 (let ((count (if (< number
0) (- number
) number
))
528 (search (if (> number
0) 're-search-forward
're-search-backward
))
529 (non-del-msg-found nil
))
530 (while (and (> count
0) (setq non-del-msg-found
531 (or (funcall search
"^....[^D]" nil t
)
533 (setq count
(1- count
))))
535 (display-buffer rmail-view-buffer
))
537 (defun rmail-summary-previous-msg (&optional number
)
538 "Display previous non-deleted msg from rmail file.
539 With optional prefix argument NUMBER, moves backward this number of
540 non-deleted messages."
542 (rmail-summary-next-msg (- (if number number
1))))
544 (defun rmail-summary-next-labeled-message (n labels
)
545 "Show next message with LABELS. Defaults to last labels used.
546 With prefix argument N moves forward N messages with these labels."
547 (interactive "p\nsMove to next msg with labels: ")
550 (set-buffer rmail-buffer
)
551 (rmail-next-labeled-message n labels
)
552 (setq msg rmail-current-message
))
553 (rmail-summary-goto-msg msg
)))
555 (defun rmail-summary-previous-labeled-message (n labels
)
556 "Show previous message with LABELS. Defaults to last labels used.
557 With prefix argument N moves backward N messages with these labels."
558 (interactive "p\nsMove to previous msg with labels: ")
561 (set-buffer rmail-buffer
)
562 (rmail-previous-labeled-message n labels
)
563 (setq msg rmail-current-message
))
564 (rmail-summary-goto-msg msg
)))
566 (defun rmail-summary-next-same-subject (n)
567 "Go to the next message in the summary having the same subject.
568 With prefix argument N, do this N times.
569 If N is negative, go backwards."
571 (let (subject search-regexp i found
574 (set-buffer rmail-buffer
)
575 (setq subject
(mail-fetch-field "Subject"))
576 (setq i rmail-current-message
))
577 (if (string-match "Re:[ \t]*" subject
)
578 (setq subject
(substring subject
(match-end 0))))
579 (setq search-regexp
(concat "^Subject: *\\(Re: *\\)?"
580 (regexp-quote subject
)
588 (while (and (not done
)
592 ;; Advance thru summary.
593 (forward-line (if forward
1 -
1))
594 ;; Get msg number of this line.
595 (setq i
(string-to-number
596 (buffer-substring (point)
597 (min (point-max) (+ 6 (point))))))
598 ;; See if that msg has desired subject.
600 (set-buffer rmail-buffer
)
603 (goto-char (rmail-msgbeg i
))
604 (search-forward "\n*** EOOH ***\n")
605 (let ((beg (point)) end
)
606 (search-forward "\n\n")
609 (setq done
(re-search-forward search-regexp end t
))))))
610 (if done
(setq found i
)))
611 (setq n
(if forward
(1- n
) (1+ n
)))))
613 (rmail-summary-goto-msg found
)
614 (error "No %s message with same subject"
615 (if forward
"following" "previous")))))
617 (defun rmail-summary-previous-same-subject (n)
618 "Go to the previous message in the summary having the same subject.
619 With prefix argument N, do this N times.
620 If N is negative, go forwards instead."
622 (rmail-summary-next-same-subject (- n
)))
624 ;; Delete and undelete summary commands.
626 (defun rmail-summary-delete-forward (&optional count
)
627 "Delete this message and move to next nondeleted one.
628 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
629 A prefix argument serves as a repeat count;
630 a negative argument means to delete and move backward."
632 (unless (numberp count
) (setq count
1))
634 (backward (< count
0)))
636 (rmail-summary-goto-msg)
637 (with-current-buffer rmail-buffer
638 (rmail-delete-message)
639 (setq del-msg rmail-current-message
))
640 (rmail-summary-mark-deleted del-msg
)
641 (while (and (not (if backward
(bobp) (eobp)))
642 (save-excursion (beginning-of-line)
643 (looking-at " *[0-9]+D")))
644 (forward-line (if backward -
1 1)))
645 ;; It looks ugly to move to the empty line at end of buffer.
646 (and (eobp) (not backward
)
649 (if (> count
0) (1- count
) (1+ count
))))))
651 (defun rmail-summary-delete-backward (&optional count
)
652 "Delete this message and move to previous nondeleted one.
653 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
654 A prefix argument serves as a repeat count;
655 a negative argument means to delete and move forward."
657 (rmail-summary-delete-forward (- count
)))
659 (defun rmail-summary-mark-deleted (&optional n undel
)
660 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
661 (and n
(rmail-summary-goto-msg n t t
))
663 (not (overlay-get rmail-summary-overlay
'face
))
664 (let ((buffer-read-only nil
))
665 (skip-chars-forward " ")
666 (skip-chars-forward "[0-9]")
669 (progn (delete-char 1) (insert " ")))
674 (defun rmail-summary-mark-undeleted (n)
675 (rmail-summary-mark-deleted n t
))
677 (defun rmail-summary-deleted-p (&optional n
)
679 (and n
(rmail-summary-goto-msg n nil t
))
680 (skip-chars-forward " ")
681 (skip-chars-forward "[0-9]")
684 (defun rmail-summary-undelete (&optional arg
)
685 "Undelete current message.
686 Optional prefix ARG means undelete ARG previous messages."
689 (rmail-summary-undelete-many arg
)
690 (let ((buffer-read-only nil
)
693 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
694 (replace-match "\\1 ")
695 (rmail-summary-goto-msg)
696 (if rmail-enable-mime
697 (set-buffer rmail-buffer
)
698 (pop-to-buffer rmail-buffer
))
699 (and (rmail-message-deleted-p rmail-current-message
)
700 (rmail-undelete-previous-message))
701 (if rmail-enable-mime
702 (pop-to-buffer rmail-view-buffer
))
703 (pop-to-buffer rmail-summary-buffer
))
704 (t (goto-char opoint
))))))
706 (defun rmail-summary-undelete-many (&optional n
)
707 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
710 (set-buffer rmail-buffer
)
711 (let* ((init-msg (if n rmail-current-message rmail-total-messages
))
712 (rmail-current-message init-msg
)
713 (n (or n rmail-total-messages
))
715 (while (and (> rmail-current-message
0)
717 (if (rmail-message-deleted-p rmail-current-message
)
718 (progn (rmail-set-attribute "deleted" nil
)
719 (setq msgs-undeled
(1+ msgs-undeled
))))
720 (setq rmail-current-message
(1- rmail-current-message
)))
721 (set-buffer rmail-summary-buffer
)
722 (setq rmail-current-message init-msg msgs-undeled
0)
723 (while (and (> rmail-current-message
0)
725 (if (rmail-summary-deleted-p rmail-current-message
)
726 (progn (rmail-summary-mark-undeleted rmail-current-message
)
727 (setq msgs-undeled
(1+ msgs-undeled
))))
728 (setq rmail-current-message
(1- rmail-current-message
))))
729 (rmail-summary-goto-msg)))
731 ;; Rmail Summary mode is suitable only for specially formatted data.
732 (put 'rmail-summary-mode
'mode-class
'special
)
734 (defun rmail-summary-mode ()
735 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
736 As commands are issued in the summary buffer, they are applied to the
737 corresponding mail messages in the rmail buffer.
739 All normal editing commands are turned off.
740 Instead, nearly all the Rmail mode commands are available,
741 though many of them move only among the messages in the summary.
743 These additional commands exist:
745 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
746 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
748 Commands for sorting the summary:
750 \\[rmail-summary-sort-by-date] Sort by date.
751 \\[rmail-summary-sort-by-subject] Sort by subject.
752 \\[rmail-summary-sort-by-author] Sort by author.
753 \\[rmail-summary-sort-by-recipient] Sort by recipient.
754 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
755 \\[rmail-summary-sort-by-lines] Sort by lines.
756 \\[rmail-summary-sort-by-labels] Sort by labels."
758 (kill-all-local-variables)
759 (setq major-mode
'rmail-summary-mode
)
760 (setq mode-name
"RMAIL Summary")
761 (setq truncate-lines t
)
762 (setq buffer-read-only t
)
763 (set-syntax-table text-mode-syntax-table
)
764 (make-local-variable 'rmail-buffer
)
765 (make-local-variable 'rmail-view-buffer
)
766 (make-local-variable 'rmail-total-messages
)
767 (make-local-variable 'rmail-current-message
)
768 (setq rmail-current-message nil
)
769 (make-local-variable 'rmail-summary-redo
)
770 (setq rmail-summary-redo nil
)
771 (make-local-variable 'revert-buffer-function
)
772 (make-local-variable 'font-lock-defaults
)
773 (setq font-lock-defaults
'(rmail-summary-font-lock-keywords t
))
774 (rmail-summary-enable)
775 (run-mode-hooks 'rmail-summary-mode-hook
))
777 ;; Summary features need to be disabled during edit mode.
778 (defun rmail-summary-disable ()
779 (use-local-map text-mode-map
)
780 (remove-hook 'post-command-hook
'rmail-summary-rmail-update t
)
781 (setq revert-buffer-function nil
))
783 (defun rmail-summary-enable ()
784 (use-local-map rmail-summary-mode-map
)
785 (add-hook 'post-command-hook
'rmail-summary-rmail-update nil t
)
786 (setq revert-buffer-function
'rmail-update-summary
))
788 (defvar rmail-summary-put-back-unseen nil
789 "Used for communicating between calls to `rmail-summary-rmail-update'.
790 If it moves to a message within an Incremental Search, and removes
791 the `unseen' attribute from that message, it sets this flag
792 so that if the next motion between messages is in the same Incremental
793 Search, the `unseen' attribute is restored.")
795 ;; Show in Rmail the message described by the summary line that point is on,
796 ;; but only if the Rmail buffer is already visible.
797 ;; This is a post-command-hook in summary buffers.
798 (defun rmail-summary-rmail-update ()
799 (let (buffer-read-only)
801 ;; If at end of buffer, pretend we are on the last text line.
805 (skip-chars-forward " ")
806 (let ((msg-num (string-to-number (buffer-substring
808 (progn (skip-chars-forward "0-9")
810 ;; Always leave `unseen' removed
811 ;; if we get out of isearch mode.
812 ;; Don't let a subsequent isearch restore that `unseen'.
813 (if (not isearch-mode
)
814 (setq rmail-summary-put-back-unseen nil
))
816 (or (eq rmail-current-message msg-num
)
817 (let ((window (get-buffer-window rmail-view-buffer t
))
818 (owin (selected-window)))
821 (set-buffer rmail-buffer
)
822 ;; If we first saw the previous message in this search,
823 ;; and we have gone to a different message while searching,
824 ;; put back `unseen' on the former one.
825 (if rmail-summary-put-back-unseen
826 (rmail-set-attribute "unseen" t
827 rmail-current-message
))
828 ;; Arrange to do that later, for the new current message,
829 ;; if it still has `unseen'.
830 (setq rmail-summary-put-back-unseen
831 (rmail-message-labels-p msg-num
", ?\\(unseen\\),")))
832 (setq rmail-summary-put-back-unseen nil
))
834 ;; Go to the desired message.
835 (setq rmail-current-message msg-num
)
837 ;; Update the summary to show the message has been seen.
838 (if (= (following-char) ?-
)
844 ;; Using save-window-excursion would cause the new value
845 ;; of point to get lost.
848 (select-window window
)
849 (rmail-show-message msg-num t
))
850 (select-window owin
))
851 (if (buffer-name rmail-buffer
)
853 (set-buffer rmail-buffer
)
854 (rmail-show-message msg-num t
))))))
855 (rmail-summary-update-highlight nil
)))))
857 (if rmail-summary-mode-map
859 (setq rmail-summary-mode-map
(make-keymap))
860 (suppress-keymap rmail-summary-mode-map
)
862 (define-key rmail-summary-mode-map
[mouse-2
] 'rmail-summary-mouse-goto-message
)
863 (define-key rmail-summary-mode-map
"a" 'rmail-summary-add-label
)
864 (define-key rmail-summary-mode-map
"b" 'rmail-summary-bury
)
865 (define-key rmail-summary-mode-map
"c" 'rmail-summary-continue
)
866 (define-key rmail-summary-mode-map
"d" 'rmail-summary-delete-forward
)
867 (define-key rmail-summary-mode-map
"\C-d" 'rmail-summary-delete-backward
)
868 (define-key rmail-summary-mode-map
"e" 'rmail-summary-edit-current-message
)
869 (define-key rmail-summary-mode-map
"f" 'rmail-summary-forward
)
870 (define-key rmail-summary-mode-map
"g" 'rmail-summary-get-new-mail
)
871 (define-key rmail-summary-mode-map
"h" 'rmail-summary
)
872 (define-key rmail-summary-mode-map
"i" 'rmail-summary-input
)
873 (define-key rmail-summary-mode-map
"j" 'rmail-summary-goto-msg
)
874 (define-key rmail-summary-mode-map
"\C-m" 'rmail-summary-goto-msg
)
875 (define-key rmail-summary-mode-map
"k" 'rmail-summary-kill-label
)
876 (define-key rmail-summary-mode-map
"l" 'rmail-summary-by-labels
)
877 (define-key rmail-summary-mode-map
"\e\C-h" 'rmail-summary
)
878 (define-key rmail-summary-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
879 (define-key rmail-summary-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
880 (define-key rmail-summary-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
881 (define-key rmail-summary-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
882 (define-key rmail-summary-mode-map
"m" 'rmail-summary-mail
)
883 (define-key rmail-summary-mode-map
"\M-m" 'rmail-summary-retry-failure
)
884 (define-key rmail-summary-mode-map
"n" 'rmail-summary-next-msg
)
885 (define-key rmail-summary-mode-map
"\en" 'rmail-summary-next-all
)
886 (define-key rmail-summary-mode-map
"\e\C-n" 'rmail-summary-next-labeled-message
)
887 (define-key rmail-summary-mode-map
"o" 'rmail-summary-output-to-rmail-file
)
888 (define-key rmail-summary-mode-map
"\C-o" 'rmail-summary-output
)
889 (define-key rmail-summary-mode-map
"p" 'rmail-summary-previous-msg
)
890 (define-key rmail-summary-mode-map
"\ep" 'rmail-summary-previous-all
)
891 (define-key rmail-summary-mode-map
"\e\C-p" 'rmail-summary-previous-labeled-message
)
892 (define-key rmail-summary-mode-map
"q" 'rmail-summary-quit
)
893 (define-key rmail-summary-mode-map
"Q" 'rmail-summary-wipe
)
894 (define-key rmail-summary-mode-map
"r" 'rmail-summary-reply
)
895 (define-key rmail-summary-mode-map
"s" 'rmail-summary-expunge-and-save
)
896 (define-key rmail-summary-mode-map
"\es" 'rmail-summary-search
)
897 (define-key rmail-summary-mode-map
"t" 'rmail-summary-toggle-header
)
898 (define-key rmail-summary-mode-map
"u" 'rmail-summary-undelete
)
899 (define-key rmail-summary-mode-map
"\M-u" 'rmail-summary-undelete-many
)
900 (define-key rmail-summary-mode-map
"x" 'rmail-summary-expunge
)
901 (define-key rmail-summary-mode-map
"w" 'rmail-summary-output-body
)
902 (define-key rmail-summary-mode-map
"." 'rmail-summary-beginning-of-message
)
903 (define-key rmail-summary-mode-map
"/" 'rmail-summary-end-of-message
)
904 (define-key rmail-summary-mode-map
"<" 'rmail-summary-first-message
)
905 (define-key rmail-summary-mode-map
">" 'rmail-summary-last-message
)
906 (define-key rmail-summary-mode-map
" " 'rmail-summary-scroll-msg-up
)
907 (define-key rmail-summary-mode-map
"\177" 'rmail-summary-scroll-msg-down
)
908 (define-key rmail-summary-mode-map
"?" 'describe-mode
)
909 (define-key rmail-summary-mode-map
"\C-c\C-n" 'rmail-summary-next-same-subject
)
910 (define-key rmail-summary-mode-map
"\C-c\C-p" 'rmail-summary-previous-same-subject
)
911 (define-key rmail-summary-mode-map
"\C-c\C-s\C-d"
912 'rmail-summary-sort-by-date
)
913 (define-key rmail-summary-mode-map
"\C-c\C-s\C-s"
914 'rmail-summary-sort-by-subject
)
915 (define-key rmail-summary-mode-map
"\C-c\C-s\C-a"
916 'rmail-summary-sort-by-author
)
917 (define-key rmail-summary-mode-map
"\C-c\C-s\C-r"
918 'rmail-summary-sort-by-recipient
)
919 (define-key rmail-summary-mode-map
"\C-c\C-s\C-c"
920 'rmail-summary-sort-by-correspondent
)
921 (define-key rmail-summary-mode-map
"\C-c\C-s\C-l"
922 'rmail-summary-sort-by-lines
)
923 (define-key rmail-summary-mode-map
"\C-c\C-s\C-k"
924 'rmail-summary-sort-by-labels
)
927 ;;; Menu bar bindings.
929 (define-key rmail-summary-mode-map
[menu-bar
] (make-sparse-keymap))
931 (define-key rmail-summary-mode-map
[menu-bar classify
]
932 (cons "Classify" (make-sparse-keymap "Classify")))
934 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
935 '("Output (Rmail Menu)..." . rmail-summary-output-menu
))
937 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
938 '("Input Rmail File (menu)..." . rmail-input-menu
))
940 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
943 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
946 (define-key rmail-summary-mode-map
[menu-bar classify output-body
]
947 '("Output (body)..." . rmail-summary-output-body
))
949 (define-key rmail-summary-mode-map
[menu-bar classify output-inbox
]
950 '("Output (inbox)..." . rmail-summary-output
))
952 (define-key rmail-summary-mode-map
[menu-bar classify output
]
953 '("Output (Rmail)..." . rmail-summary-output-to-rmail-file
))
955 (define-key rmail-summary-mode-map
[menu-bar classify kill-label
]
956 '("Kill Label..." . rmail-summary-kill-label
))
958 (define-key rmail-summary-mode-map
[menu-bar classify add-label
]
959 '("Add Label..." . rmail-summary-add-label
))
961 (define-key rmail-summary-mode-map
[menu-bar summary
]
962 (cons "Summary" (make-sparse-keymap "Summary")))
964 (define-key rmail-summary-mode-map
[menu-bar summary senders
]
965 '("By Senders..." . rmail-summary-by-senders
))
967 (define-key rmail-summary-mode-map
[menu-bar summary labels
]
968 '("By Labels..." . rmail-summary-by-labels
))
970 (define-key rmail-summary-mode-map
[menu-bar summary recipients
]
971 '("By Recipients..." . rmail-summary-by-recipients
))
973 (define-key rmail-summary-mode-map
[menu-bar summary topic
]
974 '("By Topic..." . rmail-summary-by-topic
))
976 (define-key rmail-summary-mode-map
[menu-bar summary regexp
]
977 '("By Regexp..." . rmail-summary-by-regexp
))
979 (define-key rmail-summary-mode-map
[menu-bar summary all
]
980 '("All" . rmail-summary
))
982 (define-key rmail-summary-mode-map
[menu-bar mail
]
983 (cons "Mail" (make-sparse-keymap "Mail")))
985 (define-key rmail-summary-mode-map
[menu-bar mail rmail-summary-get-new-mail
]
986 '("Get New Mail" . rmail-summary-get-new-mail
))
988 (define-key rmail-summary-mode-map
[menu-bar mail lambda
]
991 (define-key rmail-summary-mode-map
[menu-bar mail continue
]
992 '("Continue" . rmail-summary-continue
))
994 (define-key rmail-summary-mode-map
[menu-bar mail resend
]
995 '("Re-send..." . rmail-summary-resend
))
997 (define-key rmail-summary-mode-map
[menu-bar mail forward
]
998 '("Forward" . rmail-summary-forward
))
1000 (define-key rmail-summary-mode-map
[menu-bar mail retry
]
1001 '("Retry" . rmail-summary-retry-failure
))
1003 (define-key rmail-summary-mode-map
[menu-bar mail reply
]
1004 '("Reply" . rmail-summary-reply
))
1006 (define-key rmail-summary-mode-map
[menu-bar mail mail
]
1007 '("Mail" . rmail-summary-mail
))
1009 (define-key rmail-summary-mode-map
[menu-bar delete
]
1010 (cons "Delete" (make-sparse-keymap "Delete")))
1012 (define-key rmail-summary-mode-map
[menu-bar delete expunge
/save
]
1013 '("Expunge/Save" . rmail-summary-expunge-and-save
))
1015 (define-key rmail-summary-mode-map
[menu-bar delete expunge
]
1016 '("Expunge" . rmail-summary-expunge
))
1018 (define-key rmail-summary-mode-map
[menu-bar delete undelete
]
1019 '("Undelete" . rmail-summary-undelete
))
1021 (define-key rmail-summary-mode-map
[menu-bar delete delete
]
1022 '("Delete" . rmail-summary-delete-forward
))
1024 (define-key rmail-summary-mode-map
[menu-bar move
]
1025 (cons "Move" (make-sparse-keymap "Move")))
1027 (define-key rmail-summary-mode-map
[menu-bar move search-back
]
1028 '("Search Back..." . rmail-summary-search-backward
))
1030 (define-key rmail-summary-mode-map
[menu-bar move search
]
1031 '("Search..." . rmail-summary-search
))
1033 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1034 '("Previous Nondeleted" . rmail-summary-previous-msg
))
1036 (define-key rmail-summary-mode-map
[menu-bar move next
]
1037 '("Next Nondeleted" . rmail-summary-next-msg
))
1039 (define-key rmail-summary-mode-map
[menu-bar move last
]
1040 '("Last" . rmail-summary-last-message
))
1042 (define-key rmail-summary-mode-map
[menu-bar move first
]
1043 '("First" . rmail-summary-first-message
))
1045 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1046 '("Previous" . rmail-summary-previous-all
))
1048 (define-key rmail-summary-mode-map
[menu-bar move next
]
1049 '("Next" . rmail-summary-next-all
))
1051 (defun rmail-summary-mouse-goto-message (event)
1052 "Select the message whose summary line you click on."
1054 (goto-char (posn-point (event-end event
)))
1055 (rmail-summary-goto-msg))
1057 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail
)
1058 "Go to message N in the summary buffer and the Rmail buffer.
1059 If N is nil, use the message corresponding to point in the summary
1060 and move to that message in the Rmail buffer.
1062 If NOWARN, don't say anything if N is out of range.
1063 If SKIP-RMAIL, don't do anything to the Rmail buffer."
1065 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1066 (if (eobp) (forward-line -
1))
1068 (let* ((obuf (current-buffer))
1072 (curmsg (string-to-number
1073 (buffer-substring (point)
1074 (min (point-max) (+ 6 (point))))))
1075 (total (save-excursion (set-buffer buf
) rmail-total-messages
)))
1076 ;; If message number N was specified, find that message's line
1077 ;; or set message-not-found.
1078 ;; If N wasn't specified or that message can't be found.
1079 ;; set N by default.
1083 (progn (message "No preceding message")
1085 (if (and (> n total
)
1087 (progn (message "No following message")
1088 (goto-char (point-max))
1089 (rmail-summary-goto-msg nil nowarn skip-rmail
)))
1090 (goto-char (point-min))
1091 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1092 (progn (or nowarn
(message "Message %d not found" n
))
1094 (setq message-not-found t
)
1097 (skip-chars-forward " ")
1098 (skip-chars-forward "0-9")
1099 (save-excursion (if (= (following-char) ?-
)
1100 (let ((buffer-read-only nil
))
1103 (rmail-summary-update-highlight message-not-found
)
1107 (let ((selwin (selected-window)))
1109 (progn (pop-to-buffer buf
)
1110 (rmail-show-message n
))
1111 (select-window selwin
)
1112 ;; The actions above can alter the current buffer. Preserve it.
1113 (set-buffer obuf
))))))
1115 ;; Update the highlighted line in an rmail summary buffer.
1116 ;; That should be current. We highlight the line point is on.
1117 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1118 (defun rmail-summary-update-highlight (not-found)
1119 ;; Make sure we have an overlay to use.
1120 (or rmail-summary-overlay
1122 (make-local-variable 'rmail-summary-overlay
)
1123 (setq rmail-summary-overlay
(make-overlay (point) (point)))))
1124 ;; If this message is in the summary, use the overlay to highlight it.
1125 ;; Otherwise, don't highlight anything.
1127 (overlay-put rmail-summary-overlay
'face nil
)
1128 (move-overlay rmail-summary-overlay
1129 (save-excursion (beginning-of-line)
1130 (skip-chars-forward " ")
1132 (save-excursion (end-of-line) (point)))
1133 (overlay-put rmail-summary-overlay
'face
'highlight
)))
1135 (defun rmail-summary-scroll-msg-up (&optional dist
)
1136 "Scroll the Rmail window forward.
1137 If the Rmail window is displaying the end of a message,
1138 advance to the next message."
1141 (rmail-summary-scroll-msg-down nil
)
1142 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer
)))
1143 (if rmail-buffer-window
1144 (if (let ((rmail-summary-window (selected-window)))
1145 (select-window rmail-buffer-window
)
1147 ;; Is EOB visible in the buffer?
1149 (let ((ht (window-height (selected-window))))
1150 (move-to-window-line (- ht
2))
1153 (select-window rmail-summary-window
)))
1154 (if (not rmail-summary-scroll-between-messages
)
1155 (error "End of buffer")
1156 (rmail-summary-next-msg (or dist
1)))
1157 (let ((other-window-scroll-buffer rmail-view-buffer
))
1158 (scroll-other-window dist
)))
1159 ;; If it isn't visible at all, show the beginning.
1160 (rmail-summary-beginning-of-message)))))
1162 (defun rmail-summary-scroll-msg-down (&optional dist
)
1163 "Scroll the Rmail window backward.
1164 If the Rmail window is now displaying the beginning of a message,
1165 move to the previous message."
1168 (rmail-summary-scroll-msg-up nil
)
1169 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer
)))
1170 (if rmail-buffer-window
1171 (if (let ((rmail-summary-window (selected-window)))
1172 (select-window rmail-buffer-window
)
1174 ;; Is BOB visible in the buffer?
1176 (move-to-window-line 0)
1179 (select-window rmail-summary-window
)))
1180 (if (not rmail-summary-scroll-between-messages
)
1181 (error "Beginning of buffer")
1182 (rmail-summary-previous-msg (or dist
1)))
1183 (let ((other-window-scroll-buffer rmail-view-buffer
))
1184 (scroll-other-window-down dist
)))
1185 ;; If it isn't visible at all, show the beginning.
1186 (rmail-summary-beginning-of-message)))))
1188 (defun rmail-summary-beginning-of-message ()
1189 "Show current message from the beginning."
1191 (rmail-summary-show-message 'BEG
))
1193 (defun rmail-summary-end-of-message ()
1194 "Show bottom of current message."
1196 (rmail-summary-show-message 'END
))
1198 (defun rmail-summary-show-message (where)
1199 "Show current mail message.
1200 Position it according to WHERE which can be BEG or END"
1201 (if (and (one-window-p) (not pop-up-frames
))
1202 ;; If there is just one window, put the summary on the top.
1203 (let ((buffer rmail-view-buffer
))
1204 (split-window (selected-window) rmail-summary-window-size
)
1205 (select-window (frame-first-window))
1206 (pop-to-buffer rmail-view-buffer
)
1207 ;; If pop-to-buffer did not use that window, delete that
1208 ;; window. (This can happen if it uses another frame.)
1209 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1210 (delete-other-windows)))
1211 (pop-to-buffer rmail-view-buffer
))
1214 (goto-char (point-min))
1215 (search-forward "\n\n"))
1217 (goto-char (point-max))
1218 (recenter (1- (window-height))))
1220 (pop-to-buffer rmail-summary-buffer
))
1222 (defun rmail-summary-bury ()
1223 "Bury the Rmail buffer and the Rmail summary buffer."
1225 (let ((buffer-to-bury (current-buffer)))
1227 (while (setq window
(get-buffer-window rmail-buffer
))
1228 (set-window-buffer window
(other-buffer rmail-buffer
)))
1229 (bury-buffer rmail-buffer
))
1230 (switch-to-buffer (other-buffer buffer-to-bury
))
1231 (bury-buffer buffer-to-bury
)))
1233 (defun rmail-summary-quit ()
1234 "Quit out of Rmail and Rmail summary."
1236 (rmail-summary-wipe)
1239 (defun rmail-summary-wipe ()
1240 "Kill and wipe away Rmail summary, remaining within Rmail."
1242 (save-excursion (set-buffer rmail-buffer
) (setq rmail-summary-buffer nil
))
1243 (let ((local-rmail-buffer rmail-view-buffer
))
1244 (kill-buffer (current-buffer))
1245 ;; Delete window if not only one.
1246 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1248 ;; Switch windows to the rmail buffer, or switch to it in this window.
1249 (pop-to-buffer local-rmail-buffer
)))
1251 (defun rmail-summary-expunge ()
1252 "Actually erase all deleted messages and recompute summary headers."
1255 (set-buffer rmail-buffer
)
1256 (when (rmail-expunge-confirmed)
1257 (rmail-only-expunge)))
1258 (rmail-update-summary))
1260 (defun rmail-summary-expunge-and-save ()
1261 "Expunge and save RMAIL file."
1264 (set-buffer rmail-buffer
)
1265 (when (rmail-expunge-confirmed)
1266 (rmail-only-expunge)))
1267 (rmail-update-summary)
1269 (set-buffer rmail-buffer
)
1271 (set-buffer-modified-p nil
))
1273 (defun rmail-summary-get-new-mail (&optional file-name
)
1274 "Get new mail and recompute summary headers.
1276 Optionally you can specify the file to get new mail from. In this case,
1277 the file of new mail is not changed or deleted. Noninteractively, you can
1278 pass the inbox file name as an argument. Interactively, a prefix
1279 argument says to read a file name and use that file as the inbox."
1281 (list (if current-prefix-arg
1282 (read-file-name "Get new mail from file: "))))
1285 (set-buffer rmail-buffer
)
1286 (rmail-get-new-mail file-name
)
1287 ;; Get the proper new message number.
1288 (setq msg rmail-current-message
))
1289 ;; Make sure that message is displayed.
1291 (rmail-summary-goto-msg msg
))))
1293 (defun rmail-summary-input (filename)
1294 "Run Rmail on file FILENAME."
1295 (interactive "FRun rmail on RMAIL file: ")
1296 ;; We switch windows here, then display the other Rmail file there.
1297 (pop-to-buffer rmail-buffer
)
1300 (defun rmail-summary-first-message ()
1301 "Show first message in Rmail file from summary buffer."
1304 (beginning-of-buffer)))
1306 (defun rmail-summary-last-message ()
1307 "Show last message in Rmail file from summary buffer."
1313 (defvar rmail-summary-edit-map nil
)
1314 (if rmail-summary-edit-map
1316 (setq rmail-summary-edit-map
1317 (nconc (make-sparse-keymap) text-mode-map
))
1318 (define-key rmail-summary-edit-map
"\C-c\C-c" 'rmail-cease-edit
)
1319 (define-key rmail-summary-edit-map
"\C-c\C-]" 'rmail-abort-edit
))
1321 (defun rmail-summary-edit-current-message ()
1322 "Edit the contents of this message."
1324 (pop-to-buffer rmail-buffer
)
1325 (rmail-edit-current-message)
1326 (use-local-map rmail-summary-edit-map
))
1328 (defun rmail-summary-cease-edit ()
1329 "Finish editing message, then go back to Rmail summary buffer."
1332 (pop-to-buffer rmail-summary-buffer
))
1334 (defun rmail-summary-abort-edit ()
1335 "Abort edit of current message; restore original contents.
1336 Go back to summary buffer."
1339 (pop-to-buffer rmail-summary-buffer
))
1341 (defun rmail-summary-search-backward (regexp &optional n
)
1342 "Show message containing next match for REGEXP.
1343 Prefix argument gives repeat count; negative argument means search
1344 backwards (through earlier messages).
1345 Interactively, empty argument means use same regexp used last time."
1347 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1349 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1353 (if rmail-search-last-regexp
1354 (concat ", default "
1355 rmail-search-last-regexp
"): ")
1357 (setq regexp
(read-string prompt
))
1358 (cond ((not (equal regexp
""))
1359 (setq rmail-search-last-regexp regexp
))
1360 ((not rmail-search-last-regexp
)
1361 (error "No previous Rmail search string")))
1362 (list rmail-search-last-regexp
1363 (prefix-numeric-value current-prefix-arg
))))
1364 ;; Don't use save-excursion because that prevents point from moving
1365 ;; properly in the summary buffer.
1366 (let ((buffer (current-buffer)))
1369 (set-buffer rmail-buffer
)
1370 (rmail-search regexp
(- n
)))
1371 (set-buffer buffer
))))
1373 (defun rmail-summary-search (regexp &optional n
)
1374 "Show message containing next match for REGEXP.
1375 Prefix argument gives repeat count; negative argument means search
1376 backwards (through earlier messages).
1377 Interactively, empty argument means use same regexp used last time."
1379 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1381 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1385 (if rmail-search-last-regexp
1386 (concat ", default "
1387 rmail-search-last-regexp
"): ")
1389 (setq regexp
(read-string prompt
))
1390 (cond ((not (equal regexp
""))
1391 (setq rmail-search-last-regexp regexp
))
1392 ((not rmail-search-last-regexp
)
1393 (error "No previous Rmail search string")))
1394 (list rmail-search-last-regexp
1395 (prefix-numeric-value current-prefix-arg
))))
1396 ;; Don't use save-excursion because that prevents point from moving
1397 ;; properly in the summary buffer.
1398 (let ((buffer (current-buffer)))
1401 (set-buffer rmail-buffer
)
1402 (rmail-search regexp n
))
1403 (set-buffer buffer
))))
1405 (defun rmail-summary-toggle-header ()
1406 "Show original message header if pruned header currently shown, or vice versa."
1408 (save-window-excursion
1409 (set-buffer rmail-buffer
)
1410 (rmail-toggle-header))
1411 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1412 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1413 (let ((window (get-buffer-window rmail-view-buffer
)))
1415 ;; Using save-window-excursion would lose the new value of point.
1416 (let ((owin (selected-window)))
1419 (select-window window
)
1420 (goto-char (point-min)))
1421 (select-window owin
))))))
1424 (defun rmail-summary-add-label (label)
1425 "Add LABEL to labels associated with current Rmail message.
1426 Completion is performed over known labels when reading."
1427 (interactive (list (save-excursion
1428 (set-buffer rmail-buffer
)
1429 (rmail-read-label "Add label"))))
1431 (set-buffer rmail-buffer
)
1432 (rmail-add-label label
)))
1434 (defun rmail-summary-kill-label (label)
1435 "Remove LABEL from labels associated with current Rmail message.
1436 Completion is performed over known labels when reading."
1437 (interactive (list (save-excursion
1438 (set-buffer rmail-buffer
)
1439 (rmail-read-label "Kill label"))))
1441 (set-buffer rmail-buffer
)
1442 (rmail-set-label label nil
)))
1444 ;;;; *** Rmail Summary Mailing Commands ***
1446 (defun rmail-summary-override-mail-send-and-exit ()
1447 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1448 (use-local-map (copy-keymap (current-local-map)))
1449 (dolist (key (where-is-internal 'mail-send-and-exit
))
1450 (define-key (current-local-map) key
'rmail-summary-send-and-exit
)))
1452 (defun rmail-summary-mail ()
1453 "Send mail in another window.
1454 While composing the message, use \\[mail-yank-original] to yank the
1455 original message into it."
1457 (let ((window (get-buffer-window rmail-buffer
)))
1459 (select-window window
)
1460 (set-buffer rmail-buffer
)))
1461 (rmail-start-mail nil nil nil nil nil
(current-buffer))
1462 (rmail-summary-override-mail-send-and-exit))
1464 (defun rmail-summary-continue ()
1465 "Continue composing outgoing message previously being composed."
1467 (let ((window (get-buffer-window rmail-buffer
)))
1469 (select-window window
)
1470 (set-buffer rmail-buffer
)))
1471 (rmail-start-mail t
))
1473 (defun rmail-summary-reply (just-sender)
1474 "Reply to the current message.
1475 Normally include CC: to all other recipients of original message;
1476 prefix argument means ignore them. While composing the reply,
1477 use \\[mail-yank-original] to yank the original message into it."
1479 (let ((window (get-buffer-window rmail-view-buffer
)))
1481 (select-window window
)
1482 (set-buffer rmail-view-buffer
)))
1483 (rmail-reply just-sender
)
1484 (rmail-summary-override-mail-send-and-exit))
1486 (defun rmail-summary-retry-failure ()
1487 "Edit a mail message which is based on the contents of the current message.
1488 For a message rejected by the mail system, extract the interesting headers and
1489 the body of the original message; otherwise copy the current message."
1491 (let ((window (get-buffer-window rmail-buffer
)))
1493 (select-window window
)
1494 (set-buffer rmail-buffer
)))
1495 (rmail-retry-failure)
1496 (rmail-summary-override-mail-send-and-exit))
1498 (defun rmail-summary-send-and-exit ()
1499 "Send mail reply and return to summary buffer."
1501 (mail-send-and-exit t
))
1503 (defun rmail-summary-forward (resend)
1504 "Forward the current message to another user.
1505 With prefix argument, \"resend\" the message instead of forwarding it;
1506 see the documentation of `rmail-resend'."
1509 (let ((window (get-buffer-window rmail-buffer
)))
1511 (select-window window
)
1512 (set-buffer rmail-buffer
)))
1513 (rmail-forward resend
)
1514 (rmail-summary-override-mail-send-and-exit)))
1516 (defun rmail-summary-resend ()
1517 "Resend current message using `rmail-resend'."
1520 (let ((window (get-buffer-window rmail-buffer
)))
1522 (select-window window
)
1523 (set-buffer rmail-buffer
)))
1524 (call-interactively 'rmail-resend
)))
1526 ;; Summary output commands.
1528 (defun rmail-summary-output-to-rmail-file (&optional file-name n
)
1529 "Append the current message to an Rmail file named FILE-NAME.
1530 If the file does not exist, ask if it should be created.
1531 If file is being visited, the message is appended to the Emacs
1532 buffer visiting that file.
1534 A prefix argument N says to output N consecutive messages
1535 starting with the current one. Deleted messages are skipped and don't count."
1537 (progn (require 'rmailout
)
1538 (list (rmail-output-read-rmail-file-name)
1539 (prefix-numeric-value current-prefix-arg
))))
1540 (let ((i 0) prev-msg
)
1543 (progn (rmail-summary-goto-msg)
1546 (with-current-buffer rmail-buffer
1547 rmail-current-message
))))))
1549 (with-current-buffer rmail-buffer
1550 (let ((rmail-delete-after-output nil
))
1551 (rmail-output-to-rmail-file file-name
1)))
1552 (if rmail-delete-after-output
1553 (rmail-summary-delete-forward nil
)
1555 (rmail-summary-next-msg 1))))))
1557 (defun rmail-summary-output (&optional file-name n
)
1558 "Append this message to Unix mail file named FILE-NAME.
1560 A prefix argument N says to output N consecutive messages
1561 starting with the current one. Deleted messages are skipped and don't count."
1563 (progn (require 'rmailout
)
1564 (list (rmail-output-read-file-name)
1565 (prefix-numeric-value current-prefix-arg
))))
1566 (let ((i 0) prev-msg
)
1569 (progn (rmail-summary-goto-msg)
1572 (with-current-buffer rmail-buffer
1573 rmail-current-message
))))))
1575 (with-current-buffer rmail-buffer
1576 (let ((rmail-delete-after-output nil
))
1577 (rmail-output file-name
1)))
1578 (if rmail-delete-after-output
1579 (rmail-summary-delete-forward nil
)
1581 (rmail-summary-next-msg 1))))))
1583 (defun rmail-summary-output-menu ()
1584 "Output current message to another Rmail file, chosen with a menu.
1585 Also set the default for subsequent \\[rmail-output-to-rmail-file] commands.
1586 The variables `rmail-secondary-file-directory' and
1587 `rmail-secondary-file-regexp' control which files are offered in the menu."
1590 (set-buffer rmail-buffer
)
1591 (let ((rmail-delete-after-output nil
))
1592 (call-interactively 'rmail-output-menu
)))
1593 (if rmail-delete-after-output
1594 (rmail-summary-delete-forward nil
)))
1596 (defun rmail-summary-construct-io-menu ()
1597 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1600 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1601 (cons "Input Rmail File"
1602 (rmail-list-to-menu "Input Rmail File"
1604 'rmail-summary-input
)))
1605 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1606 (cons "Output Rmail File"
1607 (rmail-list-to-menu "Output Rmail File"
1609 'rmail-summary-output-to-rmail-file
))))
1610 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1611 '("Input Rmail File" . rmail-disable-menu
))
1612 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1613 '("Output Rmail File" . rmail-disable-menu
)))))
1615 (defun rmail-summary-output-body (&optional file-name
)
1616 "Write this message body to the file FILE-NAME.
1617 FILE-NAME defaults, interactively, from the Subject field of the message."
1620 (set-buffer rmail-buffer
)
1621 (let ((rmail-delete-after-output nil
))
1623 (rmail-output-body-to-file file-name
)
1624 (call-interactively 'rmail-output-body-to-file
))))
1625 (if rmail-delete-after-output
1626 (rmail-summary-delete-forward nil
)))
1628 ;; Sorting messages in Rmail Summary buffer.
1630 (defun rmail-summary-sort-by-date (reverse)
1631 "Sort messages of current Rmail summary by date.
1632 If prefix argument REVERSE is non-nil, sort them in reverse order."
1634 (rmail-sort-from-summary (function rmail-sort-by-date
) reverse
))
1636 (defun rmail-summary-sort-by-subject (reverse)
1637 "Sort messages of current Rmail summary by subject.
1638 If prefix argument REVERSE is non-nil, sort them in reverse order."
1640 (rmail-sort-from-summary (function rmail-sort-by-subject
) reverse
))
1642 (defun rmail-summary-sort-by-author (reverse)
1643 "Sort messages of current Rmail summary by author.
1644 If prefix argument REVERSE is non-nil, sort them in reverse order."
1646 (rmail-sort-from-summary (function rmail-sort-by-author
) reverse
))
1648 (defun rmail-summary-sort-by-recipient (reverse)
1649 "Sort messages of current Rmail summary by recipient.
1650 If prefix argument REVERSE is non-nil, sort them in reverse order."
1652 (rmail-sort-from-summary (function rmail-sort-by-recipient
) reverse
))
1654 (defun rmail-summary-sort-by-correspondent (reverse)
1655 "Sort messages of current Rmail summary by other correspondent.
1656 If prefix argument REVERSE is non-nil, sort them in reverse order."
1658 (rmail-sort-from-summary (function rmail-sort-by-correspondent
) reverse
))
1660 (defun rmail-summary-sort-by-lines (reverse)
1661 "Sort messages of current Rmail summary by lines of the message.
1662 If prefix argument REVERSE is non-nil, sort them in reverse order."
1664 (rmail-sort-from-summary (function rmail-sort-by-lines
) reverse
))
1666 (defun rmail-summary-sort-by-labels (reverse labels
)
1667 "Sort messages of current Rmail summary by labels.
1668 If prefix argument REVERSE is non-nil, sort them in reverse order.
1669 KEYWORDS is a comma-separated list of labels."
1670 (interactive "P\nsSort by labels: ")
1671 (rmail-sort-from-summary
1672 (function (lambda (reverse)
1673 (rmail-sort-by-labels reverse labels
)))
1676 (defun rmail-sort-from-summary (sortfun reverse
)
1677 "Sort Rmail messages from Summary buffer and update it after sorting."
1678 (require 'rmailsort
)
1679 (let ((selwin (selected-window)))
1681 (progn (pop-to-buffer rmail-buffer
)
1682 (funcall sortfun reverse
))
1683 (select-window selwin
))))
1687 ;;; arch-tag: 556079ee-75c1-47f5-9884-2e0a0bc6c5a1
1688 ;;; rmailsum.el ends here