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, 2008, 2009 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 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
26 ;; Extended by Bob Weiner of Motorola
27 ;; Provided all commands from rmail-mode in rmail-summary-mode and made key
28 ;; bindings in both modes wholly compatible.
34 ;; For rmail-select-summary
37 (defcustom rmail-summary-scroll-between-messages t
38 "Non-nil means Rmail summary scroll commands move between messages."
40 :group 'rmail-summary)
42 (defcustom rmail-summary-line-count-flag t
43 "Non-nil means Rmail summary should show the number of lines in each message."
45 :group 'rmail-summary)
47 (defvar rmail-summary-font-lock-keywords
48 '(("^.....D.*" . font-lock-string-face) ; Deleted.
49 ("^.....-.*" . font-lock-type-face) ; Unread.
50 ;; Neither of the below will be highlighted if either of the above are:
51 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date.
52 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face)) ; Labels.
53 "Additional expressions to highlight in Rmail Summary mode.")
55 (defvar rmail-summary-redo
56 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
58 (defvar rmail-summary-overlay nil)
59 (put 'rmail-summary-overlay 'permanent-local t)
61 (defvar rmail-summary-mode-map nil)
63 ;; Entry points for making a summary buffer.
65 ;; Regenerate the contents of the summary
66 ;; using the same selection criterion as last time.
67 ;; M-x revert-buffer in a summary buffer calls this function.
68 (defun rmail-update-summary (&rest ignore)
69 (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
72 (defun rmail-summary ()
73 "Display a summary of all messages, one line per message."
75 (rmail-new-summary "All" '(rmail-summary) nil)
76 (unless (get-buffer-window rmail-buffer)
77 (rmail-summary-beginning-of-message)))
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
92 (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))
109 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
110 (rmail-apply-in-message msg 'rmail-message-recipients-p-1
111 recipients primary-only))
113 (defun rmail-message-recipients-p-1 (recipients &optional primary-only)
114 ;; mail-fetch-field does not care where it starts from.
115 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
116 (or (string-match recipients (or (mail-fetch-field "To") ""))
117 (string-match recipients (or (mail-fetch-field "From") ""))
118 (if (not primary-only)
119 (string-match recipients (or (mail-fetch-field "Cc") "")))))
122 (defun rmail-summary-by-regexp (regexp)
123 "Display a summary of all messages according to regexp REGEXP.
124 If the regular expression is found in the header of the message
125 \(including in the date and other lines, as well as the subject line),
126 Emacs will list the header line in the RMAIL-summary."
127 (interactive "sRegexp to summarize by: ")
128 (if (string= regexp "")
129 (setq regexp (or rmail-last-regexp
130 (error "No regexp specified"))))
131 (setq rmail-last-regexp regexp)
132 (rmail-new-summary (concat "regexp " regexp)
133 (list 'rmail-summary-by-regexp regexp)
134 'rmail-message-regexp-p
137 (defun rmail-message-regexp-p (msg regexp)
138 "Return t, if for message number MSG, regexp REGEXP matches in the header."
139 (rmail-apply-in-message msg 'rmail-message-regexp-p-1 msg regexp))
141 (defun rmail-message-regexp-p-1 (msg regexp)
142 ;; Search functions can expect to start from the beginning.
143 (narrow-to-region (point) (save-excursion (search-forward "\n\n") (point)))
144 (if rmail-enable-mime
145 (if rmail-search-mime-header-function
146 (funcall rmail-search-mime-header-function msg regexp (point))
147 (error "You must set `rmail-search-mime-header-function'"))
148 (re-search-forward regexp nil t)))
151 (defun rmail-summary-by-topic (subject &optional whole-message)
152 "Display a summary of all messages with the given SUBJECT.
153 Normally checks the Subject field of headers;
154 but if WHOLE-MESSAGE is non-nil (prefix arg given),
155 look in the whole message.
156 SUBJECT is a string of regexps separated by commas."
158 (let* ((subject (rmail-simplified-subject))
159 (prompt (concat "Topics to summarize by (regexp"
160 (if subject ", default current subject" "")
162 (list (read-string prompt nil nil subject) current-prefix-arg)))
164 (concat "about " subject)
165 (list 'rmail-summary-by-topic subject whole-message)
166 'rmail-message-subject-p
167 (mail-comma-list-regexp subject) whole-message))
169 (defun rmail-message-subject-p (msg subject &optional whole-message)
171 (rmail-apply-in-message msg 're-search-forward subject nil t)
172 (string-match subject (rmail-simplified-subject msg))))
175 (defun rmail-summary-by-senders (senders)
176 "Display a summary of all messages with the given SENDERS.
177 SENDERS is a string of names separated by commas."
178 (interactive "sSenders to summarize by: ")
180 (concat "senders " senders)
181 (list 'rmail-summary-by-senders senders)
182 'rmail-message-senders-p
183 (mail-comma-list-regexp senders)))
185 (defun rmail-message-senders-p (msg senders)
186 (string-match senders (or (rmail-get-header "From" msg) "")))
188 ;; General making of a summary buffer.
190 (defvar rmail-summary-symbol-number 0)
192 (defvar rmail-new-summary-line-count)
194 (defun rmail-new-summary (desc redo func &rest args)
195 "Create a summary of selected messages.
196 DESC makes part of the mode line of the summary buffer. REDO is form ...
197 For each message, FUNC is applied to the message number and ARGS...
198 and if the result is non-nil, that message is included.
199 nil for FUNCTION means all messages."
200 (message "Computing summary lines...")
202 (error "No RMAIL buffer found"))
203 (let (mesg was-in-summary)
204 (if (eq major-mode 'rmail-summary-mode)
205 (setq was-in-summary t))
206 (with-current-buffer rmail-buffer
207 (if (zerop (setq mesg rmail-current-message))
208 (error "No messages to summarize"))
209 (setq rmail-summary-buffer (rmail-new-summary-1 desc redo func args)))
210 ;; Now display the summary buffer and go to the right place in it.
211 (unless was-in-summary
212 (if (and (one-window-p)
215 ;; If there is just one window, put the summary on the top.
217 (split-window (selected-window) rmail-summary-window-size)
218 (select-window (next-window (frame-first-window)))
219 (pop-to-buffer rmail-summary-buffer)
220 ;; If pop-to-buffer did not use that window, delete that
221 ;; window. (This can happen if it uses another frame.)
222 (if (not (eq rmail-summary-buffer
223 (window-buffer (frame-first-window))))
224 (delete-other-windows)))
225 (pop-to-buffer rmail-summary-buffer))
226 (set-buffer rmail-buffer)
227 ;; This is how rmail makes the summary buffer reappear.
228 ;; We do this here to make the window the proper size.
229 (rmail-select-summary nil)
230 (set-buffer rmail-summary-buffer))
231 (rmail-summary-goto-msg mesg t t)
232 (rmail-summary-construct-io-menu)
233 (message "Computing summary lines...done")))
235 (defun rmail-new-summary-1 (description form function args)
236 "Filter messages to obtain summary lines.
237 DESCRIPTION is added to the mode line.
239 Return the summary buffer by invoking FUNCTION on each message
240 passing the message number and ARGS...
244 The current buffer must be a Rmail buffer either containing a
245 collection of mbox formatted messages or displaying a single
247 (let ((summary-msgs ())
248 (rmail-new-summary-line-count 0)
249 (sumbuf (rmail-get-create-summary-buffer)))
250 ;; Scan the messages, getting their summary strings
251 ;; and putting the list of them in SUMMARY-MSGS.
253 (main-buffer (current-buffer))
254 (total rmail-total-messages)
255 (inhibit-read-only t))
257 ;; Go where the mbox text is.
258 (if (rmail-buffers-swapped-p)
259 (set-buffer rmail-view-buffer))
260 (let ((old-min (point-min-marker))
261 (old-max (point-max-marker)))
263 ;; Can't use save-restriction here; that doesn't work if we
264 ;; plan to modify text outside the original restriction.
267 (goto-char (point-min))
268 (while (>= total msgnum)
269 ;; Go back to the Rmail buffer so
270 ;; so FUNCTION and rmail-get-summary can see its local vars.
271 (with-current-buffer main-buffer
272 ;; First test whether to include this message.
273 (if (or (null function)
274 (apply function msgnum args))
276 (cons (cons msgnum (rmail-get-summary msgnum))
278 (setq msgnum (1+ msgnum))
279 ;; Provide a periodic User progress message.
280 (if (zerop (% rmail-new-summary-line-count 10))
281 (message "Computing summary lines...%d"
282 rmail-new-summary-line-count)))
283 (setq summary-msgs (nreverse summary-msgs)))
284 (narrow-to-region old-min old-max)))))
286 ;; Temporarily, while summary buffer is unfinished,
287 ;; we "don't have" a summary.
289 ;; I have not a clue what this clause is doing. If you read this
290 ;; chunk of code and have a clue, then please email that clue to
292 (setq rmail-summary-buffer nil)
293 (if rmail-enable-mime
294 (with-current-buffer rmail-buffer
295 (setq rmail-summary-buffer nil)))
298 (let ((rbuf (current-buffer))
299 (total rmail-total-messages))
301 ;; Set up the summary buffer's contents.
302 (let ((buffer-read-only nil))
305 (princ (cdr (car summary-msgs)) sumbuf)
306 (setq summary-msgs (cdr summary-msgs)))
307 (goto-char (point-min)))
308 ;; Set up the rest of its state and local variables.
309 (setq buffer-read-only t)
311 (make-local-variable 'minor-mode-alist)
312 (setq minor-mode-alist (list (list t (concat ": " description))))
313 (setq rmail-buffer rbuf
314 rmail-summary-redo form
315 rmail-total-messages total)))
318 (defun rmail-get-create-summary-buffer ()
319 "Obtain a summary buffer by re-using an existing summary
320 buffer, or by creating a new summary buffer."
321 (if (and rmail-summary-buffer (buffer-name rmail-summary-buffer))
323 (generate-new-buffer (concat (buffer-name) "-summary"))))
326 ;; Low levels of generating a summary.
328 (defun rmail-get-summary (msgnum)
329 "Return the summary line for message MSGNUM.
330 The mbox buffer must be current when you call this function
331 even if its text is swapped.
333 If the message has a summary line already, it will be stored in
334 the message as a header and simply returned, otherwise the
335 summary line is created, saved in the message header, cached and
338 The current buffer contains the unrestricted message collection."
339 (let ((line (aref rmail-summary-vector (1- msgnum))))
341 ;; Register a summary line for MSGNUM.
342 (setq rmail-new-summary-line-count (1+ rmail-new-summary-line-count)
343 line (rmail-create-summary-line msgnum))
344 ;; Cache the summary line for use during this Rmail session.
345 (aset rmail-summary-vector (1- msgnum) line))
348 (defcustom rmail-summary-line-decoder (function identity)
349 "Function to decode a Rmail summary line.
350 It receives the summary line for one message as a string
351 and should return the decoded string.
353 By default, it is `identity', which returns the string unaltered."
355 :group 'rmail-summary)
357 (defun rmail-create-summary-line (msgnum)
358 "Return the summary line for message MSGNUM.
359 Obtain the message summary from the header if it is available
360 otherwise create it and store it in the message header.
362 The mbox buffer must be current when you call this function
363 even if its text is swapped."
364 (let ((beg (rmail-msgbeg msgnum))
365 (end (rmail-msgend msgnum))
366 (deleted (rmail-message-deleted-p msgnum))
367 ;; Does not work (swapped?)
368 ;;; (unseen (rmail-message-unseen-p msgnum))
371 ;; Switch to the buffer that has the whole mbox text.
372 (if (rmail-buffers-swapped-p)
373 (set-buffer rmail-view-buffer))
374 ;; Now we can compute the line count.
375 (if rmail-summary-line-count-flag
376 (setq lines (count-lines beg end)))
377 ;; Narrow to the message header.
382 (if (search-forward "\n\n" end t)
384 (narrow-to-region beg (point))
385 ;; Replace rmail-message-unseen-p from above.
387 (setq unseen (and (search-forward
388 (concat rmail-attribute-header ": ") nil t)
389 (looking-at "......U")))
390 ;; Generate a status line from the message.
391 (rmail-create-summary msgnum deleted unseen lines))
392 (rmail-error-bad-format msgnum)))))))
394 ;; FIXME this is now unused.
395 ;; The intention was to display in the summary something like {E}
396 ;; for an edited messaged, similarly for answered, etc.
397 ;; But that conflicts with the previous rmail usage, where
398 ;; any user-defined { labels } occupied this space.
399 ;; So whilst it would be nice to have this information in the summary,
400 ;; it would need to go somewhere else.
401 (defun rmail-get-summary-status ()
402 "Return a coded string wrapped in curly braces denoting the status.
404 The current buffer must already be narrowed to the message headers for
405 the message being processed."
406 (let ((status (mail-fetch-field rmail-attribute-header))
410 ;; Strip off the read/unread and the deleted attribute which are
411 ;; handled separately.
414 (concat (substring status 0 1) (substring status 2 6))
416 (while (< index (length status))
417 (unless (string= "-" (setq char (substring status index (1+ index))))
418 (setq result (concat result char)))
419 (setq index (1+ index)))
420 (when (> (length result) 0)
421 (setq result (concat "{" result "}")))
424 (defun rmail-get-summary-labels ()
425 "Return a string wrapped in curly braces with the current message labels.
426 Returns nil if there are no labels. The current buffer must
427 already be narrowed to the message headers for the message being
429 (let ((labels (mail-fetch-field rmail-keyword-header)))
431 (not (string-equal labels ""))
432 (format "{ %s } " labels))))
434 (defun rmail-create-summary (msgnum deleted unseen lines)
435 "Return the summary line for message MSGNUM.
436 The current buffer should already be narrowed to the header for that message.
437 It could be either buffer, so don't access Rmail local variables.
438 DELETED is t if this message is marked deleted.
439 UNSEEN is t if it is marked unseen.
440 LINES is the number of lines in the message (if we should display that)
442 (goto-char (point-min))
443 (let ((line (rmail-header-summary))
444 (labels (rmail-get-summary-labels))
445 pos status prefix basic-start basic-end linecount-string)
447 (setq linecount-string
450 ((<= lines 9) (format " [%d]" lines))
451 ((<= lines 99) (format " [%d]" lines))
452 ((<= lines 999) (format " [%d]" lines))
453 ((<= lines 9999) (format " [%dk]" (/ lines 1000)))
454 ((<= lines 99999) (format " [%dk]" (/ lines 1000)))
455 (t (format "[%dk]" (/ lines 1000)))))
461 prefix (format "%5d%c " msgnum status)
462 basic-start (car line)
463 basic-end (cadr line))
464 (funcall rmail-summary-line-decoder
465 (concat prefix basic-start linecount-string " "
468 ;; FIXME move to rmail.el?
470 (defcustom rmail-user-mail-address-regexp nil
471 "Regexp matching user mail addresses.
472 If non-nil, this variable is used to identify the correspondent
473 when receiving new mail. If it matches the address of the sender,
474 the recipient is taken as correspondent of a mail.
475 If nil \(default value\), your `user-login-name' and `user-mail-address'
476 are used to exclude yourself as correspondent.
478 Usually you don't have to set this variable, except if you collect mails
479 sent by you under different user names.
480 Then it should be a regexp matching your mail addresses.
482 Setting this variable has an effect only before reading a mail."
483 :type '(choice (const :tag "None" nil) regexp)
484 :group 'rmail-retrieve
487 (defun rmail-header-summary ()
488 "Return a message summary based on the message headers.
489 The value is a list of two strings, the first and second parts of the summary.
491 The current buffer must already be narrowed to the message headers for
492 the message being processed."
493 (goto-char (point-min))
495 (concat (save-excursion
496 (if (not (re-search-forward "^Date:" nil t))
498 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
499 (line-end-position) t)
501 (string-to-number (buffer-substring
505 (match-beginning 4) (match-end 4))))
506 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
507 (line-end-position) t)
509 (string-to-number (buffer-substring
513 (match-beginning 2) (match-end 2))))
514 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
515 (line-end-position) t)
518 (match-beginning 2) (match-end 2))
520 (match-beginning 3) (match-end 3))
522 (match-beginning 4) (match-end 4))))
526 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t)
527 (mail-strip-quoted-names
530 ;; Get all the lines of the From field
531 ;; so that we get a whole comment if there is one,
532 ;; so that mail-strip-quoted-names can discard it.
533 (let ((opoint (point)))
534 (while (progn (forward-line 1)
535 (looking-at "[ \t]")))
536 ;; Back up over newline, then trailing spaces or tabs
538 (skip-chars-backward " \t")
543 (or rmail-user-mail-address-regexp
545 (regexp-quote (user-login-name))
548 ;; Don't lose if run from init file
549 ;; where user-mail-address is not
551 (or user-mail-address
552 (concat (user-login-name) "@"
553 (or mail-host-address
557 ;; No From field, or it's this user.
559 (goto-char (point-min))
560 (if (not (re-search-forward "^To:[ \t]*" nil t))
564 (mail-strip-quoted-names
568 (skip-chars-backward " \t")
572 (setq len (length from))
573 (setq mch (string-match "[@%]" from))
575 (if (or (not mch) (<= len 25))
576 (substring from (max 0 (- len 25)))
578 (setq lo (cond ((< (- mch 14) 0) 0)
582 (min len (+ lo 25)))))))))
583 (concat (if (re-search-forward "^Subject:" nil t)
584 (progn (skip-chars-forward " \t")
585 (buffer-substring (point)
588 (re-search-forward "[\n][\n]+" nil t)
589 (buffer-substring (point) (progn (end-of-line) (point))))
592 ;; Simple motion in a summary buffer.
594 (defun rmail-summary-next-all (&optional number)
596 (forward-line (if number number 1))
597 ;; It doesn't look nice to move forward past the last message line.
598 (and (eobp) (> number 0)
600 (display-buffer rmail-buffer))
602 (defun rmail-summary-previous-all (&optional number)
604 (forward-line (- (if number number 1)))
605 ;; It doesn't look nice to move forward past the last message line.
606 (and (eobp) (< number 0)
608 (display-buffer rmail-buffer))
610 (defun rmail-summary-next-msg (&optional number)
611 "Display next non-deleted msg from rmail file.
612 With optional prefix argument NUMBER, moves forward this number of non-deleted
613 messages, or backward if NUMBER is negative."
616 (and (> number 0) (end-of-line))
617 (let ((count (if (< number 0) (- number) number))
618 (search (if (> number 0) 're-search-forward 're-search-backward))
619 (non-del-msg-found nil))
620 (while (and (> count 0) (setq non-del-msg-found
621 (or (funcall search "^.....[^D]" nil t)
623 (setq count (1- count))))
625 (display-buffer rmail-buffer))
627 (defun rmail-summary-previous-msg (&optional number)
628 "Display previous non-deleted msg from rmail file.
629 With optional prefix argument NUMBER, moves backward this number of
630 non-deleted messages."
632 (rmail-summary-next-msg (- (if number number 1))))
634 (defun rmail-summary-next-labeled-message (n labels)
635 "Show next message with LABELS. Defaults to last labels used.
636 With prefix argument N moves forward N messages with these labels."
637 (interactive "p\nsMove to next msg with labels: ")
640 (set-buffer rmail-buffer)
641 (rmail-next-labeled-message n labels)
642 (setq msg rmail-current-message))
643 (rmail-summary-goto-msg msg)))
645 (defun rmail-summary-previous-labeled-message (n labels)
646 "Show previous message with LABELS. Defaults to last labels used.
647 With prefix argument N moves backward N messages with these labels."
648 (interactive "p\nsMove to previous msg with labels: ")
651 (set-buffer rmail-buffer)
652 (rmail-previous-labeled-message n labels)
653 (setq msg rmail-current-message))
654 (rmail-summary-goto-msg msg)))
656 (defun rmail-summary-next-same-subject (n)
657 "Go to the next message in the summary having the same subject.
658 With prefix argument N, do this N times.
659 If N is negative, go backwards."
661 (let ((forward (> n 0))
663 (with-current-buffer rmail-buffer
664 (setq subject (rmail-simplified-subject)
665 i rmail-current-message))
672 (while (and (not done)
676 ;; Advance thru summary.
677 (forward-line (if forward 1 -1))
678 ;; Get msg number of this line.
679 (setq i (string-to-number
680 (buffer-substring (point)
681 (min (point-max) (+ 6 (point))))))
682 (setq done (string-equal subject (rmail-simplified-subject i))))
683 (if done (setq found i)))
684 (setq n (if forward (1- n) (1+ n)))))
686 (rmail-summary-goto-msg found)
687 (error "No %s message with same subject"
688 (if forward "following" "previous")))))
690 (defun rmail-summary-previous-same-subject (n)
691 "Go to the previous message in the summary having the same subject.
692 With prefix argument N, do this N times.
693 If N is negative, go forwards instead."
695 (rmail-summary-next-same-subject (- n)))
697 ;; Delete and undelete summary commands.
699 (defun rmail-summary-delete-forward (&optional count)
700 "Delete this message and move to next nondeleted one.
701 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
702 A prefix argument serves as a repeat count;
703 a negative argument means to delete and move backward."
705 (unless (numberp count) (setq count 1))
707 (backward (< count 0)))
709 (rmail-summary-goto-msg)
710 (with-current-buffer rmail-buffer
711 (rmail-delete-message)
712 (setq del-msg rmail-current-message))
713 (rmail-summary-mark-deleted del-msg)
714 (while (and (not (if backward (bobp) (eobp)))
715 (save-excursion (beginning-of-line)
716 (looking-at " *[0-9]+D")))
717 (forward-line (if backward -1 1)))
718 ;; It looks ugly to move to the empty line at end of buffer.
719 (and (eobp) (not backward)
722 (if (> count 0) (1- count) (1+ count))))))
724 (defun rmail-summary-delete-backward (&optional count)
725 "Delete this message and move to previous nondeleted one.
726 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
727 A prefix argument serves as a repeat count;
728 a negative argument means to delete and move forward."
730 (rmail-summary-delete-forward (- count)))
732 (defun rmail-summary-mark-deleted (&optional n undel)
733 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
734 (and n (rmail-summary-goto-msg n t t))
736 (not (overlay-get rmail-summary-overlay 'face))
737 (let ((buffer-read-only nil))
738 (skip-chars-forward " ")
739 (skip-chars-forward "[0-9]")
742 (progn (delete-char 1) (insert " ")))
745 ;; Register a new summary line.
746 (with-current-buffer rmail-buffer
747 (aset rmail-summary-vector (1- n) (rmail-create-summary-line n)))))
750 (defun rmail-summary-update-line (n)
751 "Update the summary line for message N."
752 (when (rmail-summary-goto-msg n t t)
753 (let* ((buffer-read-only nil)
754 (start (line-beginning-position))
755 (end (line-beginning-position 2))
756 (overlays (overlays-in start end))
758 (while (and (setq ov (car overlays))
759 (not (setq high (overlay-get ov 'rmail-summary))))
760 (setq overlays (cdr overlays)))
761 (delete-region start end)
763 (with-current-buffer rmail-buffer
764 (aset rmail-summary-vector (1- n) (rmail-create-summary-line n)))
768 (rmail-summary-update-highlight nil)))))
770 (defun rmail-summary-mark-undeleted (n)
771 (rmail-summary-mark-deleted n t))
773 (defun rmail-summary-deleted-p (&optional n)
775 (and n (rmail-summary-goto-msg n nil t))
776 (skip-chars-forward " ")
777 (skip-chars-forward "[0-9]")
780 (defun rmail-summary-undelete (&optional arg)
781 "Undelete current message.
782 Optional prefix ARG means undelete ARG previous messages."
785 (rmail-summary-undelete-many arg)
786 (let ((buffer-read-only nil)
789 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
790 (replace-match "\\1 ")
791 (rmail-summary-goto-msg)
792 (if rmail-enable-mime
793 (set-buffer rmail-buffer)
794 (pop-to-buffer rmail-buffer))
795 (and (rmail-message-deleted-p rmail-current-message)
796 (rmail-undelete-previous-message))
797 (if rmail-enable-mime
798 (pop-to-buffer rmail-buffer))
799 (pop-to-buffer rmail-summary-buffer))
800 (t (goto-char opoint))))))
802 (defun rmail-summary-undelete-many (&optional n)
803 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
806 (set-buffer rmail-buffer)
807 (let* ((init-msg (if n rmail-current-message rmail-total-messages))
808 (rmail-current-message init-msg)
809 (n (or n rmail-total-messages))
811 (while (and (> rmail-current-message 0)
813 (if (rmail-message-deleted-p rmail-current-message)
814 (progn (rmail-set-attribute rmail-deleted-attr-index nil)
815 (setq msgs-undeled (1+ msgs-undeled))))
816 (setq rmail-current-message (1- rmail-current-message)))
817 (set-buffer rmail-summary-buffer)
818 (setq rmail-current-message init-msg msgs-undeled 0)
819 (while (and (> rmail-current-message 0)
821 (if (rmail-summary-deleted-p rmail-current-message)
822 (progn (rmail-summary-mark-undeleted rmail-current-message)
823 (setq msgs-undeled (1+ msgs-undeled))))
824 (setq rmail-current-message (1- rmail-current-message))))
825 (rmail-summary-goto-msg)))
827 ;; Rmail Summary mode is suitable only for specially formatted data.
828 (put 'rmail-summary-mode 'mode-class 'special)
830 (defun rmail-summary-mode ()
831 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
832 As commands are issued in the summary buffer, they are applied to the
833 corresponding mail messages in the rmail buffer.
835 All normal editing commands are turned off.
836 Instead, nearly all the Rmail mode commands are available,
837 though many of them move only among the messages in the summary.
839 These additional commands exist:
841 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
842 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
844 Commands for sorting the summary:
846 \\[rmail-summary-sort-by-date] Sort by date.
847 \\[rmail-summary-sort-by-subject] Sort by subject.
848 \\[rmail-summary-sort-by-author] Sort by author.
849 \\[rmail-summary-sort-by-recipient] Sort by recipient.
850 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
851 \\[rmail-summary-sort-by-lines] Sort by lines.
852 \\[rmail-summary-sort-by-labels] Sort by labels."
854 (kill-all-local-variables)
855 (setq major-mode 'rmail-summary-mode)
856 (setq mode-name "RMAIL Summary")
857 (setq truncate-lines t)
858 (setq buffer-read-only t)
859 (set-syntax-table text-mode-syntax-table)
860 (make-local-variable 'rmail-buffer)
861 (make-local-variable 'rmail-total-messages)
862 (make-local-variable 'rmail-current-message)
863 (setq rmail-current-message nil)
864 (make-local-variable 'rmail-summary-redo)
865 (setq rmail-summary-redo nil)
866 (make-local-variable 'revert-buffer-function)
867 (make-local-variable 'font-lock-defaults)
868 (setq font-lock-defaults '(rmail-summary-font-lock-keywords t))
869 (rmail-summary-enable)
870 (run-mode-hooks 'rmail-summary-mode-hook))
872 ;; Summary features need to be disabled during edit mode.
873 (defun rmail-summary-disable ()
874 (use-local-map text-mode-map)
875 (remove-hook 'post-command-hook 'rmail-summary-rmail-update t)
876 (setq revert-buffer-function nil))
878 (defun rmail-summary-enable ()
879 (use-local-map rmail-summary-mode-map)
880 (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
881 (setq revert-buffer-function 'rmail-update-summary))
883 (defvar rmail-summary-put-back-unseen nil
884 "Used for communicating between calls to `rmail-summary-rmail-update'.
885 If it moves to a message within an Incremental Search, and removes
886 the `unseen' attribute from that message, it sets this flag
887 so that if the next motion between messages is in the same Incremental
888 Search, the `unseen' attribute is restored.")
890 ;; Show in Rmail the message described by the summary line that point is on,
891 ;; but only if the Rmail buffer is already visible.
892 ;; This is a post-command-hook in summary buffers.
893 (defun rmail-summary-rmail-update ()
894 (let (buffer-read-only)
896 ;; If at end of buffer, pretend we are on the last text line.
900 (skip-chars-forward " ")
901 (let ((msg-num (string-to-number (buffer-substring
903 (progn (skip-chars-forward "0-9")
905 ;; Always leave `unseen' removed
906 ;; if we get out of isearch mode.
907 ;; Don't let a subsequent isearch restore that `unseen'.
908 (if (not isearch-mode)
909 (setq rmail-summary-put-back-unseen nil))
911 (or (eq rmail-current-message msg-num)
912 (let ((window (get-buffer-window rmail-buffer t))
913 (owin (selected-window)))
916 (set-buffer rmail-buffer)
917 ;; If we first saw the previous message in this search,
918 ;; and we have gone to a different message while searching,
919 ;; put back `unseen' on the former one.
920 (if rmail-summary-put-back-unseen
921 (rmail-set-attribute rmail-unseen-attr-index t
922 rmail-current-message))
923 ;; Arrange to do that later, for the new current message,
924 ;; if it still has `unseen'.
925 (setq rmail-summary-put-back-unseen
926 (rmail-message-attr-p msg-num rmail-unseen-attr-index)))
927 (setq rmail-summary-put-back-unseen nil))
929 ;; Go to the desired message.
930 (setq rmail-current-message msg-num)
932 ;; Update the summary to show the message has been seen.
933 (if (= (following-char) ?-)
939 ;; Using save-window-excursion would cause the new value
940 ;; of point to get lost.
943 (select-window window)
944 (rmail-show-message-maybe msg-num t))
945 (select-window owin))
946 (if (buffer-name rmail-buffer)
948 (set-buffer rmail-buffer)
949 (rmail-show-message-maybe msg-num t))))))
950 (rmail-summary-update-highlight nil)))))
952 (defun rmail-summary-save-buffer ()
953 "Save the buffer associated with this RMAIL summary."
955 (save-window-excursion
957 (switch-to-buffer rmail-buffer)
961 (if rmail-summary-mode-map
963 (setq rmail-summary-mode-map (make-keymap))
964 (suppress-keymap rmail-summary-mode-map)
966 (define-key rmail-summary-mode-map [mouse-2] 'rmail-summary-mouse-goto-message)
967 (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label)
968 (define-key rmail-summary-mode-map "b" 'rmail-summary-bury)
969 (define-key rmail-summary-mode-map "c" 'rmail-summary-continue)
970 (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward)
971 (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward)
972 (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message)
973 (define-key rmail-summary-mode-map "f" 'rmail-summary-forward)
974 (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail)
975 (define-key rmail-summary-mode-map "h" 'rmail-summary)
976 (define-key rmail-summary-mode-map "i" 'rmail-summary-input)
977 (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg)
978 (define-key rmail-summary-mode-map "\C-m" 'rmail-summary-goto-msg)
979 (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label)
980 (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels)
981 (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
982 (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
983 (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
984 (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
985 (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
986 (define-key rmail-summary-mode-map "m" 'rmail-summary-mail)
987 (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure)
988 (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg)
989 (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all)
990 (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
991 (define-key rmail-summary-mode-map "o" 'rmail-summary-output)
992 (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output)
993 (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg)
994 (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all)
995 (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
996 (define-key rmail-summary-mode-map "q" 'rmail-summary-quit)
997 (define-key rmail-summary-mode-map "Q" 'rmail-summary-wipe)
998 (define-key rmail-summary-mode-map "r" 'rmail-summary-reply)
999 (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save)
1000 (define-key rmail-summary-mode-map "\es" 'rmail-summary-search)
1001 (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header)
1002 (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete)
1003 (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many)
1004 (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge)
1005 (define-key rmail-summary-mode-map "w" 'rmail-summary-output-body)
1006 (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message)
1007 (define-key rmail-summary-mode-map "/" 'rmail-summary-end-of-message)
1008 (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message)
1009 (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message)
1010 (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up)
1011 (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down)
1012 (define-key rmail-summary-mode-map "?" 'describe-mode)
1013 (define-key rmail-summary-mode-map "\C-c\C-n" 'rmail-summary-next-same-subject)
1014 (define-key rmail-summary-mode-map "\C-c\C-p" 'rmail-summary-previous-same-subject)
1015 (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
1016 'rmail-summary-sort-by-date)
1017 (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
1018 'rmail-summary-sort-by-subject)
1019 (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
1020 'rmail-summary-sort-by-author)
1021 (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
1022 'rmail-summary-sort-by-recipient)
1023 (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
1024 'rmail-summary-sort-by-correspondent)
1025 (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
1026 'rmail-summary-sort-by-lines)
1027 (define-key rmail-summary-mode-map "\C-c\C-s\C-k"
1028 'rmail-summary-sort-by-labels)
1029 (define-key rmail-summary-mode-map "\C-x\C-s" 'rmail-summary-save-buffer)
1032 ;;; Menu bar bindings.
1034 (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
1036 (define-key rmail-summary-mode-map [menu-bar classify]
1037 (cons "Classify" (make-sparse-keymap "Classify")))
1039 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1040 '("Output (Rmail Menu)..." . rmail-summary-output-menu))
1042 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1043 '("Input Rmail File (menu)..." . rmail-input-menu))
1045 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1048 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1051 (define-key rmail-summary-mode-map [menu-bar classify output-body]
1052 '("Output (body)..." . rmail-summary-output-body))
1054 (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
1055 '("Output (inbox)..." . rmail-summary-output))
1057 (define-key rmail-summary-mode-map [menu-bar classify output]
1058 '("Output (Rmail)..." . rmail-summary-output))
1060 (define-key rmail-summary-mode-map [menu-bar classify kill-label]
1061 '("Kill Label..." . rmail-summary-kill-label))
1063 (define-key rmail-summary-mode-map [menu-bar classify add-label]
1064 '("Add Label..." . rmail-summary-add-label))
1066 (define-key rmail-summary-mode-map [menu-bar summary]
1067 (cons "Summary" (make-sparse-keymap "Summary")))
1069 (define-key rmail-summary-mode-map [menu-bar summary senders]
1070 '("By Senders..." . rmail-summary-by-senders))
1072 (define-key rmail-summary-mode-map [menu-bar summary labels]
1073 '("By Labels..." . rmail-summary-by-labels))
1075 (define-key rmail-summary-mode-map [menu-bar summary recipients]
1076 '("By Recipients..." . rmail-summary-by-recipients))
1078 (define-key rmail-summary-mode-map [menu-bar summary topic]
1079 '("By Topic..." . rmail-summary-by-topic))
1081 (define-key rmail-summary-mode-map [menu-bar summary regexp]
1082 '("By Regexp..." . rmail-summary-by-regexp))
1084 (define-key rmail-summary-mode-map [menu-bar summary all]
1085 '("All" . rmail-summary))
1087 (define-key rmail-summary-mode-map [menu-bar mail]
1088 (cons "Mail" (make-sparse-keymap "Mail")))
1090 (define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail]
1091 '("Get New Mail" . rmail-summary-get-new-mail))
1093 (define-key rmail-summary-mode-map [menu-bar mail lambda]
1096 (define-key rmail-summary-mode-map [menu-bar mail continue]
1097 '("Continue" . rmail-summary-continue))
1099 (define-key rmail-summary-mode-map [menu-bar mail resend]
1100 '("Re-send..." . rmail-summary-resend))
1102 (define-key rmail-summary-mode-map [menu-bar mail forward]
1103 '("Forward" . rmail-summary-forward))
1105 (define-key rmail-summary-mode-map [menu-bar mail retry]
1106 '("Retry" . rmail-summary-retry-failure))
1108 (define-key rmail-summary-mode-map [menu-bar mail reply]
1109 '("Reply" . rmail-summary-reply))
1111 (define-key rmail-summary-mode-map [menu-bar mail mail]
1112 '("Mail" . rmail-summary-mail))
1114 (define-key rmail-summary-mode-map [menu-bar delete]
1115 (cons "Delete" (make-sparse-keymap "Delete")))
1117 (define-key rmail-summary-mode-map [menu-bar delete expunge/save]
1118 '("Expunge/Save" . rmail-summary-expunge-and-save))
1120 (define-key rmail-summary-mode-map [menu-bar delete expunge]
1121 '("Expunge" . rmail-summary-expunge))
1123 (define-key rmail-summary-mode-map [menu-bar delete undelete]
1124 '("Undelete" . rmail-summary-undelete))
1126 (define-key rmail-summary-mode-map [menu-bar delete delete]
1127 '("Delete" . rmail-summary-delete-forward))
1129 (define-key rmail-summary-mode-map [menu-bar move]
1130 (cons "Move" (make-sparse-keymap "Move")))
1132 (define-key rmail-summary-mode-map [menu-bar move search-back]
1133 '("Search Back..." . rmail-summary-search-backward))
1135 (define-key rmail-summary-mode-map [menu-bar move search]
1136 '("Search..." . rmail-summary-search))
1138 (define-key rmail-summary-mode-map [menu-bar move previous]
1139 '("Previous Nondeleted" . rmail-summary-previous-msg))
1141 (define-key rmail-summary-mode-map [menu-bar move next]
1142 '("Next Nondeleted" . rmail-summary-next-msg))
1144 (define-key rmail-summary-mode-map [menu-bar move last]
1145 '("Last" . rmail-summary-last-message))
1147 (define-key rmail-summary-mode-map [menu-bar move first]
1148 '("First" . rmail-summary-first-message))
1150 (define-key rmail-summary-mode-map [menu-bar move previous]
1151 '("Previous" . rmail-summary-previous-all))
1153 (define-key rmail-summary-mode-map [menu-bar move next]
1154 '("Next" . rmail-summary-next-all))
1156 (defun rmail-summary-mouse-goto-message (event)
1157 "Select the message whose summary line you click on."
1159 (goto-char (posn-point (event-end event)))
1160 (rmail-summary-goto-msg))
1162 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
1163 "Go to message N in the summary buffer and the Rmail buffer.
1164 If N is nil, use the message corresponding to point in the summary
1165 and move to that message in the Rmail buffer.
1167 If NOWARN, don't say anything if N is out of range.
1168 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1169 Returns non-nil if message N was found."
1171 (if (consp n) (setq n (prefix-numeric-value n)))
1172 (if (eobp) (forward-line -1))
1174 (let* ((obuf (current-buffer))
1178 (curmsg (string-to-number
1179 (buffer-substring (point)
1180 (min (point-max) (+ 6 (point))))))
1181 (total (save-excursion (set-buffer buf) rmail-total-messages)))
1182 ;; If message number N was specified, find that message's line
1183 ;; or set message-not-found.
1184 ;; If N wasn't specified or that message can't be found.
1185 ;; set N by default.
1189 (progn (message "No preceding message")
1191 (if (and (> n total)
1193 (progn (message "No following message")
1194 (goto-char (point-max))
1195 (rmail-summary-goto-msg nil nowarn skip-rmail)))
1196 (goto-char (point-min))
1197 (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t))
1198 (progn (or nowarn (message "Message %d not found" n))
1200 (setq message-not-found t)
1203 (skip-chars-forward " ")
1204 (skip-chars-forward "0-9")
1205 (save-excursion (if (= (following-char) ?-)
1206 (let ((buffer-read-only nil))
1209 (rmail-summary-update-highlight message-not-found)
1213 (let ((selwin (selected-window)))
1215 (progn (pop-to-buffer buf)
1216 (rmail-show-message-maybe n))
1217 (select-window selwin)
1218 ;; The actions above can alter the current buffer. Preserve it.
1219 (set-buffer obuf))))
1220 (not message-not-found)))
1222 ;; Update the highlighted line in an rmail summary buffer.
1223 ;; That should be current. We highlight the line point is on.
1224 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1225 (defun rmail-summary-update-highlight (not-found)
1226 ;; Make sure we have an overlay to use.
1227 (or rmail-summary-overlay
1229 (make-local-variable 'rmail-summary-overlay)
1230 (setq rmail-summary-overlay (make-overlay (point) (point)))
1231 (overlay-put rmail-summary-overlay 'rmail-summary t)))
1232 ;; If this message is in the summary, use the overlay to highlight it.
1233 ;; Otherwise, don't highlight anything.
1235 (overlay-put rmail-summary-overlay 'face nil)
1236 (move-overlay rmail-summary-overlay
1237 (save-excursion (beginning-of-line)
1238 (skip-chars-forward " ")
1240 (line-end-position))
1241 (overlay-put rmail-summary-overlay 'face 'highlight)))
1243 (defun rmail-summary-scroll-msg-up (&optional dist)
1244 "Scroll the Rmail window forward.
1245 If the Rmail window is displaying the end of a message,
1246 advance to the next message."
1249 (rmail-summary-scroll-msg-down nil)
1250 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1251 (if rmail-buffer-window
1252 (if (let ((rmail-summary-window (selected-window)))
1253 (select-window rmail-buffer-window)
1255 ;; Is EOB visible in the buffer?
1257 (let ((ht (window-height (selected-window))))
1258 (move-to-window-line (- ht 2))
1261 (select-window rmail-summary-window)))
1262 (if (not rmail-summary-scroll-between-messages)
1263 (error "End of buffer")
1264 (rmail-summary-next-msg (or dist 1)))
1265 (let ((other-window-scroll-buffer rmail-buffer))
1266 (scroll-other-window dist)))
1267 ;; If it isn't visible at all, show the beginning.
1268 (rmail-summary-beginning-of-message)))))
1270 (defun rmail-summary-scroll-msg-down (&optional dist)
1271 "Scroll the Rmail window backward.
1272 If the Rmail window is now displaying the beginning of a message,
1273 move to the previous message."
1276 (rmail-summary-scroll-msg-up nil)
1277 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1278 (if rmail-buffer-window
1279 (if (let ((rmail-summary-window (selected-window)))
1280 (select-window rmail-buffer-window)
1282 ;; Is BOB visible in the buffer?
1284 (move-to-window-line 0)
1287 (select-window rmail-summary-window)))
1288 (if (not rmail-summary-scroll-between-messages)
1289 (error "Beginning of buffer")
1290 (rmail-summary-previous-msg (or dist 1)))
1291 (let ((other-window-scroll-buffer rmail-buffer))
1292 (scroll-other-window-down dist)))
1293 ;; If it isn't visible at all, show the beginning.
1294 (rmail-summary-beginning-of-message)))))
1296 (defun rmail-summary-beginning-of-message ()
1297 "Show current message from the beginning."
1299 (rmail-summary-show-message 'BEG))
1301 (defun rmail-summary-end-of-message ()
1302 "Show bottom of current message."
1304 (rmail-summary-show-message 'END))
1306 (defun rmail-summary-show-message (where)
1307 "Show current mail message.
1308 Position it according to WHERE which can be BEG or END"
1309 (if (and (one-window-p) (not pop-up-frames))
1310 ;; If there is just one window, put the summary on the top.
1311 (let ((buffer rmail-buffer))
1312 (split-window (selected-window) rmail-summary-window-size)
1313 (select-window (frame-first-window))
1314 (pop-to-buffer rmail-buffer)
1315 ;; If pop-to-buffer did not use that window, delete that
1316 ;; window. (This can happen if it uses another frame.)
1317 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1318 (delete-other-windows)))
1319 (pop-to-buffer rmail-buffer))
1322 (goto-char (point-min))
1323 (search-forward "\n\n"))
1325 (goto-char (point-max))
1326 (recenter (1- (window-height))))
1328 (pop-to-buffer rmail-summary-buffer))
1330 (defun rmail-summary-bury ()
1331 "Bury the Rmail buffer and the Rmail summary buffer."
1333 (let ((buffer-to-bury (current-buffer)))
1335 (while (setq window (get-buffer-window rmail-buffer))
1336 (set-window-buffer window (other-buffer rmail-buffer)))
1337 (bury-buffer rmail-buffer))
1338 (switch-to-buffer (other-buffer buffer-to-bury))
1339 (bury-buffer buffer-to-bury)))
1341 (defun rmail-summary-quit ()
1342 "Quit out of Rmail and Rmail summary."
1344 (rmail-summary-wipe)
1347 (defun rmail-summary-wipe ()
1348 "Kill and wipe away Rmail summary, remaining within Rmail."
1350 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
1351 (let ((local-rmail-buffer rmail-buffer))
1352 (kill-buffer (current-buffer))
1353 ;; Delete window if not only one.
1354 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1356 ;; Switch windows to the rmail buffer, or switch to it in this window.
1357 (pop-to-buffer local-rmail-buffer)))
1359 (defun rmail-summary-expunge ()
1360 "Actually erase all deleted messages and recompute summary headers."
1363 (set-buffer rmail-buffer)
1364 (when (rmail-expunge-confirmed)
1365 (rmail-only-expunge)))
1366 (rmail-update-summary))
1368 (defun rmail-summary-expunge-and-save ()
1369 "Expunge and save RMAIL file."
1372 (rmail-expunge-and-save))
1373 (rmail-update-summary)
1374 (set-buffer-modified-p nil))
1376 (defun rmail-summary-get-new-mail (&optional file-name)
1377 "Get new mail and recompute summary headers.
1379 Optionally you can specify the file to get new mail from. In this case,
1380 the file of new mail is not changed or deleted. Noninteractively, you can
1381 pass the inbox file name as an argument. Interactively, a prefix
1382 argument says to read a file name and use that file as the inbox."
1384 (list (if current-prefix-arg
1385 (read-file-name "Get new mail from file: "))))
1388 (set-buffer rmail-buffer)
1389 (rmail-get-new-mail file-name)
1390 ;; Get the proper new message number.
1391 (setq msg rmail-current-message))
1392 ;; Make sure that message is displayed.
1394 (rmail-summary-goto-msg msg))))
1396 (defun rmail-summary-input (filename)
1397 "Run Rmail on file FILENAME."
1398 (interactive "FRun rmail on RMAIL file: ")
1399 ;; We switch windows here, then display the other Rmail file there.
1400 (pop-to-buffer rmail-buffer)
1403 (defun rmail-summary-first-message ()
1404 "Show first message in Rmail file from summary buffer."
1407 (beginning-of-buffer)))
1409 (defun rmail-summary-last-message ()
1410 "Show last message in Rmail file from summary buffer."
1416 (declare-function rmail-abort-edit "rmailedit" ())
1417 (declare-function rmail-cease-edit "rmailedit"())
1418 (declare-function rmail-set-label "rmailkwd" (l state &optional n))
1419 (declare-function rmail-output-read-file-name "rmailout" ())
1420 (declare-function mail-send-and-exit "sendmail" (&optional arg))
1422 (defvar rmail-summary-edit-map nil)
1423 (if rmail-summary-edit-map
1425 (setq rmail-summary-edit-map
1426 (nconc (make-sparse-keymap) text-mode-map))
1427 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
1428 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
1430 (defun rmail-summary-edit-current-message ()
1431 "Edit the contents of this message."
1433 (pop-to-buffer rmail-buffer)
1434 (rmail-edit-current-message)
1435 (use-local-map rmail-summary-edit-map))
1437 (defun rmail-summary-cease-edit ()
1438 "Finish editing message, then go back to Rmail summary buffer."
1441 (pop-to-buffer rmail-summary-buffer))
1443 (defun rmail-summary-abort-edit ()
1444 "Abort edit of current message; restore original contents.
1445 Go back to summary buffer."
1448 (pop-to-buffer rmail-summary-buffer))
1450 (defun rmail-summary-search-backward (regexp &optional n)
1451 "Show message containing next match for REGEXP.
1452 Prefix argument gives repeat count; negative argument means search
1453 backwards (through earlier messages).
1454 Interactively, empty argument means use same regexp used last time."
1456 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1458 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1462 (if rmail-search-last-regexp
1463 (concat ", default "
1464 rmail-search-last-regexp "): ")
1466 (setq regexp (read-string prompt))
1467 (cond ((not (equal regexp ""))
1468 (setq rmail-search-last-regexp regexp))
1469 ((not rmail-search-last-regexp)
1470 (error "No previous Rmail search string")))
1471 (list rmail-search-last-regexp
1472 (prefix-numeric-value current-prefix-arg))))
1473 ;; Don't use save-excursion because that prevents point from moving
1474 ;; properly in the summary buffer.
1475 (let ((buffer (current-buffer)))
1478 (set-buffer rmail-buffer)
1479 (rmail-search regexp (- n)))
1480 (set-buffer buffer))))
1482 (defun rmail-summary-search (regexp &optional n)
1483 "Show message containing next match for REGEXP.
1484 Prefix argument gives repeat count; negative argument means search
1485 backwards (through earlier messages).
1486 Interactively, empty argument means use same regexp used last time."
1488 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1490 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1494 (if rmail-search-last-regexp
1495 (concat ", default "
1496 rmail-search-last-regexp "): ")
1498 (setq regexp (read-string prompt))
1499 (cond ((not (equal regexp ""))
1500 (setq rmail-search-last-regexp regexp))
1501 ((not rmail-search-last-regexp)
1502 (error "No previous Rmail search string")))
1503 (list rmail-search-last-regexp
1504 (prefix-numeric-value current-prefix-arg))))
1505 ;; Don't use save-excursion because that prevents point from moving
1506 ;; properly in the summary buffer.
1507 (let ((buffer (current-buffer)))
1510 (set-buffer rmail-buffer)
1511 (rmail-search regexp n))
1512 (set-buffer buffer))))
1514 (defun rmail-summary-toggle-header ()
1515 "Show original message header if pruned header currently shown, or vice versa."
1517 (save-window-excursion
1518 (set-buffer rmail-buffer)
1519 (rmail-toggle-header))
1520 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1521 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1522 (let ((window (get-buffer-window rmail-buffer)))
1524 ;; Using save-window-excursion would lose the new value of point.
1525 (let ((owin (selected-window)))
1528 (select-window window)
1529 (goto-char (point-min)))
1530 (select-window owin))))))
1533 (defun rmail-summary-add-label (label)
1534 "Add LABEL to labels associated with current Rmail message.
1535 Completion is performed over known labels when reading."
1536 (interactive (list (save-excursion
1537 (set-buffer rmail-buffer)
1538 (rmail-read-label "Add label"))))
1540 (set-buffer rmail-buffer)
1541 (rmail-add-label label)))
1543 (defun rmail-summary-kill-label (label)
1544 "Remove LABEL from labels associated with current Rmail message.
1545 Completion is performed over known labels when reading."
1546 (interactive (list (save-excursion
1547 (set-buffer rmail-buffer)
1548 (rmail-read-label "Kill label"))))
1550 (set-buffer rmail-buffer)
1551 (rmail-set-label label nil)))
1553 ;;;; *** Rmail Summary Mailing Commands ***
1555 (defun rmail-summary-override-mail-send-and-exit ()
1556 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1557 (use-local-map (copy-keymap (current-local-map)))
1558 (dolist (key (where-is-internal 'mail-send-and-exit))
1559 (define-key (current-local-map) key 'rmail-summary-send-and-exit)))
1561 (defun rmail-summary-mail ()
1562 "Send mail in another window.
1563 While composing the message, use \\[mail-yank-original] to yank the
1564 original message into it."
1566 (let ((window (get-buffer-window rmail-buffer)))
1568 (select-window window)
1569 (set-buffer rmail-buffer)))
1570 (rmail-start-mail nil nil nil nil nil (current-buffer))
1571 (rmail-summary-override-mail-send-and-exit))
1573 (defun rmail-summary-continue ()
1574 "Continue composing outgoing message previously being composed."
1576 (let ((window (get-buffer-window rmail-buffer)))
1578 (select-window window)
1579 (set-buffer rmail-buffer)))
1580 (rmail-start-mail t))
1582 (defun rmail-summary-reply (just-sender)
1583 "Reply to the current message.
1584 Normally include CC: to all other recipients of original message;
1585 prefix argument means ignore them. While composing the reply,
1586 use \\[mail-yank-original] to yank the original message into it."
1588 (let ((window (get-buffer-window rmail-buffer)))
1590 (select-window window)
1591 (set-buffer rmail-buffer)))
1592 (rmail-reply just-sender)
1593 (rmail-summary-override-mail-send-and-exit))
1595 (defun rmail-summary-retry-failure ()
1596 "Edit a mail message which is based on the contents of the current message.
1597 For a message rejected by the mail system, extract the interesting headers and
1598 the body of the original message; otherwise copy the current message."
1600 (let ((window (get-buffer-window rmail-buffer)))
1602 (select-window window)
1603 (set-buffer rmail-buffer)))
1604 (rmail-retry-failure)
1605 (rmail-summary-override-mail-send-and-exit))
1607 (defun rmail-summary-send-and-exit ()
1608 "Send mail reply and return to summary buffer."
1610 (mail-send-and-exit t))
1612 (defun rmail-summary-forward (resend)
1613 "Forward the current message to another user.
1614 With prefix argument, \"resend\" the message instead of forwarding it;
1615 see the documentation of `rmail-resend'."
1618 (let ((window (get-buffer-window rmail-buffer)))
1620 (select-window window)
1621 (set-buffer rmail-buffer)))
1622 (rmail-forward resend)
1623 (rmail-summary-override-mail-send-and-exit)))
1625 (defun rmail-summary-resend ()
1626 "Resend current message using `rmail-resend'."
1629 (let ((window (get-buffer-window rmail-buffer)))
1631 (select-window window)
1632 (set-buffer rmail-buffer)))
1633 (call-interactively 'rmail-resend)))
1635 ;; Summary output commands.
1637 (defun rmail-summary-output (&optional file-name n)
1638 "Append this message to mail file FILE-NAME.
1639 This works with both mbox format and Babyl format files,
1640 outputting in the appropriate format for each.
1641 The default file name comes from `rmail-default-file',
1642 which is updated to the name you use in this command.
1644 A prefix argument N says to output that many consecutive messages
1645 from those in the summary, starting with the current one.
1646 Deleted messages are skipped and don't count.
1647 When called from Lisp code, N may be omitted and defaults to 1.
1649 This command always outputs the complete message header,
1650 even the header display is currently pruned."
1652 (progn (require 'rmailout)
1653 (list (rmail-output-read-file-name)
1654 (prefix-numeric-value current-prefix-arg))))
1655 (let ((i 0) prev-msg)
1658 (progn (rmail-summary-goto-msg)
1661 (with-current-buffer rmail-buffer
1662 rmail-current-message))))))
1664 (with-current-buffer rmail-buffer
1665 (let ((rmail-delete-after-output nil))
1666 (rmail-output file-name 1)))
1667 (if rmail-delete-after-output
1668 (rmail-summary-delete-forward nil)
1670 (rmail-summary-next-msg 1))))))
1672 (defalias 'rmail-summary-output-to-rmail-file 'rmail-summary-output)
1674 (declare-function rmail-output-as-seen "rmailout"
1675 (file-name &optional count noattribute from-gnus))
1677 (defun rmail-summary-output-as-seen (&optional file-name n)
1678 "Append this message to system-inbox-format mail file named FILE-NAME.
1679 A prefix argument N says to output that many consecutive messages,
1680 from the summary, starting with the current one.
1681 Deleted messages are skipped and don't count.
1682 When called from Lisp code, N may be omitted and defaults to 1.
1684 This outputs the message header as you see it (or would see it)
1687 The default file name comes from `rmail-default-file',
1688 which is updated to the name you use in this command."
1690 (progn (require 'rmailout)
1691 (list (rmail-output-read-file-name)
1692 (prefix-numeric-value current-prefix-arg))))
1693 (require 'rmailout) ; for rmail-output-as-seen in non-interactive case
1694 (let ((i 0) prev-msg)
1697 (progn (rmail-summary-goto-msg)
1700 (with-current-buffer rmail-buffer
1701 rmail-current-message))))))
1703 (with-current-buffer rmail-buffer
1704 (let ((rmail-delete-after-output nil))
1705 (rmail-output-as-seen file-name 1)))
1706 (if rmail-delete-after-output
1707 (rmail-summary-delete-forward nil)
1709 (rmail-summary-next-msg 1))))))
1711 (defun rmail-summary-output-menu ()
1712 "Output current message to another Rmail file, chosen with a menu.
1713 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1714 The variables `rmail-secondary-file-directory' and
1715 `rmail-secondary-file-regexp' control which files are offered in the menu."
1718 (set-buffer rmail-buffer)
1719 (let ((rmail-delete-after-output nil))
1720 (call-interactively 'rmail-output-menu)))
1721 (if rmail-delete-after-output
1722 (rmail-summary-delete-forward nil)))
1724 (defun rmail-summary-construct-io-menu ()
1725 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1728 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1729 (cons "Input Rmail File"
1730 (rmail-list-to-menu "Input Rmail File"
1732 'rmail-summary-input)))
1733 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1734 (cons "Output Rmail File"
1735 (rmail-list-to-menu "Output Rmail File"
1737 'rmail-summary-output))))
1738 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1739 '("Input Rmail File" . rmail-disable-menu))
1740 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1741 '("Output Rmail File" . rmail-disable-menu)))))
1743 (defun rmail-summary-output-body (&optional file-name)
1744 "Write this message body to the file FILE-NAME.
1745 FILE-NAME defaults, interactively, from the Subject field of the message."
1748 (set-buffer rmail-buffer)
1749 (let ((rmail-delete-after-output nil))
1751 (rmail-output-body-to-file file-name)
1752 (call-interactively 'rmail-output-body-to-file))))
1753 (if rmail-delete-after-output
1754 (rmail-summary-delete-forward nil)))
1756 ;; Sorting messages in Rmail Summary buffer.
1758 (defun rmail-summary-sort-by-date (reverse)
1759 "Sort messages of current Rmail summary by date.
1760 If prefix argument REVERSE is non-nil, sort them in reverse order."
1762 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1764 (defun rmail-summary-sort-by-subject (reverse)
1765 "Sort messages of current Rmail summary by subject.
1766 If prefix argument REVERSE is non-nil, sort them in reverse order."
1768 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1770 (defun rmail-summary-sort-by-author (reverse)
1771 "Sort messages of current Rmail summary by author.
1772 If prefix argument REVERSE is non-nil, sort them in reverse order."
1774 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1776 (defun rmail-summary-sort-by-recipient (reverse)
1777 "Sort messages of current Rmail summary by recipient.
1778 If prefix argument REVERSE is non-nil, sort them in reverse order."
1780 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1782 (defun rmail-summary-sort-by-correspondent (reverse)
1783 "Sort messages of current Rmail summary by other correspondent.
1784 If prefix argument REVERSE is non-nil, sort them in reverse order."
1786 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1788 (defun rmail-summary-sort-by-lines (reverse)
1789 "Sort messages of current Rmail summary by lines of the message.
1790 If prefix argument REVERSE is non-nil, sort them in reverse order."
1792 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1794 (defun rmail-summary-sort-by-labels (reverse labels)
1795 "Sort messages of current Rmail summary by labels.
1796 If prefix argument REVERSE is non-nil, sort them in reverse order.
1797 KEYWORDS is a comma-separated list of labels."
1798 (interactive "P\nsSort by labels: ")
1799 (rmail-sort-from-summary
1800 (function (lambda (reverse)
1801 (rmail-sort-by-labels reverse labels)))
1804 (defun rmail-sort-from-summary (sortfun reverse)
1805 "Sort Rmail messages from Summary buffer and update it after sorting."
1806 (require 'rmailsort)
1807 (let ((selwin (selected-window)))
1809 (progn (pop-to-buffer rmail-buffer)
1810 (funcall sortfun reverse))
1811 (select-window selwin))))
1815 ;; arch-tag: 80b0a27a-a50d-4f37-9466-83d32d1e0ca8
1816 ;;; rmailsum.el ends here