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