(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / mail / rmailsum.el
blob9c647126d5ca4685e5454c7680b3fd109b2f4790
1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: mail
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; Extended by Bob Weiner of Motorola
29 ;; Provided all commands from rmail-mode in rmail-summary-mode and made key
30 ;; bindings in both modes wholly compatible.
32 ;;; Code:
34 ;; For rmail-select-summary
35 (require 'rmail)
37 ;;;###autoload
38 (defcustom rmail-summary-scroll-between-messages t
39 "*Non-nil means Rmail summary scroll commands move between messages."
40 :type 'boolean
41 :group 'rmail-summary)
43 ;;;###autoload
44 (defcustom rmail-summary-line-count-flag t
45 "*Non-nil means Rmail summary should show the number of lines in each message."
46 :type 'boolean
47 :group 'rmail-summary)
49 (defvar rmail-summary-font-lock-keywords
50 '(("^.....D.*" . font-lock-string-face) ; Deleted.
51 ("^.....-.*" . font-lock-type-face) ; Unread.
52 ;; Neither of the below will be highlighted if either of the above are:
53 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date.
54 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face)) ; Labels.
55 "Additional expressions to highlight in Rmail Summary mode.")
57 ;; Entry points for making a summary buffer.
59 ;; Regenerate the contents of the summary
60 ;; using the same selection criterion as last time.
61 ;; M-x revert-buffer in a summary buffer calls this function.
62 (defun rmail-update-summary (&rest ignore)
63 (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
65 ;;;###autoload
66 (defun rmail-summary ()
67 "Display a summary of all messages, one line per message."
68 (interactive)
69 (rmail-new-summary "All" '(rmail-summary) nil))
71 ;;;###autoload
72 (defun rmail-summary-by-labels (labels)
73 "Display a summary of all messages with one or more LABELS.
74 LABELS should be a string containing the desired labels, separated by commas."
75 (interactive "sLabels to summarize by: ")
76 (if (string= labels "")
77 (setq labels (or rmail-last-multi-labels
78 (error "No label specified"))))
79 (setq rmail-last-multi-labels labels)
80 (rmail-new-summary (concat "labels " labels)
81 (list 'rmail-summary-by-labels labels)
82 'rmail-message-labels-p
83 (concat ", \\(" (mail-comma-list-regexp labels) "\\),")))
85 ;;;###autoload
86 (defun rmail-summary-by-recipients (recipients &optional primary-only)
87 "Display a summary of all messages with the given RECIPIENTS.
88 Normally checks the To, From and Cc fields of headers;
89 but if PRIMARY-ONLY is non-nil (prefix arg given),
90 only look in the To and From fields.
91 RECIPIENTS is a string of regexps separated by commas."
92 (interactive "sRecipients to summarize by: \nP")
93 (rmail-new-summary
94 (concat "recipients " recipients)
95 (list 'rmail-summary-by-recipients recipients primary-only)
96 'rmail-message-recipients-p
97 (mail-comma-list-regexp recipients) primary-only))
99 ;;;###autoload
100 (defun rmail-summary-by-regexp (regexp)
101 "Display a summary of all messages according to regexp REGEXP.
102 If the regular expression is found in the header of the message
103 \(including in the date and other lines, as well as the subject line),
104 Emacs will list the header line in the RMAIL-summary."
105 (interactive "sRegexp to summarize by: ")
106 (if (string= regexp "")
107 (setq regexp (or rmail-last-regexp
108 (error "No regexp specified"))))
109 (setq rmail-last-regexp regexp)
110 (rmail-new-summary (concat "regexp " regexp)
111 (list 'rmail-summary-by-regexp regexp)
112 'rmail-message-regexp-p
113 regexp))
115 ;; rmail-summary-by-topic
116 ;; 1989 R.A. Schnitzler
118 ;;;###autoload
119 (defun rmail-summary-by-topic (subject &optional whole-message)
120 "Display a summary of all messages with the given SUBJECT.
121 Normally checks the Subject field of headers;
122 but if WHOLE-MESSAGE is non-nil (prefix arg given),
123 look in the whole message.
124 SUBJECT is a string of regexps separated by commas."
125 (interactive "sTopics to summarize by: \nP")
126 (rmail-new-summary
127 (concat "about " subject)
128 (list 'rmail-summary-by-topic subject whole-message)
129 'rmail-message-subject-p
130 (mail-comma-list-regexp subject) whole-message))
132 (defun rmail-message-subject-p (msg subject &optional whole-message)
133 (save-restriction
134 (goto-char (rmail-msgbeg msg))
135 (search-forward "\n*** EOOH ***\n" (rmail-msgend msg) 'move)
136 (narrow-to-region
137 (point)
138 (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
139 (goto-char (point-min))
140 (if whole-message (re-search-forward subject nil t)
141 (string-match subject (let ((subj (mail-fetch-field "Subject")))
142 (if subj
143 (funcall rmail-summary-line-decoder subj)
144 ""))))))
146 ;;;###autoload
147 (defun rmail-summary-by-senders (senders)
148 "Display a summary of all messages with the given SENDERS.
149 SENDERS is a string of names separated by commas."
150 (interactive "sSenders to summarize by: ")
151 (rmail-new-summary
152 (concat "senders " senders)
153 (list 'rmail-summary-by-senders senders)
154 'rmail-message-senders-p
155 (mail-comma-list-regexp senders)))
157 (defun rmail-message-senders-p (msg senders)
158 (save-restriction
159 (goto-char (rmail-msgbeg msg))
160 (search-forward "\n*** EOOH ***\n")
161 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
162 (string-match senders (or (mail-fetch-field "From") ""))))
164 ;; General making of a summary buffer.
166 (defvar rmail-summary-symbol-number 0)
168 (defun rmail-new-summary (description redo-form function &rest args)
169 "Create a summary of selected messages.
170 DESCRIPTION makes part of the mode line of the summary buffer.
171 For each message, FUNCTION is applied to the message number and ARGS...
172 and if the result is non-nil, that message is included.
173 nil for FUNCTION means all messages."
174 (message "Computing summary lines...")
175 (let (sumbuf mesg was-in-summary)
176 (save-excursion
177 ;; Go to the Rmail buffer.
178 (if (eq major-mode 'rmail-summary-mode)
179 (setq was-in-summary t))
180 (set-buffer rmail-buffer)
181 ;; Find its summary buffer, or make one.
182 (setq sumbuf
183 (if (and rmail-summary-buffer
184 (buffer-name rmail-summary-buffer))
185 rmail-summary-buffer
186 (generate-new-buffer (concat (buffer-name) "-summary"))))
187 (setq mesg rmail-current-message)
188 ;; Filter the messages; make or get their summary lines.
189 (let ((summary-msgs ())
190 (new-summary-line-count 0))
191 (let ((msgnum 1)
192 (buffer-read-only nil)
193 (old-min (point-min-marker))
194 (old-max (point-max-marker)))
195 ;; Can't use save-restriction here; that doesn't work if we
196 ;; plan to modify text outside the original restriction.
197 (save-excursion
198 (widen)
199 (goto-char (point-min))
200 (while (>= rmail-total-messages msgnum)
201 (if (or (null function)
202 (apply function (cons msgnum args)))
203 (setq summary-msgs
204 (cons (cons msgnum (rmail-make-summary-line msgnum))
205 summary-msgs)))
206 (setq msgnum (1+ msgnum)))
207 (setq summary-msgs (nreverse summary-msgs)))
208 (narrow-to-region old-min old-max))
209 ;; Temporarily, while summary buffer is unfinished,
210 ;; we "don't have" a summary.
211 (setq rmail-summary-buffer nil)
212 (if rmail-enable-mime
213 (with-current-buffer rmail-view-buffer
214 (setq rmail-summary-buffer nil)))
215 (save-excursion
216 (let ((rbuf (current-buffer))
217 (vbuf rmail-view-buffer)
218 (total rmail-total-messages))
219 (set-buffer sumbuf)
220 ;; Set up the summary buffer's contents.
221 (let ((buffer-read-only nil))
222 (erase-buffer)
223 (while summary-msgs
224 (princ (cdr (car summary-msgs)) sumbuf)
225 (setq summary-msgs (cdr summary-msgs)))
226 (goto-char (point-min)))
227 ;; Set up the rest of its state and local variables.
228 (setq buffer-read-only t)
229 (rmail-summary-mode)
230 (make-local-variable 'minor-mode-alist)
231 (setq minor-mode-alist (list (list t (concat ": " description))))
232 (setq rmail-buffer rbuf
233 rmail-view-buffer vbuf
234 rmail-summary-redo redo-form
235 rmail-total-messages total))))
236 (setq rmail-summary-buffer sumbuf))
237 ;; Now display the summary buffer and go to the right place in it.
238 (or was-in-summary
239 (progn
240 (if (and (one-window-p)
241 pop-up-windows (not pop-up-frames))
242 ;; If there is just one window, put the summary on the top.
243 (progn
244 (split-window (selected-window) rmail-summary-window-size)
245 (select-window (next-window (frame-first-window)))
246 (pop-to-buffer sumbuf)
247 ;; If pop-to-buffer did not use that window, delete that
248 ;; window. (This can happen if it uses another frame.)
249 (if (not (eq sumbuf (window-buffer (frame-first-window))))
250 (delete-other-windows)))
251 (pop-to-buffer sumbuf))
252 (set-buffer rmail-buffer)
253 ;; This is how rmail makes the summary buffer reappear.
254 ;; We do this here to make the window the proper size.
255 (rmail-select-summary nil)
256 (set-buffer rmail-summary-buffer)))
257 (rmail-summary-goto-msg mesg t t)
258 (rmail-summary-construct-io-menu)
259 (message "Computing summary lines...done")))
261 ;; Low levels of generating a summary.
263 (defun rmail-make-summary-line (msg)
264 (let ((line (or (aref rmail-summary-vector (1- msg))
265 (progn
266 (setq new-summary-line-count
267 (1+ new-summary-line-count))
268 (if (zerop (% new-summary-line-count 10))
269 (message "Computing summary lines...%d"
270 new-summary-line-count))
271 (rmail-make-summary-line-1 msg)))))
272 ;; Fix up the part of the summary that says "deleted" or "unseen".
273 (aset line 5
274 (if (rmail-message-deleted-p msg) ?\D
275 (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg))))
276 ?\- ?\ )))
277 line))
279 ;;;###autoload
280 (defcustom rmail-summary-line-decoder (function identity)
281 "*Function to decode summary-line.
283 By default, `identity' is set."
284 :type 'function
285 :group 'rmail-summary)
287 (defun rmail-make-summary-line-1 (msg)
288 (goto-char (rmail-msgbeg msg))
289 (let* ((lim (save-excursion (forward-line 2) (point)))
291 (labels
292 (progn
293 (forward-char 3)
294 (concat
295 ; (if (save-excursion (re-search-forward ",answered," lim t))
296 ; "*" "")
297 ; (if (save-excursion (re-search-forward ",filed," lim t))
298 ; "!" "")
299 (if (progn (search-forward ",,") (eolp))
301 (concat "{"
302 (buffer-substring (point)
303 (progn (end-of-line)
304 (backward-char)
305 (if (looking-at ",")
306 (point)
307 (1+ (point)))))
308 " } ")))))
309 (line
310 (progn
311 (forward-line 1)
312 (if (looking-at "Summary-line: ")
313 (progn
314 (goto-char (match-end 0))
315 (setq line
316 (buffer-substring (point)
317 (progn (forward-line 1) (point)))))))))
318 ;; Obsolete status lines lacking a # should be flushed.
319 (and line
320 (not (string-match "#" line))
321 (progn
322 (delete-region (point)
323 (progn (forward-line -1) (point)))
324 (setq line nil)))
325 ;; If we didn't get a valid status line from the message,
326 ;; make a new one and put it in the message.
327 (or line
328 (let* ((case-fold-search t)
329 (next (rmail-msgend msg))
330 (beg (if (progn (goto-char (rmail-msgbeg msg))
331 (search-forward "\n*** EOOH ***\n" next t))
332 (point)
333 (forward-line 1)
334 (point)))
335 (end (progn (search-forward "\n\n" nil t) (point))))
336 (save-restriction
337 (narrow-to-region beg end)
338 (goto-char beg)
339 (setq line (rmail-make-basic-summary-line)))
340 (goto-char (rmail-msgbeg msg))
341 (forward-line 2)
342 (insert "Summary-line: " line)))
343 (setq pos (string-match "#" line))
344 (aset rmail-summary-vector (1- msg)
345 (funcall rmail-summary-line-decoder
346 (concat (format "%5d " msg)
347 (substring line 0 pos)
348 labels
349 (substring line (1+ pos)))))
352 ;;;###autoload
353 (defcustom rmail-user-mail-address-regexp nil
354 "*Regexp matching user mail addresses.
355 If non-nil, this variable is used to identify the correspondent
356 when receiving new mail. If it matches the address of the sender,
357 the recipient is taken as correspondent of a mail.
358 If nil \(default value\), your `user-login-name' and `user-mail-address'
359 are used to exclude yourself as correspondent.
361 Usually you don't have to set this variable, except if you collect mails
362 sent by you under different user names.
363 Then it should be a regexp matching your mail addresses.
365 Setting this variable has an effect only before reading a mail."
366 :type '(choice (const :tag "None" nil) regexp)
367 :group 'rmail-retrieve
368 :version "21.1")
370 (defun rmail-make-basic-summary-line ()
371 (goto-char (point-min))
372 (concat (save-excursion
373 (if (not (re-search-forward "^Date:" nil t))
375 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
376 (save-excursion (end-of-line) (point)) t)
377 (format "%2d-%3s"
378 (string-to-number (buffer-substring
379 (match-beginning 2)
380 (match-end 2)))
381 (buffer-substring
382 (match-beginning 4) (match-end 4))))
383 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
384 (save-excursion (end-of-line) (point)) t)
385 (format "%2d-%3s"
386 (string-to-number (buffer-substring
387 (match-beginning 4)
388 (match-end 4)))
389 (buffer-substring
390 (match-beginning 2) (match-end 2))))
391 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
392 (save-excursion (end-of-line) (point)) t)
393 (format "%2s%2s%2s"
394 (buffer-substring
395 (match-beginning 2) (match-end 2))
396 (buffer-substring
397 (match-beginning 3) (match-end 3))
398 (buffer-substring
399 (match-beginning 4) (match-end 4))))
400 (t "??????"))))
402 (save-excursion
403 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t)
404 (mail-strip-quoted-names
405 (buffer-substring
406 (1- (point))
407 ;; Get all the lines of the From field
408 ;; so that we get a whole comment if there is one,
409 ;; so that mail-strip-quoted-names can discard it.
410 (let ((opoint (point)))
411 (while (progn (forward-line 1)
412 (looking-at "[ \t]")))
413 ;; Back up over newline, then trailing spaces or tabs
414 (forward-char -1)
415 (skip-chars-backward " \t")
416 (point))))))
417 len mch lo)
418 (if (or (null from)
419 (string-match
420 (or rmail-user-mail-address-regexp
421 (concat "^\\("
422 (regexp-quote (user-login-name))
423 "\\($\\|@\\)\\|"
424 (regexp-quote
425 ;; Don't lose if run from init file
426 ;; where user-mail-address is not
427 ;; set yet.
428 (or user-mail-address
429 (concat (user-login-name) "@"
430 (or mail-host-address
431 (system-name)))))
432 "\\>\\)"))
433 from))
434 ;; No From field, or it's this user.
435 (save-excursion
436 (goto-char (point-min))
437 (if (not (re-search-forward "^To:[ \t]*" nil t))
439 (setq from
440 (concat "to: "
441 (mail-strip-quoted-names
442 (buffer-substring
443 (point)
444 (progn (end-of-line)
445 (skip-chars-backward " \t")
446 (point)))))))))
447 (if (null from)
449 (setq len (length from))
450 (setq mch (string-match "[@%]" from))
451 (format "%25s"
452 (if (or (not mch) (<= len 25))
453 (substring from (max 0 (- len 25)))
454 (substring from
455 (setq lo (cond ((< (- mch 14) 0) 0)
456 ((< len (+ mch 11))
457 (- len 25))
458 (t (- mch 14))))
459 (min len (+ lo 25))))))))
460 (if rmail-summary-line-count-flag
461 (save-excursion
462 (save-restriction
463 (widen)
464 (let ((beg (rmail-msgbeg msgnum))
465 (end (rmail-msgend msgnum))
466 lines)
467 (save-excursion
468 (goto-char beg)
469 ;; Count only lines in the reformatted header,
470 ;; if we have reformatted it.
471 (search-forward "\n*** EOOH ***\n" end t)
472 (setq lines (count-lines (point) end)))
473 (format (cond
474 ((<= lines 9) " [%d]")
475 ((<= lines 99) " [%d]")
476 ((<= lines 999) " [%3d]")
477 (t "[%d]"))
478 lines))))
479 " ")
480 " #" ;The # is part of the format.
481 (if (re-search-forward "^Subject:" nil t)
482 (progn (skip-chars-forward " \t")
483 (buffer-substring (point)
484 (progn (end-of-line)
485 (point))))
486 (re-search-forward "[\n][\n]+" nil t)
487 (buffer-substring (point) (progn (end-of-line) (point))))
488 "\n"))
490 ;; Simple motion in a summary buffer.
492 (defun rmail-summary-next-all (&optional number)
493 (interactive "p")
494 (forward-line (if number number 1))
495 ;; It doesn't look nice to move forward past the last message line.
496 (and (eobp) (> number 0)
497 (forward-line -1))
498 (display-buffer rmail-buffer))
500 (defun rmail-summary-previous-all (&optional number)
501 (interactive "p")
502 (forward-line (- (if number number 1)))
503 ;; It doesn't look nice to move forward past the last message line.
504 (and (eobp) (< number 0)
505 (forward-line -1))
506 (display-buffer rmail-buffer))
508 (defun rmail-summary-next-msg (&optional number)
509 "Display next non-deleted msg from rmail file.
510 With optional prefix argument NUMBER, moves forward this number of non-deleted
511 messages, or backward if NUMBER is negative."
512 (interactive "p")
513 (forward-line 0)
514 (and (> number 0) (end-of-line))
515 (let ((count (if (< number 0) (- number) number))
516 (search (if (> number 0) 're-search-forward 're-search-backward))
517 (non-del-msg-found nil))
518 (while (and (> count 0) (setq non-del-msg-found
519 (or (funcall search "^....[^D]" nil t)
520 non-del-msg-found)))
521 (setq count (1- count))))
522 (beginning-of-line)
523 (display-buffer rmail-view-buffer))
525 (defun rmail-summary-previous-msg (&optional number)
526 "Display previous non-deleted msg from rmail file.
527 With optional prefix argument NUMBER, moves backward this number of
528 non-deleted messages."
529 (interactive "p")
530 (rmail-summary-next-msg (- (if number number 1))))
532 (defun rmail-summary-next-labeled-message (n labels)
533 "Show next message with LABELS. Defaults to last labels used.
534 With prefix argument N moves forward N messages with these labels."
535 (interactive "p\nsMove to next msg with labels: ")
536 (let (msg)
537 (save-excursion
538 (set-buffer rmail-buffer)
539 (rmail-next-labeled-message n labels)
540 (setq msg rmail-current-message))
541 (rmail-summary-goto-msg msg)))
543 (defun rmail-summary-previous-labeled-message (n labels)
544 "Show previous message with LABELS. Defaults to last labels used.
545 With prefix argument N moves backward N messages with these labels."
546 (interactive "p\nsMove to previous msg with labels: ")
547 (let (msg)
548 (save-excursion
549 (set-buffer rmail-buffer)
550 (rmail-previous-labeled-message n labels)
551 (setq msg rmail-current-message))
552 (rmail-summary-goto-msg msg)))
554 (defun rmail-summary-next-same-subject (n)
555 "Go to the next message in the summary having the same subject.
556 With prefix argument N, do this N times.
557 If N is negative, go backwards."
558 (interactive "p")
559 (let (subject search-regexp i found
560 (forward (> n 0)))
561 (save-excursion
562 (set-buffer rmail-buffer)
563 (setq subject (mail-fetch-field "Subject"))
564 (setq i rmail-current-message))
565 (if (string-match "Re:[ \t]*" subject)
566 (setq subject (substring subject (match-end 0))))
567 (setq search-regexp (concat "^Subject: *\\(Re: *\\)?"
568 (regexp-quote subject)
569 "\n"))
570 (save-excursion
571 (while (and (/= n 0)
572 (if forward
573 (not (eobp))
574 (not (bobp))))
575 (let (done)
576 (while (and (not done)
577 (if forward
578 (not (eobp))
579 (not (bobp))))
580 ;; Advance thru summary.
581 (forward-line (if forward 1 -1))
582 ;; Get msg number of this line.
583 (setq i (string-to-number
584 (buffer-substring (point)
585 (min (point-max) (+ 6 (point))))))
586 ;; See if that msg has desired subject.
587 (save-excursion
588 (set-buffer rmail-buffer)
589 (save-restriction
590 (widen)
591 (goto-char (rmail-msgbeg i))
592 (search-forward "\n*** EOOH ***\n")
593 (let ((beg (point)) end)
594 (search-forward "\n\n")
595 (setq end (point))
596 (goto-char beg)
597 (setq done (re-search-forward search-regexp end t))))))
598 (if done (setq found i)))
599 (setq n (if forward (1- n) (1+ n)))))
600 (if found
601 (rmail-summary-goto-msg found)
602 (error "No %s message with same subject"
603 (if forward "following" "previous")))))
605 (defun rmail-summary-previous-same-subject (n)
606 "Go to the previous message in the summary having the same subject.
607 With prefix argument N, do this N times.
608 If N is negative, go forwards instead."
609 (interactive "p")
610 (rmail-summary-next-same-subject (- n)))
612 ;; Delete and undelete summary commands.
614 (defun rmail-summary-delete-forward (&optional count)
615 "Delete this message and move to next nondeleted one.
616 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
617 A prefix argument serves as a repeat count;
618 a negative argument means to delete and move backward."
619 (interactive "p")
620 (unless (numberp count) (setq count 1))
621 (let (end del-msg
622 (backward (< count 0)))
623 (while (/= count 0)
624 (rmail-summary-goto-msg)
625 (with-current-buffer rmail-buffer
626 (rmail-delete-message)
627 (setq del-msg rmail-current-message))
628 (rmail-summary-mark-deleted del-msg)
629 (while (and (not (if backward (bobp) (eobp)))
630 (save-excursion (beginning-of-line)
631 (looking-at " *[0-9]+D")))
632 (forward-line (if backward -1 1)))
633 ;; It looks ugly to move to the empty line at end of buffer.
634 (and (eobp) (not backward)
635 (forward-line -1))
636 (setq count
637 (if (> count 0) (1- count) (1+ count))))))
639 (defun rmail-summary-delete-backward (&optional count)
640 "Delete this message and move to previous nondeleted one.
641 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
642 A prefix argument serves as a repeat count;
643 a negative argument means to delete and move forward."
644 (interactive "p")
645 (rmail-summary-delete-forward (- count)))
647 (defun rmail-summary-mark-deleted (&optional n undel)
648 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
649 (and n (rmail-summary-goto-msg n t t))
650 (or (eobp)
651 (not (overlay-get rmail-summary-overlay 'face))
652 (let ((buffer-read-only nil))
653 (skip-chars-forward " ")
654 (skip-chars-forward "[0-9]")
655 (if undel
656 (if (looking-at "D")
657 (progn (delete-char 1) (insert " ")))
658 (delete-char 1)
659 (insert "D"))))
660 (beginning-of-line))
662 (defun rmail-summary-mark-undeleted (n)
663 (rmail-summary-mark-deleted n t))
665 (defun rmail-summary-deleted-p (&optional n)
666 (save-excursion
667 (and n (rmail-summary-goto-msg n nil t))
668 (skip-chars-forward " ")
669 (skip-chars-forward "[0-9]")
670 (looking-at "D")))
672 (defun rmail-summary-undelete (&optional arg)
673 "Undelete current message.
674 Optional prefix ARG means undelete ARG previous messages."
675 (interactive "p")
676 (if (/= arg 1)
677 (rmail-summary-undelete-many arg)
678 (let ((buffer-read-only nil)
679 (opoint (point)))
680 (end-of-line)
681 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
682 (replace-match "\\1 ")
683 (rmail-summary-goto-msg)
684 (if rmail-enable-mime
685 (set-buffer rmail-buffer)
686 (pop-to-buffer rmail-buffer))
687 (and (rmail-message-deleted-p rmail-current-message)
688 (rmail-undelete-previous-message))
689 (if rmail-enable-mime
690 (pop-to-buffer rmail-view-buffer))
691 (pop-to-buffer rmail-summary-buffer))
692 (t (goto-char opoint))))))
694 (defun rmail-summary-undelete-many (&optional n)
695 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
696 (interactive "P")
697 (save-excursion
698 (set-buffer rmail-buffer)
699 (let* ((init-msg (if n rmail-current-message rmail-total-messages))
700 (rmail-current-message init-msg)
701 (n (or n rmail-total-messages))
702 (msgs-undeled 0))
703 (while (and (> rmail-current-message 0)
704 (< msgs-undeled n))
705 (if (rmail-message-deleted-p rmail-current-message)
706 (progn (rmail-set-attribute "deleted" nil)
707 (setq msgs-undeled (1+ msgs-undeled))))
708 (setq rmail-current-message (1- rmail-current-message)))
709 (set-buffer rmail-summary-buffer)
710 (setq rmail-current-message init-msg msgs-undeled 0)
711 (while (and (> rmail-current-message 0)
712 (< msgs-undeled n))
713 (if (rmail-summary-deleted-p rmail-current-message)
714 (progn (rmail-summary-mark-undeleted rmail-current-message)
715 (setq msgs-undeled (1+ msgs-undeled))))
716 (setq rmail-current-message (1- rmail-current-message))))
717 (rmail-summary-goto-msg)))
719 ;; Rmail Summary mode is suitable only for specially formatted data.
720 (put 'rmail-summary-mode 'mode-class 'special)
722 (defun rmail-summary-mode ()
723 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
724 As commands are issued in the summary buffer, they are applied to the
725 corresponding mail messages in the rmail buffer.
727 All normal editing commands are turned off.
728 Instead, nearly all the Rmail mode commands are available,
729 though many of them move only among the messages in the summary.
731 These additional commands exist:
733 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
734 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
736 Commands for sorting the summary:
738 \\[rmail-summary-sort-by-date] Sort by date.
739 \\[rmail-summary-sort-by-subject] Sort by subject.
740 \\[rmail-summary-sort-by-author] Sort by author.
741 \\[rmail-summary-sort-by-recipient] Sort by recipient.
742 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
743 \\[rmail-summary-sort-by-lines] Sort by lines.
744 \\[rmail-summary-sort-by-labels] Sort by labels."
745 (interactive)
746 (kill-all-local-variables)
747 (setq major-mode 'rmail-summary-mode)
748 (setq mode-name "RMAIL Summary")
749 (setq truncate-lines t)
750 (setq buffer-read-only t)
751 (set-syntax-table text-mode-syntax-table)
752 (make-local-variable 'rmail-buffer)
753 (make-local-variable 'rmail-view-buffer)
754 (make-local-variable 'rmail-total-messages)
755 (make-local-variable 'rmail-current-message)
756 (setq rmail-current-message nil)
757 (make-local-variable 'rmail-summary-redo)
758 (setq rmail-summary-redo nil)
759 (make-local-variable 'revert-buffer-function)
760 (make-local-variable 'font-lock-defaults)
761 (setq font-lock-defaults '(rmail-summary-font-lock-keywords t))
762 (rmail-summary-enable)
763 (run-mode-hooks 'rmail-summary-mode-hook))
765 ;; Summary features need to be disabled during edit mode.
766 (defun rmail-summary-disable ()
767 (use-local-map text-mode-map)
768 (remove-hook 'post-command-hook 'rmail-summary-rmail-update t)
769 (setq revert-buffer-function nil))
771 (defun rmail-summary-enable ()
772 (use-local-map rmail-summary-mode-map)
773 (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
774 (setq revert-buffer-function 'rmail-update-summary))
776 (defvar rmail-summary-put-back-unseen nil
777 "Used for communicating between calls to `rmail-summary-rmail-update'.
778 If it moves to a message within an Incremental Search, and removes
779 the `unseen' attribute from that message, it sets this flag
780 so that if the next motion between messages is in the same Incremental
781 Search, the `unseen' attribute is restored.")
783 ;; Show in Rmail the message described by the summary line that point is on,
784 ;; but only if the Rmail buffer is already visible.
785 ;; This is a post-command-hook in summary buffers.
786 (defun rmail-summary-rmail-update ()
787 (let (buffer-read-only)
788 (save-excursion
789 ;; If at end of buffer, pretend we are on the last text line.
790 (if (eobp)
791 (forward-line -1))
792 (beginning-of-line)
793 (skip-chars-forward " ")
794 (let ((msg-num (string-to-number (buffer-substring
795 (point)
796 (progn (skip-chars-forward "0-9")
797 (point))))))
798 ;; Always leave `unseen' removed
799 ;; if we get out of isearch mode.
800 ;; Don't let a subsequent isearch restore that `unseen'.
801 (if (not isearch-mode)
802 (setq rmail-summary-put-back-unseen nil))
804 (or (eq rmail-current-message msg-num)
805 (let ((window (get-buffer-window rmail-view-buffer t))
806 (owin (selected-window)))
807 (if isearch-mode
808 (save-excursion
809 (set-buffer rmail-buffer)
810 ;; If we first saw the previous message in this search,
811 ;; and we have gone to a different message while searching,
812 ;; put back `unseen' on the former one.
813 (if rmail-summary-put-back-unseen
814 (rmail-set-attribute "unseen" t
815 rmail-current-message))
816 ;; Arrange to do that later, for the new current message,
817 ;; if it still has `unseen'.
818 (setq rmail-summary-put-back-unseen
819 (rmail-message-labels-p msg-num ", ?\\(unseen\\),")))
820 (setq rmail-summary-put-back-unseen nil))
822 ;; Go to the desired message.
823 (setq rmail-current-message msg-num)
825 ;; Update the summary to show the message has been seen.
826 (if (= (following-char) ?-)
827 (progn
828 (delete-char 1)
829 (insert " ")))
831 (if window
832 ;; Using save-window-excursion would cause the new value
833 ;; of point to get lost.
834 (unwind-protect
835 (progn
836 (select-window window)
837 (rmail-show-message msg-num t))
838 (select-window owin))
839 (if (buffer-name rmail-buffer)
840 (save-excursion
841 (set-buffer rmail-buffer)
842 (rmail-show-message msg-num t))))))
843 (rmail-summary-update-highlight nil)))))
845 (defvar rmail-summary-mode-map nil)
847 (if rmail-summary-mode-map
849 (setq rmail-summary-mode-map (make-keymap))
850 (suppress-keymap rmail-summary-mode-map)
852 (define-key rmail-summary-mode-map [mouse-2] 'rmail-summary-mouse-goto-message)
853 (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label)
854 (define-key rmail-summary-mode-map "b" 'rmail-summary-bury)
855 (define-key rmail-summary-mode-map "c" 'rmail-summary-continue)
856 (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward)
857 (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward)
858 (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message)
859 (define-key rmail-summary-mode-map "f" 'rmail-summary-forward)
860 (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail)
861 (define-key rmail-summary-mode-map "h" 'rmail-summary)
862 (define-key rmail-summary-mode-map "i" 'rmail-summary-input)
863 (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg)
864 (define-key rmail-summary-mode-map "\C-m" 'rmail-summary-goto-msg)
865 (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label)
866 (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels)
867 (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
868 (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
869 (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
870 (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
871 (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
872 (define-key rmail-summary-mode-map "m" 'rmail-summary-mail)
873 (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure)
874 (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg)
875 (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all)
876 (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
877 (define-key rmail-summary-mode-map "o" 'rmail-summary-output-to-rmail-file)
878 (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output)
879 (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg)
880 (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all)
881 (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
882 (define-key rmail-summary-mode-map "q" 'rmail-summary-quit)
883 (define-key rmail-summary-mode-map "Q" 'rmail-summary-wipe)
884 (define-key rmail-summary-mode-map "r" 'rmail-summary-reply)
885 (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save)
886 (define-key rmail-summary-mode-map "\es" 'rmail-summary-search)
887 (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header)
888 (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete)
889 (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many)
890 (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge)
891 (define-key rmail-summary-mode-map "w" 'rmail-summary-output-body)
892 (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message)
893 (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message)
894 (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message)
895 (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up)
896 (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down)
897 (define-key rmail-summary-mode-map "?" 'describe-mode)
898 (define-key rmail-summary-mode-map "\C-c\C-n" 'rmail-summary-next-same-subject)
899 (define-key rmail-summary-mode-map "\C-c\C-p" 'rmail-summary-previous-same-subject)
900 (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
901 'rmail-summary-sort-by-date)
902 (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
903 'rmail-summary-sort-by-subject)
904 (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
905 'rmail-summary-sort-by-author)
906 (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
907 'rmail-summary-sort-by-recipient)
908 (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
909 'rmail-summary-sort-by-correspondent)
910 (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
911 'rmail-summary-sort-by-lines)
912 (define-key rmail-summary-mode-map "\C-c\C-s\C-k"
913 'rmail-summary-sort-by-labels)
916 ;;; Menu bar bindings.
918 (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
920 (define-key rmail-summary-mode-map [menu-bar classify]
921 (cons "Classify" (make-sparse-keymap "Classify")))
923 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
924 '("Output (Rmail Menu)..." . rmail-summary-output-menu))
926 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
927 '("Input Rmail File (menu)..." . rmail-input-menu))
929 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
930 '(nil))
932 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
933 '(nil))
935 (define-key rmail-summary-mode-map [menu-bar classify output-body]
936 '("Output (body)..." . rmail-summary-output-body))
938 (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
939 '("Output (inbox)..." . rmail-summary-output))
941 (define-key rmail-summary-mode-map [menu-bar classify output]
942 '("Output (Rmail)..." . rmail-summary-output-to-rmail-file))
944 (define-key rmail-summary-mode-map [menu-bar classify kill-label]
945 '("Kill Label..." . rmail-summary-kill-label))
947 (define-key rmail-summary-mode-map [menu-bar classify add-label]
948 '("Add Label..." . rmail-summary-add-label))
950 (define-key rmail-summary-mode-map [menu-bar summary]
951 (cons "Summary" (make-sparse-keymap "Summary")))
953 (define-key rmail-summary-mode-map [menu-bar summary senders]
954 '("By Senders..." . rmail-summary-by-senders))
956 (define-key rmail-summary-mode-map [menu-bar summary labels]
957 '("By Labels..." . rmail-summary-by-labels))
959 (define-key rmail-summary-mode-map [menu-bar summary recipients]
960 '("By Recipients..." . rmail-summary-by-recipients))
962 (define-key rmail-summary-mode-map [menu-bar summary topic]
963 '("By Topic..." . rmail-summary-by-topic))
965 (define-key rmail-summary-mode-map [menu-bar summary regexp]
966 '("By Regexp..." . rmail-summary-by-regexp))
968 (define-key rmail-summary-mode-map [menu-bar summary all]
969 '("All" . rmail-summary))
971 (define-key rmail-summary-mode-map [menu-bar mail]
972 (cons "Mail" (make-sparse-keymap "Mail")))
974 (define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail]
975 '("Get New Mail" . rmail-summary-get-new-mail))
977 (define-key rmail-summary-mode-map [menu-bar mail lambda]
978 '("----"))
980 (define-key rmail-summary-mode-map [menu-bar mail continue]
981 '("Continue" . rmail-summary-continue))
983 (define-key rmail-summary-mode-map [menu-bar mail resend]
984 '("Re-send..." . rmail-summary-resend))
986 (define-key rmail-summary-mode-map [menu-bar mail forward]
987 '("Forward" . rmail-summary-forward))
989 (define-key rmail-summary-mode-map [menu-bar mail retry]
990 '("Retry" . rmail-summary-retry-failure))
992 (define-key rmail-summary-mode-map [menu-bar mail reply]
993 '("Reply" . rmail-summary-reply))
995 (define-key rmail-summary-mode-map [menu-bar mail mail]
996 '("Mail" . rmail-summary-mail))
998 (define-key rmail-summary-mode-map [menu-bar delete]
999 (cons "Delete" (make-sparse-keymap "Delete")))
1001 (define-key rmail-summary-mode-map [menu-bar delete expunge/save]
1002 '("Expunge/Save" . rmail-summary-expunge-and-save))
1004 (define-key rmail-summary-mode-map [menu-bar delete expunge]
1005 '("Expunge" . rmail-summary-expunge))
1007 (define-key rmail-summary-mode-map [menu-bar delete undelete]
1008 '("Undelete" . rmail-summary-undelete))
1010 (define-key rmail-summary-mode-map [menu-bar delete delete]
1011 '("Delete" . rmail-summary-delete-forward))
1013 (define-key rmail-summary-mode-map [menu-bar move]
1014 (cons "Move" (make-sparse-keymap "Move")))
1016 (define-key rmail-summary-mode-map [menu-bar move search-back]
1017 '("Search Back..." . rmail-summary-search-backward))
1019 (define-key rmail-summary-mode-map [menu-bar move search]
1020 '("Search..." . rmail-summary-search))
1022 (define-key rmail-summary-mode-map [menu-bar move previous]
1023 '("Previous Nondeleted" . rmail-summary-previous-msg))
1025 (define-key rmail-summary-mode-map [menu-bar move next]
1026 '("Next Nondeleted" . rmail-summary-next-msg))
1028 (define-key rmail-summary-mode-map [menu-bar move last]
1029 '("Last" . rmail-summary-last-message))
1031 (define-key rmail-summary-mode-map [menu-bar move first]
1032 '("First" . rmail-summary-first-message))
1034 (define-key rmail-summary-mode-map [menu-bar move previous]
1035 '("Previous" . rmail-summary-previous-all))
1037 (define-key rmail-summary-mode-map [menu-bar move next]
1038 '("Next" . rmail-summary-next-all))
1040 (defvar rmail-summary-overlay nil)
1041 (put 'rmail-summary-overlay 'permanent-local t)
1043 (defun rmail-summary-mouse-goto-message (event)
1044 "Select the message whose summary line you click on."
1045 (interactive "@e")
1046 (goto-char (posn-point (event-end event)))
1047 (rmail-summary-goto-msg))
1049 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
1050 "Go to message N in the summary buffer and the Rmail buffer.
1051 If N is nil, use the message corresponding to point in the summary
1052 and move to that message in the Rmail buffer.
1054 If NOWARN, don't say anything if N is out of range.
1055 If SKIP-RMAIL, don't do anything to the Rmail buffer."
1056 (interactive "P")
1057 (if (consp n) (setq n (prefix-numeric-value n)))
1058 (if (eobp) (forward-line -1))
1059 (beginning-of-line)
1060 (let* ((obuf (current-buffer))
1061 (buf rmail-buffer)
1062 (cur (point))
1063 message-not-found
1064 (curmsg (string-to-number
1065 (buffer-substring (point)
1066 (min (point-max) (+ 6 (point))))))
1067 (total (save-excursion (set-buffer buf) rmail-total-messages)))
1068 ;; If message number N was specified, find that message's line
1069 ;; or set message-not-found.
1070 ;; If N wasn't specified or that message can't be found.
1071 ;; set N by default.
1072 (if (not n)
1073 (setq n curmsg)
1074 (if (< n 1)
1075 (progn (message "No preceding message")
1076 (setq n 1)))
1077 (if (and (> n total)
1078 (> total 0))
1079 (progn (message "No following message")
1080 (goto-char (point-max))
1081 (rmail-summary-goto-msg nil nowarn skip-rmail)))
1082 (goto-char (point-min))
1083 (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t))
1084 (progn (or nowarn (message "Message %d not found" n))
1085 (setq n curmsg)
1086 (setq message-not-found t)
1087 (goto-char cur))))
1088 (beginning-of-line)
1089 (skip-chars-forward " ")
1090 (skip-chars-forward "0-9")
1091 (save-excursion (if (= (following-char) ?-)
1092 (let ((buffer-read-only nil))
1093 (delete-char 1)
1094 (insert " "))))
1095 (rmail-summary-update-highlight message-not-found)
1096 (beginning-of-line)
1097 (if skip-rmail
1099 (let ((selwin (selected-window)))
1100 (unwind-protect
1101 (progn (pop-to-buffer buf)
1102 (rmail-show-message n))
1103 (select-window selwin)
1104 ;; The actions above can alter the current buffer. Preserve it.
1105 (set-buffer obuf))))))
1107 ;; Update the highlighted line in an rmail summary buffer.
1108 ;; That should be current. We highlight the line point is on.
1109 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1110 (defun rmail-summary-update-highlight (not-found)
1111 ;; Make sure we have an overlay to use.
1112 (or rmail-summary-overlay
1113 (progn
1114 (make-local-variable 'rmail-summary-overlay)
1115 (setq rmail-summary-overlay (make-overlay (point) (point)))))
1116 ;; If this message is in the summary, use the overlay to highlight it.
1117 ;; Otherwise, don't highlight anything.
1118 (if not-found
1119 (overlay-put rmail-summary-overlay 'face nil)
1120 (move-overlay rmail-summary-overlay
1121 (save-excursion (beginning-of-line)
1122 (skip-chars-forward " ")
1123 (point))
1124 (save-excursion (end-of-line) (point)))
1125 (overlay-put rmail-summary-overlay 'face 'highlight)))
1127 (defun rmail-summary-scroll-msg-up (&optional dist)
1128 "Scroll the Rmail window forward.
1129 If the Rmail window is displaying the end of a message,
1130 advance to the next message."
1131 (interactive "P")
1132 (if (eq dist '-)
1133 (rmail-summary-scroll-msg-down nil)
1134 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer)))
1135 (if rmail-buffer-window
1136 (if (let ((rmail-summary-window (selected-window)))
1137 (select-window rmail-buffer-window)
1138 (prog1
1139 ;; Is EOB visible in the buffer?
1140 (save-excursion
1141 (let ((ht (window-height (selected-window))))
1142 (move-to-window-line (- ht 2))
1143 (end-of-line)
1144 (eobp)))
1145 (select-window rmail-summary-window)))
1146 (if (not rmail-summary-scroll-between-messages)
1147 (error "End of buffer")
1148 (rmail-summary-next-msg (or dist 1)))
1149 (let ((other-window-scroll-buffer rmail-view-buffer))
1150 (scroll-other-window dist)))
1151 ;; If it isn't visible at all, show the beginning.
1152 (rmail-summary-beginning-of-message)))))
1154 (defun rmail-summary-scroll-msg-down (&optional dist)
1155 "Scroll the Rmail window backward.
1156 If the Rmail window is now displaying the beginning of a message,
1157 move to the previous message."
1158 (interactive "P")
1159 (if (eq dist '-)
1160 (rmail-summary-scroll-msg-up nil)
1161 (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer)))
1162 (if rmail-buffer-window
1163 (if (let ((rmail-summary-window (selected-window)))
1164 (select-window rmail-buffer-window)
1165 (prog1
1166 ;; Is BOB visible in the buffer?
1167 (save-excursion
1168 (move-to-window-line 0)
1169 (beginning-of-line)
1170 (bobp))
1171 (select-window rmail-summary-window)))
1172 (if (not rmail-summary-scroll-between-messages)
1173 (error "Beginning of buffer")
1174 (rmail-summary-previous-msg (or dist 1)))
1175 (let ((other-window-scroll-buffer rmail-view-buffer))
1176 (scroll-other-window-down dist)))
1177 ;; If it isn't visible at all, show the beginning.
1178 (rmail-summary-beginning-of-message)))))
1180 (defun rmail-summary-beginning-of-message ()
1181 "Show current message from the beginning."
1182 (interactive)
1183 (if (and (one-window-p) (not pop-up-frames))
1184 ;; If there is just one window, put the summary on the top.
1185 (let ((buffer rmail-view-buffer))
1186 (split-window (selected-window) rmail-summary-window-size)
1187 (select-window (frame-first-window))
1188 (pop-to-buffer rmail-view-buffer)
1189 ;; If pop-to-buffer did not use that window, delete that
1190 ;; window. (This can happen if it uses another frame.)
1191 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1192 (delete-other-windows)))
1193 (pop-to-buffer rmail-view-buffer))
1194 (beginning-of-buffer)
1195 (pop-to-buffer rmail-summary-buffer))
1197 (defun rmail-summary-bury ()
1198 "Bury the Rmail buffer and the Rmail summary buffer."
1199 (interactive)
1200 (let ((buffer-to-bury (current-buffer)))
1201 (let (window)
1202 (while (setq window (get-buffer-window rmail-buffer))
1203 (set-window-buffer window (other-buffer rmail-buffer)))
1204 (bury-buffer rmail-buffer))
1205 (switch-to-buffer (other-buffer buffer-to-bury))
1206 (bury-buffer buffer-to-bury)))
1208 (defun rmail-summary-quit ()
1209 "Quit out of Rmail and Rmail summary."
1210 (interactive)
1211 (rmail-summary-wipe)
1212 (rmail-quit))
1214 (defun rmail-summary-wipe ()
1215 "Kill and wipe away Rmail summary, remaining within Rmail."
1216 (interactive)
1217 (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
1218 (let ((local-rmail-buffer rmail-view-buffer))
1219 (kill-buffer (current-buffer))
1220 ;; Delete window if not only one.
1221 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1222 (delete-window))
1223 ;; Switch windows to the rmail buffer, or switch to it in this window.
1224 (pop-to-buffer local-rmail-buffer)))
1226 (defun rmail-summary-expunge ()
1227 "Actually erase all deleted messages and recompute summary headers."
1228 (interactive)
1229 (save-excursion
1230 (set-buffer rmail-buffer)
1231 (when (rmail-expunge-confirmed)
1232 (rmail-only-expunge)))
1233 (rmail-update-summary))
1235 (defun rmail-summary-expunge-and-save ()
1236 "Expunge and save RMAIL file."
1237 (interactive)
1238 (save-excursion
1239 (set-buffer rmail-buffer)
1240 (when (rmail-expunge-confirmed)
1241 (rmail-only-expunge)))
1242 (rmail-update-summary)
1243 (save-excursion
1244 (set-buffer rmail-buffer)
1245 (save-buffer))
1246 (set-buffer-modified-p nil))
1248 (defun rmail-summary-get-new-mail (&optional file-name)
1249 "Get new mail and recompute summary headers.
1251 Optionally you can specify the file to get new mail from. In this case,
1252 the file of new mail is not changed or deleted. Noninteractively, you can
1253 pass the inbox file name as an argument. Interactively, a prefix
1254 argument says to read a file name and use that file as the inbox."
1255 (interactive
1256 (list (if current-prefix-arg
1257 (read-file-name "Get new mail from file: "))))
1258 (let (msg)
1259 (save-excursion
1260 (set-buffer rmail-buffer)
1261 (rmail-get-new-mail file-name)
1262 ;; Get the proper new message number.
1263 (setq msg rmail-current-message))
1264 ;; Make sure that message is displayed.
1265 (or (zerop msg)
1266 (rmail-summary-goto-msg msg))))
1268 (defun rmail-summary-input (filename)
1269 "Run Rmail on file FILENAME."
1270 (interactive "FRun rmail on RMAIL file: ")
1271 ;; We switch windows here, then display the other Rmail file there.
1272 (pop-to-buffer rmail-buffer)
1273 (rmail filename))
1275 (defun rmail-summary-first-message ()
1276 "Show first message in Rmail file from summary buffer."
1277 (interactive)
1278 (beginning-of-buffer))
1280 (defun rmail-summary-last-message ()
1281 "Show last message in Rmail file from summary buffer."
1282 (interactive)
1283 (end-of-buffer)
1284 (forward-line -1))
1286 (defvar rmail-summary-edit-map nil)
1287 (if rmail-summary-edit-map
1289 (setq rmail-summary-edit-map
1290 (nconc (make-sparse-keymap) text-mode-map))
1291 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
1292 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
1294 (defun rmail-summary-edit-current-message ()
1295 "Edit the contents of this message."
1296 (interactive)
1297 (pop-to-buffer rmail-buffer)
1298 (rmail-edit-current-message)
1299 (use-local-map rmail-summary-edit-map))
1301 (defun rmail-summary-cease-edit ()
1302 "Finish editing message, then go back to Rmail summary buffer."
1303 (interactive)
1304 (rmail-cease-edit)
1305 (pop-to-buffer rmail-summary-buffer))
1307 (defun rmail-summary-abort-edit ()
1308 "Abort edit of current message; restore original contents.
1309 Go back to summary buffer."
1310 (interactive)
1311 (rmail-abort-edit)
1312 (pop-to-buffer rmail-summary-buffer))
1314 (defun rmail-summary-search-backward (regexp &optional n)
1315 "Show message containing next match for REGEXP.
1316 Prefix argument gives repeat count; negative argument means search
1317 backwards (through earlier messages).
1318 Interactively, empty argument means use same regexp used last time."
1319 (interactive
1320 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1321 (prompt
1322 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1323 regexp)
1324 (if rmail-search-last-regexp
1325 (setq prompt (concat prompt
1326 "(default "
1327 rmail-search-last-regexp
1328 ") ")))
1329 (setq regexp (read-string prompt))
1330 (cond ((not (equal regexp ""))
1331 (setq rmail-search-last-regexp regexp))
1332 ((not rmail-search-last-regexp)
1333 (error "No previous Rmail search string")))
1334 (list rmail-search-last-regexp
1335 (prefix-numeric-value current-prefix-arg))))
1336 ;; Don't use save-excursion because that prevents point from moving
1337 ;; properly in the summary buffer.
1338 (let ((buffer (current-buffer)))
1339 (unwind-protect
1340 (progn
1341 (set-buffer rmail-buffer)
1342 (rmail-search regexp (- n)))
1343 (set-buffer buffer))))
1345 (defun rmail-summary-search (regexp &optional n)
1346 "Show message containing next match for REGEXP.
1347 Prefix argument gives repeat count; negative argument means search
1348 backwards (through earlier messages).
1349 Interactively, empty argument means use same regexp used last time."
1350 (interactive
1351 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1352 (prompt
1353 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1354 regexp)
1355 (if rmail-search-last-regexp
1356 (setq prompt (concat prompt
1357 "(default "
1358 rmail-search-last-regexp
1359 ") ")))
1360 (setq regexp (read-string prompt))
1361 (cond ((not (equal regexp ""))
1362 (setq rmail-search-last-regexp regexp))
1363 ((not rmail-search-last-regexp)
1364 (error "No previous Rmail search string")))
1365 (list rmail-search-last-regexp
1366 (prefix-numeric-value current-prefix-arg))))
1367 ;; Don't use save-excursion because that prevents point from moving
1368 ;; properly in the summary buffer.
1369 (let ((buffer (current-buffer)))
1370 (unwind-protect
1371 (progn
1372 (set-buffer rmail-buffer)
1373 (rmail-search regexp n))
1374 (set-buffer buffer))))
1376 (defun rmail-summary-toggle-header ()
1377 "Show original message header if pruned header currently shown, or vice versa."
1378 (interactive)
1379 (save-window-excursion
1380 (set-buffer rmail-buffer)
1381 (rmail-toggle-header))
1382 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1383 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1384 (let ((window (get-buffer-window rmail-view-buffer)))
1385 (if window
1386 ;; Using save-window-excursion would lose the new value of point.
1387 (let ((owin (selected-window)))
1388 (unwind-protect
1389 (progn
1390 (select-window window)
1391 (goto-char (point-min)))
1392 (select-window owin))))))
1395 (defun rmail-summary-add-label (label)
1396 "Add LABEL to labels associated with current Rmail message.
1397 Completion is performed over known labels when reading."
1398 (interactive (list (save-excursion
1399 (set-buffer rmail-buffer)
1400 (rmail-read-label "Add label"))))
1401 (save-excursion
1402 (set-buffer rmail-buffer)
1403 (rmail-add-label label)))
1405 (defun rmail-summary-kill-label (label)
1406 "Remove LABEL from labels associated with current Rmail message.
1407 Completion is performed over known labels when reading."
1408 (interactive (list (save-excursion
1409 (set-buffer rmail-buffer)
1410 (rmail-read-label "Kill label"))))
1411 (save-excursion
1412 (set-buffer rmail-buffer)
1413 (rmail-set-label label nil)))
1415 ;;;; *** Rmail Summary Mailing Commands ***
1417 (defun rmail-summary-override-mail-send-and-exit ()
1418 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1419 (use-local-map (copy-keymap (current-local-map)))
1420 (dolist (key (where-is-internal 'mail-send-and-exit))
1421 (define-key (current-local-map) key 'rmail-summary-send-and-exit)))
1423 (defun rmail-summary-mail ()
1424 "Send mail in another window.
1425 While composing the message, use \\[mail-yank-original] to yank the
1426 original message into it."
1427 (interactive)
1428 (let ((window (get-buffer-window rmail-buffer)))
1429 (if window
1430 (select-window window)
1431 (set-buffer rmail-buffer)))
1432 (rmail-start-mail nil nil nil nil nil (current-buffer))
1433 (rmail-summary-override-mail-send-and-exit))
1435 (defun rmail-summary-continue ()
1436 "Continue composing outgoing message previously being composed."
1437 (interactive)
1438 (let ((window (get-buffer-window rmail-buffer)))
1439 (if window
1440 (select-window window)
1441 (set-buffer rmail-buffer)))
1442 (rmail-start-mail t))
1444 (defun rmail-summary-reply (just-sender)
1445 "Reply to the current message.
1446 Normally include CC: to all other recipients of original message;
1447 prefix argument means ignore them. While composing the reply,
1448 use \\[mail-yank-original] to yank the original message into it."
1449 (interactive "P")
1450 (let ((window (get-buffer-window rmail-view-buffer)))
1451 (if window
1452 (select-window window)
1453 (set-buffer rmail-view-buffer)))
1454 (rmail-reply just-sender)
1455 (rmail-summary-override-mail-send-and-exit))
1457 (defun rmail-summary-retry-failure ()
1458 "Edit a mail message which is based on the contents of the current message.
1459 For a message rejected by the mail system, extract the interesting headers and
1460 the body of the original message; otherwise copy the current message."
1461 (interactive)
1462 (let ((window (get-buffer-window rmail-buffer)))
1463 (if window
1464 (select-window window)
1465 (set-buffer rmail-buffer)))
1466 (rmail-retry-failure)
1467 (rmail-summary-override-mail-send-and-exit))
1469 (defun rmail-summary-send-and-exit ()
1470 "Send mail reply and return to summary buffer."
1471 (interactive)
1472 (mail-send-and-exit t))
1474 (defun rmail-summary-forward (resend)
1475 "Forward the current message to another user.
1476 With prefix argument, \"resend\" the message instead of forwarding it;
1477 see the documentation of `rmail-resend'."
1478 (interactive "P")
1479 (save-excursion
1480 (let ((window (get-buffer-window rmail-buffer)))
1481 (if window
1482 (select-window window)
1483 (set-buffer rmail-buffer)))
1484 (rmail-forward resend)
1485 (rmail-summary-override-mail-send-and-exit)))
1487 (defun rmail-summary-resend ()
1488 "Resend current message using `rmail-resend'."
1489 (interactive)
1490 (save-excursion
1491 (let ((window (get-buffer-window rmail-buffer)))
1492 (if window
1493 (select-window window)
1494 (set-buffer rmail-buffer)))
1495 (call-interactively 'rmail-resend)))
1497 ;; Summary output commands.
1499 (defun rmail-summary-output-to-rmail-file (&optional file-name n)
1500 "Append the current message to an Rmail file named FILE-NAME.
1501 If the file does not exist, ask if it should be created.
1502 If file is being visited, the message is appended to the Emacs
1503 buffer visiting that file.
1505 A prefix argument N says to output N consecutive messages
1506 starting with the current one. Deleted messages are skipped and don't count."
1507 (interactive
1508 (progn (require 'rmailout)
1509 (list (rmail-output-read-rmail-file-name)
1510 (prefix-numeric-value current-prefix-arg))))
1511 (let ((i 0) prev-msg)
1512 (while
1513 (and (< i n)
1514 (progn (rmail-summary-goto-msg)
1515 (not (eq prev-msg
1516 (setq prev-msg
1517 (with-current-buffer rmail-buffer
1518 rmail-current-message))))))
1519 (setq i (1+ i))
1520 (with-current-buffer rmail-buffer
1521 (let ((rmail-delete-after-output nil))
1522 (rmail-output-to-rmail-file file-name 1)))
1523 (if rmail-delete-after-output
1524 (rmail-summary-delete-forward nil)
1525 (if (< i n)
1526 (rmail-summary-next-msg 1))))))
1528 (defun rmail-summary-output (&optional file-name n)
1529 "Append this message to Unix mail file named FILE-NAME.
1531 A prefix argument N says to output N consecutive messages
1532 starting with the current one. Deleted messages are skipped and don't count."
1533 (interactive
1534 (progn (require 'rmailout)
1535 (list (rmail-output-read-file-name)
1536 (prefix-numeric-value current-prefix-arg))))
1537 (let ((i 0) prev-msg)
1538 (while
1539 (and (< i n)
1540 (progn (rmail-summary-goto-msg)
1541 (not (eq prev-msg
1542 (setq prev-msg
1543 (with-current-buffer rmail-buffer
1544 rmail-current-message))))))
1545 (setq i (1+ i))
1546 (with-current-buffer rmail-buffer
1547 (let ((rmail-delete-after-output nil))
1548 (rmail-output file-name 1)))
1549 (if rmail-delete-after-output
1550 (rmail-summary-delete-forward nil)
1551 (if (< i n)
1552 (rmail-summary-next-msg 1))))))
1554 (defun rmail-summary-output-menu ()
1555 "Output current message to another Rmail file, chosen with a menu.
1556 Also set the default for subsequent \\[rmail-output-to-rmail-file] commands.
1557 The variables `rmail-secondary-file-directory' and
1558 `rmail-secondary-file-regexp' control which files are offered in the menu."
1559 (interactive)
1560 (save-excursion
1561 (set-buffer rmail-buffer)
1562 (let ((rmail-delete-after-output nil))
1563 (call-interactively 'rmail-output-menu)))
1564 (if rmail-delete-after-output
1565 (rmail-summary-delete-forward nil)))
1567 (defun rmail-summary-construct-io-menu ()
1568 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1569 (if files
1570 (progn
1571 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1572 (cons "Input Rmail File"
1573 (rmail-list-to-menu "Input Rmail File"
1574 files
1575 'rmail-summary-input)))
1576 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1577 (cons "Output Rmail File"
1578 (rmail-list-to-menu "Output Rmail File"
1579 files
1580 'rmail-summary-output-to-rmail-file))))
1581 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1582 '("Input Rmail File" . rmail-disable-menu))
1583 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1584 '("Output Rmail File" . rmail-disable-menu)))))
1586 (defun rmail-summary-output-body (&optional file-name)
1587 "Write this message body to the file FILE-NAME.
1588 FILE-NAME defaults, interactively, from the Subject field of the message."
1589 (interactive)
1590 (save-excursion
1591 (set-buffer rmail-buffer)
1592 (let ((rmail-delete-after-output nil))
1593 (if file-name
1594 (rmail-output-body-to-file file-name)
1595 (call-interactively 'rmail-output-body-to-file))))
1596 (if rmail-delete-after-output
1597 (rmail-summary-delete-forward nil)))
1599 ;; Sorting messages in Rmail Summary buffer.
1601 (defun rmail-summary-sort-by-date (reverse)
1602 "Sort messages of current Rmail summary by date.
1603 If prefix argument REVERSE is non-nil, sort them in reverse order."
1604 (interactive "P")
1605 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1607 (defun rmail-summary-sort-by-subject (reverse)
1608 "Sort messages of current Rmail summary by subject.
1609 If prefix argument REVERSE is non-nil, sort them in reverse order."
1610 (interactive "P")
1611 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1613 (defun rmail-summary-sort-by-author (reverse)
1614 "Sort messages of current Rmail summary by author.
1615 If prefix argument REVERSE is non-nil, sort them in reverse order."
1616 (interactive "P")
1617 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1619 (defun rmail-summary-sort-by-recipient (reverse)
1620 "Sort messages of current Rmail summary by recipient.
1621 If prefix argument REVERSE is non-nil, sort them in reverse order."
1622 (interactive "P")
1623 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1625 (defun rmail-summary-sort-by-correspondent (reverse)
1626 "Sort messages of current Rmail summary by other correspondent.
1627 If prefix argument REVERSE is non-nil, sort them in reverse order."
1628 (interactive "P")
1629 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1631 (defun rmail-summary-sort-by-lines (reverse)
1632 "Sort messages of current Rmail summary by lines of the message.
1633 If prefix argument REVERSE is non-nil, sort them in reverse order."
1634 (interactive "P")
1635 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1637 (defun rmail-summary-sort-by-labels (reverse labels)
1638 "Sort messages of current Rmail summary by labels.
1639 If prefix argument REVERSE is non-nil, sort them in reverse order.
1640 KEYWORDS is a comma-separated list of labels."
1641 (interactive "P\nsSort by labels: ")
1642 (rmail-sort-from-summary
1643 (function (lambda (reverse)
1644 (rmail-sort-by-labels reverse labels)))
1645 reverse))
1647 (defun rmail-sort-from-summary (sortfun reverse)
1648 "Sort Rmail messages from Summary buffer and update it after sorting."
1649 (require 'rmailsort)
1650 (let ((selwin (selected-window)))
1651 (unwind-protect
1652 (progn (pop-to-buffer rmail-buffer)
1653 (funcall sortfun reverse))
1654 (select-window selwin))))
1656 (provide 'rmailsum)
1658 ;;; arch-tag: 556079ee-75c1-47f5-9884-2e0a0bc6c5a1
1659 ;;; rmailsum.el ends here