Make S-SPC scroll in the opposite direction to SPC
[emacs.git] / lisp / mail / rmailsum.el
blob13cd7c3f05e7f81e51ece9b3e788fde89a490f4d
1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993-1996, 2000-2013 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 func &rest args)
398 "Create a summary of selected messages.
399 DESC makes part of the mode line of the summary buffer. REDO is form ...
400 For each message, FUNC is applied to the message number and ARGS...
401 and if the result is non-nil, that message is included.
402 nil for FUNCTION means all messages."
403 (message "Computing summary lines...")
404 (unless rmail-buffer
405 (error "No RMAIL buffer found"))
406 (let (mesg was-in-summary sumbuf)
407 (if (eq major-mode 'rmail-summary-mode)
408 (setq was-in-summary t))
409 (with-current-buffer rmail-buffer
410 (setq rmail-summary-buffer (rmail-new-summary-1 desc redo func args)
411 ;; r-s-b is buffer-local.
412 sumbuf rmail-summary-buffer
413 mesg rmail-current-message))
414 ;; Now display the summary buffer and go to the right place in it.
415 (unless was-in-summary
416 (if (and (one-window-p)
417 pop-up-windows
418 (not pop-up-frames))
419 ;; If there is just one window, put the summary on the top.
420 (progn
421 (split-window (selected-window) rmail-summary-window-size)
422 (select-window (next-window (frame-first-window)))
423 (rmail-pop-to-buffer sumbuf)
424 ;; If pop-to-buffer did not use that window, delete that
425 ;; window. (This can happen if it uses another frame.)
426 (if (not (eq sumbuf (window-buffer (frame-first-window))))
427 (delete-other-windows)))
428 (rmail-pop-to-buffer sumbuf))
429 (set-buffer rmail-buffer)
430 ;; This is how rmail makes the summary buffer reappear.
431 ;; We do this here to make the window the proper size.
432 (rmail-select-summary nil)
433 (set-buffer sumbuf))
434 (rmail-summary-goto-msg mesg t t)
435 (rmail-summary-construct-io-menu)
436 (message "Computing summary lines...done")))
438 (defun rmail-new-summary-1 (description form function args)
439 "Filter messages to obtain summary lines.
440 DESCRIPTION is added to the mode line.
442 Return the summary buffer by invoking FUNCTION on each message
443 passing the message number and ARGS...
445 REDO is a form ...
447 The current buffer must be a Rmail buffer either containing a
448 collection of mbox formatted messages or displaying a single
449 message."
450 (let ((summary-msgs ())
451 (rmail-new-summary-line-count 0)
452 (sumbuf (rmail-get-create-summary-buffer)))
453 ;; Scan the messages, getting their summary strings
454 ;; and putting the list of them in SUMMARY-MSGS.
455 (let ((msgnum 1)
456 (main-buffer (current-buffer))
457 (total rmail-total-messages)
458 (inhibit-read-only t))
459 (save-excursion
460 ;; Go where the mbox text is.
461 (if (rmail-buffers-swapped-p)
462 (set-buffer rmail-view-buffer))
463 (let ((old-min (point-min-marker))
464 (old-max (point-max-marker)))
465 (unwind-protect
466 ;; Can't use save-restriction here; that doesn't work if we
467 ;; plan to modify text outside the original restriction.
468 (save-excursion
469 (widen)
470 (goto-char (point-min))
471 (while (>= total msgnum)
472 ;; Go back to the Rmail buffer so
473 ;; so FUNCTION and rmail-get-summary can see its local vars.
474 (with-current-buffer main-buffer
475 ;; First test whether to include this message.
476 (if (or (null function)
477 (apply function msgnum args))
478 (setq summary-msgs
479 (cons (cons msgnum (rmail-get-summary msgnum))
480 summary-msgs))))
481 (setq msgnum (1+ msgnum))
482 ;; Provide a periodic User progress message.
483 (if (and (not (zerop rmail-new-summary-line-count))
484 (zerop (% rmail-new-summary-line-count 10)))
485 (message "Computing summary lines...%d"
486 rmail-new-summary-line-count)))
487 (setq summary-msgs (nreverse summary-msgs)))
488 (narrow-to-region old-min old-max)))))
489 ;; Temporarily, while summary buffer is unfinished,
490 ;; we "don't have" a summary.
491 (setq rmail-summary-buffer nil)
492 ;; I have not a clue what this clause is doing. If you read this
493 ;; chunk of code and have a clue, then please email that clue to
494 ;; pmr@pajato.com
495 (if rmail-enable-mime
496 (with-current-buffer rmail-buffer
497 (setq rmail-summary-buffer nil)))
498 (save-excursion
499 (let ((rbuf (current-buffer))
500 (total rmail-total-messages))
501 (set-buffer sumbuf)
502 ;; Set up the summary buffer's contents.
503 (let ((buffer-read-only nil))
504 (erase-buffer)
505 (while summary-msgs
506 (princ (cdr (car summary-msgs)) sumbuf)
507 (setq summary-msgs (cdr summary-msgs)))
508 (goto-char (point-min)))
509 ;; Set up the rest of its state and local variables.
510 (setq buffer-read-only t)
511 (rmail-summary-mode)
512 (make-local-variable 'minor-mode-alist)
513 (setq minor-mode-alist (list (list t (concat ": " description))))
514 (setq rmail-buffer rbuf
515 rmail-summary-redo form
516 rmail-total-messages total)))
517 sumbuf))
519 (defun rmail-get-create-summary-buffer ()
520 "Return the Rmail summary buffer.
521 If necessary, it is created and undo is disabled."
522 (if (and rmail-summary-buffer (buffer-name rmail-summary-buffer))
523 rmail-summary-buffer
524 (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
525 (with-current-buffer buff
526 (setq buffer-undo-list t))
527 buff)))
530 ;; Low levels of generating a summary.
532 (defun rmail-get-summary (msgnum)
533 "Return the summary line for message MSGNUM.
534 The mbox buffer must be current when you call this function
535 even if its text is swapped.
537 If the message has a summary line already, it will be stored in
538 the message as a header and simply returned, otherwise the
539 summary line is created, saved in the message header, cached and
540 returned.
542 The current buffer contains the unrestricted message collection."
543 (let ((line (aref rmail-summary-vector (1- msgnum))))
544 (unless line
545 ;; Register a summary line for MSGNUM.
546 (setq rmail-new-summary-line-count (1+ rmail-new-summary-line-count)
547 line (rmail-create-summary-line msgnum))
548 ;; Cache the summary line for use during this Rmail session.
549 (aset rmail-summary-vector (1- msgnum) line))
550 line))
552 (defcustom rmail-summary-line-decoder (function rfc2047-decode-string)
553 "Function to decode a Rmail summary line.
554 It receives the summary line for one message as a string
555 and should return the decoded string.
557 By default, it is `rfc2047-decode-string', which decodes MIME-encoded
558 subject."
559 :type 'function
560 :version "23.3"
561 :group 'rmail-summary)
563 (defun rmail-create-summary-line (msgnum)
564 "Return the summary line for message MSGNUM.
565 Obtain the message summary from the header if it is available
566 otherwise create it and store it in the message header.
568 The mbox buffer must be current when you call this function
569 even if its text is swapped."
570 (let ((beg (rmail-msgbeg msgnum))
571 (end (rmail-msgend msgnum))
572 (deleted (rmail-message-deleted-p msgnum))
573 ;; Does not work (swapped?)
574 ;;; (unseen (rmail-message-unseen-p msgnum))
575 unseen lines)
576 (save-excursion
577 ;; Switch to the buffer that has the whole mbox text.
578 (if (rmail-buffers-swapped-p)
579 (set-buffer rmail-view-buffer))
580 ;; Now we can compute the line count.
581 (if rmail-summary-line-count-flag
582 (setq lines (count-lines beg end)))
583 ;; Narrow to the message header.
584 (save-excursion
585 (save-restriction
586 (widen)
587 (goto-char beg)
588 (if (search-forward "\n\n" end t)
589 (progn
590 (narrow-to-region beg (point))
591 ;; Replace rmail-message-unseen-p from above.
592 (goto-char beg)
593 (setq unseen (and (search-forward
594 (concat rmail-attribute-header ": ") nil t)
595 (looking-at "......U")))
596 ;; Generate a status line from the message.
597 (rmail-create-summary msgnum deleted unseen lines))
598 (rmail-error-bad-format msgnum)))))))
600 ;; FIXME this is now unused.
601 ;; The intention was to display in the summary something like {E}
602 ;; for an edited messaged, similarly for answered, etc.
603 ;; But that conflicts with the previous rmail usage, where
604 ;; any user-defined { labels } occupied this space.
605 ;; So whilst it would be nice to have this information in the summary,
606 ;; it would need to go somewhere else.
607 (defun rmail-get-summary-status ()
608 "Return a coded string wrapped in curly braces denoting the status.
610 The current buffer must already be narrowed to the message headers for
611 the message being processed."
612 (let ((status (mail-fetch-field rmail-attribute-header))
613 (index 0)
614 (result "")
615 char)
616 ;; Strip off the read/unread and the deleted attribute which are
617 ;; handled separately.
618 (setq status
619 (if status
620 (concat (substring status 0 1) (substring status 2 6))
621 ""))
622 (while (< index (length status))
623 (unless (string= "-" (setq char (substring status index (1+ index))))
624 (setq result (concat result char)))
625 (setq index (1+ index)))
626 (when (> (length result) 0)
627 (setq result (concat "{" result "}")))
628 result))
630 (autoload 'rmail-make-label "rmailkwd")
632 (defun rmail-get-summary-labels ()
633 "Return a string wrapped in curly braces with the current message labels.
634 Returns nil if there are no labels. The current buffer must
635 already be narrowed to the message headers for the message being
636 processed."
637 (let ((labels (mail-fetch-field rmail-keyword-header)))
638 (and labels
639 (not (string-equal labels ""))
640 (progn
641 ;; Intern so that rmail-read-label can offer completion.
642 (mapc 'rmail-make-label (split-string labels ", "))
643 (format "{ %s } " labels)))))
645 (defun rmail-create-summary (msgnum deleted unseen lines)
646 "Return the summary line for message MSGNUM.
647 The current buffer should already be narrowed to the header for that message.
648 It could be either buffer, so don't access Rmail local variables.
649 DELETED is t if this message is marked deleted.
650 UNSEEN is t if it is marked unseen.
651 LINES is the number of lines in the message (if we should display that)
652 or else nil."
653 (goto-char (point-min))
654 (let ((line (rmail-header-summary))
655 (labels (rmail-get-summary-labels))
656 pos status prefix basic-start basic-end linecount-string)
658 (setq linecount-string
659 (cond
660 ((not lines) " ")
661 ((<= lines 9) (format " [%d]" lines))
662 ((<= lines 99) (format " [%d]" lines))
663 ((<= lines 999) (format " [%d]" lines))
664 ((<= lines 9999) (format " [%dk]" (/ lines 1000)))
665 ((<= lines 99999) (format " [%dk]" (/ lines 1000)))
666 (t (format "[%dk]" (/ lines 1000)))))
668 (setq status (cond
669 (deleted ?D)
670 (unseen ?-)
671 (t ? ))
672 prefix (format "%5d%c " msgnum status)
673 basic-start (car line)
674 basic-end (cadr line))
675 (funcall rmail-summary-line-decoder
676 (concat prefix basic-start linecount-string " "
677 labels basic-end))))
679 (defun rmail-header-summary ()
680 "Return a message summary based on the message headers.
681 The value is a list of two strings, the first and second parts of the summary.
683 The current buffer must already be narrowed to the message headers for
684 the message being processed."
685 (goto-char (point-min))
686 (list
687 (concat (save-excursion
688 (if (not (re-search-forward "^Date:" nil t))
690 ;; Match month names case-insensitively
691 (cond ((let ((case-fold-search t))
692 (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
693 (line-end-position) t))
694 (format "%2d-%3s"
695 (string-to-number (buffer-substring
696 (match-beginning 2)
697 (match-end 2)))
698 (buffer-substring
699 (match-beginning 4) (match-end 4))))
700 ((let ((case-fold-search t))
701 (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
702 (line-end-position) t))
703 (format "%2d-%3s"
704 (string-to-number (buffer-substring
705 (match-beginning 4)
706 (match-end 4)))
707 (buffer-substring
708 (match-beginning 2) (match-end 2))))
709 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
710 (line-end-position) t)
711 (format "%2s%2s%2s"
712 (buffer-substring
713 (match-beginning 2) (match-end 2))
714 (buffer-substring
715 (match-beginning 3) (match-end 3))
716 (buffer-substring
717 (match-beginning 4) (match-end 4))))
718 (t "??????"))))
720 (save-excursion
721 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t)
722 (mail-strip-quoted-names
723 (buffer-substring
724 (1- (point))
725 ;; Get all the lines of the From field
726 ;; so that we get a whole comment if there is one,
727 ;; so that mail-strip-quoted-names can discard it.
728 (let ((opoint (point)))
729 (while (progn (forward-line 1)
730 (looking-at "[ \t]")))
731 ;; Back up over newline, then trailing spaces or tabs
732 (forward-char -1)
733 (skip-chars-backward " \t")
734 (point))))))
735 len mch lo)
736 (if (or (null from)
737 (string-match
738 (or rmail-user-mail-address-regexp
739 (concat "^\\("
740 (regexp-quote (user-login-name))
741 "\\($\\|@\\)\\|"
742 (regexp-quote
743 ;; Don't lose if run from init file
744 ;; where user-mail-address is not
745 ;; set yet.
746 (or user-mail-address
747 (concat (user-login-name) "@"
748 (or mail-host-address
749 (system-name)))))
750 "\\>\\)"))
751 from))
752 ;; No From field, or it's this user.
753 (save-excursion
754 (goto-char (point-min))
755 (if (not (re-search-forward "^To:[ \t]*" nil t))
757 (setq from
758 (concat "to: "
759 (mail-strip-quoted-names
760 (buffer-substring
761 (point)
762 (progn (end-of-line)
763 (skip-chars-backward " \t")
764 (point)))))))))
765 (if (null from)
767 ;; We are going to return only 25 characters of the
768 ;; address, so make sure it is RFC2047 decoded before
769 ;; taking its substring. This is important when the address is not on the same line as the name, e.g.:
770 ;; To: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?=
771 ;; <stepnem@gmail.com>
772 (setq from (rfc2047-decode-string from))
773 (setq len (length from))
774 (setq mch (string-match "[@%]" from))
775 (format "%25s"
776 (if (or (not mch) (<= len 25))
777 (substring from (max 0 (- len 25)))
778 (substring from
779 (setq lo (cond ((< (- mch 14) 0) 0)
780 ((< len (+ mch 11))
781 (- len 25))
782 (t (- mch 14))))
783 (min len (+ lo 25)))))))))
784 (concat (if (re-search-forward "^Subject:" nil t)
785 (let (pos str)
786 (skip-chars-forward " \t")
787 (setq pos (point))
788 (forward-line 1)
789 (setq str (buffer-substring pos (1- (point))))
790 (while (looking-at "[ \t]")
791 (setq str (concat str " "
792 (buffer-substring (match-end 0)
793 (line-end-position))))
794 (forward-line 1))
795 str)
796 (re-search-forward "[\n][\n]+" nil t)
797 (buffer-substring (point) (progn (end-of-line) (point))))
798 "\n")))
800 ;; Simple motion in a summary buffer.
802 (defun rmail-summary-next-all (&optional number)
803 (interactive "p")
804 (forward-line (if number number 1))
805 ;; It doesn't look nice to move forward past the last message line.
806 (and (eobp) (> number 0)
807 (forward-line -1))
808 (display-buffer rmail-buffer))
810 (defun rmail-summary-previous-all (&optional number)
811 (interactive "p")
812 (forward-line (- (if number number 1)))
813 ;; It doesn't look nice to move forward past the last message line.
814 (and (eobp) (< number 0)
815 (forward-line -1))
816 (display-buffer rmail-buffer))
818 (defun rmail-summary-next-msg (&optional number)
819 "Display next non-deleted msg from rmail file.
820 With optional prefix argument NUMBER, moves forward this number of non-deleted
821 messages, or backward if NUMBER is negative."
822 (interactive "p")
823 (forward-line 0)
824 (and (> number 0) (end-of-line))
825 (let ((count (if (< number 0) (- number) number))
826 (search (if (> number 0) 're-search-forward 're-search-backward))
827 (non-del-msg-found nil))
828 (while (and (> count 0) (setq non-del-msg-found
829 (or (funcall search "^.....[^D]" nil t)
830 non-del-msg-found)))
831 (setq count (1- count))))
832 (beginning-of-line)
833 (display-buffer rmail-buffer))
835 (defun rmail-summary-previous-msg (&optional number)
836 "Display previous non-deleted msg from rmail file.
837 With optional prefix argument NUMBER, moves backward this number of
838 non-deleted messages."
839 (interactive "p")
840 (rmail-summary-next-msg (- (if number number 1))))
842 (defun rmail-summary-next-labeled-message (n labels)
843 "Show next message with LABELS. Defaults to last labels used.
844 With prefix argument N moves forward N messages with these labels."
845 (interactive "p\nsMove to next msg with labels: ")
846 (let (msg)
847 (with-current-buffer rmail-buffer
848 (rmail-next-labeled-message n labels)
849 (setq msg rmail-current-message))
850 (rmail-summary-goto-msg msg)))
852 (defun rmail-summary-previous-labeled-message (n labels)
853 "Show previous message with LABELS. Defaults to last labels used.
854 With prefix argument N moves backward N messages with these labels."
855 (interactive "p\nsMove to previous msg with labels: ")
856 (let (msg)
857 (with-current-buffer rmail-buffer
858 (rmail-previous-labeled-message n labels)
859 (setq msg rmail-current-message))
860 (rmail-summary-goto-msg msg)))
862 (defun rmail-summary-next-same-subject (n)
863 "Go to the next message in the summary having the same subject.
864 With prefix argument N, do this N times.
865 If N is negative, go backwards."
866 (interactive "p")
867 (let ((forward (> n 0))
868 subject i found)
869 (with-current-buffer rmail-buffer
870 (setq subject (rmail-simplified-subject)
871 i rmail-current-message))
872 (save-excursion
873 (while (and (/= n 0)
874 (if forward
875 (not (eobp))
876 (not (bobp))))
877 (let (done)
878 (while (and (not done)
879 (if forward
880 (not (eobp))
881 (not (bobp))))
882 ;; Advance thru summary.
883 (forward-line (if forward 1 -1))
884 ;; Get msg number of this line.
885 (setq i (string-to-number
886 (buffer-substring (point)
887 (min (point-max) (+ 6 (point))))))
888 (setq done (string-equal subject (rmail-simplified-subject i))))
889 (if done (setq found i)))
890 (setq n (if forward (1- n) (1+ n)))))
891 (if found
892 (rmail-summary-goto-msg found)
893 (error "No %s message with same subject"
894 (if forward "following" "previous")))))
896 (defun rmail-summary-previous-same-subject (n)
897 "Go to the previous message in the summary having the same subject.
898 With prefix argument N, do this N times.
899 If N is negative, go forwards instead."
900 (interactive "p")
901 (rmail-summary-next-same-subject (- n)))
903 ;; Delete and undelete summary commands.
905 (defun rmail-summary-delete-forward (&optional count)
906 "Delete this message and move to next nondeleted one.
907 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
908 A prefix argument serves as a repeat count;
909 a negative argument means to delete and move backward."
910 (interactive "p")
911 (unless (numberp count) (setq count 1))
912 (let (end del-msg
913 (backward (< count 0)))
914 (while (/= count 0)
915 (rmail-summary-goto-msg)
916 (with-current-buffer rmail-buffer
917 (rmail-delete-message)
918 (setq del-msg rmail-current-message))
919 (rmail-summary-mark-deleted del-msg)
920 (while (and (not (if backward (bobp) (eobp)))
921 (save-excursion (beginning-of-line)
922 (looking-at " *[0-9]+D")))
923 (forward-line (if backward -1 1)))
924 ;; It looks ugly to move to the empty line at end of buffer.
925 (and (eobp) (not backward)
926 (forward-line -1))
927 (setq count
928 (if (> count 0) (1- count) (1+ count))))))
930 (defun rmail-summary-delete-backward (&optional count)
931 "Delete this message and move to previous nondeleted one.
932 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
933 A prefix argument serves as a repeat count;
934 a negative argument means to delete and move forward."
935 (interactive "p")
936 (rmail-summary-delete-forward (- count)))
938 (defun rmail-summary-mark-deleted (&optional n undel)
939 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
940 (and n (rmail-summary-goto-msg n t t))
941 (or (eobp)
942 (not (overlay-get rmail-summary-overlay 'face))
943 (let ((buffer-read-only nil))
944 (skip-chars-forward " ")
945 (skip-chars-forward "0-9")
946 (if undel
947 (if (looking-at "D")
948 (progn (delete-char 1) (insert " ")))
949 (delete-char 1)
950 (insert "D"))
951 ;; Register a new summary line.
952 (with-current-buffer rmail-buffer
953 (aset rmail-summary-vector (1- n) (rmail-create-summary-line n)))))
954 (beginning-of-line))
956 (defun rmail-summary-update-line (n)
957 "Update the summary line for message N."
958 (when (rmail-summary-goto-msg n t t)
959 (let* ((buffer-read-only nil)
960 (start (line-beginning-position))
961 (end (line-beginning-position 2))
962 (overlays (overlays-in start end))
963 high ov)
964 (while (and (setq ov (car overlays))
965 (not (setq high (overlay-get ov 'rmail-summary))))
966 (setq overlays (cdr overlays)))
967 (delete-region start end)
968 (princ
969 (with-current-buffer rmail-buffer
970 (aset rmail-summary-vector (1- n) (rmail-create-summary-line n)))
971 (current-buffer))
972 (when high
973 (forward-line -1)
974 (rmail-summary-update-highlight nil)))))
976 (defun rmail-summary-mark-undeleted (n)
977 (rmail-summary-mark-deleted n t))
979 (defun rmail-summary-deleted-p (&optional n)
980 (save-excursion
981 (and n (rmail-summary-goto-msg n nil t))
982 (skip-chars-forward " ")
983 (skip-chars-forward "0-9")
984 (looking-at "D")))
986 (defun rmail-summary-undelete (&optional arg)
987 "Undelete current message.
988 Optional prefix ARG means undelete ARG previous messages."
989 (interactive "p")
990 (if (/= arg 1)
991 (rmail-summary-undelete-many arg)
992 (let ((buffer-read-only nil)
993 (opoint (point)))
994 (end-of-line)
995 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
996 (replace-match "\\1 ")
997 (rmail-summary-goto-msg)
998 (if rmail-enable-mime
999 (set-buffer rmail-buffer)
1000 (rmail-pop-to-buffer rmail-buffer))
1001 (and (rmail-message-deleted-p rmail-current-message)
1002 (rmail-undelete-previous-message))
1003 (if rmail-enable-mime
1004 (rmail-pop-to-buffer rmail-buffer))
1005 (rmail-pop-to-buffer rmail-summary-buffer))
1006 (t (goto-char opoint))))))
1008 (defun rmail-summary-undelete-many (&optional n)
1009 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
1010 (interactive "P")
1011 (with-current-buffer rmail-buffer
1012 (let* ((init-msg (if n rmail-current-message rmail-total-messages))
1013 (rmail-current-message init-msg)
1014 (n (or n rmail-total-messages))
1015 (msgs-undeled 0))
1016 (while (and (> rmail-current-message 0)
1017 (< msgs-undeled n))
1018 (if (rmail-message-deleted-p rmail-current-message)
1019 (progn (rmail-set-attribute rmail-deleted-attr-index nil)
1020 (setq msgs-undeled (1+ msgs-undeled))))
1021 (setq rmail-current-message (1- rmail-current-message)))
1022 (set-buffer rmail-summary-buffer)
1023 (setq rmail-current-message init-msg msgs-undeled 0)
1024 (while (and (> rmail-current-message 0)
1025 (< msgs-undeled n))
1026 (if (rmail-summary-deleted-p rmail-current-message)
1027 (progn (rmail-summary-mark-undeleted rmail-current-message)
1028 (setq msgs-undeled (1+ msgs-undeled))))
1029 (setq rmail-current-message (1- rmail-current-message))))
1030 (rmail-summary-goto-msg)))
1032 ;; Rmail Summary mode is suitable only for specially formatted data.
1033 (put 'rmail-summary-mode 'mode-class 'special)
1035 (defun rmail-summary-mode ()
1036 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
1037 As commands are issued in the summary buffer, they are applied to the
1038 corresponding mail messages in the rmail buffer.
1040 All normal editing commands are turned off.
1041 Instead, nearly all the Rmail mode commands are available,
1042 though many of them move only among the messages in the summary.
1044 These additional commands exist:
1046 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
1047 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
1049 Commands for sorting the summary:
1051 \\[rmail-summary-sort-by-date] Sort by date.
1052 \\[rmail-summary-sort-by-subject] Sort by subject.
1053 \\[rmail-summary-sort-by-author] Sort by author.
1054 \\[rmail-summary-sort-by-recipient] Sort by recipient.
1055 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
1056 \\[rmail-summary-sort-by-lines] Sort by lines.
1057 \\[rmail-summary-sort-by-labels] Sort by labels."
1058 (interactive)
1059 (kill-all-local-variables)
1060 (setq major-mode 'rmail-summary-mode)
1061 (setq mode-name "RMAIL Summary")
1062 (setq truncate-lines t)
1063 (setq buffer-read-only t)
1064 (set-syntax-table text-mode-syntax-table)
1065 (make-local-variable 'rmail-buffer)
1066 (make-local-variable 'rmail-total-messages)
1067 (make-local-variable 'rmail-current-message)
1068 (setq rmail-current-message nil)
1069 (make-local-variable 'rmail-summary-redo)
1070 (setq rmail-summary-redo nil)
1071 (make-local-variable 'revert-buffer-function)
1072 (make-local-variable 'font-lock-defaults)
1073 (setq font-lock-defaults '(rmail-summary-font-lock-keywords t))
1074 (rmail-summary-enable)
1075 (run-mode-hooks 'rmail-summary-mode-hook))
1077 ;; Summary features need to be disabled during edit mode.
1078 (defun rmail-summary-disable ()
1079 (use-local-map text-mode-map)
1080 (remove-hook 'post-command-hook 'rmail-summary-rmail-update t)
1081 (setq revert-buffer-function nil))
1083 (defun rmail-summary-enable ()
1084 (use-local-map rmail-summary-mode-map)
1085 (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
1086 (setq revert-buffer-function 'rmail-update-summary))
1088 (defun rmail-summary-mark-seen (n &optional nomove unseen)
1089 "Remove the unseen mark from the current message, update the summary vector.
1090 N is the number of the current message. Optional argument NOMOVE
1091 non-nil means we are already at the right column. Optional argument
1092 UNSEEN non-nil means mark the message as unseen."
1093 (save-excursion
1094 (unless nomove
1095 (beginning-of-line)
1096 (skip-chars-forward " ")
1097 (skip-chars-forward "0-9"))
1098 (when (char-equal (following-char) (if unseen ?\s ?-))
1099 (let ((buffer-read-only nil))
1100 (delete-char 1)
1101 (insert (if unseen "-" " ")))
1102 (let ((line (buffer-substring-no-properties (line-beginning-position)
1103 (line-beginning-position 2))))
1104 (with-current-buffer rmail-buffer
1105 (aset rmail-summary-vector (1- n) line))))))
1107 (defvar rmail-summary-put-back-unseen nil
1108 "Used for communicating between calls to `rmail-summary-rmail-update'.
1109 If it moves to a message within an Incremental Search, and removes
1110 the `unseen' attribute from that message, it sets this flag
1111 so that if the next motion between messages is in the same Incremental
1112 Search, the `unseen' attribute is restored.")
1114 ;; Show in Rmail the message described by the summary line that point is on,
1115 ;; but only if the Rmail buffer is already visible.
1116 ;; This is a post-command-hook in summary buffers.
1117 (defun rmail-summary-rmail-update ()
1118 (let (buffer-read-only)
1119 (save-excursion
1120 ;; If at end of buffer, pretend we are on the last text line.
1121 (if (eobp)
1122 (forward-line -1))
1123 (beginning-of-line)
1124 (skip-chars-forward " ")
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 ;; If message number N was specified, find that message's line
1212 ;; or set message-not-found.
1213 ;; If N wasn't specified or that message can't be found.
1214 ;; set N by default.
1215 (if (not n)
1216 (setq n curmsg)
1217 (if (< n 1)
1218 (progn (message "No preceding message")
1219 (setq n 1)))
1220 (if (and (> n total)
1221 (> total 0))
1222 (progn (message "No following message")
1223 (goto-char (point-max))
1224 (rmail-summary-goto-msg nil nowarn skip-rmail)))
1225 (goto-char (point-min))
1226 (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t))
1227 (progn (or nowarn (message "Message %d not found" n))
1228 (setq n curmsg)
1229 (setq message-not-found t)
1230 (goto-char cur))))
1231 (rmail-summary-mark-seen n)
1232 (rmail-summary-update-highlight message-not-found)
1233 (beginning-of-line)
1234 (unless skip-rmail
1235 (let ((selwin (selected-window)))
1236 (unwind-protect
1237 (progn (rmail-pop-to-buffer buf)
1238 (rmail-show-message n))
1239 (select-window selwin)
1240 ;; The actions above can alter the current buffer. Preserve it.
1241 (set-buffer obuf))))
1242 (not message-not-found)))
1244 ;; Update the highlighted line in an rmail summary buffer.
1245 ;; That should be current. We highlight the line point is on.
1246 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1247 (defun rmail-summary-update-highlight (not-found)
1248 ;; Make sure we have an overlay to use.
1249 (or rmail-summary-overlay
1250 (progn
1251 (make-local-variable 'rmail-summary-overlay)
1252 (setq rmail-summary-overlay (make-overlay (point) (point)))
1253 (overlay-put rmail-summary-overlay 'rmail-summary t)))
1254 ;; If this message is in the summary, use the overlay to highlight it.
1255 ;; Otherwise, don't highlight anything.
1256 (if not-found
1257 (overlay-put rmail-summary-overlay 'face nil)
1258 (move-overlay rmail-summary-overlay
1259 (save-excursion (beginning-of-line)
1260 (skip-chars-forward " ")
1261 (point))
1262 (line-end-position))
1263 (overlay-put rmail-summary-overlay 'face 'highlight)))
1265 (defun rmail-summary-scroll-msg-up (&optional dist)
1266 "Scroll the Rmail window forward.
1267 If the Rmail window is displaying the end of a message,
1268 advance to the next message."
1269 (interactive "P")
1270 (if (eq dist '-)
1271 (rmail-summary-scroll-msg-down nil)
1272 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1273 (if rmail-buffer-window
1274 (if (let ((rmail-summary-window (selected-window)))
1275 (select-window rmail-buffer-window)
1276 (prog1
1277 ;; Is EOB visible in the buffer?
1278 (save-excursion
1279 (let ((ht (window-height (selected-window))))
1280 (move-to-window-line (- ht 2))
1281 (end-of-line)
1282 (eobp)))
1283 (select-window rmail-summary-window)))
1284 (if (not rmail-summary-scroll-between-messages)
1285 (error "End of buffer")
1286 (rmail-summary-next-msg (or dist 1)))
1287 (let ((other-window-scroll-buffer rmail-buffer))
1288 (scroll-other-window dist)))
1289 ;; If it isn't visible at all, show the beginning.
1290 (rmail-summary-beginning-of-message)))))
1292 (defun rmail-summary-scroll-msg-down (&optional dist)
1293 "Scroll the Rmail window backward.
1294 If the Rmail window is now displaying the beginning of a message,
1295 move to the previous message."
1296 (interactive "P")
1297 (if (eq dist '-)
1298 (rmail-summary-scroll-msg-up nil)
1299 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1300 (if rmail-buffer-window
1301 (if (let ((rmail-summary-window (selected-window)))
1302 (select-window rmail-buffer-window)
1303 (prog1
1304 ;; Is BOB visible in the buffer?
1305 (save-excursion
1306 (move-to-window-line 0)
1307 (beginning-of-line)
1308 (bobp))
1309 (select-window rmail-summary-window)))
1310 (if (not rmail-summary-scroll-between-messages)
1311 (error "Beginning of buffer")
1312 (rmail-summary-previous-msg (or dist 1)))
1313 (let ((other-window-scroll-buffer rmail-buffer))
1314 (scroll-other-window-down dist)))
1315 ;; If it isn't visible at all, show the beginning.
1316 (rmail-summary-beginning-of-message)))))
1318 (defun rmail-summary-beginning-of-message ()
1319 "Show current message from the beginning."
1320 (interactive)
1321 (rmail-summary-show-message 'BEG))
1323 (defun rmail-summary-end-of-message ()
1324 "Show bottom of current message."
1325 (interactive)
1326 (rmail-summary-show-message 'END))
1328 (defun rmail-summary-show-message (where)
1329 "Show current mail message.
1330 Position it according to WHERE which can be BEG or END"
1331 (if (and (one-window-p) (not pop-up-frames))
1332 ;; If there is just one window, put the summary on the top.
1333 (let ((buffer rmail-buffer))
1334 (split-window (selected-window) rmail-summary-window-size)
1335 (select-window (frame-first-window))
1336 (rmail-pop-to-buffer rmail-buffer)
1337 ;; If pop-to-buffer did not use that window, delete that
1338 ;; window. (This can happen if it uses another frame.)
1339 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1340 (delete-other-windows)))
1341 (rmail-pop-to-buffer rmail-buffer))
1342 (cond
1343 ((eq where 'BEG)
1344 (goto-char (point-min))
1345 (search-forward "\n\n"))
1346 ((eq where 'END)
1347 (goto-char (point-max))
1348 (recenter (1- (window-height))))
1350 (rmail-pop-to-buffer rmail-summary-buffer))
1352 (defun rmail-summary-bury ()
1353 "Bury the Rmail buffer and the Rmail summary buffer."
1354 (interactive)
1355 (let ((buffer-to-bury (current-buffer)))
1356 (let (window)
1357 (while (setq window (get-buffer-window rmail-buffer))
1358 (set-window-buffer window (other-buffer rmail-buffer)))
1359 (bury-buffer rmail-buffer))
1360 (switch-to-buffer (other-buffer buffer-to-bury))
1361 (bury-buffer buffer-to-bury)))
1363 (defun rmail-summary-quit ()
1364 "Quit out of Rmail and Rmail summary."
1365 (interactive)
1366 (rmail-summary-wipe)
1367 (rmail-quit))
1369 (defun rmail-summary-wipe ()
1370 "Kill and wipe away Rmail summary, remaining within Rmail."
1371 (interactive)
1372 (with-current-buffer rmail-buffer (setq rmail-summary-buffer nil))
1373 (let ((local-rmail-buffer rmail-buffer))
1374 (kill-buffer (current-buffer))
1375 ;; Delete window if not only one.
1376 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1377 (delete-window))
1378 ;; Switch windows to the rmail buffer, or switch to it in this window.
1379 (rmail-pop-to-buffer local-rmail-buffer)))
1381 (defun rmail-summary-expunge ()
1382 "Actually erase all deleted messages and recompute summary headers."
1383 (interactive)
1384 (with-current-buffer rmail-buffer
1385 (when (rmail-expunge-confirmed)
1386 (rmail-only-expunge)))
1387 (rmail-update-summary))
1389 (defun rmail-summary-expunge-and-save ()
1390 "Expunge and save RMAIL file."
1391 (interactive)
1392 (save-excursion
1393 (rmail-expunge-and-save))
1394 (rmail-update-summary)
1395 (set-buffer-modified-p nil))
1397 (defun rmail-summary-get-new-mail (&optional file-name)
1398 "Get new mail and recompute summary headers.
1400 Optionally you can specify the file to get new mail from. In this case,
1401 the file of new mail is not changed or deleted. Noninteractively, you can
1402 pass the inbox file name as an argument. Interactively, a prefix
1403 argument says to read a file name and use that file as the inbox."
1404 (interactive
1405 (list (if current-prefix-arg
1406 (read-file-name "Get new mail from file: "))))
1407 (let (msg)
1408 (with-current-buffer rmail-buffer
1409 (rmail-get-new-mail file-name)
1410 ;; Get the proper new message number.
1411 (setq msg rmail-current-message))
1412 ;; Make sure that message is displayed.
1413 (or (zerop msg)
1414 (rmail-summary-goto-msg msg))))
1416 (defun rmail-summary-input (filename)
1417 "Run Rmail on file FILENAME."
1418 (interactive "FRun rmail on RMAIL file: ")
1419 ;; We switch windows here, then display the other Rmail file there.
1420 (rmail-pop-to-buffer rmail-buffer)
1421 (rmail filename))
1423 (defun rmail-summary-first-message ()
1424 "Show first message in Rmail file from summary buffer."
1425 (interactive)
1426 (with-no-warnings
1427 (beginning-of-buffer)))
1429 (defun rmail-summary-last-message ()
1430 "Show last message in Rmail file from summary buffer."
1431 (interactive)
1432 (with-no-warnings
1433 (end-of-buffer))
1434 (forward-line -1))
1436 (declare-function rmail-abort-edit "rmailedit" ())
1437 (declare-function rmail-cease-edit "rmailedit"())
1438 (declare-function rmail-set-label "rmailkwd" (l state &optional n))
1439 (declare-function rmail-output-read-file-name "rmailout" ())
1440 (declare-function mail-send-and-exit "sendmail" (&optional arg))
1442 (defvar rmail-summary-edit-map nil)
1443 (if rmail-summary-edit-map
1445 (setq rmail-summary-edit-map
1446 (nconc (make-sparse-keymap) text-mode-map))
1447 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
1448 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
1450 (defun rmail-summary-edit-current-message ()
1451 "Edit the contents of this message."
1452 (interactive)
1453 (rmail-pop-to-buffer rmail-buffer)
1454 (rmail-edit-current-message)
1455 (use-local-map rmail-summary-edit-map))
1457 (defun rmail-summary-cease-edit ()
1458 "Finish editing message, then go back to Rmail summary buffer."
1459 (interactive)
1460 (rmail-cease-edit)
1461 (rmail-pop-to-buffer rmail-summary-buffer))
1463 (defun rmail-summary-abort-edit ()
1464 "Abort edit of current message; restore original contents.
1465 Go back to summary buffer."
1466 (interactive)
1467 (rmail-abort-edit)
1468 (rmail-pop-to-buffer rmail-summary-buffer))
1470 (defun rmail-summary-search-backward (regexp &optional n)
1471 "Show message containing next match for REGEXP.
1472 Prefix argument gives repeat count; negative argument means search
1473 backwards (through earlier messages).
1474 Interactively, empty argument means use same regexp used last time."
1475 (interactive
1476 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1477 (prompt
1478 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1479 regexp)
1480 (setq prompt
1481 (concat prompt
1482 (if rmail-search-last-regexp
1483 (concat ", default "
1484 rmail-search-last-regexp "): ")
1485 "): ")))
1486 (setq regexp (read-string prompt))
1487 (cond ((not (equal regexp ""))
1488 (setq rmail-search-last-regexp regexp))
1489 ((not rmail-search-last-regexp)
1490 (error "No previous Rmail search string")))
1491 (list rmail-search-last-regexp
1492 (prefix-numeric-value current-prefix-arg))))
1493 ;; Don't use save-excursion because that prevents point from moving
1494 ;; properly in the summary buffer.
1495 (with-current-buffer rmail-buffer
1496 (rmail-search regexp (- n))))
1498 (defun rmail-summary-search (regexp &optional n)
1499 "Show message containing next match for REGEXP.
1500 Prefix argument gives repeat count; negative argument means search
1501 backwards (through earlier messages).
1502 Interactively, empty argument means use same regexp used last time."
1503 (interactive
1504 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1505 (prompt
1506 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1507 regexp)
1508 (setq prompt
1509 (concat prompt
1510 (if rmail-search-last-regexp
1511 (concat ", default "
1512 rmail-search-last-regexp "): ")
1513 "): ")))
1514 (setq regexp (read-string prompt))
1515 (cond ((not (equal regexp ""))
1516 (setq rmail-search-last-regexp regexp))
1517 ((not rmail-search-last-regexp)
1518 (error "No previous Rmail search string")))
1519 (list rmail-search-last-regexp
1520 (prefix-numeric-value current-prefix-arg))))
1521 ;; Don't use save-excursion because that prevents point from moving
1522 ;; properly in the summary buffer.
1523 (let ((buffer (current-buffer))
1524 (selwin (selected-window)))
1525 (unwind-protect
1526 (progn
1527 (rmail-pop-to-buffer rmail-buffer)
1528 (rmail-search regexp n))
1529 (select-window selwin)
1530 (set-buffer buffer))))
1532 (defun rmail-summary-toggle-header ()
1533 "Show original message header if pruned header currently shown, or vice versa."
1534 (interactive)
1535 (save-window-excursion
1536 (set-buffer rmail-buffer)
1537 (rmail-toggle-header))
1538 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1539 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1540 (let ((window (get-buffer-window rmail-buffer)))
1541 (if window
1542 ;; Using save-window-excursion would lose the new value of point.
1543 (let ((owin (selected-window)))
1544 (unwind-protect
1545 (progn
1546 (select-window window)
1547 (goto-char (point-min)))
1548 (select-window owin))))))
1551 (defun rmail-summary-add-label (label)
1552 "Add LABEL to labels associated with current Rmail message.
1553 Completion is performed over known labels when reading."
1554 (interactive (list (with-current-buffer rmail-buffer
1555 (rmail-read-label "Add label"))))
1556 (with-current-buffer rmail-buffer
1557 (rmail-add-label label)))
1559 (defun rmail-summary-kill-label (label)
1560 "Remove LABEL from labels associated with current Rmail message.
1561 Completion is performed over known labels when reading."
1562 (interactive (list (with-current-buffer rmail-buffer
1563 (rmail-read-label "Kill label"))))
1564 (with-current-buffer rmail-buffer
1565 (rmail-set-label label nil)))
1567 ;;;; *** Rmail Summary Mailing Commands ***
1569 (defun rmail-summary-override-mail-send-and-exit ()
1570 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1571 (use-local-map (copy-keymap (current-local-map)))
1572 (dolist (key (where-is-internal 'mail-send-and-exit))
1573 (define-key (current-local-map) key 'rmail-summary-send-and-exit)))
1575 (defun rmail-summary-mail ()
1576 "Send mail in another window.
1577 While composing the message, use \\[mail-yank-original] to yank the
1578 original message into it."
1579 (interactive)
1580 (let ((window (get-buffer-window rmail-buffer)))
1581 (if window
1582 (select-window window)
1583 (set-buffer rmail-buffer)))
1584 (rmail-start-mail nil nil nil nil nil (current-buffer))
1585 (rmail-summary-override-mail-send-and-exit))
1587 (defun rmail-summary-continue ()
1588 "Continue composing outgoing message previously being composed."
1589 (interactive)
1590 (let ((window (get-buffer-window rmail-buffer)))
1591 (if window
1592 (select-window window)
1593 (set-buffer rmail-buffer)))
1594 (rmail-start-mail t))
1596 (defun rmail-summary-reply (just-sender)
1597 "Reply to the current message.
1598 Normally include CC: to all other recipients of original message;
1599 prefix argument means ignore them. While composing the reply,
1600 use \\[mail-yank-original] to yank the original message into it."
1601 (interactive "P")
1602 (let ((window (get-buffer-window rmail-buffer)))
1603 (if window
1604 (select-window window)
1605 (set-buffer rmail-buffer)))
1606 (rmail-reply just-sender)
1607 (rmail-summary-override-mail-send-and-exit))
1609 (defun rmail-summary-retry-failure ()
1610 "Edit a mail message which is based on the contents of the current message.
1611 For a message rejected by the mail system, extract the interesting headers and
1612 the body of the original message; otherwise copy the current message."
1613 (interactive)
1614 (let ((window (get-buffer-window rmail-buffer)))
1615 (if window
1616 (select-window window)
1617 (set-buffer rmail-buffer)))
1618 (rmail-retry-failure)
1619 (rmail-summary-override-mail-send-and-exit))
1621 (defun rmail-summary-send-and-exit ()
1622 "Send mail reply and return to summary buffer."
1623 (interactive)
1624 (mail-send-and-exit t))
1626 (defun rmail-summary-forward (resend)
1627 "Forward the current message to another user.
1628 With prefix argument, \"resend\" the message instead of forwarding it;
1629 see the documentation of `rmail-resend'."
1630 (interactive "P")
1631 (save-excursion
1632 (let ((window (get-buffer-window rmail-buffer)))
1633 (if window
1634 (select-window window)
1635 (set-buffer rmail-buffer)))
1636 (rmail-forward resend)
1637 (rmail-summary-override-mail-send-and-exit)))
1639 (defun rmail-summary-resend ()
1640 "Resend current message using `rmail-resend'."
1641 (interactive)
1642 (save-excursion
1643 (let ((window (get-buffer-window rmail-buffer)))
1644 (if window
1645 (select-window window)
1646 (set-buffer rmail-buffer)))
1647 (call-interactively 'rmail-resend)))
1649 ;; Summary output commands.
1651 (defun rmail-summary-output (&optional file-name n)
1652 "Append this message to mail file FILE-NAME.
1653 This works with both mbox format and Babyl format files,
1654 outputting in the appropriate format for each.
1655 The default file name comes from `rmail-default-file',
1656 which is updated to the name you use in this command.
1658 A prefix argument N says to output that many consecutive messages
1659 from those in the summary, starting with the current one.
1660 Deleted messages are skipped and don't count.
1661 When called from Lisp code, N may be omitted and defaults to 1.
1663 This command always outputs the complete message header,
1664 even the header display is currently pruned."
1665 (interactive
1666 (progn (require 'rmailout)
1667 (list (rmail-output-read-file-name)
1668 (prefix-numeric-value current-prefix-arg))))
1669 (let ((i 0) prev-msg)
1670 (while
1671 (and (< i n)
1672 (progn (rmail-summary-goto-msg)
1673 (not (eq prev-msg
1674 (setq prev-msg
1675 (with-current-buffer rmail-buffer
1676 rmail-current-message))))))
1677 (setq i (1+ i))
1678 (with-current-buffer rmail-buffer
1679 (let ((rmail-delete-after-output nil))
1680 (rmail-output file-name 1)))
1681 (if rmail-delete-after-output
1682 (rmail-summary-delete-forward nil)
1683 (if (< i n)
1684 (rmail-summary-next-msg 1))))))
1686 (defalias 'rmail-summary-output-to-rmail-file 'rmail-summary-output)
1688 (declare-function rmail-output-as-seen "rmailout"
1689 (file-name &optional count noattribute from-gnus))
1691 (defun rmail-summary-output-as-seen (&optional file-name n)
1692 "Append this message to mbox file named FILE-NAME.
1693 A prefix argument N says to output that many consecutive messages,
1694 from the summary, starting with the current one.
1695 Deleted messages are skipped and don't count.
1696 When called from Lisp code, N may be omitted and defaults to 1.
1698 This outputs the message header as you see it (or would see it)
1699 displayed in Rmail.
1701 The default file name comes from `rmail-default-file',
1702 which is updated to the name you use in this command."
1703 (interactive
1704 (progn (require 'rmailout)
1705 (list (rmail-output-read-file-name)
1706 (prefix-numeric-value current-prefix-arg))))
1707 (require 'rmailout) ; for rmail-output-as-seen in non-interactive case
1708 (let ((i 0) prev-msg)
1709 (while
1710 (and (< i n)
1711 (progn (rmail-summary-goto-msg)
1712 (not (eq prev-msg
1713 (setq prev-msg
1714 (with-current-buffer rmail-buffer
1715 rmail-current-message))))))
1716 (setq i (1+ i))
1717 (with-current-buffer rmail-buffer
1718 (let ((rmail-delete-after-output nil))
1719 (rmail-output-as-seen file-name 1)))
1720 (if rmail-delete-after-output
1721 (rmail-summary-delete-forward nil)
1722 (if (< i n)
1723 (rmail-summary-next-msg 1))))))
1725 (defun rmail-summary-output-menu ()
1726 "Output current message to another Rmail file, chosen with a menu.
1727 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1728 The variables `rmail-secondary-file-directory' and
1729 `rmail-secondary-file-regexp' control which files are offered in the menu."
1730 (interactive)
1731 (with-current-buffer rmail-buffer
1732 (let ((rmail-delete-after-output nil))
1733 (call-interactively 'rmail-output-menu)))
1734 (if rmail-delete-after-output
1735 (rmail-summary-delete-forward nil)))
1737 (defun rmail-summary-construct-io-menu ()
1738 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1739 (if files
1740 (progn
1741 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1742 (cons "Input Rmail File"
1743 (rmail-list-to-menu "Input Rmail File"
1744 files
1745 'rmail-summary-input)))
1746 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1747 (cons "Output Rmail File"
1748 (rmail-list-to-menu "Output Rmail File"
1749 files
1750 'rmail-summary-output))))
1751 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1752 '("Input Rmail File" . rmail-disable-menu))
1753 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1754 '("Output Rmail File" . rmail-disable-menu)))))
1756 (defun rmail-summary-output-body (&optional file-name)
1757 "Write this message body to the file FILE-NAME.
1758 FILE-NAME defaults, interactively, from the Subject field of the message."
1759 (interactive)
1760 (with-current-buffer rmail-buffer
1761 (let ((rmail-delete-after-output nil))
1762 (if file-name
1763 (rmail-output-body-to-file file-name)
1764 (call-interactively 'rmail-output-body-to-file))))
1765 (if rmail-delete-after-output
1766 (rmail-summary-delete-forward nil)))
1768 ;; Sorting messages in Rmail Summary buffer.
1770 (defun rmail-summary-sort-by-date (reverse)
1771 "Sort messages of current Rmail summary by \"Date\" header.
1772 If prefix argument REVERSE is non-nil, sorts in reverse order."
1773 (interactive "P")
1774 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1776 (defun rmail-summary-sort-by-subject (reverse)
1777 "Sort messages of current Rmail summary by \"Subject\" header.
1778 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
1779 non-nil, sorts in reverse order."
1780 (interactive "P")
1781 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1783 (defun rmail-summary-sort-by-author (reverse)
1784 "Sort messages of current Rmail summary by author.
1785 This uses either the \"From\" or \"Sender\" header, downcased.
1786 If prefix argument REVERSE is non-nil, sorts in reverse order."
1787 (interactive "P")
1788 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1790 (defun rmail-summary-sort-by-recipient (reverse)
1791 "Sort messages of current Rmail summary by recipient.
1792 This uses either the \"To\" or \"Apparently-To\" 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-recipient) reverse))
1797 (defun rmail-summary-sort-by-correspondent (reverse)
1798 "Sort messages of current Rmail summary by other correspondent.
1799 This uses either the \"From\", \"Sender\", \"To\", or
1800 \"Apparently-To\" header, downcased. Uses the first header not
1801 excluded by `mail-dont-reply-to-names'. If prefix argument
1802 REVERSE is non-nil, sorts in reverse order."
1803 (interactive "P")
1804 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1806 (defun rmail-summary-sort-by-lines (reverse)
1807 "Sort messages of current Rmail summary by the number of lines.
1808 If prefix argument REVERSE is non-nil, sorts in reverse order."
1809 (interactive "P")
1810 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1812 (defun rmail-summary-sort-by-labels (reverse labels)
1813 "Sort messages of current Rmail summary by labels.
1814 LABELS is a comma-separated list of labels.
1815 If prefix argument REVERSE is non-nil, sorts in reverse order."
1816 (interactive "P\nsSort by labels: ")
1817 (rmail-sort-from-summary
1818 (lambda (reverse) (rmail-sort-by-labels reverse labels))
1819 reverse))
1821 (defun rmail-sort-from-summary (sortfun reverse)
1822 "Sort the Rmail buffer using sorting function SORTFUN.
1823 Passes REVERSE to SORTFUN as its sole argument. Then regenerates
1824 the summary. Note that the whole Rmail buffer is sorted, even if
1825 the summary is only showing a subset of messages."
1826 (require 'rmailsort)
1827 (let ((selwin (selected-window)))
1828 (unwind-protect
1829 (progn (rmail-pop-to-buffer rmail-buffer)
1830 (funcall sortfun reverse))
1831 (select-window selwin))))
1833 (provide 'rmailsum)
1835 ;; Local Variables:
1836 ;; generated-autoload-file: "rmail.el"
1837 ;; End:
1839 ;;; rmailsum.el ends here