* lisp/mail/rmailsum.el (rmail-summary-by-recipients)
[emacs.git] / lisp / mail / rmailsum.el
blobeeb42e81c6d0960b6561589604ba7bbec0830d35
1 ;;; rmailsum.el --- make summary buffers for the mail reader -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985, 1993-1996, 2000-2015 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: mail
7 ;; Package: rmail
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/>.
24 ;;; Commentary:
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.
30 ;;; Code:
32 ;; For rmail-select-summary.
33 (require 'rmail)
34 (require 'rfc2047)
36 (defcustom rmail-summary-scroll-between-messages t
37 "Non-nil means Rmail summary scroll commands move between messages.
38 That is, after `rmail-summary-scroll-msg-up' reaches the end of a
39 message, it moves to the next message; and similarly for
40 `rmail-summary-scroll-msg-down'."
41 :type 'boolean
42 :group 'rmail-summary)
44 ;; FIXME could do with a :set function that regenerates the summary
45 ;; and updates rmail-summary-vector.
46 (defcustom rmail-summary-line-count-flag t
47 "Non-nil means Rmail summary should show the number of lines in each message.
48 Setting this option to nil might speed up the generation of summaries."
49 :type 'boolean
50 :group 'rmail-summary)
52 (defvar rmail-summary-font-lock-keywords
53 '(("^.....D.*" . font-lock-string-face) ; Deleted.
54 ("^.....-.*" . font-lock-type-face) ; Unread.
55 ;; Neither of the below will be highlighted if either of the above are:
56 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date.
57 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face)) ; Labels.
58 "Additional expressions to highlight in Rmail Summary mode.")
60 (defvar rmail-summary-redo nil
61 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
63 (defvar rmail-summary-overlay nil
64 "Overlay used to highlight the current message in the Rmail summary.")
65 (put 'rmail-summary-overlay 'permanent-local t)
67 (defvar rmail-summary-mode-map
68 (let ((map (make-keymap)))
69 (suppress-keymap map)
70 (define-key map [mouse-2] 'rmail-summary-mouse-goto-message)
71 (define-key map "a" 'rmail-summary-add-label)
72 (define-key map "b" 'rmail-summary-bury)
73 (define-key map "c" 'rmail-summary-continue)
74 (define-key map "d" 'rmail-summary-delete-forward)
75 (define-key map "\C-d" 'rmail-summary-delete-backward)
76 (define-key map "e" 'rmail-summary-edit-current-message)
77 (define-key map "f" 'rmail-summary-forward)
78 (define-key map "g" 'rmail-summary-get-new-mail)
79 (define-key map "h" 'rmail-summary)
80 (define-key map "i" 'rmail-summary-input)
81 (define-key map "j" 'rmail-summary-goto-msg)
82 (define-key map "\C-m" 'rmail-summary-goto-msg)
83 (define-key map "k" 'rmail-summary-kill-label)
84 (define-key map "l" 'rmail-summary-by-labels)
85 (define-key map "\e\C-h" 'rmail-summary)
86 (define-key map "\e\C-l" 'rmail-summary-by-labels)
87 (define-key map "\e\C-r" 'rmail-summary-by-recipients)
88 (define-key map "\e\C-s" 'rmail-summary-by-regexp)
89 ;; `f' for "from".
90 (define-key map "\e\C-f" 'rmail-summary-by-senders)
91 (define-key map "\e\C-t" 'rmail-summary-by-topic)
92 (define-key map "m" 'rmail-summary-mail)
93 (define-key map "\M-m" 'rmail-summary-retry-failure)
94 (define-key map "n" 'rmail-summary-next-msg)
95 (define-key map "\en" 'rmail-summary-next-all)
96 (define-key map "\e\C-n" 'rmail-summary-next-labeled-message)
97 (define-key map "o" 'rmail-summary-output)
98 (define-key map "\C-o" 'rmail-summary-output-as-seen)
99 (define-key map "p" 'rmail-summary-previous-msg)
100 (define-key map "\ep" 'rmail-summary-previous-all)
101 (define-key map "\e\C-p" 'rmail-summary-previous-labeled-message)
102 (define-key map "q" 'rmail-summary-quit)
103 (define-key map "Q" 'rmail-summary-wipe)
104 (define-key map "r" 'rmail-summary-reply)
105 (define-key map "s" 'rmail-summary-expunge-and-save)
106 ;; See rms's comment in rmail.el
107 ;; (define-key map "\er" 'rmail-summary-search-backward)
108 (define-key map "\es" 'rmail-summary-search)
109 (define-key map "t" 'rmail-summary-toggle-header)
110 (define-key map "u" 'rmail-summary-undelete)
111 (define-key map "\M-u" 'rmail-summary-undelete-many)
112 (define-key map "x" 'rmail-summary-expunge)
113 (define-key map "w" 'rmail-summary-output-body)
114 (define-key map "v" 'rmail-mime)
115 (define-key map "." 'rmail-summary-beginning-of-message)
116 (define-key map "/" 'rmail-summary-end-of-message)
117 (define-key map "<" 'rmail-summary-first-message)
118 (define-key map ">" 'rmail-summary-last-message)
119 (define-key map " " 'rmail-summary-scroll-msg-up)
120 (define-key map [?\S-\ ] 'rmail-summary-scroll-msg-down)
121 (define-key map "\177" 'rmail-summary-scroll-msg-down)
122 (define-key map "?" 'describe-mode)
123 (define-key map "\C-c\C-n" 'rmail-summary-next-same-subject)
124 (define-key map "\C-c\C-p" 'rmail-summary-previous-same-subject)
125 (define-key map "\C-c\C-s\C-d" 'rmail-summary-sort-by-date)
126 (define-key map "\C-c\C-s\C-s" 'rmail-summary-sort-by-subject)
127 (define-key map "\C-c\C-s\C-a" 'rmail-summary-sort-by-author)
128 (define-key map "\C-c\C-s\C-r" 'rmail-summary-sort-by-recipient)
129 (define-key map "\C-c\C-s\C-c" 'rmail-summary-sort-by-correspondent)
130 (define-key map "\C-c\C-s\C-l" 'rmail-summary-sort-by-lines)
131 (define-key map "\C-c\C-s\C-k" 'rmail-summary-sort-by-labels)
132 (define-key map "\C-x\C-s" 'rmail-summary-save-buffer)
134 ;; Menu bar bindings.
136 (define-key map [menu-bar] (make-sparse-keymap))
138 (define-key map [menu-bar classify]
139 (cons "Classify" (make-sparse-keymap "Classify")))
141 (define-key map [menu-bar classify output-menu]
142 '("Output (Rmail Menu)..." . rmail-summary-output-menu))
144 (define-key map [menu-bar classify input-menu]
145 '("Input Rmail File (menu)..." . rmail-input-menu))
147 (define-key map [menu-bar classify input-menu]
148 '(nil))
150 (define-key map [menu-bar classify output-menu]
151 '(nil))
153 (define-key map [menu-bar classify output-body]
154 '("Output body..." . rmail-summary-output-body))
156 (define-key map [menu-bar classify output-inbox]
157 '("Output..." . rmail-summary-output))
159 (define-key map [menu-bar classify output]
160 '("Output as seen..." . rmail-summary-output-as-seen))
162 (define-key map [menu-bar classify kill-label]
163 '("Kill Label..." . rmail-summary-kill-label))
165 (define-key map [menu-bar classify add-label]
166 '("Add Label..." . rmail-summary-add-label))
168 (define-key map [menu-bar summary]
169 (cons "Summary" (make-sparse-keymap "Summary")))
171 (define-key map [menu-bar summary senders]
172 '("By Senders..." . rmail-summary-by-senders))
174 (define-key map [menu-bar summary labels]
175 '("By Labels..." . rmail-summary-by-labels))
177 (define-key map [menu-bar summary recipients]
178 '("By Recipients..." . rmail-summary-by-recipients))
180 (define-key map [menu-bar summary topic]
181 '("By Topic..." . rmail-summary-by-topic))
183 (define-key map [menu-bar summary regexp]
184 '("By Regexp..." . rmail-summary-by-regexp))
186 (define-key map [menu-bar summary all]
187 '("All" . rmail-summary))
189 (define-key map [menu-bar mail]
190 (cons "Mail" (make-sparse-keymap "Mail")))
192 (define-key map [menu-bar mail rmail-summary-get-new-mail]
193 '("Get New Mail" . rmail-summary-get-new-mail))
195 (define-key map [menu-bar mail lambda]
196 '("----"))
198 (define-key map [menu-bar mail continue]
199 '("Continue" . rmail-summary-continue))
201 (define-key map [menu-bar mail resend]
202 '("Re-send..." . rmail-summary-resend))
204 (define-key map [menu-bar mail forward]
205 '("Forward" . rmail-summary-forward))
207 (define-key map [menu-bar mail retry]
208 '("Retry" . rmail-summary-retry-failure))
210 (define-key map [menu-bar mail reply]
211 '("Reply" . rmail-summary-reply))
213 (define-key map [menu-bar mail mail]
214 '("Mail" . rmail-summary-mail))
216 (define-key map [menu-bar delete]
217 (cons "Delete" (make-sparse-keymap "Delete")))
219 (define-key map [menu-bar delete expunge/save]
220 '("Expunge/Save" . rmail-summary-expunge-and-save))
222 (define-key map [menu-bar delete expunge]
223 '("Expunge" . rmail-summary-expunge))
225 (define-key map [menu-bar delete undelete]
226 '("Undelete" . rmail-summary-undelete))
228 (define-key map [menu-bar delete delete]
229 '("Delete" . rmail-summary-delete-forward))
231 (define-key map [menu-bar move]
232 (cons "Move" (make-sparse-keymap "Move")))
234 (define-key map [menu-bar move search-back]
235 '("Search Back..." . rmail-summary-search-backward))
237 (define-key map [menu-bar move search]
238 '("Search..." . rmail-summary-search))
240 (define-key map [menu-bar move previous]
241 '("Previous Nondeleted" . rmail-summary-previous-msg))
243 (define-key map [menu-bar move next]
244 '("Next Nondeleted" . rmail-summary-next-msg))
246 (define-key map [menu-bar move last]
247 '("Last" . rmail-summary-last-message))
249 (define-key map [menu-bar move first]
250 '("First" . rmail-summary-first-message))
252 (define-key map [menu-bar move previous]
253 '("Previous" . rmail-summary-previous-all))
255 (define-key map [menu-bar move next]
256 '("Next" . rmail-summary-next-all))
257 map)
258 "Keymap used in Rmail summary mode.")
260 ;; Entry points for making a summary buffer.
262 ;; Regenerate the contents of the summary
263 ;; using the same selection criterion as last time.
264 ;; M-x revert-buffer in a summary buffer calls this function.
265 (defun rmail-update-summary (&rest _)
266 (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
268 ;;;###autoload
269 (defun rmail-summary ()
270 "Display a summary of all messages, one line per message."
271 (interactive)
272 (rmail-new-summary "All" '(rmail-summary) nil))
274 ;;;###autoload
275 (defun rmail-summary-by-labels (labels)
276 "Display a summary of all messages with one or more LABELS.
277 LABELS should be a string containing the desired labels, separated by commas."
278 (interactive "sLabels to summarize by: ")
279 (if (string= labels "")
280 (setq labels (or rmail-last-multi-labels
281 (error "No label specified"))))
282 (setq rmail-last-multi-labels labels)
283 (rmail-new-summary (concat "labels " labels)
284 (list 'rmail-summary-by-labels labels)
285 'rmail-message-labels-p
286 (concat " \\("
287 (mail-comma-list-regexp labels)
288 "\\)\\(,\\|\\'\\)")))
290 ;;;###autoload
291 (defun rmail-summary-by-recipients (recipients &optional primary-only)
292 "Display a summary of all messages with the given RECIPIENTS.
293 Normally checks the To, From and Cc fields of headers;
294 but if PRIMARY-ONLY is non-nil (prefix arg given),
295 only look in the To and From fields.
296 RECIPIENTS is a regular expression."
297 (interactive "sRecipients to summarize by: \nP")
298 (rmail-new-summary
299 (concat "recipients " recipients)
300 (list 'rmail-summary-by-recipients recipients primary-only)
301 'rmail-message-recipients-p recipients primary-only))
303 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
304 (rmail-apply-in-message msg 'rmail-message-recipients-p-1
305 recipients primary-only))
307 (defun rmail-message-recipients-p-1 (recipients &optional primary-only)
308 ;; mail-fetch-field does not care where it starts from.
309 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
310 (or (string-match recipients (or (mail-fetch-field "To") ""))
311 (string-match recipients (or (mail-fetch-field "From") ""))
312 (if (not primary-only)
313 (string-match recipients (or (mail-fetch-field "Cc") "")))))
315 ;; FIXME I find this a non-obvious name for what this function does.
316 ;; Also, the optional WHOLE-MESSAGE argument of r-s-by-topic would
317 ;; seem more natural here.
318 ;;;###autoload
319 (defun rmail-summary-by-regexp (regexp)
320 "Display a summary of all messages according to regexp REGEXP.
321 If the regular expression is found in the header of the message
322 \(including in the date and other lines, as well as the subject line),
323 Emacs will list the message in the summary."
324 (interactive "sRegexp to summarize by: ")
325 (if (string= regexp "")
326 (setq regexp (or rmail-last-regexp
327 (error "No regexp specified"))))
328 (setq rmail-last-regexp regexp)
329 (rmail-new-summary (concat "regexp " regexp)
330 (list 'rmail-summary-by-regexp regexp)
331 'rmail-message-regexp-p
332 regexp))
334 (defun rmail-message-regexp-p (msg regexp)
335 "Return t, if for message number MSG, regexp REGEXP matches in the header."
336 (rmail-apply-in-message msg 'rmail-message-regexp-p-1 msg regexp))
338 (defun rmail--decode-and-apply (function &rest args)
339 "Make an RFC2047-decoded copy of current buffer, apply FUNCTION with ARGS."
340 (let ((buff (current-buffer)))
341 (with-temp-buffer
342 (insert-buffer-substring buff)
343 (goto-char (point-min))
344 ;; FIXME? In rmail-show-message-1, decoding depends on
345 ;; rmail-enable-mime being non-nil (?).
346 (rfc2047-decode-region (point-min)
347 (save-excursion
348 (progn
349 (search-forward "\n\n" nil 'move)
350 (point))))
351 (apply function args))))
353 (defun rmail-message-regexp-p-1 (msg regexp)
354 ;; Search functions can expect to start from the beginning.
355 (narrow-to-region (point) (save-excursion (search-forward "\n\n") (point)))
356 (if (and rmail-enable-mime
357 rmail-search-mime-header-function)
358 (funcall rmail-search-mime-header-function msg regexp (point))
359 ;; We need to search the full headers, but probably want to decode
360 ;; them so they match the ones people see displayed. (Bug#19088)
361 (rmail--decode-and-apply 're-search-forward regexp nil t)))
363 ;;;###autoload
364 (defun rmail-summary-by-topic (subject &optional whole-message)
365 "Display a summary of all messages with the given SUBJECT.
366 Normally checks just the Subject field of headers; but with prefix
367 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
368 SUBJECT is a regular expression."
369 (interactive
370 ;; We quote the default subject, because if it contains regexp
371 ;; special characters (eg "?"), it can fail to match itself. (Bug#2333)
372 (let* ((subject (regexp-quote (rmail-simplified-subject)))
373 (prompt (concat "Topics to summarize by (regexp"
374 (if subject ", default current subject" "")
375 "): ")))
376 (list (read-string prompt nil nil subject) current-prefix-arg)))
377 (rmail-new-summary
378 (concat "about " subject)
379 (list 'rmail-summary-by-topic subject whole-message)
380 'rmail-message-subject-p subject whole-message))
382 (defun rmail-message-subject-p (msg subject &optional whole-message)
383 (if whole-message
384 ;; SUBJECT and rmail-simplified-subject are 2047 decoded.
385 (rmail-apply-in-message msg 'rmail--decode-and-apply
386 're-search-forward subject nil t)
387 (string-match subject (rmail-simplified-subject msg))))
389 ;;;###autoload
390 (defun rmail-summary-by-senders (senders)
391 "Display a summary of all messages whose \"From\" field matches SENDERS.
392 SENDERS is a regular expression."
393 (interactive "sSenders to summarize by: ")
394 (rmail-new-summary
395 (concat "senders " senders)
396 (list 'rmail-summary-by-senders senders) 'rmail-message-senders-p senders))
398 (defun rmail-message-senders-p (msg senders)
399 (string-match senders (or (rmail-get-header "From" msg) "")))
401 ;; General making of a summary buffer.
403 (defvar rmail-summary-symbol-number 0)
405 (defvar rmail-new-summary-line-count)
407 (defun rmail-new-summary (desc redo function &rest args)
408 "Create a summary of selected messages.
409 DESC makes part of the mode line of the summary buffer.
410 REDO is what to put in `rmail-summary-redo'; usually
411 its car is the function that called `rmail-new-summary'
412 and its cdr is the arguments passed to that function.
414 For each message, applies FUNCTION to the message number and ARGS...,
415 and if the result is non-nil, it includes that message in the summary.
416 If FUNCTION is nil, includes all messages."
417 (message "Computing summary lines...")
418 (unless rmail-buffer
419 (error "No RMAIL buffer found"))
420 (let (mesg was-in-summary sumbuf)
421 (if (derived-mode-p 'rmail-summary-mode)
422 (setq was-in-summary t))
423 (with-current-buffer rmail-buffer
424 (setq rmail-summary-buffer (rmail-new-summary-1 desc redo function args)
425 ;; r-s-b is buffer-local.
426 sumbuf rmail-summary-buffer
427 mesg rmail-current-message))
428 ;; Now display the summary buffer and go to the right place in it.
429 (unless was-in-summary
430 (if (and (one-window-p)
431 pop-up-windows
432 (not pop-up-frames))
433 ;; If there is just one window, put the summary on the top.
434 (progn
435 (split-window (selected-window) rmail-summary-window-size)
436 (select-window (next-window (frame-first-window)))
437 (rmail-pop-to-buffer sumbuf)
438 ;; If pop-to-buffer did not use that window, delete that
439 ;; window. (This can happen if it uses another frame.)
440 (if (not (eq sumbuf (window-buffer (frame-first-window))))
441 (delete-other-windows)))
442 (rmail-pop-to-buffer sumbuf))
443 (set-buffer rmail-buffer)
444 ;; This is how rmail makes the summary buffer reappear.
445 ;; We do this here to make the window the proper size.
446 (rmail-select-summary nil)
447 (set-buffer sumbuf))
448 (rmail-summary-goto-msg mesg t t)
449 (rmail-summary-construct-io-menu)
450 (message "Computing summary lines...done")))
452 (defun rmail-new-summary-1 (description redo function args)
453 "Filter messages to obtain summary lines.
454 DESCRIPTION is added to the mode line.
456 Return the summary buffer by invoking FUNCTION on each message
457 passing the message number and ARGS.
459 REDO is what to put in `rmail-summary-redo'.
461 The current buffer must be a Rmail buffer either containing a
462 collection of mbox formatted messages or displaying a single
463 message."
464 (let ((summary-msgs ())
465 (rmail-new-summary-line-count 0)
466 (sumbuf (rmail-get-create-summary-buffer)))
467 ;; Scan the messages, getting their summary strings
468 ;; and putting the list of them in SUMMARY-MSGS.
469 (let ((msgnum 1)
470 (main-buffer (current-buffer))
471 (total rmail-total-messages)
472 (inhibit-read-only t))
473 (save-excursion
474 ;; Go where the mbox text is.
475 (if (rmail-buffers-swapped-p)
476 (set-buffer rmail-view-buffer))
477 (let ((old-min (point-min-marker))
478 (old-max (point-max-marker)))
479 (unwind-protect
480 ;; Can't use save-restriction here; that doesn't work if we
481 ;; plan to modify text outside the original restriction.
482 (save-excursion
483 (widen)
484 (goto-char (point-min))
485 (while (>= total msgnum)
486 ;; Go back to the Rmail buffer so FUNCTION and
487 ;; rmail-get-summary can see its local vars.
488 (with-current-buffer main-buffer
489 ;; First test whether to include this message.
490 (if (or (null function)
491 (apply function msgnum args))
492 (setq summary-msgs
493 (cons (cons msgnum (rmail-get-summary msgnum))
494 summary-msgs))))
495 (setq msgnum (1+ msgnum))
496 ;; Provide a periodic User progress message.
497 (if (and (not (zerop rmail-new-summary-line-count))
498 (zerop (% rmail-new-summary-line-count 10)))
499 (message "Computing summary lines...%d"
500 rmail-new-summary-line-count)))
501 (setq summary-msgs (nreverse summary-msgs)))
502 (narrow-to-region old-min old-max)))))
503 ;; Temporarily, while summary buffer is unfinished,
504 ;; we "don't have" a summary.
505 (setq rmail-summary-buffer nil)
506 ;; I have not a clue what this clause is doing. If you read this
507 ;; chunk of code and have a clue, then please write it here.
508 (if rmail-enable-mime
509 (with-current-buffer rmail-buffer
510 (setq rmail-summary-buffer nil)))
511 (save-excursion
512 (let ((rbuf (current-buffer))
513 (total rmail-total-messages))
514 (set-buffer sumbuf)
515 ;; Set up the summary buffer's contents.
516 (let ((buffer-read-only nil))
517 (erase-buffer)
518 (while summary-msgs
519 (princ (cdr (car summary-msgs)) sumbuf)
520 (setq summary-msgs (cdr summary-msgs)))
521 (goto-char (point-min)))
522 ;; Set up the rest of its state and local variables.
523 (setq buffer-read-only t)
524 (rmail-summary-mode)
525 (make-local-variable 'minor-mode-alist)
526 (setq minor-mode-alist (list (list t (concat ": " description))))
527 (setq rmail-buffer rbuf
528 rmail-summary-redo redo
529 rmail-total-messages total)))
530 sumbuf))
532 (defun rmail-get-create-summary-buffer ()
533 "Return the Rmail summary buffer.
534 If necessary, it is created and undo is disabled."
535 (if (and rmail-summary-buffer (buffer-name rmail-summary-buffer))
536 rmail-summary-buffer
537 (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
538 (with-current-buffer buff
539 (setq buffer-undo-list t))
540 buff)))
543 ;; Low levels of generating a summary.
545 (defun rmail-get-summary (msgnum)
546 "Return the summary line for message MSGNUM.
547 The mbox buffer must be current when you call this function
548 even if its text is swapped.
550 If the message has a summary line already, it will be stored in
551 the message as a header and simply returned, otherwise the
552 summary line is created, saved in the message header, cached and
553 returned.
555 The current buffer contains the unrestricted message collection."
556 (let ((line (aref rmail-summary-vector (1- msgnum))))
557 (unless line
558 ;; Register a summary line for MSGNUM.
559 (setq rmail-new-summary-line-count (1+ rmail-new-summary-line-count)
560 line (rmail-create-summary-line msgnum))
561 ;; Cache the summary line for use during this Rmail session.
562 (aset rmail-summary-vector (1- msgnum) line))
563 line))
565 (defcustom rmail-summary-line-decoder (function rfc2047-decode-string)
566 "Function to decode a Rmail summary line.
567 It receives the summary line for one message as a string
568 and should return the decoded string.
570 By default, it is `rfc2047-decode-string', which decodes MIME-encoded
571 subject."
572 :type 'function
573 :version "23.3"
574 :group 'rmail-summary)
576 (defun rmail-create-summary-line (msgnum)
577 "Return the summary line for message MSGNUM.
578 Obtain the message summary from the header if it is available
579 otherwise create it and store it in the message header.
581 The mbox buffer must be current when you call this function
582 even if its text is swapped."
583 (let ((beg (rmail-msgbeg msgnum))
584 (end (rmail-msgend msgnum))
585 (deleted (rmail-message-deleted-p msgnum))
586 ;; Does not work (swapped?)
587 ;;; (unseen (rmail-message-unseen-p msgnum))
588 unseen lines)
589 (save-excursion
590 ;; Switch to the buffer that has the whole mbox text.
591 (if (rmail-buffers-swapped-p)
592 (set-buffer rmail-view-buffer))
593 ;; Now we can compute the line count.
594 (if rmail-summary-line-count-flag
595 (setq lines (count-lines beg end)))
596 ;; Narrow to the message header.
597 (save-excursion
598 (save-restriction
599 (widen)
600 (goto-char beg)
601 (if (search-forward "\n\n" end t)
602 (progn
603 (narrow-to-region beg (point))
604 ;; Replace rmail-message-unseen-p from above.
605 (goto-char beg)
606 (setq unseen (and (search-forward
607 (concat rmail-attribute-header ": ") nil t)
608 (looking-at "......U")))
609 ;; Generate a status line from the message.
610 (rmail-create-summary msgnum deleted unseen lines))
611 (rmail-error-bad-format msgnum)))))))
613 ;; FIXME this is now unused.
614 ;; The intention was to display in the summary something like {E}
615 ;; for an edited messaged, similarly for answered, etc.
616 ;; But that conflicts with the previous rmail usage, where
617 ;; any user-defined { labels } occupied this space.
618 ;; So whilst it would be nice to have this information in the summary,
619 ;; it would need to go somewhere else.
620 (defun rmail-get-summary-status ()
621 "Return a coded string wrapped in curly braces denoting the status.
623 The current buffer must already be narrowed to the message headers for
624 the message being processed."
625 (let ((status (mail-fetch-field rmail-attribute-header))
626 (index 0)
627 (result "")
628 char)
629 ;; Strip off the read/unread and the deleted attribute which are
630 ;; handled separately.
631 (setq status
632 (if status
633 (concat (substring status 0 1) (substring status 2 6))
634 ""))
635 (while (< index (length status))
636 (unless (string= "-" (setq char (substring status index (1+ index))))
637 (setq result (concat result char)))
638 (setq index (1+ index)))
639 (when (> (length result) 0)
640 (setq result (concat "{" result "}")))
641 result))
643 (autoload 'rmail-make-label "rmailkwd")
645 (defun rmail-get-summary-labels ()
646 "Return a string wrapped in curly braces with the current message labels.
647 Returns nil if there are no labels. The current buffer must
648 already be narrowed to the message headers for the message being
649 processed."
650 (let ((labels (mail-fetch-field rmail-keyword-header)))
651 (and labels
652 (not (string-equal labels ""))
653 (progn
654 ;; Intern so that rmail-read-label can offer completion.
655 (mapc 'rmail-make-label (split-string labels ", "))
656 (format "{ %s } " labels)))))
658 (defun rmail-create-summary (msgnum deleted unseen lines)
659 "Return the summary line for message MSGNUM.
660 The current buffer should already be narrowed to the header for that message.
661 It could be either buffer, so don't access Rmail local variables.
662 DELETED is t if this message is marked deleted.
663 UNSEEN is t if it is marked unseen.
664 LINES is the number of lines in the message (if we should display that)
665 or else nil."
666 (goto-char (point-min))
667 (let ((line (rmail-header-summary))
668 (labels (rmail-get-summary-labels))
669 status prefix basic-start basic-end linecount-string)
671 (setq linecount-string
672 (cond
673 ((not lines) " ")
674 ((<= lines 9) (format " [%d]" lines))
675 ((<= lines 99) (format " [%d]" lines))
676 ((<= lines 999) (format " [%d]" lines))
677 ((<= lines 9999) (format " [%dk]" (/ lines 1000)))
678 ((<= lines 99999) (format " [%dk]" (/ lines 1000)))
679 (t (format "[%dk]" (/ lines 1000)))))
681 (setq status (cond
682 (deleted ?D)
683 (unseen ?-)
684 (t ? ))
685 prefix (format "%5d%c " msgnum status)
686 basic-start (car line)
687 basic-end (cadr line))
688 (funcall rmail-summary-line-decoder
689 (concat prefix basic-start linecount-string " "
690 labels basic-end))))
692 (defun rmail-header-summary ()
693 "Return a message summary based on the message headers.
694 The value is a list of two strings, the first and second parts of the summary.
696 The current buffer must already be narrowed to the message headers for
697 the message being processed."
698 (goto-char (point-min))
699 (list
700 (concat (save-excursion
701 (if (not (re-search-forward "^Date:" nil t))
703 ;; Match month names case-insensitively
704 (cond ((let ((case-fold-search t))
705 (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
706 (line-end-position) t))
707 (format "%2d-%3s"
708 (string-to-number (buffer-substring
709 (match-beginning 2)
710 (match-end 2)))
711 (buffer-substring
712 (match-beginning 4) (match-end 4))))
713 ((let ((case-fold-search t))
714 (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
715 (line-end-position) t))
716 (format "%2d-%3s"
717 (string-to-number (buffer-substring
718 (match-beginning 4)
719 (match-end 4)))
720 (buffer-substring
721 (match-beginning 2) (match-end 2))))
722 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
723 (line-end-position) t)
724 (format "%2s%2s%2s"
725 (buffer-substring
726 (match-beginning 2) (match-end 2))
727 (buffer-substring
728 (match-beginning 3) (match-end 3))
729 (buffer-substring
730 (match-beginning 4) (match-end 4))))
731 (t "??????"))))
733 (save-excursion
734 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t)
735 (mail-strip-quoted-names
736 (buffer-substring
737 (1- (point))
738 ;; Get all the lines of the From field
739 ;; so that we get a whole comment if there is one,
740 ;; so that mail-strip-quoted-names can discard it.
741 (progn
742 (while (progn (forward-line 1)
743 (looking-at "[ \t]")))
744 ;; Back up over newline, then trailing spaces or tabs
745 (forward-char -1)
746 (skip-chars-backward " \t")
747 (point))))))
748 len mch lo)
749 (if (or (null from)
750 (string-match
751 (or rmail-user-mail-address-regexp
752 (concat "^\\("
753 (regexp-quote (user-login-name))
754 "\\($\\|@\\)\\|"
755 (regexp-quote
756 ;; Don't lose if run from init file
757 ;; where user-mail-address is not
758 ;; set yet.
759 (or user-mail-address
760 (concat (user-login-name) "@"
761 (or mail-host-address
762 (system-name)))))
763 "\\>\\)"))
764 from))
765 ;; No From field, or it's this user.
766 (save-excursion
767 (goto-char (point-min))
768 (if (not (re-search-forward "^To:[ \t]*" nil t))
770 (setq from
771 (concat "to: "
772 (mail-strip-quoted-names
773 (buffer-substring
774 (point)
775 (progn (end-of-line)
776 (skip-chars-backward " \t")
777 (point)))))))))
778 (if (null from)
780 ;; We are going to return only 25 characters of the
781 ;; address, so make sure it is RFC2047 decoded before
782 ;; taking its substring. This is important when the address is not on the same line as the name, e.g.:
783 ;; To: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?=
784 ;; <stepnem@gmail.com>
785 (setq from (rfc2047-decode-string from))
786 (setq len (length from))
787 (setq mch (string-match "[@%]" from))
788 (format "%25s"
789 (if (or (not mch) (<= len 25))
790 (substring from (max 0 (- len 25)))
791 (substring from
792 (setq lo (cond ((< (- mch 14) 0) 0)
793 ((< len (+ mch 11))
794 (- len 25))
795 (t (- mch 14))))
796 (min len (+ lo 25)))))))))
797 (concat (if (re-search-forward "^Subject:" nil t)
798 (let (pos str)
799 (skip-chars-forward " \t")
800 (setq pos (point))
801 (forward-line 1)
802 (setq str (buffer-substring pos (1- (point))))
803 (while (looking-at "[ \t]")
804 (setq str (concat str " "
805 (buffer-substring (match-end 0)
806 (line-end-position))))
807 (forward-line 1))
808 str)
809 (re-search-forward "[\n][\n]+" nil t)
810 (buffer-substring (point) (progn (end-of-line) (point))))
811 "\n")))
813 ;; Simple motion in a summary buffer.
815 (defun rmail-summary-next-all (&optional number)
816 (interactive "p")
817 (or number (setq number 1))
818 (forward-line number)
819 ;; It doesn't look nice to move forward past the last message line.
820 (and (eobp) (> number 0)
821 (forward-line -1))
822 (display-buffer rmail-buffer))
824 (defun rmail-summary-previous-all (&optional number)
825 (interactive "p")
826 (rmail-summary-next-all (- (or number 1))))
828 (defun rmail-summary-next-msg (&optional number)
829 "Display next non-deleted msg from rmail file.
830 With optional prefix argument NUMBER, moves forward this number of non-deleted
831 messages, or backward if NUMBER is negative."
832 (interactive "p")
833 (or number (setq number 1))
834 (forward-line 0)
835 (and (> number 0) (end-of-line))
836 (let ((count (if (< number 0) (- number) number))
837 (search (if (> number 0) 're-search-forward 're-search-backward))
838 (non-del-msg-found nil))
839 (while (and (> count 0) (setq non-del-msg-found
840 (or (funcall search "^.....[^D]" nil t)
841 non-del-msg-found)))
842 (setq count (1- count))))
843 (beginning-of-line)
844 (display-buffer rmail-buffer))
846 (defun rmail-summary-previous-msg (&optional number)
847 "Display previous non-deleted msg from rmail file.
848 With optional prefix argument NUMBER, moves backward this number of
849 non-deleted messages."
850 (interactive "p")
851 (rmail-summary-next-msg (- (or number 1))))
853 (defun rmail-summary-next-labeled-message (n labels)
854 "Show next message with LABELS. Defaults to last labels used.
855 With prefix argument N moves forward N messages with these labels."
856 (interactive "p\nsMove to next msg with labels: ")
857 (let (msg)
858 (with-current-buffer rmail-buffer
859 (rmail-next-labeled-message n labels)
860 (setq msg rmail-current-message))
861 (rmail-summary-goto-msg msg)))
863 (defun rmail-summary-previous-labeled-message (n labels)
864 "Show previous message with LABELS. Defaults to last labels used.
865 With prefix argument N moves backward N messages with these labels."
866 (interactive "p\nsMove to previous msg with labels: ")
867 (let (msg)
868 (with-current-buffer rmail-buffer
869 (rmail-previous-labeled-message n labels)
870 (setq msg rmail-current-message))
871 (rmail-summary-goto-msg msg)))
873 (defun rmail-summary-next-same-subject (n)
874 "Go to the next message in the summary having the same subject.
875 With prefix argument N, do this N times.
876 If N is negative, go backwards."
877 (interactive "p")
878 (let ((forward (> n 0))
879 subject i found)
880 (with-current-buffer rmail-buffer
881 (setq subject (rmail-simplified-subject)
882 i rmail-current-message))
883 (save-excursion
884 (while (and (/= n 0)
885 (if forward
886 (not (eobp))
887 (not (bobp))))
888 (let (done)
889 (while (and (not done)
890 (if forward
891 (not (eobp))
892 (not (bobp))))
893 ;; Advance thru summary.
894 (forward-line (if forward 1 -1))
895 ;; Get msg number of this line.
896 (setq i (string-to-number
897 (buffer-substring (point)
898 (min (point-max) (+ 6 (point))))))
899 (setq done (string-equal subject (rmail-simplified-subject i))))
900 (if done (setq found i)))
901 (setq n (if forward (1- n) (1+ n)))))
902 (if found
903 (rmail-summary-goto-msg found)
904 (error "No %s message with same subject"
905 (if forward "following" "previous")))))
907 (defun rmail-summary-previous-same-subject (n)
908 "Go to the previous message in the summary having the same subject.
909 With prefix argument N, do this N times.
910 If N is negative, go forwards instead."
911 (interactive "p")
912 (rmail-summary-next-same-subject (- n)))
914 ;; Delete and undelete summary commands.
916 (defun rmail-summary-delete-forward (&optional count)
917 "Delete this message and move to next nondeleted one.
918 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
919 A prefix argument serves as a repeat count;
920 a negative argument means to delete and move backward."
921 (interactive "p")
922 (unless (numberp count) (setq count 1))
923 (let (del-msg
924 (backward (< count 0)))
925 (while (and (/= count 0)
926 ;; Don't waste time if we are at the beginning
927 ;; and trying to go backward.
928 (not (and backward (bobp))))
929 (rmail-summary-goto-msg)
930 (with-current-buffer rmail-buffer
931 (rmail-delete-message)
932 (setq del-msg rmail-current-message))
933 (rmail-summary-mark-deleted del-msg)
934 (while (and (not (if backward (bobp) (eobp)))
935 (save-excursion (beginning-of-line)
936 (looking-at " *[0-9]+D")))
937 (forward-line (if backward -1 1)))
938 (setq count
939 (if (> count 0) (1- count) (1+ count)))
940 ;; It looks ugly to move to the empty line at end of buffer.
941 ;; And don't waste time after hitting the end.
942 (and (eobp) (not backward)
943 (progn (setq count 0)
944 (forward-line -1))))))
946 (defun rmail-summary-delete-backward (&optional count)
947 "Delete this message and move to previous nondeleted one.
948 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
949 A prefix argument serves as a repeat count;
950 a negative argument means to delete and move forward."
951 (interactive "p")
952 (rmail-summary-delete-forward (- count)))
954 (defun rmail-summary-mark-deleted (&optional n undel)
955 (and n (not (eq n (rmail-summary-msg-number)))
956 ;; Since third arg is t, this only alters summary, not the Rmail buf.
957 (rmail-summary-goto-msg n t t))
958 (or (eobp)
959 (not (overlay-get rmail-summary-overlay 'face))
960 (let ((buffer-read-only nil))
961 (skip-chars-forward " ")
962 (skip-chars-forward "0-9")
963 (if undel
964 (if (looking-at "D")
965 (progn (delete-char 1) (insert " ")))
966 (delete-char 1)
967 (insert "D"))
968 ;; Discard cached new summary line.
969 (with-current-buffer rmail-buffer
970 (aset rmail-summary-vector (1- n) nil))))
971 (beginning-of-line))
973 (defun rmail-summary-update-line (n)
974 "Update the summary line for message N."
975 (when (rmail-summary-goto-msg n t t)
976 (let* ((buffer-read-only nil)
977 (start (line-beginning-position))
978 (end (line-beginning-position 2))
979 (overlays (overlays-in start end))
980 high ov)
981 (while (and (setq ov (car overlays))
982 (not (setq high (overlay-get ov 'rmail-summary))))
983 (setq overlays (cdr overlays)))
984 (delete-region start end)
985 (princ
986 (with-current-buffer rmail-buffer
987 (aset rmail-summary-vector (1- n) (rmail-create-summary-line n)))
988 (current-buffer))
989 (when high
990 (forward-line -1)
991 (rmail-summary-update-highlight nil)))))
993 (defun rmail-summary-mark-undeleted (n)
994 (rmail-summary-mark-deleted n t))
996 (defun rmail-summary-deleted-p (&optional n)
997 (save-excursion
998 (and n (rmail-summary-goto-msg n nil t))
999 (skip-chars-forward " ")
1000 (skip-chars-forward "0-9")
1001 (looking-at "D")))
1003 (defun rmail-summary-undelete (&optional arg)
1004 "Undelete current message.
1005 Optional prefix ARG means undelete ARG previous messages."
1006 (interactive "p")
1007 (if (/= arg 1)
1008 (rmail-summary-undelete-many arg)
1009 (let ((buffer-read-only nil)
1010 (opoint (point)))
1011 (end-of-line)
1012 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
1013 (replace-match "\\1 ")
1014 (rmail-summary-goto-msg)
1015 (if rmail-enable-mime
1016 (set-buffer rmail-buffer)
1017 (rmail-pop-to-buffer rmail-buffer))
1018 (and (rmail-message-deleted-p rmail-current-message)
1019 (rmail-undelete-previous-message 1))
1020 (if rmail-enable-mime
1021 (rmail-pop-to-buffer rmail-buffer))
1022 (rmail-pop-to-buffer rmail-summary-buffer))
1023 (t (goto-char opoint))))))
1025 (defun rmail-summary-undelete-many (&optional n)
1026 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
1027 (interactive "P")
1028 (if n
1029 (while (and (> n 0) (not (eobp)))
1030 (rmail-summary-goto-msg)
1031 (let (del-msg)
1032 (when (rmail-summary-deleted-p)
1033 (with-current-buffer rmail-buffer
1034 (rmail-undelete-previous-message 1)
1035 (setq del-msg rmail-current-message))
1036 (rmail-summary-mark-undeleted del-msg)))
1037 (while (and (not (eobp))
1038 (save-excursion (beginning-of-line)
1039 (looking-at " *[0-9]+ ")))
1040 (forward-line 1))
1041 (setq n (1- n)))
1042 (rmail-summary-goto-msg 1)
1043 (dotimes (_ rmail-total-messages)
1044 (rmail-summary-goto-msg)
1045 (let (del-msg)
1046 (when (rmail-summary-deleted-p)
1047 (with-current-buffer rmail-buffer
1048 (rmail-undelete-previous-message 1)
1049 (setq del-msg rmail-current-message))
1050 (rmail-summary-mark-undeleted del-msg)))
1051 (if (not (eobp))
1052 (forward-line 1))))
1054 ;; It looks ugly to move to the empty line at end of buffer.
1055 (and (eobp)
1056 (forward-line -1)))
1058 ;; Rmail Summary mode is suitable only for specially formatted data.
1059 (put 'rmail-summary-mode 'mode-class 'special)
1061 (define-derived-mode rmail-summary-mode special-mode "RMAIL Summary"
1062 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
1063 As commands are issued in the summary buffer, they are applied to the
1064 corresponding mail messages in the rmail buffer.
1066 All normal editing commands are turned off.
1067 Instead, nearly all the Rmail mode commands are available,
1068 though many of them move only among the messages in the summary.
1070 These additional commands exist:
1072 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
1073 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
1075 Commands for sorting the summary:
1077 \\[rmail-summary-sort-by-date] Sort by date.
1078 \\[rmail-summary-sort-by-subject] Sort by subject.
1079 \\[rmail-summary-sort-by-author] Sort by author.
1080 \\[rmail-summary-sort-by-recipient] Sort by recipient.
1081 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
1082 \\[rmail-summary-sort-by-lines] Sort by lines.
1083 \\[rmail-summary-sort-by-labels] Sort by labels."
1084 (setq truncate-lines t)
1085 (setq buffer-read-only t)
1086 (set-syntax-table text-mode-syntax-table)
1087 (make-local-variable 'rmail-buffer)
1088 (make-local-variable 'rmail-total-messages)
1089 (make-local-variable 'rmail-current-message)
1090 (setq rmail-current-message nil)
1091 (make-local-variable 'rmail-summary-redo)
1092 (setq rmail-summary-redo nil)
1093 (make-local-variable 'revert-buffer-function)
1094 (make-local-variable 'font-lock-defaults)
1095 (setq font-lock-defaults '(rmail-summary-font-lock-keywords t))
1096 (rmail-summary-enable))
1098 ;; Summary features need to be disabled during edit mode.
1099 (defun rmail-summary-disable ()
1100 (use-local-map text-mode-map)
1101 (remove-hook 'post-command-hook 'rmail-summary-rmail-update t)
1102 (setq revert-buffer-function nil))
1104 (defun rmail-summary-enable ()
1105 (use-local-map rmail-summary-mode-map)
1106 (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
1107 (setq revert-buffer-function 'rmail-update-summary))
1109 (defun rmail-summary-mark-seen (n &optional nomove unseen)
1110 "Remove the unseen mark from the current message, update the summary vector.
1111 N is the number of the current message. Optional argument NOMOVE
1112 non-nil means we are already at the right column. Optional argument
1113 UNSEEN non-nil means mark the message as unseen."
1114 (save-excursion
1115 (unless nomove
1116 (beginning-of-line)
1117 (skip-chars-forward " ")
1118 (skip-chars-forward "0-9"))
1119 (when (char-equal (following-char) (if unseen ?\s ?-))
1120 (let ((buffer-read-only nil))
1121 (delete-char 1)
1122 (insert (if unseen "-" " ")))
1123 (let ((line (buffer-substring-no-properties (line-beginning-position)
1124 (line-beginning-position 2))))
1125 (with-current-buffer rmail-buffer
1126 (aset rmail-summary-vector (1- n) line))))))
1128 (defvar rmail-summary-put-back-unseen nil
1129 "Used for communicating between calls to `rmail-summary-rmail-update'.
1130 If it moves to a message within an Incremental Search, and removes
1131 the `unseen' attribute from that message, it sets this flag
1132 so that if the next motion between messages is in the same Incremental
1133 Search, the `unseen' attribute is restored.")
1135 ;; Show in Rmail the message described by the summary line that point is on,
1136 ;; but only if the Rmail buffer is already visible.
1137 ;; This is a post-command-hook in summary buffers.
1138 (defun rmail-summary-rmail-update ()
1139 (let (buffer-read-only)
1140 (save-excursion
1141 ;; If at end of buffer, pretend we are on the last text line.
1142 (if (eobp)
1143 (forward-line -1))
1144 (beginning-of-line)
1145 (skip-chars-forward " ")
1146 ;; If the summary is empty, don't do anything.
1147 (unless (eobp)
1148 (let ((msg-num (string-to-number (buffer-substring
1149 (point)
1150 (progn (skip-chars-forward "0-9")
1151 (point))))))
1152 ;; Always leave `unseen' removed
1153 ;; if we get out of isearch mode.
1154 ;; Don't let a subsequent isearch restore that `unseen'.
1155 (if (not isearch-mode)
1156 (setq rmail-summary-put-back-unseen nil))
1158 (or (eq rmail-current-message msg-num)
1159 (let ((window (get-buffer-window rmail-buffer t))
1160 (owin (selected-window)))
1161 (if isearch-mode
1162 (progn
1163 ;; If we first saw the previous message in this search,
1164 ;; and we have gone to a different message while searching,
1165 ;; put back `unseen' on the former one.
1166 (when rmail-summary-put-back-unseen
1167 (rmail-set-attribute rmail-unseen-attr-index t
1168 rmail-current-message)
1169 (save-excursion
1170 (goto-char rmail-summary-put-back-unseen)
1171 (rmail-summary-mark-seen rmail-current-message t t)))
1172 ;; Arrange to do that later, for the new current message,
1173 ;; if it still has `unseen'.
1174 (setq rmail-summary-put-back-unseen
1175 (if (rmail-message-unseen-p msg-num)
1176 (point))))
1177 (setq rmail-summary-put-back-unseen nil))
1178 ;; Go to the desired message.
1179 (setq rmail-current-message msg-num)
1180 ;; Update the summary to show the message has been seen.
1181 (rmail-summary-mark-seen msg-num t)
1182 (if window
1183 ;; Using save-window-excursion would cause the new value
1184 ;; of point to get lost.
1185 (unwind-protect
1186 (progn
1187 (select-window window)
1188 (rmail-show-message msg-num t))
1189 (select-window owin))
1190 (if (buffer-name rmail-buffer)
1191 (with-current-buffer rmail-buffer
1192 (rmail-show-message msg-num t))))
1193 ;; In linum mode, the message buffer must be specially
1194 ;; updated (Bug#4878).
1195 (and (fboundp 'linum-update)
1196 (buffer-name rmail-buffer)
1197 (linum-update rmail-buffer))))
1198 (rmail-summary-update-highlight nil))))))
1200 (defun rmail-summary-save-buffer ()
1201 "Save the buffer associated with this RMAIL summary."
1202 (interactive)
1203 (save-window-excursion
1204 (save-excursion
1205 (switch-to-buffer rmail-buffer)
1206 (save-buffer))))
1208 (defun rmail-summary-mouse-goto-message (event)
1209 "Select the message whose summary line you click on."
1210 (interactive "@e")
1211 (goto-char (posn-point (event-end event)))
1212 (rmail-summary-goto-msg))
1214 (defun rmail-summary-msg-number ()
1215 (save-excursion
1216 (beginning-of-line)
1217 (string-to-number
1218 (buffer-substring (point)
1219 (min (point-max) (+ 6 (point)))))))
1221 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
1222 "Go to message N in the summary buffer and the Rmail buffer.
1223 If N is nil, use the message corresponding to point in the summary
1224 and move to that message in the Rmail buffer.
1226 If NOWARN, don't say anything if N is out of range.
1227 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1228 Returns non-nil if message N was found."
1229 (interactive "P")
1230 (if (consp n) (setq n (prefix-numeric-value n)))
1231 (if (eobp) (forward-line -1))
1232 (beginning-of-line)
1233 (let* ((obuf (current-buffer))
1234 (buf rmail-buffer)
1235 (cur (point))
1236 message-not-found
1237 (curmsg (string-to-number
1238 (buffer-substring (point)
1239 (min (point-max) (+ 6 (point))))))
1240 (total (with-current-buffer buf rmail-total-messages)))
1241 ;; CURMSG should be nil when there's no current summary message
1242 ;; (for instance, if the summary is empty).
1243 (if (= curmsg 0)
1244 (setq curmsg nil))
1245 ;; If message number N was specified, find that message's line
1246 ;; or set message-not-found.
1247 ;; If N wasn't specified or that message can't be found.
1248 ;; set N by default.
1249 (if (not n)
1250 (setq n curmsg)
1251 (if (< n 1)
1252 (progn (message "No preceding message")
1253 (setq n 1)))
1254 (if (and (> n total)
1255 (> total 0))
1256 (progn (message "No following message")
1257 (goto-char (point-max))
1258 (rmail-summary-goto-msg nil nowarn skip-rmail)))
1259 (goto-char (point-min))
1260 (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t))
1261 (progn (or nowarn (message "Message %d not found" n))
1262 (setq n curmsg)
1263 (setq message-not-found t)
1264 (goto-char cur))))
1265 ;; N can be nil now, along with CURMSG,
1266 ;; if the summary is empty.
1267 (when n
1268 (rmail-summary-mark-seen n)
1269 (rmail-summary-update-highlight message-not-found)
1270 (beginning-of-line)
1271 (unless skip-rmail
1272 (let ((selwin (selected-window)))
1273 (unwind-protect
1274 (progn (rmail-pop-to-buffer buf)
1275 (rmail-show-message n))
1276 (select-window selwin)
1277 ;; The actions above can alter the current buffer. Preserve it.
1278 (set-buffer obuf)))))
1279 (not message-not-found)))
1281 ;; Update the highlighted line in an rmail summary buffer.
1282 ;; That should be current. We highlight the line point is on.
1283 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1284 (defun rmail-summary-update-highlight (not-found)
1285 ;; Make sure we have an overlay to use.
1286 (or rmail-summary-overlay
1287 (progn
1288 (make-local-variable 'rmail-summary-overlay)
1289 (setq rmail-summary-overlay (make-overlay (point) (point)))
1290 (overlay-put rmail-summary-overlay 'rmail-summary t)))
1291 ;; If this message is in the summary, use the overlay to highlight it.
1292 ;; Otherwise, don't highlight anything.
1293 (if not-found
1294 (overlay-put rmail-summary-overlay 'face nil)
1295 (move-overlay rmail-summary-overlay
1296 (save-excursion (beginning-of-line)
1297 (skip-chars-forward " ")
1298 (point))
1299 (line-end-position))
1300 (overlay-put rmail-summary-overlay 'face 'highlight)))
1302 (defun rmail-summary-scroll-msg-up (&optional dist)
1303 "Scroll the Rmail window forward.
1304 If the Rmail window is displaying the end of a message,
1305 advance to the next message."
1306 (interactive "P")
1307 (if (eq dist '-)
1308 (rmail-summary-scroll-msg-down nil)
1309 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1310 (if rmail-buffer-window
1311 (if (let ((rmail-summary-window (selected-window)))
1312 (select-window rmail-buffer-window)
1313 (prog1
1314 ;; Is EOB visible in the buffer?
1315 (save-excursion
1316 (let ((ht (window-height)))
1317 (move-to-window-line (- ht 2))
1318 (end-of-line)
1319 (eobp)))
1320 (select-window rmail-summary-window)))
1321 (if (not rmail-summary-scroll-between-messages)
1322 (error "End of buffer")
1323 (rmail-summary-next-msg (or dist 1)))
1324 (let ((other-window-scroll-buffer rmail-buffer))
1325 (scroll-other-window dist)))
1326 ;; If it isn't visible at all, show the beginning.
1327 (rmail-summary-beginning-of-message)))))
1329 (defun rmail-summary-scroll-msg-down (&optional dist)
1330 "Scroll the Rmail window backward.
1331 If the Rmail window is now displaying the beginning of a message,
1332 move to the previous message."
1333 (interactive "P")
1334 (if (eq dist '-)
1335 (rmail-summary-scroll-msg-up nil)
1336 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1337 (if rmail-buffer-window
1338 (if (let ((rmail-summary-window (selected-window)))
1339 (select-window rmail-buffer-window)
1340 (prog1
1341 ;; Is BOB visible in the buffer?
1342 (save-excursion
1343 (move-to-window-line 0)
1344 (beginning-of-line)
1345 (bobp))
1346 (select-window rmail-summary-window)))
1347 (if (not rmail-summary-scroll-between-messages)
1348 (error "Beginning of buffer")
1349 (rmail-summary-previous-msg (or dist 1)))
1350 (let ((other-window-scroll-buffer rmail-buffer))
1351 (scroll-other-window-down dist)))
1352 ;; If it isn't visible at all, show the beginning.
1353 (rmail-summary-beginning-of-message)))))
1355 (defun rmail-summary-beginning-of-message ()
1356 "Show current message from the beginning."
1357 (interactive)
1358 (rmail-summary-show-message 'BEG))
1360 (defun rmail-summary-end-of-message ()
1361 "Show bottom of current message."
1362 (interactive)
1363 (rmail-summary-show-message 'END))
1365 (defun rmail-summary-show-message (where)
1366 "Show current mail message.
1367 Position it according to WHERE which can be BEG or END"
1368 (if (and (one-window-p) (not pop-up-frames))
1369 ;; If there is just one window, put the summary on the top.
1370 (let ((buffer rmail-buffer))
1371 (split-window (selected-window) rmail-summary-window-size)
1372 (select-window (frame-first-window))
1373 (rmail-pop-to-buffer rmail-buffer)
1374 ;; If pop-to-buffer did not use that window, delete that
1375 ;; window. (This can happen if it uses another frame.)
1376 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1377 (delete-other-windows)))
1378 (rmail-pop-to-buffer rmail-buffer))
1379 (cond
1380 ((eq where 'BEG)
1381 (goto-char (point-min))
1382 (search-forward "\n\n"))
1383 ((eq where 'END)
1384 (goto-char (point-max))
1385 (recenter (1- (window-height))))
1387 (rmail-pop-to-buffer rmail-summary-buffer))
1389 (defun rmail-summary-bury ()
1390 "Bury the Rmail buffer and the Rmail summary buffer."
1391 (interactive)
1392 (let ((buffer-to-bury (current-buffer)))
1393 (let (window)
1394 (while (setq window (get-buffer-window rmail-buffer))
1395 (set-window-buffer window (other-buffer rmail-buffer)))
1396 (bury-buffer rmail-buffer))
1397 (switch-to-buffer (other-buffer buffer-to-bury))
1398 (bury-buffer buffer-to-bury)))
1400 (defun rmail-summary-quit ()
1401 "Quit out of Rmail and Rmail summary."
1402 (interactive)
1403 (rmail-summary-wipe)
1404 (rmail-quit))
1406 (defun rmail-summary-wipe ()
1407 "Kill and wipe away Rmail summary, remaining within Rmail."
1408 (interactive)
1409 (with-current-buffer rmail-buffer (setq rmail-summary-buffer nil))
1410 (let ((local-rmail-buffer rmail-buffer))
1411 (kill-buffer (current-buffer))
1412 ;; Delete window if not only one.
1413 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1414 (delete-window))
1415 ;; Switch windows to the rmail buffer, or switch to it in this window.
1416 (rmail-pop-to-buffer local-rmail-buffer)))
1418 (defun rmail-summary-expunge ()
1419 "Actually erase all deleted messages and recompute summary headers."
1420 (interactive)
1421 (with-current-buffer rmail-buffer
1422 (when (rmail-expunge-confirmed)
1423 (rmail-only-expunge)))
1424 (rmail-update-summary))
1426 (defun rmail-summary-expunge-and-save ()
1427 "Expunge and save RMAIL file."
1428 (interactive)
1429 (save-excursion
1430 (rmail-expunge-and-save))
1431 (rmail-update-summary)
1432 (set-buffer-modified-p nil))
1434 (defun rmail-summary-get-new-mail (&optional file-name)
1435 "Get new mail and recompute summary headers.
1437 Optionally you can specify the file to get new mail from. In this case,
1438 the file of new mail is not changed or deleted. Noninteractively, you can
1439 pass the inbox file name as an argument. Interactively, a prefix
1440 argument says to read a file name and use that file as the inbox."
1441 (interactive
1442 (list (if current-prefix-arg
1443 (read-file-name "Get new mail from file: "))))
1444 (let (msg)
1445 (with-current-buffer rmail-buffer
1446 (rmail-get-new-mail file-name)
1447 ;; Get the proper new message number.
1448 (setq msg rmail-current-message))
1449 ;; Make sure that message is displayed.
1450 (or (zerop msg)
1451 (rmail-summary-goto-msg msg))))
1453 (defun rmail-summary-input (filename)
1454 "Run Rmail on file FILENAME."
1455 (interactive "FRun rmail on RMAIL file: ")
1456 ;; We switch windows here, then display the other Rmail file there.
1457 (rmail-pop-to-buffer rmail-buffer)
1458 (rmail filename))
1460 (defun rmail-summary-first-message ()
1461 "Show first message in Rmail file from summary buffer."
1462 (interactive)
1463 (with-no-warnings
1464 (beginning-of-buffer)))
1466 (defun rmail-summary-last-message ()
1467 "Show last message in Rmail file from summary buffer."
1468 (interactive)
1469 (with-no-warnings
1470 (end-of-buffer))
1471 (forward-line -1))
1473 (declare-function rmail-abort-edit "rmailedit" ())
1474 (declare-function rmail-cease-edit "rmailedit"())
1475 (declare-function rmail-set-label "rmailkwd" (l state &optional n))
1476 (declare-function rmail-output-read-file-name "rmailout" ())
1477 (declare-function mail-send-and-exit "sendmail" (&optional arg))
1479 (defvar rmail-summary-edit-map nil)
1480 (if rmail-summary-edit-map
1482 (setq rmail-summary-edit-map
1483 (nconc (make-sparse-keymap) text-mode-map))
1484 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
1485 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
1487 (defun rmail-summary-edit-current-message ()
1488 "Edit the contents of this message."
1489 (interactive)
1490 (rmail-pop-to-buffer rmail-buffer)
1491 (rmail-edit-current-message)
1492 (use-local-map rmail-summary-edit-map))
1494 (defun rmail-summary-cease-edit ()
1495 "Finish editing message, then go back to Rmail summary buffer."
1496 (interactive)
1497 (rmail-cease-edit)
1498 (rmail-pop-to-buffer rmail-summary-buffer))
1500 (defun rmail-summary-abort-edit ()
1501 "Abort edit of current message; restore original contents.
1502 Go back to summary buffer."
1503 (interactive)
1504 (rmail-abort-edit)
1505 (rmail-pop-to-buffer rmail-summary-buffer))
1507 (defun rmail-summary-search-backward (regexp &optional n)
1508 "Show message containing next match for REGEXP.
1509 Prefix argument gives repeat count; negative argument means search
1510 backwards (through earlier messages).
1511 Interactively, empty argument means use same regexp used last time."
1512 (interactive
1513 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1514 (prompt
1515 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1516 regexp)
1517 (setq prompt
1518 (concat prompt
1519 (if rmail-search-last-regexp
1520 (concat ", default "
1521 rmail-search-last-regexp "): ")
1522 "): ")))
1523 (setq regexp (read-string prompt))
1524 (cond ((not (equal regexp ""))
1525 (setq rmail-search-last-regexp regexp))
1526 ((not rmail-search-last-regexp)
1527 (error "No previous Rmail search string")))
1528 (list rmail-search-last-regexp
1529 (prefix-numeric-value current-prefix-arg))))
1530 ;; Don't use save-excursion because that prevents point from moving
1531 ;; properly in the summary buffer.
1532 (with-current-buffer rmail-buffer
1533 (rmail-search regexp (- n))))
1535 (defun rmail-summary-search (regexp &optional n)
1536 "Show message containing next match for REGEXP.
1537 Prefix argument gives repeat count; negative argument means search
1538 backwards (through earlier messages).
1539 Interactively, empty argument means use same regexp used last time."
1540 (interactive
1541 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1542 (prompt
1543 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1544 regexp)
1545 (setq prompt
1546 (concat prompt
1547 (if rmail-search-last-regexp
1548 (concat ", default "
1549 rmail-search-last-regexp "): ")
1550 "): ")))
1551 (setq regexp (read-string prompt))
1552 (cond ((not (equal regexp ""))
1553 (setq rmail-search-last-regexp regexp))
1554 ((not rmail-search-last-regexp)
1555 (error "No previous Rmail search string")))
1556 (list rmail-search-last-regexp
1557 (prefix-numeric-value current-prefix-arg))))
1558 ;; Don't use save-excursion because that prevents point from moving
1559 ;; properly in the summary buffer.
1560 (let ((buffer (current-buffer))
1561 (selwin (selected-window)))
1562 (unwind-protect
1563 (progn
1564 (rmail-pop-to-buffer rmail-buffer)
1565 (rmail-search regexp n))
1566 (select-window selwin)
1567 (set-buffer buffer))))
1569 (defun rmail-summary-toggle-header ()
1570 "Show original message header if pruned header currently shown, or vice versa."
1571 (interactive)
1572 (save-window-excursion
1573 (set-buffer rmail-buffer)
1574 (rmail-toggle-header))
1575 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1576 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1577 (let ((window (get-buffer-window rmail-buffer)))
1578 (if window
1579 ;; Using save-window-excursion would lose the new value of point.
1580 (let ((owin (selected-window)))
1581 (unwind-protect
1582 (progn
1583 (select-window window)
1584 (goto-char (point-min)))
1585 (select-window owin))))))
1588 (defun rmail-summary-add-label (label)
1589 "Add LABEL to labels associated with current Rmail message.
1590 Completion is performed over known labels when reading."
1591 (interactive (list (with-current-buffer rmail-buffer
1592 (rmail-read-label "Add label"))))
1593 (with-current-buffer rmail-buffer
1594 (rmail-add-label label)))
1596 (defun rmail-summary-kill-label (label)
1597 "Remove LABEL from labels associated with current Rmail message.
1598 Completion is performed over known labels when reading."
1599 (interactive (list (with-current-buffer rmail-buffer
1600 (rmail-read-label "Kill label"))))
1601 (with-current-buffer rmail-buffer
1602 (rmail-set-label label nil)))
1604 ;;;; *** Rmail Summary Mailing Commands ***
1606 (defun rmail-summary-override-mail-send-and-exit ()
1607 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1608 (use-local-map (copy-keymap (current-local-map)))
1609 (dolist (key (where-is-internal 'mail-send-and-exit))
1610 (define-key (current-local-map) key 'rmail-summary-send-and-exit)))
1612 (defun rmail-summary-mail ()
1613 "Send mail in another window.
1614 While composing the message, use \\[mail-yank-original] to yank the
1615 original message into it."
1616 (interactive)
1617 (let ((window (get-buffer-window rmail-buffer)))
1618 (if window
1619 (select-window window)
1620 (set-buffer rmail-buffer)))
1621 (rmail-start-mail nil nil nil nil nil (current-buffer))
1622 (rmail-summary-override-mail-send-and-exit))
1624 (defun rmail-summary-continue ()
1625 "Continue composing outgoing message previously being composed."
1626 (interactive)
1627 (let ((window (get-buffer-window rmail-buffer)))
1628 (if window
1629 (select-window window)
1630 (set-buffer rmail-buffer)))
1631 (rmail-start-mail t))
1633 (defun rmail-summary-reply (just-sender)
1634 "Reply to the current message.
1635 Normally include CC: to all other recipients of original message;
1636 prefix argument means ignore them. While composing the reply,
1637 use \\[mail-yank-original] to yank the original message into it."
1638 (interactive "P")
1639 (let ((window (get-buffer-window rmail-buffer)))
1640 (if window
1641 (select-window window)
1642 (set-buffer rmail-buffer)))
1643 (rmail-reply just-sender)
1644 (rmail-summary-override-mail-send-and-exit))
1646 (defun rmail-summary-retry-failure ()
1647 "Edit a mail message which is based on the contents of the current message.
1648 For a message rejected by the mail system, extract the interesting headers and
1649 the body of the original message; otherwise copy the current message."
1650 (interactive)
1651 (let ((window (get-buffer-window rmail-buffer)))
1652 (if window
1653 (select-window window)
1654 (set-buffer rmail-buffer)))
1655 (rmail-retry-failure)
1656 (rmail-summary-override-mail-send-and-exit))
1658 (defun rmail-summary-send-and-exit ()
1659 "Send mail reply and return to summary buffer."
1660 (interactive)
1661 (mail-send-and-exit t))
1663 (defun rmail-summary-forward (resend)
1664 "Forward the current message to another user.
1665 With prefix argument, \"resend\" the message instead of forwarding it;
1666 see the documentation of `rmail-resend'."
1667 (interactive "P")
1668 (save-excursion
1669 (let ((window (get-buffer-window rmail-buffer)))
1670 (if window
1671 (select-window window)
1672 (set-buffer rmail-buffer)))
1673 (rmail-forward resend)
1674 (rmail-summary-override-mail-send-and-exit)))
1676 (defun rmail-summary-resend ()
1677 "Resend current message using `rmail-resend'."
1678 (interactive)
1679 (save-excursion
1680 (let ((window (get-buffer-window rmail-buffer)))
1681 (if window
1682 (select-window window)
1683 (set-buffer rmail-buffer)))
1684 (call-interactively 'rmail-resend)))
1686 ;; Summary output commands.
1688 (defun rmail-summary-output (&optional file-name n)
1689 "Append this message to mail file FILE-NAME.
1690 This works with both mbox format and Babyl format files,
1691 outputting in the appropriate format for each.
1692 The default file name comes from `rmail-default-file',
1693 which is updated to the name you use in this command.
1695 A prefix argument N says to output that many consecutive messages
1696 from those in the summary, starting with the current one.
1697 Deleted messages are skipped and don't count.
1698 When called from Lisp code, N may be omitted and defaults to 1.
1700 This command always outputs the complete message header,
1701 even the header display is currently pruned."
1702 (interactive
1703 (progn (require 'rmailout)
1704 (list (rmail-output-read-file-name)
1705 (prefix-numeric-value current-prefix-arg))))
1706 (let ((i 0) prev-msg)
1707 (while
1708 (and (< i n)
1709 (progn (rmail-summary-goto-msg)
1710 (not (eq prev-msg
1711 (setq prev-msg
1712 (with-current-buffer rmail-buffer
1713 rmail-current-message))))))
1714 (setq i (1+ i))
1715 (with-current-buffer rmail-buffer
1716 (let ((rmail-delete-after-output nil))
1717 (rmail-output file-name 1)))
1718 (if rmail-delete-after-output
1719 (rmail-summary-delete-forward nil)
1720 (if (< i n)
1721 (rmail-summary-next-msg 1))))))
1723 (defalias 'rmail-summary-output-to-rmail-file 'rmail-summary-output)
1725 (declare-function rmail-output-as-seen "rmailout"
1726 (file-name &optional count noattribute from-gnus))
1728 (defun rmail-summary-output-as-seen (&optional file-name n)
1729 "Append this message to mbox file named FILE-NAME.
1730 A prefix argument N says to output that many consecutive messages,
1731 from the summary, starting with the current one.
1732 Deleted messages are skipped and don't count.
1733 When called from Lisp code, N may be omitted and defaults to 1.
1735 This outputs the message header as you see it (or would see it)
1736 displayed in Rmail.
1738 The default file name comes from `rmail-default-file',
1739 which is updated to the name you use in this command."
1740 (interactive
1741 (progn (require 'rmailout)
1742 (list (rmail-output-read-file-name)
1743 (prefix-numeric-value current-prefix-arg))))
1744 (require 'rmailout) ; for rmail-output-as-seen in non-interactive case
1745 (let ((i 0) prev-msg)
1746 (while
1747 (and (< i n)
1748 (progn (rmail-summary-goto-msg)
1749 (not (eq prev-msg
1750 (setq prev-msg
1751 (with-current-buffer rmail-buffer
1752 rmail-current-message))))))
1753 (setq i (1+ i))
1754 (with-current-buffer rmail-buffer
1755 (let ((rmail-delete-after-output nil))
1756 (rmail-output-as-seen file-name 1)))
1757 (if rmail-delete-after-output
1758 (rmail-summary-delete-forward nil)
1759 (if (< i n)
1760 (rmail-summary-next-msg 1))))))
1762 (defun rmail-summary-output-menu ()
1763 "Output current message to another Rmail file, chosen with a menu.
1764 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1765 The variables `rmail-secondary-file-directory' and
1766 `rmail-secondary-file-regexp' control which files are offered in the menu."
1767 (interactive)
1768 (with-current-buffer rmail-buffer
1769 (let ((rmail-delete-after-output nil))
1770 (call-interactively 'rmail-output-menu)))
1771 (if rmail-delete-after-output
1772 (rmail-summary-delete-forward nil)))
1774 (defun rmail-summary-construct-io-menu ()
1775 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1776 (if files
1777 (progn
1778 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1779 (cons "Input Rmail File"
1780 (rmail-list-to-menu "Input Rmail File"
1781 files
1782 'rmail-summary-input)))
1783 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1784 (cons "Output Rmail File"
1785 (rmail-list-to-menu "Output Rmail File"
1786 files
1787 'rmail-summary-output))))
1788 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1789 '("Input Rmail File" . rmail-disable-menu))
1790 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1791 '("Output Rmail File" . rmail-disable-menu)))))
1793 (defun rmail-summary-output-body (&optional file-name)
1794 "Write this message body to the file FILE-NAME.
1795 FILE-NAME defaults, interactively, from the Subject field of the message."
1796 (interactive)
1797 (with-current-buffer rmail-buffer
1798 (let ((rmail-delete-after-output nil))
1799 (if file-name
1800 (rmail-output-body-to-file file-name)
1801 (call-interactively 'rmail-output-body-to-file))))
1802 (if rmail-delete-after-output
1803 (rmail-summary-delete-forward nil)))
1805 ;; Sorting messages in Rmail Summary buffer.
1807 (defun rmail-summary-sort-by-date (reverse)
1808 "Sort messages of current Rmail summary by \"Date\" header.
1809 If prefix argument REVERSE is non-nil, sorts in reverse order."
1810 (interactive "P")
1811 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1813 (defun rmail-summary-sort-by-subject (reverse)
1814 "Sort messages of current Rmail summary by \"Subject\" header.
1815 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
1816 non-nil, sorts in reverse order."
1817 (interactive "P")
1818 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1820 (defun rmail-summary-sort-by-author (reverse)
1821 "Sort messages of current Rmail summary by author.
1822 This uses either the \"From\" or \"Sender\" header, downcased.
1823 If prefix argument REVERSE is non-nil, sorts in reverse order."
1824 (interactive "P")
1825 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1827 (defun rmail-summary-sort-by-recipient (reverse)
1828 "Sort messages of current Rmail summary by recipient.
1829 This uses either the \"To\" or \"Apparently-To\" header, downcased.
1830 If prefix argument REVERSE is non-nil, sorts in reverse order."
1831 (interactive "P")
1832 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1834 (defun rmail-summary-sort-by-correspondent (reverse)
1835 "Sort messages of current Rmail summary by other correspondent.
1836 This uses either the \"From\", \"Sender\", \"To\", or
1837 \"Apparently-To\" header, downcased. Uses the first header not
1838 excluded by `mail-dont-reply-to-names'. If prefix argument
1839 REVERSE is non-nil, sorts in reverse order."
1840 (interactive "P")
1841 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1843 (defun rmail-summary-sort-by-lines (reverse)
1844 "Sort messages of current Rmail summary by the number of lines.
1845 If prefix argument REVERSE is non-nil, sorts in reverse order."
1846 (interactive "P")
1847 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1849 (defun rmail-summary-sort-by-labels (reverse labels)
1850 "Sort messages of current Rmail summary by labels.
1851 LABELS is a comma-separated list of labels.
1852 If prefix argument REVERSE is non-nil, sorts in reverse order."
1853 (interactive "P\nsSort by labels: ")
1854 (rmail-sort-from-summary
1855 (lambda (reverse) (rmail-sort-by-labels reverse labels))
1856 reverse))
1858 (defun rmail-sort-from-summary (sortfun reverse)
1859 "Sort the Rmail buffer using sorting function SORTFUN.
1860 Passes REVERSE to SORTFUN as its sole argument. Then regenerates
1861 the summary. Note that the whole Rmail buffer is sorted, even if
1862 the summary is only showing a subset of messages."
1863 (require 'rmailsort)
1864 (let ((selwin (selected-window)))
1865 (unwind-protect
1866 (progn (rmail-pop-to-buffer rmail-buffer)
1867 (funcall sortfun reverse))
1868 (select-window selwin))))
1870 (provide 'rmailsum)
1872 ;; Local Variables:
1873 ;; generated-autoload-file: "rmail.el"
1874 ;; End:
1876 ;;; rmailsum.el ends here