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