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 (or (zerop (buffer-size)) ; empty summary
273 (get-buffer-window rmail-buffer
))
274 (rmail-summary-beginning-of-message)))
277 (defun rmail-summary-by-labels (labels)
278 "Display a summary of all messages with one or more LABELS.
279 LABELS should be a string containing the desired labels, separated by commas."
280 (interactive "sLabels to summarize by: ")
281 (if (string= labels
"")
282 (setq labels
(or rmail-last-multi-labels
283 (error "No label specified"))))
284 (setq rmail-last-multi-labels labels
)
285 (rmail-new-summary (concat "labels " labels
)
286 (list 'rmail-summary-by-labels labels
)
287 'rmail-message-labels-p
289 (mail-comma-list-regexp labels
)
290 "\\)\\(,\\|\\'\\)")))
292 ;; FIXME "a string of regexps separated by commas" makes no sense because:
293 ;; i) it's pointless (you can just use \\|)
294 ;; ii) it's broken (you can't specify a literal comma)
295 ;; rmail-summary-by-topic and rmail-summary-by-senders have the same issue.
297 (defun rmail-summary-by-recipients (recipients &optional primary-only
)
298 "Display a summary of all messages with the given RECIPIENTS.
299 Normally checks the To, From and Cc fields of headers;
300 but if PRIMARY-ONLY is non-nil (prefix arg given),
301 only look in the To and From fields.
302 RECIPIENTS is a string of regexps separated by commas."
303 (interactive "sRecipients to summarize by: \nP")
305 (concat "recipients " recipients
)
306 (list 'rmail-summary-by-recipients recipients primary-only
)
307 'rmail-message-recipients-p
308 (mail-comma-list-regexp recipients
) primary-only
))
310 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
311 (rmail-apply-in-message msg
'rmail-message-recipients-p-1
312 recipients primary-only
))
314 (defun rmail-message-recipients-p-1 (recipients &optional primary-only
)
315 ;; mail-fetch-field does not care where it starts from.
316 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
317 (or (string-match recipients
(or (mail-fetch-field "To") ""))
318 (string-match recipients
(or (mail-fetch-field "From") ""))
319 (if (not primary-only
)
320 (string-match recipients
(or (mail-fetch-field "Cc") "")))))
322 ;; FIXME I find this a non-obvious name for what this function does.
323 ;; Also, the optional WHOLE-MESSAGE argument of r-s-by-topic would
324 ;; seem more natural here.
326 (defun rmail-summary-by-regexp (regexp)
327 "Display a summary of all messages according to regexp REGEXP.
328 If the regular expression is found in the header of the message
329 \(including in the date and other lines, as well as the subject line),
330 Emacs will list the message in the summary."
331 (interactive "sRegexp to summarize by: ")
332 (if (string= regexp
"")
333 (setq regexp
(or rmail-last-regexp
334 (error "No regexp specified"))))
335 (setq rmail-last-regexp regexp
)
336 (rmail-new-summary (concat "regexp " regexp
)
337 (list 'rmail-summary-by-regexp regexp
)
338 'rmail-message-regexp-p
341 (defun rmail-message-regexp-p (msg regexp
)
342 "Return t, if for message number MSG, regexp REGEXP matches in the header."
343 (rmail-apply-in-message msg
'rmail-message-regexp-p-1 msg regexp
))
345 (defun rmail-message-regexp-p-1 (msg regexp
)
346 ;; Search functions can expect to start from the beginning.
347 (narrow-to-region (point) (save-excursion (search-forward "\n\n") (point)))
348 (if rmail-enable-mime
349 (if rmail-search-mime-header-function
350 (funcall rmail-search-mime-header-function msg regexp
(point))
351 (error "You must set `rmail-search-mime-header-function'"))
352 (re-search-forward regexp nil t
)))
355 (defun rmail-summary-by-topic (subject &optional whole-message
)
356 "Display a summary of all messages with the given SUBJECT.
357 Normally checks just the Subject field of headers; but with prefix
358 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
359 SUBJECT is a string of regexps separated by commas."
361 ;; We quote the default subject, because if it contains regexp
362 ;; special characters (eg "?"), it can fail to match itself. (Bug#2333)
363 (let* ((subject (regexp-quote (rmail-simplified-subject)))
364 (prompt (concat "Topics to summarize by (regexp"
365 (if subject
", default current subject" "")
367 (list (read-string prompt nil nil subject
) current-prefix-arg
)))
369 (concat "about " subject
)
370 (list 'rmail-summary-by-topic subject whole-message
)
371 'rmail-message-subject-p
372 (mail-comma-list-regexp subject
) whole-message
))
374 (defun rmail-message-subject-p (msg subject
&optional whole-message
)
376 (rmail-apply-in-message msg
're-search-forward subject nil t
)
377 (string-match subject
(rmail-simplified-subject msg
))))
380 (defun rmail-summary-by-senders (senders)
381 "Display a summary of all messages whose \"From\" field matches SENDERS.
382 SENDERS is a string of regexps separated by commas."
383 (interactive "sSenders to summarize by: ")
385 (concat "senders " senders
)
386 (list 'rmail-summary-by-senders senders
)
387 'rmail-message-senders-p
388 (mail-comma-list-regexp senders
)))
390 (defun rmail-message-senders-p (msg senders
)
391 (string-match senders
(or (rmail-get-header "From" msg
) "")))
393 ;; General making of a summary buffer.
395 (defvar rmail-summary-symbol-number
0)
397 (defvar rmail-new-summary-line-count
)
399 (defun rmail-new-summary (desc redo func
&rest args
)
400 "Create a summary of selected messages.
401 DESC makes part of the mode line of the summary buffer. REDO is form ...
402 For each message, FUNC is applied to the message number and ARGS...
403 and if the result is non-nil, that message is included.
404 nil for FUNCTION means all messages."
405 (message "Computing summary lines...")
407 (error "No RMAIL buffer found"))
408 (let (mesg was-in-summary sumbuf
)
409 (if (eq major-mode
'rmail-summary-mode
)
410 (setq was-in-summary t
))
411 (with-current-buffer rmail-buffer
412 (setq rmail-summary-buffer
(rmail-new-summary-1 desc redo func args
)
413 ;; r-s-b is buffer-local.
414 sumbuf rmail-summary-buffer
))
415 ;; Now display the summary buffer and go to the right place in it.
416 (unless was-in-summary
417 (if (and (one-window-p)
420 ;; If there is just one window, put the summary on the top.
422 (split-window (selected-window) rmail-summary-window-size
)
423 (select-window (next-window (frame-first-window)))
424 (rmail-pop-to-buffer sumbuf
)
425 ;; If pop-to-buffer did not use that window, delete that
426 ;; window. (This can happen if it uses another frame.)
427 (if (not (eq sumbuf
(window-buffer (frame-first-window))))
428 (delete-other-windows)))
429 (rmail-pop-to-buffer sumbuf
))
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
)
493 ;; I have not a clue what this clause is doing. If you read this
494 ;; chunk of code and have a clue, then please email that clue to
496 (if rmail-enable-mime
497 (with-current-buffer rmail-buffer
498 (setq rmail-summary-buffer nil
)))
500 (let ((rbuf (current-buffer))
501 (total rmail-total-messages
))
503 ;; Set up the summary buffer's contents.
504 (let ((buffer-read-only nil
))
507 (princ (cdr (car summary-msgs
)) sumbuf
)
508 (setq summary-msgs
(cdr summary-msgs
)))
509 (goto-char (point-min)))
510 ;; Set up the rest of its state and local variables.
511 (setq buffer-read-only t
)
513 (make-local-variable 'minor-mode-alist
)
514 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
515 (setq rmail-buffer rbuf
516 rmail-summary-redo form
517 rmail-total-messages total
)))
520 (defun rmail-get-create-summary-buffer ()
521 "Return the Rmail summary buffer.
522 If necessary, it is created and undo is disabled."
523 (if (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
))
525 (let ((buff (generate-new-buffer (concat (buffer-name) "-summary"))))
526 (with-current-buffer buff
527 (setq buffer-undo-list t
))
531 ;; Low levels of generating a summary.
533 (defun rmail-get-summary (msgnum)
534 "Return the summary line for message MSGNUM.
535 The mbox buffer must be current when you call this function
536 even if its text is swapped.
538 If the message has a summary line already, it will be stored in
539 the message as a header and simply returned, otherwise the
540 summary line is created, saved in the message header, cached and
543 The current buffer contains the unrestricted message collection."
544 (let ((line (aref rmail-summary-vector
(1- msgnum
))))
546 ;; Register a summary line for MSGNUM.
547 (setq rmail-new-summary-line-count
(1+ rmail-new-summary-line-count
)
548 line
(rmail-create-summary-line msgnum
))
549 ;; Cache the summary line for use during this Rmail session.
550 (aset rmail-summary-vector
(1- msgnum
) line
))
553 (defcustom rmail-summary-line-decoder
(function rfc2047-decode-string
)
554 "Function to decode a Rmail summary line.
555 It receives the summary line for one message as a string
556 and should return the decoded string.
558 By default, it is `rfc2047-decode-string', which decodes MIME-encoded
562 :group
'rmail-summary
)
564 (defun rmail-create-summary-line (msgnum)
565 "Return the summary line for message MSGNUM.
566 Obtain the message summary from the header if it is available
567 otherwise create it and store it in the message header.
569 The mbox buffer must be current when you call this function
570 even if its text is swapped."
571 (let ((beg (rmail-msgbeg msgnum
))
572 (end (rmail-msgend msgnum
))
573 (deleted (rmail-message-deleted-p msgnum
))
574 ;; Does not work (swapped?)
575 ;;; (unseen (rmail-message-unseen-p msgnum))
578 ;; Switch to the buffer that has the whole mbox text.
579 (if (rmail-buffers-swapped-p)
580 (set-buffer rmail-view-buffer
))
581 ;; Now we can compute the line count.
582 (if rmail-summary-line-count-flag
583 (setq lines
(count-lines beg end
)))
584 ;; Narrow to the message header.
589 (if (search-forward "\n\n" end t
)
591 (narrow-to-region beg
(point))
592 ;; Replace rmail-message-unseen-p from above.
594 (setq unseen
(and (search-forward
595 (concat rmail-attribute-header
": ") nil t
)
596 (looking-at "......U")))
597 ;; Generate a status line from the message.
598 (rmail-create-summary msgnum deleted unseen lines
))
599 (rmail-error-bad-format msgnum
)))))))
601 ;; FIXME this is now unused.
602 ;; The intention was to display in the summary something like {E}
603 ;; for an edited messaged, similarly for answered, etc.
604 ;; But that conflicts with the previous rmail usage, where
605 ;; any user-defined { labels } occupied this space.
606 ;; So whilst it would be nice to have this information in the summary,
607 ;; it would need to go somewhere else.
608 (defun rmail-get-summary-status ()
609 "Return a coded string wrapped in curly braces denoting the status.
611 The current buffer must already be narrowed to the message headers for
612 the message being processed."
613 (let ((status (mail-fetch-field rmail-attribute-header
))
617 ;; Strip off the read/unread and the deleted attribute which are
618 ;; handled separately.
621 (concat (substring status
0 1) (substring status
2 6))
623 (while (< index
(length status
))
624 (unless (string= "-" (setq char
(substring status index
(1+ index
))))
625 (setq result
(concat result char
)))
626 (setq index
(1+ index
)))
627 (when (> (length result
) 0)
628 (setq result
(concat "{" result
"}")))
631 (autoload 'rmail-make-label
"rmailkwd")
633 (defun rmail-get-summary-labels ()
634 "Return a string wrapped in curly braces with the current message labels.
635 Returns nil if there are no labels. The current buffer must
636 already be narrowed to the message headers for the message being
638 (let ((labels (mail-fetch-field rmail-keyword-header
)))
640 (not (string-equal labels
""))
642 ;; Intern so that rmail-read-label can offer completion.
643 (mapc 'rmail-make-label
(split-string labels
", "))
644 (format "{ %s } " labels
)))))
646 (defun rmail-create-summary (msgnum deleted unseen lines
)
647 "Return the summary line for message MSGNUM.
648 The current buffer should already be narrowed to the header for that message.
649 It could be either buffer, so don't access Rmail local variables.
650 DELETED is t if this message is marked deleted.
651 UNSEEN is t if it is marked unseen.
652 LINES is the number of lines in the message (if we should display that)
654 (goto-char (point-min))
655 (let ((line (rmail-header-summary))
656 (labels (rmail-get-summary-labels))
657 pos status prefix basic-start basic-end linecount-string
)
659 (setq linecount-string
662 ((<= lines
9) (format " [%d]" lines
))
663 ((<= lines
99) (format " [%d]" lines
))
664 ((<= lines
999) (format " [%d]" lines
))
665 ((<= lines
9999) (format " [%dk]" (/ lines
1000)))
666 ((<= lines
99999) (format " [%dk]" (/ lines
1000)))
667 (t (format "[%dk]" (/ lines
1000)))))
673 prefix
(format "%5d%c " msgnum status
)
674 basic-start
(car line
)
675 basic-end
(cadr line
))
676 (funcall rmail-summary-line-decoder
677 (concat prefix basic-start linecount-string
" "
680 (defun rmail-header-summary ()
681 "Return a message summary based on the message headers.
682 The value is a list of two strings, the first and second parts of the summary.
684 The current buffer must already be narrowed to the message headers for
685 the message being processed."
686 (goto-char (point-min))
688 (concat (save-excursion
689 (if (not (re-search-forward "^Date:" nil t
))
691 ;; Match month names case-insensitively
692 (cond ((let ((case-fold-search t
))
693 (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
694 (line-end-position) t
))
696 (string-to-number (buffer-substring
700 (match-beginning 4) (match-end 4))))
701 ((let ((case-fold-search t
))
702 (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
703 (line-end-position) t
))
705 (string-to-number (buffer-substring
709 (match-beginning 2) (match-end 2))))
710 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
711 (line-end-position) t
)
714 (match-beginning 2) (match-end 2))
716 (match-beginning 3) (match-end 3))
718 (match-beginning 4) (match-end 4))))
722 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
723 (mail-strip-quoted-names
726 ;; Get all the lines of the From field
727 ;; so that we get a whole comment if there is one,
728 ;; so that mail-strip-quoted-names can discard it.
729 (let ((opoint (point)))
730 (while (progn (forward-line 1)
731 (looking-at "[ \t]")))
732 ;; Back up over newline, then trailing spaces or tabs
734 (skip-chars-backward " \t")
739 (or rmail-user-mail-address-regexp
741 (regexp-quote (user-login-name))
744 ;; Don't lose if run from init file
745 ;; where user-mail-address is not
747 (or user-mail-address
748 (concat (user-login-name) "@"
749 (or mail-host-address
753 ;; No From field, or it's this user.
755 (goto-char (point-min))
756 (if (not (re-search-forward "^To:[ \t]*" nil t
))
760 (mail-strip-quoted-names
764 (skip-chars-backward " \t")
768 (setq len
(length from
))
769 (setq mch
(string-match "[@%]" from
))
771 (if (or (not mch
) (<= len
25))
772 (substring from
(max 0 (- len
25)))
774 (setq lo
(cond ((< (- mch
14) 0) 0)
778 (min len
(+ lo
25)))))))))
779 (concat (if (re-search-forward "^Subject:" nil t
)
781 (skip-chars-forward " \t")
784 (setq str
(buffer-substring pos
(1- (point))))
785 (while (looking-at "\\s ")
786 (setq str
(concat str
" "
787 (buffer-substring (match-end 0)
788 (line-end-position))))
791 (re-search-forward "[\n][\n]+" nil t
)
792 (buffer-substring (point) (progn (end-of-line) (point))))
795 ;; Simple motion in a summary buffer.
797 (defun rmail-summary-next-all (&optional number
)
799 (forward-line (if number number
1))
800 ;; It doesn't look nice to move forward past the last message line.
801 (and (eobp) (> number
0)
803 (display-buffer rmail-buffer
))
805 (defun rmail-summary-previous-all (&optional number
)
807 (forward-line (- (if number number
1)))
808 ;; It doesn't look nice to move forward past the last message line.
809 (and (eobp) (< number
0)
811 (display-buffer rmail-buffer
))
813 (defun rmail-summary-next-msg (&optional number
)
814 "Display next non-deleted msg from rmail file.
815 With optional prefix argument NUMBER, moves forward this number of non-deleted
816 messages, or backward if NUMBER is negative."
819 (and (> number
0) (end-of-line))
820 (let ((count (if (< number
0) (- number
) number
))
821 (search (if (> number
0) 're-search-forward
're-search-backward
))
822 (non-del-msg-found nil
))
823 (while (and (> count
0) (setq non-del-msg-found
824 (or (funcall search
"^.....[^D]" nil t
)
826 (setq count
(1- count
))))
828 (display-buffer rmail-buffer
))
830 (defun rmail-summary-previous-msg (&optional number
)
831 "Display previous non-deleted msg from rmail file.
832 With optional prefix argument NUMBER, moves backward this number of
833 non-deleted messages."
835 (rmail-summary-next-msg (- (if number number
1))))
837 (defun rmail-summary-next-labeled-message (n labels
)
838 "Show next message with LABELS. Defaults to last labels used.
839 With prefix argument N moves forward N messages with these labels."
840 (interactive "p\nsMove to next msg with labels: ")
842 (with-current-buffer rmail-buffer
843 (rmail-next-labeled-message n labels
)
844 (setq msg rmail-current-message
))
845 (rmail-summary-goto-msg msg
)))
847 (defun rmail-summary-previous-labeled-message (n labels
)
848 "Show previous message with LABELS. Defaults to last labels used.
849 With prefix argument N moves backward N messages with these labels."
850 (interactive "p\nsMove to previous msg with labels: ")
852 (with-current-buffer rmail-buffer
853 (rmail-previous-labeled-message n labels
)
854 (setq msg rmail-current-message
))
855 (rmail-summary-goto-msg msg
)))
857 (defun rmail-summary-next-same-subject (n)
858 "Go to the next message in the summary having the same subject.
859 With prefix argument N, do this N times.
860 If N is negative, go backwards."
862 (let ((forward (> n
0))
864 (with-current-buffer rmail-buffer
865 (setq subject
(rmail-simplified-subject)
866 i rmail-current-message
))
873 (while (and (not done
)
877 ;; Advance thru summary.
878 (forward-line (if forward
1 -
1))
879 ;; Get msg number of this line.
880 (setq i
(string-to-number
881 (buffer-substring (point)
882 (min (point-max) (+ 6 (point))))))
883 (setq done
(string-equal subject
(rmail-simplified-subject i
))))
884 (if done
(setq found i
)))
885 (setq n
(if forward
(1- n
) (1+ n
)))))
887 (rmail-summary-goto-msg found
)
888 (error "No %s message with same subject"
889 (if forward
"following" "previous")))))
891 (defun rmail-summary-previous-same-subject (n)
892 "Go to the previous message in the summary having the same subject.
893 With prefix argument N, do this N times.
894 If N is negative, go forwards instead."
896 (rmail-summary-next-same-subject (- n
)))
898 ;; Delete and undelete summary commands.
900 (defun rmail-summary-delete-forward (&optional count
)
901 "Delete this message and move to next nondeleted one.
902 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
903 A prefix argument serves as a repeat count;
904 a negative argument means to delete and move backward."
906 (unless (numberp count
) (setq count
1))
908 (backward (< count
0)))
910 (rmail-summary-goto-msg)
911 (with-current-buffer rmail-buffer
912 (rmail-delete-message)
913 (setq del-msg rmail-current-message
))
914 (rmail-summary-mark-deleted del-msg
)
915 (while (and (not (if backward
(bobp) (eobp)))
916 (save-excursion (beginning-of-line)
917 (looking-at " *[0-9]+D")))
918 (forward-line (if backward -
1 1)))
919 ;; It looks ugly to move to the empty line at end of buffer.
920 (and (eobp) (not backward
)
923 (if (> count
0) (1- count
) (1+ count
))))))
925 (defun rmail-summary-delete-backward (&optional count
)
926 "Delete this message and move to previous nondeleted one.
927 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
928 A prefix argument serves as a repeat count;
929 a negative argument means to delete and move forward."
931 (rmail-summary-delete-forward (- count
)))
933 (defun rmail-summary-mark-deleted (&optional n undel
)
934 ;; Since third arg is t, this only alters the summary, not the Rmail buf.
935 (and n
(rmail-summary-goto-msg n t t
))
937 (not (overlay-get rmail-summary-overlay
'face
))
938 (let ((buffer-read-only nil
))
939 (skip-chars-forward " ")
940 (skip-chars-forward "0-9")
943 (progn (delete-char 1) (insert " ")))
946 ;; Register a new summary line.
947 (with-current-buffer rmail-buffer
948 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))))
951 (defun rmail-summary-update-line (n)
952 "Update the summary line for message N."
953 (when (rmail-summary-goto-msg n t t
)
954 (let* ((buffer-read-only nil
)
955 (start (line-beginning-position))
956 (end (line-beginning-position 2))
957 (overlays (overlays-in start end
))
959 (while (and (setq ov
(car overlays
))
960 (not (setq high
(overlay-get ov
'rmail-summary
))))
961 (setq overlays
(cdr overlays
)))
962 (delete-region start end
)
964 (with-current-buffer rmail-buffer
965 (aset rmail-summary-vector
(1- n
) (rmail-create-summary-line n
)))
969 (rmail-summary-update-highlight nil
)))))
971 (defun rmail-summary-mark-undeleted (n)
972 (rmail-summary-mark-deleted n t
))
974 (defun rmail-summary-deleted-p (&optional n
)
976 (and n
(rmail-summary-goto-msg n nil t
))
977 (skip-chars-forward " ")
978 (skip-chars-forward "0-9")
981 (defun rmail-summary-undelete (&optional arg
)
982 "Undelete current message.
983 Optional prefix ARG means undelete ARG previous messages."
986 (rmail-summary-undelete-many arg
)
987 (let ((buffer-read-only nil
)
990 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
991 (replace-match "\\1 ")
992 (rmail-summary-goto-msg)
993 (if rmail-enable-mime
994 (set-buffer rmail-buffer
)
995 (rmail-pop-to-buffer rmail-buffer
))
996 (and (rmail-message-deleted-p rmail-current-message
)
997 (rmail-undelete-previous-message))
998 (if rmail-enable-mime
999 (rmail-pop-to-buffer rmail-buffer
))
1000 (rmail-pop-to-buffer rmail-summary-buffer
))
1001 (t (goto-char opoint
))))))
1003 (defun rmail-summary-undelete-many (&optional n
)
1004 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
1006 (with-current-buffer rmail-buffer
1007 (let* ((init-msg (if n rmail-current-message rmail-total-messages
))
1008 (rmail-current-message init-msg
)
1009 (n (or n rmail-total-messages
))
1011 (while (and (> rmail-current-message
0)
1013 (if (rmail-message-deleted-p rmail-current-message
)
1014 (progn (rmail-set-attribute rmail-deleted-attr-index nil
)
1015 (setq msgs-undeled
(1+ msgs-undeled
))))
1016 (setq rmail-current-message
(1- rmail-current-message
)))
1017 (set-buffer rmail-summary-buffer
)
1018 (setq rmail-current-message init-msg msgs-undeled
0)
1019 (while (and (> rmail-current-message
0)
1021 (if (rmail-summary-deleted-p rmail-current-message
)
1022 (progn (rmail-summary-mark-undeleted rmail-current-message
)
1023 (setq msgs-undeled
(1+ msgs-undeled
))))
1024 (setq rmail-current-message
(1- rmail-current-message
))))
1025 (rmail-summary-goto-msg)))
1027 ;; Rmail Summary mode is suitable only for specially formatted data.
1028 (put 'rmail-summary-mode
'mode-class
'special
)
1030 (defun rmail-summary-mode ()
1031 "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
1032 As commands are issued in the summary buffer, they are applied to the
1033 corresponding mail messages in the rmail buffer.
1035 All normal editing commands are turned off.
1036 Instead, nearly all the Rmail mode commands are available,
1037 though many of them move only among the messages in the summary.
1039 These additional commands exist:
1041 \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
1042 \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
1044 Commands for sorting the summary:
1046 \\[rmail-summary-sort-by-date] Sort by date.
1047 \\[rmail-summary-sort-by-subject] Sort by subject.
1048 \\[rmail-summary-sort-by-author] Sort by author.
1049 \\[rmail-summary-sort-by-recipient] Sort by recipient.
1050 \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
1051 \\[rmail-summary-sort-by-lines] Sort by lines.
1052 \\[rmail-summary-sort-by-labels] Sort by labels."
1054 (kill-all-local-variables)
1055 (setq major-mode
'rmail-summary-mode
)
1056 (setq mode-name
"RMAIL Summary")
1057 (setq truncate-lines t
)
1058 (setq buffer-read-only t
)
1059 (set-syntax-table text-mode-syntax-table
)
1060 (make-local-variable 'rmail-buffer
)
1061 (make-local-variable 'rmail-total-messages
)
1062 (make-local-variable 'rmail-current-message
)
1063 (setq rmail-current-message nil
)
1064 (make-local-variable 'rmail-summary-redo
)
1065 (setq rmail-summary-redo nil
)
1066 (make-local-variable 'revert-buffer-function
)
1067 (make-local-variable 'font-lock-defaults
)
1068 (setq font-lock-defaults
'(rmail-summary-font-lock-keywords t
))
1069 (rmail-summary-enable)
1070 (run-mode-hooks 'rmail-summary-mode-hook
))
1072 ;; Summary features need to be disabled during edit mode.
1073 (defun rmail-summary-disable ()
1074 (use-local-map text-mode-map
)
1075 (remove-hook 'post-command-hook
'rmail-summary-rmail-update t
)
1076 (setq revert-buffer-function nil
))
1078 (defun rmail-summary-enable ()
1079 (use-local-map rmail-summary-mode-map
)
1080 (add-hook 'post-command-hook
'rmail-summary-rmail-update nil t
)
1081 (setq revert-buffer-function
'rmail-update-summary
))
1083 (defun rmail-summary-mark-seen (n &optional nomove unseen
)
1084 "Remove the unseen mark from the current message, update the summary vector.
1085 N is the number of the current message. Optional argument NOMOVE
1086 non-nil means we are already at the right column. Optional argument
1087 UNSEEN non-nil means mark the message as unseen."
1091 (skip-chars-forward " ")
1092 (skip-chars-forward "0-9"))
1093 (when (char-equal (following-char) (if unseen ?\s ?-
))
1094 (let ((buffer-read-only nil
))
1096 (insert (if unseen
"-" " ")))
1097 (let ((line (buffer-substring-no-properties (line-beginning-position)
1098 (line-beginning-position 2))))
1099 (with-current-buffer rmail-buffer
1100 (aset rmail-summary-vector
(1- n
) line
))))))
1102 (defvar rmail-summary-put-back-unseen nil
1103 "Used for communicating between calls to `rmail-summary-rmail-update'.
1104 If it moves to a message within an Incremental Search, and removes
1105 the `unseen' attribute from that message, it sets this flag
1106 so that if the next motion between messages is in the same Incremental
1107 Search, the `unseen' attribute is restored.")
1109 ;; Show in Rmail the message described by the summary line that point is on,
1110 ;; but only if the Rmail buffer is already visible.
1111 ;; This is a post-command-hook in summary buffers.
1112 (defun rmail-summary-rmail-update ()
1113 (let (buffer-read-only)
1115 ;; If at end of buffer, pretend we are on the last text line.
1119 (skip-chars-forward " ")
1120 (let ((msg-num (string-to-number (buffer-substring
1122 (progn (skip-chars-forward "0-9")
1124 ;; Always leave `unseen' removed
1125 ;; if we get out of isearch mode.
1126 ;; Don't let a subsequent isearch restore that `unseen'.
1127 (if (not isearch-mode
)
1128 (setq rmail-summary-put-back-unseen nil
))
1130 (or (eq rmail-current-message msg-num
)
1131 (let ((window (get-buffer-window rmail-buffer t
))
1132 (owin (selected-window)))
1135 ;; If we first saw the previous message in this search,
1136 ;; and we have gone to a different message while searching,
1137 ;; put back `unseen' on the former one.
1138 (when rmail-summary-put-back-unseen
1139 (rmail-set-attribute rmail-unseen-attr-index t
1140 rmail-current-message
)
1142 (goto-char rmail-summary-put-back-unseen
)
1143 (rmail-summary-mark-seen rmail-current-message t t
)))
1144 ;; Arrange to do that later, for the new current message,
1145 ;; if it still has `unseen'.
1146 (setq rmail-summary-put-back-unseen
1147 (if (rmail-message-unseen-p msg-num
)
1149 (setq rmail-summary-put-back-unseen nil
))
1150 ;; Go to the desired message.
1151 (setq rmail-current-message msg-num
)
1152 ;; Update the summary to show the message has been seen.
1153 (rmail-summary-mark-seen msg-num t
)
1155 ;; Using save-window-excursion would cause the new value
1156 ;; of point to get lost.
1159 (select-window window
)
1160 (rmail-show-message msg-num t
))
1161 (select-window owin
))
1162 (if (buffer-name rmail-buffer
)
1163 (with-current-buffer rmail-buffer
1164 (rmail-show-message msg-num t
))))
1165 ;; In linum mode, the message buffer must be specially
1166 ;; updated (Bug#4878).
1167 (and (fboundp 'linum-update
)
1168 (buffer-name rmail-buffer
)
1169 (linum-update rmail-buffer
))))
1170 (rmail-summary-update-highlight nil
)))))
1172 (defun rmail-summary-save-buffer ()
1173 "Save the buffer associated with this RMAIL summary."
1175 (save-window-excursion
1177 (switch-to-buffer rmail-buffer
)
1180 (defun rmail-summary-mouse-goto-message (event)
1181 "Select the message whose summary line you click on."
1183 (goto-char (posn-point (event-end event
)))
1184 (rmail-summary-goto-msg))
1186 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail
)
1187 "Go to message N in the summary buffer and the Rmail buffer.
1188 If N is nil, use the message corresponding to point in the summary
1189 and move to that message in the Rmail buffer.
1191 If NOWARN, don't say anything if N is out of range.
1192 If SKIP-RMAIL, don't do anything to the Rmail buffer.
1193 Returns non-nil if message N was found."
1195 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1196 (if (eobp) (forward-line -
1))
1198 (let* ((obuf (current-buffer))
1202 (curmsg (string-to-number
1203 (buffer-substring (point)
1204 (min (point-max) (+ 6 (point))))))
1205 (total (with-current-buffer buf rmail-total-messages
)))
1206 ;; If message number N was specified, find that message's line
1207 ;; or set message-not-found.
1208 ;; If N wasn't specified or that message can't be found.
1209 ;; set N by default.
1213 (progn (message "No preceding message")
1215 (if (and (> n total
)
1217 (progn (message "No following message")
1218 (goto-char (point-max))
1219 (rmail-summary-goto-msg nil nowarn skip-rmail
)))
1220 (goto-char (point-min))
1221 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1222 (progn (or nowarn
(message "Message %d not found" n
))
1224 (setq message-not-found t
)
1226 (rmail-summary-mark-seen n
)
1227 (rmail-summary-update-highlight message-not-found
)
1230 (let ((selwin (selected-window)))
1232 (progn (rmail-pop-to-buffer buf
)
1233 (rmail-show-message n
))
1234 (select-window selwin
)
1235 ;; The actions above can alter the current buffer. Preserve it.
1236 (set-buffer obuf
))))
1237 (not message-not-found
)))
1239 ;; Update the highlighted line in an rmail summary buffer.
1240 ;; That should be current. We highlight the line point is on.
1241 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1242 (defun rmail-summary-update-highlight (not-found)
1243 ;; Make sure we have an overlay to use.
1244 (or rmail-summary-overlay
1246 (make-local-variable 'rmail-summary-overlay
)
1247 (setq rmail-summary-overlay
(make-overlay (point) (point)))
1248 (overlay-put rmail-summary-overlay
'rmail-summary t
)))
1249 ;; If this message is in the summary, use the overlay to highlight it.
1250 ;; Otherwise, don't highlight anything.
1252 (overlay-put rmail-summary-overlay
'face nil
)
1253 (move-overlay rmail-summary-overlay
1254 (save-excursion (beginning-of-line)
1255 (skip-chars-forward " ")
1257 (line-end-position))
1258 (overlay-put rmail-summary-overlay
'face
'highlight
)))
1260 (defun rmail-summary-scroll-msg-up (&optional dist
)
1261 "Scroll the Rmail window forward.
1262 If the Rmail window is displaying the end of a message,
1263 advance to the next message."
1266 (rmail-summary-scroll-msg-down nil
)
1267 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1268 (if rmail-buffer-window
1269 (if (let ((rmail-summary-window (selected-window)))
1270 (select-window rmail-buffer-window
)
1272 ;; Is EOB visible in the buffer?
1274 (let ((ht (window-height (selected-window))))
1275 (move-to-window-line (- ht
2))
1278 (select-window rmail-summary-window
)))
1279 (if (not rmail-summary-scroll-between-messages
)
1280 (error "End of buffer")
1281 (rmail-summary-next-msg (or dist
1)))
1282 (let ((other-window-scroll-buffer rmail-buffer
))
1283 (scroll-other-window dist
)))
1284 ;; If it isn't visible at all, show the beginning.
1285 (rmail-summary-beginning-of-message)))))
1287 (defun rmail-summary-scroll-msg-down (&optional dist
)
1288 "Scroll the Rmail window backward.
1289 If the Rmail window is now displaying the beginning of a message,
1290 move to the previous message."
1293 (rmail-summary-scroll-msg-up nil
)
1294 (let ((rmail-buffer-window (get-buffer-window rmail-buffer
)))
1295 (if rmail-buffer-window
1296 (if (let ((rmail-summary-window (selected-window)))
1297 (select-window rmail-buffer-window
)
1299 ;; Is BOB visible in the buffer?
1301 (move-to-window-line 0)
1304 (select-window rmail-summary-window
)))
1305 (if (not rmail-summary-scroll-between-messages
)
1306 (error "Beginning of buffer")
1307 (rmail-summary-previous-msg (or dist
1)))
1308 (let ((other-window-scroll-buffer rmail-buffer
))
1309 (scroll-other-window-down dist
)))
1310 ;; If it isn't visible at all, show the beginning.
1311 (rmail-summary-beginning-of-message)))))
1313 (defun rmail-summary-beginning-of-message ()
1314 "Show current message from the beginning."
1316 (rmail-summary-show-message 'BEG
))
1318 (defun rmail-summary-end-of-message ()
1319 "Show bottom of current message."
1321 (rmail-summary-show-message 'END
))
1323 (defun rmail-summary-show-message (where)
1324 "Show current mail message.
1325 Position it according to WHERE which can be BEG or END"
1326 (if (and (one-window-p) (not pop-up-frames
))
1327 ;; If there is just one window, put the summary on the top.
1328 (let ((buffer rmail-buffer
))
1329 (split-window (selected-window) rmail-summary-window-size
)
1330 (select-window (frame-first-window))
1331 (rmail-pop-to-buffer rmail-buffer
)
1332 ;; If pop-to-buffer did not use that window, delete that
1333 ;; window. (This can happen if it uses another frame.)
1334 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1335 (delete-other-windows)))
1336 (rmail-pop-to-buffer rmail-buffer
))
1339 (goto-char (point-min))
1340 (search-forward "\n\n"))
1342 (goto-char (point-max))
1343 (recenter (1- (window-height))))
1345 (rmail-pop-to-buffer rmail-summary-buffer
))
1347 (defun rmail-summary-bury ()
1348 "Bury the Rmail buffer and the Rmail summary buffer."
1350 (let ((buffer-to-bury (current-buffer)))
1352 (while (setq window
(get-buffer-window rmail-buffer
))
1353 (set-window-buffer window
(other-buffer rmail-buffer
)))
1354 (bury-buffer rmail-buffer
))
1355 (switch-to-buffer (other-buffer buffer-to-bury
))
1356 (bury-buffer buffer-to-bury
)))
1358 (defun rmail-summary-quit ()
1359 "Quit out of Rmail and Rmail summary."
1361 (rmail-summary-wipe)
1364 (defun rmail-summary-wipe ()
1365 "Kill and wipe away Rmail summary, remaining within Rmail."
1367 (with-current-buffer rmail-buffer
(setq rmail-summary-buffer nil
))
1368 (let ((local-rmail-buffer rmail-buffer
))
1369 (kill-buffer (current-buffer))
1370 ;; Delete window if not only one.
1371 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1373 ;; Switch windows to the rmail buffer, or switch to it in this window.
1374 (rmail-pop-to-buffer local-rmail-buffer
)))
1376 (defun rmail-summary-expunge ()
1377 "Actually erase all deleted messages and recompute summary headers."
1379 (with-current-buffer rmail-buffer
1380 (when (rmail-expunge-confirmed)
1381 (rmail-only-expunge)))
1382 (rmail-update-summary))
1384 (defun rmail-summary-expunge-and-save ()
1385 "Expunge and save RMAIL file."
1388 (rmail-expunge-and-save))
1389 (rmail-update-summary)
1390 (set-buffer-modified-p nil
))
1392 (defun rmail-summary-get-new-mail (&optional file-name
)
1393 "Get new mail and recompute summary headers.
1395 Optionally you can specify the file to get new mail from. In this case,
1396 the file of new mail is not changed or deleted. Noninteractively, you can
1397 pass the inbox file name as an argument. Interactively, a prefix
1398 argument says to read a file name and use that file as the inbox."
1400 (list (if current-prefix-arg
1401 (read-file-name "Get new mail from file: "))))
1403 (with-current-buffer rmail-buffer
1404 (rmail-get-new-mail file-name
)
1405 ;; Get the proper new message number.
1406 (setq msg rmail-current-message
))
1407 ;; Make sure that message is displayed.
1409 (rmail-summary-goto-msg msg
))))
1411 (defun rmail-summary-input (filename)
1412 "Run Rmail on file FILENAME."
1413 (interactive "FRun rmail on RMAIL file: ")
1414 ;; We switch windows here, then display the other Rmail file there.
1415 (rmail-pop-to-buffer rmail-buffer
)
1418 (defun rmail-summary-first-message ()
1419 "Show first message in Rmail file from summary buffer."
1422 (beginning-of-buffer)))
1424 (defun rmail-summary-last-message ()
1425 "Show last message in Rmail file from summary buffer."
1431 (declare-function rmail-abort-edit
"rmailedit" ())
1432 (declare-function rmail-cease-edit
"rmailedit"())
1433 (declare-function rmail-set-label
"rmailkwd" (l state
&optional n
))
1434 (declare-function rmail-output-read-file-name
"rmailout" ())
1435 (declare-function mail-send-and-exit
"sendmail" (&optional arg
))
1437 (defvar rmail-summary-edit-map nil
)
1438 (if rmail-summary-edit-map
1440 (setq rmail-summary-edit-map
1441 (nconc (make-sparse-keymap) text-mode-map
))
1442 (define-key rmail-summary-edit-map
"\C-c\C-c" 'rmail-cease-edit
)
1443 (define-key rmail-summary-edit-map
"\C-c\C-]" 'rmail-abort-edit
))
1445 (defun rmail-summary-edit-current-message ()
1446 "Edit the contents of this message."
1448 (rmail-pop-to-buffer rmail-buffer
)
1449 (rmail-edit-current-message)
1450 (use-local-map rmail-summary-edit-map
))
1452 (defun rmail-summary-cease-edit ()
1453 "Finish editing message, then go back to Rmail summary buffer."
1456 (rmail-pop-to-buffer rmail-summary-buffer
))
1458 (defun rmail-summary-abort-edit ()
1459 "Abort edit of current message; restore original contents.
1460 Go back to summary buffer."
1463 (rmail-pop-to-buffer rmail-summary-buffer
))
1465 (defun rmail-summary-search-backward (regexp &optional n
)
1466 "Show message containing next match for REGEXP.
1467 Prefix argument gives repeat count; negative argument means search
1468 backwards (through earlier messages).
1469 Interactively, empty argument means use same regexp used last time."
1471 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1473 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1477 (if rmail-search-last-regexp
1478 (concat ", default "
1479 rmail-search-last-regexp
"): ")
1481 (setq regexp
(read-string prompt
))
1482 (cond ((not (equal regexp
""))
1483 (setq rmail-search-last-regexp regexp
))
1484 ((not rmail-search-last-regexp
)
1485 (error "No previous Rmail search string")))
1486 (list rmail-search-last-regexp
1487 (prefix-numeric-value current-prefix-arg
))))
1488 ;; Don't use save-excursion because that prevents point from moving
1489 ;; properly in the summary buffer.
1490 (with-current-buffer rmail-buffer
1491 (rmail-search regexp
(- n
))))
1493 (defun rmail-summary-search (regexp &optional n
)
1494 "Show message containing next match for REGEXP.
1495 Prefix argument gives repeat count; negative argument means search
1496 backwards (through earlier messages).
1497 Interactively, empty argument means use same regexp used last time."
1499 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1501 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
1505 (if rmail-search-last-regexp
1506 (concat ", default "
1507 rmail-search-last-regexp
"): ")
1509 (setq regexp
(read-string prompt
))
1510 (cond ((not (equal regexp
""))
1511 (setq rmail-search-last-regexp regexp
))
1512 ((not rmail-search-last-regexp
)
1513 (error "No previous Rmail search string")))
1514 (list rmail-search-last-regexp
1515 (prefix-numeric-value current-prefix-arg
))))
1516 ;; Don't use save-excursion because that prevents point from moving
1517 ;; properly in the summary buffer.
1518 (let ((buffer (current-buffer))
1519 (selwin (selected-window)))
1522 (rmail-pop-to-buffer rmail-buffer
)
1523 (rmail-search regexp n
))
1524 (select-window selwin
)
1525 (set-buffer buffer
))))
1527 (defun rmail-summary-toggle-header ()
1528 "Show original message header if pruned header currently shown, or vice versa."
1530 (save-window-excursion
1531 (set-buffer rmail-buffer
)
1532 (rmail-toggle-header))
1533 ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost.
1534 ;; Set point to point-min in the RMAIL buffer, if it is visible.
1535 (let ((window (get-buffer-window rmail-buffer
)))
1537 ;; Using save-window-excursion would lose the new value of point.
1538 (let ((owin (selected-window)))
1541 (select-window window
)
1542 (goto-char (point-min)))
1543 (select-window owin
))))))
1546 (defun rmail-summary-add-label (label)
1547 "Add LABEL to labels associated with current Rmail message.
1548 Completion is performed over known labels when reading."
1549 (interactive (list (with-current-buffer rmail-buffer
1550 (rmail-read-label "Add label"))))
1551 (with-current-buffer rmail-buffer
1552 (rmail-add-label label
)))
1554 (defun rmail-summary-kill-label (label)
1555 "Remove LABEL from labels associated with current Rmail message.
1556 Completion is performed over known labels when reading."
1557 (interactive (list (with-current-buffer rmail-buffer
1558 (rmail-read-label "Kill label"))))
1559 (with-current-buffer rmail-buffer
1560 (rmail-set-label label nil
)))
1562 ;;;; *** Rmail Summary Mailing Commands ***
1564 (defun rmail-summary-override-mail-send-and-exit ()
1565 "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'."
1566 (use-local-map (copy-keymap (current-local-map)))
1567 (dolist (key (where-is-internal 'mail-send-and-exit
))
1568 (define-key (current-local-map) key
'rmail-summary-send-and-exit
)))
1570 (defun rmail-summary-mail ()
1571 "Send mail in another window.
1572 While composing the message, use \\[mail-yank-original] to yank the
1573 original message into it."
1575 (let ((window (get-buffer-window rmail-buffer
)))
1577 (select-window window
)
1578 (set-buffer rmail-buffer
)))
1579 (rmail-start-mail nil nil nil nil nil
(current-buffer))
1580 (rmail-summary-override-mail-send-and-exit))
1582 (defun rmail-summary-continue ()
1583 "Continue composing outgoing message previously being composed."
1585 (let ((window (get-buffer-window rmail-buffer
)))
1587 (select-window window
)
1588 (set-buffer rmail-buffer
)))
1589 (rmail-start-mail t
))
1591 (defun rmail-summary-reply (just-sender)
1592 "Reply to the current message.
1593 Normally include CC: to all other recipients of original message;
1594 prefix argument means ignore them. While composing the reply,
1595 use \\[mail-yank-original] to yank the original message into it."
1597 (let ((window (get-buffer-window rmail-buffer
)))
1599 (select-window window
)
1600 (set-buffer rmail-buffer
)))
1601 (rmail-reply just-sender
)
1602 (rmail-summary-override-mail-send-and-exit))
1604 (defun rmail-summary-retry-failure ()
1605 "Edit a mail message which is based on the contents of the current message.
1606 For a message rejected by the mail system, extract the interesting headers and
1607 the body of the original message; otherwise copy the current message."
1609 (let ((window (get-buffer-window rmail-buffer
)))
1611 (select-window window
)
1612 (set-buffer rmail-buffer
)))
1613 (rmail-retry-failure)
1614 (rmail-summary-override-mail-send-and-exit))
1616 (defun rmail-summary-send-and-exit ()
1617 "Send mail reply and return to summary buffer."
1619 (mail-send-and-exit t
))
1621 (defun rmail-summary-forward (resend)
1622 "Forward the current message to another user.
1623 With prefix argument, \"resend\" the message instead of forwarding it;
1624 see the documentation of `rmail-resend'."
1627 (let ((window (get-buffer-window rmail-buffer
)))
1629 (select-window window
)
1630 (set-buffer rmail-buffer
)))
1631 (rmail-forward resend
)
1632 (rmail-summary-override-mail-send-and-exit)))
1634 (defun rmail-summary-resend ()
1635 "Resend current message using `rmail-resend'."
1638 (let ((window (get-buffer-window rmail-buffer
)))
1640 (select-window window
)
1641 (set-buffer rmail-buffer
)))
1642 (call-interactively 'rmail-resend
)))
1644 ;; Summary output commands.
1646 (defun rmail-summary-output (&optional file-name n
)
1647 "Append this message to mail file FILE-NAME.
1648 This works with both mbox format and Babyl format files,
1649 outputting in the appropriate format for each.
1650 The default file name comes from `rmail-default-file',
1651 which is updated to the name you use in this command.
1653 A prefix argument N says to output that many consecutive messages
1654 from those in the summary, starting with the current one.
1655 Deleted messages are skipped and don't count.
1656 When called from Lisp code, N may be omitted and defaults to 1.
1658 This command always outputs the complete message header,
1659 even the header display is currently pruned."
1661 (progn (require 'rmailout
)
1662 (list (rmail-output-read-file-name)
1663 (prefix-numeric-value current-prefix-arg
))))
1664 (let ((i 0) prev-msg
)
1667 (progn (rmail-summary-goto-msg)
1670 (with-current-buffer rmail-buffer
1671 rmail-current-message
))))))
1673 (with-current-buffer rmail-buffer
1674 (let ((rmail-delete-after-output nil
))
1675 (rmail-output file-name
1)))
1676 (if rmail-delete-after-output
1677 (rmail-summary-delete-forward nil
)
1679 (rmail-summary-next-msg 1))))))
1681 (defalias 'rmail-summary-output-to-rmail-file
'rmail-summary-output
)
1683 (declare-function rmail-output-as-seen
"rmailout"
1684 (file-name &optional count noattribute from-gnus
))
1686 (defun rmail-summary-output-as-seen (&optional file-name n
)
1687 "Append this message to mbox file named FILE-NAME.
1688 A prefix argument N says to output that many consecutive messages,
1689 from the summary, starting with the current one.
1690 Deleted messages are skipped and don't count.
1691 When called from Lisp code, N may be omitted and defaults to 1.
1693 This outputs the message header as you see it (or would see it)
1696 The default file name comes from `rmail-default-file',
1697 which is updated to the name you use in this command."
1699 (progn (require 'rmailout
)
1700 (list (rmail-output-read-file-name)
1701 (prefix-numeric-value current-prefix-arg
))))
1702 (require 'rmailout
) ; for rmail-output-as-seen in non-interactive case
1703 (let ((i 0) prev-msg
)
1706 (progn (rmail-summary-goto-msg)
1709 (with-current-buffer rmail-buffer
1710 rmail-current-message
))))))
1712 (with-current-buffer rmail-buffer
1713 (let ((rmail-delete-after-output nil
))
1714 (rmail-output-as-seen file-name
1)))
1715 (if rmail-delete-after-output
1716 (rmail-summary-delete-forward nil
)
1718 (rmail-summary-next-msg 1))))))
1720 (defun rmail-summary-output-menu ()
1721 "Output current message to another Rmail file, chosen with a menu.
1722 Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
1723 The variables `rmail-secondary-file-directory' and
1724 `rmail-secondary-file-regexp' control which files are offered in the menu."
1726 (with-current-buffer rmail-buffer
1727 (let ((rmail-delete-after-output nil
))
1728 (call-interactively 'rmail-output-menu
)))
1729 (if rmail-delete-after-output
1730 (rmail-summary-delete-forward nil
)))
1732 (defun rmail-summary-construct-io-menu ()
1733 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1736 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1737 (cons "Input Rmail File"
1738 (rmail-list-to-menu "Input Rmail File"
1740 'rmail-summary-input
)))
1741 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1742 (cons "Output Rmail File"
1743 (rmail-list-to-menu "Output Rmail File"
1745 'rmail-summary-output
))))
1746 (define-key rmail-summary-mode-map
[menu-bar classify input-menu
]
1747 '("Input Rmail File" . rmail-disable-menu
))
1748 (define-key rmail-summary-mode-map
[menu-bar classify output-menu
]
1749 '("Output Rmail File" . rmail-disable-menu
)))))
1751 (defun rmail-summary-output-body (&optional file-name
)
1752 "Write this message body to the file FILE-NAME.
1753 FILE-NAME defaults, interactively, from the Subject field of the message."
1755 (with-current-buffer rmail-buffer
1756 (let ((rmail-delete-after-output nil
))
1758 (rmail-output-body-to-file file-name
)
1759 (call-interactively 'rmail-output-body-to-file
))))
1760 (if rmail-delete-after-output
1761 (rmail-summary-delete-forward nil
)))
1763 ;; Sorting messages in Rmail Summary buffer.
1765 (defun rmail-summary-sort-by-date (reverse)
1766 "Sort messages of current Rmail summary by \"Date\" header.
1767 If prefix argument REVERSE is non-nil, sorts in reverse order."
1769 (rmail-sort-from-summary (function rmail-sort-by-date
) reverse
))
1771 (defun rmail-summary-sort-by-subject (reverse)
1772 "Sort messages of current Rmail summary by \"Subject\" header.
1773 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
1774 non-nil, sorts in reverse order."
1776 (rmail-sort-from-summary (function rmail-sort-by-subject
) reverse
))
1778 (defun rmail-summary-sort-by-author (reverse)
1779 "Sort messages of current Rmail summary by author.
1780 This uses either the \"From\" or \"Sender\" header, downcased.
1781 If prefix argument REVERSE is non-nil, sorts in reverse order."
1783 (rmail-sort-from-summary (function rmail-sort-by-author
) reverse
))
1785 (defun rmail-summary-sort-by-recipient (reverse)
1786 "Sort messages of current Rmail summary by recipient.
1787 This uses either the \"To\" or \"Apparently-To\" header, downcased.
1788 If prefix argument REVERSE is non-nil, sorts in reverse order."
1790 (rmail-sort-from-summary (function rmail-sort-by-recipient
) reverse
))
1792 (defun rmail-summary-sort-by-correspondent (reverse)
1793 "Sort messages of current Rmail summary by other correspondent.
1794 This uses either the \"From\", \"Sender\", \"To\", or
1795 \"Apparently-To\" header, downcased. Uses the first header not
1796 excluded by `mail-dont-reply-to-names'. If prefix argument
1797 REVERSE is non-nil, sorts in reverse order."
1799 (rmail-sort-from-summary (function rmail-sort-by-correspondent
) reverse
))
1801 (defun rmail-summary-sort-by-lines (reverse)
1802 "Sort messages of current Rmail summary by the number of lines.
1803 If prefix argument REVERSE is non-nil, sorts in reverse order."
1805 (rmail-sort-from-summary (function rmail-sort-by-lines
) reverse
))
1807 (defun rmail-summary-sort-by-labels (reverse labels
)
1808 "Sort messages of current Rmail summary by labels.
1809 LABELS is a comma-separated list of labels.
1810 If prefix argument REVERSE is non-nil, sorts in reverse order."
1811 (interactive "P\nsSort by labels: ")
1812 (rmail-sort-from-summary
1813 (lambda (reverse) (rmail-sort-by-labels reverse labels
))
1816 (defun rmail-sort-from-summary (sortfun reverse
)
1817 "Sort the Rmail buffer using sorting function SORTFUN.
1818 Passes REVERSE to SORTFUN as its sole argument. Then regenerates
1819 the summary. Note that the whole Rmail buffer is sorted, even if
1820 the summary is only showing a subset of messages."
1821 (require 'rmailsort
)
1822 (let ((selwin (selected-window)))
1824 (progn (rmail-pop-to-buffer rmail-buffer
)
1825 (funcall sortfun reverse
))
1826 (select-window selwin
))))
1831 ;; generated-autoload-file: "rmail.el"
1834 ;;; rmailsum.el ends here