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, 2006, 2007 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 3, 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."
136 (let* ((subject (with-current-buffer rmail-buffer
137 (rmail-current-subject)))
138 (subject-re (with-current-buffer rmail-buffer
139 (rmail-current-subject-regexp)))
140 (prompt (concat "Topics to summarize by (regexp"
141 (if subject
", default current subject" "")
143 (list (read-string prompt nil nil subject
) current-prefix-arg
)))
145 (concat "about " subject
)
146 (list 'rmail-summary-by-topic subject whole-message
)
147 'rmail-message-subject-p
148 (mail-comma-list-regexp subject
) whole-message
))
150 (defun rmail-message-subject-p (msg subject
&optional whole-message
)
152 (goto-char (rmail-msgbeg msg
))
153 (search-forward "\n*** EOOH ***\n" (rmail-msgend msg
) 'move
)
156 (progn (search-forward (if whole-message
"\^_" "\n\n")) (point)))
157 (goto-char (point-min))
158 (if whole-message
(re-search-forward subject nil t
)
159 (string-match subject
(let ((subj (mail-fetch-field "Subject")))
161 (funcall rmail-summary-line-decoder subj
)
165 (defun rmail-summary-by-senders (senders)
166 "Display a summary of all messages with the given SENDERS.
167 SENDERS is a string of names separated by commas."
168 (interactive "sSenders to summarize by: ")
170 (concat "senders " senders
)
171 (list 'rmail-summary-by-senders senders
)
172 'rmail-message-senders-p
173 (mail-comma-list-regexp senders
)))
175 (defun rmail-message-senders-p (msg senders
)
177 (goto-char (rmail-msgbeg msg
))
178 (search-forward "\n*** EOOH ***\n")
179 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
180 (string-match senders
(or (mail-fetch-field "From") ""))))
182 ;; General making of a summary buffer.
184 (defvar rmail-summary-symbol-number
0)
186 (defvar rmail-new-summary-line-count
)
188 (defun rmail-new-summary (description redo-form function
&rest args
)
189 "Create a summary of selected messages.
190 DESCRIPTION makes part of the mode line of the summary buffer.
191 For each message, FUNCTION is applied to the message number and ARGS...
192 and if the result is non-nil, that message is included.
193 nil for FUNCTION means all messages."
194 (message "Computing summary lines...")
195 (let (sumbuf mesg was-in-summary
)
197 ;; Go to the Rmail buffer.
198 (if (eq major-mode
'rmail-summary-mode
)
199 (setq was-in-summary t
))
200 (set-buffer rmail-buffer
)
201 ;; Find its summary buffer, or make one.
203 (if (and rmail-summary-buffer
204 (buffer-name rmail-summary-buffer
))
206 (generate-new-buffer (concat (buffer-name) "-summary"))))
207 (setq mesg rmail-current-message
)
208 ;; Filter the messages; make or get their summary lines.
209 (let ((summary-msgs ())
210 (rmail-new-summary-line-count 0))
212 (buffer-read-only nil
)
213 (old-min (point-min-marker))
214 (old-max (point-max-marker)))
215 ;; Can't use save-restriction here; that doesn't work if we
216 ;; plan to modify text outside the original restriction.
219 (goto-char (point-min))
220 (while (>= rmail-total-messages msgnum
)
221 (if (or (null function
)
222 (apply function
(cons msgnum args
)))
224 (cons (cons msgnum
(rmail-make-summary-line msgnum
))
226 (setq msgnum
(1+ msgnum
)))
227 (setq summary-msgs
(nreverse summary-msgs
)))
228 (narrow-to-region old-min old-max
))
229 ;; Temporarily, while summary buffer is unfinished,
230 ;; we "don't have" a summary.
231 (setq rmail-summary-buffer nil
)
232 (if rmail-enable-mime
233 (with-current-buffer rmail-view-buffer
234 (setq rmail-summary-buffer nil
)))
236 (let ((rbuf (current-buffer))
237 (vbuf rmail-view-buffer
)
238 (total rmail-total-messages
))
240 ;; Set up the summary buffer's contents.
241 (let ((buffer-read-only nil
))
244 (princ (cdr (car summary-msgs
)) sumbuf
)
245 (setq summary-msgs
(cdr summary-msgs
)))
246 (goto-char (point-min)))
247 ;; Set up the rest of its state and local variables.
248 (setq buffer-read-only t
)
250 (make-local-variable 'minor-mode-alist
)
251 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
252 (setq rmail-buffer rbuf
253 rmail-view-buffer vbuf
254 rmail-summary-redo redo-form
255 rmail-total-messages total
))))
256 (setq rmail-summary-buffer sumbuf
))
257 ;; Now display the summary buffer and go to the right place in it.
260 (if (and (one-window-p)
261 pop-up-windows
(not pop-up-frames
))
262 ;; If there is just one window, put the summary on the top.
264 (split-window (selected-window) rmail-summary-window-size
)
265 (select-window (next-window (frame-first-window)))
266 (pop-to-buffer sumbuf
)
267 ;; If pop-to-buffer did not use that window, delete that
268 ;; window. (This can happen if it uses another frame.)
269 (if (not (eq sumbuf
(window-buffer (frame-first-window))))
270 (delete-other-windows)))
271 (pop-to-buffer sumbuf
))
272 (set-buffer rmail-buffer
)
273 ;; This is how rmail makes the summary buffer reappear.
274 ;; We do this here to make the window the proper size.
275 (rmail-select-summary nil
)
276 (set-buffer rmail-summary-buffer
)))
277 (rmail-summary-goto-msg mesg t t
)
278 (rmail-summary-construct-io-menu)
279 (message "Computing summary lines...done")))
281 ;; Low levels of generating a summary.
283 (defun rmail-make-summary-line (msg)
284 (let ((line (or (aref rmail-summary-vector
(1- msg
))
286 (setq rmail-new-summary-line-count
287 (1+ rmail-new-summary-line-count
))
288 (if (zerop (% rmail-new-summary-line-count
10))
289 (message "Computing summary lines...%d"
290 rmail-new-summary-line-count
))
291 (rmail-make-summary-line-1 msg
))))
293 ;; Fix up the part of the summary that says "deleted" or "unseen".
294 (string-match "[0-9]+" line
)
295 (aset line
(match-end 0)
296 (if (rmail-message-deleted-p msg
) ?D
297 (if (= ?
0 (char-after (+ 3 (rmail-msgbeg msg
))))
302 (defcustom rmail-summary-line-decoder
(function identity
)
303 "*Function to decode summary-line.
305 By default, `identity' is set."
307 :group
'rmail-summary
)
309 (defun rmail-make-summary-line-1 (msg)
310 (goto-char (rmail-msgbeg msg
))
311 (let* ((lim (save-excursion (forward-line 2) (point)))
317 ; (if (save-excursion (re-search-forward ",answered," lim t))
319 ; (if (save-excursion (re-search-forward ",filed," lim t))
321 (if (progn (search-forward ",,") (eolp))
324 (buffer-substring (point)
334 (if (looking-at "Summary-line: ")
336 (goto-char (match-end 0))
337 (buffer-substring (point)
338 (progn (forward-line 1) (point))))))))
339 ;; Obsolete status lines lacking a # should be flushed.
341 (not (string-match "#" line
))
343 (delete-region (point)
344 (progn (forward-line -
1) (point)))
346 ;; If we didn't get a valid status line from the message,
347 ;; make a new one and put it in the message.
349 (let* ((case-fold-search t
)
350 (next (rmail-msgend msg
))
351 (beg (if (progn (goto-char (rmail-msgbeg msg
))
352 (search-forward "\n*** EOOH ***\n" next t
))
356 (end (progn (search-forward "\n\n" nil t
) (point))))
358 (narrow-to-region beg end
)
360 (setq line
(rmail-make-basic-summary-line)))
361 (goto-char (rmail-msgbeg msg
))
363 (insert "Summary-line: " line
)))
364 (setq pos
(string-match "#" line
))
365 (aset rmail-summary-vector
(1- msg
)
366 (funcall rmail-summary-line-decoder
367 (concat (format "%5d " msg
)
368 (substring line
0 pos
)
370 (substring line
(1+ pos
)))))
374 (defcustom rmail-user-mail-address-regexp nil
375 "*Regexp matching user mail addresses.
376 If non-nil, this variable is used to identify the correspondent
377 when receiving new mail. If it matches the address of the sender,
378 the recipient is taken as correspondent of a mail.
379 If nil \(default value\), your `user-login-name' and `user-mail-address'
380 are used to exclude yourself as correspondent.
382 Usually you don't have to set this variable, except if you collect mails
383 sent by you under different user names.
384 Then it should be a regexp matching your mail addresses.
386 Setting this variable has an effect only before reading a mail."
387 :type
'(choice (const :tag
"None" nil
) regexp
)
388 :group
'rmail-retrieve
391 (defun rmail-make-basic-summary-line ()
392 (goto-char (point-min))
393 (concat (save-excursion
394 (if (not (re-search-forward "^Date:" nil t
))
396 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
397 (save-excursion (end-of-line) (point)) t
)
399 (string-to-number (buffer-substring
403 (match-beginning 4) (match-end 4))))
404 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
405 (save-excursion (end-of-line) (point)) t
)
407 (string-to-number (buffer-substring
411 (match-beginning 2) (match-end 2))))
412 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
413 (save-excursion (end-of-line) (point)) t
)
416 (match-beginning 2) (match-end 2))
418 (match-beginning 3) (match-end 3))
420 (match-beginning 4) (match-end 4))))
424 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
425 (mail-strip-quoted-names
428 ;; Get all the lines of the From field
429 ;; so that we get a whole comment if there is one,
430 ;; so that mail-strip-quoted-names can discard it.
431 (let ((opoint (point)))
432 (while (progn (forward-line 1)
433 (looking-at "[ \t]")))
434 ;; Back up over newline, then trailing spaces or tabs
436 (skip-chars-backward " \t")
441 (or rmail-user-mail-address-regexp
443 (regexp-quote (user-login-name))
446 ;; Don't lose if run from init file
447 ;; where user-mail-address is not
449 (or user-mail-address
450 (concat (user-login-name) "@"
451 (or mail-host-address
455 ;; No From field, or it's this user.
457 (goto-char (point-min))
458 (if (not (re-search-forward "^To:[ \t]*" nil t
))
462 (mail-strip-quoted-names
466 (skip-chars-backward " \t")
470 (setq len
(length from
))
471 (setq mch
(string-match "[@%]" from
))
473 (if (or (not mch
) (<= len
25))
474 (substring from
(max 0 (- len
25)))
476 (setq lo
(cond ((< (- mch
14) 0) 0)
480 (min len
(+ lo
25))))))))
481 (if rmail-summary-line-count-flag
485 (let ((beg (rmail-msgbeg msgnum
))
486 (end (rmail-msgend msgnum
))
490 ;; Count only lines in the reformatted header,
491 ;; if we have reformatted it.
492 (search-forward "\n*** EOOH ***\n" end t
)
493 (setq lines
(count-lines (point) end
)))
495 ((<= lines
9) " [%d]")
496 ((<= lines
99) " [%d]")
497 ((<= lines
999) " [%3d]")
501 " #" ;The # is part of the format.
502 (if (re-search-forward "^Subject:" nil t
)
503 (progn (skip-chars-forward " \t")
504 (buffer-substring (point)
507 (re-search-forward "[\n][\n]+" nil t
)
508 (buffer-substring (point) (progn (end-of-line) (point))))
511 ;; Simple motion in a summary buffer.
513 (defun rmail-summary-next-all (&optional number
)
515 (forward-line (if number number
1))
516 ;; It doesn't look nice to move forward past the last message line.
517 (and (eobp) (> number
0)
519 (display-buffer rmail-buffer
))
521 (defun rmail-summary-previous-all (&optional number
)
523 (forward-line (- (if number number
1)))
524 ;; It doesn't look nice to move forward past the last message line.
525 (and (eobp) (< number
0)
527 (display-buffer rmail-buffer
))
529 (defun rmail-summary-next-msg (&optional number
)
530 "Display next non-deleted msg from rmail file.
531 With optional prefix argument NUMBER, moves forward this number of non-deleted
532 messages, or backward if NUMBER is negative."
535 (and (> number
0) (end-of-line))
536 (let ((count (if (< number
0) (- number
) number
))
537 (search (if (> number
0) 're-search-forward
're-search-backward
))
538 (non-del-msg-found nil
))
539 (while (and (> count
0) (setq non-del-msg-found
540 (or (funcall search
"^.....[^D]" nil t
)
542 (setq count
(1- count
))))
544 (display-buffer rmail-view-buffer
))
546 (defun rmail-summary-previous-msg (&optional number
)
547 "Display previous non-deleted msg from rmail file.
548 With optional prefix argument NUMBER, moves backward this number of
549 non-deleted messages."
551 (rmail-summary-next-msg (- (if number number
1))))
553 (defun rmail-summary-next-labeled-message (n labels
)
554 "Show next message with LABELS. Defaults to last labels used.
555 With prefix argument N moves forward N messages with these labels."
556 (interactive "p\nsMove to next msg with labels: ")
559 (set-buffer rmail-buffer
)
560 (rmail-next-labeled-message n labels
)
561 (setq msg rmail-current-message
))
562 (rmail-summary-goto-msg msg
)))
564 (defun rmail-summary-previous-labeled-message (n labels
)
565 "Show previous message with LABELS. Defaults to last labels used.
566 With prefix argument N moves backward N messages with these labels."
567 (interactive "p\nsMove to previous msg with labels: ")
570 (set-buffer rmail-buffer
)
571 (rmail-previous-labeled-message n labels
)
572 (setq msg rmail-current-message
))
573 (rmail-summary-goto-msg msg
)))
575 (defun rmail-summary-next-same-subject (n)
576 "Go to the next message in the summary having the same subject.
577 With prefix argument N, do this N times.
578 If N is negative, go backwards."
580 (let ((forward (> n
0))
581 search-regexp i found
)
582 (with-current-buffer rmail-buffer
583 (setq search-regexp
(rmail-current-subject-regexp)
584 i rmail-current-message
))
591 (while (and (not done
)
595 ;; Advance thru summary.
596 (forward-line (if forward
1 -
1))
597 ;; Get msg number of this line.
598 (setq i
(string-to-number
599 (buffer-substring (point)
600 (min (point-max) (+ 6 (point))))))
601 ;; See if that msg has desired subject.
603 (set-buffer rmail-buffer
)
606 (goto-char (rmail-msgbeg i
))
607 (search-forward "\n*** EOOH ***\n")
608 (let ((beg (point)) end
)
609 (search-forward "\n\n")
612 (setq done
(re-search-forward search-regexp end t
))))))
613 (if done
(setq found i
)))
614 (setq n
(if forward
(1- n
) (1+ n
)))))
616 (rmail-summary-goto-msg found
)
617 (error "No %s message with same subject"
618 (if forward
"following" "previous")))))
620 (defun rmail-summary-previous-same-subject (n)
621 "Go to the previous message in the summary having the same subject.
622 With prefix argument N, do this N times.
623 If N is negative, go forwards instead."
625 (rmail-summary-next-same-subject (- n
)))
627 ;; Delete and undelete summary commands.
629 (defun rmail-summary-delete-forward (&optional count
)
630 "Delete this message and move to next nondeleted one.
631 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
632 A prefix argument serves as a repeat count;
633 a negative argument means to delete and move backward."
635 (unless (numberp count
) (setq count
1))
637 (backward (< count
0)))
639 (rmail-summary-goto-msg)
640 (with-current-buffer rmail-buffer
641 (rmail-delete-message)
642 (setq del-msg rmail-current-message
))
643 (rmail-summary-mark-deleted del-msg
)
644 (while (and (not (if backward
(bobp) (eobp)))
645 (save-excursion (beginning-of-line)
646 (looking-at " *[0-9]+D")))
647 (forward-line (if backward -
1 1)))
648 ;; It looks ugly to move to the empty line at end of buffer.
649 (and (eobp) (not backward
)
652 (if (> count
0) (1- count
) (1+ count
))))))
654 (defun rmail-summary-delete-backward (&optional count
)
655 "Delete this message and move to previous nondeleted one.
656 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
657 A prefix argument serves as a repeat count;
658 a negative argument means to delete and move forward."
660 (rmail-summary-delete-forward (- count
)))
662 (defun rmail-summary-mark-deleted (&optional n undel
)
663 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
664 (and n
(rmail-summary-goto-msg n t t
))
666 (not (overlay-get rmail-summary-overlay
'face
))
667 (let ((buffer-read-only nil
))
668 (skip-chars-forward " ")
669 (skip-chars-forward "[0-9]")
672 (progn (delete-char 1) (insert " ")))
677 (defun rmail-summary-mark-undeleted (n)
678 (rmail-summary-mark-deleted n t
))
680 (defun rmail-summary-deleted-p (&optional n
)
682 (and n
(rmail-summary-goto-msg n nil t
))
683 (skip-chars-forward " ")
684 (skip-chars-forward "[0-9]")
687 (defun rmail-summary-undelete (&optional arg
)
688 "Undelete current message.
689 Optional prefix ARG means undelete ARG previous messages."
692 (rmail-summary-undelete-many arg
)
693 (let ((buffer-read-only nil
)
696 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
697 (replace-match "\\1 ")
698 (rmail-summary-goto-msg)
699 (if rmail-enable-mime
700 (set-buffer rmail-buffer
)
701 (pop-to-buffer rmail-buffer
))
702 (and (rmail-message-deleted-p rmail-current-message
)
703 (rmail-undelete-previous-message))
704 (if rmail-enable-mime
705 (pop-to-buffer rmail-view-buffer
))
706 (pop-to-buffer rmail-summary-buffer
))
707 (t (goto-char opoint
))))))
709 (defun rmail-summary-undelete-many (&optional n
)
710 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
713 (set-buffer rmail-buffer
)
714 (let* ((init-msg (if n rmail-current-message rmail-total-messages
))
715 (rmail-current-message init-msg
)
716 (n (or n rmail-total-messages
))
718 (while (and (> rmail-current-message
0)
720 (if (rmail-message-deleted-p rmail-current-message
)
721 (progn (rmail-set-attribute "deleted" nil
)
722 (setq msgs-undeled
(1+ msgs-undeled
))))
723 (setq rmail-current-message
(1- rmail-current-message
)))
724 (set-buffer rmail-summary-buffer
)
725 (setq rmail-current-message init-msg msgs-undeled
0)
726 (while (and (> rmail-current-message
0)
728 (if (rmail-summary-deleted-p rmail-current-message
)
729 (progn (rmail-summary-mark-undeleted rmail-current-message
)
730 (setq msgs-undeled
(1+ msgs-undeled
))))
731 (setq rmail-current-message
(1- rmail-current-message
))))
732 (rmail-summary-goto-msg)))
734 ;; Rmail Summary mode is suitable only for specially formatted data.
735 (put 'rmail-summary-mode
'mode-class
'special
)
737 (defun rmail-summary-mode ()
738 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
739 As commands are issued in the summary buffer, they are applied to the
740 corresponding mail messages in the rmail buffer.
742 All normal editing commands are turned off.
743 Instead, nearly all the Rmail mode commands are available,
744 though many of them move only among the messages in the summary.
746 These additional commands exist:
748 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
749 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
751 Commands for sorting the summary:
753 \\[rmail-summary-sort-by-date] Sort by date.
754 \\[rmail-summary-sort-by-subject] Sort by subject.
755 \\[rmail-summary-sort-by-author] Sort by author.
756 \\[rmail-summary-sort-by-recipient] Sort by recipient.
757 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
758 \\[rmail-summary-sort-by-lines] Sort by lines.
759 \\[rmail-summary-sort-by-labels] Sort by labels."
761 (kill-all-local-variables)
762 (setq major-mode
'rmail-summary-mode
)
763 (setq mode-name
"RMAIL Summary")
764 (setq truncate-lines t
)
765 (setq buffer-read-only t
)
766 (set-syntax-table text-mode-syntax-table
)
767 (make-local-variable 'rmail-buffer
)
768 (make-local-variable 'rmail-view-buffer
)
769 (make-local-variable 'rmail-total-messages
)
770 (make-local-variable 'rmail-current-message
)
771 (setq rmail-current-message nil
)
772 (make-local-variable 'rmail-summary-redo
)
773 (setq rmail-summary-redo nil
)
774 (make-local-variable 'revert-buffer-function
)
775 (make-local-variable 'font-lock-defaults
)
776 (setq font-lock-defaults
'(rmail-summary-font-lock-keywords t
))
777 (rmail-summary-enable)
778 (run-mode-hooks 'rmail-summary-mode-hook
))
780 ;; Summary features need to be disabled during edit mode.
781 (defun rmail-summary-disable ()
782 (use-local-map text-mode-map
)
783 (remove-hook 'post-command-hook
'rmail-summary-rmail-update t
)
784 (setq revert-buffer-function nil
))
786 (defun rmail-summary-enable ()
787 (use-local-map rmail-summary-mode-map
)
788 (add-hook 'post-command-hook
'rmail-summary-rmail-update nil t
)
789 (setq revert-buffer-function
'rmail-update-summary
))
791 (defvar rmail-summary-put-back-unseen nil
792 "Used for communicating between calls to `rmail-summary-rmail-update'.
793 If it moves to a message within an Incremental Search, and removes
794 the `unseen' attribute from that message, it sets this flag
795 so that if the next motion between messages is in the same Incremental
796 Search, the `unseen' attribute is restored.")
798 ;; Show in Rmail the message described by the summary line that point is on,
799 ;; but only if the Rmail buffer is already visible.
800 ;; This is a post-command-hook in summary buffers.
801 (defun rmail-summary-rmail-update ()
802 (let (buffer-read-only)
804 ;; If at end of buffer, pretend we are on the last text line.
808 (skip-chars-forward " ")
809 (let ((msg-num (string-to-number (buffer-substring
811 (progn (skip-chars-forward "0-9")
813 ;; Always leave `unseen' removed
814 ;; if we get out of isearch mode.
815 ;; Don't let a subsequent isearch restore that `unseen'.
816 (if (not isearch-mode
)
817 (setq rmail-summary-put-back-unseen nil
))
819 (or (eq rmail-current-message msg-num
)
820 (let ((window (get-buffer-window rmail-view-buffer t
))
821 (owin (selected-window)))
824 (set-buffer rmail-buffer
)
825 ;; If we first saw the previous message in this search,
826 ;; and we have gone to a different message while searching,
827 ;; put back `unseen' on the former one.
828 (if rmail-summary-put-back-unseen
829 (rmail-set-attribute "unseen" t
830 rmail-current-message
))
831 ;; Arrange to do that later, for the new current message,
832 ;; if it still has `unseen'.
833 (setq rmail-summary-put-back-unseen
834 (rmail-message-labels-p msg-num
", ?\\(unseen\\),")))
835 (setq rmail-summary-put-back-unseen nil
))
837 ;; Go to the desired message.
838 (setq rmail-current-message msg-num
)
840 ;; Update the summary to show the message has been seen.
841 (if (= (following-char) ?-
)
847 ;; Using save-window-excursion would cause the new value
848 ;; of point to get lost.
851 (select-window window
)
852 (rmail-show-message msg-num t
))
853 (select-window owin
))
854 (if (buffer-name rmail-buffer
)
856 (set-buffer rmail-buffer
)
857 (rmail-show-message msg-num t
))))))
858 (rmail-summary-update-highlight nil
)))))
860 (defun rmail-summary-save-buffer ()
861 "Save the buffer associated with this RMAIL summary."
863 (save-window-excursion
865 (switch-to-buffer rmail-buffer
)
869 (if rmail-summary-mode-map
871 (setq rmail-summary-mode-map
(make-keymap))
872 (suppress-keymap rmail-summary-mode-map
)
874 (define-key rmail-summary-mode-map
[mouse-2
] 'rmail-summary-mouse-goto-message
)
875 (define-key rmail-summary-mode-map
"a" 'rmail-summary-add-label
)
876 (define-key rmail-summary-mode-map
"b" 'rmail-summary-bury
)
877 (define-key rmail-summary-mode-map
"c" 'rmail-summary-continue
)
878 (define-key rmail-summary-mode-map
"d" 'rmail-summary-delete-forward
)
879 (define-key rmail-summary-mode-map
"\C-d" 'rmail-summary-delete-backward
)
880 (define-key rmail-summary-mode-map
"e" 'rmail-summary-edit-current-message
)
881 (define-key rmail-summary-mode-map
"f" 'rmail-summary-forward
)
882 (define-key rmail-summary-mode-map
"g" 'rmail-summary-get-new-mail
)
883 (define-key rmail-summary-mode-map
"h" 'rmail-summary
)
884 (define-key rmail-summary-mode-map
"i" 'rmail-summary-input
)
885 (define-key rmail-summary-mode-map
"j" 'rmail-summary-goto-msg
)
886 (define-key rmail-summary-mode-map
"\C-m" 'rmail-summary-goto-msg
)
887 (define-key rmail-summary-mode-map
"k" 'rmail-summary-kill-label
)
888 (define-key rmail-summary-mode-map
"l" 'rmail-summary-by-labels
)
889 (define-key rmail-summary-mode-map
"\e\C-h" 'rmail-summary
)
890 (define-key rmail-summary-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
891 (define-key rmail-summary-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
892 (define-key rmail-summary-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
893 (define-key rmail-summary-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
894 (define-key rmail-summary-mode-map
"m" 'rmail-summary-mail
)
895 (define-key rmail-summary-mode-map
"\M-m" 'rmail-summary-retry-failure
)
896 (define-key rmail-summary-mode-map
"n" 'rmail-summary-next-msg
)
897 (define-key rmail-summary-mode-map
"\en" 'rmail-summary-next-all
)
898 (define-key rmail-summary-mode-map
"\e\C-n" 'rmail-summary-next-labeled-message
)
899 (define-key rmail-summary-mode-map
"o" 'rmail-summary-output-to-rmail-file
)
900 (define-key rmail-summary-mode-map
"\C-o" 'rmail-summary-output
)
901 (define-key rmail-summary-mode-map
"p" 'rmail-summary-previous-msg
)
902 (define-key rmail-summary-mode-map
"\ep" 'rmail-summary-previous-all
)
903 (define-key rmail-summary-mode-map
"\e\C-p" 'rmail-summary-previous-labeled-message
)
904 (define-key rmail-summary-mode-map
"q" 'rmail-summary-quit
)
905 (define-key rmail-summary-mode-map
"Q" 'rmail-summary-wipe
)
906 (define-key rmail-summary-mode-map
"r" 'rmail-summary-reply
)
907 (define-key rmail-summary-mode-map
"s" 'rmail-summary-expunge-and-save
)
908 (define-key rmail-summary-mode-map
"\es" 'rmail-summary-search
)
909 (define-key rmail-summary-mode-map
"t" 'rmail-summary-toggle-header
)
910 (define-key rmail-summary-mode-map
"u" 'rmail-summary-undelete
)
911 (define-key rmail-summary-mode-map
"\M-u" 'rmail-summary-undelete-many
)
912 (define-key rmail-summary-mode-map
"x" 'rmail-summary-expunge
)
913 (define-key rmail-summary-mode-map
"w" 'rmail-summary-output-body
)
914 (define-key rmail-summary-mode-map
"." 'rmail-summary-beginning-of-message
)
915 (define-key rmail-summary-mode-map
"/" 'rmail-summary-end-of-message
)
916 (define-key rmail-summary-mode-map
"<" 'rmail-summary-first-message
)
917 (define-key rmail-summary-mode-map
">" 'rmail-summary-last-message
)
918 (define-key rmail-summary-mode-map
" " 'rmail-summary-scroll-msg-up
)
919 (define-key rmail-summary-mode-map
"\177" 'rmail-summary-scroll-msg-down
)
920 (define-key rmail-summary-mode-map
"?" 'describe-mode
)
921 (define-key rmail-summary-mode-map
"\C-c\C-n" 'rmail-summary-next-same-subject
)
922 (define-key rmail-summary-mode-map
"\C-c\C-p" 'rmail-summary-previous-same-subject
)
923 (define-key rmail-summary-mode-map
"\C-c\C-s\C-d"
924 'rmail-summary-sort-by-date
)
925 (define-key rmail-summary-mode-map
"\C-c\C-s\C-s"
926 'rmail-summary-sort-by-subject
)
927 (define-key rmail-summary-mode-map
"\C-c\C-s\C-a"
928 'rmail-summary-sort-by-author
)
929 (define-key rmail-summary-mode-map
"\C-c\C-s\C-r"
930 'rmail-summary-sort-by-recipient
)
931 (define-key rmail-summary-mode-map
"\C-c\C-s\C-c"
932 'rmail-summary-sort-by-correspondent
)
933 (define-key rmail-summary-mode-map
"\C-c\C-s\C-l"
934 'rmail-summary-sort-by-lines
)
935 (define-key rmail-summary-mode-map
"\C-c\C-s\C-k"
936 'rmail-summary-sort-by-labels
)
937 (define-key rmail-summary-mode-map
"\C-x\C-s" 'rmail-summary-save-buffer
)
940 ;;; Menu bar bindings.
942 (define-key rmail-summary-mode-map
[menu-bar
] (make-sparse-keymap))
944 (define-key rmail-summary-mode-map
[menu-bar classify
]
945 (cons "Classify" (make-sparse-keymap "Classify")))
947 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
948 '("Output (Rmail Menu)..." . rmail-summary-output-menu
))
950 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
951 '("Input Rmail File (menu)..." . rmail-input-menu
))
953 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
956 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
959 (define-key rmail-summary-mode-map
[menu-bar classify output-body
]
960 '("Output (body)..." . rmail-summary-output-body
))
962 (define-key rmail-summary-mode-map
[menu-bar classify output-inbox
]
963 '("Output (inbox)..." . rmail-summary-output
))
965 (define-key rmail-summary-mode-map
[menu-bar classify output
]
966 '("Output (Rmail)..." . rmail-summary-output-to-rmail-file
))
968 (define-key rmail-summary-mode-map
[menu-bar classify kill-label
]
969 '("Kill Label..." . rmail-summary-kill-label
))
971 (define-key rmail-summary-mode-map
[menu-bar classify add-label
]
972 '("Add Label..." . rmail-summary-add-label
))
974 (define-key rmail-summary-mode-map
[menu-bar summary
]
975 (cons "Summary" (make-sparse-keymap "Summary")))
977 (define-key rmail-summary-mode-map
[menu-bar summary senders
]
978 '("By Senders..." . rmail-summary-by-senders
))
980 (define-key rmail-summary-mode-map
[menu-bar summary labels
]
981 '("By Labels..." . rmail-summary-by-labels
))
983 (define-key rmail-summary-mode-map
[menu-bar summary recipients
]
984 '("By Recipients..." . rmail-summary-by-recipients
))
986 (define-key rmail-summary-mode-map
[menu-bar summary topic
]
987 '("By Topic..." . rmail-summary-by-topic
))
989 (define-key rmail-summary-mode-map
[menu-bar summary regexp
]
990 '("By Regexp..." . rmail-summary-by-regexp
))
992 (define-key rmail-summary-mode-map
[menu-bar summary all
]
993 '("All" . rmail-summary
))
995 (define-key rmail-summary-mode-map
[menu-bar mail
]
996 (cons "Mail" (make-sparse-keymap "Mail")))
998 (define-key rmail-summary-mode-map
[menu-bar mail rmail-summary-get-new-mail
]
999 '("Get New Mail" . rmail-summary-get-new-mail
))
1001 (define-key rmail-summary-mode-map
[menu-bar mail lambda
]
1004 (define-key rmail-summary-mode-map
[menu-bar mail continue
]
1005 '("Continue" . rmail-summary-continue
))
1007 (define-key rmail-summary-mode-map
[menu-bar mail resend
]
1008 '("Re-send..." . rmail-summary-resend
))
1010 (define-key rmail-summary-mode-map
[menu-bar mail forward
]
1011 '("Forward" . rmail-summary-forward
))
1013 (define-key rmail-summary-mode-map
[menu-bar mail retry
]
1014 '("Retry" . rmail-summary-retry-failure
))
1016 (define-key rmail-summary-mode-map
[menu-bar mail reply
]
1017 '("Reply" . rmail-summary-reply
))
1019 (define-key rmail-summary-mode-map
[menu-bar mail mail
]
1020 '("Mail" . rmail-summary-mail
))
1022 (define-key rmail-summary-mode-map
[menu-bar delete
]
1023 (cons "Delete" (make-sparse-keymap "Delete")))
1025 (define-key rmail-summary-mode-map
[menu-bar delete expunge
/save
]
1026 '("Expunge/Save" . rmail-summary-expunge-and-save
))
1028 (define-key rmail-summary-mode-map
[menu-bar delete expunge
]
1029 '("Expunge" . rmail-summary-expunge
))
1031 (define-key rmail-summary-mode-map
[menu-bar delete undelete
]
1032 '("Undelete" . rmail-summary-undelete
))
1034 (define-key rmail-summary-mode-map
[menu-bar delete delete
]
1035 '("Delete" . rmail-summary-delete-forward
))
1037 (define-key rmail-summary-mode-map
[menu-bar move
]
1038 (cons "Move" (make-sparse-keymap "Move")))
1040 (define-key rmail-summary-mode-map
[menu-bar move search-back
]
1041 '("Search Back..." . rmail-summary-search-backward
))
1043 (define-key rmail-summary-mode-map
[menu-bar move search
]
1044 '("Search..." . rmail-summary-search
))
1046 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1047 '("Previous Nondeleted" . rmail-summary-previous-msg
))
1049 (define-key rmail-summary-mode-map
[menu-bar move next
]
1050 '("Next Nondeleted" . rmail-summary-next-msg
))
1052 (define-key rmail-summary-mode-map
[menu-bar move last
]
1053 '("Last" . rmail-summary-last-message
))
1055 (define-key rmail-summary-mode-map
[menu-bar move first
]
1056 '("First" . rmail-summary-first-message
))
1058 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1059 '("Previous" . rmail-summary-previous-all
))
1061 (define-key rmail-summary-mode-map
[menu-bar move next
]
1062 '("Next" . rmail-summary-next-all
))
1064 (defun rmail-summary-mouse-goto-message (event)
1065 "Select the message whose summary line you click on."
1067 (goto-char (posn-point (event-end event
)))
1068 (rmail-summary-goto-msg))
1070 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail
)
1071 "Go to message N in the summary buffer and the Rmail buffer.
1072 If N is nil, use the message corresponding to point in the summary
1073 and move to that message in the Rmail buffer.
1075 If NOWARN, don't say anything if N is out of range.
1076 If SKIP-RMAIL, don't do anything to the Rmail buffer."
1078 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1079 (if (eobp) (forward-line -
1))
1081 (let* ((obuf (current-buffer))
1085 (curmsg (string-to-number
1086 (buffer-substring (point)
1087 (min (point-max) (+ 6 (point))))))
1088 (total (save-excursion (set-buffer buf
) rmail-total-messages
)))
1089 ;; If message number N was specified, find that message's line
1090 ;; or set message-not-found.
1091 ;; If N wasn't specified or that message can't be found.
1092 ;; set N by default.
1096 (progn (message "No preceding message")
1098 (if (and (> n total
)
1100 (progn (message "No following message")
1101 (goto-char (point-max))
1102 (rmail-summary-goto-msg nil nowarn skip-rmail
)))
1103 (goto-char (point-min))
1104 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1105 (progn (or nowarn
(message "Message %d not found" n
))
1107 (setq message-not-found t
)
1110 (skip-chars-forward " ")
1111 (skip-chars-forward "0-9")
1112 (save-excursion (if (= (following-char) ?-
)
1113 (let ((buffer-read-only nil
))
1116 (rmail-summary-update-highlight message-not-found
)
1120 (let ((selwin (selected-window)))
1122 (progn (pop-to-buffer buf
)
1123 (rmail-show-message n
))
1124 (select-window selwin
)
1125 ;; The actions above can alter the current buffer. Preserve it.
1126 (set-buffer obuf
))))))
1128 ;; Update the highlighted line in an rmail summary buffer.
1129 ;; That should be current. We highlight the line point is on.
1130 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1131 (defun rmail-summary-update-highlight (not-found)
1132 ;; Make sure we have an overlay to use.
1133 (or rmail-summary-overlay
1135 (make-local-variable 'rmail-summary-overlay
)
1136 (setq rmail-summary-overlay
(make-overlay (point) (point)))))
1137 ;; If this message is in the summary, use the overlay to highlight it.
1138 ;; Otherwise, don't highlight anything.
1140 (overlay-put rmail-summary-overlay
'face nil
)
1141 (move-overlay rmail-summary-overlay
1142 (save-excursion (beginning-of-line)
1143 (skip-chars-forward " ")
1145 (save-excursion (end-of-line) (point)))
1146 (overlay-put rmail-summary-overlay
'face
'highlight
)))
1148 (defun rmail-summary-scroll-msg-up (&optional dist
)
1149 "Scroll the Rmail window forward.
1150 If the Rmail window is displaying the end of a message,
1151 advance to the next message."
1154 (rmail-summary-scroll-msg-down nil
)
1155 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer
)))
1156 (if rmail-buffer-window
1157 (if (let ((rmail-summary-window (selected-window)))
1158 (select-window rmail-buffer-window
)
1160 ;; Is EOB visible in the buffer?
1162 (let ((ht (window-height (selected-window))))
1163 (move-to-window-line (- ht
2))
1166 (select-window rmail-summary-window
)))
1167 (if (not rmail-summary-scroll-between-messages
)
1168 (error "End of buffer")
1169 (rmail-summary-next-msg (or dist
1)))
1170 (let ((other-window-scroll-buffer rmail-view-buffer
))
1171 (scroll-other-window dist
)))
1172 ;; If it isn't visible at all, show the beginning.
1173 (rmail-summary-beginning-of-message)))))
1175 (defun rmail-summary-scroll-msg-down (&optional dist
)
1176 "Scroll the Rmail window backward.
1177 If the Rmail window is now displaying the beginning of a message,
1178 move to the previous message."
1181 (rmail-summary-scroll-msg-up nil
)
1182 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer
)))
1183 (if rmail-buffer-window
1184 (if (let ((rmail-summary-window (selected-window)))
1185 (select-window rmail-buffer-window
)
1187 ;; Is BOB visible in the buffer?
1189 (move-to-window-line 0)
1192 (select-window rmail-summary-window
)))
1193 (if (not rmail-summary-scroll-between-messages
)
1194 (error "Beginning of buffer")
1195 (rmail-summary-previous-msg (or dist
1)))
1196 (let ((other-window-scroll-buffer rmail-view-buffer
))
1197 (scroll-other-window-down dist
)))
1198 ;; If it isn't visible at all, show the beginning.
1199 (rmail-summary-beginning-of-message)))))
1201 (defun rmail-summary-beginning-of-message ()
1202 "Show current message from the beginning."
1204 (rmail-summary-show-message 'BEG
))
1206 (defun rmail-summary-end-of-message ()
1207 "Show bottom of current message."
1209 (rmail-summary-show-message 'END
))
1211 (defun rmail-summary-show-message (where)
1212 "Show current mail message.
1213 Position it according to WHERE which can be BEG or END"
1214 (if (and (one-window-p) (not pop-up-frames
))
1215 ;; If there is just one window, put the summary on the top.
1216 (let ((buffer rmail-view-buffer
))
1217 (split-window (selected-window) rmail-summary-window-size
)
1218 (select-window (frame-first-window))
1219 (pop-to-buffer rmail-view-buffer
)
1220 ;; If pop-to-buffer did not use that window, delete that
1221 ;; window. (This can happen if it uses another frame.)
1222 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1223 (delete-other-windows)))
1224 (pop-to-buffer rmail-view-buffer
))
1227 (goto-char (point-min))
1228 (search-forward "\n\n"))
1230 (goto-char (point-max))
1231 (recenter (1- (window-height))))
1233 (pop-to-buffer rmail-summary-buffer
))
1235 (defun rmail-summary-bury ()
1236 "Bury the Rmail buffer and the Rmail summary buffer."
1238 (let ((buffer-to-bury (current-buffer)))
1240 (while (setq window
(get-buffer-window rmail-buffer
))
1241 (set-window-buffer window
(other-buffer rmail-buffer
)))
1242 (bury-buffer rmail-buffer
))
1243 (switch-to-buffer (other-buffer buffer-to-bury
))
1244 (bury-buffer buffer-to-bury
)))
1246 (defun rmail-summary-quit ()
1247 "Quit out of Rmail and Rmail summary."
1249 (rmail-summary-wipe)
1252 (defun rmail-summary-wipe ()
1253 "Kill and wipe away Rmail summary, remaining within Rmail."
1255 (save-excursion (set-buffer rmail-buffer
) (setq rmail-summary-buffer nil
))
1256 (let ((local-rmail-buffer rmail-view-buffer
))
1257 (kill-buffer (current-buffer))
1258 ;; Delete window if not only one.
1259 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1261 ;; Switch windows to the rmail buffer, or switch to it in this window.
1262 (pop-to-buffer local-rmail-buffer
)))
1264 (defun rmail-summary-expunge ()
1265 "Actually erase all deleted messages and recompute summary headers."
1268 (set-buffer rmail-buffer
)
1269 (when (rmail-expunge-confirmed)
1270 (rmail-only-expunge)))
1271 (rmail-update-summary))
1273 (defun rmail-summary-expunge-and-save ()
1274 "Expunge and save RMAIL file."
1277 (set-buffer rmail-buffer
)
1278 (when (rmail-expunge-confirmed)
1279 (rmail-only-expunge)))
1280 (rmail-update-summary)
1282 (set-buffer rmail-buffer
)
1284 (set-buffer-modified-p nil
))
1286 (defun rmail-summary-get-new-mail (&optional file-name
)
1287 "Get new mail and recompute summary headers.
1289 Optionally you can specify the file to get new mail from. In this case,
1290 the file of new mail is not changed or deleted. Noninteractively, you can
1291 pass the inbox file name as an argument. Interactively, a prefix
1292 argument says to read a file name and use that file as the inbox."
1294 (list (if current-prefix-arg
1295 (read-file-name "Get new mail from file: "))))
1298 (set-buffer rmail-buffer
)
1299 (rmail-get-new-mail file-name
)
1300 ;; Get the proper new message number.
1301 (setq msg rmail-current-message
))
1302 ;; Make sure that message is displayed.
1304 (rmail-summary-goto-msg msg
))))
1306 (defun rmail-summary-input (filename)
1307 "Run Rmail on file FILENAME."
1308 (interactive "FRun rmail on RMAIL file: ")
1309 ;; We switch windows here, then display the other Rmail file there.
1310 (pop-to-buffer rmail-buffer
)
1313 (defun rmail-summary-first-message ()
1314 "Show first message in Rmail file from summary buffer."
1317 (beginning-of-buffer)))
1319 (defun rmail-summary-last-message ()
1320 "Show last message in Rmail file from summary buffer."
1326 (declare-function rmail-abort-edit
"rmailedit" ())
1327 (declare-function rmail-cease-edit
"rmailedit"())
1328 (declare-function rmail-set-label
"rmailkwd" (l state
&optional n
))
1329 (declare-function rmail-output-read-file-name
"rmailout" ())
1330 (declare-function rmail-output-read-rmail-file-name
"rmailout" ())
1331 (declare-function mail-send-and-exit
"sendmail" (&optional arg
))
1333 (defvar rmail-summary-edit-map nil
)
1334 (if rmail-summary-edit-map
1336 (setq rmail-summary-edit-map
1337 (nconc (make-sparse-keymap) text-mode-map
))
1338 (define-key rmail-summary-edit-map
"\C-c\C-c" 'rmail-cease-edit
)
1339 (define-key rmail-summary-edit-map
"\C-c\C-]" 'rmail-abort-edit
))
1341 (defun rmail-summary-edit-current-message ()
1342 "Edit the contents of this message."
1344 (pop-to-buffer rmail-buffer
)
1345 (rmail-edit-current-message)
1346 (use-local-map rmail-summary-edit-map
))
1348 (defun rmail-summary-cease-edit ()
1349 "Finish editing message, then go back to Rmail summary buffer."
1352 (pop-to-buffer rmail-summary-buffer
))
1354 (defun rmail-summary-abort-edit ()
1355 "Abort edit of current message; restore original contents.
1356 Go back to summary buffer."
1359 (pop-to-buffer rmail-summary-buffer
))
1361 (defun rmail-summary-search-backward (regexp &optional n
)
1362 "Show message containing next match for REGEXP.
1363 Prefix argument gives repeat count; negative argument means search
1364 backwards (through earlier messages).
1365 Interactively, empty argument means use same regexp used last time."
1367 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1369 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1373 (if rmail-search-last-regexp
1374 (concat ", default "
1375 rmail-search-last-regexp
"): ")
1377 (setq regexp
(read-string prompt
))
1378 (cond ((not (equal regexp
""))
1379 (setq rmail-search-last-regexp regexp
))
1380 ((not rmail-search-last-regexp
)
1381 (error "No previous Rmail search string")))
1382 (list rmail-search-last-regexp
1383 (prefix-numeric-value current-prefix-arg
))))
1384 ;; Don't use save-excursion because that prevents point from moving
1385 ;; properly in the summary buffer.
1386 (let ((buffer (current-buffer)))
1389 (set-buffer rmail-buffer
)
1390 (rmail-search regexp
(- n
)))
1391 (set-buffer buffer
))))
1393 (defun rmail-summary-search (regexp &optional n
)
1394 "Show message containing next match for REGEXP.
1395 Prefix argument gives repeat count; negative argument means search
1396 backwards (through earlier messages).
1397 Interactively, empty argument means use same regexp used last time."
1399 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1401 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1405 (if rmail-search-last-regexp
1406 (concat ", default "
1407 rmail-search-last-regexp
"): ")
1409 (setq regexp
(read-string prompt
))
1410 (cond ((not (equal regexp
""))
1411 (setq rmail-search-last-regexp regexp
))
1412 ((not rmail-search-last-regexp
)
1413 (error "No previous Rmail search string")))
1414 (list rmail-search-last-regexp
1415 (prefix-numeric-value current-prefix-arg
))))
1416 ;; Don't use save-excursion because that prevents point from moving
1417 ;; properly in the summary buffer.
1418 (let ((buffer (current-buffer)))
1421 (set-buffer rmail-buffer
)
1422 (rmail-search regexp n
))
1423 (set-buffer buffer
))))
1425 (defun rmail-summary-toggle-header ()
1426 "Show original message header if pruned header currently shown, or vice versa."
1428 (save-window-excursion
1429 (set-buffer rmail-buffer
)
1430 (rmail-toggle-header))
1431 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1432 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1433 (let ((window (get-buffer-window rmail-view-buffer
)))
1435 ;; Using save-window-excursion would lose the new value of point.
1436 (let ((owin (selected-window)))
1439 (select-window window
)
1440 (goto-char (point-min)))
1441 (select-window owin
))))))
1444 (defun rmail-summary-add-label (label)
1445 "Add LABEL to labels associated with current Rmail message.
1446 Completion is performed over known labels when reading."
1447 (interactive (list (save-excursion
1448 (set-buffer rmail-buffer
)
1449 (rmail-read-label "Add label"))))
1451 (set-buffer rmail-buffer
)
1452 (rmail-add-label label
)))
1454 (defun rmail-summary-kill-label (label)
1455 "Remove LABEL from labels associated with current Rmail message.
1456 Completion is performed over known labels when reading."
1457 (interactive (list (save-excursion
1458 (set-buffer rmail-buffer
)
1459 (rmail-read-label "Kill label"))))
1461 (set-buffer rmail-buffer
)
1462 (rmail-set-label label nil
)))
1464 ;;;; *** Rmail Summary Mailing Commands ***
1466 (defun rmail-summary-override-mail-send-and-exit ()
1467 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1468 (use-local-map (copy-keymap (current-local-map)))
1469 (dolist (key (where-is-internal 'mail-send-and-exit
))
1470 (define-key (current-local-map) key
'rmail-summary-send-and-exit
)))
1472 (defun rmail-summary-mail ()
1473 "Send mail in another window.
1474 While composing the message, use \\[mail-yank-original] to yank the
1475 original message into it."
1477 (let ((window (get-buffer-window rmail-buffer
)))
1479 (select-window window
)
1480 (set-buffer rmail-buffer
)))
1481 (rmail-start-mail nil nil nil nil nil
(current-buffer))
1482 (rmail-summary-override-mail-send-and-exit))
1484 (defun rmail-summary-continue ()
1485 "Continue composing outgoing message previously being composed."
1487 (let ((window (get-buffer-window rmail-buffer
)))
1489 (select-window window
)
1490 (set-buffer rmail-buffer
)))
1491 (rmail-start-mail t
))
1493 (defun rmail-summary-reply (just-sender)
1494 "Reply to the current message.
1495 Normally include CC: to all other recipients of original message;
1496 prefix argument means ignore them. While composing the reply,
1497 use \\[mail-yank-original] to yank the original message into it."
1499 (let ((window (get-buffer-window rmail-view-buffer
)))
1501 (select-window window
)
1502 (set-buffer rmail-view-buffer
)))
1503 (rmail-reply just-sender
)
1504 (rmail-summary-override-mail-send-and-exit))
1506 (defun rmail-summary-retry-failure ()
1507 "Edit a mail message which is based on the contents of the current message.
1508 For a message rejected by the mail system, extract the interesting headers and
1509 the body of the original message; otherwise copy the current message."
1511 (let ((window (get-buffer-window rmail-buffer
)))
1513 (select-window window
)
1514 (set-buffer rmail-buffer
)))
1515 (rmail-retry-failure)
1516 (rmail-summary-override-mail-send-and-exit))
1518 (defun rmail-summary-send-and-exit ()
1519 "Send mail reply and return to summary buffer."
1521 (mail-send-and-exit t
))
1523 (defun rmail-summary-forward (resend)
1524 "Forward the current message to another user.
1525 With prefix argument, \"resend\" the message instead of forwarding it;
1526 see the documentation of `rmail-resend'."
1529 (let ((window (get-buffer-window rmail-buffer
)))
1531 (select-window window
)
1532 (set-buffer rmail-buffer
)))
1533 (rmail-forward resend
)
1534 (rmail-summary-override-mail-send-and-exit)))
1536 (defun rmail-summary-resend ()
1537 "Resend current message using `rmail-resend'."
1540 (let ((window (get-buffer-window rmail-buffer
)))
1542 (select-window window
)
1543 (set-buffer rmail-buffer
)))
1544 (call-interactively 'rmail-resend
)))
1546 ;; Summary output commands.
1548 (defun rmail-summary-output-to-rmail-file (&optional file-name n
)
1549 "Append the current message to an Rmail file named FILE-NAME.
1550 If the file does not exist, ask if it should be created.
1551 If file is being visited, the message is appended to the Emacs
1552 buffer visiting that file.
1554 A prefix argument N says to output N consecutive messages
1555 starting with the current one. Deleted messages are skipped and don't count."
1557 (progn (require 'rmailout
)
1558 (list (rmail-output-read-rmail-file-name)
1559 (prefix-numeric-value current-prefix-arg
))))
1560 (let ((i 0) prev-msg
)
1563 (progn (rmail-summary-goto-msg)
1566 (with-current-buffer rmail-buffer
1567 rmail-current-message
))))))
1569 (with-current-buffer rmail-buffer
1570 (let ((rmail-delete-after-output nil
))
1571 (rmail-output-to-rmail-file file-name
1)))
1572 (if rmail-delete-after-output
1573 (rmail-summary-delete-forward nil
)
1575 (rmail-summary-next-msg 1))))))
1577 (defun rmail-summary-output (&optional file-name n
)
1578 "Append this message to Unix mail file named FILE-NAME.
1580 A prefix argument N says to output N consecutive messages
1581 starting with the current one. Deleted messages are skipped and don't count."
1583 (progn (require 'rmailout
)
1584 (list (rmail-output-read-file-name)
1585 (prefix-numeric-value current-prefix-arg
))))
1586 (let ((i 0) prev-msg
)
1589 (progn (rmail-summary-goto-msg)
1592 (with-current-buffer rmail-buffer
1593 rmail-current-message
))))))
1595 (with-current-buffer rmail-buffer
1596 (let ((rmail-delete-after-output nil
))
1597 (rmail-output file-name
1)))
1598 (if rmail-delete-after-output
1599 (rmail-summary-delete-forward nil
)
1601 (rmail-summary-next-msg 1))))))
1603 (defun rmail-summary-output-menu ()
1604 "Output current message to another Rmail file, chosen with a menu.
1605 Also set the default for subsequent \\[rmail-output-to-rmail-file] commands.
1606 The variables `rmail-secondary-file-directory' and
1607 `rmail-secondary-file-regexp' control which files are offered in the menu."
1610 (set-buffer rmail-buffer
)
1611 (let ((rmail-delete-after-output nil
))
1612 (call-interactively 'rmail-output-menu
)))
1613 (if rmail-delete-after-output
1614 (rmail-summary-delete-forward nil
)))
1616 (defun rmail-summary-construct-io-menu ()
1617 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1620 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1621 (cons "Input Rmail File"
1622 (rmail-list-to-menu "Input Rmail File"
1624 'rmail-summary-input
)))
1625 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1626 (cons "Output Rmail File"
1627 (rmail-list-to-menu "Output Rmail File"
1629 'rmail-summary-output-to-rmail-file
))))
1630 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1631 '("Input Rmail File" . rmail-disable-menu
))
1632 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1633 '("Output Rmail File" . rmail-disable-menu
)))))
1635 (defun rmail-summary-output-body (&optional file-name
)
1636 "Write this message body to the file FILE-NAME.
1637 FILE-NAME defaults, interactively, from the Subject field of the message."
1640 (set-buffer rmail-buffer
)
1641 (let ((rmail-delete-after-output nil
))
1643 (rmail-output-body-to-file file-name
)
1644 (call-interactively 'rmail-output-body-to-file
))))
1645 (if rmail-delete-after-output
1646 (rmail-summary-delete-forward nil
)))
1648 ;; Sorting messages in Rmail Summary buffer.
1650 (defun rmail-summary-sort-by-date (reverse)
1651 "Sort messages of current Rmail summary by date.
1652 If prefix argument REVERSE is non-nil, sort them in reverse order."
1654 (rmail-sort-from-summary (function rmail-sort-by-date
) reverse
))
1656 (defun rmail-summary-sort-by-subject (reverse)
1657 "Sort messages of current Rmail summary by subject.
1658 If prefix argument REVERSE is non-nil, sort them in reverse order."
1660 (rmail-sort-from-summary (function rmail-sort-by-subject
) reverse
))
1662 (defun rmail-summary-sort-by-author (reverse)
1663 "Sort messages of current Rmail summary by author.
1664 If prefix argument REVERSE is non-nil, sort them in reverse order."
1666 (rmail-sort-from-summary (function rmail-sort-by-author
) reverse
))
1668 (defun rmail-summary-sort-by-recipient (reverse)
1669 "Sort messages of current Rmail summary by recipient.
1670 If prefix argument REVERSE is non-nil, sort them in reverse order."
1672 (rmail-sort-from-summary (function rmail-sort-by-recipient
) reverse
))
1674 (defun rmail-summary-sort-by-correspondent (reverse)
1675 "Sort messages of current Rmail summary by other correspondent.
1676 If prefix argument REVERSE is non-nil, sort them in reverse order."
1678 (rmail-sort-from-summary (function rmail-sort-by-correspondent
) reverse
))
1680 (defun rmail-summary-sort-by-lines (reverse)
1681 "Sort messages of current Rmail summary by lines of the message.
1682 If prefix argument REVERSE is non-nil, sort them in reverse order."
1684 (rmail-sort-from-summary (function rmail-sort-by-lines
) reverse
))
1686 (defun rmail-summary-sort-by-labels (reverse labels
)
1687 "Sort messages of current Rmail summary by labels.
1688 If prefix argument REVERSE is non-nil, sort them in reverse order.
1689 KEYWORDS is a comma-separated list of labels."
1690 (interactive "P\nsSort by labels: ")
1691 (rmail-sort-from-summary
1692 (function (lambda (reverse)
1693 (rmail-sort-by-labels reverse labels
)))
1696 (defun rmail-sort-from-summary (sortfun reverse
)
1697 "Sort Rmail messages from Summary buffer and update it after sorting."
1698 (require 'rmailsort
)
1699 (let ((selwin (selected-window)))
1701 (progn (pop-to-buffer rmail-buffer
)
1702 (funcall sortfun reverse
))
1703 (select-window selwin
))))
1707 ;;; arch-tag: 556079ee-75c1-47f5-9884-2e0a0bc6c5a1
1708 ;;; rmailsum.el ends here