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