1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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.
32 ;; For rmail-select-summary.
35 (defcustom rmail-summary-scroll-between-messages t
36 "Non-nil means Rmail summary scroll commands move between messages."
38 :group
'rmail-summary
)
40 (defcustom rmail-summary-line-count-flag t
41 "Non-nil means Rmail summary should show the number of lines in each message."
43 :group
'rmail-summary
)
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.")
53 (defvar rmail-summary-redo nil
54 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
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
)
60 (defvar rmail-summary-mode-map nil
61 "Keymap used in Rmail summary mode.")
63 ;; Entry points for making a summary buffer.
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
)))
72 (defun rmail-summary ()
73 "Display a summary of all messages, one line per message."
75 (rmail-new-summary "All" '(rmail-summary) nil
)
76 (unless (get-buffer-window rmail-buffer
)
77 (rmail-summary-beginning-of-message)))
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
92 (mail-comma-list-regexp labels
)
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")
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
))
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
))
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") "")))))
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
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
))
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
)))
151 (defun rmail-summary-by-topic (subject &optional whole-message
)
152 "Display a summary of all messages with the given SUBJECT.
153 Normally checks the Subject field of headers;
154 but if WHOLE-MESSAGE is non-nil (prefix arg given),
155 look in the whole message.
156 SUBJECT is a string of regexps separated by commas."
158 (let* ((subject (rmail-simplified-subject))
159 (prompt (concat "Topics to summarize by (regexp"
160 (if subject
", default current subject" "")
162 (list (read-string prompt nil nil subject
) current-prefix-arg
)))
164 (concat "about " subject
)
165 (list 'rmail-summary-by-topic subject whole-message
)
166 'rmail-message-subject-p
167 (mail-comma-list-regexp subject
) whole-message
))
169 (defun rmail-message-subject-p (msg subject
&optional whole-message
)
171 (rmail-apply-in-message msg
're-search-forward subject nil t
)
172 (string-match subject
(rmail-simplified-subject msg
))))
175 (defun rmail-summary-by-senders (senders)
176 "Display a summary of all messages with the given SENDERS.
177 SENDERS is a string of names separated by commas."
178 (interactive "sSenders to summarize by: ")
180 (concat "senders " senders
)
181 (list 'rmail-summary-by-senders senders
)
182 'rmail-message-senders-p
183 (mail-comma-list-regexp senders
)))
185 (defun rmail-message-senders-p (msg senders
)
186 (string-match senders
(or (rmail-get-header "From" msg
) "")))
188 ;; General making of a summary buffer.
190 (defvar rmail-summary-symbol-number
0)
192 (defvar rmail-new-summary-line-count
)
194 (defun rmail-new-summary (desc redo func
&rest args
)
195 "Create a summary of selected messages.
196 DESC makes part of the mode line of the summary buffer. REDO is form ...
197 For each message, FUNC is applied to the message number and ARGS...
198 and if the result is non-nil, that message is included.
199 nil for FUNCTION means all messages."
200 (message "Computing summary lines...")
202 (error "No RMAIL buffer found"))
203 (let (mesg was-in-summary
)
204 (if (eq major-mode
'rmail-summary-mode
)
205 (setq was-in-summary t
))
206 (with-current-buffer rmail-buffer
207 (if (zerop (setq mesg rmail-current-message
))
208 (error "No messages to summarize"))
209 (setq rmail-summary-buffer
(rmail-new-summary-1 desc redo func args
)))
210 ;; Now display the summary buffer and go to the right place in it.
211 (unless was-in-summary
212 (if (and (one-window-p)
215 ;; If there is just one window, put the summary on the top.
217 (split-window (selected-window) rmail-summary-window-size
)
218 (select-window (next-window (frame-first-window)))
219 (pop-to-buffer rmail-summary-buffer
)
220 ;; If pop-to-buffer did not use that window, delete that
221 ;; window. (This can happen if it uses another frame.)
222 (if (not (eq rmail-summary-buffer
223 (window-buffer (frame-first-window))))
224 (delete-other-windows)))
225 (pop-to-buffer rmail-summary-buffer
))
226 (set-buffer rmail-buffer
)
227 ;; This is how rmail makes the summary buffer reappear.
228 ;; We do this here to make the window the proper size.
229 (rmail-select-summary nil
)
230 (set-buffer rmail-summary-buffer
))
231 (rmail-summary-goto-msg mesg t t
)
232 (rmail-summary-construct-io-menu)
233 (message "Computing summary lines...done")))
235 (defun rmail-new-summary-1 (description form function args
)
236 "Filter messages to obtain summary lines.
237 DESCRIPTION is added to the mode line.
239 Return the summary buffer by invoking FUNCTION on each message
240 passing the message number and ARGS...
244 The current buffer must be a Rmail buffer either containing a
245 collection of mbox formatted messages or displaying a single
247 (let ((summary-msgs ())
248 (rmail-new-summary-line-count 0)
249 (sumbuf (rmail-get-create-summary-buffer)))
250 ;; Scan the messages, getting their summary strings
251 ;; and putting the list of them in SUMMARY-MSGS.
253 (main-buffer (current-buffer))
254 (total rmail-total-messages
)
255 (inhibit-read-only t
))
257 ;; Go where the mbox text is.
258 (if (rmail-buffers-swapped-p)
259 (set-buffer rmail-view-buffer
))
260 (let ((old-min (point-min-marker))
261 (old-max (point-max-marker)))
263 ;; Can't use save-restriction here; that doesn't work if we
264 ;; plan to modify text outside the original restriction.
267 (goto-char (point-min))
268 (while (>= total msgnum
)
269 ;; Go back to the Rmail buffer so
270 ;; so FUNCTION and rmail-get-summary can see its local vars.
271 (with-current-buffer main-buffer
272 ;; First test whether to include this message.
273 (if (or (null function
)
274 (apply function msgnum args
))
276 (cons (cons msgnum
(rmail-get-summary msgnum
))
278 (setq msgnum
(1+ msgnum
))
279 ;; Provide a periodic User progress message.
280 (if (zerop (% rmail-new-summary-line-count
10))
281 (message "Computing summary lines...%d"
282 rmail-new-summary-line-count
)))
283 (setq summary-msgs
(nreverse summary-msgs
)))
284 (narrow-to-region old-min old-max
)))))
286 ;; Temporarily, while summary buffer is unfinished,
287 ;; we "don't have" a summary.
289 ;; I have not a clue what this clause is doing. If you read this
290 ;; chunk of code and have a clue, then please email that clue to
292 (setq rmail-summary-buffer nil
)
293 (if rmail-enable-mime
294 (with-current-buffer rmail-buffer
295 (setq rmail-summary-buffer nil
)))
298 (let ((rbuf (current-buffer))
299 (total rmail-total-messages
))
301 ;; Set up the summary buffer's contents.
302 (let ((buffer-read-only nil
))
305 (princ (cdr (car summary-msgs
)) sumbuf
)
306 (setq summary-msgs
(cdr summary-msgs
)))
307 (goto-char (point-min)))
308 ;; Set up the rest of its state and local variables.
309 (setq buffer-read-only t
)
311 (make-local-variable 'minor-mode-alist
)
312 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
313 (setq rmail-buffer rbuf
314 rmail-summary-redo form
315 rmail-total-messages total
)))
318 (defun rmail-get-create-summary-buffer ()
319 "Obtain a summary buffer by re-using an existing summary
320 buffer, or by creating a new summary buffer."
321 (if (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
))
323 (generate-new-buffer (concat (buffer-name) "-summary"))))
326 ;; Low levels of generating a summary.
328 (defun rmail-get-summary (msgnum)
329 "Return the summary line for message MSGNUM.
330 The mbox buffer must be current when you call this function
331 even if its text is swapped.
333 If the message has a summary line already, it will be stored in
334 the message as a header and simply returned, otherwise the
335 summary line is created, saved in the message header, cached and
338 The current buffer contains the unrestricted message collection."
339 (let ((line (aref rmail-summary-vector
(1- msgnum
))))
341 ;; Register a summary line for MSGNUM.
342 (setq rmail-new-summary-line-count
(1+ rmail-new-summary-line-count
)
343 line
(rmail-create-summary-line msgnum
))
344 ;; Cache the summary line for use during this Rmail session.
345 (aset rmail-summary-vector
(1- msgnum
) line
))
348 (defcustom rmail-summary-line-decoder
(function identity
)
349 "Function to decode a Rmail summary line.
350 It receives the summary line for one message as a string
351 and should return the decoded string.
353 By default, it is `identity', which returns the string unaltered."
355 :group
'rmail-summary
)
357 (defun rmail-create-summary-line (msgnum)
358 "Return the summary line for message MSGNUM.
359 Obtain the message summary from the header if it is available
360 otherwise create it and store it in the message header.
362 The mbox buffer must be current when you call this function
363 even if its text is swapped."
364 (let ((beg (rmail-msgbeg msgnum
))
365 (end (rmail-msgend msgnum
))
366 (deleted (rmail-message-deleted-p msgnum
))
367 ;; Does not work (swapped?)
368 ;;; (unseen (rmail-message-unseen-p msgnum))
371 ;; Switch to the buffer that has the whole mbox text.
372 (if (rmail-buffers-swapped-p)
373 (set-buffer rmail-view-buffer
))
374 ;; Now we can compute the line count.
375 (if rmail-summary-line-count-flag
376 (setq lines
(count-lines beg end
)))
377 ;; Narrow to the message header.
382 (if (search-forward "\n\n" end t
)
384 (narrow-to-region beg
(point))
385 ;; Replace rmail-message-unseen-p from above.
387 (setq unseen
(and (search-forward
388 (concat rmail-attribute-header
": ") nil t
)
389 (looking-at "......U")))
390 ;; Generate a status line from the message.
391 (rmail-create-summary msgnum deleted unseen lines
))
392 (rmail-error-bad-format msgnum
)))))))
394 ;; FIXME this is now unused.
395 ;; The intention was to display in the summary something like {E}
396 ;; for an edited messaged, similarly for answered, etc.
397 ;; But that conflicts with the previous rmail usage, where
398 ;; any user-defined { labels } occupied this space.
399 ;; So whilst it would be nice to have this information in the summary,
400 ;; it would need to go somewhere else.
401 (defun rmail-get-summary-status ()
402 "Return a coded string wrapped in curly braces denoting the status.
404 The current buffer must already be narrowed to the message headers for
405 the message being processed."
406 (let ((status (mail-fetch-field rmail-attribute-header
))
410 ;; Strip off the read/unread and the deleted attribute which are
411 ;; handled separately.
414 (concat (substring status
0 1) (substring status
2 6))
416 (while (< index
(length status
))
417 (unless (string= "-" (setq char
(substring status index
(1+ index
))))
418 (setq result
(concat result char
)))
419 (setq index
(1+ index
)))
420 (when (> (length result
) 0)
421 (setq result
(concat "{" result
"}")))
424 (autoload 'rmail-make-label
"rmailkwd")
426 (defun rmail-get-summary-labels ()
427 "Return a string wrapped in curly braces with the current message labels.
428 Returns nil if there are no labels. The current buffer must
429 already be narrowed to the message headers for the message being
431 (let ((labels (mail-fetch-field rmail-keyword-header
)))
433 (not (string-equal labels
""))
435 ;; Intern so that rmail-read-label can offer completion.
436 (mapc 'rmail-make-label
(split-string labels
", "))
437 (format "{ %s } " labels
)))))
439 (defun rmail-create-summary (msgnum deleted unseen lines
)
440 "Return the summary line for message MSGNUM.
441 The current buffer should already be narrowed to the header for that message.
442 It could be either buffer, so don't access Rmail local variables.
443 DELETED is t if this message is marked deleted.
444 UNSEEN is t if it is marked unseen.
445 LINES is the number of lines in the message (if we should display that)
447 (goto-char (point-min))
448 (let ((line (rmail-header-summary))
449 (labels (rmail-get-summary-labels))
450 pos status prefix basic-start basic-end linecount-string
)
452 (setq linecount-string
455 ((<= lines
9) (format " [%d]" lines
))
456 ((<= lines
99) (format " [%d]" lines
))
457 ((<= lines
999) (format " [%d]" lines
))
458 ((<= lines
9999) (format " [%dk]" (/ lines
1000)))
459 ((<= lines
99999) (format " [%dk]" (/ lines
1000)))
460 (t (format "[%dk]" (/ lines
1000)))))
466 prefix
(format "%5d%c " msgnum status
)
467 basic-start
(car line
)
468 basic-end
(cadr line
))
469 (funcall rmail-summary-line-decoder
470 (concat prefix basic-start linecount-string
" "
473 ;; FIXME move to rmail.el?
475 (defcustom rmail-user-mail-address-regexp nil
476 "Regexp matching user mail addresses.
477 If non-nil, this variable is used to identify the correspondent
478 when receiving new mail. If it matches the address of the sender,
479 the recipient is taken as correspondent of a mail.
480 If nil \(default value\), your `user-login-name' and `user-mail-address'
481 are used to exclude yourself as correspondent.
483 Usually you don't have to set this variable, except if you collect mails
484 sent by you under different user names.
485 Then it should be a regexp matching your mail addresses.
487 Setting this variable has an effect only before reading a mail."
488 :type
'(choice (const :tag
"None" nil
) regexp
)
489 :group
'rmail-retrieve
492 (defun rmail-header-summary ()
493 "Return a message summary based on the message headers.
494 The value is a list of two strings, the first and second parts of the summary.
496 The current buffer must already be narrowed to the message headers for
497 the message being processed."
498 (goto-char (point-min))
500 (concat (save-excursion
501 (if (not (re-search-forward "^Date:" nil t
))
503 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
504 (line-end-position) t
)
506 (string-to-number (buffer-substring
510 (match-beginning 4) (match-end 4))))
511 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
512 (line-end-position) t
)
514 (string-to-number (buffer-substring
518 (match-beginning 2) (match-end 2))))
519 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
520 (line-end-position) t
)
523 (match-beginning 2) (match-end 2))
525 (match-beginning 3) (match-end 3))
527 (match-beginning 4) (match-end 4))))
531 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
532 (mail-strip-quoted-names
535 ;; Get all the lines of the From field
536 ;; so that we get a whole comment if there is one,
537 ;; so that mail-strip-quoted-names can discard it.
538 (let ((opoint (point)))
539 (while (progn (forward-line 1)
540 (looking-at "[ \t]")))
541 ;; Back up over newline, then trailing spaces or tabs
543 (skip-chars-backward " \t")
548 (or rmail-user-mail-address-regexp
550 (regexp-quote (user-login-name))
553 ;; Don't lose if run from init file
554 ;; where user-mail-address is not
556 (or user-mail-address
557 (concat (user-login-name) "@"
558 (or mail-host-address
562 ;; No From field, or it's this user.
564 (goto-char (point-min))
565 (if (not (re-search-forward "^To:[ \t]*" nil t
))
569 (mail-strip-quoted-names
573 (skip-chars-backward " \t")
577 (setq len
(length from
))
578 (setq mch
(string-match "[@%]" from
))
580 (if (or (not mch
) (<= len
25))
581 (substring from
(max 0 (- len
25)))
583 (setq lo
(cond ((< (- mch
14) 0) 0)
587 (min len
(+ lo
25)))))))))
588 (concat (if (re-search-forward "^Subject:" nil t
)
589 (progn (skip-chars-forward " \t")
590 (buffer-substring (point)
593 (re-search-forward "[\n][\n]+" nil t
)
594 (buffer-substring (point) (progn (end-of-line) (point))))
597 ;; Simple motion in a summary buffer.
599 (defun rmail-summary-next-all (&optional number
)
601 (forward-line (if number number
1))
602 ;; It doesn't look nice to move forward past the last message line.
603 (and (eobp) (> number
0)
605 (display-buffer rmail-buffer
))
607 (defun rmail-summary-previous-all (&optional number
)
609 (forward-line (- (if number number
1)))
610 ;; It doesn't look nice to move forward past the last message line.
611 (and (eobp) (< number
0)
613 (display-buffer rmail-buffer
))
615 (defun rmail-summary-next-msg (&optional number
)
616 "Display next non-deleted msg from rmail file.
617 With optional prefix argument NUMBER, moves forward this number of non-deleted
618 messages, or backward if NUMBER is negative."
621 (and (> number
0) (end-of-line))
622 (let ((count (if (< number
0) (- number
) number
))
623 (search (if (> number
0) 're-search-forward
're-search-backward
))
624 (non-del-msg-found nil
))
625 (while (and (> count
0) (setq non-del-msg-found
626 (or (funcall search
"^.....[^D]" nil t
)
628 (setq count
(1- count
))))
630 (display-buffer rmail-buffer
))
632 (defun rmail-summary-previous-msg (&optional number
)
633 "Display previous non-deleted msg from rmail file.
634 With optional prefix argument NUMBER, moves backward this number of
635 non-deleted messages."
637 (rmail-summary-next-msg (- (if number number
1))))
639 (defun rmail-summary-next-labeled-message (n labels
)
640 "Show next message with LABELS. Defaults to last labels used.
641 With prefix argument N moves forward N messages with these labels."
642 (interactive "p\nsMove to next msg with labels: ")
645 (set-buffer rmail-buffer
)
646 (rmail-next-labeled-message n labels
)
647 (setq msg rmail-current-message
))
648 (rmail-summary-goto-msg msg
)))
650 (defun rmail-summary-previous-labeled-message (n labels
)
651 "Show previous message with LABELS. Defaults to last labels used.
652 With prefix argument N moves backward N messages with these labels."
653 (interactive "p\nsMove to previous msg with labels: ")
656 (set-buffer rmail-buffer
)
657 (rmail-previous-labeled-message n labels
)
658 (setq msg rmail-current-message
))
659 (rmail-summary-goto-msg msg
)))
661 (defun rmail-summary-next-same-subject (n)
662 "Go to the next message in the summary having the same subject.
663 With prefix argument N, do this N times.
664 If N is negative, go backwards."
666 (let ((forward (> n
0))
668 (with-current-buffer rmail-buffer
669 (setq subject
(rmail-simplified-subject)
670 i rmail-current-message
))
677 (while (and (not done
)
681 ;; Advance thru summary.
682 (forward-line (if forward
1 -
1))
683 ;; Get msg number of this line.
684 (setq i
(string-to-number
685 (buffer-substring (point)
686 (min (point-max) (+ 6 (point))))))
687 (setq done
(string-equal subject
(rmail-simplified-subject i
))))
688 (if done
(setq found i
)))
689 (setq n
(if forward
(1- n
) (1+ n
)))))
691 (rmail-summary-goto-msg found
)
692 (error "No %s message with same subject"
693 (if forward
"following" "previous")))))
695 (defun rmail-summary-previous-same-subject (n)
696 "Go to the previous message in the summary having the same subject.
697 With prefix argument N, do this N times.
698 If N is negative, go forwards instead."
700 (rmail-summary-next-same-subject (- n
)))
702 ;; Delete and undelete summary commands.
704 (defun rmail-summary-delete-forward (&optional count
)
705 "Delete this message and move to next nondeleted one.
706 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
707 A prefix argument serves as a repeat count;
708 a negative argument means to delete and move backward."
710 (unless (numberp count
) (setq count
1))
712 (backward (< count
0)))
714 (rmail-summary-goto-msg)
715 (with-current-buffer rmail-buffer
716 (rmail-delete-message)
717 (setq del-msg rmail-current-message
))
718 (rmail-summary-mark-deleted del-msg
)
719 (while (and (not (if backward
(bobp) (eobp)))
720 (save-excursion (beginning-of-line)
721 (looking-at " *[0-9]+D")))
722 (forward-line (if backward -
1 1)))
723 ;; It looks ugly to move to the empty line at end of buffer.
724 (and (eobp) (not backward
)
727 (if (> count
0) (1- count
) (1+ count
))))))
729 (defun rmail-summary-delete-backward (&optional count
)
730 "Delete this message and move to previous nondeleted one.
731 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
732 A prefix argument serves as a repeat count;
733 a negative argument means to delete and move forward."
735 (rmail-summary-delete-forward (- count
)))
737 (defun rmail-summary-mark-deleted (&optional n undel
)
738 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
739 (and n
(rmail-summary-goto-msg n t t
))
741 (not (overlay-get rmail-summary-overlay
'face
))
742 (let ((buffer-read-only nil
))
743 (skip-chars-forward " ")
744 (skip-chars-forward "0-9")
747 (progn (delete-char 1) (insert " ")))
750 ;; Register a new summary line.
751 (with-current-buffer rmail-buffer
752 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))))
755 (defun rmail-summary-update-line (n)
756 "Update the summary line for message N."
757 (when (rmail-summary-goto-msg n t t
)
758 (let* ((buffer-read-only nil
)
759 (start (line-beginning-position))
760 (end (line-beginning-position 2))
761 (overlays (overlays-in start end
))
763 (while (and (setq ov
(car overlays
))
764 (not (setq high
(overlay-get ov
'rmail-summary
))))
765 (setq overlays
(cdr overlays
)))
766 (delete-region start end
)
768 (with-current-buffer rmail-buffer
769 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))
773 (rmail-summary-update-highlight nil
)))))
775 (defun rmail-summary-mark-undeleted (n)
776 (rmail-summary-mark-deleted n t
))
778 (defun rmail-summary-deleted-p (&optional n
)
780 (and n
(rmail-summary-goto-msg n nil t
))
781 (skip-chars-forward " ")
782 (skip-chars-forward "0-9")
785 (defun rmail-summary-undelete (&optional arg
)
786 "Undelete current message.
787 Optional prefix ARG means undelete ARG previous messages."
790 (rmail-summary-undelete-many arg
)
791 (let ((buffer-read-only nil
)
794 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
795 (replace-match "\\1 ")
796 (rmail-summary-goto-msg)
797 (if rmail-enable-mime
798 (set-buffer rmail-buffer
)
799 (pop-to-buffer rmail-buffer
))
800 (and (rmail-message-deleted-p rmail-current-message
)
801 (rmail-undelete-previous-message))
802 (if rmail-enable-mime
803 (pop-to-buffer rmail-buffer
))
804 (pop-to-buffer rmail-summary-buffer
))
805 (t (goto-char opoint
))))))
807 (defun rmail-summary-undelete-many (&optional n
)
808 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
811 (set-buffer rmail-buffer
)
812 (let* ((init-msg (if n rmail-current-message rmail-total-messages
))
813 (rmail-current-message init-msg
)
814 (n (or n rmail-total-messages
))
816 (while (and (> rmail-current-message
0)
818 (if (rmail-message-deleted-p rmail-current-message
)
819 (progn (rmail-set-attribute rmail-deleted-attr-index nil
)
820 (setq msgs-undeled
(1+ msgs-undeled
))))
821 (setq rmail-current-message
(1- rmail-current-message
)))
822 (set-buffer rmail-summary-buffer
)
823 (setq rmail-current-message init-msg msgs-undeled
0)
824 (while (and (> rmail-current-message
0)
826 (if (rmail-summary-deleted-p rmail-current-message
)
827 (progn (rmail-summary-mark-undeleted rmail-current-message
)
828 (setq msgs-undeled
(1+ msgs-undeled
))))
829 (setq rmail-current-message
(1- rmail-current-message
))))
830 (rmail-summary-goto-msg)))
832 ;; Rmail Summary mode is suitable only for specially formatted data.
833 (put 'rmail-summary-mode
'mode-class
'special
)
835 (defun rmail-summary-mode ()
836 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
837 As commands are issued in the summary buffer, they are applied to the
838 corresponding mail messages in the rmail buffer.
840 All normal editing commands are turned off.
841 Instead, nearly all the Rmail mode commands are available,
842 though many of them move only among the messages in the summary.
844 These additional commands exist:
846 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
847 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
849 Commands for sorting the summary:
851 \\[rmail-summary-sort-by-date] Sort by date.
852 \\[rmail-summary-sort-by-subject] Sort by subject.
853 \\[rmail-summary-sort-by-author] Sort by author.
854 \\[rmail-summary-sort-by-recipient] Sort by recipient.
855 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
856 \\[rmail-summary-sort-by-lines] Sort by lines.
857 \\[rmail-summary-sort-by-labels] Sort by labels."
859 (kill-all-local-variables)
860 (setq major-mode
'rmail-summary-mode
)
861 (setq mode-name
"RMAIL Summary")
862 (setq truncate-lines t
)
863 (setq buffer-read-only t
)
864 (set-syntax-table text-mode-syntax-table
)
865 (make-local-variable 'rmail-buffer
)
866 (make-local-variable 'rmail-total-messages
)
867 (make-local-variable 'rmail-current-message
)
868 (setq rmail-current-message nil
)
869 (make-local-variable 'rmail-summary-redo
)
870 (setq rmail-summary-redo nil
)
871 (make-local-variable 'revert-buffer-function
)
872 (make-local-variable 'font-lock-defaults
)
873 (setq font-lock-defaults
'(rmail-summary-font-lock-keywords t
))
874 (rmail-summary-enable)
875 (run-mode-hooks 'rmail-summary-mode-hook
))
877 ;; Summary features need to be disabled during edit mode.
878 (defun rmail-summary-disable ()
879 (use-local-map text-mode-map
)
880 (remove-hook 'post-command-hook
'rmail-summary-rmail-update t
)
881 (setq revert-buffer-function nil
))
883 (defun rmail-summary-enable ()
884 (use-local-map rmail-summary-mode-map
)
885 (add-hook 'post-command-hook
'rmail-summary-rmail-update nil t
)
886 (setq revert-buffer-function
'rmail-update-summary
))
888 (defun rmail-summary-mark-seen (n &optional nomove
)
889 "Remove the unseen mark from the current message, update the summary vector.
890 N is the number of the current message. Optional argument NOMOVE
891 non-nil means we are already at the right column."
895 (skip-chars-forward " ")
896 (skip-chars-forward "0-9"))
897 (when (char-equal (following-char) ?-
)
898 (let ((buffer-read-only nil
))
901 (let ((line (buffer-substring-no-properties (line-beginning-position)
902 (line-beginning-position 2))))
903 (with-current-buffer rmail-buffer
904 (aset rmail-summary-vector
(1- n
) line
))))))
906 (defvar rmail-summary-put-back-unseen nil
907 "Used for communicating between calls to `rmail-summary-rmail-update'.
908 If it moves to a message within an Incremental Search, and removes
909 the `unseen' attribute from that message, it sets this flag
910 so that if the next motion between messages is in the same Incremental
911 Search, the `unseen' attribute is restored.")
913 ;; Show in Rmail the message described by the summary line that point is on,
914 ;; but only if the Rmail buffer is already visible.
915 ;; This is a post-command-hook in summary buffers.
916 (defun rmail-summary-rmail-update ()
917 (let (buffer-read-only)
919 ;; If at end of buffer, pretend we are on the last text line.
923 (skip-chars-forward " ")
924 (let ((msg-num (string-to-number (buffer-substring
926 (progn (skip-chars-forward "0-9")
928 ;; Always leave `unseen' removed
929 ;; if we get out of isearch mode.
930 ;; Don't let a subsequent isearch restore that `unseen'.
931 (if (not isearch-mode
)
932 (setq rmail-summary-put-back-unseen nil
))
934 (or (eq rmail-current-message msg-num
)
935 (let ((window (get-buffer-window rmail-buffer t
))
936 (owin (selected-window)))
939 (set-buffer rmail-buffer
)
940 ;; If we first saw the previous message in this search,
941 ;; and we have gone to a different message while searching,
942 ;; put back `unseen' on the former one.
943 (if rmail-summary-put-back-unseen
944 (rmail-set-attribute rmail-unseen-attr-index t
945 rmail-current-message
))
946 ;; Arrange to do that later, for the new current message,
947 ;; if it still has `unseen'.
948 (setq rmail-summary-put-back-unseen
949 (rmail-message-attr-p msg-num rmail-unseen-attr-index
)))
950 (setq rmail-summary-put-back-unseen nil
))
951 ;; Go to the desired message.
952 (setq rmail-current-message msg-num
)
953 ;; Update the summary to show the message has been seen.
954 (rmail-summary-mark-seen msg-num t
)
956 ;; Using save-window-excursion would cause the new value
957 ;; of point to get lost.
960 (select-window window
)
961 (rmail-show-message msg-num t
))
962 (select-window owin
))
963 (if (buffer-name rmail-buffer
)
965 (set-buffer rmail-buffer
)
966 (rmail-show-message msg-num t
))))))
967 (rmail-summary-update-highlight nil
)))))
969 (defun rmail-summary-save-buffer ()
970 "Save the buffer associated with this RMAIL summary."
972 (save-window-excursion
974 (switch-to-buffer rmail-buffer
)
978 (if rmail-summary-mode-map
980 (setq rmail-summary-mode-map
(make-keymap))
981 (suppress-keymap rmail-summary-mode-map
)
983 (define-key rmail-summary-mode-map
[mouse-2
] 'rmail-summary-mouse-goto-message
)
984 (define-key rmail-summary-mode-map
"a" 'rmail-summary-add-label
)
985 (define-key rmail-summary-mode-map
"b" 'rmail-summary-bury
)
986 (define-key rmail-summary-mode-map
"c" 'rmail-summary-continue
)
987 (define-key rmail-summary-mode-map
"d" 'rmail-summary-delete-forward
)
988 (define-key rmail-summary-mode-map
"\C-d" 'rmail-summary-delete-backward
)
989 (define-key rmail-summary-mode-map
"e" 'rmail-summary-edit-current-message
)
990 (define-key rmail-summary-mode-map
"f" 'rmail-summary-forward
)
991 (define-key rmail-summary-mode-map
"g" 'rmail-summary-get-new-mail
)
992 (define-key rmail-summary-mode-map
"h" 'rmail-summary
)
993 (define-key rmail-summary-mode-map
"i" 'rmail-summary-input
)
994 (define-key rmail-summary-mode-map
"j" 'rmail-summary-goto-msg
)
995 (define-key rmail-summary-mode-map
"\C-m" 'rmail-summary-goto-msg
)
996 (define-key rmail-summary-mode-map
"k" 'rmail-summary-kill-label
)
997 (define-key rmail-summary-mode-map
"l" 'rmail-summary-by-labels
)
998 (define-key rmail-summary-mode-map
"\e\C-h" 'rmail-summary
)
999 (define-key rmail-summary-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
1000 (define-key rmail-summary-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
1001 (define-key rmail-summary-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
1002 (define-key rmail-summary-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
1003 (define-key rmail-summary-mode-map
"m" 'rmail-summary-mail
)
1004 (define-key rmail-summary-mode-map
"\M-m" 'rmail-summary-retry-failure
)
1005 (define-key rmail-summary-mode-map
"n" 'rmail-summary-next-msg
)
1006 (define-key rmail-summary-mode-map
"\en" 'rmail-summary-next-all
)
1007 (define-key rmail-summary-mode-map
"\e\C-n" 'rmail-summary-next-labeled-message
)
1008 (define-key rmail-summary-mode-map
"o" 'rmail-summary-output
)
1009 (define-key rmail-summary-mode-map
"\C-o" 'rmail-summary-output
)
1010 (define-key rmail-summary-mode-map
"p" 'rmail-summary-previous-msg
)
1011 (define-key rmail-summary-mode-map
"\ep" 'rmail-summary-previous-all
)
1012 (define-key rmail-summary-mode-map
"\e\C-p" 'rmail-summary-previous-labeled-message
)
1013 (define-key rmail-summary-mode-map
"q" 'rmail-summary-quit
)
1014 (define-key rmail-summary-mode-map
"Q" 'rmail-summary-wipe
)
1015 (define-key rmail-summary-mode-map
"r" 'rmail-summary-reply
)
1016 (define-key rmail-summary-mode-map
"s" 'rmail-summary-expunge-and-save
)
1017 (define-key rmail-summary-mode-map
"\es" 'rmail-summary-search
)
1018 (define-key rmail-summary-mode-map
"t" 'rmail-summary-toggle-header
)
1019 (define-key rmail-summary-mode-map
"u" 'rmail-summary-undelete
)
1020 (define-key rmail-summary-mode-map
"\M-u" 'rmail-summary-undelete-many
)
1021 (define-key rmail-summary-mode-map
"x" 'rmail-summary-expunge
)
1022 (define-key rmail-summary-mode-map
"w" 'rmail-summary-output-body
)
1023 (define-key rmail-summary-mode-map
"." 'rmail-summary-beginning-of-message
)
1024 (define-key rmail-summary-mode-map
"/" 'rmail-summary-end-of-message
)
1025 (define-key rmail-summary-mode-map
"<" 'rmail-summary-first-message
)
1026 (define-key rmail-summary-mode-map
">" 'rmail-summary-last-message
)
1027 (define-key rmail-summary-mode-map
" " 'rmail-summary-scroll-msg-up
)
1028 (define-key rmail-summary-mode-map
"\177" 'rmail-summary-scroll-msg-down
)
1029 (define-key rmail-summary-mode-map
"?" 'describe-mode
)
1030 (define-key rmail-summary-mode-map
"\C-c\C-n" 'rmail-summary-next-same-subject
)
1031 (define-key rmail-summary-mode-map
"\C-c\C-p" 'rmail-summary-previous-same-subject
)
1032 (define-key rmail-summary-mode-map
"\C-c\C-s\C-d"
1033 'rmail-summary-sort-by-date
)
1034 (define-key rmail-summary-mode-map
"\C-c\C-s\C-s"
1035 'rmail-summary-sort-by-subject
)
1036 (define-key rmail-summary-mode-map
"\C-c\C-s\C-a"
1037 'rmail-summary-sort-by-author
)
1038 (define-key rmail-summary-mode-map
"\C-c\C-s\C-r"
1039 'rmail-summary-sort-by-recipient
)
1040 (define-key rmail-summary-mode-map
"\C-c\C-s\C-c"
1041 'rmail-summary-sort-by-correspondent
)
1042 (define-key rmail-summary-mode-map
"\C-c\C-s\C-l"
1043 'rmail-summary-sort-by-lines
)
1044 (define-key rmail-summary-mode-map
"\C-c\C-s\C-k"
1045 'rmail-summary-sort-by-labels
)
1046 (define-key rmail-summary-mode-map
"\C-x\C-s" 'rmail-summary-save-buffer
)
1049 ;;; Menu bar bindings.
1051 (define-key rmail-summary-mode-map
[menu-bar
] (make-sparse-keymap))
1053 (define-key rmail-summary-mode-map
[menu-bar classify
]
1054 (cons "Classify" (make-sparse-keymap "Classify")))
1056 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1057 '("Output (Rmail Menu)..." . rmail-summary-output-menu
))
1059 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1060 '("Input Rmail File (menu)..." . rmail-input-menu
))
1062 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1065 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1068 (define-key rmail-summary-mode-map
[menu-bar classify output-body
]
1069 '("Output (body)..." . rmail-summary-output-body
))
1071 (define-key rmail-summary-mode-map
[menu-bar classify output-inbox
]
1072 '("Output (inbox)..." . rmail-summary-output
))
1074 (define-key rmail-summary-mode-map
[menu-bar classify output
]
1075 '("Output (Rmail)..." . rmail-summary-output
))
1077 (define-key rmail-summary-mode-map
[menu-bar classify kill-label
]
1078 '("Kill Label..." . rmail-summary-kill-label
))
1080 (define-key rmail-summary-mode-map
[menu-bar classify add-label
]
1081 '("Add Label..." . rmail-summary-add-label
))
1083 (define-key rmail-summary-mode-map
[menu-bar summary
]
1084 (cons "Summary" (make-sparse-keymap "Summary")))
1086 (define-key rmail-summary-mode-map
[menu-bar summary senders
]
1087 '("By Senders..." . rmail-summary-by-senders
))
1089 (define-key rmail-summary-mode-map
[menu-bar summary labels
]
1090 '("By Labels..." . rmail-summary-by-labels
))
1092 (define-key rmail-summary-mode-map
[menu-bar summary recipients
]
1093 '("By Recipients..." . rmail-summary-by-recipients
))
1095 (define-key rmail-summary-mode-map
[menu-bar summary topic
]
1096 '("By Topic..." . rmail-summary-by-topic
))
1098 (define-key rmail-summary-mode-map
[menu-bar summary regexp
]
1099 '("By Regexp..." . rmail-summary-by-regexp
))
1101 (define-key rmail-summary-mode-map
[menu-bar summary all
]
1102 '("All" . rmail-summary
))
1104 (define-key rmail-summary-mode-map
[menu-bar mail
]
1105 (cons "Mail" (make-sparse-keymap "Mail")))
1107 (define-key rmail-summary-mode-map
[menu-bar mail rmail-summary-get-new-mail
]
1108 '("Get New Mail" . rmail-summary-get-new-mail
))
1110 (define-key rmail-summary-mode-map
[menu-bar mail lambda
]
1113 (define-key rmail-summary-mode-map
[menu-bar mail continue
]
1114 '("Continue" . rmail-summary-continue
))
1116 (define-key rmail-summary-mode-map
[menu-bar mail resend
]
1117 '("Re-send..." . rmail-summary-resend
))
1119 (define-key rmail-summary-mode-map
[menu-bar mail forward
]
1120 '("Forward" . rmail-summary-forward
))
1122 (define-key rmail-summary-mode-map
[menu-bar mail retry
]
1123 '("Retry" . rmail-summary-retry-failure
))
1125 (define-key rmail-summary-mode-map
[menu-bar mail reply
]
1126 '("Reply" . rmail-summary-reply
))
1128 (define-key rmail-summary-mode-map
[menu-bar mail mail
]
1129 '("Mail" . rmail-summary-mail
))
1131 (define-key rmail-summary-mode-map
[menu-bar delete
]
1132 (cons "Delete" (make-sparse-keymap "Delete")))
1134 (define-key rmail-summary-mode-map
[menu-bar delete expunge
/save
]
1135 '("Expunge/Save" . rmail-summary-expunge-and-save
))
1137 (define-key rmail-summary-mode-map
[menu-bar delete expunge
]
1138 '("Expunge" . rmail-summary-expunge
))
1140 (define-key rmail-summary-mode-map
[menu-bar delete undelete
]
1141 '("Undelete" . rmail-summary-undelete
))
1143 (define-key rmail-summary-mode-map
[menu-bar delete delete
]
1144 '("Delete" . rmail-summary-delete-forward
))
1146 (define-key rmail-summary-mode-map
[menu-bar move
]
1147 (cons "Move" (make-sparse-keymap "Move")))
1149 (define-key rmail-summary-mode-map
[menu-bar move search-back
]
1150 '("Search Back..." . rmail-summary-search-backward
))
1152 (define-key rmail-summary-mode-map
[menu-bar move search
]
1153 '("Search..." . rmail-summary-search
))
1155 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1156 '("Previous Nondeleted" . rmail-summary-previous-msg
))
1158 (define-key rmail-summary-mode-map
[menu-bar move next
]
1159 '("Next Nondeleted" . rmail-summary-next-msg
))
1161 (define-key rmail-summary-mode-map
[menu-bar move last
]
1162 '("Last" . rmail-summary-last-message
))
1164 (define-key rmail-summary-mode-map
[menu-bar move first
]
1165 '("First" . rmail-summary-first-message
))
1167 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1168 '("Previous" . rmail-summary-previous-all
))
1170 (define-key rmail-summary-mode-map
[menu-bar move next
]
1171 '("Next" . rmail-summary-next-all
))
1173 (defun rmail-summary-mouse-goto-message (event)
1174 "Select the message whose summary line you click on."
1176 (goto-char (posn-point (event-end event
)))
1177 (rmail-summary-goto-msg))
1179 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail
)
1180 "Go to message N in the summary buffer and the Rmail buffer.
1181 If N is nil, use the message corresponding to point in the summary
1182 and move to that message in the Rmail buffer.
1184 If NOWARN, don't say anything if N is out of range.
1185 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1186 Returns non-nil if message N was found."
1188 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1189 (if (eobp) (forward-line -
1))
1191 (let* ((obuf (current-buffer))
1195 (curmsg (string-to-number
1196 (buffer-substring (point)
1197 (min (point-max) (+ 6 (point))))))
1198 (total (save-excursion (set-buffer buf
) rmail-total-messages
)))
1199 ;; If message number N was specified, find that message's line
1200 ;; or set message-not-found.
1201 ;; If N wasn't specified or that message can't be found.
1202 ;; set N by default.
1206 (progn (message "No preceding message")
1208 (if (and (> n total
)
1210 (progn (message "No following message")
1211 (goto-char (point-max))
1212 (rmail-summary-goto-msg nil nowarn skip-rmail
)))
1213 (goto-char (point-min))
1214 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1215 (progn (or nowarn
(message "Message %d not found" n
))
1217 (setq message-not-found t
)
1219 (rmail-summary-mark-seen n
)
1220 (rmail-summary-update-highlight message-not-found
)
1223 (let ((selwin (selected-window)))
1225 (progn (pop-to-buffer buf
)
1226 (rmail-show-message n
))
1227 (select-window selwin
)
1228 ;; The actions above can alter the current buffer. Preserve it.
1229 (set-buffer obuf
))))
1230 (not message-not-found
)))
1232 ;; Update the highlighted line in an rmail summary buffer.
1233 ;; That should be current. We highlight the line point is on.
1234 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1235 (defun rmail-summary-update-highlight (not-found)
1236 ;; Make sure we have an overlay to use.
1237 (or rmail-summary-overlay
1239 (make-local-variable 'rmail-summary-overlay
)
1240 (setq rmail-summary-overlay
(make-overlay (point) (point)))
1241 (overlay-put rmail-summary-overlay
'rmail-summary t
)))
1242 ;; If this message is in the summary, use the overlay to highlight it.
1243 ;; Otherwise, don't highlight anything.
1245 (overlay-put rmail-summary-overlay
'face nil
)
1246 (move-overlay rmail-summary-overlay
1247 (save-excursion (beginning-of-line)
1248 (skip-chars-forward " ")
1250 (line-end-position))
1251 (overlay-put rmail-summary-overlay
'face
'highlight
)))
1253 (defun rmail-summary-scroll-msg-up (&optional dist
)
1254 "Scroll the Rmail window forward.
1255 If the Rmail window is displaying the end of a message,
1256 advance to the next message."
1259 (rmail-summary-scroll-msg-down nil
)
1260 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1261 (if rmail-buffer-window
1262 (if (let ((rmail-summary-window (selected-window)))
1263 (select-window rmail-buffer-window
)
1265 ;; Is EOB visible in the buffer?
1267 (let ((ht (window-height (selected-window))))
1268 (move-to-window-line (- ht
2))
1271 (select-window rmail-summary-window
)))
1272 (if (not rmail-summary-scroll-between-messages
)
1273 (error "End of buffer")
1274 (rmail-summary-next-msg (or dist
1)))
1275 (let ((other-window-scroll-buffer rmail-buffer
))
1276 (scroll-other-window dist
)))
1277 ;; If it isn't visible at all, show the beginning.
1278 (rmail-summary-beginning-of-message)))))
1280 (defun rmail-summary-scroll-msg-down (&optional dist
)
1281 "Scroll the Rmail window backward.
1282 If the Rmail window is now displaying the beginning of a message,
1283 move to the previous message."
1286 (rmail-summary-scroll-msg-up nil
)
1287 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1288 (if rmail-buffer-window
1289 (if (let ((rmail-summary-window (selected-window)))
1290 (select-window rmail-buffer-window
)
1292 ;; Is BOB visible in the buffer?
1294 (move-to-window-line 0)
1297 (select-window rmail-summary-window
)))
1298 (if (not rmail-summary-scroll-between-messages
)
1299 (error "Beginning of buffer")
1300 (rmail-summary-previous-msg (or dist
1)))
1301 (let ((other-window-scroll-buffer rmail-buffer
))
1302 (scroll-other-window-down dist
)))
1303 ;; If it isn't visible at all, show the beginning.
1304 (rmail-summary-beginning-of-message)))))
1306 (defun rmail-summary-beginning-of-message ()
1307 "Show current message from the beginning."
1309 (rmail-summary-show-message 'BEG
))
1311 (defun rmail-summary-end-of-message ()
1312 "Show bottom of current message."
1314 (rmail-summary-show-message 'END
))
1316 (defun rmail-summary-show-message (where)
1317 "Show current mail message.
1318 Position it according to WHERE which can be BEG or END"
1319 (if (and (one-window-p) (not pop-up-frames
))
1320 ;; If there is just one window, put the summary on the top.
1321 (let ((buffer rmail-buffer
))
1322 (split-window (selected-window) rmail-summary-window-size
)
1323 (select-window (frame-first-window))
1324 (pop-to-buffer rmail-buffer
)
1325 ;; If pop-to-buffer did not use that window, delete that
1326 ;; window. (This can happen if it uses another frame.)
1327 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1328 (delete-other-windows)))
1329 (pop-to-buffer rmail-buffer
))
1332 (goto-char (point-min))
1333 (search-forward "\n\n"))
1335 (goto-char (point-max))
1336 (recenter (1- (window-height))))
1338 (pop-to-buffer rmail-summary-buffer
))
1340 (defun rmail-summary-bury ()
1341 "Bury the Rmail buffer and the Rmail summary buffer."
1343 (let ((buffer-to-bury (current-buffer)))
1345 (while (setq window
(get-buffer-window rmail-buffer
))
1346 (set-window-buffer window
(other-buffer rmail-buffer
)))
1347 (bury-buffer rmail-buffer
))
1348 (switch-to-buffer (other-buffer buffer-to-bury
))
1349 (bury-buffer buffer-to-bury
)))
1351 (defun rmail-summary-quit ()
1352 "Quit out of Rmail and Rmail summary."
1354 (rmail-summary-wipe)
1357 (defun rmail-summary-wipe ()
1358 "Kill and wipe away Rmail summary, remaining within Rmail."
1360 (save-excursion (set-buffer rmail-buffer
) (setq rmail-summary-buffer nil
))
1361 (let ((local-rmail-buffer rmail-buffer
))
1362 (kill-buffer (current-buffer))
1363 ;; Delete window if not only one.
1364 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1366 ;; Switch windows to the rmail buffer, or switch to it in this window.
1367 (pop-to-buffer local-rmail-buffer
)))
1369 (defun rmail-summary-expunge ()
1370 "Actually erase all deleted messages and recompute summary headers."
1373 (set-buffer rmail-buffer
)
1374 (when (rmail-expunge-confirmed)
1375 (rmail-only-expunge)))
1376 (rmail-update-summary))
1378 (defun rmail-summary-expunge-and-save ()
1379 "Expunge and save RMAIL file."
1382 (rmail-expunge-and-save))
1383 (rmail-update-summary)
1384 (set-buffer-modified-p nil
))
1386 (defun rmail-summary-get-new-mail (&optional file-name
)
1387 "Get new mail and recompute summary headers.
1389 Optionally you can specify the file to get new mail from. In this case,
1390 the file of new mail is not changed or deleted. Noninteractively, you can
1391 pass the inbox file name as an argument. Interactively, a prefix
1392 argument says to read a file name and use that file as the inbox."
1394 (list (if current-prefix-arg
1395 (read-file-name "Get new mail from file: "))))
1398 (set-buffer rmail-buffer
)
1399 (rmail-get-new-mail file-name
)
1400 ;; Get the proper new message number.
1401 (setq msg rmail-current-message
))
1402 ;; Make sure that message is displayed.
1404 (rmail-summary-goto-msg msg
))))
1406 (defun rmail-summary-input (filename)
1407 "Run Rmail on file FILENAME."
1408 (interactive "FRun rmail on RMAIL file: ")
1409 ;; We switch windows here, then display the other Rmail file there.
1410 (pop-to-buffer rmail-buffer
)
1413 (defun rmail-summary-first-message ()
1414 "Show first message in Rmail file from summary buffer."
1417 (beginning-of-buffer)))
1419 (defun rmail-summary-last-message ()
1420 "Show last message in Rmail file from summary buffer."
1426 (declare-function rmail-abort-edit
"rmailedit" ())
1427 (declare-function rmail-cease-edit
"rmailedit"())
1428 (declare-function rmail-set-label
"rmailkwd" (l state
&optional n
))
1429 (declare-function rmail-output-read-file-name
"rmailout" ())
1430 (declare-function mail-send-and-exit
"sendmail" (&optional arg
))
1432 (defvar rmail-summary-edit-map nil
)
1433 (if rmail-summary-edit-map
1435 (setq rmail-summary-edit-map
1436 (nconc (make-sparse-keymap) text-mode-map
))
1437 (define-key rmail-summary-edit-map
"\C-c\C-c" 'rmail-cease-edit
)
1438 (define-key rmail-summary-edit-map
"\C-c\C-]" 'rmail-abort-edit
))
1440 (defun rmail-summary-edit-current-message ()
1441 "Edit the contents of this message."
1443 (pop-to-buffer rmail-buffer
)
1444 (rmail-edit-current-message)
1445 (use-local-map rmail-summary-edit-map
))
1447 (defun rmail-summary-cease-edit ()
1448 "Finish editing message, then go back to Rmail summary buffer."
1451 (pop-to-buffer rmail-summary-buffer
))
1453 (defun rmail-summary-abort-edit ()
1454 "Abort edit of current message; restore original contents.
1455 Go back to summary buffer."
1458 (pop-to-buffer rmail-summary-buffer
))
1460 (defun rmail-summary-search-backward (regexp &optional n
)
1461 "Show message containing next match for REGEXP.
1462 Prefix argument gives repeat count; negative argument means search
1463 backwards (through earlier messages).
1464 Interactively, empty argument means use same regexp used last time."
1466 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1468 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1472 (if rmail-search-last-regexp
1473 (concat ", default "
1474 rmail-search-last-regexp
"): ")
1476 (setq regexp
(read-string prompt
))
1477 (cond ((not (equal regexp
""))
1478 (setq rmail-search-last-regexp regexp
))
1479 ((not rmail-search-last-regexp
)
1480 (error "No previous Rmail search string")))
1481 (list rmail-search-last-regexp
1482 (prefix-numeric-value current-prefix-arg
))))
1483 ;; Don't use save-excursion because that prevents point from moving
1484 ;; properly in the summary buffer.
1485 (let ((buffer (current-buffer)))
1488 (set-buffer rmail-buffer
)
1489 (rmail-search regexp
(- n
)))
1490 (set-buffer buffer
))))
1492 (defun rmail-summary-search (regexp &optional n
)
1493 "Show message containing next match for REGEXP.
1494 Prefix argument gives repeat count; negative argument means search
1495 backwards (through earlier messages).
1496 Interactively, empty argument means use same regexp used last time."
1498 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1500 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1504 (if rmail-search-last-regexp
1505 (concat ", default "
1506 rmail-search-last-regexp
"): ")
1508 (setq regexp
(read-string prompt
))
1509 (cond ((not (equal regexp
""))
1510 (setq rmail-search-last-regexp regexp
))
1511 ((not rmail-search-last-regexp
)
1512 (error "No previous Rmail search string")))
1513 (list rmail-search-last-regexp
1514 (prefix-numeric-value current-prefix-arg
))))
1515 ;; Don't use save-excursion because that prevents point from moving
1516 ;; properly in the summary buffer.
1517 (let ((buffer (current-buffer)))
1520 (set-buffer rmail-buffer
)
1521 (rmail-search regexp n
))
1522 (set-buffer buffer
))))
1524 (defun rmail-summary-toggle-header ()
1525 "Show original message header if pruned header currently shown, or vice versa."
1527 (save-window-excursion
1528 (set-buffer rmail-buffer
)
1529 (rmail-toggle-header))
1530 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1531 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1532 (let ((window (get-buffer-window rmail-buffer
)))
1534 ;; Using save-window-excursion would lose the new value of point.
1535 (let ((owin (selected-window)))
1538 (select-window window
)
1539 (goto-char (point-min)))
1540 (select-window owin
))))))
1543 (defun rmail-summary-add-label (label)
1544 "Add LABEL to labels associated with current Rmail message.
1545 Completion is performed over known labels when reading."
1546 (interactive (list (save-excursion
1547 (set-buffer rmail-buffer
)
1548 (rmail-read-label "Add label"))))
1550 (set-buffer rmail-buffer
)
1551 (rmail-add-label label
)))
1553 (defun rmail-summary-kill-label (label)
1554 "Remove LABEL from labels associated with current Rmail message.
1555 Completion is performed over known labels when reading."
1556 (interactive (list (save-excursion
1557 (set-buffer rmail-buffer
)
1558 (rmail-read-label "Kill label"))))
1560 (set-buffer rmail-buffer
)
1561 (rmail-set-label label nil
)))
1563 ;;;; *** Rmail Summary Mailing Commands ***
1565 (defun rmail-summary-override-mail-send-and-exit ()
1566 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1567 (use-local-map (copy-keymap (current-local-map)))
1568 (dolist (key (where-is-internal 'mail-send-and-exit
))
1569 (define-key (current-local-map) key
'rmail-summary-send-and-exit
)))
1571 (defun rmail-summary-mail ()
1572 "Send mail in another window.
1573 While composing the message, use \\[mail-yank-original] to yank the
1574 original message into it."
1576 (let ((window (get-buffer-window rmail-buffer
)))
1578 (select-window window
)
1579 (set-buffer rmail-buffer
)))
1580 (rmail-start-mail nil nil nil nil nil
(current-buffer))
1581 (rmail-summary-override-mail-send-and-exit))
1583 (defun rmail-summary-continue ()
1584 "Continue composing outgoing message previously being composed."
1586 (let ((window (get-buffer-window rmail-buffer
)))
1588 (select-window window
)
1589 (set-buffer rmail-buffer
)))
1590 (rmail-start-mail t
))
1592 (defun rmail-summary-reply (just-sender)
1593 "Reply to the current message.
1594 Normally include CC: to all other recipients of original message;
1595 prefix argument means ignore them. While composing the reply,
1596 use \\[mail-yank-original] to yank the original message into it."
1598 (let ((window (get-buffer-window rmail-buffer
)))
1600 (select-window window
)
1601 (set-buffer rmail-buffer
)))
1602 (rmail-reply just-sender
)
1603 (rmail-summary-override-mail-send-and-exit))
1605 (defun rmail-summary-retry-failure ()
1606 "Edit a mail message which is based on the contents of the current message.
1607 For a message rejected by the mail system, extract the interesting headers and
1608 the body of the original message; otherwise copy the current message."
1610 (let ((window (get-buffer-window rmail-buffer
)))
1612 (select-window window
)
1613 (set-buffer rmail-buffer
)))
1614 (rmail-retry-failure)
1615 (rmail-summary-override-mail-send-and-exit))
1617 (defun rmail-summary-send-and-exit ()
1618 "Send mail reply and return to summary buffer."
1620 (mail-send-and-exit t
))
1622 (defun rmail-summary-forward (resend)
1623 "Forward the current message to another user.
1624 With prefix argument, \"resend\" the message instead of forwarding it;
1625 see the documentation of `rmail-resend'."
1628 (let ((window (get-buffer-window rmail-buffer
)))
1630 (select-window window
)
1631 (set-buffer rmail-buffer
)))
1632 (rmail-forward resend
)
1633 (rmail-summary-override-mail-send-and-exit)))
1635 (defun rmail-summary-resend ()
1636 "Resend current message using `rmail-resend'."
1639 (let ((window (get-buffer-window rmail-buffer
)))
1641 (select-window window
)
1642 (set-buffer rmail-buffer
)))
1643 (call-interactively 'rmail-resend
)))
1645 ;; Summary output commands.
1647 (defun rmail-summary-output (&optional file-name n
)
1648 "Append this message to mail file FILE-NAME.
1649 This works with both mbox format and Babyl format files,
1650 outputting in the appropriate format for each.
1651 The default file name comes from `rmail-default-file',
1652 which is updated to the name you use in this command.
1654 A prefix argument N says to output that many consecutive messages
1655 from those in the summary, starting with the current one.
1656 Deleted messages are skipped and don't count.
1657 When called from Lisp code, N may be omitted and defaults to 1.
1659 This command always outputs the complete message header,
1660 even the header display is currently pruned."
1662 (progn (require 'rmailout
)
1663 (list (rmail-output-read-file-name)
1664 (prefix-numeric-value current-prefix-arg
))))
1665 (let ((i 0) prev-msg
)
1668 (progn (rmail-summary-goto-msg)
1671 (with-current-buffer rmail-buffer
1672 rmail-current-message
))))))
1674 (with-current-buffer rmail-buffer
1675 (let ((rmail-delete-after-output nil
))
1676 (rmail-output file-name
1)))
1677 (if rmail-delete-after-output
1678 (rmail-summary-delete-forward nil
)
1680 (rmail-summary-next-msg 1))))))
1682 (defalias 'rmail-summary-output-to-rmail-file
'rmail-summary-output
)
1684 (declare-function rmail-output-as-seen
"rmailout"
1685 (file-name &optional count noattribute from-gnus
))
1687 (defun rmail-summary-output-as-seen (&optional file-name n
)
1688 "Append this message to mbox file named FILE-NAME.
1689 A prefix argument N says to output that many consecutive messages,
1690 from the summary, starting with the current one.
1691 Deleted messages are skipped and don't count.
1692 When called from Lisp code, N may be omitted and defaults to 1.
1694 This outputs the message header as you see it (or would see it)
1697 The default file name comes from `rmail-default-file',
1698 which is updated to the name you use in this command."
1700 (progn (require 'rmailout
)
1701 (list (rmail-output-read-file-name)
1702 (prefix-numeric-value current-prefix-arg
))))
1703 (require 'rmailout
) ; for rmail-output-as-seen in non-interactive case
1704 (let ((i 0) prev-msg
)
1707 (progn (rmail-summary-goto-msg)
1710 (with-current-buffer rmail-buffer
1711 rmail-current-message
))))))
1713 (with-current-buffer rmail-buffer
1714 (let ((rmail-delete-after-output nil
))
1715 (rmail-output-as-seen file-name
1)))
1716 (if rmail-delete-after-output
1717 (rmail-summary-delete-forward nil
)
1719 (rmail-summary-next-msg 1))))))
1721 (defun rmail-summary-output-menu ()
1722 "Output current message to another Rmail file, chosen with a menu.
1723 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1724 The variables `rmail-secondary-file-directory' and
1725 `rmail-secondary-file-regexp' control which files are offered in the menu."
1728 (set-buffer rmail-buffer
)
1729 (let ((rmail-delete-after-output nil
))
1730 (call-interactively 'rmail-output-menu
)))
1731 (if rmail-delete-after-output
1732 (rmail-summary-delete-forward nil
)))
1734 (defun rmail-summary-construct-io-menu ()
1735 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1738 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1739 (cons "Input Rmail File"
1740 (rmail-list-to-menu "Input Rmail File"
1742 'rmail-summary-input
)))
1743 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1744 (cons "Output Rmail File"
1745 (rmail-list-to-menu "Output Rmail File"
1747 'rmail-summary-output
))))
1748 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1749 '("Input Rmail File" . rmail-disable-menu
))
1750 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1751 '("Output Rmail File" . rmail-disable-menu
)))))
1753 (defun rmail-summary-output-body (&optional file-name
)
1754 "Write this message body to the file FILE-NAME.
1755 FILE-NAME defaults, interactively, from the Subject field of the message."
1758 (set-buffer rmail-buffer
)
1759 (let ((rmail-delete-after-output nil
))
1761 (rmail-output-body-to-file file-name
)
1762 (call-interactively 'rmail-output-body-to-file
))))
1763 (if rmail-delete-after-output
1764 (rmail-summary-delete-forward nil
)))
1766 ;; Sorting messages in Rmail Summary buffer.
1768 (defun rmail-summary-sort-by-date (reverse)
1769 "Sort messages of current Rmail summary by date.
1770 If prefix argument REVERSE is non-nil, sort them in reverse order."
1772 (rmail-sort-from-summary (function rmail-sort-by-date
) reverse
))
1774 (defun rmail-summary-sort-by-subject (reverse)
1775 "Sort messages of current Rmail summary by subject.
1776 If prefix argument REVERSE is non-nil, sort them in reverse order."
1778 (rmail-sort-from-summary (function rmail-sort-by-subject
) reverse
))
1780 (defun rmail-summary-sort-by-author (reverse)
1781 "Sort messages of current Rmail summary by author.
1782 If prefix argument REVERSE is non-nil, sort them in reverse order."
1784 (rmail-sort-from-summary (function rmail-sort-by-author
) reverse
))
1786 (defun rmail-summary-sort-by-recipient (reverse)
1787 "Sort messages of current Rmail summary by recipient.
1788 If prefix argument REVERSE is non-nil, sort them in reverse order."
1790 (rmail-sort-from-summary (function rmail-sort-by-recipient
) reverse
))
1792 (defun rmail-summary-sort-by-correspondent (reverse)
1793 "Sort messages of current Rmail summary by other correspondent.
1794 If prefix argument REVERSE is non-nil, sort them in reverse order."
1796 (rmail-sort-from-summary (function rmail-sort-by-correspondent
) reverse
))
1798 (defun rmail-summary-sort-by-lines (reverse)
1799 "Sort messages of current Rmail summary by lines of the message.
1800 If prefix argument REVERSE is non-nil, sort them in reverse order."
1802 (rmail-sort-from-summary (function rmail-sort-by-lines
) reverse
))
1804 (defun rmail-summary-sort-by-labels (reverse labels
)
1805 "Sort messages of current Rmail summary by labels.
1806 If prefix argument REVERSE is non-nil, sort them in reverse order.
1807 KEYWORDS is a comma-separated list of labels."
1808 (interactive "P\nsSort by labels: ")
1809 (rmail-sort-from-summary
1810 (function (lambda (reverse)
1811 (rmail-sort-by-labels reverse labels
)))
1814 (defun rmail-sort-from-summary (sortfun reverse
)
1815 "Sort Rmail messages from Summary buffer and update it after sorting."
1816 (require 'rmailsort
)
1817 (let ((selwin (selected-window)))
1819 (progn (pop-to-buffer rmail-buffer
)
1820 (funcall sortfun reverse
))
1821 (select-window selwin
))))
1825 ;; arch-tag: 80b0a27a-a50d-4f37-9466-83d32d1e0ca8
1826 ;;; rmailsum.el ends here