1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001
4 ;; 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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, 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.
34 ;; For rmail-select-summary
38 (defcustom rmail-summary-scroll-between-messages t
39 "*Non-nil means Rmail summary scroll commands move between messages."
41 :group 'rmail-summary)
44 (defcustom rmail-summary-line-count-flag t
45 "*Non-nil means Rmail summary should show the number of lines in each message."
47 :group 'rmail-summary)
49 (defvar rmail-summary-font-lock-keywords
50 '(("^.....D.*" . font-lock-string-face) ; Deleted.
51 ("^.....-.*" . font-lock-type-face) ; Unread.
52 ;; Neither of the below will be highlighted if either of the above are:
53 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date.
54 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face)) ; Labels.
55 "Additional expressions to highlight in Rmail Summary mode.")
57 (defvar rmail-summary-redo
58 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
60 (defvar rmail-summary-overlay nil)
61 (put 'rmail-summary-overlay 'permanent-local t)
63 (defvar rmail-summary-mode-map nil)
65 ;; Entry points for making a summary buffer.
67 ;; Regenerate the contents of the summary
68 ;; using the same selection criterion as last time.
69 ;; M-x revert-buffer in a summary buffer calls this function.
70 (defun rmail-update-summary (&rest ignore)
71 (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
74 (defun rmail-summary ()
75 "Display a summary of all messages, one line per message."
77 (rmail-new-summary "All" '(rmail-summary) nil))
80 (defun rmail-summary-by-labels (labels)
81 "Display a summary of all messages with one or more LABELS.
82 LABELS should be a string containing the desired labels, separated by commas."
83 (interactive "sLabels to summarize by: ")
84 (if (string= labels "")
85 (setq labels (or rmail-last-multi-labels
86 (error "No label specified"))))
87 (setq rmail-last-multi-labels labels)
88 (rmail-new-summary (concat "labels " labels)
89 (list 'rmail-summary-by-labels labels)
90 'rmail-message-labels-p
91 (concat ", \\(" (mail-comma-list-regexp labels) "\\),")))
94 (defun rmail-summary-by-recipients (recipients &optional primary-only)
95 "Display a summary of all messages with the given RECIPIENTS.
96 Normally checks the To, From and Cc fields of headers;
97 but if PRIMARY-ONLY is non-nil (prefix arg given),
98 only look in the To and From fields.
99 RECIPIENTS is a string of regexps separated by commas."
100 (interactive "sRecipients to summarize by: \nP")
102 (concat "recipients " recipients)
103 (list 'rmail-summary-by-recipients recipients primary-only)
104 'rmail-message-recipients-p
105 (mail-comma-list-regexp recipients) primary-only))
108 (defun rmail-summary-by-regexp (regexp)
109 "Display a summary of all messages according to regexp REGEXP.
110 If the regular expression is found in the header of the message
111 \(including in the date and other lines, as well as the subject line),
112 Emacs will list the header line in the RMAIL-summary."
113 (interactive "sRegexp to summarize by: ")
114 (if (string= regexp "")
115 (setq regexp (or rmail-last-regexp
116 (error "No regexp specified"))))
117 (setq rmail-last-regexp regexp)
118 (rmail-new-summary (concat "regexp " regexp)
119 (list 'rmail-summary-by-regexp regexp)
120 'rmail-message-regexp-p
123 ;; rmail-summary-by-topic
124 ;; 1989 R.A. Schnitzler
127 (defun rmail-summary-by-topic (subject &optional whole-message)
128 "Display a summary of all messages with the given SUBJECT.
129 Normally checks the Subject field of headers;
130 but if WHOLE-MESSAGE is non-nil (prefix arg given),
131 look in the whole message.
132 SUBJECT is a string of regexps separated by commas."
133 (interactive "sTopics to summarize by: \nP")
135 (concat "about " subject)
136 (list 'rmail-summary-by-topic subject whole-message)
137 'rmail-message-subject-p
138 (mail-comma-list-regexp subject) whole-message))
140 (defun rmail-message-subject-p (msg subject &optional whole-message)
142 (goto-char (rmail-msgbeg msg))
143 (search-forward "\n*** EOOH ***\n" (rmail-msgend msg) 'move)
146 (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
147 (goto-char (point-min))
148 (if whole-message (re-search-forward subject nil t)
149 (string-match subject (let ((subj (mail-fetch-field "Subject")))
151 (funcall rmail-summary-line-decoder subj)
155 (defun rmail-summary-by-senders (senders)
156 "Display a summary of all messages with the given SENDERS.
157 SENDERS is a string of names separated by commas."
158 (interactive "sSenders to summarize by: ")
160 (concat "senders " senders)
161 (list 'rmail-summary-by-senders senders)
162 'rmail-message-senders-p
163 (mail-comma-list-regexp senders)))
165 (defun rmail-message-senders-p (msg senders)
167 (goto-char (rmail-msgbeg msg))
168 (search-forward "\n*** EOOH ***\n")
169 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
170 (string-match senders (or (mail-fetch-field "From") ""))))
172 ;; General making of a summary buffer.
174 (defvar rmail-summary-symbol-number 0)
176 (defvar rmail-new-summary-line-count)
178 (defun rmail-new-summary (description redo-form function &rest args)
179 "Create a summary of selected messages.
180 DESCRIPTION makes part of the mode line of the summary buffer.
181 For each message, FUNCTION is applied to the message number and ARGS...
182 and if the result is non-nil, that message is included.
183 nil for FUNCTION means all messages."
184 (message "Computing summary lines...")
185 (let (sumbuf mesg was-in-summary)
187 ;; Go to the Rmail buffer.
188 (if (eq major-mode 'rmail-summary-mode)
189 (setq was-in-summary t))
190 (set-buffer rmail-buffer)
191 ;; Find its summary buffer, or make one.
193 (if (and rmail-summary-buffer
194 (buffer-name rmail-summary-buffer))
196 (generate-new-buffer (concat (buffer-name) "-summary"))))
197 (setq mesg rmail-current-message)
198 ;; Filter the messages; make or get their summary lines.
199 (let ((summary-msgs ())
200 (rmail-new-summary-line-count 0))
202 (buffer-read-only nil)
203 (old-min (point-min-marker))
204 (old-max (point-max-marker)))
205 ;; Can't use save-restriction here; that doesn't work if we
206 ;; plan to modify text outside the original restriction.
209 (goto-char (point-min))
210 (while (>= rmail-total-messages msgnum)
211 (if (or (null function)
212 (apply function (cons msgnum args)))
214 (cons (cons msgnum (rmail-make-summary-line msgnum))
216 (setq msgnum (1+ msgnum)))
217 (setq summary-msgs (nreverse summary-msgs)))
218 (narrow-to-region old-min old-max))
219 ;; Temporarily, while summary buffer is unfinished,
220 ;; we "don't have" a summary.
221 (setq rmail-summary-buffer nil)
222 (if rmail-enable-mime
223 (with-current-buffer rmail-view-buffer
224 (setq rmail-summary-buffer nil)))
226 (let ((rbuf (current-buffer))
227 (vbuf rmail-view-buffer)
228 (total rmail-total-messages))
230 ;; Set up the summary buffer's contents.
231 (let ((buffer-read-only nil))
234 (princ (cdr (car summary-msgs)) sumbuf)
235 (setq summary-msgs (cdr summary-msgs)))
236 (goto-char (point-min)))
237 ;; Set up the rest of its state and local variables.
238 (setq buffer-read-only t)
240 (make-local-variable 'minor-mode-alist)
241 (setq minor-mode-alist (list (list t (concat ": " description))))
242 (setq rmail-buffer rbuf
243 rmail-view-buffer vbuf
244 rmail-summary-redo redo-form
245 rmail-total-messages total))))
246 (setq rmail-summary-buffer sumbuf))
247 ;; Now display the summary buffer and go to the right place in it.
250 (if (and (one-window-p)
251 pop-up-windows (not pop-up-frames))
252 ;; If there is just one window, put the summary on the top.
254 (split-window (selected-window) rmail-summary-window-size)
255 (select-window (next-window (frame-first-window)))
256 (pop-to-buffer sumbuf)
257 ;; If pop-to-buffer did not use that window, delete that
258 ;; window. (This can happen if it uses another frame.)
259 (if (not (eq sumbuf (window-buffer (frame-first-window))))
260 (delete-other-windows)))
261 (pop-to-buffer sumbuf))
262 (set-buffer rmail-buffer)
263 ;; This is how rmail makes the summary buffer reappear.
264 ;; We do this here to make the window the proper size.
265 (rmail-select-summary nil)
266 (set-buffer rmail-summary-buffer)))
267 (rmail-summary-goto-msg mesg t t)
268 (rmail-summary-construct-io-menu)
269 (message "Computing summary lines...done")))
271 ;; Low levels of generating a summary.
273 (defun rmail-make-summary-line (msg)
274 (let ((line (or (aref rmail-summary-vector (1- msg))
276 (setq rmail-new-summary-line-count
277 (1+ rmail-new-summary-line-count))
278 (if (zerop (% rmail-new-summary-line-count 10))
279 (message "Computing summary lines...%d"
280 rmail-new-summary-line-count))
281 (rmail-make-summary-line-1 msg)))))
282 ;; Fix up the part of the summary that says "deleted" or "unseen".
284 (if (rmail-message-deleted-p msg) ?\D
285 (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg))))
290 (defcustom rmail-summary-line-decoder (function identity)
291 "*Function to decode summary-line.
293 By default, `identity' is set."
295 :group 'rmail-summary)
297 (defun rmail-make-summary-line-1 (msg)
298 (goto-char (rmail-msgbeg msg))
299 (let* ((lim (save-excursion (forward-line 2) (point)))
305 ; (if (save-excursion (re-search-forward ",answered," lim t))
307 ; (if (save-excursion (re-search-forward ",filed," lim t))
309 (if (progn (search-forward ",,") (eolp))
312 (buffer-substring (point)
322 (if (looking-at "Summary-line: ")
324 (goto-char (match-end 0))
326 (buffer-substring (point)
327 (progn (forward-line 1) (point)))))))))
328 ;; Obsolete status lines lacking a # should be flushed.
330 (not (string-match "#" line))
332 (delete-region (point)
333 (progn (forward-line -1) (point)))
335 ;; If we didn't get a valid status line from the message,
336 ;; make a new one and put it in the message.
338 (let* ((case-fold-search t)
339 (next (rmail-msgend msg))
340 (beg (if (progn (goto-char (rmail-msgbeg msg))
341 (search-forward "\n*** EOOH ***\n" next t))
345 (end (progn (search-forward "\n\n" nil t) (point))))
347 (narrow-to-region beg end)
349 (setq line (rmail-make-basic-summary-line)))
350 (goto-char (rmail-msgbeg msg))
352 (insert "Summary-line: " line)))
353 (setq pos (string-match "#" line))
354 (aset rmail-summary-vector (1- msg)
355 (funcall rmail-summary-line-decoder
356 (concat (format "%5d " msg)
357 (substring line 0 pos)
359 (substring line (1+ pos)))))
363 (defcustom rmail-user-mail-address-regexp nil
364 "*Regexp matching user mail addresses.
365 If non-nil, this variable is used to identify the correspondent
366 when receiving new mail. If it matches the address of the sender,
367 the recipient is taken as correspondent of a mail.
368 If nil \(default value\), your `user-login-name' and `user-mail-address'
369 are used to exclude yourself as correspondent.
371 Usually you don't have to set this variable, except if you collect mails
372 sent by you under different user names.
373 Then it should be a regexp matching your mail addresses.
375 Setting this variable has an effect only before reading a mail."
376 :type '(choice (const :tag "None" nil) regexp)
377 :group 'rmail-retrieve
380 (defun rmail-make-basic-summary-line ()
381 (goto-char (point-min))
382 (concat (save-excursion
383 (if (not (re-search-forward "^Date:" nil t))
385 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
386 (save-excursion (end-of-line) (point)) t)
388 (string-to-number (buffer-substring
392 (match-beginning 4) (match-end 4))))
393 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
394 (save-excursion (end-of-line) (point)) t)
396 (string-to-number (buffer-substring
400 (match-beginning 2) (match-end 2))))
401 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
402 (save-excursion (end-of-line) (point)) t)
405 (match-beginning 2) (match-end 2))
407 (match-beginning 3) (match-end 3))
409 (match-beginning 4) (match-end 4))))
413 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t)
414 (mail-strip-quoted-names
417 ;; Get all the lines of the From field
418 ;; so that we get a whole comment if there is one,
419 ;; so that mail-strip-quoted-names can discard it.
420 (let ((opoint (point)))
421 (while (progn (forward-line 1)
422 (looking-at "[ \t]")))
423 ;; Back up over newline, then trailing spaces or tabs
425 (skip-chars-backward " \t")
430 (or rmail-user-mail-address-regexp
432 (regexp-quote (user-login-name))
435 ;; Don't lose if run from init file
436 ;; where user-mail-address is not
438 (or user-mail-address
439 (concat (user-login-name) "@"
440 (or mail-host-address
444 ;; No From field, or it's this user.
446 (goto-char (point-min))
447 (if (not (re-search-forward "^To:[ \t]*" nil t))
451 (mail-strip-quoted-names
455 (skip-chars-backward " \t")
459 (setq len (length from))
460 (setq mch (string-match "[@%]" from))
462 (if (or (not mch) (<= len 25))
463 (substring from (max 0 (- len 25)))
465 (setq lo (cond ((< (- mch 14) 0) 0)
469 (min len (+ lo 25))))))))
470 (if rmail-summary-line-count-flag
474 (let ((beg (rmail-msgbeg msgnum))
475 (end (rmail-msgend msgnum))
479 ;; Count only lines in the reformatted header,
480 ;; if we have reformatted it.
481 (search-forward "\n*** EOOH ***\n" end t)
482 (setq lines (count-lines (point) end)))
484 ((<= lines 9) " [%d]")
485 ((<= lines 99) " [%d]")
486 ((<= lines 999) " [%3d]")
490 " #" ;The # is part of the format.
491 (if (re-search-forward "^Subject:" nil t)
492 (progn (skip-chars-forward " \t")
493 (buffer-substring (point)
496 (re-search-forward "[\n][\n]+" nil t)
497 (buffer-substring (point) (progn (end-of-line) (point))))
500 ;; Simple motion in a summary buffer.
502 (defun rmail-summary-next-all (&optional number)
504 (forward-line (if number number 1))
505 ;; It doesn't look nice to move forward past the last message line.
506 (and (eobp) (> number 0)
508 (display-buffer rmail-buffer))
510 (defun rmail-summary-previous-all (&optional number)
512 (forward-line (- (if number number 1)))
513 ;; It doesn't look nice to move forward past the last message line.
514 (and (eobp) (< number 0)
516 (display-buffer rmail-buffer))
518 (defun rmail-summary-next-msg (&optional number)
519 "Display next non-deleted msg from rmail file.
520 With optional prefix argument NUMBER, moves forward this number of non-deleted
521 messages, or backward if NUMBER is negative."
524 (and (> number 0) (end-of-line))
525 (let ((count (if (< number 0) (- number) number))
526 (search (if (> number 0) 're-search-forward 're-search-backward))
527 (non-del-msg-found nil))
528 (while (and (> count 0) (setq non-del-msg-found
529 (or (funcall search "^....[^D]" nil t)
531 (setq count (1- count))))
533 (display-buffer rmail-view-buffer))
535 (defun rmail-summary-previous-msg (&optional number)
536 "Display previous non-deleted msg from rmail file.
537 With optional prefix argument NUMBER, moves backward this number of
538 non-deleted messages."
540 (rmail-summary-next-msg (- (if number number 1))))
542 (defun rmail-summary-next-labeled-message (n labels)
543 "Show next message with LABELS. Defaults to last labels used.
544 With prefix argument N moves forward N messages with these labels."
545 (interactive "p\nsMove to next msg with labels: ")
548 (set-buffer rmail-buffer)
549 (rmail-next-labeled-message n labels)
550 (setq msg rmail-current-message))
551 (rmail-summary-goto-msg msg)))
553 (defun rmail-summary-previous-labeled-message (n labels)
554 "Show previous message with LABELS. Defaults to last labels used.
555 With prefix argument N moves backward N messages with these labels."
556 (interactive "p\nsMove to previous msg with labels: ")
559 (set-buffer rmail-buffer)
560 (rmail-previous-labeled-message n labels)
561 (setq msg rmail-current-message))
562 (rmail-summary-goto-msg msg)))
564 (defun rmail-summary-next-same-subject (n)
565 "Go to the next message in the summary having the same subject.
566 With prefix argument N, do this N times.
567 If N is negative, go backwards."
569 (let (subject search-regexp i found
572 (set-buffer rmail-buffer)
573 (setq subject (mail-fetch-field "Subject"))
574 (setq i rmail-current-message))
575 (if (string-match "Re:[ \t]*" subject)
576 (setq subject (substring subject (match-end 0))))
577 (setq search-regexp (concat "^Subject: *\\(Re: *\\)?"
578 (regexp-quote subject)
586 (while (and (not done)
590 ;; Advance thru summary.
591 (forward-line (if forward 1 -1))
592 ;; Get msg number of this line.
593 (setq i (string-to-number
594 (buffer-substring (point)
595 (min (point-max) (+ 6 (point))))))
596 ;; See if that msg has desired subject.
598 (set-buffer rmail-buffer)
601 (goto-char (rmail-msgbeg i))
602 (search-forward "\n*** EOOH ***\n")
603 (let ((beg (point)) end)
604 (search-forward "\n\n")
607 (setq done (re-search-forward search-regexp end t))))))
608 (if done (setq found i)))
609 (setq n (if forward (1- n) (1+ n)))))
611 (rmail-summary-goto-msg found)
612 (error "No %s message with same subject"
613 (if forward "following" "previous")))))
615 (defun rmail-summary-previous-same-subject (n)
616 "Go to the previous message in the summary having the same subject.
617 With prefix argument N, do this N times.
618 If N is negative, go forwards instead."
620 (rmail-summary-next-same-subject (- n)))
622 ;; Delete and undelete summary commands.
624 (defun rmail-summary-delete-forward (&optional count)
625 "Delete this message and move to next nondeleted one.
626 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
627 A prefix argument serves as a repeat count;
628 a negative argument means to delete and move backward."
630 (unless (numberp count) (setq count 1))
632 (backward (< count 0)))
634 (rmail-summary-goto-msg)
635 (with-current-buffer rmail-buffer
636 (rmail-delete-message)
637 (setq del-msg rmail-current-message))
638 (rmail-summary-mark-deleted del-msg)
639 (while (and (not (if backward (bobp) (eobp)))
640 (save-excursion (beginning-of-line)
641 (looking-at " *[0-9]+D")))
642 (forward-line (if backward -1 1)))
643 ;; It looks ugly to move to the empty line at end of buffer.
644 (and (eobp) (not backward)
647 (if (> count 0) (1- count) (1+ count))))))
649 (defun rmail-summary-delete-backward (&optional count)
650 "Delete this message and move to previous nondeleted one.
651 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
652 A prefix argument serves as a repeat count;
653 a negative argument means to delete and move forward."
655 (rmail-summary-delete-forward (- count)))
657 (defun rmail-summary-mark-deleted (&optional n undel)
658 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
659 (and n (rmail-summary-goto-msg n t t))
661 (not (overlay-get rmail-summary-overlay 'face))
662 (let ((buffer-read-only nil))
663 (skip-chars-forward " ")
664 (skip-chars-forward "[0-9]")
667 (progn (delete-char 1) (insert " ")))
672 (defun rmail-summary-mark-undeleted (n)
673 (rmail-summary-mark-deleted n t))
675 (defun rmail-summary-deleted-p (&optional n)
677 (and n (rmail-summary-goto-msg n nil t))
678 (skip-chars-forward " ")
679 (skip-chars-forward "[0-9]")
682 (defun rmail-summary-undelete (&optional arg)
683 "Undelete current message.
684 Optional prefix ARG means undelete ARG previous messages."
687 (rmail-summary-undelete-many arg)
688 (let ((buffer-read-only nil)
691 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
692 (replace-match "\\1 ")
693 (rmail-summary-goto-msg)
694 (if rmail-enable-mime
695 (set-buffer rmail-buffer)
696 (pop-to-buffer rmail-buffer))
697 (and (rmail-message-deleted-p rmail-current-message)
698 (rmail-undelete-previous-message))
699 (if rmail-enable-mime
700 (pop-to-buffer rmail-view-buffer))
701 (pop-to-buffer rmail-summary-buffer))
702 (t (goto-char opoint))))))
704 (defun rmail-summary-undelete-many (&optional n)
705 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
708 (set-buffer rmail-buffer)
709 (let* ((init-msg (if n rmail-current-message rmail-total-messages))
710 (rmail-current-message init-msg)
711 (n (or n rmail-total-messages))
713 (while (and (> rmail-current-message 0)
715 (if (rmail-message-deleted-p rmail-current-message)
716 (progn (rmail-set-attribute "deleted" nil)
717 (setq msgs-undeled (1+ msgs-undeled))))
718 (setq rmail-current-message (1- rmail-current-message)))
719 (set-buffer rmail-summary-buffer)
720 (setq rmail-current-message init-msg msgs-undeled 0)
721 (while (and (> rmail-current-message 0)
723 (if (rmail-summary-deleted-p rmail-current-message)
724 (progn (rmail-summary-mark-undeleted rmail-current-message)
725 (setq msgs-undeled (1+ msgs-undeled))))
726 (setq rmail-current-message (1- rmail-current-message))))
727 (rmail-summary-goto-msg)))
729 ;; Rmail Summary mode is suitable only for specially formatted data.
730 (put 'rmail-summary-mode 'mode-class 'special)
732 (defun rmail-summary-mode ()
733 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
734 As commands are issued in the summary buffer, they are applied to the
735 corresponding mail messages in the rmail buffer.
737 All normal editing commands are turned off.
738 Instead, nearly all the Rmail mode commands are available,
739 though many of them move only among the messages in the summary.
741 These additional commands exist:
743 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
744 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
746 Commands for sorting the summary:
748 \\[rmail-summary-sort-by-date] Sort by date.
749 \\[rmail-summary-sort-by-subject] Sort by subject.
750 \\[rmail-summary-sort-by-author] Sort by author.
751 \\[rmail-summary-sort-by-recipient] Sort by recipient.
752 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
753 \\[rmail-summary-sort-by-lines] Sort by lines.
754 \\[rmail-summary-sort-by-labels] Sort by labels."
756 (kill-all-local-variables)
757 (setq major-mode 'rmail-summary-mode)
758 (setq mode-name "RMAIL Summary")
759 (setq truncate-lines t)
760 (setq buffer-read-only t)
761 (set-syntax-table text-mode-syntax-table)
762 (make-local-variable 'rmail-buffer)
763 (make-local-variable 'rmail-view-buffer)
764 (make-local-variable 'rmail-total-messages)
765 (make-local-variable 'rmail-current-message)
766 (setq rmail-current-message nil)
767 (make-local-variable 'rmail-summary-redo)
768 (setq rmail-summary-redo nil)
769 (make-local-variable 'revert-buffer-function)
770 (make-local-variable 'font-lock-defaults)
771 (setq font-lock-defaults '(rmail-summary-font-lock-keywords t))
772 (rmail-summary-enable)
773 (run-mode-hooks 'rmail-summary-mode-hook))
775 ;; Summary features need to be disabled during edit mode.
776 (defun rmail-summary-disable ()
777 (use-local-map text-mode-map)
778 (remove-hook 'post-command-hook 'rmail-summary-rmail-update t)
779 (setq revert-buffer-function nil))
781 (defun rmail-summary-enable ()
782 (use-local-map rmail-summary-mode-map)
783 (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
784 (setq revert-buffer-function 'rmail-update-summary))
786 (defvar rmail-summary-put-back-unseen nil
787 "Used for communicating between calls to `rmail-summary-rmail-update'.
788 If it moves to a message within an Incremental Search, and removes
789 the `unseen' attribute from that message, it sets this flag
790 so that if the next motion between messages is in the same Incremental
791 Search, the `unseen' attribute is restored.")
793 ;; Show in Rmail the message described by the summary line that point is on,
794 ;; but only if the Rmail buffer is already visible.
795 ;; This is a post-command-hook in summary buffers.
796 (defun rmail-summary-rmail-update ()
797 (let (buffer-read-only)
799 ;; If at end of buffer, pretend we are on the last text line.
803 (skip-chars-forward " ")
804 (let ((msg-num (string-to-number (buffer-substring
806 (progn (skip-chars-forward "0-9")
808 ;; Always leave `unseen' removed
809 ;; if we get out of isearch mode.
810 ;; Don't let a subsequent isearch restore that `unseen'.
811 (if (not isearch-mode)
812 (setq rmail-summary-put-back-unseen nil))
814 (or (eq rmail-current-message msg-num)
815 (let ((window (get-buffer-window rmail-view-buffer t))
816 (owin (selected-window)))
819 (set-buffer rmail-buffer)
820 ;; If we first saw the previous message in this search,
821 ;; and we have gone to a different message while searching,
822 ;; put back `unseen' on the former one.
823 (if rmail-summary-put-back-unseen
824 (rmail-set-attribute "unseen" t
825 rmail-current-message))
826 ;; Arrange to do that later, for the new current message,
827 ;; if it still has `unseen'.
828 (setq rmail-summary-put-back-unseen
829 (rmail-message-labels-p msg-num ", ?\\(unseen\\),")))
830 (setq rmail-summary-put-back-unseen nil))
832 ;; Go to the desired message.
833 (setq rmail-current-message msg-num)
835 ;; Update the summary to show the message has been seen.
836 (if (= (following-char) ?-)
842 ;; Using save-window-excursion would cause the new value
843 ;; of point to get lost.
846 (select-window window)
847 (rmail-show-message msg-num t))
848 (select-window owin))
849 (if (buffer-name rmail-buffer)
851 (set-buffer rmail-buffer)
852 (rmail-show-message msg-num t))))))
853 (rmail-summary-update-highlight nil)))))
855 (if rmail-summary-mode-map
857 (setq rmail-summary-mode-map (make-keymap))
858 (suppress-keymap rmail-summary-mode-map)
860 (define-key rmail-summary-mode-map [mouse-2] 'rmail-summary-mouse-goto-message)
861 (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label)
862 (define-key rmail-summary-mode-map "b" 'rmail-summary-bury)
863 (define-key rmail-summary-mode-map "c" 'rmail-summary-continue)
864 (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward)
865 (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward)
866 (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message)
867 (define-key rmail-summary-mode-map "f" 'rmail-summary-forward)
868 (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail)
869 (define-key rmail-summary-mode-map "h" 'rmail-summary)
870 (define-key rmail-summary-mode-map "i" 'rmail-summary-input)
871 (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg)
872 (define-key rmail-summary-mode-map "\C-m" 'rmail-summary-goto-msg)
873 (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label)
874 (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels)
875 (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
876 (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
877 (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
878 (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
879 (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
880 (define-key rmail-summary-mode-map "m" 'rmail-summary-mail)
881 (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure)
882 (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg)
883 (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all)
884 (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
885 (define-key rmail-summary-mode-map "o" 'rmail-summary-output-to-rmail-file)
886 (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output)
887 (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg)
888 (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all)
889 (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
890 (define-key rmail-summary-mode-map "q" 'rmail-summary-quit)
891 (define-key rmail-summary-mode-map "Q" 'rmail-summary-wipe)
892 (define-key rmail-summary-mode-map "r" 'rmail-summary-reply)
893 (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save)
894 (define-key rmail-summary-mode-map "\es" 'rmail-summary-search)
895 (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header)
896 (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete)
897 (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many)
898 (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge)
899 (define-key rmail-summary-mode-map "w" 'rmail-summary-output-body)
900 (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message)
901 (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message)
902 (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message)
903 (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up)
904 (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down)
905 (define-key rmail-summary-mode-map "?" 'describe-mode)
906 (define-key rmail-summary-mode-map "\C-c\C-n" 'rmail-summary-next-same-subject)
907 (define-key rmail-summary-mode-map "\C-c\C-p" 'rmail-summary-previous-same-subject)
908 (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
909 'rmail-summary-sort-by-date)
910 (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
911 'rmail-summary-sort-by-subject)
912 (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
913 'rmail-summary-sort-by-author)
914 (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
915 'rmail-summary-sort-by-recipient)
916 (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
917 'rmail-summary-sort-by-correspondent)
918 (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
919 'rmail-summary-sort-by-lines)
920 (define-key rmail-summary-mode-map "\C-c\C-s\C-k"
921 'rmail-summary-sort-by-labels)
924 ;;; Menu bar bindings.
926 (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
928 (define-key rmail-summary-mode-map [menu-bar classify]
929 (cons "Classify" (make-sparse-keymap "Classify")))
931 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
932 '("Output (Rmail Menu)..." . rmail-summary-output-menu))
934 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
935 '("Input Rmail File (menu)..." . rmail-input-menu))
937 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
940 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
943 (define-key rmail-summary-mode-map [menu-bar classify output-body]
944 '("Output (body)..." . rmail-summary-output-body))
946 (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
947 '("Output (inbox)..." . rmail-summary-output))
949 (define-key rmail-summary-mode-map [menu-bar classify output]
950 '("Output (Rmail)..." . rmail-summary-output-to-rmail-file))
952 (define-key rmail-summary-mode-map [menu-bar classify kill-label]
953 '("Kill Label..." . rmail-summary-kill-label))
955 (define-key rmail-summary-mode-map [menu-bar classify add-label]
956 '("Add Label..." . rmail-summary-add-label))
958 (define-key rmail-summary-mode-map [menu-bar summary]
959 (cons "Summary" (make-sparse-keymap "Summary")))
961 (define-key rmail-summary-mode-map [menu-bar summary senders]
962 '("By Senders..." . rmail-summary-by-senders))
964 (define-key rmail-summary-mode-map [menu-bar summary labels]
965 '("By Labels..." . rmail-summary-by-labels))
967 (define-key rmail-summary-mode-map [menu-bar summary recipients]
968 '("By Recipients..." . rmail-summary-by-recipients))
970 (define-key rmail-summary-mode-map [menu-bar summary topic]
971 '("By Topic..." . rmail-summary-by-topic))
973 (define-key rmail-summary-mode-map [menu-bar summary regexp]
974 '("By Regexp..." . rmail-summary-by-regexp))
976 (define-key rmail-summary-mode-map [menu-bar summary all]
977 '("All" . rmail-summary))
979 (define-key rmail-summary-mode-map [menu-bar mail]
980 (cons "Mail" (make-sparse-keymap "Mail")))
982 (define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail]
983 '("Get New Mail" . rmail-summary-get-new-mail))
985 (define-key rmail-summary-mode-map [menu-bar mail lambda]
988 (define-key rmail-summary-mode-map [menu-bar mail continue]
989 '("Continue" . rmail-summary-continue))
991 (define-key rmail-summary-mode-map [menu-bar mail resend]
992 '("Re-send..." . rmail-summary-resend))
994 (define-key rmail-summary-mode-map [menu-bar mail forward]
995 '("Forward" . rmail-summary-forward))
997 (define-key rmail-summary-mode-map [menu-bar mail retry]
998 '("Retry" . rmail-summary-retry-failure))
1000 (define-key rmail-summary-mode-map [menu-bar mail reply]
1001 '("Reply" . rmail-summary-reply))
1003 (define-key rmail-summary-mode-map [menu-bar mail mail]
1004 '("Mail" . rmail-summary-mail))
1006 (define-key rmail-summary-mode-map [menu-bar delete]
1007 (cons "Delete" (make-sparse-keymap "Delete")))
1009 (define-key rmail-summary-mode-map [menu-bar delete expunge/save]
1010 '("Expunge/Save" . rmail-summary-expunge-and-save))
1012 (define-key rmail-summary-mode-map [menu-bar delete expunge]
1013 '("Expunge" . rmail-summary-expunge))
1015 (define-key rmail-summary-mode-map [menu-bar delete undelete]
1016 '("Undelete" . rmail-summary-undelete))
1018 (define-key rmail-summary-mode-map [menu-bar delete delete]
1019 '("Delete" . rmail-summary-delete-forward))
1021 (define-key rmail-summary-mode-map [menu-bar move]
1022 (cons "Move" (make-sparse-keymap "Move")))
1024 (define-key rmail-summary-mode-map [menu-bar move search-back]
1025 '("Search Back..." . rmail-summary-search-backward))
1027 (define-key rmail-summary-mode-map [menu-bar move search]
1028 '("Search..." . rmail-summary-search))
1030 (define-key rmail-summary-mode-map [menu-bar move previous]
1031 '("Previous Nondeleted" . rmail-summary-previous-msg))
1033 (define-key rmail-summary-mode-map [menu-bar move next]
1034 '("Next Nondeleted" . rmail-summary-next-msg))
1036 (define-key rmail-summary-mode-map [menu-bar move last]
1037 '("Last" . rmail-summary-last-message))
1039 (define-key rmail-summary-mode-map [menu-bar move first]
1040 '("First" . rmail-summary-first-message))
1042 (define-key rmail-summary-mode-map [menu-bar move previous]
1043 '("Previous" . rmail-summary-previous-all))
1045 (define-key rmail-summary-mode-map [menu-bar move next]
1046 '("Next" . rmail-summary-next-all))
1048 (defun rmail-summary-mouse-goto-message (event)
1049 "Select the message whose summary line you click on."
1051 (goto-char (posn-point (event-end event)))
1052 (rmail-summary-goto-msg))
1054 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
1055 "Go to message N in the summary buffer and the Rmail buffer.
1056 If N is nil, use the message corresponding to point in the summary
1057 and move to that message in the Rmail buffer.
1059 If NOWARN, don't say anything if N is out of range.
1060 If SKIP-RMAIL, don't do anything to the Rmail buffer."
1062 (if (consp n) (setq n (prefix-numeric-value n)))
1063 (if (eobp) (forward-line -1))
1065 (let* ((obuf (current-buffer))
1069 (curmsg (string-to-number
1070 (buffer-substring (point)
1071 (min (point-max) (+ 6 (point))))))
1072 (total (save-excursion (set-buffer buf) rmail-total-messages)))
1073 ;; If message number N was specified, find that message's line
1074 ;; or set message-not-found.
1075 ;; If N wasn't specified or that message can't be found.
1076 ;; set N by default.
1080 (progn (message "No preceding message")
1082 (if (and (> n total)
1084 (progn (message "No following message")
1085 (goto-char (point-max))
1086 (rmail-summary-goto-msg nil nowarn skip-rmail)))
1087 (goto-char (point-min))
1088 (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t))
1089 (progn (or nowarn (message "Message %d not found" n))
1091 (setq message-not-found t)
1094 (skip-chars-forward " ")
1095 (skip-chars-forward "0-9")
1096 (save-excursion (if (= (following-char) ?-)
1097 (let ((buffer-read-only nil))
1100 (rmail-summary-update-highlight message-not-found)
1104 (let ((selwin (selected-window)))
1106 (progn (pop-to-buffer buf)
1107 (rmail-show-message n))
1108 (select-window selwin)
1109 ;; The actions above can alter the current buffer. Preserve it.
1110 (set-buffer obuf))))))
1112 ;; Update the highlighted line in an rmail summary buffer.
1113 ;; That should be current. We highlight the line point is on.
1114 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1115 (defun rmail-summary-update-highlight (not-found)
1116 ;; Make sure we have an overlay to use.
1117 (or rmail-summary-overlay
1119 (make-local-variable 'rmail-summary-overlay)
1120 (setq rmail-summary-overlay (make-overlay (point) (point)))))
1121 ;; If this message is in the summary, use the overlay to highlight it.
1122 ;; Otherwise, don't highlight anything.
1124 (overlay-put rmail-summary-overlay 'face nil)
1125 (move-overlay rmail-summary-overlay
1126 (save-excursion (beginning-of-line)
1127 (skip-chars-forward " ")
1129 (save-excursion (end-of-line) (point)))
1130 (overlay-put rmail-summary-overlay 'face 'highlight)))
1132 (defun rmail-summary-scroll-msg-up (&optional dist)
1133 "Scroll the Rmail window forward.
1134 If the Rmail window is displaying the end of a message,
1135 advance to the next message."
1138 (rmail-summary-scroll-msg-down nil)
1139 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer)))
1140 (if rmail-buffer-window
1141 (if (let ((rmail-summary-window (selected-window)))
1142 (select-window rmail-buffer-window)
1144 ;; Is EOB visible in the buffer?
1146 (let ((ht (window-height (selected-window))))
1147 (move-to-window-line (- ht 2))
1150 (select-window rmail-summary-window)))
1151 (if (not rmail-summary-scroll-between-messages)
1152 (error "End of buffer")
1153 (rmail-summary-next-msg (or dist 1)))
1154 (let ((other-window-scroll-buffer rmail-view-buffer))
1155 (scroll-other-window dist)))
1156 ;; If it isn't visible at all, show the beginning.
1157 (rmail-summary-beginning-of-message)))))
1159 (defun rmail-summary-scroll-msg-down (&optional dist)
1160 "Scroll the Rmail window backward.
1161 If the Rmail window is now displaying the beginning of a message,
1162 move to the previous message."
1165 (rmail-summary-scroll-msg-up nil)
1166 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer)))
1167 (if rmail-buffer-window
1168 (if (let ((rmail-summary-window (selected-window)))
1169 (select-window rmail-buffer-window)
1171 ;; Is BOB visible in the buffer?
1173 (move-to-window-line 0)
1176 (select-window rmail-summary-window)))
1177 (if (not rmail-summary-scroll-between-messages)
1178 (error "Beginning of buffer")
1179 (rmail-summary-previous-msg (or dist 1)))
1180 (let ((other-window-scroll-buffer rmail-view-buffer))
1181 (scroll-other-window-down dist)))
1182 ;; If it isn't visible at all, show the beginning.
1183 (rmail-summary-beginning-of-message)))))
1185 (defun rmail-summary-beginning-of-message ()
1186 "Show current message from the beginning."
1188 (if (and (one-window-p) (not pop-up-frames))
1189 ;; If there is just one window, put the summary on the top.
1190 (let ((buffer rmail-view-buffer))
1191 (split-window (selected-window) rmail-summary-window-size)
1192 (select-window (frame-first-window))
1193 (pop-to-buffer rmail-view-buffer)
1194 ;; If pop-to-buffer did not use that window, delete that
1195 ;; window. (This can happen if it uses another frame.)
1196 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1197 (delete-other-windows)))
1198 (pop-to-buffer rmail-view-buffer))
1200 (beginning-of-buffer))
1201 (pop-to-buffer rmail-summary-buffer))
1203 (defun rmail-summary-bury ()
1204 "Bury the Rmail buffer and the Rmail summary buffer."
1206 (let ((buffer-to-bury (current-buffer)))
1208 (while (setq window (get-buffer-window rmail-buffer))
1209 (set-window-buffer window (other-buffer rmail-buffer)))
1210 (bury-buffer rmail-buffer))
1211 (switch-to-buffer (other-buffer buffer-to-bury))
1212 (bury-buffer buffer-to-bury)))
1214 (defun rmail-summary-quit ()
1215 "Quit out of Rmail and Rmail summary."
1217 (rmail-summary-wipe)
1220 (defun rmail-summary-wipe ()
1221 "Kill and wipe away Rmail summary, remaining within Rmail."
1223 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
1224 (let ((local-rmail-buffer rmail-view-buffer))
1225 (kill-buffer (current-buffer))
1226 ;; Delete window if not only one.
1227 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1229 ;; Switch windows to the rmail buffer, or switch to it in this window.
1230 (pop-to-buffer local-rmail-buffer)))
1232 (defun rmail-summary-expunge ()
1233 "Actually erase all deleted messages and recompute summary headers."
1236 (set-buffer rmail-buffer)
1237 (when (rmail-expunge-confirmed)
1238 (rmail-only-expunge)))
1239 (rmail-update-summary))
1241 (defun rmail-summary-expunge-and-save ()
1242 "Expunge and save RMAIL file."
1245 (set-buffer rmail-buffer)
1246 (when (rmail-expunge-confirmed)
1247 (rmail-only-expunge)))
1248 (rmail-update-summary)
1250 (set-buffer rmail-buffer)
1252 (set-buffer-modified-p nil))
1254 (defun rmail-summary-get-new-mail (&optional file-name)
1255 "Get new mail and recompute summary headers.
1257 Optionally you can specify the file to get new mail from. In this case,
1258 the file of new mail is not changed or deleted. Noninteractively, you can
1259 pass the inbox file name as an argument. Interactively, a prefix
1260 argument says to read a file name and use that file as the inbox."
1262 (list (if current-prefix-arg
1263 (read-file-name "Get new mail from file: "))))
1266 (set-buffer rmail-buffer)
1267 (rmail-get-new-mail file-name)
1268 ;; Get the proper new message number.
1269 (setq msg rmail-current-message))
1270 ;; Make sure that message is displayed.
1272 (rmail-summary-goto-msg msg))))
1274 (defun rmail-summary-input (filename)
1275 "Run Rmail on file FILENAME."
1276 (interactive "FRun rmail on RMAIL file: ")
1277 ;; We switch windows here, then display the other Rmail file there.
1278 (pop-to-buffer rmail-buffer)
1281 (defun rmail-summary-first-message ()
1282 "Show first message in Rmail file from summary buffer."
1285 (beginning-of-buffer)))
1287 (defun rmail-summary-last-message ()
1288 "Show last message in Rmail file from summary buffer."
1294 (defvar rmail-summary-edit-map nil)
1295 (if rmail-summary-edit-map
1297 (setq rmail-summary-edit-map
1298 (nconc (make-sparse-keymap) text-mode-map))
1299 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
1300 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
1302 (defun rmail-summary-edit-current-message ()
1303 "Edit the contents of this message."
1305 (pop-to-buffer rmail-buffer)
1306 (rmail-edit-current-message)
1307 (use-local-map rmail-summary-edit-map))
1309 (defun rmail-summary-cease-edit ()
1310 "Finish editing message, then go back to Rmail summary buffer."
1313 (pop-to-buffer rmail-summary-buffer))
1315 (defun rmail-summary-abort-edit ()
1316 "Abort edit of current message; restore original contents.
1317 Go back to summary buffer."
1320 (pop-to-buffer rmail-summary-buffer))
1322 (defun rmail-summary-search-backward (regexp &optional n)
1323 "Show message containing next match for REGEXP.
1324 Prefix argument gives repeat count; negative argument means search
1325 backwards (through earlier messages).
1326 Interactively, empty argument means use same regexp used last time."
1328 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1330 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1332 (if rmail-search-last-regexp
1333 (setq prompt (concat prompt
1335 rmail-search-last-regexp
1337 (setq regexp (read-string prompt))
1338 (cond ((not (equal regexp ""))
1339 (setq rmail-search-last-regexp regexp))
1340 ((not rmail-search-last-regexp)
1341 (error "No previous Rmail search string")))
1342 (list rmail-search-last-regexp
1343 (prefix-numeric-value current-prefix-arg))))
1344 ;; Don't use save-excursion because that prevents point from moving
1345 ;; properly in the summary buffer.
1346 (let ((buffer (current-buffer)))
1349 (set-buffer rmail-buffer)
1350 (rmail-search regexp (- n)))
1351 (set-buffer buffer))))
1353 (defun rmail-summary-search (regexp &optional n)
1354 "Show message containing next match for REGEXP.
1355 Prefix argument gives repeat count; negative argument means search
1356 backwards (through earlier messages).
1357 Interactively, empty argument means use same regexp used last time."
1359 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1361 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1363 (if rmail-search-last-regexp
1364 (setq prompt (concat prompt
1366 rmail-search-last-regexp
1368 (setq regexp (read-string prompt))
1369 (cond ((not (equal regexp ""))
1370 (setq rmail-search-last-regexp regexp))
1371 ((not rmail-search-last-regexp)
1372 (error "No previous Rmail search string")))
1373 (list rmail-search-last-regexp
1374 (prefix-numeric-value current-prefix-arg))))
1375 ;; Don't use save-excursion because that prevents point from moving
1376 ;; properly in the summary buffer.
1377 (let ((buffer (current-buffer)))
1380 (set-buffer rmail-buffer)
1381 (rmail-search regexp n))
1382 (set-buffer buffer))))
1384 (defun rmail-summary-toggle-header ()
1385 "Show original message header if pruned header currently shown, or vice versa."
1387 (save-window-excursion
1388 (set-buffer rmail-buffer)
1389 (rmail-toggle-header))
1390 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1391 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1392 (let ((window (get-buffer-window rmail-view-buffer)))
1394 ;; Using save-window-excursion would lose the new value of point.
1395 (let ((owin (selected-window)))
1398 (select-window window)
1399 (goto-char (point-min)))
1400 (select-window owin))))))
1403 (defun rmail-summary-add-label (label)
1404 "Add LABEL to labels associated with current Rmail message.
1405 Completion is performed over known labels when reading."
1406 (interactive (list (save-excursion
1407 (set-buffer rmail-buffer)
1408 (rmail-read-label "Add label"))))
1410 (set-buffer rmail-buffer)
1411 (rmail-add-label label)))
1413 (defun rmail-summary-kill-label (label)
1414 "Remove LABEL from labels associated with current Rmail message.
1415 Completion is performed over known labels when reading."
1416 (interactive (list (save-excursion
1417 (set-buffer rmail-buffer)
1418 (rmail-read-label "Kill label"))))
1420 (set-buffer rmail-buffer)
1421 (rmail-set-label label nil)))
1423 ;;;; *** Rmail Summary Mailing Commands ***
1425 (defun rmail-summary-override-mail-send-and-exit ()
1426 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1427 (use-local-map (copy-keymap (current-local-map)))
1428 (dolist (key (where-is-internal 'mail-send-and-exit))
1429 (define-key (current-local-map) key 'rmail-summary-send-and-exit)))
1431 (defun rmail-summary-mail ()
1432 "Send mail in another window.
1433 While composing the message, use \\[mail-yank-original] to yank the
1434 original message into it."
1436 (let ((window (get-buffer-window rmail-buffer)))
1438 (select-window window)
1439 (set-buffer rmail-buffer)))
1440 (rmail-start-mail nil nil nil nil nil (current-buffer))
1441 (rmail-summary-override-mail-send-and-exit))
1443 (defun rmail-summary-continue ()
1444 "Continue composing outgoing message previously being composed."
1446 (let ((window (get-buffer-window rmail-buffer)))
1448 (select-window window)
1449 (set-buffer rmail-buffer)))
1450 (rmail-start-mail t))
1452 (defun rmail-summary-reply (just-sender)
1453 "Reply to the current message.
1454 Normally include CC: to all other recipients of original message;
1455 prefix argument means ignore them. While composing the reply,
1456 use \\[mail-yank-original] to yank the original message into it."
1458 (let ((window (get-buffer-window rmail-view-buffer)))
1460 (select-window window)
1461 (set-buffer rmail-view-buffer)))
1462 (rmail-reply just-sender)
1463 (rmail-summary-override-mail-send-and-exit))
1465 (defun rmail-summary-retry-failure ()
1466 "Edit a mail message which is based on the contents of the current message.
1467 For a message rejected by the mail system, extract the interesting headers and
1468 the body of the original message; otherwise copy the current message."
1470 (let ((window (get-buffer-window rmail-buffer)))
1472 (select-window window)
1473 (set-buffer rmail-buffer)))
1474 (rmail-retry-failure)
1475 (rmail-summary-override-mail-send-and-exit))
1477 (defun rmail-summary-send-and-exit ()
1478 "Send mail reply and return to summary buffer."
1480 (mail-send-and-exit t))
1482 (defun rmail-summary-forward (resend)
1483 "Forward the current message to another user.
1484 With prefix argument, \"resend\" the message instead of forwarding it;
1485 see the documentation of `rmail-resend'."
1488 (let ((window (get-buffer-window rmail-buffer)))
1490 (select-window window)
1491 (set-buffer rmail-buffer)))
1492 (rmail-forward resend)
1493 (rmail-summary-override-mail-send-and-exit)))
1495 (defun rmail-summary-resend ()
1496 "Resend current message using `rmail-resend'."
1499 (let ((window (get-buffer-window rmail-buffer)))
1501 (select-window window)
1502 (set-buffer rmail-buffer)))
1503 (call-interactively 'rmail-resend)))
1505 ;; Summary output commands.
1507 (defun rmail-summary-output-to-rmail-file (&optional file-name n)
1508 "Append the current message to an Rmail file named FILE-NAME.
1509 If the file does not exist, ask if it should be created.
1510 If file is being visited, the message is appended to the Emacs
1511 buffer visiting that file.
1513 A prefix argument N says to output N consecutive messages
1514 starting with the current one. Deleted messages are skipped and don't count."
1516 (progn (require 'rmailout)
1517 (list (rmail-output-read-rmail-file-name)
1518 (prefix-numeric-value current-prefix-arg))))
1519 (let ((i 0) prev-msg)
1522 (progn (rmail-summary-goto-msg)
1525 (with-current-buffer rmail-buffer
1526 rmail-current-message))))))
1528 (with-current-buffer rmail-buffer
1529 (let ((rmail-delete-after-output nil))
1530 (rmail-output-to-rmail-file file-name 1)))
1531 (if rmail-delete-after-output
1532 (rmail-summary-delete-forward nil)
1534 (rmail-summary-next-msg 1))))))
1536 (defun rmail-summary-output (&optional file-name n)
1537 "Append this message to Unix mail file named FILE-NAME.
1539 A prefix argument N says to output N consecutive messages
1540 starting with the current one. Deleted messages are skipped and don't count."
1542 (progn (require 'rmailout)
1543 (list (rmail-output-read-file-name)
1544 (prefix-numeric-value current-prefix-arg))))
1545 (let ((i 0) prev-msg)
1548 (progn (rmail-summary-goto-msg)
1551 (with-current-buffer rmail-buffer
1552 rmail-current-message))))))
1554 (with-current-buffer rmail-buffer
1555 (let ((rmail-delete-after-output nil))
1556 (rmail-output file-name 1)))
1557 (if rmail-delete-after-output
1558 (rmail-summary-delete-forward nil)
1560 (rmail-summary-next-msg 1))))))
1562 (defun rmail-summary-output-menu ()
1563 "Output current message to another Rmail file, chosen with a menu.
1564 Also set the default for subsequent \\[rmail-output-to-rmail-file] commands.
1565 The variables `rmail-secondary-file-directory' and
1566 `rmail-secondary-file-regexp' control which files are offered in the menu."
1569 (set-buffer rmail-buffer)
1570 (let ((rmail-delete-after-output nil))
1571 (call-interactively 'rmail-output-menu)))
1572 (if rmail-delete-after-output
1573 (rmail-summary-delete-forward nil)))
1575 (defun rmail-summary-construct-io-menu ()
1576 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1579 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1580 (cons "Input Rmail File"
1581 (rmail-list-to-menu "Input Rmail File"
1583 'rmail-summary-input)))
1584 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1585 (cons "Output Rmail File"
1586 (rmail-list-to-menu "Output Rmail File"
1588 'rmail-summary-output-to-rmail-file))))
1589 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1590 '("Input Rmail File" . rmail-disable-menu))
1591 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1592 '("Output Rmail File" . rmail-disable-menu)))))
1594 (defun rmail-summary-output-body (&optional file-name)
1595 "Write this message body to the file FILE-NAME.
1596 FILE-NAME defaults, interactively, from the Subject field of the message."
1599 (set-buffer rmail-buffer)
1600 (let ((rmail-delete-after-output nil))
1602 (rmail-output-body-to-file file-name)
1603 (call-interactively 'rmail-output-body-to-file))))
1604 (if rmail-delete-after-output
1605 (rmail-summary-delete-forward nil)))
1607 ;; Sorting messages in Rmail Summary buffer.
1609 (defun rmail-summary-sort-by-date (reverse)
1610 "Sort messages of current Rmail summary by date.
1611 If prefix argument REVERSE is non-nil, sort them in reverse order."
1613 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1615 (defun rmail-summary-sort-by-subject (reverse)
1616 "Sort messages of current Rmail summary by subject.
1617 If prefix argument REVERSE is non-nil, sort them in reverse order."
1619 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1621 (defun rmail-summary-sort-by-author (reverse)
1622 "Sort messages of current Rmail summary by author.
1623 If prefix argument REVERSE is non-nil, sort them in reverse order."
1625 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1627 (defun rmail-summary-sort-by-recipient (reverse)
1628 "Sort messages of current Rmail summary by recipient.
1629 If prefix argument REVERSE is non-nil, sort them in reverse order."
1631 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1633 (defun rmail-summary-sort-by-correspondent (reverse)
1634 "Sort messages of current Rmail summary by other correspondent.
1635 If prefix argument REVERSE is non-nil, sort them in reverse order."
1637 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1639 (defun rmail-summary-sort-by-lines (reverse)
1640 "Sort messages of current Rmail summary by lines of the message.
1641 If prefix argument REVERSE is non-nil, sort them in reverse order."
1643 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1645 (defun rmail-summary-sort-by-labels (reverse labels)
1646 "Sort messages of current Rmail summary by labels.
1647 If prefix argument REVERSE is non-nil, sort them in reverse order.
1648 KEYWORDS is a comma-separated list of labels."
1649 (interactive "P\nsSort by labels: ")
1650 (rmail-sort-from-summary
1651 (function (lambda (reverse)
1652 (rmail-sort-by-labels reverse labels)))
1655 (defun rmail-sort-from-summary (sortfun reverse)
1656 "Sort Rmail messages from Summary buffer and update it after sorting."
1657 (require 'rmailsort)
1658 (let ((selwin (selected-window)))
1660 (progn (pop-to-buffer rmail-buffer)
1661 (funcall sortfun reverse))
1662 (select-window selwin))))
1666 ;;; arch-tag: 556079ee-75c1-47f5-9884-2e0a0bc6c5a1
1667 ;;; rmailsum.el ends here