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