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