1 ;;; rmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993-1996, 2000-2011 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Extended by Bob Weiner of Motorola
27 ;; Provided all commands from rmail-mode in rmail-summary-mode and made key
28 ;; bindings in both modes wholly compatible.
32 ;; For rmail-select-summary.
36 (defcustom rmail-summary-scroll-between-messages t
37 "Non-nil means Rmail summary scroll commands move between messages.
38 That is, after `rmail-summary-scroll-msg-up' reaches the end of a
39 message, it moves to the next message; and similarly for
40 `rmail-summary-scroll-msg-down'."
42 :group
'rmail-summary
)
44 ;; FIXME could do with a :set function that regenerates the summary
45 ;; and updates rmail-summary-vector.
46 (defcustom rmail-summary-line-count-flag t
47 "Non-nil means Rmail summary should show the number of lines in each message.
48 Setting this option to nil might speed up the generation of summaries."
50 :group
'rmail-summary
)
52 (defvar rmail-summary-font-lock-keywords
53 '(("^.....D.*" . font-lock-string-face
) ; Deleted.
54 ("^.....-.*" . font-lock-type-face
) ; Unread.
55 ;; Neither of the below will be highlighted if either of the above are:
56 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face
) ; Date.
57 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face
)) ; Labels.
58 "Additional expressions to highlight in Rmail Summary mode.")
60 (defvar rmail-summary-redo nil
61 "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.")
63 (defvar rmail-summary-overlay nil
64 "Overlay used to highlight the current message in the Rmail summary.")
65 (put 'rmail-summary-overlay
'permanent-local t
)
67 (defvar rmail-summary-mode-map
68 (let ((map (make-keymap)))
70 (define-key map
[mouse-2
] 'rmail-summary-mouse-goto-message
)
71 (define-key map
"a" 'rmail-summary-add-label
)
72 (define-key map
"b" 'rmail-summary-bury
)
73 (define-key map
"c" 'rmail-summary-continue
)
74 (define-key map
"d" 'rmail-summary-delete-forward
)
75 (define-key map
"\C-d" 'rmail-summary-delete-backward
)
76 (define-key map
"e" 'rmail-summary-edit-current-message
)
77 (define-key map
"f" 'rmail-summary-forward
)
78 (define-key map
"g" 'rmail-summary-get-new-mail
)
79 (define-key map
"h" 'rmail-summary
)
80 (define-key map
"i" 'rmail-summary-input
)
81 (define-key map
"j" 'rmail-summary-goto-msg
)
82 (define-key map
"\C-m" 'rmail-summary-goto-msg
)
83 (define-key map
"k" 'rmail-summary-kill-label
)
84 (define-key map
"l" 'rmail-summary-by-labels
)
85 (define-key map
"\e\C-h" 'rmail-summary
)
86 (define-key map
"\e\C-l" 'rmail-summary-by-labels
)
87 (define-key map
"\e\C-r" 'rmail-summary-by-recipients
)
88 (define-key map
"\e\C-s" 'rmail-summary-by-regexp
)
90 (define-key map
"\e\C-f" 'rmail-summary-by-senders
)
91 (define-key map
"\e\C-t" 'rmail-summary-by-topic
)
92 (define-key map
"m" 'rmail-summary-mail
)
93 (define-key map
"\M-m" 'rmail-summary-retry-failure
)
94 (define-key map
"n" 'rmail-summary-next-msg
)
95 (define-key map
"\en" 'rmail-summary-next-all
)
96 (define-key map
"\e\C-n" 'rmail-summary-next-labeled-message
)
97 (define-key map
"o" 'rmail-summary-output
)
98 (define-key map
"\C-o" 'rmail-summary-output-as-seen
)
99 (define-key map
"p" 'rmail-summary-previous-msg
)
100 (define-key map
"\ep" 'rmail-summary-previous-all
)
101 (define-key map
"\e\C-p" 'rmail-summary-previous-labeled-message
)
102 (define-key map
"q" 'rmail-summary-quit
)
103 (define-key map
"Q" 'rmail-summary-wipe
)
104 (define-key map
"r" 'rmail-summary-reply
)
105 (define-key map
"s" 'rmail-summary-expunge-and-save
)
106 ;; See rms's comment in rmail.el
107 ;; (define-key map "\er" 'rmail-summary-search-backward)
108 (define-key map
"\es" 'rmail-summary-search
)
109 (define-key map
"t" 'rmail-summary-toggle-header
)
110 (define-key map
"u" 'rmail-summary-undelete
)
111 (define-key map
"\M-u" 'rmail-summary-undelete-many
)
112 (define-key map
"x" 'rmail-summary-expunge
)
113 (define-key map
"w" 'rmail-summary-output-body
)
114 (define-key map
"v" 'rmail-mime
)
115 (define-key map
"." 'rmail-summary-beginning-of-message
)
116 (define-key map
"/" 'rmail-summary-end-of-message
)
117 (define-key map
"<" 'rmail-summary-first-message
)
118 (define-key map
">" 'rmail-summary-last-message
)
119 (define-key map
" " 'rmail-summary-scroll-msg-up
)
120 (define-key map
"\177" 'rmail-summary-scroll-msg-down
)
121 (define-key map
"?" 'describe-mode
)
122 (define-key map
"\C-c\C-n" 'rmail-summary-next-same-subject
)
123 (define-key map
"\C-c\C-p" 'rmail-summary-previous-same-subject
)
124 (define-key map
"\C-c\C-s\C-d" 'rmail-summary-sort-by-date
)
125 (define-key map
"\C-c\C-s\C-s" 'rmail-summary-sort-by-subject
)
126 (define-key map
"\C-c\C-s\C-a" 'rmail-summary-sort-by-author
)
127 (define-key map
"\C-c\C-s\C-r" 'rmail-summary-sort-by-recipient
)
128 (define-key map
"\C-c\C-s\C-c" 'rmail-summary-sort-by-correspondent
)
129 (define-key map
"\C-c\C-s\C-l" 'rmail-summary-sort-by-lines
)
130 (define-key map
"\C-c\C-s\C-k" 'rmail-summary-sort-by-labels
)
131 (define-key map
"\C-x\C-s" 'rmail-summary-save-buffer
)
133 ;; Menu bar bindings.
135 (define-key map
[menu-bar
] (make-sparse-keymap))
137 (define-key map
[menu-bar classify
]
138 (cons "Classify" (make-sparse-keymap "Classify")))
140 (define-key map
[menu-bar classify output-menu
]
141 '("Output (Rmail Menu)..." . rmail-summary-output-menu
))
143 (define-key map
[menu-bar classify input-menu
]
144 '("Input Rmail File (menu)..." . rmail-input-menu
))
146 (define-key map
[menu-bar classify input-menu
]
149 (define-key map
[menu-bar classify output-menu
]
152 (define-key map
[menu-bar classify output-body
]
153 '("Output body..." . rmail-summary-output-body
))
155 (define-key map
[menu-bar classify output-inbox
]
156 '("Output..." . rmail-summary-output
))
158 (define-key map
[menu-bar classify output
]
159 '("Output as seen..." . rmail-summary-output-as-seen
))
161 (define-key map
[menu-bar classify kill-label
]
162 '("Kill Label..." . rmail-summary-kill-label
))
164 (define-key map
[menu-bar classify add-label
]
165 '("Add Label..." . rmail-summary-add-label
))
167 (define-key map
[menu-bar summary
]
168 (cons "Summary" (make-sparse-keymap "Summary")))
170 (define-key map
[menu-bar summary senders
]
171 '("By Senders..." . rmail-summary-by-senders
))
173 (define-key map
[menu-bar summary labels
]
174 '("By Labels..." . rmail-summary-by-labels
))
176 (define-key map
[menu-bar summary recipients
]
177 '("By Recipients..." . rmail-summary-by-recipients
))
179 (define-key map
[menu-bar summary topic
]
180 '("By Topic..." . rmail-summary-by-topic
))
182 (define-key map
[menu-bar summary regexp
]
183 '("By Regexp..." . rmail-summary-by-regexp
))
185 (define-key map
[menu-bar summary all
]
186 '("All" . rmail-summary
))
188 (define-key map
[menu-bar mail
]
189 (cons "Mail" (make-sparse-keymap "Mail")))
191 (define-key map
[menu-bar mail rmail-summary-get-new-mail
]
192 '("Get New Mail" . rmail-summary-get-new-mail
))
194 (define-key map
[menu-bar mail lambda
]
197 (define-key map
[menu-bar mail continue
]
198 '("Continue" . rmail-summary-continue
))
200 (define-key map
[menu-bar mail resend
]
201 '("Re-send..." . rmail-summary-resend
))
203 (define-key map
[menu-bar mail forward
]
204 '("Forward" . rmail-summary-forward
))
206 (define-key map
[menu-bar mail retry
]
207 '("Retry" . rmail-summary-retry-failure
))
209 (define-key map
[menu-bar mail reply
]
210 '("Reply" . rmail-summary-reply
))
212 (define-key map
[menu-bar mail mail
]
213 '("Mail" . rmail-summary-mail
))
215 (define-key map
[menu-bar delete
]
216 (cons "Delete" (make-sparse-keymap "Delete")))
218 (define-key map
[menu-bar delete expunge
/save
]
219 '("Expunge/Save" . rmail-summary-expunge-and-save
))
221 (define-key map
[menu-bar delete expunge
]
222 '("Expunge" . rmail-summary-expunge
))
224 (define-key map
[menu-bar delete undelete
]
225 '("Undelete" . rmail-summary-undelete
))
227 (define-key map
[menu-bar delete delete
]
228 '("Delete" . rmail-summary-delete-forward
))
230 (define-key map
[menu-bar move
]
231 (cons "Move" (make-sparse-keymap "Move")))
233 (define-key map
[menu-bar move search-back
]
234 '("Search Back..." . rmail-summary-search-backward
))
236 (define-key map
[menu-bar move search
]
237 '("Search..." . rmail-summary-search
))
239 (define-key map
[menu-bar move previous
]
240 '("Previous Nondeleted" . rmail-summary-previous-msg
))
242 (define-key map
[menu-bar move next
]
243 '("Next Nondeleted" . rmail-summary-next-msg
))
245 (define-key map
[menu-bar move last
]
246 '("Last" . rmail-summary-last-message
))
248 (define-key map
[menu-bar move first
]
249 '("First" . rmail-summary-first-message
))
251 (define-key map
[menu-bar move previous
]
252 '("Previous" . rmail-summary-previous-all
))
254 (define-key map
[menu-bar move next
]
255 '("Next" . rmail-summary-next-all
))
257 "Keymap used in Rmail summary mode.")
259 ;; Entry points for making a summary buffer.
261 ;; Regenerate the contents of the summary
262 ;; using the same selection criterion as last time.
263 ;; M-x revert-buffer in a summary buffer calls this function.
264 (defun rmail-update-summary (&rest ignore
)
265 (apply (car rmail-summary-redo
) (cdr rmail-summary-redo
)))
268 (defun rmail-summary ()
269 "Display a summary of all messages, one line per message."
271 (rmail-new-summary "All" '(rmail-summary) nil
)
272 (unless (get-buffer-window rmail-buffer
)
273 (rmail-summary-beginning-of-message)))
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 rmail-enable-mime
348 (if rmail-search-mime-header-function
349 (funcall rmail-search-mime-header-function msg regexp
(point))
350 (error "You must set `rmail-search-mime-header-function'"))
351 (re-search-forward regexp nil t
)))
354 (defun rmail-summary-by-topic (subject &optional whole-message
)
355 "Display a summary of all messages with the given SUBJECT.
356 Normally checks just the Subject field of headers; but with prefix
357 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
358 SUBJECT is a string of regexps separated by commas."
360 ;; We quote the default subject, because if it contains regexp
361 ;; special characters (eg "?"), it can fail to match itself. (Bug#2333)
362 (let* ((subject (regexp-quote (rmail-simplified-subject)))
363 (prompt (concat "Topics to summarize by (regexp"
364 (if subject
", default current subject" "")
366 (list (read-string prompt nil nil subject
) current-prefix-arg
)))
368 (concat "about " subject
)
369 (list 'rmail-summary-by-topic subject whole-message
)
370 'rmail-message-subject-p
371 (mail-comma-list-regexp subject
) whole-message
))
373 (defun rmail-message-subject-p (msg subject
&optional whole-message
)
375 (rmail-apply-in-message msg
're-search-forward subject nil t
)
376 (string-match subject
(rmail-simplified-subject msg
))))
379 (defun rmail-summary-by-senders (senders)
380 "Display a summary of all messages whose \"From\" field matches SENDERS.
381 SENDERS is a string of regexps separated by commas."
382 (interactive "sSenders to summarize by: ")
384 (concat "senders " senders
)
385 (list 'rmail-summary-by-senders senders
)
386 'rmail-message-senders-p
387 (mail-comma-list-regexp senders
)))
389 (defun rmail-message-senders-p (msg senders
)
390 (string-match senders
(or (rmail-get-header "From" msg
) "")))
392 ;; General making of a summary buffer.
394 (defvar rmail-summary-symbol-number
0)
396 (defvar rmail-new-summary-line-count
)
398 (defun rmail-new-summary (desc redo func
&rest args
)
399 "Create a summary of selected messages.
400 DESC makes part of the mode line of the summary buffer. REDO is form ...
401 For each message, FUNC is applied to the message number and ARGS...
402 and if the result is non-nil, that message is included.
403 nil for FUNCTION means all messages."
404 (message "Computing summary lines...")
406 (error "No RMAIL buffer found"))
407 (let (mesg was-in-summary
)
408 (if (eq major-mode
'rmail-summary-mode
)
409 (setq was-in-summary t
))
410 (with-current-buffer rmail-buffer
411 (if (zerop (setq mesg rmail-current-message
))
412 (error "No messages to summarize"))
413 (setq rmail-summary-buffer
(rmail-new-summary-1 desc redo func args
)))
414 ;; Now display the summary buffer and go to the right place in it.
415 (unless was-in-summary
416 (if (and (one-window-p)
419 ;; If there is just one window, put the summary on the top.
421 (split-window (selected-window) rmail-summary-window-size
)
422 (select-window (next-window (frame-first-window)))
423 (rmail-pop-to-buffer rmail-summary-buffer
)
424 ;; If pop-to-buffer did not use that window, delete that
425 ;; window. (This can happen if it uses another frame.)
426 (if (not (eq rmail-summary-buffer
427 (window-buffer (frame-first-window))))
428 (delete-other-windows)))
429 (rmail-pop-to-buffer rmail-summary-buffer
))
430 (set-buffer rmail-buffer
)
431 ;; This is how rmail makes the summary buffer reappear.
432 ;; We do this here to make the window the proper size.
433 (rmail-select-summary nil
)
434 (set-buffer rmail-summary-buffer
))
435 (rmail-summary-goto-msg mesg t t
)
436 (rmail-summary-construct-io-menu)
437 (message "Computing summary lines...done")))
439 (defun rmail-new-summary-1 (description form function args
)
440 "Filter messages to obtain summary lines.
441 DESCRIPTION is added to the mode line.
443 Return the summary buffer by invoking FUNCTION on each message
444 passing the message number and ARGS...
448 The current buffer must be a Rmail buffer either containing a
449 collection of mbox formatted messages or displaying a single
451 (let ((summary-msgs ())
452 (rmail-new-summary-line-count 0)
453 (sumbuf (rmail-get-create-summary-buffer)))
454 ;; Scan the messages, getting their summary strings
455 ;; and putting the list of them in SUMMARY-MSGS.
457 (main-buffer (current-buffer))
458 (total rmail-total-messages
)
459 (inhibit-read-only t
))
461 ;; Go where the mbox text is.
462 (if (rmail-buffers-swapped-p)
463 (set-buffer rmail-view-buffer
))
464 (let ((old-min (point-min-marker))
465 (old-max (point-max-marker)))
467 ;; Can't use save-restriction here; that doesn't work if we
468 ;; plan to modify text outside the original restriction.
471 (goto-char (point-min))
472 (while (>= total msgnum
)
473 ;; Go back to the Rmail buffer so
474 ;; so FUNCTION and rmail-get-summary can see its local vars.
475 (with-current-buffer main-buffer
476 ;; First test whether to include this message.
477 (if (or (null function
)
478 (apply function msgnum args
))
480 (cons (cons msgnum
(rmail-get-summary msgnum
))
482 (setq msgnum
(1+ msgnum
))
483 ;; Provide a periodic User progress message.
484 (if (and (not (zerop rmail-new-summary-line-count
))
485 (zerop (% rmail-new-summary-line-count
10)))
486 (message "Computing summary lines...%d"
487 rmail-new-summary-line-count
)))
488 (setq summary-msgs
(nreverse summary-msgs
)))
489 (narrow-to-region old-min old-max
)))))
490 ;; Temporarily, while summary buffer is unfinished,
491 ;; we "don't have" a summary.
492 (setq rmail-summary-buffer nil
)
495 (error "Nothing to summarize"))
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 email that clue to
499 (if rmail-enable-mime
500 (with-current-buffer rmail-buffer
501 (setq rmail-summary-buffer nil
)))
503 (let ((rbuf (current-buffer))
504 (total rmail-total-messages
))
506 ;; Set up the summary buffer's contents.
507 (let ((buffer-read-only nil
))
510 (princ (cdr (car summary-msgs
)) sumbuf
)
511 (setq summary-msgs
(cdr summary-msgs
)))
512 (goto-char (point-min)))
513 ;; Set up the rest of its state and local variables.
514 (setq buffer-read-only t
)
516 (make-local-variable 'minor-mode-alist
)
517 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
518 (setq rmail-buffer rbuf
519 rmail-summary-redo form
520 rmail-total-messages total
)))
523 (defun rmail-get-create-summary-buffer ()
524 "Return the Rmail summary buffer.
525 If necessary, it is created and undo is disabled."
526 (if (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
))
528 (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
529 (with-current-buffer buff
530 (setq buffer-undo-list t
))
534 ;; Low levels of generating a summary.
536 (defun rmail-get-summary (msgnum)
537 "Return the summary line for message MSGNUM.
538 The mbox buffer must be current when you call this function
539 even if its text is swapped.
541 If the message has a summary line already, it will be stored in
542 the message as a header and simply returned, otherwise the
543 summary line is created, saved in the message header, cached and
546 The current buffer contains the unrestricted message collection."
547 (let ((line (aref rmail-summary-vector
(1- msgnum
))))
549 ;; Register a summary line for MSGNUM.
550 (setq rmail-new-summary-line-count
(1+ rmail-new-summary-line-count
)
551 line
(rmail-create-summary-line msgnum
))
552 ;; Cache the summary line for use during this Rmail session.
553 (aset rmail-summary-vector
(1- msgnum
) line
))
556 (defcustom rmail-summary-line-decoder
(function rfc2047-decode-string
)
557 "Function to decode a Rmail summary line.
558 It receives the summary line for one message as a string
559 and should return the decoded string.
561 By default, it is `rfc2047-decode-string', which decodes MIME-encoded
565 :group
'rmail-summary
)
567 (defun rmail-create-summary-line (msgnum)
568 "Return the summary line for message MSGNUM.
569 Obtain the message summary from the header if it is available
570 otherwise create it and store it in the message header.
572 The mbox buffer must be current when you call this function
573 even if its text is swapped."
574 (let ((beg (rmail-msgbeg msgnum
))
575 (end (rmail-msgend msgnum
))
576 (deleted (rmail-message-deleted-p msgnum
))
577 ;; Does not work (swapped?)
578 ;;; (unseen (rmail-message-unseen-p msgnum))
581 ;; Switch to the buffer that has the whole mbox text.
582 (if (rmail-buffers-swapped-p)
583 (set-buffer rmail-view-buffer
))
584 ;; Now we can compute the line count.
585 (if rmail-summary-line-count-flag
586 (setq lines
(count-lines beg end
)))
587 ;; Narrow to the message header.
592 (if (search-forward "\n\n" end t
)
594 (narrow-to-region beg
(point))
595 ;; Replace rmail-message-unseen-p from above.
597 (setq unseen
(and (search-forward
598 (concat rmail-attribute-header
": ") nil t
)
599 (looking-at "......U")))
600 ;; Generate a status line from the message.
601 (rmail-create-summary msgnum deleted unseen lines
))
602 (rmail-error-bad-format msgnum
)))))))
604 ;; FIXME this is now unused.
605 ;; The intention was to display in the summary something like {E}
606 ;; for an edited messaged, similarly for answered, etc.
607 ;; But that conflicts with the previous rmail usage, where
608 ;; any user-defined { labels } occupied this space.
609 ;; So whilst it would be nice to have this information in the summary,
610 ;; it would need to go somewhere else.
611 (defun rmail-get-summary-status ()
612 "Return a coded string wrapped in curly braces denoting the status.
614 The current buffer must already be narrowed to the message headers for
615 the message being processed."
616 (let ((status (mail-fetch-field rmail-attribute-header
))
620 ;; Strip off the read/unread and the deleted attribute which are
621 ;; handled separately.
624 (concat (substring status
0 1) (substring status
2 6))
626 (while (< index
(length status
))
627 (unless (string= "-" (setq char
(substring status index
(1+ index
))))
628 (setq result
(concat result char
)))
629 (setq index
(1+ index
)))
630 (when (> (length result
) 0)
631 (setq result
(concat "{" result
"}")))
634 (autoload 'rmail-make-label
"rmailkwd")
636 (defun rmail-get-summary-labels ()
637 "Return a string wrapped in curly braces with the current message labels.
638 Returns nil if there are no labels. The current buffer must
639 already be narrowed to the message headers for the message being
641 (let ((labels (mail-fetch-field rmail-keyword-header
)))
643 (not (string-equal labels
""))
645 ;; Intern so that rmail-read-label can offer completion.
646 (mapc 'rmail-make-label
(split-string labels
", "))
647 (format "{ %s } " labels
)))))
649 (defun rmail-create-summary (msgnum deleted unseen lines
)
650 "Return the summary line for message MSGNUM.
651 The current buffer should already be narrowed to the header for that message.
652 It could be either buffer, so don't access Rmail local variables.
653 DELETED is t if this message is marked deleted.
654 UNSEEN is t if it is marked unseen.
655 LINES is the number of lines in the message (if we should display that)
657 (goto-char (point-min))
658 (let ((line (rmail-header-summary))
659 (labels (rmail-get-summary-labels))
660 pos status prefix basic-start basic-end linecount-string
)
662 (setq linecount-string
665 ((<= lines
9) (format " [%d]" lines
))
666 ((<= lines
99) (format " [%d]" lines
))
667 ((<= lines
999) (format " [%d]" lines
))
668 ((<= lines
9999) (format " [%dk]" (/ lines
1000)))
669 ((<= lines
99999) (format " [%dk]" (/ lines
1000)))
670 (t (format "[%dk]" (/ lines
1000)))))
676 prefix
(format "%5d%c " msgnum status
)
677 basic-start
(car line
)
678 basic-end
(cadr line
))
679 (funcall rmail-summary-line-decoder
680 (concat prefix basic-start linecount-string
" "
683 (defun rmail-header-summary ()
684 "Return a message summary based on the message headers.
685 The value is a list of two strings, the first and second parts of the summary.
687 The current buffer must already be narrowed to the message headers for
688 the message being processed."
689 (goto-char (point-min))
691 (concat (save-excursion
692 (if (not (re-search-forward "^Date:" nil t
))
694 ;; Match month names case-insensitively
695 (cond ((let ((case-fold-search t
))
696 (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
697 (line-end-position) t
))
699 (string-to-number (buffer-substring
703 (match-beginning 4) (match-end 4))))
704 ((let ((case-fold-search t
))
705 (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
706 (line-end-position) t
))
708 (string-to-number (buffer-substring
712 (match-beginning 2) (match-end 2))))
713 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
714 (line-end-position) t
)
717 (match-beginning 2) (match-end 2))
719 (match-beginning 3) (match-end 3))
721 (match-beginning 4) (match-end 4))))
725 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
726 (mail-strip-quoted-names
729 ;; Get all the lines of the From field
730 ;; so that we get a whole comment if there is one,
731 ;; so that mail-strip-quoted-names can discard it.
732 (let ((opoint (point)))
733 (while (progn (forward-line 1)
734 (looking-at "[ \t]")))
735 ;; Back up over newline, then trailing spaces or tabs
737 (skip-chars-backward " \t")
742 (or rmail-user-mail-address-regexp
744 (regexp-quote (user-login-name))
747 ;; Don't lose if run from init file
748 ;; where user-mail-address is not
750 (or user-mail-address
751 (concat (user-login-name) "@"
752 (or mail-host-address
756 ;; No From field, or it's this user.
758 (goto-char (point-min))
759 (if (not (re-search-forward "^To:[ \t]*" nil t
))
763 (mail-strip-quoted-names
767 (skip-chars-backward " \t")
771 (setq len
(length from
))
772 (setq mch
(string-match "[@%]" from
))
774 (if (or (not mch
) (<= len
25))
775 (substring from
(max 0 (- len
25)))
777 (setq lo
(cond ((< (- mch
14) 0) 0)
781 (min len
(+ lo
25)))))))))
782 (concat (if (re-search-forward "^Subject:" nil t
)
784 (skip-chars-forward " \t")
787 (setq str
(buffer-substring pos
(1- (point))))
788 (while (looking-at "\\s ")
789 (setq str
(concat str
" "
790 (buffer-substring (match-end 0)
791 (line-end-position))))
794 (re-search-forward "[\n][\n]+" nil t
)
795 (buffer-substring (point) (progn (end-of-line) (point))))
798 ;; Simple motion in a summary buffer.
800 (defun rmail-summary-next-all (&optional number
)
802 (forward-line (if number number
1))
803 ;; It doesn't look nice to move forward past the last message line.
804 (and (eobp) (> number
0)
806 (display-buffer rmail-buffer
))
808 (defun rmail-summary-previous-all (&optional number
)
810 (forward-line (- (if number number
1)))
811 ;; It doesn't look nice to move forward past the last message line.
812 (and (eobp) (< number
0)
814 (display-buffer rmail-buffer
))
816 (defun rmail-summary-next-msg (&optional number
)
817 "Display next non-deleted msg from rmail file.
818 With optional prefix argument NUMBER, moves forward this number of non-deleted
819 messages, or backward if NUMBER is negative."
822 (and (> number
0) (end-of-line))
823 (let ((count (if (< number
0) (- number
) number
))
824 (search (if (> number
0) 're-search-forward
're-search-backward
))
825 (non-del-msg-found nil
))
826 (while (and (> count
0) (setq non-del-msg-found
827 (or (funcall search
"^.....[^D]" nil t
)
829 (setq count
(1- count
))))
831 (display-buffer rmail-buffer
))
833 (defun rmail-summary-previous-msg (&optional number
)
834 "Display previous non-deleted msg from rmail file.
835 With optional prefix argument NUMBER, moves backward this number of
836 non-deleted messages."
838 (rmail-summary-next-msg (- (if number number
1))))
840 (defun rmail-summary-next-labeled-message (n labels
)
841 "Show next message with LABELS. Defaults to last labels used.
842 With prefix argument N moves forward N messages with these labels."
843 (interactive "p\nsMove to next msg with labels: ")
845 (with-current-buffer rmail-buffer
846 (rmail-next-labeled-message n labels
)
847 (setq msg rmail-current-message
))
848 (rmail-summary-goto-msg msg
)))
850 (defun rmail-summary-previous-labeled-message (n labels
)
851 "Show previous message with LABELS. Defaults to last labels used.
852 With prefix argument N moves backward N messages with these labels."
853 (interactive "p\nsMove to previous msg with labels: ")
855 (with-current-buffer rmail-buffer
856 (rmail-previous-labeled-message n labels
)
857 (setq msg rmail-current-message
))
858 (rmail-summary-goto-msg msg
)))
860 (defun rmail-summary-next-same-subject (n)
861 "Go to the next message in the summary having the same subject.
862 With prefix argument N, do this N times.
863 If N is negative, go backwards."
865 (let ((forward (> n
0))
867 (with-current-buffer rmail-buffer
868 (setq subject
(rmail-simplified-subject)
869 i rmail-current-message
))
876 (while (and (not done
)
880 ;; Advance thru summary.
881 (forward-line (if forward
1 -
1))
882 ;; Get msg number of this line.
883 (setq i
(string-to-number
884 (buffer-substring (point)
885 (min (point-max) (+ 6 (point))))))
886 (setq done
(string-equal subject
(rmail-simplified-subject i
))))
887 (if done
(setq found i
)))
888 (setq n
(if forward
(1- n
) (1+ n
)))))
890 (rmail-summary-goto-msg found
)
891 (error "No %s message with same subject"
892 (if forward
"following" "previous")))))
894 (defun rmail-summary-previous-same-subject (n)
895 "Go to the previous message in the summary having the same subject.
896 With prefix argument N, do this N times.
897 If N is negative, go forwards instead."
899 (rmail-summary-next-same-subject (- n
)))
901 ;; Delete and undelete summary commands.
903 (defun rmail-summary-delete-forward (&optional count
)
904 "Delete this message and move to next nondeleted one.
905 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
906 A prefix argument serves as a repeat count;
907 a negative argument means to delete and move backward."
909 (unless (numberp count
) (setq count
1))
911 (backward (< count
0)))
913 (rmail-summary-goto-msg)
914 (with-current-buffer rmail-buffer
915 (rmail-delete-message)
916 (setq del-msg rmail-current-message
))
917 (rmail-summary-mark-deleted del-msg
)
918 (while (and (not (if backward
(bobp) (eobp)))
919 (save-excursion (beginning-of-line)
920 (looking-at " *[0-9]+D")))
921 (forward-line (if backward -
1 1)))
922 ;; It looks ugly to move to the empty line at end of buffer.
923 (and (eobp) (not backward
)
926 (if (> count
0) (1- count
) (1+ count
))))))
928 (defun rmail-summary-delete-backward (&optional count
)
929 "Delete this message and move to previous nondeleted one.
930 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
931 A prefix argument serves as a repeat count;
932 a negative argument means to delete and move forward."
934 (rmail-summary-delete-forward (- count
)))
936 (defun rmail-summary-mark-deleted (&optional n undel
)
937 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
938 (and n
(rmail-summary-goto-msg n t t
))
940 (not (overlay-get rmail-summary-overlay
'face
))
941 (let ((buffer-read-only nil
))
942 (skip-chars-forward " ")
943 (skip-chars-forward "0-9")
946 (progn (delete-char 1) (insert " ")))
949 ;; Register a new summary line.
950 (with-current-buffer rmail-buffer
951 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))))
954 (defun rmail-summary-update-line (n)
955 "Update the summary line for message N."
956 (when (rmail-summary-goto-msg n t t
)
957 (let* ((buffer-read-only nil
)
958 (start (line-beginning-position))
959 (end (line-beginning-position 2))
960 (overlays (overlays-in start end
))
962 (while (and (setq ov
(car overlays
))
963 (not (setq high
(overlay-get ov
'rmail-summary
))))
964 (setq overlays
(cdr overlays
)))
965 (delete-region start end
)
967 (with-current-buffer rmail-buffer
968 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))
972 (rmail-summary-update-highlight nil
)))))
974 (defun rmail-summary-mark-undeleted (n)
975 (rmail-summary-mark-deleted n t
))
977 (defun rmail-summary-deleted-p (&optional n
)
979 (and n
(rmail-summary-goto-msg n nil t
))
980 (skip-chars-forward " ")
981 (skip-chars-forward "0-9")
984 (defun rmail-summary-undelete (&optional arg
)
985 "Undelete current message.
986 Optional prefix ARG means undelete ARG previous messages."
989 (rmail-summary-undelete-many arg
)
990 (let ((buffer-read-only nil
)
993 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
994 (replace-match "\\1 ")
995 (rmail-summary-goto-msg)
996 (if rmail-enable-mime
997 (set-buffer rmail-buffer
)
998 (rmail-pop-to-buffer rmail-buffer
))
999 (and (rmail-message-deleted-p rmail-current-message
)
1000 (rmail-undelete-previous-message))
1001 (if rmail-enable-mime
1002 (rmail-pop-to-buffer rmail-buffer
))
1003 (rmail-pop-to-buffer rmail-summary-buffer
))
1004 (t (goto-char opoint
))))))
1006 (defun rmail-summary-undelete-many (&optional n
)
1007 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
1009 (with-current-buffer rmail-buffer
1010 (let* ((init-msg (if n rmail-current-message rmail-total-messages
))
1011 (rmail-current-message init-msg
)
1012 (n (or n rmail-total-messages
))
1014 (while (and (> rmail-current-message
0)
1016 (if (rmail-message-deleted-p rmail-current-message
)
1017 (progn (rmail-set-attribute rmail-deleted-attr-index nil
)
1018 (setq msgs-undeled
(1+ msgs-undeled
))))
1019 (setq rmail-current-message
(1- rmail-current-message
)))
1020 (set-buffer rmail-summary-buffer
)
1021 (setq rmail-current-message init-msg msgs-undeled
0)
1022 (while (and (> rmail-current-message
0)
1024 (if (rmail-summary-deleted-p rmail-current-message
)
1025 (progn (rmail-summary-mark-undeleted rmail-current-message
)
1026 (setq msgs-undeled
(1+ msgs-undeled
))))
1027 (setq rmail-current-message
(1- rmail-current-message
))))
1028 (rmail-summary-goto-msg)))
1030 ;; Rmail Summary mode is suitable only for specially formatted data.
1031 (put 'rmail-summary-mode
'mode-class
'special
)
1033 (defun rmail-summary-mode ()
1034 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
1035 As commands are issued in the summary buffer, they are applied to the
1036 corresponding mail messages in the rmail buffer.
1038 All normal editing commands are turned off.
1039 Instead, nearly all the Rmail mode commands are available,
1040 though many of them move only among the messages in the summary.
1042 These additional commands exist:
1044 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
1045 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
1047 Commands for sorting the summary:
1049 \\[rmail-summary-sort-by-date] Sort by date.
1050 \\[rmail-summary-sort-by-subject] Sort by subject.
1051 \\[rmail-summary-sort-by-author] Sort by author.
1052 \\[rmail-summary-sort-by-recipient] Sort by recipient.
1053 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
1054 \\[rmail-summary-sort-by-lines] Sort by lines.
1055 \\[rmail-summary-sort-by-labels] Sort by labels."
1057 (kill-all-local-variables)
1058 (setq major-mode
'rmail-summary-mode
)
1059 (setq mode-name
"RMAIL Summary")
1060 (setq truncate-lines t
)
1061 (setq buffer-read-only t
)
1062 (set-syntax-table text-mode-syntax-table
)
1063 (make-local-variable 'rmail-buffer
)
1064 (make-local-variable 'rmail-total-messages
)
1065 (make-local-variable 'rmail-current-message
)
1066 (setq rmail-current-message nil
)
1067 (make-local-variable 'rmail-summary-redo
)
1068 (setq rmail-summary-redo nil
)
1069 (make-local-variable 'revert-buffer-function
)
1070 (make-local-variable 'font-lock-defaults
)
1071 (setq font-lock-defaults
'(rmail-summary-font-lock-keywords t
))
1072 (rmail-summary-enable)
1073 (run-mode-hooks 'rmail-summary-mode-hook
))
1075 ;; Summary features need to be disabled during edit mode.
1076 (defun rmail-summary-disable ()
1077 (use-local-map text-mode-map
)
1078 (remove-hook 'post-command-hook
'rmail-summary-rmail-update t
)
1079 (setq revert-buffer-function nil
))
1081 (defun rmail-summary-enable ()
1082 (use-local-map rmail-summary-mode-map
)
1083 (add-hook 'post-command-hook
'rmail-summary-rmail-update nil t
)
1084 (setq revert-buffer-function
'rmail-update-summary
))
1086 (defun rmail-summary-mark-seen (n &optional nomove unseen
)
1087 "Remove the unseen mark from the current message, update the summary vector.
1088 N is the number of the current message. Optional argument NOMOVE
1089 non-nil means we are already at the right column. Optional argument
1090 UNSEEN non-nil means mark the message as unseen."
1094 (skip-chars-forward " ")
1095 (skip-chars-forward "0-9"))
1096 (when (char-equal (following-char) (if unseen ?\s ?-
))
1097 (let ((buffer-read-only nil
))
1099 (insert (if unseen
"-" " ")))
1100 (let ((line (buffer-substring-no-properties (line-beginning-position)
1101 (line-beginning-position 2))))
1102 (with-current-buffer rmail-buffer
1103 (aset rmail-summary-vector
(1- n
) line
))))))
1105 (defvar rmail-summary-put-back-unseen nil
1106 "Used for communicating between calls to `rmail-summary-rmail-update'.
1107 If it moves to a message within an Incremental Search, and removes
1108 the `unseen' attribute from that message, it sets this flag
1109 so that if the next motion between messages is in the same Incremental
1110 Search, the `unseen' attribute is restored.")
1112 ;; Show in Rmail the message described by the summary line that point is on,
1113 ;; but only if the Rmail buffer is already visible.
1114 ;; This is a post-command-hook in summary buffers.
1115 (defun rmail-summary-rmail-update ()
1116 (let (buffer-read-only)
1118 ;; If at end of buffer, pretend we are on the last text line.
1122 (skip-chars-forward " ")
1123 (let ((msg-num (string-to-number (buffer-substring
1125 (progn (skip-chars-forward "0-9")
1127 ;; Always leave `unseen' removed
1128 ;; if we get out of isearch mode.
1129 ;; Don't let a subsequent isearch restore that `unseen'.
1130 (if (not isearch-mode
)
1131 (setq rmail-summary-put-back-unseen nil
))
1133 (or (eq rmail-current-message msg-num
)
1134 (let ((window (get-buffer-window rmail-buffer t
))
1135 (owin (selected-window)))
1138 ;; If we first saw the previous message in this search,
1139 ;; and we have gone to a different message while searching,
1140 ;; put back `unseen' on the former one.
1141 (when rmail-summary-put-back-unseen
1142 (rmail-set-attribute rmail-unseen-attr-index t
1143 rmail-current-message
)
1145 (goto-char rmail-summary-put-back-unseen
)
1146 (rmail-summary-mark-seen rmail-current-message t t
)))
1147 ;; Arrange to do that later, for the new current message,
1148 ;; if it still has `unseen'.
1149 (setq rmail-summary-put-back-unseen
1150 (if (rmail-message-unseen-p msg-num
)
1152 (setq rmail-summary-put-back-unseen nil
))
1153 ;; Go to the desired message.
1154 (setq rmail-current-message msg-num
)
1155 ;; Update the summary to show the message has been seen.
1156 (rmail-summary-mark-seen msg-num t
)
1158 ;; Using save-window-excursion would cause the new value
1159 ;; of point to get lost.
1162 (select-window window
)
1163 (rmail-show-message msg-num t
))
1164 (select-window owin
))
1165 (if (buffer-name rmail-buffer
)
1166 (with-current-buffer rmail-buffer
1167 (rmail-show-message msg-num t
))))
1168 ;; In linum mode, the message buffer must be specially
1169 ;; updated (Bug#4878).
1170 (and (fboundp 'linum-update
)
1171 (buffer-name rmail-buffer
)
1172 (linum-update rmail-buffer
))))
1173 (rmail-summary-update-highlight nil
)))))
1175 (defun rmail-summary-save-buffer ()
1176 "Save the buffer associated with this RMAIL summary."
1178 (save-window-excursion
1180 (switch-to-buffer rmail-buffer
)
1183 (defun rmail-summary-mouse-goto-message (event)
1184 "Select the message whose summary line you click on."
1186 (goto-char (posn-point (event-end event
)))
1187 (rmail-summary-goto-msg))
1189 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail
)
1190 "Go to message N in the summary buffer and the Rmail buffer.
1191 If N is nil, use the message corresponding to point in the summary
1192 and move to that message in the Rmail buffer.
1194 If NOWARN, don't say anything if N is out of range.
1195 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1196 Returns non-nil if message N was found."
1198 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1199 (if (eobp) (forward-line -
1))
1201 (let* ((obuf (current-buffer))
1205 (curmsg (string-to-number
1206 (buffer-substring (point)
1207 (min (point-max) (+ 6 (point))))))
1208 (total (with-current-buffer buf rmail-total-messages
)))
1209 ;; If message number N was specified, find that message's line
1210 ;; or set message-not-found.
1211 ;; If N wasn't specified or that message can't be found.
1212 ;; set N by default.
1216 (progn (message "No preceding message")
1218 (if (and (> n total
)
1220 (progn (message "No following message")
1221 (goto-char (point-max))
1222 (rmail-summary-goto-msg nil nowarn skip-rmail
)))
1223 (goto-char (point-min))
1224 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1225 (progn (or nowarn
(message "Message %d not found" n
))
1227 (setq message-not-found t
)
1229 (rmail-summary-mark-seen n
)
1230 (rmail-summary-update-highlight message-not-found
)
1233 (let ((selwin (selected-window)))
1235 (progn (rmail-pop-to-buffer buf
)
1236 (rmail-show-message n
))
1237 (select-window selwin
)
1238 ;; The actions above can alter the current buffer. Preserve it.
1239 (set-buffer obuf
))))
1240 (not message-not-found
)))
1242 ;; Update the highlighted line in an rmail summary buffer.
1243 ;; That should be current. We highlight the line point is on.
1244 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1245 (defun rmail-summary-update-highlight (not-found)
1246 ;; Make sure we have an overlay to use.
1247 (or rmail-summary-overlay
1249 (make-local-variable 'rmail-summary-overlay
)
1250 (setq rmail-summary-overlay
(make-overlay (point) (point)))
1251 (overlay-put rmail-summary-overlay
'rmail-summary t
)))
1252 ;; If this message is in the summary, use the overlay to highlight it.
1253 ;; Otherwise, don't highlight anything.
1255 (overlay-put rmail-summary-overlay
'face nil
)
1256 (move-overlay rmail-summary-overlay
1257 (save-excursion (beginning-of-line)
1258 (skip-chars-forward " ")
1260 (line-end-position))
1261 (overlay-put rmail-summary-overlay
'face
'highlight
)))
1263 (defun rmail-summary-scroll-msg-up (&optional dist
)
1264 "Scroll the Rmail window forward.
1265 If the Rmail window is displaying the end of a message,
1266 advance to the next message."
1269 (rmail-summary-scroll-msg-down nil
)
1270 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1271 (if rmail-buffer-window
1272 (if (let ((rmail-summary-window (selected-window)))
1273 (select-window rmail-buffer-window
)
1275 ;; Is EOB visible in the buffer?
1277 (let ((ht (window-height (selected-window))))
1278 (move-to-window-line (- ht
2))
1281 (select-window rmail-summary-window
)))
1282 (if (not rmail-summary-scroll-between-messages
)
1283 (error "End of buffer")
1284 (rmail-summary-next-msg (or dist
1)))
1285 (let ((other-window-scroll-buffer rmail-buffer
))
1286 (scroll-other-window dist
)))
1287 ;; If it isn't visible at all, show the beginning.
1288 (rmail-summary-beginning-of-message)))))
1290 (defun rmail-summary-scroll-msg-down (&optional dist
)
1291 "Scroll the Rmail window backward.
1292 If the Rmail window is now displaying the beginning of a message,
1293 move to the previous message."
1296 (rmail-summary-scroll-msg-up nil
)
1297 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1298 (if rmail-buffer-window
1299 (if (let ((rmail-summary-window (selected-window)))
1300 (select-window rmail-buffer-window
)
1302 ;; Is BOB visible in the buffer?
1304 (move-to-window-line 0)
1307 (select-window rmail-summary-window
)))
1308 (if (not rmail-summary-scroll-between-messages
)
1309 (error "Beginning of buffer")
1310 (rmail-summary-previous-msg (or dist
1)))
1311 (let ((other-window-scroll-buffer rmail-buffer
))
1312 (scroll-other-window-down dist
)))
1313 ;; If it isn't visible at all, show the beginning.
1314 (rmail-summary-beginning-of-message)))))
1316 (defun rmail-summary-beginning-of-message ()
1317 "Show current message from the beginning."
1319 (rmail-summary-show-message 'BEG
))
1321 (defun rmail-summary-end-of-message ()
1322 "Show bottom of current message."
1324 (rmail-summary-show-message 'END
))
1326 (defun rmail-summary-show-message (where)
1327 "Show current mail message.
1328 Position it according to WHERE which can be BEG or END"
1329 (if (and (one-window-p) (not pop-up-frames
))
1330 ;; If there is just one window, put the summary on the top.
1331 (let ((buffer rmail-buffer
))
1332 (split-window (selected-window) rmail-summary-window-size
)
1333 (select-window (frame-first-window))
1334 (rmail-pop-to-buffer rmail-buffer
)
1335 ;; If pop-to-buffer did not use that window, delete that
1336 ;; window. (This can happen if it uses another frame.)
1337 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1338 (delete-other-windows)))
1339 (rmail-pop-to-buffer rmail-buffer
))
1342 (goto-char (point-min))
1343 (search-forward "\n\n"))
1345 (goto-char (point-max))
1346 (recenter (1- (window-height))))
1348 (rmail-pop-to-buffer rmail-summary-buffer
))
1350 (defun rmail-summary-bury ()
1351 "Bury the Rmail buffer and the Rmail summary buffer."
1353 (let ((buffer-to-bury (current-buffer)))
1355 (while (setq window
(get-buffer-window rmail-buffer
))
1356 (set-window-buffer window
(other-buffer rmail-buffer
)))
1357 (bury-buffer rmail-buffer
))
1358 (switch-to-buffer (other-buffer buffer-to-bury
))
1359 (bury-buffer buffer-to-bury
)))
1361 (defun rmail-summary-quit ()
1362 "Quit out of Rmail and Rmail summary."
1364 (rmail-summary-wipe)
1367 (defun rmail-summary-wipe ()
1368 "Kill and wipe away Rmail summary, remaining within Rmail."
1370 (with-current-buffer rmail-buffer
(setq rmail-summary-buffer nil
))
1371 (let ((local-rmail-buffer rmail-buffer
))
1372 (kill-buffer (current-buffer))
1373 ;; Delete window if not only one.
1374 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1376 ;; Switch windows to the rmail buffer, or switch to it in this window.
1377 (rmail-pop-to-buffer local-rmail-buffer
)))
1379 (defun rmail-summary-expunge ()
1380 "Actually erase all deleted messages and recompute summary headers."
1382 (with-current-buffer rmail-buffer
1383 (when (rmail-expunge-confirmed)
1384 (rmail-only-expunge)))
1385 (rmail-update-summary))
1387 (defun rmail-summary-expunge-and-save ()
1388 "Expunge and save RMAIL file."
1391 (rmail-expunge-and-save))
1392 (rmail-update-summary)
1393 (set-buffer-modified-p nil
))
1395 (defun rmail-summary-get-new-mail (&optional file-name
)
1396 "Get new mail and recompute summary headers.
1398 Optionally you can specify the file to get new mail from. In this case,
1399 the file of new mail is not changed or deleted. Noninteractively, you can
1400 pass the inbox file name as an argument. Interactively, a prefix
1401 argument says to read a file name and use that file as the inbox."
1403 (list (if current-prefix-arg
1404 (read-file-name "Get new mail from file: "))))
1406 (with-current-buffer rmail-buffer
1407 (rmail-get-new-mail file-name
)
1408 ;; Get the proper new message number.
1409 (setq msg rmail-current-message
))
1410 ;; Make sure that message is displayed.
1412 (rmail-summary-goto-msg msg
))))
1414 (defun rmail-summary-input (filename)
1415 "Run Rmail on file FILENAME."
1416 (interactive "FRun rmail on RMAIL file: ")
1417 ;; We switch windows here, then display the other Rmail file there.
1418 (rmail-pop-to-buffer rmail-buffer
)
1421 (defun rmail-summary-first-message ()
1422 "Show first message in Rmail file from summary buffer."
1425 (beginning-of-buffer)))
1427 (defun rmail-summary-last-message ()
1428 "Show last message in Rmail file from summary buffer."
1434 (declare-function rmail-abort-edit
"rmailedit" ())
1435 (declare-function rmail-cease-edit
"rmailedit"())
1436 (declare-function rmail-set-label
"rmailkwd" (l state
&optional n
))
1437 (declare-function rmail-output-read-file-name
"rmailout" ())
1438 (declare-function mail-send-and-exit
"sendmail" (&optional arg
))
1440 (defvar rmail-summary-edit-map nil
)
1441 (if rmail-summary-edit-map
1443 (setq rmail-summary-edit-map
1444 (nconc (make-sparse-keymap) text-mode-map
))
1445 (define-key rmail-summary-edit-map
"\C-c\C-c" 'rmail-cease-edit
)
1446 (define-key rmail-summary-edit-map
"\C-c\C-]" 'rmail-abort-edit
))
1448 (defun rmail-summary-edit-current-message ()
1449 "Edit the contents of this message."
1451 (rmail-pop-to-buffer rmail-buffer
)
1452 (rmail-edit-current-message)
1453 (use-local-map rmail-summary-edit-map
))
1455 (defun rmail-summary-cease-edit ()
1456 "Finish editing message, then go back to Rmail summary buffer."
1459 (rmail-pop-to-buffer rmail-summary-buffer
))
1461 (defun rmail-summary-abort-edit ()
1462 "Abort edit of current message; restore original contents.
1463 Go back to summary buffer."
1466 (rmail-pop-to-buffer rmail-summary-buffer
))
1468 (defun rmail-summary-search-backward (regexp &optional n
)
1469 "Show message containing next match for REGEXP.
1470 Prefix argument gives repeat count; negative argument means search
1471 backwards (through earlier messages).
1472 Interactively, empty argument means use same regexp used last time."
1474 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1476 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1480 (if rmail-search-last-regexp
1481 (concat ", default "
1482 rmail-search-last-regexp
"): ")
1484 (setq regexp
(read-string prompt
))
1485 (cond ((not (equal regexp
""))
1486 (setq rmail-search-last-regexp regexp
))
1487 ((not rmail-search-last-regexp
)
1488 (error "No previous Rmail search string")))
1489 (list rmail-search-last-regexp
1490 (prefix-numeric-value current-prefix-arg
))))
1491 ;; Don't use save-excursion because that prevents point from moving
1492 ;; properly in the summary buffer.
1493 (with-current-buffer rmail-buffer
1494 (rmail-search regexp
(- n
))))
1496 (defun rmail-summary-search (regexp &optional n
)
1497 "Show message containing next match for REGEXP.
1498 Prefix argument gives repeat count; negative argument means search
1499 backwards (through earlier messages).
1500 Interactively, empty argument means use same regexp used last time."
1502 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1504 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1508 (if rmail-search-last-regexp
1509 (concat ", default "
1510 rmail-search-last-regexp
"): ")
1512 (setq regexp
(read-string prompt
))
1513 (cond ((not (equal regexp
""))
1514 (setq rmail-search-last-regexp regexp
))
1515 ((not rmail-search-last-regexp
)
1516 (error "No previous Rmail search string")))
1517 (list rmail-search-last-regexp
1518 (prefix-numeric-value current-prefix-arg
))))
1519 ;; Don't use save-excursion because that prevents point from moving
1520 ;; properly in the summary buffer.
1521 (let ((buffer (current-buffer))
1522 (selwin (selected-window)))
1525 (rmail-pop-to-buffer rmail-buffer
)
1526 (rmail-search regexp n
))
1527 (select-window selwin
)
1528 (set-buffer buffer
))))
1530 (defun rmail-summary-toggle-header ()
1531 "Show original message header if pruned header currently shown, or vice versa."
1533 (save-window-excursion
1534 (set-buffer rmail-buffer
)
1535 (rmail-toggle-header))
1536 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1537 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1538 (let ((window (get-buffer-window rmail-buffer
)))
1540 ;; Using save-window-excursion would lose the new value of point.
1541 (let ((owin (selected-window)))
1544 (select-window window
)
1545 (goto-char (point-min)))
1546 (select-window owin
))))))
1549 (defun rmail-summary-add-label (label)
1550 "Add LABEL to labels associated with current Rmail message.
1551 Completion is performed over known labels when reading."
1552 (interactive (list (with-current-buffer rmail-buffer
1553 (rmail-read-label "Add label"))))
1554 (with-current-buffer rmail-buffer
1555 (rmail-add-label label
)))
1557 (defun rmail-summary-kill-label (label)
1558 "Remove LABEL from labels associated with current Rmail message.
1559 Completion is performed over known labels when reading."
1560 (interactive (list (with-current-buffer rmail-buffer
1561 (rmail-read-label "Kill label"))))
1562 (with-current-buffer rmail-buffer
1563 (rmail-set-label label nil
)))
1565 ;;;; *** Rmail Summary Mailing Commands ***
1567 (defun rmail-summary-override-mail-send-and-exit ()
1568 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1569 (use-local-map (copy-keymap (current-local-map)))
1570 (dolist (key (where-is-internal 'mail-send-and-exit
))
1571 (define-key (current-local-map) key
'rmail-summary-send-and-exit
)))
1573 (defun rmail-summary-mail ()
1574 "Send mail in another window.
1575 While composing the message, use \\[mail-yank-original] to yank the
1576 original message into it."
1578 (let ((window (get-buffer-window rmail-buffer
)))
1580 (select-window window
)
1581 (set-buffer rmail-buffer
)))
1582 (rmail-start-mail nil nil nil nil nil
(current-buffer))
1583 (rmail-summary-override-mail-send-and-exit))
1585 (defun rmail-summary-continue ()
1586 "Continue composing outgoing message previously being composed."
1588 (let ((window (get-buffer-window rmail-buffer
)))
1590 (select-window window
)
1591 (set-buffer rmail-buffer
)))
1592 (rmail-start-mail t
))
1594 (defun rmail-summary-reply (just-sender)
1595 "Reply to the current message.
1596 Normally include CC: to all other recipients of original message;
1597 prefix argument means ignore them. While composing the reply,
1598 use \\[mail-yank-original] to yank the original message into it."
1600 (let ((window (get-buffer-window rmail-buffer
)))
1602 (select-window window
)
1603 (set-buffer rmail-buffer
)))
1604 (rmail-reply just-sender
)
1605 (rmail-summary-override-mail-send-and-exit))
1607 (defun rmail-summary-retry-failure ()
1608 "Edit a mail message which is based on the contents of the current message.
1609 For a message rejected by the mail system, extract the interesting headers and
1610 the body of the original message; otherwise copy the current message."
1612 (let ((window (get-buffer-window rmail-buffer
)))
1614 (select-window window
)
1615 (set-buffer rmail-buffer
)))
1616 (rmail-retry-failure)
1617 (rmail-summary-override-mail-send-and-exit))
1619 (defun rmail-summary-send-and-exit ()
1620 "Send mail reply and return to summary buffer."
1622 (mail-send-and-exit t
))
1624 (defun rmail-summary-forward (resend)
1625 "Forward the current message to another user.
1626 With prefix argument, \"resend\" the message instead of forwarding it;
1627 see the documentation of `rmail-resend'."
1630 (let ((window (get-buffer-window rmail-buffer
)))
1632 (select-window window
)
1633 (set-buffer rmail-buffer
)))
1634 (rmail-forward resend
)
1635 (rmail-summary-override-mail-send-and-exit)))
1637 (defun rmail-summary-resend ()
1638 "Resend current message using `rmail-resend'."
1641 (let ((window (get-buffer-window rmail-buffer
)))
1643 (select-window window
)
1644 (set-buffer rmail-buffer
)))
1645 (call-interactively 'rmail-resend
)))
1647 ;; Summary output commands.
1649 (defun rmail-summary-output (&optional file-name n
)
1650 "Append this message to mail file FILE-NAME.
1651 This works with both mbox format and Babyl format files,
1652 outputting in the appropriate format for each.
1653 The default file name comes from `rmail-default-file',
1654 which is updated to the name you use in this command.
1656 A prefix argument N says to output that many consecutive messages
1657 from those in the summary, starting with the current one.
1658 Deleted messages are skipped and don't count.
1659 When called from Lisp code, N may be omitted and defaults to 1.
1661 This command always outputs the complete message header,
1662 even the header display is currently pruned."
1664 (progn (require 'rmailout
)
1665 (list (rmail-output-read-file-name)
1666 (prefix-numeric-value current-prefix-arg
))))
1667 (let ((i 0) prev-msg
)
1670 (progn (rmail-summary-goto-msg)
1673 (with-current-buffer rmail-buffer
1674 rmail-current-message
))))))
1676 (with-current-buffer rmail-buffer
1677 (let ((rmail-delete-after-output nil
))
1678 (rmail-output file-name
1)))
1679 (if rmail-delete-after-output
1680 (rmail-summary-delete-forward nil
)
1682 (rmail-summary-next-msg 1))))))
1684 (defalias 'rmail-summary-output-to-rmail-file
'rmail-summary-output
)
1686 (declare-function rmail-output-as-seen
"rmailout"
1687 (file-name &optional count noattribute from-gnus
))
1689 (defun rmail-summary-output-as-seen (&optional file-name n
)
1690 "Append this message to mbox file named FILE-NAME.
1691 A prefix argument N says to output that many consecutive messages,
1692 from the summary, starting with the current one.
1693 Deleted messages are skipped and don't count.
1694 When called from Lisp code, N may be omitted and defaults to 1.
1696 This outputs the message header as you see it (or would see it)
1699 The default file name comes from `rmail-default-file',
1700 which is updated to the name you use in this command."
1702 (progn (require 'rmailout
)
1703 (list (rmail-output-read-file-name)
1704 (prefix-numeric-value current-prefix-arg
))))
1705 (require 'rmailout
) ; for rmail-output-as-seen in non-interactive case
1706 (let ((i 0) prev-msg
)
1709 (progn (rmail-summary-goto-msg)
1712 (with-current-buffer rmail-buffer
1713 rmail-current-message
))))))
1715 (with-current-buffer rmail-buffer
1716 (let ((rmail-delete-after-output nil
))
1717 (rmail-output-as-seen file-name
1)))
1718 (if rmail-delete-after-output
1719 (rmail-summary-delete-forward nil
)
1721 (rmail-summary-next-msg 1))))))
1723 (defun rmail-summary-output-menu ()
1724 "Output current message to another Rmail file, chosen with a menu.
1725 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1726 The variables `rmail-secondary-file-directory' and
1727 `rmail-secondary-file-regexp' control which files are offered in the menu."
1729 (with-current-buffer rmail-buffer
1730 (let ((rmail-delete-after-output nil
))
1731 (call-interactively 'rmail-output-menu
)))
1732 (if rmail-delete-after-output
1733 (rmail-summary-delete-forward nil
)))
1735 (defun rmail-summary-construct-io-menu ()
1736 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1739 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1740 (cons "Input Rmail File"
1741 (rmail-list-to-menu "Input Rmail File"
1743 'rmail-summary-input
)))
1744 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1745 (cons "Output Rmail File"
1746 (rmail-list-to-menu "Output Rmail File"
1748 'rmail-summary-output
))))
1749 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1750 '("Input Rmail File" . rmail-disable-menu
))
1751 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1752 '("Output Rmail File" . rmail-disable-menu
)))))
1754 (defun rmail-summary-output-body (&optional file-name
)
1755 "Write this message body to the file FILE-NAME.
1756 FILE-NAME defaults, interactively, from the Subject field of the message."
1758 (with-current-buffer rmail-buffer
1759 (let ((rmail-delete-after-output nil
))
1761 (rmail-output-body-to-file file-name
)
1762 (call-interactively 'rmail-output-body-to-file
))))
1763 (if rmail-delete-after-output
1764 (rmail-summary-delete-forward nil
)))
1766 ;; Sorting messages in Rmail Summary buffer.
1768 (defun rmail-summary-sort-by-date (reverse)
1769 "Sort messages of current Rmail summary by \"Date\" header.
1770 If prefix argument REVERSE is non-nil, sorts in reverse order."
1772 (rmail-sort-from-summary (function rmail-sort-by-date
) reverse
))
1774 (defun rmail-summary-sort-by-subject (reverse)
1775 "Sort messages of current Rmail summary by \"Subject\" header.
1776 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
1777 non-nil, sorts in reverse order."
1779 (rmail-sort-from-summary (function rmail-sort-by-subject
) reverse
))
1781 (defun rmail-summary-sort-by-author (reverse)
1782 "Sort messages of current Rmail summary by author.
1783 This uses either the \"From\" or \"Sender\" header, downcased.
1784 If prefix argument REVERSE is non-nil, sorts in reverse order."
1786 (rmail-sort-from-summary (function rmail-sort-by-author
) reverse
))
1788 (defun rmail-summary-sort-by-recipient (reverse)
1789 "Sort messages of current Rmail summary by recipient.
1790 This uses either the \"To\" or \"Apparently-To\" header, downcased.
1791 If prefix argument REVERSE is non-nil, sorts in reverse order."
1793 (rmail-sort-from-summary (function rmail-sort-by-recipient
) reverse
))
1795 (defun rmail-summary-sort-by-correspondent (reverse)
1796 "Sort messages of current Rmail summary by other correspondent.
1797 This uses either the \"From\", \"Sender\", \"To\", or
1798 \"Apparently-To\" header, downcased. Uses the first header not
1799 excluded by `mail-dont-reply-to-names'. If prefix argument
1800 REVERSE is non-nil, sorts in reverse order."
1802 (rmail-sort-from-summary (function rmail-sort-by-correspondent
) reverse
))
1804 (defun rmail-summary-sort-by-lines (reverse)
1805 "Sort messages of current Rmail summary by the number of lines.
1806 If prefix argument REVERSE is non-nil, sorts in reverse order."
1808 (rmail-sort-from-summary (function rmail-sort-by-lines
) reverse
))
1810 (defun rmail-summary-sort-by-labels (reverse labels
)
1811 "Sort messages of current Rmail summary by labels.
1812 LABELS is a comma-separated list of labels.
1813 If prefix argument REVERSE is non-nil, sorts in reverse order."
1814 (interactive "P\nsSort by labels: ")
1815 (rmail-sort-from-summary
1816 (lambda (reverse) (rmail-sort-by-labels reverse labels
))
1819 (defun rmail-sort-from-summary (sortfun reverse
)
1820 "Sort the Rmail buffer using sorting function SORTFUN.
1821 Passes REVERSE to SORTFUN as its sole argument. Then regenerates
1822 the summary. Note that the whole Rmail buffer is sorted, even if
1823 the summary is only showing a subset of messages."
1824 (require 'rmailsort
)
1825 (let ((selwin (selected-window)))
1827 (progn (rmail-pop-to-buffer rmail-buffer
)
1828 (funcall sortfun reverse
))
1829 (select-window selwin
))))
1834 ;; generated-autoload-file: "rmail.el"
1837 ;;; rmailsum.el ends here