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