1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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.
36 (defcustom rmail-summary-scroll-between-messages t
37 "Non-nil means Rmail summary scroll commands move between messages.
38 That is, after `rmail-summary-scroll-msg-up' reaches the end of a
39 message, it moves to the next message; and similarly for
40 `rmail-summary-scroll-msg-down'."
42 :group
'rmail-summary
)
44 ;; FIXME could do with a :set function that regenerates the summary
45 ;; and updates rmail-summary-vector.
46 (defcustom rmail-summary-line-count-flag t
47 "Non-nil means Rmail summary should show the number of lines in each message.
48 Setting this option to nil might speed up the generation of summaries."
50 :group
'rmail-summary
)
52 (defvar rmail-summary-font-lock-keywords
53 '(("^.....D.*" . font-lock-string-face
) ; Deleted.
54 ("^.....-.*" . font-lock-type-face
) ; Unread.
55 ;; Neither of the below will be highlighted if either of the above are:
56 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face
) ; Date.
57 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face
)) ; Labels.
58 "Additional expressions to highlight in Rmail Summary mode.")
60 (defvar rmail-summary-redo nil
61 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
63 (defvar rmail-summary-overlay nil
64 "Overlay used to highlight the current message in the Rmail summary.")
65 (put 'rmail-summary-overlay
'permanent-local t
)
67 (defvar rmail-summary-mode-map nil
68 "Keymap used in Rmail summary mode.")
70 ;; Entry points for making a summary buffer.
72 ;; Regenerate the contents of the summary
73 ;; using the same selection criterion as last time.
74 ;; M-x revert-buffer in a summary buffer calls this function.
75 (defun rmail-update-summary (&rest ignore
)
76 (apply (car rmail-summary-redo
) (cdr rmail-summary-redo
)))
79 (defun rmail-summary ()
80 "Display a summary of all messages, one line per message."
82 (rmail-new-summary "All" '(rmail-summary) nil
)
83 (unless (get-buffer-window rmail-buffer
)
84 (rmail-summary-beginning-of-message)))
87 (defun rmail-summary-by-labels (labels)
88 "Display a summary of all messages with one or more LABELS.
89 LABELS should be a string containing the desired labels, separated by commas."
90 (interactive "sLabels to summarize by: ")
91 (if (string= labels
"")
92 (setq labels
(or rmail-last-multi-labels
93 (error "No label specified"))))
94 (setq rmail-last-multi-labels labels
)
95 (rmail-new-summary (concat "labels " labels
)
96 (list 'rmail-summary-by-labels labels
)
97 'rmail-message-labels-p
99 (mail-comma-list-regexp labels
)
100 "\\)\\(,\\|\\'\\)")))
102 ;; FIXME "a string of regexps separated by commas" makes no sense because:
103 ;; i) it's pointless (you can just use \\|)
104 ;; ii) it's broken (you can't specify a literal comma)
105 ;; rmail-summary-by-topic and rmail-summary-by-senders have the same issue.
107 (defun rmail-summary-by-recipients (recipients &optional primary-only
)
108 "Display a summary of all messages with the given RECIPIENTS.
109 Normally checks the To, From and Cc fields of headers;
110 but if PRIMARY-ONLY is non-nil (prefix arg given),
111 only look in the To and From fields.
112 RECIPIENTS is a string of regexps separated by commas."
113 (interactive "sRecipients to summarize by: \nP")
115 (concat "recipients " recipients
)
116 (list 'rmail-summary-by-recipients recipients primary-only
)
117 'rmail-message-recipients-p
118 (mail-comma-list-regexp recipients
) primary-only
))
120 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
121 (rmail-apply-in-message msg
'rmail-message-recipients-p-1
122 recipients primary-only
))
124 (defun rmail-message-recipients-p-1 (recipients &optional primary-only
)
125 ;; mail-fetch-field does not care where it starts from.
126 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
127 (or (string-match recipients
(or (mail-fetch-field "To") ""))
128 (string-match recipients
(or (mail-fetch-field "From") ""))
129 (if (not primary-only
)
130 (string-match recipients
(or (mail-fetch-field "Cc") "")))))
132 ;; FIXME I find this a non-obvious name for what this function does.
133 ;; Also, the optional WHOLE-MESSAGE argument of r-s-by-topic would
134 ;; seem more natural here.
136 (defun rmail-summary-by-regexp (regexp)
137 "Display a summary of all messages according to regexp REGEXP.
138 If the regular expression is found in the header of the message
139 \(including in the date and other lines, as well as the subject line),
140 Emacs will list the message in the summary."
141 (interactive "sRegexp to summarize by: ")
142 (if (string= regexp
"")
143 (setq regexp
(or rmail-last-regexp
144 (error "No regexp specified"))))
145 (setq rmail-last-regexp regexp
)
146 (rmail-new-summary (concat "regexp " regexp
)
147 (list 'rmail-summary-by-regexp regexp
)
148 'rmail-message-regexp-p
151 (defun rmail-message-regexp-p (msg regexp
)
152 "Return t, if for message number MSG, regexp REGEXP matches in the header."
153 (rmail-apply-in-message msg
'rmail-message-regexp-p-1 msg regexp
))
155 (defun rmail-message-regexp-p-1 (msg regexp
)
156 ;; Search functions can expect to start from the beginning.
157 (narrow-to-region (point) (save-excursion (search-forward "\n\n") (point)))
158 (if rmail-enable-mime
159 (if rmail-search-mime-header-function
160 (funcall rmail-search-mime-header-function msg regexp
(point))
161 (error "You must set `rmail-search-mime-header-function'"))
162 (re-search-forward regexp nil t
)))
165 (defun rmail-summary-by-topic (subject &optional whole-message
)
166 "Display a summary of all messages with the given SUBJECT.
167 Normally checks just the Subject field of headers; but with prefix
168 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
169 SUBJECT is a string of regexps separated by commas."
171 ;; We quote the default subject, because if it contains regexp
172 ;; special characters (eg "?"), it can fail to match itself. (Bug#2333)
173 (let* ((subject (regexp-quote (rmail-simplified-subject)))
174 (prompt (concat "Topics to summarize by (regexp"
175 (if subject
", default current subject" "")
177 (list (read-string prompt nil nil subject
) current-prefix-arg
)))
179 (concat "about " subject
)
180 (list 'rmail-summary-by-topic subject whole-message
)
181 'rmail-message-subject-p
182 (mail-comma-list-regexp subject
) whole-message
))
184 (defun rmail-message-subject-p (msg subject
&optional whole-message
)
186 (rmail-apply-in-message msg
're-search-forward subject nil t
)
187 (string-match subject
(rmail-simplified-subject msg
))))
190 (defun rmail-summary-by-senders (senders)
191 "Display a summary of all messages whose \"From\" field matches SENDERS.
192 SENDERS is a string of regexps separated by commas."
193 (interactive "sSenders to summarize by: ")
195 (concat "senders " senders
)
196 (list 'rmail-summary-by-senders senders
)
197 'rmail-message-senders-p
198 (mail-comma-list-regexp senders
)))
200 (defun rmail-message-senders-p (msg senders
)
201 (string-match senders
(or (rmail-get-header "From" msg
) "")))
203 ;; General making of a summary buffer.
205 (defvar rmail-summary-symbol-number
0)
207 (defvar rmail-new-summary-line-count
)
209 (defun rmail-new-summary (desc redo func
&rest args
)
210 "Create a summary of selected messages.
211 DESC makes part of the mode line of the summary buffer. REDO is form ...
212 For each message, FUNC is applied to the message number and ARGS...
213 and if the result is non-nil, that message is included.
214 nil for FUNCTION means all messages."
215 (message "Computing summary lines...")
217 (error "No RMAIL buffer found"))
218 (let (mesg was-in-summary
)
219 (if (eq major-mode
'rmail-summary-mode
)
220 (setq was-in-summary t
))
221 (with-current-buffer rmail-buffer
222 (if (zerop (setq mesg rmail-current-message
))
223 (error "No messages to summarize"))
224 (setq rmail-summary-buffer
(rmail-new-summary-1 desc redo func args
)))
225 ;; Now display the summary buffer and go to the right place in it.
226 (unless was-in-summary
227 (if (and (one-window-p)
230 ;; If there is just one window, put the summary on the top.
232 (split-window (selected-window) rmail-summary-window-size
)
233 (select-window (next-window (frame-first-window)))
234 (rmail-pop-to-buffer rmail-summary-buffer
)
235 ;; If pop-to-buffer did not use that window, delete that
236 ;; window. (This can happen if it uses another frame.)
237 (if (not (eq rmail-summary-buffer
238 (window-buffer (frame-first-window))))
239 (delete-other-windows)))
240 (rmail-pop-to-buffer rmail-summary-buffer
))
241 (set-buffer rmail-buffer
)
242 ;; This is how rmail makes the summary buffer reappear.
243 ;; We do this here to make the window the proper size.
244 (rmail-select-summary nil
)
245 (set-buffer rmail-summary-buffer
))
246 (rmail-summary-goto-msg mesg t t
)
247 (rmail-summary-construct-io-menu)
248 (message "Computing summary lines...done")))
250 (defun rmail-new-summary-1 (description form function args
)
251 "Filter messages to obtain summary lines.
252 DESCRIPTION is added to the mode line.
254 Return the summary buffer by invoking FUNCTION on each message
255 passing the message number and ARGS...
259 The current buffer must be a Rmail buffer either containing a
260 collection of mbox formatted messages or displaying a single
262 (let ((summary-msgs ())
263 (rmail-new-summary-line-count 0)
264 (sumbuf (rmail-get-create-summary-buffer)))
265 ;; Scan the messages, getting their summary strings
266 ;; and putting the list of them in SUMMARY-MSGS.
268 (main-buffer (current-buffer))
269 (total rmail-total-messages
)
270 (inhibit-read-only t
))
272 ;; Go where the mbox text is.
273 (if (rmail-buffers-swapped-p)
274 (set-buffer rmail-view-buffer
))
275 (let ((old-min (point-min-marker))
276 (old-max (point-max-marker)))
278 ;; Can't use save-restriction here; that doesn't work if we
279 ;; plan to modify text outside the original restriction.
282 (goto-char (point-min))
283 (while (>= total msgnum
)
284 ;; Go back to the Rmail buffer so
285 ;; so FUNCTION and rmail-get-summary can see its local vars.
286 (with-current-buffer main-buffer
287 ;; First test whether to include this message.
288 (if (or (null function
)
289 (apply function msgnum args
))
291 (cons (cons msgnum
(rmail-get-summary msgnum
))
293 (setq msgnum
(1+ msgnum
))
294 ;; Provide a periodic User progress message.
295 (if (and (not (zerop rmail-new-summary-line-count
))
296 (zerop (% rmail-new-summary-line-count
10)))
297 (message "Computing summary lines...%d"
298 rmail-new-summary-line-count
)))
299 (setq summary-msgs
(nreverse summary-msgs
)))
300 (narrow-to-region old-min old-max
)))))
301 ;; Temporarily, while summary buffer is unfinished,
302 ;; we "don't have" a summary.
303 (setq rmail-summary-buffer nil
)
306 (error "Nothing to summarize"))
307 ;; I have not a clue what this clause is doing. If you read this
308 ;; chunk of code and have a clue, then please email that clue to
310 (if rmail-enable-mime
311 (with-current-buffer rmail-buffer
312 (setq rmail-summary-buffer nil
)))
314 (let ((rbuf (current-buffer))
315 (total rmail-total-messages
))
317 ;; Set up the summary buffer's contents.
318 (let ((buffer-read-only nil
))
321 (princ (cdr (car summary-msgs
)) sumbuf
)
322 (setq summary-msgs
(cdr summary-msgs
)))
323 (goto-char (point-min)))
324 ;; Set up the rest of its state and local variables.
325 (setq buffer-read-only t
)
327 (make-local-variable 'minor-mode-alist
)
328 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
329 (setq rmail-buffer rbuf
330 rmail-summary-redo form
331 rmail-total-messages total
)))
334 (defun rmail-get-create-summary-buffer ()
335 "Return the Rmail summary buffer.
336 If necessary, it is created and undo is disabled."
337 (if (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
))
339 (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
340 (with-current-buffer buff
341 (setq buffer-undo-list t
))
345 ;; Low levels of generating a summary.
347 (defun rmail-get-summary (msgnum)
348 "Return the summary line for message MSGNUM.
349 The mbox buffer must be current when you call this function
350 even if its text is swapped.
352 If the message has a summary line already, it will be stored in
353 the message as a header and simply returned, otherwise the
354 summary line is created, saved in the message header, cached and
357 The current buffer contains the unrestricted message collection."
358 (let ((line (aref rmail-summary-vector
(1- msgnum
))))
360 ;; Register a summary line for MSGNUM.
361 (setq rmail-new-summary-line-count
(1+ rmail-new-summary-line-count
)
362 line
(rmail-create-summary-line msgnum
))
363 ;; Cache the summary line for use during this Rmail session.
364 (aset rmail-summary-vector
(1- msgnum
) line
))
367 (defcustom rmail-summary-line-decoder
(function rfc2047-decode-string
)
368 "Function to decode a Rmail summary line.
369 It receives the summary line for one message as a string
370 and should return the decoded string.
372 By default, it is `rfc2047-decode-string', which decodes MIME-encoded
376 :group
'rmail-summary
)
378 (defun rmail-create-summary-line (msgnum)
379 "Return the summary line for message MSGNUM.
380 Obtain the message summary from the header if it is available
381 otherwise create it and store it in the message header.
383 The mbox buffer must be current when you call this function
384 even if its text is swapped."
385 (let ((beg (rmail-msgbeg msgnum
))
386 (end (rmail-msgend msgnum
))
387 (deleted (rmail-message-deleted-p msgnum
))
388 ;; Does not work (swapped?)
389 ;;; (unseen (rmail-message-unseen-p msgnum))
392 ;; Switch to the buffer that has the whole mbox text.
393 (if (rmail-buffers-swapped-p)
394 (set-buffer rmail-view-buffer
))
395 ;; Now we can compute the line count.
396 (if rmail-summary-line-count-flag
397 (setq lines
(count-lines beg end
)))
398 ;; Narrow to the message header.
403 (if (search-forward "\n\n" end t
)
405 (narrow-to-region beg
(point))
406 ;; Replace rmail-message-unseen-p from above.
408 (setq unseen
(and (search-forward
409 (concat rmail-attribute-header
": ") nil t
)
410 (looking-at "......U")))
411 ;; Generate a status line from the message.
412 (rmail-create-summary msgnum deleted unseen lines
))
413 (rmail-error-bad-format msgnum
)))))))
415 ;; FIXME this is now unused.
416 ;; The intention was to display in the summary something like {E}
417 ;; for an edited messaged, similarly for answered, etc.
418 ;; But that conflicts with the previous rmail usage, where
419 ;; any user-defined { labels } occupied this space.
420 ;; So whilst it would be nice to have this information in the summary,
421 ;; it would need to go somewhere else.
422 (defun rmail-get-summary-status ()
423 "Return a coded string wrapped in curly braces denoting the status.
425 The current buffer must already be narrowed to the message headers for
426 the message being processed."
427 (let ((status (mail-fetch-field rmail-attribute-header
))
431 ;; Strip off the read/unread and the deleted attribute which are
432 ;; handled separately.
435 (concat (substring status
0 1) (substring status
2 6))
437 (while (< index
(length status
))
438 (unless (string= "-" (setq char
(substring status index
(1+ index
))))
439 (setq result
(concat result char
)))
440 (setq index
(1+ index
)))
441 (when (> (length result
) 0)
442 (setq result
(concat "{" result
"}")))
445 (autoload 'rmail-make-label
"rmailkwd")
447 (defun rmail-get-summary-labels ()
448 "Return a string wrapped in curly braces with the current message labels.
449 Returns nil if there are no labels. The current buffer must
450 already be narrowed to the message headers for the message being
452 (let ((labels (mail-fetch-field rmail-keyword-header
)))
454 (not (string-equal labels
""))
456 ;; Intern so that rmail-read-label can offer completion.
457 (mapc 'rmail-make-label
(split-string labels
", "))
458 (format "{ %s } " labels
)))))
460 (defun rmail-create-summary (msgnum deleted unseen lines
)
461 "Return the summary line for message MSGNUM.
462 The current buffer should already be narrowed to the header for that message.
463 It could be either buffer, so don't access Rmail local variables.
464 DELETED is t if this message is marked deleted.
465 UNSEEN is t if it is marked unseen.
466 LINES is the number of lines in the message (if we should display that)
468 (goto-char (point-min))
469 (let ((line (rmail-header-summary))
470 (labels (rmail-get-summary-labels))
471 pos status prefix basic-start basic-end linecount-string
)
473 (setq linecount-string
476 ((<= lines
9) (format " [%d]" lines
))
477 ((<= lines
99) (format " [%d]" lines
))
478 ((<= lines
999) (format " [%d]" lines
))
479 ((<= lines
9999) (format " [%dk]" (/ lines
1000)))
480 ((<= lines
99999) (format " [%dk]" (/ lines
1000)))
481 (t (format "[%dk]" (/ lines
1000)))))
487 prefix
(format "%5d%c " msgnum status
)
488 basic-start
(car line
)
489 basic-end
(cadr line
))
490 (funcall rmail-summary-line-decoder
491 (concat prefix basic-start linecount-string
" "
494 (defun rmail-header-summary ()
495 "Return a message summary based on the message headers.
496 The value is a list of two strings, the first and second parts of the summary.
498 The current buffer must already be narrowed to the message headers for
499 the message being processed."
500 (goto-char (point-min))
502 (concat (save-excursion
503 (if (not (re-search-forward "^Date:" nil t
))
505 ;; Match month names case-insensitively
506 (cond ((let ((case-fold-search t
))
507 (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
508 (line-end-position) t
))
510 (string-to-number (buffer-substring
514 (match-beginning 4) (match-end 4))))
515 ((let ((case-fold-search t
))
516 (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
517 (line-end-position) t
))
519 (string-to-number (buffer-substring
523 (match-beginning 2) (match-end 2))))
524 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
525 (line-end-position) t
)
528 (match-beginning 2) (match-end 2))
530 (match-beginning 3) (match-end 3))
532 (match-beginning 4) (match-end 4))))
536 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
537 (mail-strip-quoted-names
540 ;; Get all the lines of the From field
541 ;; so that we get a whole comment if there is one,
542 ;; so that mail-strip-quoted-names can discard it.
543 (let ((opoint (point)))
544 (while (progn (forward-line 1)
545 (looking-at "[ \t]")))
546 ;; Back up over newline, then trailing spaces or tabs
548 (skip-chars-backward " \t")
553 (or rmail-user-mail-address-regexp
555 (regexp-quote (user-login-name))
558 ;; Don't lose if run from init file
559 ;; where user-mail-address is not
561 (or user-mail-address
562 (concat (user-login-name) "@"
563 (or mail-host-address
567 ;; No From field, or it's this user.
569 (goto-char (point-min))
570 (if (not (re-search-forward "^To:[ \t]*" nil t
))
574 (mail-strip-quoted-names
578 (skip-chars-backward " \t")
582 (setq len
(length from
))
583 (setq mch
(string-match "[@%]" from
))
585 (if (or (not mch
) (<= len
25))
586 (substring from
(max 0 (- len
25)))
588 (setq lo
(cond ((< (- mch
14) 0) 0)
592 (min len
(+ lo
25)))))))))
593 (concat (if (re-search-forward "^Subject:" nil t
)
595 (skip-chars-forward " \t")
598 (setq str
(buffer-substring pos
(1- (point))))
599 (while (looking-at "\\s ")
600 (setq str
(concat str
" "
601 (buffer-substring (match-end 0)
602 (line-end-position))))
605 (re-search-forward "[\n][\n]+" nil t
)
606 (buffer-substring (point) (progn (end-of-line) (point))))
609 ;; Simple motion in a summary buffer.
611 (defun rmail-summary-next-all (&optional number
)
613 (forward-line (if number number
1))
614 ;; It doesn't look nice to move forward past the last message line.
615 (and (eobp) (> number
0)
617 (display-buffer rmail-buffer
))
619 (defun rmail-summary-previous-all (&optional number
)
621 (forward-line (- (if number number
1)))
622 ;; It doesn't look nice to move forward past the last message line.
623 (and (eobp) (< number
0)
625 (display-buffer rmail-buffer
))
627 (defun rmail-summary-next-msg (&optional number
)
628 "Display next non-deleted msg from rmail file.
629 With optional prefix argument NUMBER, moves forward this number of non-deleted
630 messages, or backward if NUMBER is negative."
633 (and (> number
0) (end-of-line))
634 (let ((count (if (< number
0) (- number
) number
))
635 (search (if (> number
0) 're-search-forward
're-search-backward
))
636 (non-del-msg-found nil
))
637 (while (and (> count
0) (setq non-del-msg-found
638 (or (funcall search
"^.....[^D]" nil t
)
640 (setq count
(1- count
))))
642 (display-buffer rmail-buffer
))
644 (defun rmail-summary-previous-msg (&optional number
)
645 "Display previous non-deleted msg from rmail file.
646 With optional prefix argument NUMBER, moves backward this number of
647 non-deleted messages."
649 (rmail-summary-next-msg (- (if number number
1))))
651 (defun rmail-summary-next-labeled-message (n labels
)
652 "Show next message with LABELS. Defaults to last labels used.
653 With prefix argument N moves forward N messages with these labels."
654 (interactive "p\nsMove to next msg with labels: ")
656 (with-current-buffer rmail-buffer
657 (rmail-next-labeled-message n labels
)
658 (setq msg rmail-current-message
))
659 (rmail-summary-goto-msg msg
)))
661 (defun rmail-summary-previous-labeled-message (n labels
)
662 "Show previous message with LABELS. Defaults to last labels used.
663 With prefix argument N moves backward N messages with these labels."
664 (interactive "p\nsMove to previous msg with labels: ")
666 (with-current-buffer rmail-buffer
667 (rmail-previous-labeled-message n labels
)
668 (setq msg rmail-current-message
))
669 (rmail-summary-goto-msg msg
)))
671 (defun rmail-summary-next-same-subject (n)
672 "Go to the next message in the summary having the same subject.
673 With prefix argument N, do this N times.
674 If N is negative, go backwards."
676 (let ((forward (> n
0))
678 (with-current-buffer rmail-buffer
679 (setq subject
(rmail-simplified-subject)
680 i rmail-current-message
))
687 (while (and (not done
)
691 ;; Advance thru summary.
692 (forward-line (if forward
1 -
1))
693 ;; Get msg number of this line.
694 (setq i
(string-to-number
695 (buffer-substring (point)
696 (min (point-max) (+ 6 (point))))))
697 (setq done
(string-equal subject
(rmail-simplified-subject i
))))
698 (if done
(setq found i
)))
699 (setq n
(if forward
(1- n
) (1+ n
)))))
701 (rmail-summary-goto-msg found
)
702 (error "No %s message with same subject"
703 (if forward
"following" "previous")))))
705 (defun rmail-summary-previous-same-subject (n)
706 "Go to the previous message in the summary having the same subject.
707 With prefix argument N, do this N times.
708 If N is negative, go forwards instead."
710 (rmail-summary-next-same-subject (- n
)))
712 ;; Delete and undelete summary commands.
714 (defun rmail-summary-delete-forward (&optional count
)
715 "Delete this message and move to next nondeleted one.
716 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
717 A prefix argument serves as a repeat count;
718 a negative argument means to delete and move backward."
720 (unless (numberp count
) (setq count
1))
722 (backward (< count
0)))
724 (rmail-summary-goto-msg)
725 (with-current-buffer rmail-buffer
726 (rmail-delete-message)
727 (setq del-msg rmail-current-message
))
728 (rmail-summary-mark-deleted del-msg
)
729 (while (and (not (if backward
(bobp) (eobp)))
730 (save-excursion (beginning-of-line)
731 (looking-at " *[0-9]+D")))
732 (forward-line (if backward -
1 1)))
733 ;; It looks ugly to move to the empty line at end of buffer.
734 (and (eobp) (not backward
)
737 (if (> count
0) (1- count
) (1+ count
))))))
739 (defun rmail-summary-delete-backward (&optional count
)
740 "Delete this message and move to previous nondeleted one.
741 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
742 A prefix argument serves as a repeat count;
743 a negative argument means to delete and move forward."
745 (rmail-summary-delete-forward (- count
)))
747 (defun rmail-summary-mark-deleted (&optional n undel
)
748 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
749 (and n
(rmail-summary-goto-msg n t t
))
751 (not (overlay-get rmail-summary-overlay
'face
))
752 (let ((buffer-read-only nil
))
753 (skip-chars-forward " ")
754 (skip-chars-forward "0-9")
757 (progn (delete-char 1) (insert " ")))
760 ;; Register a new summary line.
761 (with-current-buffer rmail-buffer
762 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))))
765 (defun rmail-summary-update-line (n)
766 "Update the summary line for message N."
767 (when (rmail-summary-goto-msg n t t
)
768 (let* ((buffer-read-only nil
)
769 (start (line-beginning-position))
770 (end (line-beginning-position 2))
771 (overlays (overlays-in start end
))
773 (while (and (setq ov
(car overlays
))
774 (not (setq high
(overlay-get ov
'rmail-summary
))))
775 (setq overlays
(cdr overlays
)))
776 (delete-region start end
)
778 (with-current-buffer rmail-buffer
779 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))
783 (rmail-summary-update-highlight nil
)))))
785 (defun rmail-summary-mark-undeleted (n)
786 (rmail-summary-mark-deleted n t
))
788 (defun rmail-summary-deleted-p (&optional n
)
790 (and n
(rmail-summary-goto-msg n nil t
))
791 (skip-chars-forward " ")
792 (skip-chars-forward "0-9")
795 (defun rmail-summary-undelete (&optional arg
)
796 "Undelete current message.
797 Optional prefix ARG means undelete ARG previous messages."
800 (rmail-summary-undelete-many arg
)
801 (let ((buffer-read-only nil
)
804 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
805 (replace-match "\\1 ")
806 (rmail-summary-goto-msg)
807 (if rmail-enable-mime
808 (set-buffer rmail-buffer
)
809 (rmail-pop-to-buffer rmail-buffer
))
810 (and (rmail-message-deleted-p rmail-current-message
)
811 (rmail-undelete-previous-message))
812 (if rmail-enable-mime
813 (rmail-pop-to-buffer rmail-buffer
))
814 (rmail-pop-to-buffer rmail-summary-buffer
))
815 (t (goto-char opoint
))))))
817 (defun rmail-summary-undelete-many (&optional n
)
818 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
820 (with-current-buffer rmail-buffer
821 (let* ((init-msg (if n rmail-current-message rmail-total-messages
))
822 (rmail-current-message init-msg
)
823 (n (or n rmail-total-messages
))
825 (while (and (> rmail-current-message
0)
827 (if (rmail-message-deleted-p rmail-current-message
)
828 (progn (rmail-set-attribute rmail-deleted-attr-index nil
)
829 (setq msgs-undeled
(1+ msgs-undeled
))))
830 (setq rmail-current-message
(1- rmail-current-message
)))
831 (set-buffer rmail-summary-buffer
)
832 (setq rmail-current-message init-msg msgs-undeled
0)
833 (while (and (> rmail-current-message
0)
835 (if (rmail-summary-deleted-p rmail-current-message
)
836 (progn (rmail-summary-mark-undeleted rmail-current-message
)
837 (setq msgs-undeled
(1+ msgs-undeled
))))
838 (setq rmail-current-message
(1- rmail-current-message
))))
839 (rmail-summary-goto-msg)))
841 ;; Rmail Summary mode is suitable only for specially formatted data.
842 (put 'rmail-summary-mode
'mode-class
'special
)
844 (defun rmail-summary-mode ()
845 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
846 As commands are issued in the summary buffer, they are applied to the
847 corresponding mail messages in the rmail buffer.
849 All normal editing commands are turned off.
850 Instead, nearly all the Rmail mode commands are available,
851 though many of them move only among the messages in the summary.
853 These additional commands exist:
855 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
856 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
858 Commands for sorting the summary:
860 \\[rmail-summary-sort-by-date] Sort by date.
861 \\[rmail-summary-sort-by-subject] Sort by subject.
862 \\[rmail-summary-sort-by-author] Sort by author.
863 \\[rmail-summary-sort-by-recipient] Sort by recipient.
864 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
865 \\[rmail-summary-sort-by-lines] Sort by lines.
866 \\[rmail-summary-sort-by-labels] Sort by labels."
868 (kill-all-local-variables)
869 (setq major-mode
'rmail-summary-mode
)
870 (setq mode-name
"RMAIL Summary")
871 (setq truncate-lines t
)
872 (setq buffer-read-only t
)
873 (set-syntax-table text-mode-syntax-table
)
874 (make-local-variable 'rmail-buffer
)
875 (make-local-variable 'rmail-total-messages
)
876 (make-local-variable 'rmail-current-message
)
877 (setq rmail-current-message nil
)
878 (make-local-variable 'rmail-summary-redo
)
879 (setq rmail-summary-redo nil
)
880 (make-local-variable 'revert-buffer-function
)
881 (make-local-variable 'font-lock-defaults
)
882 (setq font-lock-defaults
'(rmail-summary-font-lock-keywords t
))
883 (rmail-summary-enable)
884 (run-mode-hooks 'rmail-summary-mode-hook
))
886 ;; Summary features need to be disabled during edit mode.
887 (defun rmail-summary-disable ()
888 (use-local-map text-mode-map
)
889 (remove-hook 'post-command-hook
'rmail-summary-rmail-update t
)
890 (setq revert-buffer-function nil
))
892 (defun rmail-summary-enable ()
893 (use-local-map rmail-summary-mode-map
)
894 (add-hook 'post-command-hook
'rmail-summary-rmail-update nil t
)
895 (setq revert-buffer-function
'rmail-update-summary
))
897 (defun rmail-summary-mark-seen (n &optional nomove unseen
)
898 "Remove the unseen mark from the current message, update the summary vector.
899 N is the number of the current message. Optional argument NOMOVE
900 non-nil means we are already at the right column. Optional argument
901 UNSEEN non-nil means mark the message as unseen."
905 (skip-chars-forward " ")
906 (skip-chars-forward "0-9"))
907 (when (char-equal (following-char) (if unseen ?\s ?-
))
908 (let ((buffer-read-only nil
))
910 (insert (if unseen
"-" " ")))
911 (let ((line (buffer-substring-no-properties (line-beginning-position)
912 (line-beginning-position 2))))
913 (with-current-buffer rmail-buffer
914 (aset rmail-summary-vector
(1- n
) line
))))))
916 (defvar rmail-summary-put-back-unseen nil
917 "Used for communicating between calls to `rmail-summary-rmail-update'.
918 If it moves to a message within an Incremental Search, and removes
919 the `unseen' attribute from that message, it sets this flag
920 so that if the next motion between messages is in the same Incremental
921 Search, the `unseen' attribute is restored.")
923 ;; Show in Rmail the message described by the summary line that point is on,
924 ;; but only if the Rmail buffer is already visible.
925 ;; This is a post-command-hook in summary buffers.
926 (defun rmail-summary-rmail-update ()
927 (let (buffer-read-only)
929 ;; If at end of buffer, pretend we are on the last text line.
933 (skip-chars-forward " ")
934 (let ((msg-num (string-to-number (buffer-substring
936 (progn (skip-chars-forward "0-9")
938 ;; Always leave `unseen' removed
939 ;; if we get out of isearch mode.
940 ;; Don't let a subsequent isearch restore that `unseen'.
941 (if (not isearch-mode
)
942 (setq rmail-summary-put-back-unseen nil
))
944 (or (eq rmail-current-message msg-num
)
945 (let ((window (get-buffer-window rmail-buffer t
))
946 (owin (selected-window)))
949 ;; If we first saw the previous message in this search,
950 ;; and we have gone to a different message while searching,
951 ;; put back `unseen' on the former one.
952 (when rmail-summary-put-back-unseen
953 (rmail-set-attribute rmail-unseen-attr-index t
954 rmail-current-message
)
956 (goto-char rmail-summary-put-back-unseen
)
957 (rmail-summary-mark-seen rmail-current-message t t
)))
958 ;; Arrange to do that later, for the new current message,
959 ;; if it still has `unseen'.
960 (setq rmail-summary-put-back-unseen
961 (if (rmail-message-unseen-p msg-num
)
963 (setq rmail-summary-put-back-unseen nil
))
964 ;; Go to the desired message.
965 (setq rmail-current-message msg-num
)
966 ;; Update the summary to show the message has been seen.
967 (rmail-summary-mark-seen msg-num t
)
969 ;; Using save-window-excursion would cause the new value
970 ;; of point to get lost.
973 (select-window window
)
974 (rmail-show-message msg-num t
))
975 (select-window owin
))
976 (if (buffer-name rmail-buffer
)
977 (with-current-buffer rmail-buffer
978 (rmail-show-message msg-num t
))))
979 ;; In linum mode, the message buffer must be specially
980 ;; updated (Bug#4878).
981 (and (fboundp 'linum-update
)
982 (buffer-name rmail-buffer
)
983 (linum-update rmail-buffer
))))
984 (rmail-summary-update-highlight nil
)))))
986 (defun rmail-summary-save-buffer ()
987 "Save the buffer associated with this RMAIL summary."
989 (save-window-excursion
991 (switch-to-buffer rmail-buffer
)
995 (if rmail-summary-mode-map
997 (setq rmail-summary-mode-map
(make-keymap))
998 (suppress-keymap rmail-summary-mode-map
)
1000 (define-key rmail-summary-mode-map
[mouse-2
] 'rmail-summary-mouse-goto-message
)
1001 (define-key rmail-summary-mode-map
"a" 'rmail-summary-add-label
)
1002 (define-key rmail-summary-mode-map
"b" 'rmail-summary-bury
)
1003 (define-key rmail-summary-mode-map
"c" 'rmail-summary-continue
)
1004 (define-key rmail-summary-mode-map
"d" 'rmail-summary-delete-forward
)
1005 (define-key rmail-summary-mode-map
"\C-d" 'rmail-summary-delete-backward
)
1006 (define-key rmail-summary-mode-map
"e" 'rmail-summary-edit-current-message
)
1007 (define-key rmail-summary-mode-map
"f" 'rmail-summary-forward
)
1008 (define-key rmail-summary-mode-map
"g" 'rmail-summary-get-new-mail
)
1009 (define-key rmail-summary-mode-map
"h" 'rmail-summary
)
1010 (define-key rmail-summary-mode-map
"i" 'rmail-summary-input
)
1011 (define-key rmail-summary-mode-map
"j" 'rmail-summary-goto-msg
)
1012 (define-key rmail-summary-mode-map
"\C-m" 'rmail-summary-goto-msg
)
1013 (define-key rmail-summary-mode-map
"k" 'rmail-summary-kill-label
)
1014 (define-key rmail-summary-mode-map
"l" 'rmail-summary-by-labels
)
1015 (define-key rmail-summary-mode-map
"\e\C-h" 'rmail-summary
)
1016 (define-key rmail-summary-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
1017 (define-key rmail-summary-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
1018 (define-key rmail-summary-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
1020 (define-key rmail-summary-mode-map
"\e\C-f" 'rmail-summary-by-senders
)
1021 (define-key rmail-summary-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
1022 (define-key rmail-summary-mode-map
"m" 'rmail-summary-mail
)
1023 (define-key rmail-summary-mode-map
"\M-m" 'rmail-summary-retry-failure
)
1024 (define-key rmail-summary-mode-map
"n" 'rmail-summary-next-msg
)
1025 (define-key rmail-summary-mode-map
"\en" 'rmail-summary-next-all
)
1026 (define-key rmail-summary-mode-map
"\e\C-n" 'rmail-summary-next-labeled-message
)
1027 (define-key rmail-summary-mode-map
"o" 'rmail-summary-output
)
1028 (define-key rmail-summary-mode-map
"\C-o" 'rmail-summary-output-as-seen
)
1029 (define-key rmail-summary-mode-map
"p" 'rmail-summary-previous-msg
)
1030 (define-key rmail-summary-mode-map
"\ep" 'rmail-summary-previous-all
)
1031 (define-key rmail-summary-mode-map
"\e\C-p" 'rmail-summary-previous-labeled-message
)
1032 (define-key rmail-summary-mode-map
"q" 'rmail-summary-quit
)
1033 (define-key rmail-summary-mode-map
"Q" 'rmail-summary-wipe
)
1034 (define-key rmail-summary-mode-map
"r" 'rmail-summary-reply
)
1035 (define-key rmail-summary-mode-map
"s" 'rmail-summary-expunge-and-save
)
1036 ;; See rms's comment in rmail.el
1037 ;;; (define-key rmail-summary-mode-map "\er" 'rmail-summary-search-backward)
1038 (define-key rmail-summary-mode-map
"\es" 'rmail-summary-search
)
1039 (define-key rmail-summary-mode-map
"t" 'rmail-summary-toggle-header
)
1040 (define-key rmail-summary-mode-map
"u" 'rmail-summary-undelete
)
1041 (define-key rmail-summary-mode-map
"\M-u" 'rmail-summary-undelete-many
)
1042 (define-key rmail-summary-mode-map
"x" 'rmail-summary-expunge
)
1043 (define-key rmail-summary-mode-map
"w" 'rmail-summary-output-body
)
1044 (define-key rmail-summary-mode-map
"v" 'rmail-mime
)
1045 (define-key rmail-summary-mode-map
"." 'rmail-summary-beginning-of-message
)
1046 (define-key rmail-summary-mode-map
"/" 'rmail-summary-end-of-message
)
1047 (define-key rmail-summary-mode-map
"<" 'rmail-summary-first-message
)
1048 (define-key rmail-summary-mode-map
">" 'rmail-summary-last-message
)
1049 (define-key rmail-summary-mode-map
" " 'rmail-summary-scroll-msg-up
)
1050 (define-key rmail-summary-mode-map
"\177" 'rmail-summary-scroll-msg-down
)
1051 (define-key rmail-summary-mode-map
"?" 'describe-mode
)
1052 (define-key rmail-summary-mode-map
"\C-c\C-n" 'rmail-summary-next-same-subject
)
1053 (define-key rmail-summary-mode-map
"\C-c\C-p" 'rmail-summary-previous-same-subject
)
1054 (define-key rmail-summary-mode-map
"\C-c\C-s\C-d"
1055 'rmail-summary-sort-by-date
)
1056 (define-key rmail-summary-mode-map
"\C-c\C-s\C-s"
1057 'rmail-summary-sort-by-subject
)
1058 (define-key rmail-summary-mode-map
"\C-c\C-s\C-a"
1059 'rmail-summary-sort-by-author
)
1060 (define-key rmail-summary-mode-map
"\C-c\C-s\C-r"
1061 'rmail-summary-sort-by-recipient
)
1062 (define-key rmail-summary-mode-map
"\C-c\C-s\C-c"
1063 'rmail-summary-sort-by-correspondent
)
1064 (define-key rmail-summary-mode-map
"\C-c\C-s\C-l"
1065 'rmail-summary-sort-by-lines
)
1066 (define-key rmail-summary-mode-map
"\C-c\C-s\C-k"
1067 'rmail-summary-sort-by-labels
)
1068 (define-key rmail-summary-mode-map
"\C-x\C-s" 'rmail-summary-save-buffer
)
1071 ;;; Menu bar bindings.
1073 (define-key rmail-summary-mode-map
[menu-bar
] (make-sparse-keymap))
1075 (define-key rmail-summary-mode-map
[menu-bar classify
]
1076 (cons "Classify" (make-sparse-keymap "Classify")))
1078 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1079 '("Output (Rmail Menu)..." . rmail-summary-output-menu
))
1081 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1082 '("Input Rmail File (menu)..." . rmail-input-menu
))
1084 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1087 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1090 (define-key rmail-summary-mode-map
[menu-bar classify output-body
]
1091 '("Output body..." . rmail-summary-output-body
))
1093 (define-key rmail-summary-mode-map
[menu-bar classify output-inbox
]
1094 '("Output..." . rmail-summary-output
))
1096 (define-key rmail-summary-mode-map
[menu-bar classify output
]
1097 '("Output as seen..." . rmail-summary-output-as-seen
))
1099 (define-key rmail-summary-mode-map
[menu-bar classify kill-label
]
1100 '("Kill Label..." . rmail-summary-kill-label
))
1102 (define-key rmail-summary-mode-map
[menu-bar classify add-label
]
1103 '("Add Label..." . rmail-summary-add-label
))
1105 (define-key rmail-summary-mode-map
[menu-bar summary
]
1106 (cons "Summary" (make-sparse-keymap "Summary")))
1108 (define-key rmail-summary-mode-map
[menu-bar summary senders
]
1109 '("By Senders..." . rmail-summary-by-senders
))
1111 (define-key rmail-summary-mode-map
[menu-bar summary labels
]
1112 '("By Labels..." . rmail-summary-by-labels
))
1114 (define-key rmail-summary-mode-map
[menu-bar summary recipients
]
1115 '("By Recipients..." . rmail-summary-by-recipients
))
1117 (define-key rmail-summary-mode-map
[menu-bar summary topic
]
1118 '("By Topic..." . rmail-summary-by-topic
))
1120 (define-key rmail-summary-mode-map
[menu-bar summary regexp
]
1121 '("By Regexp..." . rmail-summary-by-regexp
))
1123 (define-key rmail-summary-mode-map
[menu-bar summary all
]
1124 '("All" . rmail-summary
))
1126 (define-key rmail-summary-mode-map
[menu-bar mail
]
1127 (cons "Mail" (make-sparse-keymap "Mail")))
1129 (define-key rmail-summary-mode-map
[menu-bar mail rmail-summary-get-new-mail
]
1130 '("Get New Mail" . rmail-summary-get-new-mail
))
1132 (define-key rmail-summary-mode-map
[menu-bar mail lambda
]
1135 (define-key rmail-summary-mode-map
[menu-bar mail continue
]
1136 '("Continue" . rmail-summary-continue
))
1138 (define-key rmail-summary-mode-map
[menu-bar mail resend
]
1139 '("Re-send..." . rmail-summary-resend
))
1141 (define-key rmail-summary-mode-map
[menu-bar mail forward
]
1142 '("Forward" . rmail-summary-forward
))
1144 (define-key rmail-summary-mode-map
[menu-bar mail retry
]
1145 '("Retry" . rmail-summary-retry-failure
))
1147 (define-key rmail-summary-mode-map
[menu-bar mail reply
]
1148 '("Reply" . rmail-summary-reply
))
1150 (define-key rmail-summary-mode-map
[menu-bar mail mail
]
1151 '("Mail" . rmail-summary-mail
))
1153 (define-key rmail-summary-mode-map
[menu-bar delete
]
1154 (cons "Delete" (make-sparse-keymap "Delete")))
1156 (define-key rmail-summary-mode-map
[menu-bar delete expunge
/save
]
1157 '("Expunge/Save" . rmail-summary-expunge-and-save
))
1159 (define-key rmail-summary-mode-map
[menu-bar delete expunge
]
1160 '("Expunge" . rmail-summary-expunge
))
1162 (define-key rmail-summary-mode-map
[menu-bar delete undelete
]
1163 '("Undelete" . rmail-summary-undelete
))
1165 (define-key rmail-summary-mode-map
[menu-bar delete delete
]
1166 '("Delete" . rmail-summary-delete-forward
))
1168 (define-key rmail-summary-mode-map
[menu-bar move
]
1169 (cons "Move" (make-sparse-keymap "Move")))
1171 (define-key rmail-summary-mode-map
[menu-bar move search-back
]
1172 '("Search Back..." . rmail-summary-search-backward
))
1174 (define-key rmail-summary-mode-map
[menu-bar move search
]
1175 '("Search..." . rmail-summary-search
))
1177 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1178 '("Previous Nondeleted" . rmail-summary-previous-msg
))
1180 (define-key rmail-summary-mode-map
[menu-bar move next
]
1181 '("Next Nondeleted" . rmail-summary-next-msg
))
1183 (define-key rmail-summary-mode-map
[menu-bar move last
]
1184 '("Last" . rmail-summary-last-message
))
1186 (define-key rmail-summary-mode-map
[menu-bar move first
]
1187 '("First" . rmail-summary-first-message
))
1189 (define-key rmail-summary-mode-map
[menu-bar move previous
]
1190 '("Previous" . rmail-summary-previous-all
))
1192 (define-key rmail-summary-mode-map
[menu-bar move next
]
1193 '("Next" . rmail-summary-next-all
))
1195 (defun rmail-summary-mouse-goto-message (event)
1196 "Select the message whose summary line you click on."
1198 (goto-char (posn-point (event-end event
)))
1199 (rmail-summary-goto-msg))
1201 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail
)
1202 "Go to message N in the summary buffer and the Rmail buffer.
1203 If N is nil, use the message corresponding to point in the summary
1204 and move to that message in the Rmail buffer.
1206 If NOWARN, don't say anything if N is out of range.
1207 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1208 Returns non-nil if message N was found."
1210 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1211 (if (eobp) (forward-line -
1))
1213 (let* ((obuf (current-buffer))
1217 (curmsg (string-to-number
1218 (buffer-substring (point)
1219 (min (point-max) (+ 6 (point))))))
1220 (total (with-current-buffer buf rmail-total-messages
)))
1221 ;; If message number N was specified, find that message's line
1222 ;; or set message-not-found.
1223 ;; If N wasn't specified or that message can't be found.
1224 ;; set N by default.
1228 (progn (message "No preceding message")
1230 (if (and (> n total
)
1232 (progn (message "No following message")
1233 (goto-char (point-max))
1234 (rmail-summary-goto-msg nil nowarn skip-rmail
)))
1235 (goto-char (point-min))
1236 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1237 (progn (or nowarn
(message "Message %d not found" n
))
1239 (setq message-not-found t
)
1241 (rmail-summary-mark-seen n
)
1242 (rmail-summary-update-highlight message-not-found
)
1245 (let ((selwin (selected-window)))
1247 (progn (rmail-pop-to-buffer buf
)
1248 (rmail-show-message n
))
1249 (select-window selwin
)
1250 ;; The actions above can alter the current buffer. Preserve it.
1251 (set-buffer obuf
))))
1252 (not message-not-found
)))
1254 ;; Update the highlighted line in an rmail summary buffer.
1255 ;; That should be current. We highlight the line point is on.
1256 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1257 (defun rmail-summary-update-highlight (not-found)
1258 ;; Make sure we have an overlay to use.
1259 (or rmail-summary-overlay
1261 (make-local-variable 'rmail-summary-overlay
)
1262 (setq rmail-summary-overlay
(make-overlay (point) (point)))
1263 (overlay-put rmail-summary-overlay
'rmail-summary t
)))
1264 ;; If this message is in the summary, use the overlay to highlight it.
1265 ;; Otherwise, don't highlight anything.
1267 (overlay-put rmail-summary-overlay
'face nil
)
1268 (move-overlay rmail-summary-overlay
1269 (save-excursion (beginning-of-line)
1270 (skip-chars-forward " ")
1272 (line-end-position))
1273 (overlay-put rmail-summary-overlay
'face
'highlight
)))
1275 (defun rmail-summary-scroll-msg-up (&optional dist
)
1276 "Scroll the Rmail window forward.
1277 If the Rmail window is displaying the end of a message,
1278 advance to the next message."
1281 (rmail-summary-scroll-msg-down nil
)
1282 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1283 (if rmail-buffer-window
1284 (if (let ((rmail-summary-window (selected-window)))
1285 (select-window rmail-buffer-window
)
1287 ;; Is EOB visible in the buffer?
1289 (let ((ht (window-height (selected-window))))
1290 (move-to-window-line (- ht
2))
1293 (select-window rmail-summary-window
)))
1294 (if (not rmail-summary-scroll-between-messages
)
1295 (error "End of buffer")
1296 (rmail-summary-next-msg (or dist
1)))
1297 (let ((other-window-scroll-buffer rmail-buffer
))
1298 (scroll-other-window dist
)))
1299 ;; If it isn't visible at all, show the beginning.
1300 (rmail-summary-beginning-of-message)))))
1302 (defun rmail-summary-scroll-msg-down (&optional dist
)
1303 "Scroll the Rmail window backward.
1304 If the Rmail window is now displaying the beginning of a message,
1305 move to the previous message."
1308 (rmail-summary-scroll-msg-up nil
)
1309 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1310 (if rmail-buffer-window
1311 (if (let ((rmail-summary-window (selected-window)))
1312 (select-window rmail-buffer-window
)
1314 ;; Is BOB visible in the buffer?
1316 (move-to-window-line 0)
1319 (select-window rmail-summary-window
)))
1320 (if (not rmail-summary-scroll-between-messages
)
1321 (error "Beginning of buffer")
1322 (rmail-summary-previous-msg (or dist
1)))
1323 (let ((other-window-scroll-buffer rmail-buffer
))
1324 (scroll-other-window-down dist
)))
1325 ;; If it isn't visible at all, show the beginning.
1326 (rmail-summary-beginning-of-message)))))
1328 (defun rmail-summary-beginning-of-message ()
1329 "Show current message from the beginning."
1331 (rmail-summary-show-message 'BEG
))
1333 (defun rmail-summary-end-of-message ()
1334 "Show bottom of current message."
1336 (rmail-summary-show-message 'END
))
1338 (defun rmail-summary-show-message (where)
1339 "Show current mail message.
1340 Position it according to WHERE which can be BEG or END"
1341 (if (and (one-window-p) (not pop-up-frames
))
1342 ;; If there is just one window, put the summary on the top.
1343 (let ((buffer rmail-buffer
))
1344 (split-window (selected-window) rmail-summary-window-size
)
1345 (select-window (frame-first-window))
1346 (rmail-pop-to-buffer rmail-buffer
)
1347 ;; If pop-to-buffer did not use that window, delete that
1348 ;; window. (This can happen if it uses another frame.)
1349 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1350 (delete-other-windows)))
1351 (rmail-pop-to-buffer rmail-buffer
))
1354 (goto-char (point-min))
1355 (search-forward "\n\n"))
1357 (goto-char (point-max))
1358 (recenter (1- (window-height))))
1360 (rmail-pop-to-buffer rmail-summary-buffer
))
1362 (defun rmail-summary-bury ()
1363 "Bury the Rmail buffer and the Rmail summary buffer."
1365 (let ((buffer-to-bury (current-buffer)))
1367 (while (setq window
(get-buffer-window rmail-buffer
))
1368 (set-window-buffer window
(other-buffer rmail-buffer
)))
1369 (bury-buffer rmail-buffer
))
1370 (switch-to-buffer (other-buffer buffer-to-bury
))
1371 (bury-buffer buffer-to-bury
)))
1373 (defun rmail-summary-quit ()
1374 "Quit out of Rmail and Rmail summary."
1376 (rmail-summary-wipe)
1379 (defun rmail-summary-wipe ()
1380 "Kill and wipe away Rmail summary, remaining within Rmail."
1382 (with-current-buffer rmail-buffer
(setq rmail-summary-buffer nil
))
1383 (let ((local-rmail-buffer rmail-buffer
))
1384 (kill-buffer (current-buffer))
1385 ;; Delete window if not only one.
1386 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1388 ;; Switch windows to the rmail buffer, or switch to it in this window.
1389 (rmail-pop-to-buffer local-rmail-buffer
)))
1391 (defun rmail-summary-expunge ()
1392 "Actually erase all deleted messages and recompute summary headers."
1394 (with-current-buffer rmail-buffer
1395 (when (rmail-expunge-confirmed)
1396 (rmail-only-expunge)))
1397 (rmail-update-summary))
1399 (defun rmail-summary-expunge-and-save ()
1400 "Expunge and save RMAIL file."
1403 (rmail-expunge-and-save))
1404 (rmail-update-summary)
1405 (set-buffer-modified-p nil
))
1407 (defun rmail-summary-get-new-mail (&optional file-name
)
1408 "Get new mail and recompute summary headers.
1410 Optionally you can specify the file to get new mail from. In this case,
1411 the file of new mail is not changed or deleted. Noninteractively, you can
1412 pass the inbox file name as an argument. Interactively, a prefix
1413 argument says to read a file name and use that file as the inbox."
1415 (list (if current-prefix-arg
1416 (read-file-name "Get new mail from file: "))))
1418 (with-current-buffer rmail-buffer
1419 (rmail-get-new-mail file-name
)
1420 ;; Get the proper new message number.
1421 (setq msg rmail-current-message
))
1422 ;; Make sure that message is displayed.
1424 (rmail-summary-goto-msg msg
))))
1426 (defun rmail-summary-input (filename)
1427 "Run Rmail on file FILENAME."
1428 (interactive "FRun rmail on RMAIL file: ")
1429 ;; We switch windows here, then display the other Rmail file there.
1430 (rmail-pop-to-buffer rmail-buffer
)
1433 (defun rmail-summary-first-message ()
1434 "Show first message in Rmail file from summary buffer."
1437 (beginning-of-buffer)))
1439 (defun rmail-summary-last-message ()
1440 "Show last message in Rmail file from summary buffer."
1446 (declare-function rmail-abort-edit
"rmailedit" ())
1447 (declare-function rmail-cease-edit
"rmailedit"())
1448 (declare-function rmail-set-label
"rmailkwd" (l state
&optional n
))
1449 (declare-function rmail-output-read-file-name
"rmailout" ())
1450 (declare-function mail-send-and-exit
"sendmail" (&optional arg
))
1452 (defvar rmail-summary-edit-map nil
)
1453 (if rmail-summary-edit-map
1455 (setq rmail-summary-edit-map
1456 (nconc (make-sparse-keymap) text-mode-map
))
1457 (define-key rmail-summary-edit-map
"\C-c\C-c" 'rmail-cease-edit
)
1458 (define-key rmail-summary-edit-map
"\C-c\C-]" 'rmail-abort-edit
))
1460 (defun rmail-summary-edit-current-message ()
1461 "Edit the contents of this message."
1463 (rmail-pop-to-buffer rmail-buffer
)
1464 (rmail-edit-current-message)
1465 (use-local-map rmail-summary-edit-map
))
1467 (defun rmail-summary-cease-edit ()
1468 "Finish editing message, then go back to Rmail summary buffer."
1471 (rmail-pop-to-buffer rmail-summary-buffer
))
1473 (defun rmail-summary-abort-edit ()
1474 "Abort edit of current message; restore original contents.
1475 Go back to summary buffer."
1478 (rmail-pop-to-buffer rmail-summary-buffer
))
1480 (defun rmail-summary-search-backward (regexp &optional n
)
1481 "Show message containing next match for REGEXP.
1482 Prefix argument gives repeat count; negative argument means search
1483 backwards (through earlier messages).
1484 Interactively, empty argument means use same regexp used last time."
1486 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1488 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1492 (if rmail-search-last-regexp
1493 (concat ", default "
1494 rmail-search-last-regexp
"): ")
1496 (setq regexp
(read-string prompt
))
1497 (cond ((not (equal regexp
""))
1498 (setq rmail-search-last-regexp regexp
))
1499 ((not rmail-search-last-regexp
)
1500 (error "No previous Rmail search string")))
1501 (list rmail-search-last-regexp
1502 (prefix-numeric-value current-prefix-arg
))))
1503 ;; Don't use save-excursion because that prevents point from moving
1504 ;; properly in the summary buffer.
1505 (with-current-buffer rmail-buffer
1506 (rmail-search regexp
(- n
))))
1508 (defun rmail-summary-search (regexp &optional n
)
1509 "Show message containing next match for REGEXP.
1510 Prefix argument gives repeat count; negative argument means search
1511 backwards (through earlier messages).
1512 Interactively, empty argument means use same regexp used last time."
1514 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1516 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1520 (if rmail-search-last-regexp
1521 (concat ", default "
1522 rmail-search-last-regexp
"): ")
1524 (setq regexp
(read-string prompt
))
1525 (cond ((not (equal regexp
""))
1526 (setq rmail-search-last-regexp regexp
))
1527 ((not rmail-search-last-regexp
)
1528 (error "No previous Rmail search string")))
1529 (list rmail-search-last-regexp
1530 (prefix-numeric-value current-prefix-arg
))))
1531 ;; Don't use save-excursion because that prevents point from moving
1532 ;; properly in the summary buffer.
1533 (let ((buffer (current-buffer))
1534 (selwin (selected-window)))
1537 (rmail-pop-to-buffer rmail-buffer
)
1538 (rmail-search regexp n
))
1539 (select-window selwin
)
1540 (set-buffer buffer
))))
1542 (defun rmail-summary-toggle-header ()
1543 "Show original message header if pruned header currently shown, or vice versa."
1545 (save-window-excursion
1546 (set-buffer rmail-buffer
)
1547 (rmail-toggle-header))
1548 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1549 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1550 (let ((window (get-buffer-window rmail-buffer
)))
1552 ;; Using save-window-excursion would lose the new value of point.
1553 (let ((owin (selected-window)))
1556 (select-window window
)
1557 (goto-char (point-min)))
1558 (select-window owin
))))))
1561 (defun rmail-summary-add-label (label)
1562 "Add LABEL to labels associated with current Rmail message.
1563 Completion is performed over known labels when reading."
1564 (interactive (list (with-current-buffer rmail-buffer
1565 (rmail-read-label "Add label"))))
1566 (with-current-buffer rmail-buffer
1567 (rmail-add-label label
)))
1569 (defun rmail-summary-kill-label (label)
1570 "Remove LABEL from labels associated with current Rmail message.
1571 Completion is performed over known labels when reading."
1572 (interactive (list (with-current-buffer rmail-buffer
1573 (rmail-read-label "Kill label"))))
1574 (with-current-buffer rmail-buffer
1575 (rmail-set-label label nil
)))
1577 ;;;; *** Rmail Summary Mailing Commands ***
1579 (defun rmail-summary-override-mail-send-and-exit ()
1580 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1581 (use-local-map (copy-keymap (current-local-map)))
1582 (dolist (key (where-is-internal 'mail-send-and-exit
))
1583 (define-key (current-local-map) key
'rmail-summary-send-and-exit
)))
1585 (defun rmail-summary-mail ()
1586 "Send mail in another window.
1587 While composing the message, use \\[mail-yank-original] to yank the
1588 original message into it."
1590 (let ((window (get-buffer-window rmail-buffer
)))
1592 (select-window window
)
1593 (set-buffer rmail-buffer
)))
1594 (rmail-start-mail nil nil nil nil nil
(current-buffer))
1595 (rmail-summary-override-mail-send-and-exit))
1597 (defun rmail-summary-continue ()
1598 "Continue composing outgoing message previously being composed."
1600 (let ((window (get-buffer-window rmail-buffer
)))
1602 (select-window window
)
1603 (set-buffer rmail-buffer
)))
1604 (rmail-start-mail t
))
1606 (defun rmail-summary-reply (just-sender)
1607 "Reply to the current message.
1608 Normally include CC: to all other recipients of original message;
1609 prefix argument means ignore them. While composing the reply,
1610 use \\[mail-yank-original] to yank the original message into it."
1612 (let ((window (get-buffer-window rmail-buffer
)))
1614 (select-window window
)
1615 (set-buffer rmail-buffer
)))
1616 (rmail-reply just-sender
)
1617 (rmail-summary-override-mail-send-and-exit))
1619 (defun rmail-summary-retry-failure ()
1620 "Edit a mail message which is based on the contents of the current message.
1621 For a message rejected by the mail system, extract the interesting headers and
1622 the body of the original message; otherwise copy the current message."
1624 (let ((window (get-buffer-window rmail-buffer
)))
1626 (select-window window
)
1627 (set-buffer rmail-buffer
)))
1628 (rmail-retry-failure)
1629 (rmail-summary-override-mail-send-and-exit))
1631 (defun rmail-summary-send-and-exit ()
1632 "Send mail reply and return to summary buffer."
1634 (mail-send-and-exit t
))
1636 (defun rmail-summary-forward (resend)
1637 "Forward the current message to another user.
1638 With prefix argument, \"resend\" the message instead of forwarding it;
1639 see the documentation of `rmail-resend'."
1642 (let ((window (get-buffer-window rmail-buffer
)))
1644 (select-window window
)
1645 (set-buffer rmail-buffer
)))
1646 (rmail-forward resend
)
1647 (rmail-summary-override-mail-send-and-exit)))
1649 (defun rmail-summary-resend ()
1650 "Resend current message using `rmail-resend'."
1653 (let ((window (get-buffer-window rmail-buffer
)))
1655 (select-window window
)
1656 (set-buffer rmail-buffer
)))
1657 (call-interactively 'rmail-resend
)))
1659 ;; Summary output commands.
1661 (defun rmail-summary-output (&optional file-name n
)
1662 "Append this message to mail file FILE-NAME.
1663 This works with both mbox format and Babyl format files,
1664 outputting in the appropriate format for each.
1665 The default file name comes from `rmail-default-file',
1666 which is updated to the name you use in this command.
1668 A prefix argument N says to output that many consecutive messages
1669 from those in the summary, starting with the current one.
1670 Deleted messages are skipped and don't count.
1671 When called from Lisp code, N may be omitted and defaults to 1.
1673 This command always outputs the complete message header,
1674 even the header display is currently pruned."
1676 (progn (require 'rmailout
)
1677 (list (rmail-output-read-file-name)
1678 (prefix-numeric-value current-prefix-arg
))))
1679 (let ((i 0) prev-msg
)
1682 (progn (rmail-summary-goto-msg)
1685 (with-current-buffer rmail-buffer
1686 rmail-current-message
))))))
1688 (with-current-buffer rmail-buffer
1689 (let ((rmail-delete-after-output nil
))
1690 (rmail-output file-name
1)))
1691 (if rmail-delete-after-output
1692 (rmail-summary-delete-forward nil
)
1694 (rmail-summary-next-msg 1))))))
1696 (defalias 'rmail-summary-output-to-rmail-file
'rmail-summary-output
)
1698 (declare-function rmail-output-as-seen
"rmailout"
1699 (file-name &optional count noattribute from-gnus
))
1701 (defun rmail-summary-output-as-seen (&optional file-name n
)
1702 "Append this message to mbox file named FILE-NAME.
1703 A prefix argument N says to output that many consecutive messages,
1704 from the summary, starting with the current one.
1705 Deleted messages are skipped and don't count.
1706 When called from Lisp code, N may be omitted and defaults to 1.
1708 This outputs the message header as you see it (or would see it)
1711 The default file name comes from `rmail-default-file',
1712 which is updated to the name you use in this command."
1714 (progn (require 'rmailout
)
1715 (list (rmail-output-read-file-name)
1716 (prefix-numeric-value current-prefix-arg
))))
1717 (require 'rmailout
) ; for rmail-output-as-seen in non-interactive case
1718 (let ((i 0) prev-msg
)
1721 (progn (rmail-summary-goto-msg)
1724 (with-current-buffer rmail-buffer
1725 rmail-current-message
))))))
1727 (with-current-buffer rmail-buffer
1728 (let ((rmail-delete-after-output nil
))
1729 (rmail-output-as-seen file-name
1)))
1730 (if rmail-delete-after-output
1731 (rmail-summary-delete-forward nil
)
1733 (rmail-summary-next-msg 1))))))
1735 (defun rmail-summary-output-menu ()
1736 "Output current message to another Rmail file, chosen with a menu.
1737 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1738 The variables `rmail-secondary-file-directory' and
1739 `rmail-secondary-file-regexp' control which files are offered in the menu."
1741 (with-current-buffer rmail-buffer
1742 (let ((rmail-delete-after-output nil
))
1743 (call-interactively 'rmail-output-menu
)))
1744 (if rmail-delete-after-output
1745 (rmail-summary-delete-forward nil
)))
1747 (defun rmail-summary-construct-io-menu ()
1748 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1751 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1752 (cons "Input Rmail File"
1753 (rmail-list-to-menu "Input Rmail File"
1755 'rmail-summary-input
)))
1756 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1757 (cons "Output Rmail File"
1758 (rmail-list-to-menu "Output Rmail File"
1760 'rmail-summary-output
))))
1761 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1762 '("Input Rmail File" . rmail-disable-menu
))
1763 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1764 '("Output Rmail File" . rmail-disable-menu
)))))
1766 (defun rmail-summary-output-body (&optional file-name
)
1767 "Write this message body to the file FILE-NAME.
1768 FILE-NAME defaults, interactively, from the Subject field of the message."
1770 (with-current-buffer rmail-buffer
1771 (let ((rmail-delete-after-output nil
))
1773 (rmail-output-body-to-file file-name
)
1774 (call-interactively 'rmail-output-body-to-file
))))
1775 (if rmail-delete-after-output
1776 (rmail-summary-delete-forward nil
)))
1778 ;; Sorting messages in Rmail Summary buffer.
1780 (defun rmail-summary-sort-by-date (reverse)
1781 "Sort messages of current Rmail summary by \"Date\" header.
1782 If prefix argument REVERSE is non-nil, sorts in reverse order."
1784 (rmail-sort-from-summary (function rmail-sort-by-date
) reverse
))
1786 (defun rmail-summary-sort-by-subject (reverse)
1787 "Sort messages of current Rmail summary by \"Subject\" header.
1788 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
1789 non-nil, sorts in reverse order."
1791 (rmail-sort-from-summary (function rmail-sort-by-subject
) reverse
))
1793 (defun rmail-summary-sort-by-author (reverse)
1794 "Sort messages of current Rmail summary by author.
1795 This uses either the \"From\" or \"Sender\" header, downcased.
1796 If prefix argument REVERSE is non-nil, sorts in reverse order."
1798 (rmail-sort-from-summary (function rmail-sort-by-author
) reverse
))
1800 (defun rmail-summary-sort-by-recipient (reverse)
1801 "Sort messages of current Rmail summary by recipient.
1802 This uses either the \"To\" or \"Apparently-To\" header, downcased.
1803 If prefix argument REVERSE is non-nil, sorts in reverse order."
1805 (rmail-sort-from-summary (function rmail-sort-by-recipient
) reverse
))
1807 (defun rmail-summary-sort-by-correspondent (reverse)
1808 "Sort messages of current Rmail summary by other correspondent.
1809 This uses either the \"From\", \"Sender\", \"To\", or
1810 \"Apparently-To\" header, downcased. Uses the first header not
1811 excluded by `rmail-dont-reply-to-names'. If prefix argument
1812 REVERSE is non-nil, sorts in reverse order."
1814 (rmail-sort-from-summary (function rmail-sort-by-correspondent
) reverse
))
1816 (defun rmail-summary-sort-by-lines (reverse)
1817 "Sort messages of current Rmail summary by the number of lines.
1818 If prefix argument REVERSE is non-nil, sorts in reverse order."
1820 (rmail-sort-from-summary (function rmail-sort-by-lines
) reverse
))
1822 (defun rmail-summary-sort-by-labels (reverse labels
)
1823 "Sort messages of current Rmail summary by labels.
1824 LABELS is a comma-separated list of labels.
1825 If prefix argument REVERSE is non-nil, sorts in reverse order."
1826 (interactive "P\nsSort by labels: ")
1827 (rmail-sort-from-summary
1828 (lambda (reverse) (rmail-sort-by-labels reverse labels
))
1831 (defun rmail-sort-from-summary (sortfun reverse
)
1832 "Sort the Rmail buffer using sorting function SORTFUN.
1833 Passes REVERSE to SORTFUN as its sole argument. Then regenerates
1834 the summary. Note that the whole Rmail buffer is sorted, even if
1835 the summary is only showing a subset of messages."
1836 (require 'rmailsort
)
1837 (let ((selwin (selected-window)))
1839 (progn (rmail-pop-to-buffer rmail-buffer
)
1840 (funcall sortfun reverse
))
1841 (select-window selwin
))))
1846 ;; generated-autoload-file: "rmail.el"
1849 ;; arch-tag: 80b0a27a-a50d-4f37-9466-83d32d1e0ca8
1850 ;;; rmailsum.el ends here