1 ;;; rmailsum.el --- make summary buffers for the mail reader -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985, 1993-1996, 2000-2017 Free Software Foundation,
6 ;; Maintainer: emacs-devel@gnu.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
27 ;; Extended by Bob Weiner of Motorola
28 ;; Provided all commands from rmail-mode in rmail-summary-mode and made key
29 ;; bindings in both modes wholly compatible.
33 ;; For rmail-select-summary.
37 (defcustom rmail-summary-scroll-between-messages t
38 "Non-nil means Rmail summary scroll commands move between messages.
39 That is, after `rmail-summary-scroll-msg-up' reaches the end of a
40 message, it moves to the next message; and similarly for
41 `rmail-summary-scroll-msg-down'."
43 :group
'rmail-summary
)
45 ;; FIXME could do with a :set function that regenerates the summary
46 ;; and updates rmail-summary-vector.
47 (defcustom rmail-summary-line-count-flag t
48 "Non-nil means Rmail summary should show the number of lines in each message.
49 Setting this option to nil might speed up the generation of summaries."
51 :group
'rmail-summary
)
53 (defvar rmail-summary-font-lock-keywords
54 '(("^.....D.*" . font-lock-string-face
) ; Deleted.
55 ("^.....-.*" . font-lock-type-face
) ; Unread.
56 ;; Neither of the below will be highlighted if either of the above are:
57 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face
) ; Date.
58 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face
)) ; Labels.
59 "Additional expressions to highlight in Rmail Summary mode.")
61 (defvar rmail-summary-redo nil
62 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
64 (defvar rmail-summary-overlay nil
65 "Overlay used to highlight the current message in the Rmail summary.")
66 (put 'rmail-summary-overlay
'permanent-local t
)
68 (defvar rmail-summary-mode-map
69 (let ((map (make-keymap)))
71 (define-key map
[mouse-2
] 'rmail-summary-mouse-goto-message
)
72 (define-key map
"a" 'rmail-summary-add-label
)
73 (define-key map
"b" 'rmail-summary-bury
)
74 (define-key map
"c" 'rmail-summary-continue
)
75 (define-key map
"d" 'rmail-summary-delete-forward
)
76 (define-key map
"\C-d" 'rmail-summary-delete-backward
)
77 (define-key map
"e" 'rmail-summary-edit-current-message
)
78 (define-key map
"f" 'rmail-summary-forward
)
79 (define-key map
"g" 'rmail-summary-get-new-mail
)
80 (define-key map
"h" 'rmail-summary
)
81 (define-key map
"i" 'rmail-summary-input
)
82 (define-key map
"j" 'rmail-summary-goto-msg
)
83 (define-key map
"\C-m" 'rmail-summary-goto-msg
)
84 (define-key map
"k" 'rmail-summary-kill-label
)
85 (define-key map
"l" 'rmail-summary-by-labels
)
86 (define-key map
"\e\C-h" 'rmail-summary
)
87 (define-key map
"\e\C-l" 'rmail-summary-by-labels
)
88 (define-key map
"\e\C-r" 'rmail-summary-by-recipients
)
89 (define-key map
"\e\C-s" 'rmail-summary-by-regexp
)
91 (define-key map
"\e\C-f" 'rmail-summary-by-senders
)
92 (define-key map
"\e\C-t" 'rmail-summary-by-topic
)
93 (define-key map
"m" 'rmail-summary-mail
)
94 (define-key map
"\M-m" 'rmail-summary-retry-failure
)
95 (define-key map
"n" 'rmail-summary-next-msg
)
96 (define-key map
"\en" 'rmail-summary-next-all
)
97 (define-key map
"\e\C-n" 'rmail-summary-next-labeled-message
)
98 (define-key map
"o" 'rmail-summary-output
)
99 (define-key map
"\C-o" 'rmail-summary-output-as-seen
)
100 (define-key map
"p" 'rmail-summary-previous-msg
)
101 (define-key map
"\ep" 'rmail-summary-previous-all
)
102 (define-key map
"\e\C-p" 'rmail-summary-previous-labeled-message
)
103 (define-key map
"q" 'rmail-summary-quit
)
104 (define-key map
"Q" 'rmail-summary-wipe
)
105 (define-key map
"r" 'rmail-summary-reply
)
106 (define-key map
"s" 'rmail-summary-expunge-and-save
)
107 ;; See rms's comment in rmail.el
108 ;; (define-key map "\er" 'rmail-summary-search-backward)
109 (define-key map
"\es" 'rmail-summary-search
)
110 (define-key map
"t" 'rmail-summary-toggle-header
)
111 (define-key map
"u" 'rmail-summary-undelete
)
112 (define-key map
"\M-u" 'rmail-summary-undelete-many
)
113 (define-key map
"x" 'rmail-summary-expunge
)
114 (define-key map
"w" 'rmail-summary-output-body
)
115 (define-key map
"v" 'rmail-mime
)
116 (define-key map
"." 'rmail-summary-beginning-of-message
)
117 (define-key map
"/" 'rmail-summary-end-of-message
)
118 (define-key map
"<" 'rmail-summary-first-message
)
119 (define-key map
">" 'rmail-summary-last-message
)
120 (define-key map
" " 'rmail-summary-scroll-msg-up
)
121 (define-key map
[?\S-\
] 'rmail-summary-scroll-msg-down
)
122 (define-key map
"\177" 'rmail-summary-scroll-msg-down
)
123 (define-key map
"?" 'describe-mode
)
124 (define-key map
"\C-c\C-n" 'rmail-summary-next-same-subject
)
125 (define-key map
"\C-c\C-p" 'rmail-summary-previous-same-subject
)
126 (define-key map
"\C-c\C-s\C-d" 'rmail-summary-sort-by-date
)
127 (define-key map
"\C-c\C-s\C-s" 'rmail-summary-sort-by-subject
)
128 (define-key map
"\C-c\C-s\C-a" 'rmail-summary-sort-by-author
)
129 (define-key map
"\C-c\C-s\C-r" 'rmail-summary-sort-by-recipient
)
130 (define-key map
"\C-c\C-s\C-c" 'rmail-summary-sort-by-correspondent
)
131 (define-key map
"\C-c\C-s\C-l" 'rmail-summary-sort-by-lines
)
132 (define-key map
"\C-c\C-s\C-k" 'rmail-summary-sort-by-labels
)
133 (define-key map
"\C-x\C-s" 'rmail-summary-save-buffer
)
135 ;; Menu bar bindings.
137 (define-key map
[menu-bar
] (make-sparse-keymap))
139 (define-key map
[menu-bar classify
]
140 (cons "Classify" (make-sparse-keymap "Classify")))
142 (define-key map
[menu-bar classify output-menu
]
143 '("Output (Rmail Menu)..." . rmail-summary-output-menu
))
145 (define-key map
[menu-bar classify input-menu
]
146 '("Input Rmail File (menu)..." . rmail-input-menu
))
148 (define-key map
[menu-bar classify input-menu
]
151 (define-key map
[menu-bar classify output-menu
]
154 (define-key map
[menu-bar classify output-body
]
155 '("Output body..." . rmail-summary-output-body
))
157 (define-key map
[menu-bar classify output-inbox
]
158 '("Output..." . rmail-summary-output
))
160 (define-key map
[menu-bar classify output
]
161 '("Output as seen..." . rmail-summary-output-as-seen
))
163 (define-key map
[menu-bar classify kill-label
]
164 '("Kill Label..." . rmail-summary-kill-label
))
166 (define-key map
[menu-bar classify add-label
]
167 '("Add Label..." . rmail-summary-add-label
))
169 (define-key map
[menu-bar summary
]
170 (cons "Summary" (make-sparse-keymap "Summary")))
172 (define-key map
[menu-bar summary senders
]
173 '("By Senders..." . rmail-summary-by-senders
))
175 (define-key map
[menu-bar summary labels
]
176 '("By Labels..." . rmail-summary-by-labels
))
178 (define-key map
[menu-bar summary recipients
]
179 '("By Recipients..." . rmail-summary-by-recipients
))
181 (define-key map
[menu-bar summary topic
]
182 '("By Topic..." . rmail-summary-by-topic
))
184 (define-key map
[menu-bar summary regexp
]
185 '("By Regexp..." . rmail-summary-by-regexp
))
187 (define-key map
[menu-bar summary all
]
188 '("All" . rmail-summary
))
190 (define-key map
[menu-bar mail
]
191 (cons "Mail" (make-sparse-keymap "Mail")))
193 (define-key map
[menu-bar mail rmail-summary-get-new-mail
]
194 '("Get New Mail" . rmail-summary-get-new-mail
))
196 (define-key map
[menu-bar mail lambda
]
199 (define-key map
[menu-bar mail continue
]
200 '("Continue" . rmail-summary-continue
))
202 (define-key map
[menu-bar mail resend
]
203 '("Re-send..." . rmail-summary-resend
))
205 (define-key map
[menu-bar mail forward
]
206 '("Forward" . rmail-summary-forward
))
208 (define-key map
[menu-bar mail retry
]
209 '("Retry" . rmail-summary-retry-failure
))
211 (define-key map
[menu-bar mail reply
]
212 '("Reply" . rmail-summary-reply
))
214 (define-key map
[menu-bar mail mail
]
215 '("Mail" . rmail-summary-mail
))
217 (define-key map
[menu-bar delete
]
218 (cons "Delete" (make-sparse-keymap "Delete")))
220 (define-key map
[menu-bar delete expunge
/save
]
221 '("Expunge/Save" . rmail-summary-expunge-and-save
))
223 (define-key map
[menu-bar delete expunge
]
224 '("Expunge" . rmail-summary-expunge
))
226 (define-key map
[menu-bar delete undelete
]
227 '("Undelete" . rmail-summary-undelete
))
229 (define-key map
[menu-bar delete delete
]
230 '("Delete" . rmail-summary-delete-forward
))
232 (define-key map
[menu-bar move
]
233 (cons "Move" (make-sparse-keymap "Move")))
235 (define-key map
[menu-bar move search-back
]
236 '("Search Back..." . rmail-summary-search-backward
))
238 (define-key map
[menu-bar move search
]
239 '("Search..." . rmail-summary-search
))
241 (define-key map
[menu-bar move previous
]
242 '("Previous Nondeleted" . rmail-summary-previous-msg
))
244 (define-key map
[menu-bar move next
]
245 '("Next Nondeleted" . rmail-summary-next-msg
))
247 (define-key map
[menu-bar move last
]
248 '("Last" . rmail-summary-last-message
))
250 (define-key map
[menu-bar move first
]
251 '("First" . rmail-summary-first-message
))
253 (define-key map
[menu-bar move previous
]
254 '("Previous" . rmail-summary-previous-all
))
256 (define-key map
[menu-bar move next
]
257 '("Next" . rmail-summary-next-all
))
259 "Keymap used in Rmail summary mode.")
261 ;; Entry points for making a summary buffer.
263 ;; Regenerate the contents of the summary
264 ;; using the same selection criterion as last time.
265 ;; M-x revert-buffer in a summary buffer calls this function.
266 (defun rmail-update-summary (&rest _
)
267 (apply (car rmail-summary-redo
) (cdr rmail-summary-redo
)))
270 (defun rmail-summary ()
271 "Display a summary of all messages, one line per message."
273 (rmail-new-summary "All" '(rmail-summary) nil
))
276 (defun rmail-summary-by-labels (labels)
277 "Display a summary of all messages with one or more LABELS.
278 LABELS should be a string containing the desired labels, separated by commas."
279 (interactive "sLabels to summarize by: ")
280 (if (string= labels
"")
281 (setq labels
(or rmail-last-multi-labels
282 (error "No label specified"))))
283 (setq rmail-last-multi-labels labels
)
284 (rmail-new-summary (concat "labels " labels
)
285 (list 'rmail-summary-by-labels labels
)
286 'rmail-message-labels-p
288 (mail-comma-list-regexp labels
)
289 "\\)\\(,\\|\\'\\)")))
292 (defun rmail-summary-by-recipients (recipients &optional primary-only
)
293 "Display a summary of all messages with the given RECIPIENTS.
294 Normally checks the To, From and Cc fields of headers;
295 but if PRIMARY-ONLY is non-nil (prefix arg given),
296 only look in the To and From fields.
297 RECIPIENTS is a regular expression."
298 (interactive "sRecipients to summarize by: \nP")
300 (concat "recipients " recipients
)
301 (list 'rmail-summary-by-recipients recipients primary-only
)
302 'rmail-message-recipients-p recipients primary-only
))
304 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
305 (rmail-apply-in-message msg
'rmail-message-recipients-p-1
306 recipients primary-only
))
308 (defun rmail-message-recipients-p-1 (recipients &optional primary-only
)
309 ;; mail-fetch-field does not care where it starts from.
310 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
311 (or (string-match recipients
(or (mail-fetch-field "To") ""))
312 (string-match recipients
(or (mail-fetch-field "From") ""))
313 (if (not primary-only
)
314 (string-match recipients
(or (mail-fetch-field "Cc") "")))))
316 ;; FIXME I find this a non-obvious name for what this function does.
317 ;; Also, the optional WHOLE-MESSAGE argument of r-s-by-topic would
318 ;; seem more natural here.
320 (defun rmail-summary-by-regexp (regexp)
321 "Display a summary of all messages according to regexp REGEXP.
322 If the regular expression is found in the header of the message
323 \(including in the date and other lines, as well as the subject line),
324 Emacs will list the message in the summary."
325 (interactive "sRegexp to summarize by: ")
326 (if (string= regexp
"")
327 (setq regexp
(or rmail-last-regexp
328 (error "No regexp specified"))))
329 (setq rmail-last-regexp regexp
)
330 (rmail-new-summary (concat "regexp " regexp
)
331 (list 'rmail-summary-by-regexp regexp
)
332 'rmail-message-regexp-p
335 (defun rmail-message-regexp-p (msg regexp
)
336 "Return t, if for message number MSG, regexp REGEXP matches in the header."
337 (rmail-apply-in-message msg
'rmail-message-regexp-p-1 msg regexp
))
339 (defun rmail--decode-and-apply (function &rest args
)
340 "Make an RFC2047-decoded copy of current buffer, apply FUNCTION with ARGS."
341 (let ((buff (current-buffer)))
343 (insert-buffer-substring buff
)
344 (goto-char (point-min))
345 ;; FIXME? In rmail-show-message-1, decoding depends on
346 ;; rmail-enable-mime being non-nil (?).
347 (rfc2047-decode-region (point-min)
350 (search-forward "\n\n" nil
'move
)
352 (apply function args
))))
354 (defun rmail-message-regexp-p-1 (msg regexp
)
355 ;; Search functions can expect to start from the beginning.
356 (narrow-to-region (point) (save-excursion (search-forward "\n\n") (point)))
357 (if (and rmail-enable-mime
358 rmail-search-mime-header-function
)
359 (funcall rmail-search-mime-header-function msg regexp
(point))
360 ;; We need to search the full headers, but probably want to decode
361 ;; them so they match the ones people see displayed. (Bug#19088)
362 (rmail--decode-and-apply 're-search-forward regexp nil t
)))
365 (defun rmail-summary-by-topic (subject &optional whole-message
)
366 "Display a summary of all messages with the given SUBJECT.
367 Normally checks just the Subject field of headers; but with prefix
368 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
369 SUBJECT is a regular expression."
371 ;; We quote the default subject, because if it contains regexp
372 ;; special characters (eg "?"), it can fail to match itself. (Bug#2333)
373 (let* ((subject (regexp-quote (rmail-simplified-subject)))
374 (prompt (concat "Topics to summarize by (regexp"
375 (if subject
", default current subject" "")
377 (list (read-string prompt nil nil subject
) current-prefix-arg
)))
379 (concat "about " subject
)
380 (list 'rmail-summary-by-topic subject whole-message
)
381 'rmail-message-subject-p subject whole-message
))
383 (defun rmail-message-subject-p (msg subject
&optional whole-message
)
385 ;; SUBJECT and rmail-simplified-subject are 2047 decoded.
386 (rmail-apply-in-message msg
'rmail--decode-and-apply
387 're-search-forward subject nil t
)
388 (string-match subject
(rmail-simplified-subject msg
))))
391 (defun rmail-summary-by-senders (senders)
392 "Display a summary of all messages whose \"From\" field matches SENDERS.
393 SENDERS is a regular expression."
394 (interactive "sSenders to summarize by: ")
396 (concat "senders " senders
)
397 (list 'rmail-summary-by-senders senders
) 'rmail-message-senders-p senders
))
399 (defun rmail-message-senders-p (msg senders
)
400 (string-match senders
(or (rmail-get-header "From" msg
) "")))
402 ;; General making of a summary buffer.
404 (defvar rmail-summary-symbol-number
0)
406 (defvar rmail-new-summary-line-count
)
408 (defun rmail-new-summary (desc redo function
&rest args
)
409 "Create a summary of selected messages.
410 DESC makes part of the mode line of the summary buffer.
411 REDO is what to put in `rmail-summary-redo'; usually
412 its car is the function that called `rmail-new-summary'
413 and its cdr is the arguments passed to that function.
415 For each message, applies FUNCTION to the message number and ARGS...,
416 and if the result is non-nil, it includes that message in the summary.
417 If FUNCTION is nil, includes all messages."
418 (message "Computing summary lines...")
420 (error "No RMAIL buffer found"))
421 (let (mesg was-in-summary sumbuf
)
422 (if (derived-mode-p 'rmail-summary-mode
)
423 (setq was-in-summary t
))
424 (with-current-buffer rmail-buffer
425 (setq rmail-summary-buffer
(rmail-new-summary-1 desc redo function args
)
426 ;; r-s-b is buffer-local.
427 sumbuf rmail-summary-buffer
428 mesg rmail-current-message
))
429 ;; Now display the summary buffer and go to the right place in it.
430 (unless was-in-summary
431 (if (and (one-window-p)
434 ;; If there is just one window, put the summary on the top.
436 (split-window (selected-window) rmail-summary-window-size
)
437 (select-window (next-window (frame-first-window)))
438 (rmail-pop-to-buffer sumbuf
)
439 ;; If pop-to-buffer did not use that window, delete that
440 ;; window. (This can happen if it uses another frame.)
441 (if (not (eq sumbuf
(window-buffer (frame-first-window))))
442 (delete-other-windows)))
443 (rmail-pop-to-buffer sumbuf
))
444 (set-buffer rmail-buffer
)
445 ;; This is how rmail makes the summary buffer reappear.
446 ;; We do this here to make the window the proper size.
447 (rmail-select-summary nil
)
449 (rmail-summary-goto-msg mesg t t
)
450 (rmail-summary-construct-io-menu)
451 (message "Computing summary lines...done")))
453 (defun rmail-new-summary-1 (description redo function args
)
454 "Filter messages to obtain summary lines.
455 DESCRIPTION is added to the mode line.
457 Return the summary buffer by invoking FUNCTION on each message
458 passing the message number and ARGS.
460 REDO is what to put in `rmail-summary-redo'.
462 The current buffer must be a Rmail buffer either containing a
463 collection of mbox formatted messages or displaying a single
465 (let ((summary-msgs ())
466 (rmail-new-summary-line-count 0)
467 (sumbuf (rmail-get-create-summary-buffer)))
468 ;; Scan the messages, getting their summary strings
469 ;; and putting the list of them in SUMMARY-MSGS.
471 (main-buffer (current-buffer))
472 (total rmail-total-messages
)
473 (inhibit-read-only t
))
475 ;; Go where the mbox text is.
476 (if (rmail-buffers-swapped-p)
477 (set-buffer rmail-view-buffer
))
478 (let ((old-min (point-min-marker))
479 (old-max (point-max-marker)))
481 ;; Can't use save-restriction here; that doesn't work if we
482 ;; plan to modify text outside the original restriction.
485 (goto-char (point-min))
486 (while (>= total msgnum
)
487 ;; Go back to the Rmail buffer so FUNCTION and
488 ;; rmail-get-summary can see its local vars.
489 (with-current-buffer main-buffer
490 ;; First test whether to include this message.
491 (if (or (null function
)
492 (apply function msgnum args
))
494 (cons (cons msgnum
(rmail-get-summary msgnum
))
496 (setq msgnum
(1+ msgnum
))
497 ;; Provide a periodic User progress message.
498 (if (and (not (zerop rmail-new-summary-line-count
))
499 (zerop (% rmail-new-summary-line-count
10)))
500 (message "Computing summary lines...%d"
501 rmail-new-summary-line-count
)))
502 (setq summary-msgs
(nreverse summary-msgs
)))
503 (narrow-to-region old-min old-max
)))))
504 ;; Temporarily, while summary buffer is unfinished,
505 ;; we "don't have" a summary.
506 (setq rmail-summary-buffer nil
)
507 ;; I have not a clue what this clause is doing. If you read this
508 ;; chunk of code and have a clue, then please write it here.
509 (if rmail-enable-mime
510 (with-current-buffer rmail-buffer
511 (setq rmail-summary-buffer nil
)))
513 (let ((rbuf (current-buffer))
514 (total rmail-total-messages
))
516 ;; Set up the summary buffer's contents.
517 (let ((buffer-read-only nil
))
520 (princ (cdr (car summary-msgs
)) sumbuf
)
521 (setq summary-msgs
(cdr summary-msgs
)))
522 (goto-char (point-min)))
523 ;; Set up the rest of its state and local variables.
524 (setq buffer-read-only t
)
526 (make-local-variable 'minor-mode-alist
)
527 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
528 (setq rmail-buffer rbuf
529 rmail-summary-redo redo
530 rmail-total-messages total
)))
533 (defun rmail-get-create-summary-buffer ()
534 "Return the Rmail summary buffer.
535 If necessary, it is created and undo is disabled."
536 (if (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
))
538 (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
539 (with-current-buffer buff
540 (setq buffer-undo-list t
))
544 ;; Low levels of generating a summary.
546 (defun rmail-get-summary (msgnum)
547 "Return the summary line for message MSGNUM.
548 The mbox buffer must be current when you call this function
549 even if its text is swapped.
551 If the message has a summary line already, it will be stored in
552 the message as a header and simply returned, otherwise the
553 summary line is created, saved in the message header, cached and
556 The current buffer contains the unrestricted message collection."
557 (let ((line (aref rmail-summary-vector
(1- msgnum
))))
559 ;; Register a summary line for MSGNUM.
560 (setq rmail-new-summary-line-count
(1+ rmail-new-summary-line-count
)
561 line
(rmail-create-summary-line msgnum
))
562 ;; Cache the summary line for use during this Rmail session.
563 (aset rmail-summary-vector
(1- msgnum
) line
))
566 (defcustom rmail-summary-line-decoder
(function rfc2047-decode-string
)
567 "Function to decode a Rmail summary line.
568 It receives the summary line for one message as a string
569 and should return the decoded string.
571 By default, it is `rfc2047-decode-string', which decodes MIME-encoded
575 :group
'rmail-summary
)
577 (defun rmail-create-summary-line (msgnum)
578 "Return the summary line for message MSGNUM.
579 Obtain the message summary from the header if it is available
580 otherwise create it and store it in the message header.
582 The mbox buffer must be current when you call this function
583 even if its text is swapped."
584 (let ((beg (rmail-msgbeg msgnum
))
585 (end (rmail-msgend msgnum
))
586 (deleted (rmail-message-deleted-p msgnum
))
587 ;; Does not work (swapped?)
588 ;;; (unseen (rmail-message-unseen-p msgnum))
591 ;; Switch to the buffer that has the whole mbox text.
592 (if (rmail-buffers-swapped-p)
593 (set-buffer rmail-view-buffer
))
594 ;; Now we can compute the line count.
595 (if rmail-summary-line-count-flag
596 (setq lines
(count-lines beg end
)))
597 ;; Narrow to the message header.
602 (if (search-forward "\n\n" end t
)
604 (narrow-to-region beg
(point))
605 ;; Replace rmail-message-unseen-p from above.
607 (setq unseen
(and (search-forward
608 (concat rmail-attribute-header
": ") nil t
)
609 (looking-at "......U")))
610 ;; Generate a status line from the message.
611 (rmail-create-summary msgnum deleted unseen lines
))
612 (rmail-error-bad-format msgnum
)))))))
614 ;; FIXME this is now unused.
615 ;; The intention was to display in the summary something like {E}
616 ;; for an edited messaged, similarly for answered, etc.
617 ;; But that conflicts with the previous rmail usage, where
618 ;; any user-defined { labels } occupied this space.
619 ;; So whilst it would be nice to have this information in the summary,
620 ;; it would need to go somewhere else.
621 (defun rmail-get-summary-status ()
622 "Return a coded string wrapped in curly braces denoting the status.
624 The current buffer must already be narrowed to the message headers for
625 the message being processed."
626 (let ((status (mail-fetch-field rmail-attribute-header
))
630 ;; Strip off the read/unread and the deleted attribute which are
631 ;; handled separately.
634 (concat (substring status
0 1) (substring status
2 6))
636 (while (< index
(length status
))
637 (unless (string= "-" (setq char
(substring status index
(1+ index
))))
638 (setq result
(concat result char
)))
639 (setq index
(1+ index
)))
640 (when (> (length result
) 0)
641 (setq result
(concat "{" result
"}")))
644 (autoload 'rmail-make-label
"rmailkwd")
646 (defun rmail-get-summary-labels ()
647 "Return a string wrapped in curly braces with the current message labels.
648 Returns nil if there are no labels. The current buffer must
649 already be narrowed to the message headers for the message being
651 (let ((labels (mail-fetch-field rmail-keyword-header
)))
653 (not (string-equal labels
""))
655 ;; Intern so that rmail-read-label can offer completion.
656 (mapc 'rmail-make-label
(split-string labels
", "))
657 (format "{ %s } " labels
)))))
659 (defun rmail-create-summary (msgnum deleted unseen lines
)
660 "Return the summary line for message MSGNUM.
661 The current buffer should already be narrowed to the header for that message.
662 It could be either buffer, so don't access Rmail local variables.
663 DELETED is t if this message is marked deleted.
664 UNSEEN is t if it is marked unseen.
665 LINES is the number of lines in the message (if we should display that)
667 (goto-char (point-min))
668 (let ((line (rmail-header-summary))
669 (labels (rmail-get-summary-labels))
670 status prefix basic-start basic-end linecount-string
)
672 (setq linecount-string
675 ((<= lines
9) (format " [%d]" lines
))
676 ((<= lines
99) (format " [%d]" lines
))
677 ((<= lines
999) (format " [%d]" lines
))
678 ((<= lines
9999) (format " [%dk]" (/ lines
1000)))
679 ((<= lines
99999) (format " [%dk]" (/ lines
1000)))
680 (t (format "[%dk]" (/ lines
1000)))))
686 prefix
(format "%5d%c " msgnum status
)
687 basic-start
(car line
)
688 basic-end
(cadr line
))
689 (funcall rmail-summary-line-decoder
690 (concat prefix basic-start linecount-string
" "
693 (defun rmail-header-summary ()
694 "Return a message summary based on the message headers.
695 The value is a list of two strings, the first and second parts of the summary.
697 The current buffer must already be narrowed to the message headers for
698 the message being processed."
699 (goto-char (point-min))
701 (concat (save-excursion
702 (if (not (re-search-forward "^Date:" nil t
))
704 ;; Match month names case-insensitively
705 (cond ((let ((case-fold-search t
))
706 (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
707 (line-end-position) t
))
709 (string-to-number (buffer-substring
713 (match-beginning 4) (match-end 4))))
714 ((let ((case-fold-search t
))
715 (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
716 (line-end-position) t
))
718 (string-to-number (buffer-substring
722 (match-beginning 2) (match-end 2))))
723 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
724 (line-end-position) t
)
727 (match-beginning 2) (match-end 2))
729 (match-beginning 3) (match-end 3))
731 (match-beginning 4) (match-end 4))))
735 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
736 (mail-strip-quoted-names
739 ;; Get all the lines of the From field
740 ;; so that we get a whole comment if there is one,
741 ;; so that mail-strip-quoted-names can discard it.
743 (while (progn (forward-line 1)
744 (looking-at "[ \t]")))
745 ;; Back up over newline, then trailing spaces or tabs
747 (skip-chars-backward " \t")
752 (or rmail-user-mail-address-regexp
754 (regexp-quote (user-login-name))
756 (regexp-quote user-mail-address
)
759 ;; No From field, or it's this user.
761 (goto-char (point-min))
762 (if (not (re-search-forward "^To:[ \t]*" nil t
))
766 (mail-strip-quoted-names
770 (skip-chars-backward " \t")
774 ;; We are going to return only 25 characters of the
775 ;; address, so make sure it is RFC2047 decoded before
776 ;; taking its substring. This is important when the address is not on the same line as the name, e.g.:
777 ;; To: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?=
778 ;; <stepnem@gmail.com>
779 (setq from
(rfc2047-decode-string from
))
780 (setq len
(length from
))
781 (setq mch
(string-match "[@%]" from
))
783 (if (or (not mch
) (<= len
25))
784 (substring from
(max 0 (- len
25)))
786 (setq lo
(cond ((< (- mch
14) 0) 0)
790 (min len
(+ lo
25)))))))))
791 (concat (if (re-search-forward "^Subject:" nil t
)
793 (skip-chars-forward " \t")
796 (setq str
(buffer-substring pos
(1- (point))))
797 (while (looking-at "[ \t]")
798 (setq str
(concat str
" "
799 (buffer-substring (match-end 0)
800 (line-end-position))))
803 (re-search-forward "[\n][\n]+" nil t
)
804 (buffer-substring (point) (progn (end-of-line) (point))))
807 ;; Simple motion in a summary buffer.
809 (defun rmail-summary-next-all (&optional number
)
811 (or number
(setq number
1))
812 (forward-line number
)
813 ;; It doesn't look nice to move forward past the last message line.
814 (and (eobp) (> number
0)
816 (display-buffer rmail-buffer
))
818 (defun rmail-summary-previous-all (&optional number
)
820 (rmail-summary-next-all (- (or number
1))))
822 (defun rmail-summary-next-msg (&optional number
)
823 "Display next non-deleted msg from rmail file.
824 With optional prefix argument NUMBER, moves forward this number of non-deleted
825 messages, or backward if NUMBER is negative."
827 (or number
(setq number
1))
829 (and (> number
0) (end-of-line))
830 (let ((count (if (< number
0) (- number
) number
))
831 (search (if (> number
0) 're-search-forward
're-search-backward
))
832 (non-del-msg-found nil
))
833 (while (and (> count
0) (setq non-del-msg-found
834 (or (funcall search
"^.....[^D]" nil t
)
836 (setq count
(1- count
))))
838 (display-buffer rmail-buffer
))
840 (defun rmail-summary-previous-msg (&optional number
)
841 "Display previous non-deleted msg from rmail file.
842 With optional prefix argument NUMBER, moves backward this number of
843 non-deleted messages."
845 (rmail-summary-next-msg (- (or number
1))))
847 (defun rmail-summary-next-labeled-message (n labels
)
848 "Show next message with LABELS. Defaults to last labels used.
849 With prefix argument N moves forward N messages with these labels."
850 (interactive "p\nsMove to next msg with labels: ")
852 (with-current-buffer rmail-buffer
853 (rmail-next-labeled-message n labels
)
854 (setq msg rmail-current-message
))
855 (rmail-summary-goto-msg msg
)))
857 (defun rmail-summary-previous-labeled-message (n labels
)
858 "Show previous message with LABELS. Defaults to last labels used.
859 With prefix argument N moves backward N messages with these labels."
860 (interactive "p\nsMove to previous msg with labels: ")
862 (with-current-buffer rmail-buffer
863 (rmail-previous-labeled-message n labels
)
864 (setq msg rmail-current-message
))
865 (rmail-summary-goto-msg msg
)))
867 (defun rmail-summary-next-same-subject (n)
868 "Go to the next message in the summary having the same subject.
869 With prefix argument N, do this N times.
870 If N is negative, go backwards."
872 (let ((forward (> n
0))
874 (with-current-buffer rmail-buffer
875 (setq subject
(rmail-simplified-subject)
876 i rmail-current-message
))
883 (while (and (not done
)
887 ;; Advance thru summary.
888 (forward-line (if forward
1 -
1))
889 ;; Get msg number of this line.
890 (setq i
(string-to-number
891 (buffer-substring (point)
892 (min (point-max) (+ 6 (point))))))
893 (setq done
(string-equal subject
(rmail-simplified-subject i
))))
894 (if done
(setq found i
)))
895 (setq n
(if forward
(1- n
) (1+ n
)))))
897 (rmail-summary-goto-msg found
)
898 (error "No %s message with same subject"
899 (if forward
"following" "previous")))))
901 (defun rmail-summary-previous-same-subject (n)
902 "Go to the previous message in the summary having the same subject.
903 With prefix argument N, do this N times.
904 If N is negative, go forwards instead."
906 (rmail-summary-next-same-subject (- n
)))
908 ;; Delete and undelete summary commands.
910 (defun rmail-summary-delete-forward (&optional count
)
911 "Delete this message and move to next nondeleted one.
912 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
913 A prefix argument serves as a repeat count;
914 a negative argument means to delete and move backward."
916 (unless (numberp count
) (setq count
1))
918 (backward (< count
0)))
919 (while (and (/= count
0)
920 ;; Don't waste time if we are at the beginning
921 ;; and trying to go backward.
922 (not (and backward
(bobp))))
923 (rmail-summary-goto-msg)
924 (with-current-buffer rmail-buffer
925 (rmail-delete-message)
926 (setq del-msg rmail-current-message
))
927 (rmail-summary-mark-deleted del-msg
)
928 (while (and (not (if backward
(bobp) (eobp)))
929 (save-excursion (beginning-of-line)
930 (looking-at " *[0-9]+D")))
931 (forward-line (if backward -
1 1)))
933 (if (> count
0) (1- count
) (1+ count
)))
934 ;; It looks ugly to move to the empty line at end of buffer.
935 ;; And don't waste time after hitting the end.
936 (and (eobp) (not backward
)
937 (progn (setq count
0)
938 (forward-line -
1))))))
940 (defun rmail-summary-delete-backward (&optional count
)
941 "Delete this message and move to previous nondeleted one.
942 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
943 A prefix argument serves as a repeat count;
944 a negative argument means to delete and move forward."
946 (rmail-summary-delete-forward (- count
)))
948 (defun rmail-summary-mark-deleted (&optional n undel
)
949 (and n
(not (eq n
(rmail-summary-msg-number)))
950 ;; Since third arg is t, this only alters summary, not the Rmail buf.
951 (rmail-summary-goto-msg n t t
))
953 (not (overlay-get rmail-summary-overlay
'face
))
954 (let ((buffer-read-only nil
))
955 (skip-chars-forward " ")
956 (skip-chars-forward "0-9")
959 (progn (delete-char 1) (insert " ")))
962 ;; Discard cached new summary line.
963 (with-current-buffer rmail-buffer
964 (aset rmail-summary-vector
(1- n
) nil
))))
967 (defun rmail-summary-update-line (n)
968 "Update the summary line for message N."
969 (when (rmail-summary-goto-msg n t t
)
970 (let* ((buffer-read-only nil
)
971 (start (line-beginning-position))
972 (end (line-beginning-position 2))
973 (overlays (overlays-in start end
))
975 (while (and (setq ov
(car overlays
))
976 (not (setq high
(overlay-get ov
'rmail-summary
))))
977 (setq overlays
(cdr overlays
)))
978 (delete-region start end
)
980 (with-current-buffer rmail-buffer
981 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))
985 (rmail-summary-update-highlight nil
)))))
987 (defun rmail-summary-mark-undeleted (n)
988 (rmail-summary-mark-deleted n t
))
990 (defun rmail-summary-deleted-p (&optional n
)
992 (and n
(rmail-summary-goto-msg n nil t
))
993 (skip-chars-forward " ")
994 (skip-chars-forward "0-9")
997 (defun rmail-summary-undelete (&optional arg
)
998 "Undelete current message.
999 Optional prefix ARG means undelete ARG previous messages."
1002 (rmail-summary-undelete-many arg
)
1003 (let ((buffer-read-only nil
)
1006 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
1007 (replace-match "\\1 ")
1008 (rmail-summary-goto-msg)
1009 (if rmail-enable-mime
1010 (set-buffer rmail-buffer
)
1011 (rmail-pop-to-buffer rmail-buffer
))
1012 (and (rmail-message-deleted-p rmail-current-message
)
1013 (rmail-undelete-previous-message 1))
1014 (if rmail-enable-mime
1015 (rmail-pop-to-buffer rmail-buffer
))
1016 (rmail-pop-to-buffer rmail-summary-buffer
))
1017 (t (goto-char opoint
))))))
1019 (defun rmail-summary-undelete-many (&optional n
)
1020 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
1023 (while (and (> n
0) (not (eobp)))
1024 (rmail-summary-goto-msg)
1026 (when (rmail-summary-deleted-p)
1027 (with-current-buffer rmail-buffer
1028 (rmail-undelete-previous-message 1)
1029 (setq del-msg rmail-current-message
))
1030 (rmail-summary-mark-undeleted del-msg
)))
1031 (while (and (not (eobp))
1032 (save-excursion (beginning-of-line)
1033 (looking-at " *[0-9]+ ")))
1036 (rmail-summary-goto-msg 1)
1037 (dotimes (_ rmail-total-messages
)
1038 (rmail-summary-goto-msg)
1040 (when (rmail-summary-deleted-p)
1041 (with-current-buffer rmail-buffer
1042 (rmail-undelete-previous-message 1)
1043 (setq del-msg rmail-current-message
))
1044 (rmail-summary-mark-undeleted del-msg
)))
1048 ;; It looks ugly to move to the empty line at end of buffer.
1052 ;; Rmail Summary mode is suitable only for specially formatted data.
1053 (put 'rmail-summary-mode
'mode-class
'special
)
1055 (define-derived-mode rmail-summary-mode special-mode
"RMAIL Summary"
1056 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
1057 As commands are issued in the summary buffer, they are applied to the
1058 corresponding mail messages in the rmail buffer.
1060 All normal editing commands are turned off.
1061 Instead, nearly all the Rmail mode commands are available,
1062 though many of them move only among the messages in the summary.
1064 These additional commands exist:
1066 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
1067 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
1069 Commands for sorting the summary:
1071 \\[rmail-summary-sort-by-date] Sort by date.
1072 \\[rmail-summary-sort-by-subject] Sort by subject.
1073 \\[rmail-summary-sort-by-author] Sort by author.
1074 \\[rmail-summary-sort-by-recipient] Sort by recipient.
1075 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
1076 \\[rmail-summary-sort-by-lines] Sort by lines.
1077 \\[rmail-summary-sort-by-labels] Sort by labels."
1078 (setq truncate-lines t
)
1079 (setq buffer-read-only t
)
1080 (set-syntax-table text-mode-syntax-table
)
1081 (make-local-variable 'rmail-buffer
)
1082 (make-local-variable 'rmail-total-messages
)
1083 (make-local-variable 'rmail-current-message
)
1084 (setq rmail-current-message nil
)
1085 (make-local-variable 'rmail-summary-redo
)
1086 (setq rmail-summary-redo nil
)
1087 (make-local-variable 'revert-buffer-function
)
1088 (make-local-variable 'font-lock-defaults
)
1089 (setq font-lock-defaults
'(rmail-summary-font-lock-keywords t
))
1090 (rmail-summary-enable))
1092 ;; Summary features need to be disabled during edit mode.
1093 (defun rmail-summary-disable ()
1094 (use-local-map text-mode-map
)
1095 (remove-hook 'post-command-hook
'rmail-summary-rmail-update t
)
1096 (setq revert-buffer-function nil
))
1098 (defun rmail-summary-enable ()
1099 (use-local-map rmail-summary-mode-map
)
1100 (add-hook 'post-command-hook
'rmail-summary-rmail-update nil t
)
1101 (setq revert-buffer-function
'rmail-update-summary
))
1103 (defun rmail-summary-mark-seen (n &optional nomove unseen
)
1104 "Remove the unseen mark from the current message, update the summary vector.
1105 N is the number of the current message. Optional argument NOMOVE
1106 non-nil means we are already at the right column. Optional argument
1107 UNSEEN non-nil means mark the message as unseen."
1111 (skip-chars-forward " ")
1112 (skip-chars-forward "0-9"))
1113 (when (char-equal (following-char) (if unseen ?\s ?-
))
1114 (let ((buffer-read-only nil
))
1116 (insert (if unseen
"-" " ")))
1117 (let ((line (buffer-substring-no-properties (line-beginning-position)
1118 (line-beginning-position 2))))
1119 (with-current-buffer rmail-buffer
1120 (aset rmail-summary-vector
(1- n
) line
))))))
1122 (defvar rmail-summary-put-back-unseen nil
1123 "Used for communicating between calls to `rmail-summary-rmail-update'.
1124 If it moves to a message within an Incremental Search, and removes
1125 the `unseen' attribute from that message, it sets this flag
1126 so that if the next motion between messages is in the same Incremental
1127 Search, the `unseen' attribute is restored.")
1129 ;; Show in Rmail the message described by the summary line that point is on,
1130 ;; but only if the Rmail buffer is already visible.
1131 ;; This is a post-command-hook in summary buffers.
1132 (defun rmail-summary-rmail-update ()
1133 (let (buffer-read-only)
1135 ;; If at end of buffer, pretend we are on the last text line.
1139 (skip-chars-forward " ")
1140 ;; If the summary is empty, don't do anything.
1142 (let ((msg-num (string-to-number (buffer-substring
1144 (progn (skip-chars-forward "0-9")
1146 ;; Always leave `unseen' removed
1147 ;; if we get out of isearch mode.
1148 ;; Don't let a subsequent isearch restore that `unseen'.
1149 (if (not isearch-mode
)
1150 (setq rmail-summary-put-back-unseen nil
))
1152 (or (eq rmail-current-message msg-num
)
1153 (let ((window (get-buffer-window rmail-buffer t
))
1154 (owin (selected-window)))
1157 ;; If we first saw the previous message in this search,
1158 ;; and we have gone to a different message while searching,
1159 ;; put back `unseen' on the former one.
1160 (when rmail-summary-put-back-unseen
1161 (rmail-set-attribute rmail-unseen-attr-index t
1162 rmail-current-message
)
1164 (goto-char rmail-summary-put-back-unseen
)
1165 (rmail-summary-mark-seen rmail-current-message t t
)))
1166 ;; Arrange to do that later, for the new current message,
1167 ;; if it still has `unseen'.
1168 (setq rmail-summary-put-back-unseen
1169 (if (rmail-message-unseen-p msg-num
)
1171 (setq rmail-summary-put-back-unseen nil
))
1172 ;; Go to the desired message.
1173 (setq rmail-current-message msg-num
)
1174 ;; Update the summary to show the message has been seen.
1175 (rmail-summary-mark-seen msg-num t
)
1177 ;; Using save-window-excursion would cause the new value
1178 ;; of point to get lost.
1181 (select-window window
)
1182 (rmail-show-message msg-num t
))
1183 (select-window owin
))
1184 (if (buffer-name rmail-buffer
)
1185 (with-current-buffer rmail-buffer
1186 (rmail-show-message msg-num t
))))
1187 ;; In linum mode, the message buffer must be specially
1188 ;; updated (Bug#4878).
1189 (and (fboundp 'linum-update
)
1190 (buffer-name rmail-buffer
)
1191 (linum-update rmail-buffer
))))
1192 (rmail-summary-update-highlight nil
))))))
1194 (defun rmail-summary-save-buffer ()
1195 "Save the buffer associated with this RMAIL summary."
1197 (save-window-excursion
1199 (switch-to-buffer rmail-buffer
)
1202 (defun rmail-summary-mouse-goto-message (event)
1203 "Select the message whose summary line you click on."
1205 (goto-char (posn-point (event-end event
)))
1206 (rmail-summary-goto-msg))
1208 (defun rmail-summary-msg-number ()
1212 (buffer-substring (point)
1213 (min (point-max) (+ 6 (point)))))))
1215 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail
)
1216 "Go to message N in the summary buffer and the Rmail buffer.
1217 If N is nil, use the message corresponding to point in the summary
1218 and move to that message in the Rmail buffer.
1220 If NOWARN, don't say anything if N is out of range.
1221 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1222 Returns non-nil if message N was found."
1224 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1225 (if (eobp) (forward-line -
1))
1227 (let* ((obuf (current-buffer))
1231 (curmsg (string-to-number
1232 (buffer-substring (point)
1233 (min (point-max) (+ 6 (point))))))
1234 (total (with-current-buffer buf rmail-total-messages
)))
1235 ;; CURMSG should be nil when there's no current summary message
1236 ;; (for instance, if the summary is empty).
1239 ;; If message number N was specified, find that message's line
1240 ;; or set message-not-found.
1241 ;; If N wasn't specified or that message can't be found.
1242 ;; set N by default.
1246 (progn (message "No preceding message")
1248 (if (and (> n total
)
1250 (progn (message "No following message")
1251 (goto-char (point-max))
1252 (rmail-summary-goto-msg nil nowarn skip-rmail
)))
1253 (goto-char (point-min))
1254 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1255 (progn (or nowarn
(message "Message %d not found" n
))
1257 (setq message-not-found t
)
1259 ;; N can be nil now, along with CURMSG,
1260 ;; if the summary is empty.
1262 (rmail-summary-mark-seen n
)
1263 (rmail-summary-update-highlight message-not-found
)
1266 (let ((selwin (selected-window)))
1268 (progn (rmail-pop-to-buffer buf
)
1269 (rmail-show-message n
))
1270 (select-window selwin
)
1271 ;; The actions above can alter the current buffer. Preserve it.
1272 (set-buffer obuf
)))))
1273 (not message-not-found
)))
1275 ;; Update the highlighted line in an rmail summary buffer.
1276 ;; That should be current. We highlight the line point is on.
1277 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1278 (defun rmail-summary-update-highlight (not-found)
1279 ;; Make sure we have an overlay to use.
1280 (or rmail-summary-overlay
1282 (make-local-variable 'rmail-summary-overlay
)
1283 (setq rmail-summary-overlay
(make-overlay (point) (point)))
1284 (overlay-put rmail-summary-overlay
'rmail-summary t
)))
1285 ;; If this message is in the summary, use the overlay to highlight it.
1286 ;; Otherwise, don't highlight anything.
1288 (overlay-put rmail-summary-overlay
'face nil
)
1289 (move-overlay rmail-summary-overlay
1290 (save-excursion (beginning-of-line)
1291 (skip-chars-forward " ")
1293 (line-end-position))
1294 (overlay-put rmail-summary-overlay
'face
'highlight
)))
1296 (defun rmail-summary-scroll-msg-up (&optional dist
)
1297 "Scroll the Rmail window forward.
1298 If the Rmail window is displaying the end of a message,
1299 advance to the next message."
1302 (rmail-summary-scroll-msg-down nil
)
1303 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1304 (if rmail-buffer-window
1305 (if (let ((rmail-summary-window (selected-window)))
1306 (select-window rmail-buffer-window
)
1308 ;; Is EOB visible in the buffer?
1310 (let ((ht (window-height)))
1311 (move-to-window-line (- ht
2))
1314 (select-window rmail-summary-window
)))
1315 (if (not rmail-summary-scroll-between-messages
)
1316 (error "End of buffer")
1317 (rmail-summary-next-msg (or dist
1)))
1318 (let ((other-window-scroll-buffer rmail-buffer
))
1319 (scroll-other-window dist
)))
1320 ;; If it isn't visible at all, show the beginning.
1321 (rmail-summary-beginning-of-message)))))
1323 (defun rmail-summary-scroll-msg-down (&optional dist
)
1324 "Scroll the Rmail window backward.
1325 If the Rmail window is now displaying the beginning of a message,
1326 move to the previous message."
1329 (rmail-summary-scroll-msg-up nil
)
1330 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1331 (if rmail-buffer-window
1332 (if (let ((rmail-summary-window (selected-window)))
1333 (select-window rmail-buffer-window
)
1335 ;; Is BOB visible in the buffer?
1337 (move-to-window-line 0)
1340 (select-window rmail-summary-window
)))
1341 (if (not rmail-summary-scroll-between-messages
)
1342 (error "Beginning of buffer")
1343 (rmail-summary-previous-msg (or dist
1)))
1344 (let ((other-window-scroll-buffer rmail-buffer
))
1345 (scroll-other-window-down dist
)))
1346 ;; If it isn't visible at all, show the beginning.
1347 (rmail-summary-beginning-of-message)))))
1349 (defun rmail-summary-beginning-of-message ()
1350 "Show current message from the beginning."
1352 (rmail-summary-show-message 'BEG
))
1354 (defun rmail-summary-end-of-message ()
1355 "Show bottom of current message."
1357 (rmail-summary-show-message 'END
))
1359 (defun rmail-summary-show-message (where)
1360 "Show current mail message.
1361 Position it according to WHERE which can be BEG or END"
1362 (if (and (one-window-p) (not pop-up-frames
))
1363 ;; If there is just one window, put the summary on the top.
1364 (let ((buffer rmail-buffer
))
1365 (split-window (selected-window) rmail-summary-window-size
)
1366 (select-window (frame-first-window))
1367 (rmail-pop-to-buffer rmail-buffer
)
1368 ;; If pop-to-buffer did not use that window, delete that
1369 ;; window. (This can happen if it uses another frame.)
1370 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1371 (delete-other-windows)))
1372 (rmail-pop-to-buffer rmail-buffer
))
1375 (goto-char (point-min))
1376 (search-forward "\n\n"))
1378 (goto-char (point-max))
1379 (recenter (1- (window-height))))
1381 (rmail-pop-to-buffer rmail-summary-buffer
))
1383 (defun rmail-summary-bury ()
1384 "Bury the Rmail buffer and the Rmail summary buffer."
1386 (let ((buffer-to-bury (current-buffer)))
1388 (while (setq window
(get-buffer-window rmail-buffer
))
1389 (set-window-buffer window
(other-buffer rmail-buffer
)))
1390 (bury-buffer rmail-buffer
))
1391 (switch-to-buffer (other-buffer buffer-to-bury
))
1392 (bury-buffer buffer-to-bury
)))
1394 (defun rmail-summary-quit ()
1395 "Quit out of Rmail and Rmail summary."
1397 (rmail-summary-wipe)
1400 (defun rmail-summary-wipe ()
1401 "Kill and wipe away Rmail summary, remaining within Rmail."
1403 (with-current-buffer rmail-buffer
(setq rmail-summary-buffer nil
))
1404 (let ((local-rmail-buffer rmail-buffer
))
1405 (kill-buffer (current-buffer))
1406 ;; Delete window if not only one.
1407 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1409 ;; Switch windows to the rmail buffer, or switch to it in this window.
1410 (rmail-pop-to-buffer local-rmail-buffer
)))
1412 (defun rmail-summary-expunge ()
1413 "Actually erase all deleted messages and recompute summary headers."
1415 (with-current-buffer rmail-buffer
1416 (when (rmail-expunge-confirmed)
1417 (rmail-only-expunge)))
1418 (rmail-update-summary))
1420 (defun rmail-summary-expunge-and-save ()
1421 "Expunge and save RMAIL file."
1424 (rmail-expunge-and-save))
1425 (rmail-update-summary)
1426 (set-buffer-modified-p nil
))
1428 (defun rmail-summary-get-new-mail (&optional file-name
)
1429 "Get new mail and recompute summary headers.
1431 Optionally you can specify the file to get new mail from. In this case,
1432 the file of new mail is not changed or deleted. Noninteractively, you can
1433 pass the inbox file name as an argument. Interactively, a prefix
1434 argument says to read a file name and use that file as the inbox."
1436 (list (if current-prefix-arg
1437 (read-file-name "Get new mail from file: "))))
1439 (with-current-buffer rmail-buffer
1440 (rmail-get-new-mail file-name
)
1441 ;; Get the proper new message number.
1442 (setq msg rmail-current-message
))
1443 ;; Make sure that message is displayed.
1445 (rmail-summary-goto-msg msg
))))
1447 (defun rmail-summary-input (filename)
1448 "Run Rmail on file FILENAME."
1449 (interactive "FRun rmail on RMAIL file: ")
1450 ;; We switch windows here, then display the other Rmail file there.
1451 (rmail-pop-to-buffer rmail-buffer
)
1454 (defun rmail-summary-first-message ()
1455 "Show first message in Rmail file from summary buffer."
1458 (beginning-of-buffer)))
1460 (defun rmail-summary-last-message ()
1461 "Show last message in Rmail file from summary buffer."
1467 (declare-function rmail-abort-edit
"rmailedit" ())
1468 (declare-function rmail-cease-edit
"rmailedit"())
1469 (declare-function rmail-set-label
"rmailkwd" (l state
&optional n
))
1470 (declare-function rmail-output-read-file-name
"rmailout" ())
1471 (declare-function mail-send-and-exit
"sendmail" (&optional arg
))
1473 (defvar rmail-summary-edit-map nil
)
1474 (if rmail-summary-edit-map
1476 (setq rmail-summary-edit-map
1477 (nconc (make-sparse-keymap) text-mode-map
))
1478 (define-key rmail-summary-edit-map
"\C-c\C-c" 'rmail-cease-edit
)
1479 (define-key rmail-summary-edit-map
"\C-c\C-]" 'rmail-abort-edit
))
1481 (defun rmail-summary-edit-current-message ()
1482 "Edit the contents of this message."
1484 (rmail-pop-to-buffer rmail-buffer
)
1485 (rmail-edit-current-message)
1486 (use-local-map rmail-summary-edit-map
))
1488 (defun rmail-summary-cease-edit ()
1489 "Finish editing message, then go back to Rmail summary buffer."
1492 (rmail-pop-to-buffer rmail-summary-buffer
))
1494 (defun rmail-summary-abort-edit ()
1495 "Abort edit of current message; restore original contents.
1496 Go back to summary buffer."
1499 (rmail-pop-to-buffer rmail-summary-buffer
))
1501 (defun rmail-summary-search-backward (regexp &optional n
)
1502 "Show message containing next match for REGEXP.
1503 Prefix argument gives repeat count; negative argument means search
1504 backwards (through earlier messages).
1505 Interactively, empty argument means use same regexp used last time."
1507 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1509 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1513 (if rmail-search-last-regexp
1514 (concat ", default "
1515 rmail-search-last-regexp
"): ")
1517 (setq regexp
(read-string prompt
))
1518 (cond ((not (equal regexp
""))
1519 (setq rmail-search-last-regexp regexp
))
1520 ((not rmail-search-last-regexp
)
1521 (error "No previous Rmail search string")))
1522 (list rmail-search-last-regexp
1523 (prefix-numeric-value current-prefix-arg
))))
1524 ;; Don't use save-excursion because that prevents point from moving
1525 ;; properly in the summary buffer.
1526 (with-current-buffer rmail-buffer
1527 (rmail-search regexp
(- n
))))
1529 (defun rmail-summary-search (regexp &optional n
)
1530 "Show message containing next match for REGEXP.
1531 Prefix argument gives repeat count; negative argument means search
1532 backwards (through earlier messages).
1533 Interactively, empty argument means use same regexp used last time."
1535 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1537 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1541 (if rmail-search-last-regexp
1542 (concat ", default "
1543 rmail-search-last-regexp
"): ")
1545 (setq regexp
(read-string prompt
))
1546 (cond ((not (equal regexp
""))
1547 (setq rmail-search-last-regexp regexp
))
1548 ((not rmail-search-last-regexp
)
1549 (error "No previous Rmail search string")))
1550 (list rmail-search-last-regexp
1551 (prefix-numeric-value current-prefix-arg
))))
1552 ;; Don't use save-excursion because that prevents point from moving
1553 ;; properly in the summary buffer.
1554 (let ((buffer (current-buffer))
1555 (selwin (selected-window)))
1558 (rmail-pop-to-buffer rmail-buffer
)
1559 (rmail-search regexp n
))
1560 (select-window selwin
)
1561 (set-buffer buffer
))))
1563 (defun rmail-summary-toggle-header ()
1564 "Show original message header if pruned header currently shown, or vice versa."
1566 (save-window-excursion
1567 (set-buffer rmail-buffer
)
1568 (rmail-toggle-header))
1569 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1570 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1571 (let ((window (get-buffer-window rmail-buffer
)))
1573 ;; Using save-window-excursion would lose the new value of point.
1574 (let ((owin (selected-window)))
1577 (select-window window
)
1578 (goto-char (point-min)))
1579 (select-window owin
))))))
1582 (defun rmail-summary-add-label (label)
1583 "Add LABEL to labels associated with current Rmail message.
1584 Completion is performed over known labels when reading."
1585 (interactive (list (with-current-buffer rmail-buffer
1586 (rmail-read-label "Add label"))))
1587 (with-current-buffer rmail-buffer
1588 (rmail-add-label label
)))
1590 (defun rmail-summary-kill-label (label)
1591 "Remove LABEL from labels associated with current Rmail message.
1592 Completion is performed over known labels when reading."
1593 (interactive (list (with-current-buffer rmail-buffer
1594 (rmail-read-label "Kill label"))))
1595 (with-current-buffer rmail-buffer
1596 (rmail-set-label label nil
)))
1598 ;;;; *** Rmail Summary Mailing Commands ***
1600 (defun rmail-summary-override-mail-send-and-exit ()
1601 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1602 (use-local-map (copy-keymap (current-local-map)))
1603 (dolist (key (where-is-internal 'mail-send-and-exit
))
1604 (define-key (current-local-map) key
'rmail-summary-send-and-exit
)))
1606 (defun rmail-summary-mail ()
1607 "Send mail in another window.
1608 While composing the message, use \\[mail-yank-original] to yank the
1609 original message into it."
1611 (let ((window (get-buffer-window rmail-buffer
)))
1613 (select-window window
)
1614 (set-buffer rmail-buffer
)))
1615 (rmail-start-mail nil nil nil nil nil
(current-buffer))
1616 (rmail-summary-override-mail-send-and-exit))
1618 (defun rmail-summary-continue ()
1619 "Continue composing outgoing message previously being composed."
1621 (let ((window (get-buffer-window rmail-buffer
)))
1623 (select-window window
)
1624 (set-buffer rmail-buffer
)))
1625 (rmail-start-mail t
))
1627 (defun rmail-summary-reply (just-sender)
1628 "Reply to the current message.
1629 Normally include CC: to all other recipients of original message;
1630 prefix argument means ignore them. While composing the reply,
1631 use \\[mail-yank-original] to yank the original message into it."
1633 (let ((window (get-buffer-window rmail-buffer
)))
1635 (select-window window
)
1636 (set-buffer rmail-buffer
)))
1637 (rmail-reply just-sender
)
1638 (rmail-summary-override-mail-send-and-exit))
1640 (defun rmail-summary-retry-failure ()
1641 "Edit a mail message which is based on the contents of the current message.
1642 For a message rejected by the mail system, extract the interesting headers and
1643 the body of the original message; otherwise copy the current message."
1645 (let ((window (get-buffer-window rmail-buffer
)))
1647 (select-window window
)
1648 (set-buffer rmail-buffer
)))
1649 (rmail-retry-failure)
1650 (rmail-summary-override-mail-send-and-exit))
1652 (defun rmail-summary-send-and-exit ()
1653 "Send mail reply and return to summary buffer."
1655 (mail-send-and-exit t
))
1657 (defun rmail-summary-forward (resend)
1658 "Forward the current message to another user.
1659 With prefix argument, \"resend\" the message instead of forwarding it;
1660 see the documentation of `rmail-resend'."
1663 (let ((window (get-buffer-window rmail-buffer
)))
1665 (select-window window
)
1666 (set-buffer rmail-buffer
)))
1667 (rmail-forward resend
)
1668 (rmail-summary-override-mail-send-and-exit)))
1670 (defun rmail-summary-resend ()
1671 "Resend current message using `rmail-resend'."
1674 (let ((window (get-buffer-window rmail-buffer
)))
1676 (select-window window
)
1677 (set-buffer rmail-buffer
)))
1678 (call-interactively 'rmail-resend
)))
1680 ;; Summary output commands.
1682 (defun rmail-summary-output (&optional file-name n
)
1683 "Append this message to mail file FILE-NAME.
1684 This works with both mbox format and Babyl format files,
1685 outputting in the appropriate format for each.
1686 The default file name comes from `rmail-default-file',
1687 which is updated to the name you use in this command.
1689 A prefix argument N says to output that many consecutive messages
1690 from those in 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 command always outputs the complete message header,
1695 even the header display is currently pruned."
1697 (progn (require 'rmailout
)
1698 (list (rmail-output-read-file-name)
1699 (prefix-numeric-value current-prefix-arg
))))
1700 (let ((i 0) prev-msg
)
1703 (progn (rmail-summary-goto-msg)
1706 (with-current-buffer rmail-buffer
1707 rmail-current-message
))))))
1709 (with-current-buffer rmail-buffer
1710 (let ((rmail-delete-after-output nil
))
1711 (rmail-output file-name
1)))
1712 (if rmail-delete-after-output
1713 (rmail-summary-delete-forward nil
)
1715 (rmail-summary-next-msg 1))))))
1717 (defalias 'rmail-summary-output-to-rmail-file
'rmail-summary-output
)
1719 (declare-function rmail-output-as-seen
"rmailout"
1720 (file-name &optional count noattribute from-gnus
))
1722 (defun rmail-summary-output-as-seen (&optional file-name n
)
1723 "Append this message to mbox file named FILE-NAME.
1724 A prefix argument N says to output that many consecutive messages,
1725 from the summary, starting with the current one.
1726 Deleted messages are skipped and don't count.
1727 When called from Lisp code, N may be omitted and defaults to 1.
1729 This outputs the message header as you see it (or would see it)
1732 The default file name comes from `rmail-default-file',
1733 which is updated to the name you use in this command."
1735 (progn (require 'rmailout
)
1736 (list (rmail-output-read-file-name)
1737 (prefix-numeric-value current-prefix-arg
))))
1738 (require 'rmailout
) ; for rmail-output-as-seen in non-interactive case
1739 (let ((i 0) prev-msg
)
1742 (progn (rmail-summary-goto-msg)
1745 (with-current-buffer rmail-buffer
1746 rmail-current-message
))))))
1748 (with-current-buffer rmail-buffer
1749 (let ((rmail-delete-after-output nil
))
1750 (rmail-output-as-seen file-name
1)))
1751 (if rmail-delete-after-output
1752 (rmail-summary-delete-forward nil
)
1754 (rmail-summary-next-msg 1))))))
1756 (defun rmail-summary-output-menu ()
1757 "Output current message to another Rmail file, chosen with a menu.
1758 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1759 The variables `rmail-secondary-file-directory' and
1760 `rmail-secondary-file-regexp' control which files are offered in the menu."
1762 (with-current-buffer rmail-buffer
1763 (let ((rmail-delete-after-output nil
))
1764 (call-interactively 'rmail-output-menu
)))
1765 (if rmail-delete-after-output
1766 (rmail-summary-delete-forward nil
)))
1768 (defun rmail-summary-construct-io-menu ()
1769 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1772 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1773 (cons "Input Rmail File"
1774 (rmail-list-to-menu "Input Rmail File"
1776 'rmail-summary-input
)))
1777 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1778 (cons "Output Rmail File"
1779 (rmail-list-to-menu "Output Rmail File"
1781 'rmail-summary-output
))))
1782 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1783 '("Input Rmail File" . rmail-disable-menu
))
1784 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1785 '("Output Rmail File" . rmail-disable-menu
)))))
1787 (defun rmail-summary-output-body (&optional file-name
)
1788 "Write this message body to the file FILE-NAME.
1789 FILE-NAME defaults, interactively, from the Subject field of the message."
1791 (with-current-buffer rmail-buffer
1792 (let ((rmail-delete-after-output nil
))
1794 (rmail-output-body-to-file file-name
)
1795 (call-interactively 'rmail-output-body-to-file
))))
1796 (if rmail-delete-after-output
1797 (rmail-summary-delete-forward nil
)))
1799 ;; Sorting messages in Rmail Summary buffer.
1801 (defun rmail-summary-sort-by-date (reverse)
1802 "Sort messages of current Rmail summary by \"Date\" header.
1803 If prefix argument REVERSE is non-nil, sorts in reverse order."
1805 (rmail-sort-from-summary (function rmail-sort-by-date
) reverse
))
1807 (defun rmail-summary-sort-by-subject (reverse)
1808 "Sort messages of current Rmail summary by \"Subject\" header.
1809 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
1810 non-nil, sorts in reverse order."
1812 (rmail-sort-from-summary (function rmail-sort-by-subject
) reverse
))
1814 (defun rmail-summary-sort-by-author (reverse)
1815 "Sort messages of current Rmail summary by author.
1816 This uses either the \"From\" or \"Sender\" header, downcased.
1817 If prefix argument REVERSE is non-nil, sorts in reverse order."
1819 (rmail-sort-from-summary (function rmail-sort-by-author
) reverse
))
1821 (defun rmail-summary-sort-by-recipient (reverse)
1822 "Sort messages of current Rmail summary by recipient.
1823 This uses either the \"To\" or \"Apparently-To\" header, downcased.
1824 If prefix argument REVERSE is non-nil, sorts in reverse order."
1826 (rmail-sort-from-summary (function rmail-sort-by-recipient
) reverse
))
1828 (defun rmail-summary-sort-by-correspondent (reverse)
1829 "Sort messages of current Rmail summary by other correspondent.
1830 This uses either the \"From\", \"Sender\", \"To\", or
1831 \"Apparently-To\" header, downcased. Uses the first header not
1832 excluded by `mail-dont-reply-to-names'. If prefix argument
1833 REVERSE is non-nil, sorts in reverse order."
1835 (rmail-sort-from-summary (function rmail-sort-by-correspondent
) reverse
))
1837 (defun rmail-summary-sort-by-lines (reverse)
1838 "Sort messages of current Rmail summary by the number of lines.
1839 If prefix argument REVERSE is non-nil, sorts in reverse order."
1841 (rmail-sort-from-summary (function rmail-sort-by-lines
) reverse
))
1843 (defun rmail-summary-sort-by-labels (reverse labels
)
1844 "Sort messages of current Rmail summary by labels.
1845 LABELS is a comma-separated list of labels.
1846 If prefix argument REVERSE is non-nil, sorts in reverse order."
1847 (interactive "P\nsSort by labels: ")
1848 (rmail-sort-from-summary
1849 (lambda (reverse) (rmail-sort-by-labels reverse labels
))
1852 (defun rmail-sort-from-summary (sortfun reverse
)
1853 "Sort the Rmail buffer using sorting function SORTFUN.
1854 Passes REVERSE to SORTFUN as its sole argument. Then regenerates
1855 the summary. Note that the whole Rmail buffer is sorted, even if
1856 the summary is only showing a subset of messages."
1857 (require 'rmailsort
)
1858 (let ((selwin (selected-window)))
1860 (progn (rmail-pop-to-buffer rmail-buffer
)
1861 (funcall sortfun reverse
))
1862 (select-window selwin
))))
1867 ;; generated-autoload-file: "rmail-loaddefs.el"
1870 ;;; rmailsum.el ends here