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