1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993-1996, 2000-2015 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 <http://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 ignore)
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 "\\)\\(,\\|\\'\\)")))
291 ;; FIXME "a string of regexps separated by commas" makes no sense because:
292 ;; i) it's pointless (you can just use \\|)
293 ;; ii) it's broken (you can't specify a literal comma)
294 ;; rmail-summary-by-topic and rmail-summary-by-senders have the same issue.
296 (defun rmail-summary-by-recipients (recipients &optional primary-only)
297 "Display a summary of all messages with the given RECIPIENTS.
298 Normally checks the To, From and Cc fields of headers;
299 but if PRIMARY-ONLY is non-nil (prefix arg given),
300 only look in the To and From fields.
301 RECIPIENTS is a string of regexps separated by commas."
302 (interactive "sRecipients to summarize by: \nP")
304 (concat "recipients " recipients)
305 (list 'rmail-summary-by-recipients recipients primary-only)
306 'rmail-message-recipients-p
307 (mail-comma-list-regexp recipients) primary-only))
309 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
310 (rmail-apply-in-message msg 'rmail-message-recipients-p-1
311 recipients primary-only))
313 (defun rmail-message-recipients-p-1 (recipients &optional primary-only)
314 ;; mail-fetch-field does not care where it starts from.
315 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
316 (or (string-match recipients (or (mail-fetch-field "To") ""))
317 (string-match recipients (or (mail-fetch-field "From") ""))
318 (if (not primary-only)
319 (string-match recipients (or (mail-fetch-field "Cc") "")))))
321 ;; FIXME I find this a non-obvious name for what this function does.
322 ;; Also, the optional WHOLE-MESSAGE argument of r-s-by-topic would
323 ;; seem more natural here.
325 (defun rmail-summary-by-regexp (regexp)
326 "Display a summary of all messages according to regexp REGEXP.
327 If the regular expression is found in the header of the message
328 \(including in the date and other lines, as well as the subject line),
329 Emacs will list the message in the summary."
330 (interactive "sRegexp to summarize by: ")
331 (if (string= regexp "")
332 (setq regexp (or rmail-last-regexp
333 (error "No regexp specified"))))
334 (setq rmail-last-regexp regexp)
335 (rmail-new-summary (concat "regexp " regexp)
336 (list 'rmail-summary-by-regexp regexp)
337 'rmail-message-regexp-p
340 (defun rmail-message-regexp-p (msg regexp)
341 "Return t, if for message number MSG, regexp REGEXP matches in the header."
342 (rmail-apply-in-message msg 'rmail-message-regexp-p-1 msg regexp))
344 (defun rmail-message-regexp-p-1 (msg regexp)
345 ;; Search functions can expect to start from the beginning.
346 (narrow-to-region (point) (save-excursion (search-forward "\n\n") (point)))
347 (if (and rmail-enable-mime
348 rmail-search-mime-header-function)
349 (funcall rmail-search-mime-header-function msg regexp (point))
350 (re-search-forward regexp nil t)))
353 (defun rmail-summary-by-topic (subject &optional whole-message)
354 "Display a summary of all messages with the given SUBJECT.
355 Normally checks just the Subject field of headers; but with prefix
356 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
357 SUBJECT is a string of regexps separated by commas."
359 ;; We quote the default subject, because if it contains regexp
360 ;; special characters (eg "?"), it can fail to match itself. (Bug#2333)
361 (let* ((subject (regexp-quote (rmail-simplified-subject)))
362 (prompt (concat "Topics to summarize by (regexp"
363 (if subject ", default current subject" "")
365 (list (read-string prompt nil nil subject) current-prefix-arg)))
367 (concat "about " subject)
368 (list 'rmail-summary-by-topic subject whole-message)
369 'rmail-message-subject-p
370 (mail-comma-list-regexp subject) whole-message))
372 (defun rmail-message-subject-p (msg subject &optional whole-message)
374 (rmail-apply-in-message msg 're-search-forward subject nil t)
375 (string-match subject (rmail-simplified-subject msg))))
378 (defun rmail-summary-by-senders (senders)
379 "Display a summary of all messages whose \"From\" field matches SENDERS.
380 SENDERS is a string of regexps separated by commas."
381 (interactive "sSenders to summarize by: ")
383 (concat "senders " senders)
384 (list 'rmail-summary-by-senders senders)
385 'rmail-message-senders-p
386 (mail-comma-list-regexp senders)))
388 (defun rmail-message-senders-p (msg senders)
389 (string-match senders (or (rmail-get-header "From" msg) "")))
391 ;; General making of a summary buffer.
393 (defvar rmail-summary-symbol-number 0)
395 (defvar rmail-new-summary-line-count)
397 (defun rmail-new-summary (desc redo function &rest args)
398 "Create a summary of selected messages.
399 DESC makes part of the mode line of the summary buffer.
400 REDO is what to put in `rmail-summary-redo'; usually
401 its car is the function that called `rmail-new-summary'
402 and its cdr is the arguments passed to that function.
404 For each message, applies FUNCTION to the message number and ARGS...,
405 and if the result is non-nil, it includes that message in the summary.
406 If FUNCTION is nil, includes all messages."
407 (message "Computing summary lines...")
409 (error "No RMAIL buffer found"))
410 (let (mesg was-in-summary sumbuf)
411 (if (derived-mode-p 'rmail-summary-mode)
412 (setq was-in-summary t))
413 (with-current-buffer rmail-buffer
414 (setq rmail-summary-buffer (rmail-new-summary-1 desc redo function args)
415 ;; r-s-b is buffer-local.
416 sumbuf rmail-summary-buffer
417 mesg rmail-current-message))
418 ;; Now display the summary buffer and go to the right place in it.
419 (unless was-in-summary
420 (if (and (one-window-p)
423 ;; If there is just one window, put the summary on the top.
425 (split-window (selected-window) rmail-summary-window-size)
426 (select-window (next-window (frame-first-window)))
427 (rmail-pop-to-buffer sumbuf)
428 ;; If pop-to-buffer did not use that window, delete that
429 ;; window. (This can happen if it uses another frame.)
430 (if (not (eq sumbuf (window-buffer (frame-first-window))))
431 (delete-other-windows)))
432 (rmail-pop-to-buffer sumbuf))
433 (set-buffer rmail-buffer)
434 ;; This is how rmail makes the summary buffer reappear.
435 ;; We do this here to make the window the proper size.
436 (rmail-select-summary nil)
438 (rmail-summary-goto-msg mesg t t)
439 (rmail-summary-construct-io-menu)
440 (message "Computing summary lines...done")))
442 (defun rmail-new-summary-1 (description redo function args)
443 "Filter messages to obtain summary lines.
444 DESCRIPTION is added to the mode line.
446 Return the summary buffer by invoking FUNCTION on each message
447 passing the message number and ARGS.
449 REDO is what to put in `rmail-summary-redo'.
451 The current buffer must be a Rmail buffer either containing a
452 collection of mbox formatted messages or displaying a single
454 (let ((summary-msgs ())
455 (rmail-new-summary-line-count 0)
456 (sumbuf (rmail-get-create-summary-buffer)))
457 ;; Scan the messages, getting their summary strings
458 ;; and putting the list of them in SUMMARY-MSGS.
460 (main-buffer (current-buffer))
461 (total rmail-total-messages)
462 (inhibit-read-only t))
464 ;; Go where the mbox text is.
465 (if (rmail-buffers-swapped-p)
466 (set-buffer rmail-view-buffer))
467 (let ((old-min (point-min-marker))
468 (old-max (point-max-marker)))
470 ;; Can't use save-restriction here; that doesn't work if we
471 ;; plan to modify text outside the original restriction.
474 (goto-char (point-min))
475 (while (>= total msgnum)
476 ;; Go back to the Rmail buffer so FUNCTION and
477 ;; rmail-get-summary can see its local vars.
478 (with-current-buffer main-buffer
479 ;; First test whether to include this message.
480 (if (or (null function)
481 (apply function msgnum args))
483 (cons (cons msgnum (rmail-get-summary msgnum))
485 (setq msgnum (1+ msgnum))
486 ;; Provide a periodic User progress message.
487 (if (and (not (zerop rmail-new-summary-line-count))
488 (zerop (% rmail-new-summary-line-count 10)))
489 (message "Computing summary lines...%d"
490 rmail-new-summary-line-count)))
491 (setq summary-msgs (nreverse summary-msgs)))
492 (narrow-to-region old-min old-max)))))
493 ;; Temporarily, while summary buffer is unfinished,
494 ;; we "don't have" a summary.
495 (setq rmail-summary-buffer nil)
496 ;; I have not a clue what this clause is doing. If you read this
497 ;; chunk of code and have a clue, then please write it here.
498 (if rmail-enable-mime
499 (with-current-buffer rmail-buffer
500 (setq rmail-summary-buffer nil)))
502 (let ((rbuf (current-buffer))
503 (total rmail-total-messages))
505 ;; Set up the summary buffer's contents.
506 (let ((buffer-read-only nil))
509 (princ (cdr (car summary-msgs)) sumbuf)
510 (setq summary-msgs (cdr summary-msgs)))
511 (goto-char (point-min)))
512 ;; Set up the rest of its state and local variables.
513 (setq buffer-read-only t)
515 (make-local-variable 'minor-mode-alist)
516 (setq minor-mode-alist (list (list t (concat ": " description))))
517 (setq rmail-buffer rbuf
518 rmail-summary-redo redo
519 rmail-total-messages total)))
522 (defun rmail-get-create-summary-buffer ()
523 "Return the Rmail summary buffer.
524 If necessary, it is created and undo is disabled."
525 (if (and rmail-summary-buffer (buffer-name rmail-summary-buffer))
527 (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
528 (with-current-buffer buff
529 (setq buffer-undo-list t))
533 ;; Low levels of generating a summary.
535 (defun rmail-get-summary (msgnum)
536 "Return the summary line for message MSGNUM.
537 The mbox buffer must be current when you call this function
538 even if its text is swapped.
540 If the message has a summary line already, it will be stored in
541 the message as a header and simply returned, otherwise the
542 summary line is created, saved in the message header, cached and
545 The current buffer contains the unrestricted message collection."
546 (let ((line (aref rmail-summary-vector (1- msgnum))))
548 ;; Register a summary line for MSGNUM.
549 (setq rmail-new-summary-line-count (1+ rmail-new-summary-line-count)
550 line (rmail-create-summary-line msgnum))
551 ;; Cache the summary line for use during this Rmail session.
552 (aset rmail-summary-vector (1- msgnum) line))
555 (defcustom rmail-summary-line-decoder (function rfc2047-decode-string)
556 "Function to decode a Rmail summary line.
557 It receives the summary line for one message as a string
558 and should return the decoded string.
560 By default, it is `rfc2047-decode-string', which decodes MIME-encoded
564 :group 'rmail-summary)
566 (defun rmail-create-summary-line (msgnum)
567 "Return the summary line for message MSGNUM.
568 Obtain the message summary from the header if it is available
569 otherwise create it and store it in the message header.
571 The mbox buffer must be current when you call this function
572 even if its text is swapped."
573 (let ((beg (rmail-msgbeg msgnum))
574 (end (rmail-msgend msgnum))
575 (deleted (rmail-message-deleted-p msgnum))
576 ;; Does not work (swapped?)
577 ;;; (unseen (rmail-message-unseen-p msgnum))
580 ;; Switch to the buffer that has the whole mbox text.
581 (if (rmail-buffers-swapped-p)
582 (set-buffer rmail-view-buffer))
583 ;; Now we can compute the line count.
584 (if rmail-summary-line-count-flag
585 (setq lines (count-lines beg end)))
586 ;; Narrow to the message header.
591 (if (search-forward "\n\n" end t)
593 (narrow-to-region beg (point))
594 ;; Replace rmail-message-unseen-p from above.
596 (setq unseen (and (search-forward
597 (concat rmail-attribute-header ": ") nil t)
598 (looking-at "......U")))
599 ;; Generate a status line from the message.
600 (rmail-create-summary msgnum deleted unseen lines))
601 (rmail-error-bad-format msgnum)))))))
603 ;; FIXME this is now unused.
604 ;; The intention was to display in the summary something like {E}
605 ;; for an edited messaged, similarly for answered, etc.
606 ;; But that conflicts with the previous rmail usage, where
607 ;; any user-defined { labels } occupied this space.
608 ;; So whilst it would be nice to have this information in the summary,
609 ;; it would need to go somewhere else.
610 (defun rmail-get-summary-status ()
611 "Return a coded string wrapped in curly braces denoting the status.
613 The current buffer must already be narrowed to the message headers for
614 the message being processed."
615 (let ((status (mail-fetch-field rmail-attribute-header))
619 ;; Strip off the read/unread and the deleted attribute which are
620 ;; handled separately.
623 (concat (substring status 0 1) (substring status 2 6))
625 (while (< index (length status))
626 (unless (string= "-" (setq char (substring status index (1+ index))))
627 (setq result (concat result char)))
628 (setq index (1+ index)))
629 (when (> (length result) 0)
630 (setq result (concat "{" result "}")))
633 (autoload 'rmail-make-label "rmailkwd")
635 (defun rmail-get-summary-labels ()
636 "Return a string wrapped in curly braces with the current message labels.
637 Returns nil if there are no labels. The current buffer must
638 already be narrowed to the message headers for the message being
640 (let ((labels (mail-fetch-field rmail-keyword-header)))
642 (not (string-equal labels ""))
644 ;; Intern so that rmail-read-label can offer completion.
645 (mapc 'rmail-make-label (split-string labels ", "))
646 (format "{ %s } " labels)))))
648 (defun rmail-create-summary (msgnum deleted unseen lines)
649 "Return the summary line for message MSGNUM.
650 The current buffer should already be narrowed to the header for that message.
651 It could be either buffer, so don't access Rmail local variables.
652 DELETED is t if this message is marked deleted.
653 UNSEEN is t if it is marked unseen.
654 LINES is the number of lines in the message (if we should display that)
656 (goto-char (point-min))
657 (let ((line (rmail-header-summary))
658 (labels (rmail-get-summary-labels))
659 pos status prefix basic-start basic-end linecount-string)
661 (setq linecount-string
664 ((<= lines 9) (format " [%d]" lines))
665 ((<= lines 99) (format " [%d]" lines))
666 ((<= lines 999) (format " [%d]" lines))
667 ((<= lines 9999) (format " [%dk]" (/ lines 1000)))
668 ((<= lines 99999) (format " [%dk]" (/ lines 1000)))
669 (t (format "[%dk]" (/ lines 1000)))))
675 prefix (format "%5d%c " msgnum status)
676 basic-start (car line)
677 basic-end (cadr line))
678 (funcall rmail-summary-line-decoder
679 (concat prefix basic-start linecount-string " "
682 (defun rmail-header-summary ()
683 "Return a message summary based on the message headers.
684 The value is a list of two strings, the first and second parts of the summary.
686 The current buffer must already be narrowed to the message headers for
687 the message being processed."
688 (goto-char (point-min))
690 (concat (save-excursion
691 (if (not (re-search-forward "^Date:" nil t))
693 ;; Match month names case-insensitively
694 (cond ((let ((case-fold-search t))
695 (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
696 (line-end-position) t))
698 (string-to-number (buffer-substring
702 (match-beginning 4) (match-end 4))))
703 ((let ((case-fold-search t))
704 (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
705 (line-end-position) t))
707 (string-to-number (buffer-substring
711 (match-beginning 2) (match-end 2))))
712 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
713 (line-end-position) t)
716 (match-beginning 2) (match-end 2))
718 (match-beginning 3) (match-end 3))
720 (match-beginning 4) (match-end 4))))
724 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t)
725 (mail-strip-quoted-names
728 ;; Get all the lines of the From field
729 ;; so that we get a whole comment if there is one,
730 ;; so that mail-strip-quoted-names can discard it.
731 (let ((opoint (point)))
732 (while (progn (forward-line 1)
733 (looking-at "[ \t]")))
734 ;; Back up over newline, then trailing spaces or tabs
736 (skip-chars-backward " \t")
741 (or rmail-user-mail-address-regexp
743 (regexp-quote (user-login-name))
746 ;; Don't lose if run from init file
747 ;; where user-mail-address is not
749 (or user-mail-address
750 (concat (user-login-name) "@"
751 (or mail-host-address
755 ;; No From field, or it's this user.
757 (goto-char (point-min))
758 (if (not (re-search-forward "^To:[ \t]*" nil t))
762 (mail-strip-quoted-names
766 (skip-chars-backward " \t")
770 ;; We are going to return only 25 characters of the
771 ;; address, so make sure it is RFC2047 decoded before
772 ;; taking its substring. This is important when the address is not on the same line as the name, e.g.:
773 ;; To: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?=
774 ;; <stepnem@gmail.com>
775 (setq from (rfc2047-decode-string from))
776 (setq len (length from))
777 (setq mch (string-match "[@%]" from))
779 (if (or (not mch) (<= len 25))
780 (substring from (max 0 (- len 25)))
782 (setq lo (cond ((< (- mch 14) 0) 0)
786 (min len (+ lo 25)))))))))
787 (concat (if (re-search-forward "^Subject:" nil t)
789 (skip-chars-forward " \t")
792 (setq str (buffer-substring pos (1- (point))))
793 (while (looking-at "[ \t]")
794 (setq str (concat str " "
795 (buffer-substring (match-end 0)
796 (line-end-position))))
799 (re-search-forward "[\n][\n]+" nil t)
800 (buffer-substring (point) (progn (end-of-line) (point))))
803 ;; Simple motion in a summary buffer.
805 (defun rmail-summary-next-all (&optional number)
807 (or number (setq number 1))
808 (forward-line number)
809 ;; It doesn't look nice to move forward past the last message line.
810 (and (eobp) (> number 0)
812 (display-buffer rmail-buffer))
814 (defun rmail-summary-previous-all (&optional number)
816 (or number (setq number 1))
817 (forward-line (- number))
818 ;; It doesn't look nice to move forward past the last message line.
819 (and (eobp) (< number 0)
821 (display-buffer rmail-buffer))
823 (defun rmail-summary-next-msg (&optional number)
824 "Display next non-deleted msg from rmail file.
825 With optional prefix argument NUMBER, moves forward this number of non-deleted
826 messages, or backward if NUMBER is negative."
828 (or number (setq number 1))
830 (and (> number 0) (end-of-line))
831 (let ((count (if (< number 0) (- number) number))
832 (search (if (> number 0) 're-search-forward 're-search-backward))
833 (non-del-msg-found nil))
834 (while (and (> count 0) (setq non-del-msg-found
835 (or (funcall search "^.....[^D]" nil t)
837 (setq count (1- count))))
839 (display-buffer rmail-buffer))
841 (defun rmail-summary-previous-msg (&optional number)
842 "Display previous non-deleted msg from rmail file.
843 With optional prefix argument NUMBER, moves backward this number of
844 non-deleted messages."
846 (rmail-summary-next-msg (- (if number number 1))))
848 (defun rmail-summary-next-labeled-message (n labels)
849 "Show next message with LABELS. Defaults to last labels used.
850 With prefix argument N moves forward N messages with these labels."
851 (interactive "p\nsMove to next msg with labels: ")
853 (with-current-buffer rmail-buffer
854 (rmail-next-labeled-message n labels)
855 (setq msg rmail-current-message))
856 (rmail-summary-goto-msg msg)))
858 (defun rmail-summary-previous-labeled-message (n labels)
859 "Show previous message with LABELS. Defaults to last labels used.
860 With prefix argument N moves backward N messages with these labels."
861 (interactive "p\nsMove to previous msg with labels: ")
863 (with-current-buffer rmail-buffer
864 (rmail-previous-labeled-message n labels)
865 (setq msg rmail-current-message))
866 (rmail-summary-goto-msg msg)))
868 (defun rmail-summary-next-same-subject (n)
869 "Go to the next message in the summary having the same subject.
870 With prefix argument N, do this N times.
871 If N is negative, go backwards."
873 (let ((forward (> n 0))
875 (with-current-buffer rmail-buffer
876 (setq subject (rmail-simplified-subject)
877 i rmail-current-message))
884 (while (and (not done)
888 ;; Advance thru summary.
889 (forward-line (if forward 1 -1))
890 ;; Get msg number of this line.
891 (setq i (string-to-number
892 (buffer-substring (point)
893 (min (point-max) (+ 6 (point))))))
894 (setq done (string-equal subject (rmail-simplified-subject i))))
895 (if done (setq found i)))
896 (setq n (if forward (1- n) (1+ n)))))
898 (rmail-summary-goto-msg found)
899 (error "No %s message with same subject"
900 (if forward "following" "previous")))))
902 (defun rmail-summary-previous-same-subject (n)
903 "Go to the previous message in the summary having the same subject.
904 With prefix argument N, do this N times.
905 If N is negative, go forwards instead."
907 (rmail-summary-next-same-subject (- n)))
909 ;; Delete and undelete summary commands.
911 (defun rmail-summary-delete-forward (&optional count)
912 "Delete this message and move to next nondeleted one.
913 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
914 A prefix argument serves as a repeat count;
915 a negative argument means to delete and move backward."
917 (unless (numberp count) (setq count 1))
919 (backward (< count 0)))
920 (while (and (/= count 0)
921 ;; Don't waste time if we are at the beginning
922 ;; and trying to go backward.
923 (not (and backward (bobp))))
924 (rmail-summary-goto-msg)
925 (with-current-buffer rmail-buffer
926 (rmail-delete-message)
927 (setq del-msg rmail-current-message))
928 (rmail-summary-mark-deleted del-msg)
929 (while (and (not (if backward (bobp) (eobp)))
930 (save-excursion (beginning-of-line)
931 (looking-at " *[0-9]+D")))
932 (forward-line (if backward -1 1)))
934 (if (> count 0) (1- count) (1+ count)))
935 ;; It looks ugly to move to the empty line at end of buffer.
936 ;; And don't waste time after hitting the end.
937 (and (eobp) (not backward)
938 (progn (setq count 0)
939 (forward-line -1))))))
941 (defun rmail-summary-delete-backward (&optional count)
942 "Delete this message and move to previous nondeleted one.
943 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
944 A prefix argument serves as a repeat count;
945 a negative argument means to delete and move forward."
947 (rmail-summary-delete-forward (- count)))
949 (defun rmail-summary-mark-deleted (&optional n undel)
950 (and n (not (eq n (rmail-summary-msg-number)))
951 ;; Since third arg is t, this only alters summary, not the Rmail buf.
952 (rmail-summary-goto-msg n t t))
954 (not (overlay-get rmail-summary-overlay 'face))
955 (let ((buffer-read-only nil))
956 (skip-chars-forward " ")
957 (skip-chars-forward "0-9")
960 (progn (delete-char 1) (insert " ")))
963 ;; Discard cached new summary line.
964 (with-current-buffer rmail-buffer
965 (aset rmail-summary-vector (1- n) nil))))
968 (defun rmail-summary-update-line (n)
969 "Update the summary line for message N."
970 (when (rmail-summary-goto-msg n t t)
971 (let* ((buffer-read-only nil)
972 (start (line-beginning-position))
973 (end (line-beginning-position 2))
974 (overlays (overlays-in start end))
976 (while (and (setq ov (car overlays))
977 (not (setq high (overlay-get ov 'rmail-summary))))
978 (setq overlays (cdr overlays)))
979 (delete-region start end)
981 (with-current-buffer rmail-buffer
982 (aset rmail-summary-vector (1- n) (rmail-create-summary-line n)))
986 (rmail-summary-update-highlight nil)))))
988 (defun rmail-summary-mark-undeleted (n)
989 (rmail-summary-mark-deleted n t))
991 (defun rmail-summary-deleted-p (&optional n)
993 (and n (rmail-summary-goto-msg n nil t))
994 (skip-chars-forward " ")
995 (skip-chars-forward "0-9")
998 (defun rmail-summary-undelete (&optional arg)
999 "Undelete current message.
1000 Optional prefix ARG means undelete ARG previous messages."
1003 (rmail-summary-undelete-many arg)
1004 (let ((buffer-read-only nil)
1007 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
1008 (replace-match "\\1 ")
1009 (rmail-summary-goto-msg)
1010 (if rmail-enable-mime
1011 (set-buffer rmail-buffer)
1012 (rmail-pop-to-buffer rmail-buffer))
1013 (and (rmail-message-deleted-p rmail-current-message)
1014 (rmail-undelete-previous-message 1))
1015 (if rmail-enable-mime
1016 (rmail-pop-to-buffer rmail-buffer))
1017 (rmail-pop-to-buffer rmail-summary-buffer))
1018 (t (goto-char opoint))))))
1020 (defun rmail-summary-undelete-many (&optional n)
1021 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
1024 (while (and (> n 0) (not (eobp)))
1025 (rmail-summary-goto-msg)
1027 (when (rmail-summary-deleted-p)
1028 (with-current-buffer rmail-buffer
1029 (rmail-undelete-previous-message 1)
1030 (setq del-msg rmail-current-message))
1031 (rmail-summary-mark-undeleted del-msg)))
1032 (while (and (not (eobp))
1033 (save-excursion (beginning-of-line)
1034 (looking-at " *[0-9]+ ")))
1037 (rmail-summary-goto-msg 1)
1038 (dotimes (i rmail-total-messages)
1039 (rmail-summary-goto-msg)
1041 (when (rmail-summary-deleted-p)
1042 (with-current-buffer rmail-buffer
1043 (rmail-undelete-previous-message 1)
1044 (setq del-msg rmail-current-message))
1045 (rmail-summary-mark-undeleted del-msg)))
1049 ;; It looks ugly to move to the empty line at end of buffer.
1053 ;; Rmail Summary mode is suitable only for specially formatted data.
1054 (put 'rmail-summary-mode 'mode-class 'special)
1056 (define-derived-mode rmail-summary-mode special-mode "RMAIL Summary"
1057 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
1058 As commands are issued in the summary buffer, they are applied to the
1059 corresponding mail messages in the rmail buffer.
1061 All normal editing commands are turned off.
1062 Instead, nearly all the Rmail mode commands are available,
1063 though many of them move only among the messages in the summary.
1065 These additional commands exist:
1067 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
1068 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
1070 Commands for sorting the summary:
1072 \\[rmail-summary-sort-by-date] Sort by date.
1073 \\[rmail-summary-sort-by-subject] Sort by subject.
1074 \\[rmail-summary-sort-by-author] Sort by author.
1075 \\[rmail-summary-sort-by-recipient] Sort by recipient.
1076 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
1077 \\[rmail-summary-sort-by-lines] Sort by lines.
1078 \\[rmail-summary-sort-by-labels] Sort by labels."
1079 (setq truncate-lines t)
1080 (setq buffer-read-only t)
1081 (set-syntax-table text-mode-syntax-table)
1082 (make-local-variable 'rmail-buffer)
1083 (make-local-variable 'rmail-total-messages)
1084 (make-local-variable 'rmail-current-message)
1085 (setq rmail-current-message nil)
1086 (make-local-variable 'rmail-summary-redo)
1087 (setq rmail-summary-redo nil)
1088 (make-local-variable 'revert-buffer-function)
1089 (make-local-variable 'font-lock-defaults)
1090 (setq font-lock-defaults '(rmail-summary-font-lock-keywords t))
1091 (rmail-summary-enable))
1093 ;; Summary features need to be disabled during edit mode.
1094 (defun rmail-summary-disable ()
1095 (use-local-map text-mode-map)
1096 (remove-hook 'post-command-hook 'rmail-summary-rmail-update t)
1097 (setq revert-buffer-function nil))
1099 (defun rmail-summary-enable ()
1100 (use-local-map rmail-summary-mode-map)
1101 (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
1102 (setq revert-buffer-function 'rmail-update-summary))
1104 (defun rmail-summary-mark-seen (n &optional nomove unseen)
1105 "Remove the unseen mark from the current message, update the summary vector.
1106 N is the number of the current message. Optional argument NOMOVE
1107 non-nil means we are already at the right column. Optional argument
1108 UNSEEN non-nil means mark the message as unseen."
1112 (skip-chars-forward " ")
1113 (skip-chars-forward "0-9"))
1114 (when (char-equal (following-char) (if unseen ?\s ?-))
1115 (let ((buffer-read-only nil))
1117 (insert (if unseen "-" " ")))
1118 (let ((line (buffer-substring-no-properties (line-beginning-position)
1119 (line-beginning-position 2))))
1120 (with-current-buffer rmail-buffer
1121 (aset rmail-summary-vector (1- n) line))))))
1123 (defvar rmail-summary-put-back-unseen nil
1124 "Used for communicating between calls to `rmail-summary-rmail-update'.
1125 If it moves to a message within an Incremental Search, and removes
1126 the `unseen' attribute from that message, it sets this flag
1127 so that if the next motion between messages is in the same Incremental
1128 Search, the `unseen' attribute is restored.")
1130 ;; Show in Rmail the message described by the summary line that point is on,
1131 ;; but only if the Rmail buffer is already visible.
1132 ;; This is a post-command-hook in summary buffers.
1133 (defun rmail-summary-rmail-update ()
1134 (let (buffer-read-only)
1136 ;; If at end of buffer, pretend we are on the last text line.
1140 (skip-chars-forward " ")
1141 ;; If the summary is empty, don't do anything.
1143 (let ((msg-num (string-to-number (buffer-substring
1145 (progn (skip-chars-forward "0-9")
1147 ;; Always leave `unseen' removed
1148 ;; if we get out of isearch mode.
1149 ;; Don't let a subsequent isearch restore that `unseen'.
1150 (if (not isearch-mode)
1151 (setq rmail-summary-put-back-unseen nil))
1153 (or (eq rmail-current-message msg-num)
1154 (let ((window (get-buffer-window rmail-buffer t))
1155 (owin (selected-window)))
1158 ;; If we first saw the previous message in this search,
1159 ;; and we have gone to a different message while searching,
1160 ;; put back `unseen' on the former one.
1161 (when rmail-summary-put-back-unseen
1162 (rmail-set-attribute rmail-unseen-attr-index t
1163 rmail-current-message)
1165 (goto-char rmail-summary-put-back-unseen)
1166 (rmail-summary-mark-seen rmail-current-message t t)))
1167 ;; Arrange to do that later, for the new current message,
1168 ;; if it still has `unseen'.
1169 (setq rmail-summary-put-back-unseen
1170 (if (rmail-message-unseen-p msg-num)
1172 (setq rmail-summary-put-back-unseen nil))
1173 ;; Go to the desired message.
1174 (setq rmail-current-message msg-num)
1175 ;; Update the summary to show the message has been seen.
1176 (rmail-summary-mark-seen msg-num t)
1178 ;; Using save-window-excursion would cause the new value
1179 ;; of point to get lost.
1182 (select-window window)
1183 (rmail-show-message msg-num t))
1184 (select-window owin))
1185 (if (buffer-name rmail-buffer)
1186 (with-current-buffer rmail-buffer
1187 (rmail-show-message msg-num t))))
1188 ;; In linum mode, the message buffer must be specially
1189 ;; updated (Bug#4878).
1190 (and (fboundp 'linum-update)
1191 (buffer-name rmail-buffer)
1192 (linum-update rmail-buffer))))
1193 (rmail-summary-update-highlight nil))))))
1195 (defun rmail-summary-save-buffer ()
1196 "Save the buffer associated with this RMAIL summary."
1198 (save-window-excursion
1200 (switch-to-buffer rmail-buffer)
1203 (defun rmail-summary-mouse-goto-message (event)
1204 "Select the message whose summary line you click on."
1206 (goto-char (posn-point (event-end event)))
1207 (rmail-summary-goto-msg))
1209 (defun rmail-summary-msg-number ()
1213 (buffer-substring (point)
1214 (min (point-max) (+ 6 (point)))))))
1216 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
1217 "Go to message N in the summary buffer and the Rmail buffer.
1218 If N is nil, use the message corresponding to point in the summary
1219 and move to that message in the Rmail buffer.
1221 If NOWARN, don't say anything if N is out of range.
1222 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1223 Returns non-nil if message N was found."
1225 (if (consp n) (setq n (prefix-numeric-value n)))
1226 (if (eobp) (forward-line -1))
1228 (let* ((obuf (current-buffer))
1232 (curmsg (string-to-number
1233 (buffer-substring (point)
1234 (min (point-max) (+ 6 (point))))))
1235 (total (with-current-buffer buf rmail-total-messages)))
1236 ;; CURMSG should be nil when there's no current summary message
1237 ;; (for instance, if the summary is empty).
1240 ;; If message number N was specified, find that message's line
1241 ;; or set message-not-found.
1242 ;; If N wasn't specified or that message can't be found.
1243 ;; set N by default.
1247 (progn (message "No preceding message")
1249 (if (and (> n total)
1251 (progn (message "No following message")
1252 (goto-char (point-max))
1253 (rmail-summary-goto-msg nil nowarn skip-rmail)))
1254 (goto-char (point-min))
1255 (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t))
1256 (progn (or nowarn (message "Message %d not found" n))
1258 (setq message-not-found t)
1260 ;; N can be nil now, along with CURMSG,
1261 ;; if the summary is empty.
1263 (rmail-summary-mark-seen n)
1264 (rmail-summary-update-highlight message-not-found)
1267 (let ((selwin (selected-window)))
1269 (progn (rmail-pop-to-buffer buf)
1270 (rmail-show-message n))
1271 (select-window selwin)
1272 ;; The actions above can alter the current buffer. Preserve it.
1273 (set-buffer obuf)))))
1274 (not message-not-found)))
1276 ;; Update the highlighted line in an rmail summary buffer.
1277 ;; That should be current. We highlight the line point is on.
1278 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1279 (defun rmail-summary-update-highlight (not-found)
1280 ;; Make sure we have an overlay to use.
1281 (or rmail-summary-overlay
1283 (make-local-variable 'rmail-summary-overlay)
1284 (setq rmail-summary-overlay (make-overlay (point) (point)))
1285 (overlay-put rmail-summary-overlay 'rmail-summary t)))
1286 ;; If this message is in the summary, use the overlay to highlight it.
1287 ;; Otherwise, don't highlight anything.
1289 (overlay-put rmail-summary-overlay 'face nil)
1290 (move-overlay rmail-summary-overlay
1291 (save-excursion (beginning-of-line)
1292 (skip-chars-forward " ")
1294 (line-end-position))
1295 (overlay-put rmail-summary-overlay 'face 'highlight)))
1297 (defun rmail-summary-scroll-msg-up (&optional dist)
1298 "Scroll the Rmail window forward.
1299 If the Rmail window is displaying the end of a message,
1300 advance to the next message."
1303 (rmail-summary-scroll-msg-down nil)
1304 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1305 (if rmail-buffer-window
1306 (if (let ((rmail-summary-window (selected-window)))
1307 (select-window rmail-buffer-window)
1309 ;; Is EOB visible in the buffer?
1311 (let ((ht (window-height)))
1312 (move-to-window-line (- ht 2))
1315 (select-window rmail-summary-window)))
1316 (if (not rmail-summary-scroll-between-messages)
1317 (error "End of buffer")
1318 (rmail-summary-next-msg (or dist 1)))
1319 (let ((other-window-scroll-buffer rmail-buffer))
1320 (scroll-other-window dist)))
1321 ;; If it isn't visible at all, show the beginning.
1322 (rmail-summary-beginning-of-message)))))
1324 (defun rmail-summary-scroll-msg-down (&optional dist)
1325 "Scroll the Rmail window backward.
1326 If the Rmail window is now displaying the beginning of a message,
1327 move to the previous message."
1330 (rmail-summary-scroll-msg-up nil)
1331 (let ((rmail-buffer-window (get-buffer-window rmail-buffer)))
1332 (if rmail-buffer-window
1333 (if (let ((rmail-summary-window (selected-window)))
1334 (select-window rmail-buffer-window)
1336 ;; Is BOB visible in the buffer?
1338 (move-to-window-line 0)
1341 (select-window rmail-summary-window)))
1342 (if (not rmail-summary-scroll-between-messages)
1343 (error "Beginning of buffer")
1344 (rmail-summary-previous-msg (or dist 1)))
1345 (let ((other-window-scroll-buffer rmail-buffer))
1346 (scroll-other-window-down dist)))
1347 ;; If it isn't visible at all, show the beginning.
1348 (rmail-summary-beginning-of-message)))))
1350 (defun rmail-summary-beginning-of-message ()
1351 "Show current message from the beginning."
1353 (rmail-summary-show-message 'BEG))
1355 (defun rmail-summary-end-of-message ()
1356 "Show bottom of current message."
1358 (rmail-summary-show-message 'END))
1360 (defun rmail-summary-show-message (where)
1361 "Show current mail message.
1362 Position it according to WHERE which can be BEG or END"
1363 (if (and (one-window-p) (not pop-up-frames))
1364 ;; If there is just one window, put the summary on the top.
1365 (let ((buffer rmail-buffer))
1366 (split-window (selected-window) rmail-summary-window-size)
1367 (select-window (frame-first-window))
1368 (rmail-pop-to-buffer rmail-buffer)
1369 ;; If pop-to-buffer did not use that window, delete that
1370 ;; window. (This can happen if it uses another frame.)
1371 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1372 (delete-other-windows)))
1373 (rmail-pop-to-buffer rmail-buffer))
1376 (goto-char (point-min))
1377 (search-forward "\n\n"))
1379 (goto-char (point-max))
1380 (recenter (1- (window-height))))
1382 (rmail-pop-to-buffer rmail-summary-buffer))
1384 (defun rmail-summary-bury ()
1385 "Bury the Rmail buffer and the Rmail summary buffer."
1387 (let ((buffer-to-bury (current-buffer)))
1389 (while (setq window (get-buffer-window rmail-buffer))
1390 (set-window-buffer window (other-buffer rmail-buffer)))
1391 (bury-buffer rmail-buffer))
1392 (switch-to-buffer (other-buffer buffer-to-bury))
1393 (bury-buffer buffer-to-bury)))
1395 (defun rmail-summary-quit ()
1396 "Quit out of Rmail and Rmail summary."
1398 (rmail-summary-wipe)
1401 (defun rmail-summary-wipe ()
1402 "Kill and wipe away Rmail summary, remaining within Rmail."
1404 (with-current-buffer rmail-buffer (setq rmail-summary-buffer nil))
1405 (let ((local-rmail-buffer rmail-buffer))
1406 (kill-buffer (current-buffer))
1407 ;; Delete window if not only one.
1408 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1410 ;; Switch windows to the rmail buffer, or switch to it in this window.
1411 (rmail-pop-to-buffer local-rmail-buffer)))
1413 (defun rmail-summary-expunge ()
1414 "Actually erase all deleted messages and recompute summary headers."
1416 (with-current-buffer rmail-buffer
1417 (when (rmail-expunge-confirmed)
1418 (rmail-only-expunge)))
1419 (rmail-update-summary))
1421 (defun rmail-summary-expunge-and-save ()
1422 "Expunge and save RMAIL file."
1425 (rmail-expunge-and-save))
1426 (rmail-update-summary)
1427 (set-buffer-modified-p nil))
1429 (defun rmail-summary-get-new-mail (&optional file-name)
1430 "Get new mail and recompute summary headers.
1432 Optionally you can specify the file to get new mail from. In this case,
1433 the file of new mail is not changed or deleted. Noninteractively, you can
1434 pass the inbox file name as an argument. Interactively, a prefix
1435 argument says to read a file name and use that file as the inbox."
1437 (list (if current-prefix-arg
1438 (read-file-name "Get new mail from file: "))))
1440 (with-current-buffer rmail-buffer
1441 (rmail-get-new-mail file-name)
1442 ;; Get the proper new message number.
1443 (setq msg rmail-current-message))
1444 ;; Make sure that message is displayed.
1446 (rmail-summary-goto-msg msg))))
1448 (defun rmail-summary-input (filename)
1449 "Run Rmail on file FILENAME."
1450 (interactive "FRun rmail on RMAIL file: ")
1451 ;; We switch windows here, then display the other Rmail file there.
1452 (rmail-pop-to-buffer rmail-buffer)
1455 (defun rmail-summary-first-message ()
1456 "Show first message in Rmail file from summary buffer."
1459 (beginning-of-buffer)))
1461 (defun rmail-summary-last-message ()
1462 "Show last message in Rmail file from summary buffer."
1468 (declare-function rmail-abort-edit "rmailedit" ())
1469 (declare-function rmail-cease-edit "rmailedit"())
1470 (declare-function rmail-set-label "rmailkwd" (l state &optional n))
1471 (declare-function rmail-output-read-file-name "rmailout" ())
1472 (declare-function mail-send-and-exit "sendmail" (&optional arg))
1474 (defvar rmail-summary-edit-map nil)
1475 (if rmail-summary-edit-map
1477 (setq rmail-summary-edit-map
1478 (nconc (make-sparse-keymap) text-mode-map))
1479 (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
1480 (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
1482 (defun rmail-summary-edit-current-message ()
1483 "Edit the contents of this message."
1485 (rmail-pop-to-buffer rmail-buffer)
1486 (rmail-edit-current-message)
1487 (use-local-map rmail-summary-edit-map))
1489 (defun rmail-summary-cease-edit ()
1490 "Finish editing message, then go back to Rmail summary buffer."
1493 (rmail-pop-to-buffer rmail-summary-buffer))
1495 (defun rmail-summary-abort-edit ()
1496 "Abort edit of current message; restore original contents.
1497 Go back to summary buffer."
1500 (rmail-pop-to-buffer rmail-summary-buffer))
1502 (defun rmail-summary-search-backward (regexp &optional n)
1503 "Show message containing next match for REGEXP.
1504 Prefix argument gives repeat count; negative argument means search
1505 backwards (through earlier messages).
1506 Interactively, empty argument means use same regexp used last time."
1508 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1510 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1514 (if rmail-search-last-regexp
1515 (concat ", default "
1516 rmail-search-last-regexp "): ")
1518 (setq regexp (read-string prompt))
1519 (cond ((not (equal regexp ""))
1520 (setq rmail-search-last-regexp regexp))
1521 ((not rmail-search-last-regexp)
1522 (error "No previous Rmail search string")))
1523 (list rmail-search-last-regexp
1524 (prefix-numeric-value current-prefix-arg))))
1525 ;; Don't use save-excursion because that prevents point from moving
1526 ;; properly in the summary buffer.
1527 (with-current-buffer rmail-buffer
1528 (rmail-search regexp (- n))))
1530 (defun rmail-summary-search (regexp &optional n)
1531 "Show message containing next match for REGEXP.
1532 Prefix argument gives repeat count; negative argument means search
1533 backwards (through earlier messages).
1534 Interactively, empty argument means use same regexp used last time."
1536 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1538 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
1542 (if rmail-search-last-regexp
1543 (concat ", default "
1544 rmail-search-last-regexp "): ")
1546 (setq regexp (read-string prompt))
1547 (cond ((not (equal regexp ""))
1548 (setq rmail-search-last-regexp regexp))
1549 ((not rmail-search-last-regexp)
1550 (error "No previous Rmail search string")))
1551 (list rmail-search-last-regexp
1552 (prefix-numeric-value current-prefix-arg))))
1553 ;; Don't use save-excursion because that prevents point from moving
1554 ;; properly in the summary buffer.
1555 (let ((buffer (current-buffer))
1556 (selwin (selected-window)))
1559 (rmail-pop-to-buffer rmail-buffer)
1560 (rmail-search regexp n))
1561 (select-window selwin)
1562 (set-buffer buffer))))
1564 (defun rmail-summary-toggle-header ()
1565 "Show original message header if pruned header currently shown, or vice versa."
1567 (save-window-excursion
1568 (set-buffer rmail-buffer)
1569 (rmail-toggle-header))
1570 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1571 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1572 (let ((window (get-buffer-window rmail-buffer)))
1574 ;; Using save-window-excursion would lose the new value of point.
1575 (let ((owin (selected-window)))
1578 (select-window window)
1579 (goto-char (point-min)))
1580 (select-window owin))))))
1583 (defun rmail-summary-add-label (label)
1584 "Add LABEL to labels associated with current Rmail message.
1585 Completion is performed over known labels when reading."
1586 (interactive (list (with-current-buffer rmail-buffer
1587 (rmail-read-label "Add label"))))
1588 (with-current-buffer rmail-buffer
1589 (rmail-add-label label)))
1591 (defun rmail-summary-kill-label (label)
1592 "Remove LABEL from labels associated with current Rmail message.
1593 Completion is performed over known labels when reading."
1594 (interactive (list (with-current-buffer rmail-buffer
1595 (rmail-read-label "Kill label"))))
1596 (with-current-buffer rmail-buffer
1597 (rmail-set-label label nil)))
1599 ;;;; *** Rmail Summary Mailing Commands ***
1601 (defun rmail-summary-override-mail-send-and-exit ()
1602 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1603 (use-local-map (copy-keymap (current-local-map)))
1604 (dolist (key (where-is-internal 'mail-send-and-exit))
1605 (define-key (current-local-map) key 'rmail-summary-send-and-exit)))
1607 (defun rmail-summary-mail ()
1608 "Send mail in another window.
1609 While composing the message, use \\[mail-yank-original] to yank the
1610 original message into it."
1612 (let ((window (get-buffer-window rmail-buffer)))
1614 (select-window window)
1615 (set-buffer rmail-buffer)))
1616 (rmail-start-mail nil nil nil nil nil (current-buffer))
1617 (rmail-summary-override-mail-send-and-exit))
1619 (defun rmail-summary-continue ()
1620 "Continue composing outgoing message previously being composed."
1622 (let ((window (get-buffer-window rmail-buffer)))
1624 (select-window window)
1625 (set-buffer rmail-buffer)))
1626 (rmail-start-mail t))
1628 (defun rmail-summary-reply (just-sender)
1629 "Reply to the current message.
1630 Normally include CC: to all other recipients of original message;
1631 prefix argument means ignore them. While composing the reply,
1632 use \\[mail-yank-original] to yank the original message into it."
1634 (let ((window (get-buffer-window rmail-buffer)))
1636 (select-window window)
1637 (set-buffer rmail-buffer)))
1638 (rmail-reply just-sender)
1639 (rmail-summary-override-mail-send-and-exit))
1641 (defun rmail-summary-retry-failure ()
1642 "Edit a mail message which is based on the contents of the current message.
1643 For a message rejected by the mail system, extract the interesting headers and
1644 the body of the original message; otherwise copy the current message."
1646 (let ((window (get-buffer-window rmail-buffer)))
1648 (select-window window)
1649 (set-buffer rmail-buffer)))
1650 (rmail-retry-failure)
1651 (rmail-summary-override-mail-send-and-exit))
1653 (defun rmail-summary-send-and-exit ()
1654 "Send mail reply and return to summary buffer."
1656 (mail-send-and-exit t))
1658 (defun rmail-summary-forward (resend)
1659 "Forward the current message to another user.
1660 With prefix argument, \"resend\" the message instead of forwarding it;
1661 see the documentation of `rmail-resend'."
1664 (let ((window (get-buffer-window rmail-buffer)))
1666 (select-window window)
1667 (set-buffer rmail-buffer)))
1668 (rmail-forward resend)
1669 (rmail-summary-override-mail-send-and-exit)))
1671 (defun rmail-summary-resend ()
1672 "Resend current message using `rmail-resend'."
1675 (let ((window (get-buffer-window rmail-buffer)))
1677 (select-window window)
1678 (set-buffer rmail-buffer)))
1679 (call-interactively 'rmail-resend)))
1681 ;; Summary output commands.
1683 (defun rmail-summary-output (&optional file-name n)
1684 "Append this message to mail file FILE-NAME.
1685 This works with both mbox format and Babyl format files,
1686 outputting in the appropriate format for each.
1687 The default file name comes from `rmail-default-file',
1688 which is updated to the name you use in this command.
1690 A prefix argument N says to output that many consecutive messages
1691 from those in the summary, starting with the current one.
1692 Deleted messages are skipped and don't count.
1693 When called from Lisp code, N may be omitted and defaults to 1.
1695 This command always outputs the complete message header,
1696 even the header display is currently pruned."
1698 (progn (require 'rmailout)
1699 (list (rmail-output-read-file-name)
1700 (prefix-numeric-value current-prefix-arg))))
1701 (let ((i 0) prev-msg)
1704 (progn (rmail-summary-goto-msg)
1707 (with-current-buffer rmail-buffer
1708 rmail-current-message))))))
1710 (with-current-buffer rmail-buffer
1711 (let ((rmail-delete-after-output nil))
1712 (rmail-output file-name 1)))
1713 (if rmail-delete-after-output
1714 (rmail-summary-delete-forward nil)
1716 (rmail-summary-next-msg 1))))))
1718 (defalias 'rmail-summary-output-to-rmail-file 'rmail-summary-output)
1720 (declare-function rmail-output-as-seen "rmailout"
1721 (file-name &optional count noattribute from-gnus))
1723 (defun rmail-summary-output-as-seen (&optional file-name n)
1724 "Append this message to mbox file named FILE-NAME.
1725 A prefix argument N says to output that many consecutive messages,
1726 from the summary, starting with the current one.
1727 Deleted messages are skipped and don't count.
1728 When called from Lisp code, N may be omitted and defaults to 1.
1730 This outputs the message header as you see it (or would see it)
1733 The default file name comes from `rmail-default-file',
1734 which is updated to the name you use in this command."
1736 (progn (require 'rmailout)
1737 (list (rmail-output-read-file-name)
1738 (prefix-numeric-value current-prefix-arg))))
1739 (require 'rmailout) ; for rmail-output-as-seen in non-interactive case
1740 (let ((i 0) prev-msg)
1743 (progn (rmail-summary-goto-msg)
1746 (with-current-buffer rmail-buffer
1747 rmail-current-message))))))
1749 (with-current-buffer rmail-buffer
1750 (let ((rmail-delete-after-output nil))
1751 (rmail-output-as-seen file-name 1)))
1752 (if rmail-delete-after-output
1753 (rmail-summary-delete-forward nil)
1755 (rmail-summary-next-msg 1))))))
1757 (defun rmail-summary-output-menu ()
1758 "Output current message to another Rmail file, chosen with a menu.
1759 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1760 The variables `rmail-secondary-file-directory' and
1761 `rmail-secondary-file-regexp' control which files are offered in the menu."
1763 (with-current-buffer rmail-buffer
1764 (let ((rmail-delete-after-output nil))
1765 (call-interactively 'rmail-output-menu)))
1766 (if rmail-delete-after-output
1767 (rmail-summary-delete-forward nil)))
1769 (defun rmail-summary-construct-io-menu ()
1770 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1773 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1774 (cons "Input Rmail File"
1775 (rmail-list-to-menu "Input Rmail File"
1777 'rmail-summary-input)))
1778 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1779 (cons "Output Rmail File"
1780 (rmail-list-to-menu "Output Rmail File"
1782 'rmail-summary-output))))
1783 (define-key rmail-summary-mode-map [menu-bar classify input-menu]
1784 '("Input Rmail File" . rmail-disable-menu))
1785 (define-key rmail-summary-mode-map [menu-bar classify output-menu]
1786 '("Output Rmail File" . rmail-disable-menu)))))
1788 (defun rmail-summary-output-body (&optional file-name)
1789 "Write this message body to the file FILE-NAME.
1790 FILE-NAME defaults, interactively, from the Subject field of the message."
1792 (with-current-buffer rmail-buffer
1793 (let ((rmail-delete-after-output nil))
1795 (rmail-output-body-to-file file-name)
1796 (call-interactively 'rmail-output-body-to-file))))
1797 (if rmail-delete-after-output
1798 (rmail-summary-delete-forward nil)))
1800 ;; Sorting messages in Rmail Summary buffer.
1802 (defun rmail-summary-sort-by-date (reverse)
1803 "Sort messages of current Rmail summary by \"Date\" header.
1804 If prefix argument REVERSE is non-nil, sorts in reverse order."
1806 (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
1808 (defun rmail-summary-sort-by-subject (reverse)
1809 "Sort messages of current Rmail summary by \"Subject\" header.
1810 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
1811 non-nil, sorts in reverse order."
1813 (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
1815 (defun rmail-summary-sort-by-author (reverse)
1816 "Sort messages of current Rmail summary by author.
1817 This uses either the \"From\" or \"Sender\" header, downcased.
1818 If prefix argument REVERSE is non-nil, sorts in reverse order."
1820 (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
1822 (defun rmail-summary-sort-by-recipient (reverse)
1823 "Sort messages of current Rmail summary by recipient.
1824 This uses either the \"To\" or \"Apparently-To\" header, downcased.
1825 If prefix argument REVERSE is non-nil, sorts in reverse order."
1827 (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
1829 (defun rmail-summary-sort-by-correspondent (reverse)
1830 "Sort messages of current Rmail summary by other correspondent.
1831 This uses either the \"From\", \"Sender\", \"To\", or
1832 \"Apparently-To\" header, downcased. Uses the first header not
1833 excluded by `mail-dont-reply-to-names'. If prefix argument
1834 REVERSE is non-nil, sorts in reverse order."
1836 (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
1838 (defun rmail-summary-sort-by-lines (reverse)
1839 "Sort messages of current Rmail summary by the number of lines.
1840 If prefix argument REVERSE is non-nil, sorts in reverse order."
1842 (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
1844 (defun rmail-summary-sort-by-labels (reverse labels)
1845 "Sort messages of current Rmail summary by labels.
1846 LABELS is a comma-separated list of labels.
1847 If prefix argument REVERSE is non-nil, sorts in reverse order."
1848 (interactive "P\nsSort by labels: ")
1849 (rmail-sort-from-summary
1850 (lambda (reverse) (rmail-sort-by-labels reverse labels))
1853 (defun rmail-sort-from-summary (sortfun reverse)
1854 "Sort the Rmail buffer using sorting function SORTFUN.
1855 Passes REVERSE to SORTFUN as its sole argument. Then regenerates
1856 the summary. Note that the whole Rmail buffer is sorted, even if
1857 the summary is only showing a subset of messages."
1858 (require 'rmailsort)
1859 (let ((selwin (selected-window)))
1861 (progn (rmail-pop-to-buffer rmail-buffer)
1862 (funcall sortfun reverse))
1863 (select-window selwin))))
1868 ;; generated-autoload-file: "rmail.el"
1871 ;;; rmailsum.el ends here