Commit | Line | Data |
---|---|---|
537ab246 BG |
1 | ;;; rmailsum.el --- make summary buffers for the mail reader |
2 | ||
ba318903 | 3 | ;; Copyright (C) 1985, 1993-1996, 2000-2014 Free Software Foundation, |
ab422c4d | 4 | ;; Inc. |
537ab246 | 5 | |
34dc21db | 6 | ;; Maintainer: emacs-devel@gnu.org |
537ab246 | 7 | ;; Keywords: mail |
bd78fa1d | 8 | ;; Package: rmail |
537ab246 BG |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
12 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
13 | ;; it under the terms of the GNU General Public License as published by | |
14 | ;; the Free Software Foundation, either version 3 of the License, or | |
15 | ;; (at your option) any later version. | |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
24 | ||
25 | ;;; Commentary: | |
26 | ||
27 | ;; Extended by Bob Weiner of Motorola | |
28 | ;; Provided all commands from rmail-mode in rmail-summary-mode and made key | |
29 | ;; bindings in both modes wholly compatible. | |
30 | ||
31 | ;;; Code: | |
32 | ||
97e92ffb | 33 | ;; For rmail-select-summary. |
537ab246 | 34 | (require 'rmail) |
d1be4ec2 | 35 | (require 'rfc2047) |
537ab246 | 36 | |
537ab246 | 37 | (defcustom rmail-summary-scroll-between-messages t |
4b12219b GM |
38 | "Non-nil means Rmail summary scroll commands move between messages. |
39 | That is, after `rmail-summary-scroll-msg-up' reaches the end of a | |
40 | message, it moves to the next message; and similarly for | |
41 | `rmail-summary-scroll-msg-down'." | |
537ab246 BG |
42 | :type 'boolean |
43 | :group 'rmail-summary) | |
44 | ||
4b12219b GM |
45 | ;; FIXME could do with a :set function that regenerates the summary |
46 | ;; and updates rmail-summary-vector. | |
537ab246 | 47 | (defcustom rmail-summary-line-count-flag t |
4b12219b GM |
48 | "Non-nil means Rmail summary should show the number of lines in each message. |
49 | Setting this option to nil might speed up the generation of summaries." | |
537ab246 BG |
50 | :type 'boolean |
51 | :group 'rmail-summary) | |
52 | ||
53 | (defvar rmail-summary-font-lock-keywords | |
54 | '(("^.....D.*" . font-lock-string-face) ; Deleted. | |
55 | ("^.....-.*" . font-lock-type-face) ; Unread. | |
56 | ;; Neither of the below will be highlighted if either of the above are: | |
57 | ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date. | |
58 | ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face)) ; Labels. | |
59 | "Additional expressions to highlight in Rmail Summary mode.") | |
60 | ||
97e92ffb | 61 | (defvar rmail-summary-redo nil |
537ab246 BG |
62 | "(FUNCTION . ARGS) to regenerate this Rmail summary buffer.") |
63 | ||
97e92ffb GM |
64 | (defvar rmail-summary-overlay nil |
65 | "Overlay used to highlight the current message in the Rmail summary.") | |
537ab246 BG |
66 | (put 'rmail-summary-overlay 'permanent-local t) |
67 | ||
b016851c SM |
68 | (defvar rmail-summary-mode-map |
69 | (let ((map (make-keymap))) | |
70 | (suppress-keymap map) | |
71 | (define-key map [mouse-2] 'rmail-summary-mouse-goto-message) | |
72 | (define-key map "a" 'rmail-summary-add-label) | |
73 | (define-key map "b" 'rmail-summary-bury) | |
74 | (define-key map "c" 'rmail-summary-continue) | |
75 | (define-key map "d" 'rmail-summary-delete-forward) | |
76 | (define-key map "\C-d" 'rmail-summary-delete-backward) | |
77 | (define-key map "e" 'rmail-summary-edit-current-message) | |
78 | (define-key map "f" 'rmail-summary-forward) | |
79 | (define-key map "g" 'rmail-summary-get-new-mail) | |
80 | (define-key map "h" 'rmail-summary) | |
81 | (define-key map "i" 'rmail-summary-input) | |
82 | (define-key map "j" 'rmail-summary-goto-msg) | |
83 | (define-key map "\C-m" 'rmail-summary-goto-msg) | |
84 | (define-key map "k" 'rmail-summary-kill-label) | |
85 | (define-key map "l" 'rmail-summary-by-labels) | |
86 | (define-key map "\e\C-h" 'rmail-summary) | |
87 | (define-key map "\e\C-l" 'rmail-summary-by-labels) | |
88 | (define-key map "\e\C-r" 'rmail-summary-by-recipients) | |
89 | (define-key map "\e\C-s" 'rmail-summary-by-regexp) | |
90 | ;; `f' for "from". | |
91 | (define-key map "\e\C-f" 'rmail-summary-by-senders) | |
92 | (define-key map "\e\C-t" 'rmail-summary-by-topic) | |
93 | (define-key map "m" 'rmail-summary-mail) | |
94 | (define-key map "\M-m" 'rmail-summary-retry-failure) | |
95 | (define-key map "n" 'rmail-summary-next-msg) | |
96 | (define-key map "\en" 'rmail-summary-next-all) | |
97 | (define-key map "\e\C-n" 'rmail-summary-next-labeled-message) | |
98 | (define-key map "o" 'rmail-summary-output) | |
99 | (define-key map "\C-o" 'rmail-summary-output-as-seen) | |
100 | (define-key map "p" 'rmail-summary-previous-msg) | |
101 | (define-key map "\ep" 'rmail-summary-previous-all) | |
102 | (define-key map "\e\C-p" 'rmail-summary-previous-labeled-message) | |
103 | (define-key map "q" 'rmail-summary-quit) | |
104 | (define-key map "Q" 'rmail-summary-wipe) | |
105 | (define-key map "r" 'rmail-summary-reply) | |
106 | (define-key map "s" 'rmail-summary-expunge-and-save) | |
107 | ;; See rms's comment in rmail.el | |
108 | ;; (define-key map "\er" 'rmail-summary-search-backward) | |
109 | (define-key map "\es" 'rmail-summary-search) | |
110 | (define-key map "t" 'rmail-summary-toggle-header) | |
111 | (define-key map "u" 'rmail-summary-undelete) | |
112 | (define-key map "\M-u" 'rmail-summary-undelete-many) | |
113 | (define-key map "x" 'rmail-summary-expunge) | |
114 | (define-key map "w" 'rmail-summary-output-body) | |
115 | (define-key map "v" 'rmail-mime) | |
116 | (define-key map "." 'rmail-summary-beginning-of-message) | |
117 | (define-key map "/" 'rmail-summary-end-of-message) | |
118 | (define-key map "<" 'rmail-summary-first-message) | |
119 | (define-key map ">" 'rmail-summary-last-message) | |
120 | (define-key map " " 'rmail-summary-scroll-msg-up) | |
958614cf | 121 | (define-key map [?\S-\ ] 'rmail-summary-scroll-msg-down) |
b016851c SM |
122 | (define-key map "\177" 'rmail-summary-scroll-msg-down) |
123 | (define-key map "?" 'describe-mode) | |
124 | (define-key map "\C-c\C-n" 'rmail-summary-next-same-subject) | |
125 | (define-key map "\C-c\C-p" 'rmail-summary-previous-same-subject) | |
126 | (define-key map "\C-c\C-s\C-d" 'rmail-summary-sort-by-date) | |
127 | (define-key map "\C-c\C-s\C-s" 'rmail-summary-sort-by-subject) | |
128 | (define-key map "\C-c\C-s\C-a" 'rmail-summary-sort-by-author) | |
129 | (define-key map "\C-c\C-s\C-r" 'rmail-summary-sort-by-recipient) | |
130 | (define-key map "\C-c\C-s\C-c" 'rmail-summary-sort-by-correspondent) | |
131 | (define-key map "\C-c\C-s\C-l" 'rmail-summary-sort-by-lines) | |
132 | (define-key map "\C-c\C-s\C-k" 'rmail-summary-sort-by-labels) | |
133 | (define-key map "\C-x\C-s" 'rmail-summary-save-buffer) | |
134 | ||
135 | ;; Menu bar bindings. | |
136 | ||
137 | (define-key map [menu-bar] (make-sparse-keymap)) | |
138 | ||
139 | (define-key map [menu-bar classify] | |
140 | (cons "Classify" (make-sparse-keymap "Classify"))) | |
141 | ||
142 | (define-key map [menu-bar classify output-menu] | |
143 | '("Output (Rmail Menu)..." . rmail-summary-output-menu)) | |
144 | ||
145 | (define-key map [menu-bar classify input-menu] | |
146 | '("Input Rmail File (menu)..." . rmail-input-menu)) | |
147 | ||
148 | (define-key map [menu-bar classify input-menu] | |
149 | '(nil)) | |
150 | ||
151 | (define-key map [menu-bar classify output-menu] | |
152 | '(nil)) | |
153 | ||
154 | (define-key map [menu-bar classify output-body] | |
155 | '("Output body..." . rmail-summary-output-body)) | |
156 | ||
157 | (define-key map [menu-bar classify output-inbox] | |
158 | '("Output..." . rmail-summary-output)) | |
159 | ||
160 | (define-key map [menu-bar classify output] | |
161 | '("Output as seen..." . rmail-summary-output-as-seen)) | |
162 | ||
163 | (define-key map [menu-bar classify kill-label] | |
164 | '("Kill Label..." . rmail-summary-kill-label)) | |
165 | ||
166 | (define-key map [menu-bar classify add-label] | |
167 | '("Add Label..." . rmail-summary-add-label)) | |
168 | ||
169 | (define-key map [menu-bar summary] | |
170 | (cons "Summary" (make-sparse-keymap "Summary"))) | |
171 | ||
172 | (define-key map [menu-bar summary senders] | |
173 | '("By Senders..." . rmail-summary-by-senders)) | |
174 | ||
175 | (define-key map [menu-bar summary labels] | |
176 | '("By Labels..." . rmail-summary-by-labels)) | |
177 | ||
178 | (define-key map [menu-bar summary recipients] | |
179 | '("By Recipients..." . rmail-summary-by-recipients)) | |
180 | ||
181 | (define-key map [menu-bar summary topic] | |
182 | '("By Topic..." . rmail-summary-by-topic)) | |
183 | ||
184 | (define-key map [menu-bar summary regexp] | |
185 | '("By Regexp..." . rmail-summary-by-regexp)) | |
186 | ||
187 | (define-key map [menu-bar summary all] | |
188 | '("All" . rmail-summary)) | |
189 | ||
190 | (define-key map [menu-bar mail] | |
191 | (cons "Mail" (make-sparse-keymap "Mail"))) | |
192 | ||
193 | (define-key map [menu-bar mail rmail-summary-get-new-mail] | |
194 | '("Get New Mail" . rmail-summary-get-new-mail)) | |
195 | ||
196 | (define-key map [menu-bar mail lambda] | |
197 | '("----")) | |
198 | ||
199 | (define-key map [menu-bar mail continue] | |
200 | '("Continue" . rmail-summary-continue)) | |
201 | ||
202 | (define-key map [menu-bar mail resend] | |
203 | '("Re-send..." . rmail-summary-resend)) | |
204 | ||
205 | (define-key map [menu-bar mail forward] | |
206 | '("Forward" . rmail-summary-forward)) | |
207 | ||
208 | (define-key map [menu-bar mail retry] | |
209 | '("Retry" . rmail-summary-retry-failure)) | |
210 | ||
211 | (define-key map [menu-bar mail reply] | |
212 | '("Reply" . rmail-summary-reply)) | |
213 | ||
214 | (define-key map [menu-bar mail mail] | |
215 | '("Mail" . rmail-summary-mail)) | |
216 | ||
217 | (define-key map [menu-bar delete] | |
218 | (cons "Delete" (make-sparse-keymap "Delete"))) | |
219 | ||
220 | (define-key map [menu-bar delete expunge/save] | |
221 | '("Expunge/Save" . rmail-summary-expunge-and-save)) | |
222 | ||
223 | (define-key map [menu-bar delete expunge] | |
224 | '("Expunge" . rmail-summary-expunge)) | |
225 | ||
226 | (define-key map [menu-bar delete undelete] | |
227 | '("Undelete" . rmail-summary-undelete)) | |
228 | ||
229 | (define-key map [menu-bar delete delete] | |
230 | '("Delete" . rmail-summary-delete-forward)) | |
231 | ||
232 | (define-key map [menu-bar move] | |
233 | (cons "Move" (make-sparse-keymap "Move"))) | |
234 | ||
235 | (define-key map [menu-bar move search-back] | |
236 | '("Search Back..." . rmail-summary-search-backward)) | |
237 | ||
238 | (define-key map [menu-bar move search] | |
239 | '("Search..." . rmail-summary-search)) | |
240 | ||
241 | (define-key map [menu-bar move previous] | |
242 | '("Previous Nondeleted" . rmail-summary-previous-msg)) | |
243 | ||
244 | (define-key map [menu-bar move next] | |
245 | '("Next Nondeleted" . rmail-summary-next-msg)) | |
246 | ||
247 | (define-key map [menu-bar move last] | |
248 | '("Last" . rmail-summary-last-message)) | |
249 | ||
250 | (define-key map [menu-bar move first] | |
251 | '("First" . rmail-summary-first-message)) | |
252 | ||
253 | (define-key map [menu-bar move previous] | |
254 | '("Previous" . rmail-summary-previous-all)) | |
255 | ||
256 | (define-key map [menu-bar move next] | |
257 | '("Next" . rmail-summary-next-all)) | |
258 | map) | |
97e92ffb | 259 | "Keymap used in Rmail summary mode.") |
537ab246 BG |
260 | |
261 | ;; Entry points for making a summary buffer. | |
262 | ||
263 | ;; Regenerate the contents of the summary | |
264 | ;; using the same selection criterion as last time. | |
265 | ;; M-x revert-buffer in a summary buffer calls this function. | |
266 | (defun rmail-update-summary (&rest ignore) | |
267 | (apply (car rmail-summary-redo) (cdr rmail-summary-redo))) | |
268 | ||
269 | ;;;###autoload | |
270 | (defun rmail-summary () | |
271 | "Display a summary of all messages, one line per message." | |
272 | (interactive) | |
40500957 | 273 | (rmail-new-summary "All" '(rmail-summary) nil)) |
537ab246 BG |
274 | |
275 | ;;;###autoload | |
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 | |
bfc03247 CY |
287 | (concat " \\(" |
288 | (mail-comma-list-regexp labels) | |
289 | "\\)\\(,\\|\\'\\)"))) | |
537ab246 | 290 | |
4b12219b GM |
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. | |
537ab246 BG |
295 | ;;;###autoload |
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") | |
303 | (rmail-new-summary | |
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)) | |
308 | ||
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)) | |
312 | ||
313 | (defun rmail-message-recipients-p-1 (recipients &optional primary-only) | |
3ea5d765 GM |
314 | ;; mail-fetch-field does not care where it starts from. |
315 | (narrow-to-region (point) (progn (search-forward "\n\n") (point))) | |
537ab246 BG |
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") ""))))) | |
320 | ||
4b12219b GM |
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. | |
537ab246 BG |
324 | ;;;###autoload |
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), | |
4b12219b | 329 | Emacs will list the message in the summary." |
537ab246 BG |
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 | |
338 | regexp)) | |
339 | ||
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)) | |
343 | ||
344 | (defun rmail-message-regexp-p-1 (msg regexp) | |
3ea5d765 | 345 | ;; Search functions can expect to start from the beginning. |
3fbc055f | 346 | (narrow-to-region (point) (save-excursion (search-forward "\n\n") (point))) |
7fb18e9e GM |
347 | (if (and rmail-enable-mime |
348 | rmail-search-mime-header-function) | |
349 | (funcall rmail-search-mime-header-function msg regexp (point)) | |
537ab246 BG |
350 | (re-search-forward regexp nil t))) |
351 | ||
352 | ;;;###autoload | |
353 | (defun rmail-summary-by-topic (subject &optional whole-message) | |
354 | "Display a summary of all messages with the given SUBJECT. | |
70369cd3 GM |
355 | Normally checks just the Subject field of headers; but with prefix |
356 | argument WHOLE-MESSAGE is non-nil, looks in the whole message. | |
537ab246 BG |
357 | SUBJECT is a string of regexps separated by commas." |
358 | (interactive | |
70369cd3 GM |
359 | ;; We quote the default subject, because if it contains regexp |
360 | ;; special characters (eg "?"), it can fail to match itself. (Bug#2333) | |
361 | (let* ((subject (regexp-quote (rmail-simplified-subject))) | |
537ab246 BG |
362 | (prompt (concat "Topics to summarize by (regexp" |
363 | (if subject ", default current subject" "") | |
364 | "): "))) | |
365 | (list (read-string prompt nil nil subject) current-prefix-arg))) | |
366 | (rmail-new-summary | |
367 | (concat "about " subject) | |
368 | (list 'rmail-summary-by-topic subject whole-message) | |
369 | 'rmail-message-subject-p | |
370 | (mail-comma-list-regexp subject) whole-message)) | |
371 | ||
372 | (defun rmail-message-subject-p (msg subject &optional whole-message) | |
373 | (if whole-message | |
374 | (rmail-apply-in-message msg 're-search-forward subject nil t) | |
375 | (string-match subject (rmail-simplified-subject msg)))) | |
376 | ||
377 | ;;;###autoload | |
378 | (defun rmail-summary-by-senders (senders) | |
ac203e01 GM |
379 | "Display a summary of all messages whose \"From\" field matches SENDERS. |
380 | SENDERS is a string of regexps separated by commas." | |
537ab246 BG |
381 | (interactive "sSenders to summarize by: ") |
382 | (rmail-new-summary | |
383 | (concat "senders " senders) | |
384 | (list 'rmail-summary-by-senders senders) | |
385 | 'rmail-message-senders-p | |
386 | (mail-comma-list-regexp senders))) | |
387 | ||
388 | (defun rmail-message-senders-p (msg senders) | |
389 | (string-match senders (or (rmail-get-header "From" msg) ""))) | |
390 | \f | |
391 | ;; General making of a summary buffer. | |
392 | ||
393 | (defvar rmail-summary-symbol-number 0) | |
394 | ||
395 | (defvar rmail-new-summary-line-count) | |
396 | ||
df8f35df | 397 | (defun rmail-new-summary (desc redo function &rest args) |
537ab246 | 398 | "Create a summary of selected messages. |
df8f35df RS |
399 | DESC makes part of the mode line of the summary buffer. |
400 | REDO is what to put in `rmail-summary-redo'; usually | |
401 | its car is the function that called `rmail-new-summary' | |
402 | and its cdr is the arguments passed to that function. | |
403 | ||
404 | For each message, applies FUNCTION to the message number and ARGS..., | |
405 | and if the result is non-nil, it includes that message in the summary. | |
406 | If FUNCTION is nil, includes all messages." | |
537ab246 BG |
407 | (message "Computing summary lines...") |
408 | (unless rmail-buffer | |
409 | (error "No RMAIL buffer found")) | |
71e027ac | 410 | (let (mesg was-in-summary sumbuf) |
1b3b87df | 411 | (if (derived-mode-p 'rmail-summary-mode) |
537ab246 BG |
412 | (setq was-in-summary t)) |
413 | (with-current-buffer rmail-buffer | |
df8f35df | 414 | (setq rmail-summary-buffer (rmail-new-summary-1 desc redo function args) |
71e027ac | 415 | ;; r-s-b is buffer-local. |
071c2340 GM |
416 | sumbuf rmail-summary-buffer |
417 | mesg rmail-current-message)) | |
537ab246 BG |
418 | ;; Now display the summary buffer and go to the right place in it. |
419 | (unless was-in-summary | |
420 | (if (and (one-window-p) | |
421 | pop-up-windows | |
422 | (not pop-up-frames)) | |
423 | ;; If there is just one window, put the summary on the top. | |
424 | (progn | |
425 | (split-window (selected-window) rmail-summary-window-size) | |
426 | (select-window (next-window (frame-first-window))) | |
71e027ac | 427 | (rmail-pop-to-buffer sumbuf) |
537ab246 BG |
428 | ;; If pop-to-buffer did not use that window, delete that |
429 | ;; window. (This can happen if it uses another frame.) | |
71e027ac | 430 | (if (not (eq sumbuf (window-buffer (frame-first-window)))) |
537ab246 | 431 | (delete-other-windows))) |
71e027ac | 432 | (rmail-pop-to-buffer sumbuf)) |
537ab246 BG |
433 | (set-buffer rmail-buffer) |
434 | ;; This is how rmail makes the summary buffer reappear. | |
435 | ;; We do this here to make the window the proper size. | |
436 | (rmail-select-summary nil) | |
52d129cd | 437 | (set-buffer sumbuf)) |
537ab246 BG |
438 | (rmail-summary-goto-msg mesg t t) |
439 | (rmail-summary-construct-io-menu) | |
440 | (message "Computing summary lines...done"))) | |
441 | ||
df8f35df | 442 | (defun rmail-new-summary-1 (description redo function args) |
537ab246 BG |
443 | "Filter messages to obtain summary lines. |
444 | DESCRIPTION is added to the mode line. | |
445 | ||
446 | Return the summary buffer by invoking FUNCTION on each message | |
df8f35df | 447 | passing the message number and ARGS. |
537ab246 | 448 | |
df8f35df | 449 | REDO is what to put in `rmail-summary-redo'. |
537ab246 BG |
450 | |
451 | The current buffer must be a Rmail buffer either containing a | |
452 | collection of mbox formatted messages or displaying a single | |
453 | message." | |
454 | (let ((summary-msgs ()) | |
455 | (rmail-new-summary-line-count 0) | |
456 | (sumbuf (rmail-get-create-summary-buffer))) | |
457 | ;; Scan the messages, getting their summary strings | |
458 | ;; and putting the list of them in SUMMARY-MSGS. | |
459 | (let ((msgnum 1) | |
460 | (main-buffer (current-buffer)) | |
461 | (total rmail-total-messages) | |
462 | (inhibit-read-only t)) | |
463 | (save-excursion | |
464 | ;; Go where the mbox text is. | |
465 | (if (rmail-buffers-swapped-p) | |
466 | (set-buffer rmail-view-buffer)) | |
467 | (let ((old-min (point-min-marker)) | |
468 | (old-max (point-max-marker))) | |
469 | (unwind-protect | |
470 | ;; Can't use save-restriction here; that doesn't work if we | |
471 | ;; plan to modify text outside the original restriction. | |
472 | (save-excursion | |
473 | (widen) | |
474 | (goto-char (point-min)) | |
475 | (while (>= total msgnum) | |
74a9022a EZ |
476 | ;; Go back to the Rmail buffer so FUNCTION and |
477 | ;; rmail-get-summary can see its local vars. | |
537ab246 BG |
478 | (with-current-buffer main-buffer |
479 | ;; First test whether to include this message. | |
480 | (if (or (null function) | |
481 | (apply function msgnum args)) | |
482 | (setq summary-msgs | |
483 | (cons (cons msgnum (rmail-get-summary msgnum)) | |
484 | summary-msgs)))) | |
485 | (setq msgnum (1+ msgnum)) | |
486 | ;; Provide a periodic User progress message. | |
435f0dd2 EZ |
487 | (if (and (not (zerop rmail-new-summary-line-count)) |
488 | (zerop (% rmail-new-summary-line-count 10))) | |
537ab246 BG |
489 | (message "Computing summary lines...%d" |
490 | rmail-new-summary-line-count))) | |
491 | (setq summary-msgs (nreverse summary-msgs))) | |
492 | (narrow-to-region old-min old-max))))) | |
537ab246 BG |
493 | ;; Temporarily, while summary buffer is unfinished, |
494 | ;; we "don't have" a summary. | |
70369cd3 | 495 | (setq rmail-summary-buffer nil) |
537ab246 | 496 | ;; I have not a clue what this clause is doing. If you read this |
0dc04f42 | 497 | ;; chunk of code and have a clue, then please write it here. |
537ab246 BG |
498 | (if rmail-enable-mime |
499 | (with-current-buffer rmail-buffer | |
500 | (setq rmail-summary-buffer nil))) | |
537ab246 BG |
501 | (save-excursion |
502 | (let ((rbuf (current-buffer)) | |
503 | (total rmail-total-messages)) | |
504 | (set-buffer sumbuf) | |
505 | ;; Set up the summary buffer's contents. | |
506 | (let ((buffer-read-only nil)) | |
507 | (erase-buffer) | |
508 | (while summary-msgs | |
509 | (princ (cdr (car summary-msgs)) sumbuf) | |
510 | (setq summary-msgs (cdr summary-msgs))) | |
511 | (goto-char (point-min))) | |
512 | ;; Set up the rest of its state and local variables. | |
513 | (setq buffer-read-only t) | |
514 | (rmail-summary-mode) | |
515 | (make-local-variable 'minor-mode-alist) | |
516 | (setq minor-mode-alist (list (list t (concat ": " description)))) | |
517 | (setq rmail-buffer rbuf | |
df8f35df | 518 | rmail-summary-redo redo |
537ab246 BG |
519 | rmail-total-messages total))) |
520 | sumbuf)) | |
521 | ||
522 | (defun rmail-get-create-summary-buffer () | |
11d6c061 GM |
523 | "Return the Rmail summary buffer. |
524 | If necessary, it is created and undo is disabled." | |
537ab246 BG |
525 | (if (and rmail-summary-buffer (buffer-name rmail-summary-buffer)) |
526 | rmail-summary-buffer | |
11d6c061 GM |
527 | (let ((buff (generate-new-buffer (concat (buffer-name) "-summary")))) |
528 | (with-current-buffer buff | |
529 | (setq buffer-undo-list t)) | |
530 | buff))) | |
8d2b2df4 | 531 | |
537ab246 BG |
532 | \f |
533 | ;; Low levels of generating a summary. | |
534 | ||
535 | (defun rmail-get-summary (msgnum) | |
536 | "Return the summary line for message MSGNUM. | |
537 | The mbox buffer must be current when you call this function | |
538 | even if its text is swapped. | |
539 | ||
540 | If the message has a summary line already, it will be stored in | |
541 | the message as a header and simply returned, otherwise the | |
542 | summary line is created, saved in the message header, cached and | |
543 | returned. | |
544 | ||
545 | The current buffer contains the unrestricted message collection." | |
546 | (let ((line (aref rmail-summary-vector (1- msgnum)))) | |
547 | (unless line | |
548 | ;; Register a summary line for MSGNUM. | |
549 | (setq rmail-new-summary-line-count (1+ rmail-new-summary-line-count) | |
550 | line (rmail-create-summary-line msgnum)) | |
551 | ;; Cache the summary line for use during this Rmail session. | |
552 | (aset rmail-summary-vector (1- msgnum) line)) | |
553 | line)) | |
554 | ||
d1be4ec2 | 555 | (defcustom rmail-summary-line-decoder (function rfc2047-decode-string) |
8d2b2df4 | 556 | "Function to decode a Rmail summary line. |
537ab246 BG |
557 | It receives the summary line for one message as a string |
558 | and should return the decoded string. | |
559 | ||
d1be4ec2 KH |
560 | By default, it is `rfc2047-decode-string', which decodes MIME-encoded |
561 | subject." | |
537ab246 | 562 | :type 'function |
d1be4ec2 | 563 | :version "23.3" |
537ab246 BG |
564 | :group 'rmail-summary) |
565 | ||
566 | (defun rmail-create-summary-line (msgnum) | |
567 | "Return the summary line for message MSGNUM. | |
568 | Obtain the message summary from the header if it is available | |
569 | otherwise create it and store it in the message header. | |
570 | ||
571 | The mbox buffer must be current when you call this function | |
572 | even if its text is swapped." | |
573 | (let ((beg (rmail-msgbeg msgnum)) | |
574 | (end (rmail-msgend msgnum)) | |
575 | (deleted (rmail-message-deleted-p msgnum)) | |
3ea5d765 GM |
576 | ;; Does not work (swapped?) |
577 | ;;; (unseen (rmail-message-unseen-p msgnum)) | |
578 | unseen lines) | |
537ab246 BG |
579 | (save-excursion |
580 | ;; Switch to the buffer that has the whole mbox text. | |
581 | (if (rmail-buffers-swapped-p) | |
582 | (set-buffer rmail-view-buffer)) | |
583 | ;; Now we can compute the line count. | |
584 | (if rmail-summary-line-count-flag | |
585 | (setq lines (count-lines beg end))) | |
537ab246 BG |
586 | ;; Narrow to the message header. |
587 | (save-excursion | |
8acdd748 GM |
588 | (save-restriction |
589 | (widen) | |
590 | (goto-char beg) | |
591 | (if (search-forward "\n\n" end t) | |
592 | (progn | |
593 | (narrow-to-region beg (point)) | |
594 | ;; Replace rmail-message-unseen-p from above. | |
595 | (goto-char beg) | |
596 | (setq unseen (and (search-forward | |
597 | (concat rmail-attribute-header ": ") nil t) | |
598 | (looking-at "......U"))) | |
599 | ;; Generate a status line from the message. | |
600 | (rmail-create-summary msgnum deleted unseen lines)) | |
601 | (rmail-error-bad-format msgnum))))))) | |
537ab246 | 602 | |
3ea5d765 GM |
603 | ;; FIXME this is now unused. |
604 | ;; The intention was to display in the summary something like {E} | |
605 | ;; for an edited messaged, similarly for answered, etc. | |
606 | ;; But that conflicts with the previous rmail usage, where | |
607 | ;; any user-defined { labels } occupied this space. | |
608 | ;; So whilst it would be nice to have this information in the summary, | |
609 | ;; it would need to go somewhere else. | |
610 | (defun rmail-get-summary-status () | |
611 | "Return a coded string wrapped in curly braces denoting the status. | |
537ab246 BG |
612 | |
613 | The current buffer must already be narrowed to the message headers for | |
614 | the message being processed." | |
615 | (let ((status (mail-fetch-field rmail-attribute-header)) | |
616 | (index 0) | |
617 | (result "") | |
618 | char) | |
619 | ;; Strip off the read/unread and the deleted attribute which are | |
620 | ;; handled separately. | |
621 | (setq status | |
622 | (if status | |
623 | (concat (substring status 0 1) (substring status 2 6)) | |
624 | "")) | |
625 | (while (< index (length status)) | |
626 | (unless (string= "-" (setq char (substring status index (1+ index)))) | |
627 | (setq result (concat result char))) | |
628 | (setq index (1+ index))) | |
629 | (when (> (length result) 0) | |
630 | (setq result (concat "{" result "}"))) | |
631 | result)) | |
632 | ||
5c9b1aaa GM |
633 | (autoload 'rmail-make-label "rmailkwd") |
634 | ||
3ea5d765 GM |
635 | (defun rmail-get-summary-labels () |
636 | "Return a string wrapped in curly braces with the current message labels. | |
637 | Returns nil if there are no labels. The current buffer must | |
638 | already be narrowed to the message headers for the message being | |
639 | processed." | |
640 | (let ((labels (mail-fetch-field rmail-keyword-header))) | |
c49edcd1 GM |
641 | (and labels |
642 | (not (string-equal labels "")) | |
5c9b1aaa GM |
643 | (progn |
644 | ;; Intern so that rmail-read-label can offer completion. | |
645 | (mapc 'rmail-make-label (split-string labels ", ")) | |
646 | (format "{ %s } " labels))))) | |
3ea5d765 | 647 | |
537ab246 BG |
648 | (defun rmail-create-summary (msgnum deleted unseen lines) |
649 | "Return the summary line for message MSGNUM. | |
650 | The current buffer should already be narrowed to the header for that message. | |
651 | It could be either buffer, so don't access Rmail local variables. | |
652 | DELETED is t if this message is marked deleted. | |
653 | UNSEEN is t if it is marked unseen. | |
654 | LINES is the number of lines in the message (if we should display that) | |
655 | or else nil." | |
656 | (goto-char (point-min)) | |
657 | (let ((line (rmail-header-summary)) | |
658 | (labels (rmail-get-summary-labels)) | |
659 | pos status prefix basic-start basic-end linecount-string) | |
660 | ||
661 | (setq linecount-string | |
662 | (cond | |
663 | ((not lines) " ") | |
664 | ((<= lines 9) (format " [%d]" lines)) | |
665 | ((<= lines 99) (format " [%d]" lines)) | |
666 | ((<= lines 999) (format " [%d]" lines)) | |
667 | ((<= lines 9999) (format " [%dk]" (/ lines 1000))) | |
668 | ((<= lines 99999) (format " [%dk]" (/ lines 1000))) | |
669 | (t (format "[%dk]" (/ lines 1000))))) | |
670 | ||
671 | (setq status (cond | |
672 | (deleted ?D) | |
673 | (unseen ?-) | |
674 | (t ? )) | |
3ea5d765 | 675 | prefix (format "%5d%c " msgnum status) |
537ab246 BG |
676 | basic-start (car line) |
677 | basic-end (cadr line)) | |
678 | (funcall rmail-summary-line-decoder | |
679 | (concat prefix basic-start linecount-string " " | |
680 | labels basic-end)))) | |
681 | ||
537ab246 BG |
682 | (defun rmail-header-summary () |
683 | "Return a message summary based on the message headers. | |
684 | The value is a list of two strings, the first and second parts of the summary. | |
685 | ||
686 | The current buffer must already be narrowed to the message headers for | |
687 | the message being processed." | |
688 | (goto-char (point-min)) | |
689 | (list | |
690 | (concat (save-excursion | |
691 | (if (not (re-search-forward "^Date:" nil t)) | |
692 | " " | |
8f94cbed EZ |
693 | ;; Match month names case-insensitively |
694 | (cond ((let ((case-fold-search t)) | |
695 | (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)" | |
696 | (line-end-position) t)) | |
537ab246 BG |
697 | (format "%2d-%3s" |
698 | (string-to-number (buffer-substring | |
699 | (match-beginning 2) | |
700 | (match-end 2))) | |
701 | (buffer-substring | |
702 | (match-beginning 4) (match-end 4)))) | |
8f94cbed EZ |
703 | ((let ((case-fold-search t)) |
704 | (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)" | |
705 | (line-end-position) t)) | |
537ab246 BG |
706 | (format "%2d-%3s" |
707 | (string-to-number (buffer-substring | |
708 | (match-beginning 4) | |
709 | (match-end 4))) | |
710 | (buffer-substring | |
711 | (match-beginning 2) (match-end 2)))) | |
712 | ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)" | |
98a9d488 | 713 | (line-end-position) t) |
537ab246 BG |
714 | (format "%2s%2s%2s" |
715 | (buffer-substring | |
716 | (match-beginning 2) (match-end 2)) | |
717 | (buffer-substring | |
718 | (match-beginning 3) (match-end 3)) | |
719 | (buffer-substring | |
720 | (match-beginning 4) (match-end 4)))) | |
721 | (t "??????")))) | |
722 | " " | |
723 | (save-excursion | |
724 | (let* ((from (and (re-search-forward "^From:[ \t]*" nil t) | |
725 | (mail-strip-quoted-names | |
726 | (buffer-substring | |
727 | (1- (point)) | |
728 | ;; Get all the lines of the From field | |
729 | ;; so that we get a whole comment if there is one, | |
730 | ;; so that mail-strip-quoted-names can discard it. | |
731 | (let ((opoint (point))) | |
732 | (while (progn (forward-line 1) | |
733 | (looking-at "[ \t]"))) | |
734 | ;; Back up over newline, then trailing spaces or tabs | |
735 | (forward-char -1) | |
736 | (skip-chars-backward " \t") | |
737 | (point)))))) | |
738 | len mch lo) | |
739 | (if (or (null from) | |
740 | (string-match | |
741 | (or rmail-user-mail-address-regexp | |
742 | (concat "^\\(" | |
743 | (regexp-quote (user-login-name)) | |
744 | "\\($\\|@\\)\\|" | |
745 | (regexp-quote | |
746 | ;; Don't lose if run from init file | |
747 | ;; where user-mail-address is not | |
748 | ;; set yet. | |
749 | (or user-mail-address | |
750 | (concat (user-login-name) "@" | |
751 | (or mail-host-address | |
752 | (system-name))))) | |
753 | "\\>\\)")) | |
754 | from)) | |
755 | ;; No From field, or it's this user. | |
756 | (save-excursion | |
757 | (goto-char (point-min)) | |
758 | (if (not (re-search-forward "^To:[ \t]*" nil t)) | |
759 | nil | |
760 | (setq from | |
761 | (concat "to: " | |
762 | (mail-strip-quoted-names | |
763 | (buffer-substring | |
764 | (point) | |
765 | (progn (end-of-line) | |
766 | (skip-chars-backward " \t") | |
767 | (point))))))))) | |
768 | (if (null from) | |
769 | " " | |
92a8eba5 EZ |
770 | ;; We are going to return only 25 characters of the |
771 | ;; address, so make sure it is RFC2047 decoded before | |
772 | ;; taking its substring. This is important when the address is not on the same line as the name, e.g.: | |
773 | ;; To: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= | |
774 | ;; <stepnem@gmail.com> | |
775 | (setq from (rfc2047-decode-string from)) | |
537ab246 BG |
776 | (setq len (length from)) |
777 | (setq mch (string-match "[@%]" from)) | |
778 | (format "%25s" | |
779 | (if (or (not mch) (<= len 25)) | |
780 | (substring from (max 0 (- len 25))) | |
781 | (substring from | |
782 | (setq lo (cond ((< (- mch 14) 0) 0) | |
783 | ((< len (+ mch 11)) | |
784 | (- len 25)) | |
785 | (t (- mch 14)))) | |
786 | (min len (+ lo 25))))))))) | |
787 | (concat (if (re-search-forward "^Subject:" nil t) | |
d1be4ec2 KH |
788 | (let (pos str) |
789 | (skip-chars-forward " \t") | |
790 | (setq pos (point)) | |
791 | (forward-line 1) | |
792 | (setq str (buffer-substring pos (1- (point)))) | |
3a989246 | 793 | (while (looking-at "[ \t]") |
d1be4ec2 KH |
794 | (setq str (concat str " " |
795 | (buffer-substring (match-end 0) | |
796 | (line-end-position)))) | |
797 | (forward-line 1)) | |
798 | str) | |
537ab246 BG |
799 | (re-search-forward "[\n][\n]+" nil t) |
800 | (buffer-substring (point) (progn (end-of-line) (point)))) | |
801 | "\n"))) | |
802 | \f | |
803 | ;; Simple motion in a summary buffer. | |
804 | ||
805 | (defun rmail-summary-next-all (&optional number) | |
806 | (interactive "p") | |
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) | |
810 | (forward-line -1)) | |
811 | (display-buffer rmail-buffer)) | |
812 | ||
813 | (defun rmail-summary-previous-all (&optional number) | |
814 | (interactive "p") | |
815 | (forward-line (- (if number number 1))) | |
816 | ;; It doesn't look nice to move forward past the last message line. | |
817 | (and (eobp) (< number 0) | |
818 | (forward-line -1)) | |
819 | (display-buffer rmail-buffer)) | |
820 | ||
821 | (defun rmail-summary-next-msg (&optional number) | |
822 | "Display next non-deleted msg from rmail file. | |
823 | With optional prefix argument NUMBER, moves forward this number of non-deleted | |
824 | messages, or backward if NUMBER is negative." | |
825 | (interactive "p") | |
826 | (forward-line 0) | |
827 | (and (> number 0) (end-of-line)) | |
828 | (let ((count (if (< number 0) (- number) number)) | |
829 | (search (if (> number 0) 're-search-forward 're-search-backward)) | |
830 | (non-del-msg-found nil)) | |
831 | (while (and (> count 0) (setq non-del-msg-found | |
832 | (or (funcall search "^.....[^D]" nil t) | |
833 | non-del-msg-found))) | |
834 | (setq count (1- count)))) | |
835 | (beginning-of-line) | |
836 | (display-buffer rmail-buffer)) | |
837 | ||
838 | (defun rmail-summary-previous-msg (&optional number) | |
839 | "Display previous non-deleted msg from rmail file. | |
840 | With optional prefix argument NUMBER, moves backward this number of | |
841 | non-deleted messages." | |
842 | (interactive "p") | |
843 | (rmail-summary-next-msg (- (if number number 1)))) | |
844 | ||
845 | (defun rmail-summary-next-labeled-message (n labels) | |
846 | "Show next message with LABELS. Defaults to last labels used. | |
847 | With prefix argument N moves forward N messages with these labels." | |
848 | (interactive "p\nsMove to next msg with labels: ") | |
849 | (let (msg) | |
937e6a56 | 850 | (with-current-buffer rmail-buffer |
537ab246 BG |
851 | (rmail-next-labeled-message n labels) |
852 | (setq msg rmail-current-message)) | |
853 | (rmail-summary-goto-msg msg))) | |
854 | ||
855 | (defun rmail-summary-previous-labeled-message (n labels) | |
856 | "Show previous message with LABELS. Defaults to last labels used. | |
857 | With prefix argument N moves backward N messages with these labels." | |
858 | (interactive "p\nsMove to previous msg with labels: ") | |
859 | (let (msg) | |
937e6a56 | 860 | (with-current-buffer rmail-buffer |
537ab246 BG |
861 | (rmail-previous-labeled-message n labels) |
862 | (setq msg rmail-current-message)) | |
863 | (rmail-summary-goto-msg msg))) | |
864 | ||
865 | (defun rmail-summary-next-same-subject (n) | |
866 | "Go to the next message in the summary having the same subject. | |
867 | With prefix argument N, do this N times. | |
868 | If N is negative, go backwards." | |
869 | (interactive "p") | |
870 | (let ((forward (> n 0)) | |
871 | subject i found) | |
872 | (with-current-buffer rmail-buffer | |
873 | (setq subject (rmail-simplified-subject) | |
874 | i rmail-current-message)) | |
875 | (save-excursion | |
876 | (while (and (/= n 0) | |
877 | (if forward | |
878 | (not (eobp)) | |
879 | (not (bobp)))) | |
880 | (let (done) | |
881 | (while (and (not done) | |
882 | (if forward | |
883 | (not (eobp)) | |
884 | (not (bobp)))) | |
885 | ;; Advance thru summary. | |
886 | (forward-line (if forward 1 -1)) | |
887 | ;; Get msg number of this line. | |
888 | (setq i (string-to-number | |
889 | (buffer-substring (point) | |
890 | (min (point-max) (+ 6 (point)))))) | |
891 | (setq done (string-equal subject (rmail-simplified-subject i)))) | |
892 | (if done (setq found i))) | |
893 | (setq n (if forward (1- n) (1+ n))))) | |
894 | (if found | |
895 | (rmail-summary-goto-msg found) | |
896 | (error "No %s message with same subject" | |
897 | (if forward "following" "previous"))))) | |
898 | ||
899 | (defun rmail-summary-previous-same-subject (n) | |
900 | "Go to the previous message in the summary having the same subject. | |
901 | With prefix argument N, do this N times. | |
902 | If N is negative, go forwards instead." | |
903 | (interactive "p") | |
904 | (rmail-summary-next-same-subject (- n))) | |
905 | \f | |
906 | ;; Delete and undelete summary commands. | |
907 | ||
908 | (defun rmail-summary-delete-forward (&optional count) | |
909 | "Delete this message and move to next nondeleted one. | |
910 | Deleted messages stay in the file until the \\[rmail-expunge] command is given. | |
911 | A prefix argument serves as a repeat count; | |
912 | a negative argument means to delete and move backward." | |
913 | (interactive "p") | |
914 | (unless (numberp count) (setq count 1)) | |
915 | (let (end del-msg | |
916 | (backward (< count 0))) | |
59271b3e RS |
917 | (while (and (/= count 0) |
918 | ;; Don't waste time if we are at the beginning | |
919 | ;; and trying to go backward. | |
920 | (not (and backward (bobp)))) | |
537ab246 BG |
921 | (rmail-summary-goto-msg) |
922 | (with-current-buffer rmail-buffer | |
923 | (rmail-delete-message) | |
924 | (setq del-msg rmail-current-message)) | |
925 | (rmail-summary-mark-deleted del-msg) | |
926 | (while (and (not (if backward (bobp) (eobp))) | |
927 | (save-excursion (beginning-of-line) | |
928 | (looking-at " *[0-9]+D"))) | |
929 | (forward-line (if backward -1 1))) | |
59271b3e RS |
930 | (setq count |
931 | (if (> count 0) (1- count) (1+ count))) | |
537ab246 | 932 | ;; It looks ugly to move to the empty line at end of buffer. |
59271b3e | 933 | ;; And don't waste time after hitting the end. |
537ab246 | 934 | (and (eobp) (not backward) |
59271b3e RS |
935 | (progn (setq count 0) |
936 | (forward-line -1)))))) | |
537ab246 BG |
937 | |
938 | (defun rmail-summary-delete-backward (&optional count) | |
939 | "Delete this message and move to previous nondeleted one. | |
940 | Deleted messages stay in the file until the \\[rmail-expunge] command is given. | |
941 | A prefix argument serves as a repeat count; | |
942 | a negative argument means to delete and move forward." | |
943 | (interactive "p") | |
944 | (rmail-summary-delete-forward (- count))) | |
945 | ||
946 | (defun rmail-summary-mark-deleted (&optional n undel) | |
59271b3e RS |
947 | (and n (not (eq n (rmail-summary-msg-number))) |
948 | ;; Since third arg is t, this only alters summary, not the Rmail buf. | |
949 | (rmail-summary-goto-msg n t t)) | |
537ab246 BG |
950 | (or (eobp) |
951 | (not (overlay-get rmail-summary-overlay 'face)) | |
952 | (let ((buffer-read-only nil)) | |
953 | (skip-chars-forward " ") | |
97e92ffb | 954 | (skip-chars-forward "0-9") |
537ab246 BG |
955 | (if undel |
956 | (if (looking-at "D") | |
957 | (progn (delete-char 1) (insert " "))) | |
958 | (delete-char 1) | |
96a07ae9 | 959 | (insert "D")) |
59271b3e | 960 | ;; Discard cached new summary line. |
96a07ae9 | 961 | (with-current-buffer rmail-buffer |
59271b3e | 962 | (aset rmail-summary-vector (1- n) nil)))) |
537ab246 BG |
963 | (beginning-of-line)) |
964 | ||
8fbbdd44 GM |
965 | (defun rmail-summary-update-line (n) |
966 | "Update the summary line for message N." | |
967 | (when (rmail-summary-goto-msg n t t) | |
968 | (let* ((buffer-read-only nil) | |
969 | (start (line-beginning-position)) | |
970 | (end (line-beginning-position 2)) | |
971 | (overlays (overlays-in start end)) | |
972 | high ov) | |
973 | (while (and (setq ov (car overlays)) | |
974 | (not (setq high (overlay-get ov 'rmail-summary)))) | |
975 | (setq overlays (cdr overlays))) | |
45bd6461 | 976 | (delete-region start end) |
8fbbdd44 GM |
977 | (princ |
978 | (with-current-buffer rmail-buffer | |
979 | (aset rmail-summary-vector (1- n) (rmail-create-summary-line n))) | |
980 | (current-buffer)) | |
981 | (when high | |
982 | (forward-line -1) | |
983 | (rmail-summary-update-highlight nil))))) | |
984 | ||
537ab246 BG |
985 | (defun rmail-summary-mark-undeleted (n) |
986 | (rmail-summary-mark-deleted n t)) | |
987 | ||
988 | (defun rmail-summary-deleted-p (&optional n) | |
989 | (save-excursion | |
990 | (and n (rmail-summary-goto-msg n nil t)) | |
991 | (skip-chars-forward " ") | |
97e92ffb | 992 | (skip-chars-forward "0-9") |
537ab246 BG |
993 | (looking-at "D"))) |
994 | ||
995 | (defun rmail-summary-undelete (&optional arg) | |
996 | "Undelete current message. | |
997 | Optional prefix ARG means undelete ARG previous messages." | |
998 | (interactive "p") | |
999 | (if (/= arg 1) | |
1000 | (rmail-summary-undelete-many arg) | |
1001 | (let ((buffer-read-only nil) | |
1002 | (opoint (point))) | |
1003 | (end-of-line) | |
1004 | (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t) | |
1005 | (replace-match "\\1 ") | |
1006 | (rmail-summary-goto-msg) | |
1007 | (if rmail-enable-mime | |
1008 | (set-buffer rmail-buffer) | |
60f2013c | 1009 | (rmail-pop-to-buffer rmail-buffer)) |
537ab246 | 1010 | (and (rmail-message-deleted-p rmail-current-message) |
59271b3e | 1011 | (rmail-undelete-previous-message 1)) |
537ab246 | 1012 | (if rmail-enable-mime |
60f2013c GM |
1013 | (rmail-pop-to-buffer rmail-buffer)) |
1014 | (rmail-pop-to-buffer rmail-summary-buffer)) | |
537ab246 BG |
1015 | (t (goto-char opoint)))))) |
1016 | ||
1017 | (defun rmail-summary-undelete-many (&optional n) | |
1018 | "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs." | |
1019 | (interactive "P") | |
59271b3e RS |
1020 | (if n |
1021 | (while (and (> n 0) (not (eobp))) | |
1022 | (rmail-summary-goto-msg) | |
1023 | (let (del-msg) | |
1024 | (when (rmail-summary-deleted-p) | |
1025 | (with-current-buffer rmail-buffer | |
1026 | (rmail-undelete-previous-message 1) | |
1027 | (setq del-msg rmail-current-message)) | |
1028 | (rmail-summary-mark-undeleted del-msg))) | |
1029 | (while (and (not (eobp)) | |
1030 | (save-excursion (beginning-of-line) | |
1031 | (looking-at " *[0-9]+ "))) | |
1032 | (forward-line 1)) | |
1033 | (setq n (1- n))) | |
1034 | (rmail-summary-goto-msg 1) | |
1035 | (dotimes (i rmail-total-messages) | |
1036 | (rmail-summary-goto-msg) | |
1037 | (let (del-msg) | |
1038 | (when (rmail-summary-deleted-p) | |
1039 | (with-current-buffer rmail-buffer | |
1040 | (rmail-undelete-previous-message 1) | |
1041 | (setq del-msg rmail-current-message)) | |
1042 | (rmail-summary-mark-undeleted del-msg))) | |
1043 | (if (not (eobp)) | |
1044 | (forward-line 1)))) | |
1045 | ||
1046 | ;; It looks ugly to move to the empty line at end of buffer. | |
1047 | (and (eobp) | |
1048 | (forward-line -1))) | |
537ab246 BG |
1049 | \f |
1050 | ;; Rmail Summary mode is suitable only for specially formatted data. | |
1051 | (put 'rmail-summary-mode 'mode-class 'special) | |
1052 | ||
1b3b87df | 1053 | (define-derived-mode rmail-summary-mode special-mode "RMAIL Summary" |
537ab246 BG |
1054 | "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary]. |
1055 | As commands are issued in the summary buffer, they are applied to the | |
1056 | corresponding mail messages in the rmail buffer. | |
1057 | ||
1058 | All normal editing commands are turned off. | |
1059 | Instead, nearly all the Rmail mode commands are available, | |
1060 | though many of them move only among the messages in the summary. | |
1061 | ||
1062 | These additional commands exist: | |
1063 | ||
1064 | \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages. | |
1065 | \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer. | |
1066 | ||
1067 | Commands for sorting the summary: | |
1068 | ||
1069 | \\[rmail-summary-sort-by-date] Sort by date. | |
1070 | \\[rmail-summary-sort-by-subject] Sort by subject. | |
1071 | \\[rmail-summary-sort-by-author] Sort by author. | |
1072 | \\[rmail-summary-sort-by-recipient] Sort by recipient. | |
1073 | \\[rmail-summary-sort-by-correspondent] Sort by correspondent. | |
1074 | \\[rmail-summary-sort-by-lines] Sort by lines. | |
1075 | \\[rmail-summary-sort-by-labels] Sort by labels." | |
537ab246 BG |
1076 | (setq truncate-lines t) |
1077 | (setq buffer-read-only t) | |
1078 | (set-syntax-table text-mode-syntax-table) | |
1079 | (make-local-variable 'rmail-buffer) | |
1080 | (make-local-variable 'rmail-total-messages) | |
1081 | (make-local-variable 'rmail-current-message) | |
1082 | (setq rmail-current-message nil) | |
1083 | (make-local-variable 'rmail-summary-redo) | |
1084 | (setq rmail-summary-redo nil) | |
1085 | (make-local-variable 'revert-buffer-function) | |
1086 | (make-local-variable 'font-lock-defaults) | |
1087 | (setq font-lock-defaults '(rmail-summary-font-lock-keywords t)) | |
1b3b87df | 1088 | (rmail-summary-enable)) |
537ab246 BG |
1089 | |
1090 | ;; Summary features need to be disabled during edit mode. | |
1091 | (defun rmail-summary-disable () | |
1092 | (use-local-map text-mode-map) | |
1093 | (remove-hook 'post-command-hook 'rmail-summary-rmail-update t) | |
1094 | (setq revert-buffer-function nil)) | |
1095 | ||
1096 | (defun rmail-summary-enable () | |
1097 | (use-local-map rmail-summary-mode-map) | |
1098 | (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t) | |
1099 | (setq revert-buffer-function 'rmail-update-summary)) | |
1100 | ||
36aecf22 | 1101 | (defun rmail-summary-mark-seen (n &optional nomove unseen) |
97e92ffb GM |
1102 | "Remove the unseen mark from the current message, update the summary vector. |
1103 | N is the number of the current message. Optional argument NOMOVE | |
36aecf22 GM |
1104 | non-nil means we are already at the right column. Optional argument |
1105 | UNSEEN non-nil means mark the message as unseen." | |
97e92ffb GM |
1106 | (save-excursion |
1107 | (unless nomove | |
1108 | (beginning-of-line) | |
1109 | (skip-chars-forward " ") | |
1110 | (skip-chars-forward "0-9")) | |
36aecf22 | 1111 | (when (char-equal (following-char) (if unseen ?\s ?-)) |
97e92ffb GM |
1112 | (let ((buffer-read-only nil)) |
1113 | (delete-char 1) | |
36aecf22 | 1114 | (insert (if unseen "-" " "))) |
97e92ffb GM |
1115 | (let ((line (buffer-substring-no-properties (line-beginning-position) |
1116 | (line-beginning-position 2)))) | |
1117 | (with-current-buffer rmail-buffer | |
1118 | (aset rmail-summary-vector (1- n) line)))))) | |
1119 | ||
537ab246 BG |
1120 | (defvar rmail-summary-put-back-unseen nil |
1121 | "Used for communicating between calls to `rmail-summary-rmail-update'. | |
1122 | If it moves to a message within an Incremental Search, and removes | |
1123 | the `unseen' attribute from that message, it sets this flag | |
1124 | so that if the next motion between messages is in the same Incremental | |
1125 | Search, the `unseen' attribute is restored.") | |
1126 | ||
1127 | ;; Show in Rmail the message described by the summary line that point is on, | |
1128 | ;; but only if the Rmail buffer is already visible. | |
1129 | ;; This is a post-command-hook in summary buffers. | |
1130 | (defun rmail-summary-rmail-update () | |
1131 | (let (buffer-read-only) | |
1132 | (save-excursion | |
1133 | ;; If at end of buffer, pretend we are on the last text line. | |
1134 | (if (eobp) | |
1135 | (forward-line -1)) | |
1136 | (beginning-of-line) | |
1137 | (skip-chars-forward " ") | |
0dc04f42 RS |
1138 | ;; If the summary is empty, don't do anything. |
1139 | (unless (eobp) | |
1140 | (let ((msg-num (string-to-number (buffer-substring | |
1141 | (point) | |
1142 | (progn (skip-chars-forward "0-9") | |
1143 | (point)))))) | |
1144 | ;; Always leave `unseen' removed | |
1145 | ;; if we get out of isearch mode. | |
1146 | ;; Don't let a subsequent isearch restore that `unseen'. | |
1147 | (if (not isearch-mode) | |
1148 | (setq rmail-summary-put-back-unseen nil)) | |
1149 | ||
1150 | (or (eq rmail-current-message msg-num) | |
1151 | (let ((window (get-buffer-window rmail-buffer t)) | |
1152 | (owin (selected-window))) | |
1153 | (if isearch-mode | |
1154 | (progn | |
1155 | ;; If we first saw the previous message in this search, | |
1156 | ;; and we have gone to a different message while searching, | |
1157 | ;; put back `unseen' on the former one. | |
1158 | (when rmail-summary-put-back-unseen | |
1159 | (rmail-set-attribute rmail-unseen-attr-index t | |
1160 | rmail-current-message) | |
1161 | (save-excursion | |
1162 | (goto-char rmail-summary-put-back-unseen) | |
1163 | (rmail-summary-mark-seen rmail-current-message t t))) | |
1164 | ;; Arrange to do that later, for the new current message, | |
1165 | ;; if it still has `unseen'. | |
1166 | (setq rmail-summary-put-back-unseen | |
1167 | (if (rmail-message-unseen-p msg-num) | |
1168 | (point)))) | |
1169 | (setq rmail-summary-put-back-unseen nil)) | |
1170 | ;; Go to the desired message. | |
1171 | (setq rmail-current-message msg-num) | |
1172 | ;; Update the summary to show the message has been seen. | |
1173 | (rmail-summary-mark-seen msg-num t) | |
1174 | (if window | |
1175 | ;; Using save-window-excursion would cause the new value | |
1176 | ;; of point to get lost. | |
1177 | (unwind-protect | |
1178 | (progn | |
1179 | (select-window window) | |
1180 | (rmail-show-message msg-num t)) | |
1181 | (select-window owin)) | |
1182 | (if (buffer-name rmail-buffer) | |
1183 | (with-current-buffer rmail-buffer | |
1184 | (rmail-show-message msg-num t)))) | |
1185 | ;; In linum mode, the message buffer must be specially | |
1186 | ;; updated (Bug#4878). | |
1187 | (and (fboundp 'linum-update) | |
1188 | (buffer-name rmail-buffer) | |
1189 | (linum-update rmail-buffer)))) | |
1190 | (rmail-summary-update-highlight nil)))))) | |
537ab246 BG |
1191 | |
1192 | (defun rmail-summary-save-buffer () | |
1193 | "Save the buffer associated with this RMAIL summary." | |
1194 | (interactive) | |
1195 | (save-window-excursion | |
1196 | (save-excursion | |
1197 | (switch-to-buffer rmail-buffer) | |
1198 | (save-buffer)))) | |
537ab246 BG |
1199 | \f |
1200 | (defun rmail-summary-mouse-goto-message (event) | |
1201 | "Select the message whose summary line you click on." | |
1202 | (interactive "@e") | |
1203 | (goto-char (posn-point (event-end event))) | |
1204 | (rmail-summary-goto-msg)) | |
1205 | ||
59271b3e RS |
1206 | (defun rmail-summary-msg-number () |
1207 | (save-excursion | |
1208 | (beginning-of-line) | |
1209 | (string-to-number | |
1210 | (buffer-substring (point) | |
1211 | (min (point-max) (+ 6 (point))))))) | |
1212 | ||
537ab246 BG |
1213 | (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail) |
1214 | "Go to message N in the summary buffer and the Rmail buffer. | |
1215 | If N is nil, use the message corresponding to point in the summary | |
1216 | and move to that message in the Rmail buffer. | |
1217 | ||
1218 | If NOWARN, don't say anything if N is out of range. | |
8fbbdd44 GM |
1219 | If SKIP-RMAIL, don't do anything to the Rmail buffer. |
1220 | Returns non-nil if message N was found." | |
537ab246 BG |
1221 | (interactive "P") |
1222 | (if (consp n) (setq n (prefix-numeric-value n))) | |
1223 | (if (eobp) (forward-line -1)) | |
1224 | (beginning-of-line) | |
1225 | (let* ((obuf (current-buffer)) | |
1226 | (buf rmail-buffer) | |
1227 | (cur (point)) | |
1228 | message-not-found | |
1229 | (curmsg (string-to-number | |
1230 | (buffer-substring (point) | |
1231 | (min (point-max) (+ 6 (point)))))) | |
937e6a56 | 1232 | (total (with-current-buffer buf rmail-total-messages))) |
0dc04f42 RS |
1233 | ;; CURMSG should be nil when there's no current summary message |
1234 | ;; (for instance, if the summary is empty). | |
1235 | (if (= curmsg 0) | |
1236 | (setq curmsg nil)) | |
537ab246 BG |
1237 | ;; If message number N was specified, find that message's line |
1238 | ;; or set message-not-found. | |
1239 | ;; If N wasn't specified or that message can't be found. | |
1240 | ;; set N by default. | |
1241 | (if (not n) | |
1242 | (setq n curmsg) | |
1243 | (if (< n 1) | |
1244 | (progn (message "No preceding message") | |
1245 | (setq n 1))) | |
1246 | (if (and (> n total) | |
1247 | (> total 0)) | |
1248 | (progn (message "No following message") | |
1249 | (goto-char (point-max)) | |
1250 | (rmail-summary-goto-msg nil nowarn skip-rmail))) | |
1251 | (goto-char (point-min)) | |
1252 | (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t)) | |
1253 | (progn (or nowarn (message "Message %d not found" n)) | |
1254 | (setq n curmsg) | |
1255 | (setq message-not-found t) | |
1256 | (goto-char cur)))) | |
0dc04f42 RS |
1257 | ;; N can be nil now, along with CURMSG, |
1258 | ;; if the summary is empty. | |
1259 | (when n | |
1260 | (rmail-summary-mark-seen n) | |
1261 | (rmail-summary-update-highlight message-not-found) | |
1262 | (beginning-of-line) | |
1263 | (unless skip-rmail | |
1264 | (let ((selwin (selected-window))) | |
1265 | (unwind-protect | |
1266 | (progn (rmail-pop-to-buffer buf) | |
1267 | (rmail-show-message n)) | |
1268 | (select-window selwin) | |
1269 | ;; The actions above can alter the current buffer. Preserve it. | |
1270 | (set-buffer obuf))))) | |
8fbbdd44 | 1271 | (not message-not-found))) |
537ab246 BG |
1272 | |
1273 | ;; Update the highlighted line in an rmail summary buffer. | |
1274 | ;; That should be current. We highlight the line point is on. | |
1275 | ;; If NOT-FOUND is non-nil, we turn off highlighting. | |
1276 | (defun rmail-summary-update-highlight (not-found) | |
1277 | ;; Make sure we have an overlay to use. | |
1278 | (or rmail-summary-overlay | |
1279 | (progn | |
1280 | (make-local-variable 'rmail-summary-overlay) | |
8fbbdd44 GM |
1281 | (setq rmail-summary-overlay (make-overlay (point) (point))) |
1282 | (overlay-put rmail-summary-overlay 'rmail-summary t))) | |
537ab246 BG |
1283 | ;; If this message is in the summary, use the overlay to highlight it. |
1284 | ;; Otherwise, don't highlight anything. | |
1285 | (if not-found | |
1286 | (overlay-put rmail-summary-overlay 'face nil) | |
1287 | (move-overlay rmail-summary-overlay | |
1288 | (save-excursion (beginning-of-line) | |
1289 | (skip-chars-forward " ") | |
1290 | (point)) | |
8fbbdd44 | 1291 | (line-end-position)) |
537ab246 BG |
1292 | (overlay-put rmail-summary-overlay 'face 'highlight))) |
1293 | \f | |
1294 | (defun rmail-summary-scroll-msg-up (&optional dist) | |
1295 | "Scroll the Rmail window forward. | |
1296 | If the Rmail window is displaying the end of a message, | |
1297 | advance to the next message." | |
1298 | (interactive "P") | |
1299 | (if (eq dist '-) | |
1300 | (rmail-summary-scroll-msg-down nil) | |
1301 | (let ((rmail-buffer-window (get-buffer-window rmail-buffer))) | |
1302 | (if rmail-buffer-window | |
1303 | (if (let ((rmail-summary-window (selected-window))) | |
1304 | (select-window rmail-buffer-window) | |
1305 | (prog1 | |
1306 | ;; Is EOB visible in the buffer? | |
1307 | (save-excursion | |
290d5b58 | 1308 | (let ((ht (window-height))) |
537ab246 BG |
1309 | (move-to-window-line (- ht 2)) |
1310 | (end-of-line) | |
1311 | (eobp))) | |
1312 | (select-window rmail-summary-window))) | |
1313 | (if (not rmail-summary-scroll-between-messages) | |
1314 | (error "End of buffer") | |
1315 | (rmail-summary-next-msg (or dist 1))) | |
1316 | (let ((other-window-scroll-buffer rmail-buffer)) | |
1317 | (scroll-other-window dist))) | |
1318 | ;; If it isn't visible at all, show the beginning. | |
1319 | (rmail-summary-beginning-of-message))))) | |
1320 | ||
1321 | (defun rmail-summary-scroll-msg-down (&optional dist) | |
1322 | "Scroll the Rmail window backward. | |
1323 | If the Rmail window is now displaying the beginning of a message, | |
1324 | move to the previous message." | |
1325 | (interactive "P") | |
1326 | (if (eq dist '-) | |
1327 | (rmail-summary-scroll-msg-up nil) | |
1328 | (let ((rmail-buffer-window (get-buffer-window rmail-buffer))) | |
1329 | (if rmail-buffer-window | |
1330 | (if (let ((rmail-summary-window (selected-window))) | |
1331 | (select-window rmail-buffer-window) | |
1332 | (prog1 | |
1333 | ;; Is BOB visible in the buffer? | |
1334 | (save-excursion | |
1335 | (move-to-window-line 0) | |
1336 | (beginning-of-line) | |
1337 | (bobp)) | |
1338 | (select-window rmail-summary-window))) | |
1339 | (if (not rmail-summary-scroll-between-messages) | |
1340 | (error "Beginning of buffer") | |
1341 | (rmail-summary-previous-msg (or dist 1))) | |
1342 | (let ((other-window-scroll-buffer rmail-buffer)) | |
1343 | (scroll-other-window-down dist))) | |
1344 | ;; If it isn't visible at all, show the beginning. | |
1345 | (rmail-summary-beginning-of-message))))) | |
1346 | ||
1347 | (defun rmail-summary-beginning-of-message () | |
1348 | "Show current message from the beginning." | |
1349 | (interactive) | |
1350 | (rmail-summary-show-message 'BEG)) | |
1351 | ||
1352 | (defun rmail-summary-end-of-message () | |
1353 | "Show bottom of current message." | |
1354 | (interactive) | |
1355 | (rmail-summary-show-message 'END)) | |
1356 | ||
1357 | (defun rmail-summary-show-message (where) | |
1358 | "Show current mail message. | |
1359 | Position it according to WHERE which can be BEG or END" | |
1360 | (if (and (one-window-p) (not pop-up-frames)) | |
1361 | ;; If there is just one window, put the summary on the top. | |
1362 | (let ((buffer rmail-buffer)) | |
1363 | (split-window (selected-window) rmail-summary-window-size) | |
1364 | (select-window (frame-first-window)) | |
60f2013c | 1365 | (rmail-pop-to-buffer rmail-buffer) |
537ab246 BG |
1366 | ;; If pop-to-buffer did not use that window, delete that |
1367 | ;; window. (This can happen if it uses another frame.) | |
1368 | (or (eq buffer (window-buffer (next-window (frame-first-window)))) | |
1369 | (delete-other-windows))) | |
60f2013c | 1370 | (rmail-pop-to-buffer rmail-buffer)) |
537ab246 BG |
1371 | (cond |
1372 | ((eq where 'BEG) | |
1373 | (goto-char (point-min)) | |
1374 | (search-forward "\n\n")) | |
1375 | ((eq where 'END) | |
1376 | (goto-char (point-max)) | |
1377 | (recenter (1- (window-height)))) | |
1378 | ) | |
60f2013c | 1379 | (rmail-pop-to-buffer rmail-summary-buffer)) |
537ab246 BG |
1380 | |
1381 | (defun rmail-summary-bury () | |
1382 | "Bury the Rmail buffer and the Rmail summary buffer." | |
1383 | (interactive) | |
1384 | (let ((buffer-to-bury (current-buffer))) | |
1385 | (let (window) | |
1386 | (while (setq window (get-buffer-window rmail-buffer)) | |
1387 | (set-window-buffer window (other-buffer rmail-buffer))) | |
1388 | (bury-buffer rmail-buffer)) | |
1389 | (switch-to-buffer (other-buffer buffer-to-bury)) | |
1390 | (bury-buffer buffer-to-bury))) | |
1391 | ||
1392 | (defun rmail-summary-quit () | |
1393 | "Quit out of Rmail and Rmail summary." | |
1394 | (interactive) | |
1395 | (rmail-summary-wipe) | |
1396 | (rmail-quit)) | |
1397 | ||
1398 | (defun rmail-summary-wipe () | |
1399 | "Kill and wipe away Rmail summary, remaining within Rmail." | |
1400 | (interactive) | |
937e6a56 | 1401 | (with-current-buffer rmail-buffer (setq rmail-summary-buffer nil)) |
537ab246 BG |
1402 | (let ((local-rmail-buffer rmail-buffer)) |
1403 | (kill-buffer (current-buffer)) | |
1404 | ;; Delete window if not only one. | |
1405 | (if (not (eq (selected-window) (next-window nil 'no-minibuf))) | |
1406 | (delete-window)) | |
1407 | ;; Switch windows to the rmail buffer, or switch to it in this window. | |
60f2013c | 1408 | (rmail-pop-to-buffer local-rmail-buffer))) |
537ab246 BG |
1409 | |
1410 | (defun rmail-summary-expunge () | |
1411 | "Actually erase all deleted messages and recompute summary headers." | |
1412 | (interactive) | |
937e6a56 | 1413 | (with-current-buffer rmail-buffer |
537ab246 BG |
1414 | (when (rmail-expunge-confirmed) |
1415 | (rmail-only-expunge))) | |
1416 | (rmail-update-summary)) | |
1417 | ||
1418 | (defun rmail-summary-expunge-and-save () | |
1419 | "Expunge and save RMAIL file." | |
1420 | (interactive) | |
1421 | (save-excursion | |
1422 | (rmail-expunge-and-save)) | |
1423 | (rmail-update-summary) | |
1424 | (set-buffer-modified-p nil)) | |
1425 | ||
1426 | (defun rmail-summary-get-new-mail (&optional file-name) | |
1427 | "Get new mail and recompute summary headers. | |
1428 | ||
1429 | Optionally you can specify the file to get new mail from. In this case, | |
1430 | the file of new mail is not changed or deleted. Noninteractively, you can | |
1431 | pass the inbox file name as an argument. Interactively, a prefix | |
1432 | argument says to read a file name and use that file as the inbox." | |
1433 | (interactive | |
1434 | (list (if current-prefix-arg | |
1435 | (read-file-name "Get new mail from file: ")))) | |
1436 | (let (msg) | |
937e6a56 | 1437 | (with-current-buffer rmail-buffer |
537ab246 BG |
1438 | (rmail-get-new-mail file-name) |
1439 | ;; Get the proper new message number. | |
1440 | (setq msg rmail-current-message)) | |
1441 | ;; Make sure that message is displayed. | |
1442 | (or (zerop msg) | |
1443 | (rmail-summary-goto-msg msg)))) | |
1444 | ||
1445 | (defun rmail-summary-input (filename) | |
1446 | "Run Rmail on file FILENAME." | |
1447 | (interactive "FRun rmail on RMAIL file: ") | |
1448 | ;; We switch windows here, then display the other Rmail file there. | |
60f2013c | 1449 | (rmail-pop-to-buffer rmail-buffer) |
537ab246 BG |
1450 | (rmail filename)) |
1451 | ||
1452 | (defun rmail-summary-first-message () | |
1453 | "Show first message in Rmail file from summary buffer." | |
1454 | (interactive) | |
1455 | (with-no-warnings | |
1456 | (beginning-of-buffer))) | |
1457 | ||
1458 | (defun rmail-summary-last-message () | |
1459 | "Show last message in Rmail file from summary buffer." | |
1460 | (interactive) | |
1461 | (with-no-warnings | |
1462 | (end-of-buffer)) | |
1463 | (forward-line -1)) | |
1464 | ||
1465 | (declare-function rmail-abort-edit "rmailedit" ()) | |
1466 | (declare-function rmail-cease-edit "rmailedit"()) | |
1467 | (declare-function rmail-set-label "rmailkwd" (l state &optional n)) | |
1468 | (declare-function rmail-output-read-file-name "rmailout" ()) | |
1469 | (declare-function mail-send-and-exit "sendmail" (&optional arg)) | |
1470 | ||
1471 | (defvar rmail-summary-edit-map nil) | |
1472 | (if rmail-summary-edit-map | |
1473 | nil | |
1474 | (setq rmail-summary-edit-map | |
1475 | (nconc (make-sparse-keymap) text-mode-map)) | |
1476 | (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit) | |
1477 | (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit)) | |
1478 | ||
1479 | (defun rmail-summary-edit-current-message () | |
1480 | "Edit the contents of this message." | |
1481 | (interactive) | |
60f2013c | 1482 | (rmail-pop-to-buffer rmail-buffer) |
537ab246 BG |
1483 | (rmail-edit-current-message) |
1484 | (use-local-map rmail-summary-edit-map)) | |
1485 | ||
1486 | (defun rmail-summary-cease-edit () | |
1487 | "Finish editing message, then go back to Rmail summary buffer." | |
1488 | (interactive) | |
1489 | (rmail-cease-edit) | |
60f2013c | 1490 | (rmail-pop-to-buffer rmail-summary-buffer)) |
537ab246 BG |
1491 | |
1492 | (defun rmail-summary-abort-edit () | |
1493 | "Abort edit of current message; restore original contents. | |
1494 | Go back to summary buffer." | |
1495 | (interactive) | |
1496 | (rmail-abort-edit) | |
60f2013c | 1497 | (rmail-pop-to-buffer rmail-summary-buffer)) |
537ab246 BG |
1498 | |
1499 | (defun rmail-summary-search-backward (regexp &optional n) | |
1500 | "Show message containing next match for REGEXP. | |
1501 | Prefix argument gives repeat count; negative argument means search | |
1502 | backwards (through earlier messages). | |
1503 | Interactively, empty argument means use same regexp used last time." | |
1504 | (interactive | |
1505 | (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0)) | |
1506 | (prompt | |
1507 | (concat (if reversep "Reverse " "") "Rmail search (regexp")) | |
1508 | regexp) | |
1509 | (setq prompt | |
1510 | (concat prompt | |
1511 | (if rmail-search-last-regexp | |
1512 | (concat ", default " | |
1513 | rmail-search-last-regexp "): ") | |
1514 | "): "))) | |
1515 | (setq regexp (read-string prompt)) | |
1516 | (cond ((not (equal regexp "")) | |
1517 | (setq rmail-search-last-regexp regexp)) | |
1518 | ((not rmail-search-last-regexp) | |
1519 | (error "No previous Rmail search string"))) | |
1520 | (list rmail-search-last-regexp | |
1521 | (prefix-numeric-value current-prefix-arg)))) | |
1522 | ;; Don't use save-excursion because that prevents point from moving | |
1523 | ;; properly in the summary buffer. | |
937e6a56 SM |
1524 | (with-current-buffer rmail-buffer |
1525 | (rmail-search regexp (- n)))) | |
537ab246 BG |
1526 | |
1527 | (defun rmail-summary-search (regexp &optional n) | |
1528 | "Show message containing next match for REGEXP. | |
1529 | Prefix argument gives repeat count; negative argument means search | |
1530 | backwards (through earlier messages). | |
1531 | Interactively, empty argument means use same regexp used last time." | |
1532 | (interactive | |
1533 | (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0)) | |
1534 | (prompt | |
1535 | (concat (if reversep "Reverse " "") "Rmail search (regexp")) | |
1536 | regexp) | |
1537 | (setq prompt | |
1538 | (concat prompt | |
1539 | (if rmail-search-last-regexp | |
1540 | (concat ", default " | |
1541 | rmail-search-last-regexp "): ") | |
1542 | "): "))) | |
1543 | (setq regexp (read-string prompt)) | |
1544 | (cond ((not (equal regexp "")) | |
1545 | (setq rmail-search-last-regexp regexp)) | |
1546 | ((not rmail-search-last-regexp) | |
1547 | (error "No previous Rmail search string"))) | |
1548 | (list rmail-search-last-regexp | |
1549 | (prefix-numeric-value current-prefix-arg)))) | |
1550 | ;; Don't use save-excursion because that prevents point from moving | |
1551 | ;; properly in the summary buffer. | |
a5110f66 GM |
1552 | (let ((buffer (current-buffer)) |
1553 | (selwin (selected-window))) | |
537ab246 BG |
1554 | (unwind-protect |
1555 | (progn | |
60f2013c | 1556 | (rmail-pop-to-buffer rmail-buffer) |
537ab246 | 1557 | (rmail-search regexp n)) |
a5110f66 | 1558 | (select-window selwin) |
537ab246 BG |
1559 | (set-buffer buffer)))) |
1560 | ||
1561 | (defun rmail-summary-toggle-header () | |
1562 | "Show original message header if pruned header currently shown, or vice versa." | |
1563 | (interactive) | |
1564 | (save-window-excursion | |
1565 | (set-buffer rmail-buffer) | |
1566 | (rmail-toggle-header)) | |
1567 | ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost. | |
1568 | ;; Set point to point-min in the RMAIL buffer, if it is visible. | |
1569 | (let ((window (get-buffer-window rmail-buffer))) | |
1570 | (if window | |
1571 | ;; Using save-window-excursion would lose the new value of point. | |
1572 | (let ((owin (selected-window))) | |
1573 | (unwind-protect | |
1574 | (progn | |
1575 | (select-window window) | |
1576 | (goto-char (point-min))) | |
1577 | (select-window owin)))))) | |
1578 | ||
1579 | ||
1580 | (defun rmail-summary-add-label (label) | |
1581 | "Add LABEL to labels associated with current Rmail message. | |
1582 | Completion is performed over known labels when reading." | |
937e6a56 | 1583 | (interactive (list (with-current-buffer rmail-buffer |
537ab246 | 1584 | (rmail-read-label "Add label")))) |
937e6a56 | 1585 | (with-current-buffer rmail-buffer |
537ab246 BG |
1586 | (rmail-add-label label))) |
1587 | ||
1588 | (defun rmail-summary-kill-label (label) | |
1589 | "Remove LABEL from labels associated with current Rmail message. | |
1590 | Completion is performed over known labels when reading." | |
937e6a56 | 1591 | (interactive (list (with-current-buffer rmail-buffer |
537ab246 | 1592 | (rmail-read-label "Kill label")))) |
937e6a56 | 1593 | (with-current-buffer rmail-buffer |
537ab246 BG |
1594 | (rmail-set-label label nil))) |
1595 | \f | |
1596 | ;;;; *** Rmail Summary Mailing Commands *** | |
1597 | ||
1598 | (defun rmail-summary-override-mail-send-and-exit () | |
1599 | "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'." | |
1600 | (use-local-map (copy-keymap (current-local-map))) | |
1601 | (dolist (key (where-is-internal 'mail-send-and-exit)) | |
1602 | (define-key (current-local-map) key 'rmail-summary-send-and-exit))) | |
1603 | ||
1604 | (defun rmail-summary-mail () | |
1605 | "Send mail in another window. | |
1606 | While composing the message, use \\[mail-yank-original] to yank the | |
1607 | original message into it." | |
1608 | (interactive) | |
1609 | (let ((window (get-buffer-window rmail-buffer))) | |
1610 | (if window | |
1611 | (select-window window) | |
1612 | (set-buffer rmail-buffer))) | |
1613 | (rmail-start-mail nil nil nil nil nil (current-buffer)) | |
1614 | (rmail-summary-override-mail-send-and-exit)) | |
1615 | ||
1616 | (defun rmail-summary-continue () | |
1617 | "Continue composing outgoing message previously being composed." | |
1618 | (interactive) | |
1619 | (let ((window (get-buffer-window rmail-buffer))) | |
1620 | (if window | |
1621 | (select-window window) | |
1622 | (set-buffer rmail-buffer))) | |
1623 | (rmail-start-mail t)) | |
1624 | ||
1625 | (defun rmail-summary-reply (just-sender) | |
1626 | "Reply to the current message. | |
1627 | Normally include CC: to all other recipients of original message; | |
1628 | prefix argument means ignore them. While composing the reply, | |
1629 | use \\[mail-yank-original] to yank the original message into it." | |
1630 | (interactive "P") | |
1631 | (let ((window (get-buffer-window rmail-buffer))) | |
1632 | (if window | |
1633 | (select-window window) | |
1634 | (set-buffer rmail-buffer))) | |
1635 | (rmail-reply just-sender) | |
1636 | (rmail-summary-override-mail-send-and-exit)) | |
1637 | ||
1638 | (defun rmail-summary-retry-failure () | |
1639 | "Edit a mail message which is based on the contents of the current message. | |
1640 | For a message rejected by the mail system, extract the interesting headers and | |
1641 | the body of the original message; otherwise copy the current message." | |
1642 | (interactive) | |
1643 | (let ((window (get-buffer-window rmail-buffer))) | |
1644 | (if window | |
1645 | (select-window window) | |
1646 | (set-buffer rmail-buffer))) | |
1647 | (rmail-retry-failure) | |
1648 | (rmail-summary-override-mail-send-and-exit)) | |
1649 | ||
1650 | (defun rmail-summary-send-and-exit () | |
1651 | "Send mail reply and return to summary buffer." | |
1652 | (interactive) | |
1653 | (mail-send-and-exit t)) | |
1654 | ||
1655 | (defun rmail-summary-forward (resend) | |
1656 | "Forward the current message to another user. | |
1657 | With prefix argument, \"resend\" the message instead of forwarding it; | |
1658 | see the documentation of `rmail-resend'." | |
1659 | (interactive "P") | |
1660 | (save-excursion | |
1661 | (let ((window (get-buffer-window rmail-buffer))) | |
1662 | (if window | |
1663 | (select-window window) | |
1664 | (set-buffer rmail-buffer))) | |
1665 | (rmail-forward resend) | |
1666 | (rmail-summary-override-mail-send-and-exit))) | |
1667 | ||
1668 | (defun rmail-summary-resend () | |
1669 | "Resend current message using `rmail-resend'." | |
1670 | (interactive) | |
1671 | (save-excursion | |
1672 | (let ((window (get-buffer-window rmail-buffer))) | |
1673 | (if window | |
1674 | (select-window window) | |
1675 | (set-buffer rmail-buffer))) | |
1676 | (call-interactively 'rmail-resend))) | |
1677 | \f | |
1678 | ;; Summary output commands. | |
1679 | ||
1680 | (defun rmail-summary-output (&optional file-name n) | |
1681 | "Append this message to mail file FILE-NAME. | |
1682 | This works with both mbox format and Babyl format files, | |
1683 | outputting in the appropriate format for each. | |
1684 | The default file name comes from `rmail-default-file', | |
1685 | which is updated to the name you use in this command. | |
1686 | ||
1687 | A prefix argument N says to output that many consecutive messages | |
1688 | from those in the summary, starting with the current one. | |
1689 | Deleted messages are skipped and don't count. | |
1690 | When called from Lisp code, N may be omitted and defaults to 1. | |
1691 | ||
1692 | This command always outputs the complete message header, | |
1693 | even the header display is currently pruned." | |
1694 | (interactive | |
1695 | (progn (require 'rmailout) | |
1696 | (list (rmail-output-read-file-name) | |
1697 | (prefix-numeric-value current-prefix-arg)))) | |
1698 | (let ((i 0) prev-msg) | |
1699 | (while | |
1700 | (and (< i n) | |
1701 | (progn (rmail-summary-goto-msg) | |
1702 | (not (eq prev-msg | |
1703 | (setq prev-msg | |
1704 | (with-current-buffer rmail-buffer | |
1705 | rmail-current-message)))))) | |
1706 | (setq i (1+ i)) | |
1707 | (with-current-buffer rmail-buffer | |
1708 | (let ((rmail-delete-after-output nil)) | |
1709 | (rmail-output file-name 1))) | |
1710 | (if rmail-delete-after-output | |
1711 | (rmail-summary-delete-forward nil) | |
1712 | (if (< i n) | |
1713 | (rmail-summary-next-msg 1)))))) | |
1714 | ||
1715 | (defalias 'rmail-summary-output-to-rmail-file 'rmail-summary-output) | |
1716 | ||
1717 | (declare-function rmail-output-as-seen "rmailout" | |
1718 | (file-name &optional count noattribute from-gnus)) | |
1719 | ||
1720 | (defun rmail-summary-output-as-seen (&optional file-name n) | |
8f8cecb3 | 1721 | "Append this message to mbox file named FILE-NAME. |
537ab246 BG |
1722 | A prefix argument N says to output that many consecutive messages, |
1723 | from the summary, starting with the current one. | |
1724 | Deleted messages are skipped and don't count. | |
1725 | When called from Lisp code, N may be omitted and defaults to 1. | |
1726 | ||
1727 | This outputs the message header as you see it (or would see it) | |
1728 | displayed in Rmail. | |
1729 | ||
1730 | The default file name comes from `rmail-default-file', | |
1731 | which is updated to the name you use in this command." | |
1732 | (interactive | |
1733 | (progn (require 'rmailout) | |
1734 | (list (rmail-output-read-file-name) | |
1735 | (prefix-numeric-value current-prefix-arg)))) | |
1736 | (require 'rmailout) ; for rmail-output-as-seen in non-interactive case | |
1737 | (let ((i 0) prev-msg) | |
1738 | (while | |
1739 | (and (< i n) | |
1740 | (progn (rmail-summary-goto-msg) | |
1741 | (not (eq prev-msg | |
1742 | (setq prev-msg | |
1743 | (with-current-buffer rmail-buffer | |
1744 | rmail-current-message)))))) | |
1745 | (setq i (1+ i)) | |
1746 | (with-current-buffer rmail-buffer | |
1747 | (let ((rmail-delete-after-output nil)) | |
1748 | (rmail-output-as-seen file-name 1))) | |
1749 | (if rmail-delete-after-output | |
1750 | (rmail-summary-delete-forward nil) | |
1751 | (if (< i n) | |
1752 | (rmail-summary-next-msg 1)))))) | |
1753 | ||
1754 | (defun rmail-summary-output-menu () | |
1755 | "Output current message to another Rmail file, chosen with a menu. | |
1756 | Also set the default for subsequent \\[rmail-output-to-babyl-file] commands. | |
1757 | The variables `rmail-secondary-file-directory' and | |
1758 | `rmail-secondary-file-regexp' control which files are offered in the menu." | |
1759 | (interactive) | |
937e6a56 | 1760 | (with-current-buffer rmail-buffer |
537ab246 BG |
1761 | (let ((rmail-delete-after-output nil)) |
1762 | (call-interactively 'rmail-output-menu))) | |
1763 | (if rmail-delete-after-output | |
1764 | (rmail-summary-delete-forward nil))) | |
1765 | ||
1766 | (defun rmail-summary-construct-io-menu () | |
1767 | (let ((files (rmail-find-all-files rmail-secondary-file-directory))) | |
1768 | (if files | |
1769 | (progn | |
1770 | (define-key rmail-summary-mode-map [menu-bar classify input-menu] | |
1771 | (cons "Input Rmail File" | |
1772 | (rmail-list-to-menu "Input Rmail File" | |
1773 | files | |
1774 | 'rmail-summary-input))) | |
1775 | (define-key rmail-summary-mode-map [menu-bar classify output-menu] | |
1776 | (cons "Output Rmail File" | |
1777 | (rmail-list-to-menu "Output Rmail File" | |
1778 | files | |
1779 | 'rmail-summary-output)))) | |
1780 | (define-key rmail-summary-mode-map [menu-bar classify input-menu] | |
1781 | '("Input Rmail File" . rmail-disable-menu)) | |
1782 | (define-key rmail-summary-mode-map [menu-bar classify output-menu] | |
1783 | '("Output Rmail File" . rmail-disable-menu))))) | |
1784 | ||
1785 | (defun rmail-summary-output-body (&optional file-name) | |
1786 | "Write this message body to the file FILE-NAME. | |
1787 | FILE-NAME defaults, interactively, from the Subject field of the message." | |
1788 | (interactive) | |
937e6a56 | 1789 | (with-current-buffer rmail-buffer |
537ab246 BG |
1790 | (let ((rmail-delete-after-output nil)) |
1791 | (if file-name | |
1792 | (rmail-output-body-to-file file-name) | |
1793 | (call-interactively 'rmail-output-body-to-file)))) | |
1794 | (if rmail-delete-after-output | |
1795 | (rmail-summary-delete-forward nil))) | |
1796 | \f | |
1797 | ;; Sorting messages in Rmail Summary buffer. | |
1798 | ||
1799 | (defun rmail-summary-sort-by-date (reverse) | |
11d6c061 GM |
1800 | "Sort messages of current Rmail summary by \"Date\" header. |
1801 | If prefix argument REVERSE is non-nil, sorts in reverse order." | |
537ab246 BG |
1802 | (interactive "P") |
1803 | (rmail-sort-from-summary (function rmail-sort-by-date) reverse)) | |
1804 | ||
1805 | (defun rmail-summary-sort-by-subject (reverse) | |
11d6c061 GM |
1806 | "Sort messages of current Rmail summary by \"Subject\" header. |
1807 | Ignores any \"Re: \" prefix. If prefix argument REVERSE is | |
1808 | non-nil, sorts in reverse order." | |
537ab246 BG |
1809 | (interactive "P") |
1810 | (rmail-sort-from-summary (function rmail-sort-by-subject) reverse)) | |
1811 | ||
1812 | (defun rmail-summary-sort-by-author (reverse) | |
1813 | "Sort messages of current Rmail summary by author. | |
11d6c061 GM |
1814 | This uses either the \"From\" or \"Sender\" header, downcased. |
1815 | If prefix argument REVERSE is non-nil, sorts in reverse order." | |
537ab246 BG |
1816 | (interactive "P") |
1817 | (rmail-sort-from-summary (function rmail-sort-by-author) reverse)) | |
1818 | ||
1819 | (defun rmail-summary-sort-by-recipient (reverse) | |
1820 | "Sort messages of current Rmail summary by recipient. | |
11d6c061 GM |
1821 | This uses either the \"To\" or \"Apparently-To\" header, downcased. |
1822 | If prefix argument REVERSE is non-nil, sorts in reverse order." | |
537ab246 BG |
1823 | (interactive "P") |
1824 | (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse)) | |
1825 | ||
1826 | (defun rmail-summary-sort-by-correspondent (reverse) | |
1827 | "Sort messages of current Rmail summary by other correspondent. | |
11d6c061 GM |
1828 | This uses either the \"From\", \"Sender\", \"To\", or |
1829 | \"Apparently-To\" header, downcased. Uses the first header not | |
38a71655 | 1830 | excluded by `mail-dont-reply-to-names'. If prefix argument |
11d6c061 | 1831 | REVERSE is non-nil, sorts in reverse order." |
537ab246 BG |
1832 | (interactive "P") |
1833 | (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse)) | |
1834 | ||
1835 | (defun rmail-summary-sort-by-lines (reverse) | |
11d6c061 GM |
1836 | "Sort messages of current Rmail summary by the number of lines. |
1837 | If prefix argument REVERSE is non-nil, sorts in reverse order." | |
537ab246 BG |
1838 | (interactive "P") |
1839 | (rmail-sort-from-summary (function rmail-sort-by-lines) reverse)) | |
1840 | ||
1841 | (defun rmail-summary-sort-by-labels (reverse labels) | |
1842 | "Sort messages of current Rmail summary by labels. | |
11d6c061 GM |
1843 | LABELS is a comma-separated list of labels. |
1844 | If prefix argument REVERSE is non-nil, sorts in reverse order." | |
537ab246 BG |
1845 | (interactive "P\nsSort by labels: ") |
1846 | (rmail-sort-from-summary | |
11d6c061 | 1847 | (lambda (reverse) (rmail-sort-by-labels reverse labels)) |
537ab246 BG |
1848 | reverse)) |
1849 | ||
1850 | (defun rmail-sort-from-summary (sortfun reverse) | |
11d6c061 GM |
1851 | "Sort the Rmail buffer using sorting function SORTFUN. |
1852 | Passes REVERSE to SORTFUN as its sole argument. Then regenerates | |
1853 | the summary. Note that the whole Rmail buffer is sorted, even if | |
1854 | the summary is only showing a subset of messages." | |
537ab246 BG |
1855 | (require 'rmailsort) |
1856 | (let ((selwin (selected-window))) | |
1857 | (unwind-protect | |
60f2013c | 1858 | (progn (rmail-pop-to-buffer rmail-buffer) |
537ab246 BG |
1859 | (funcall sortfun reverse)) |
1860 | (select-window selwin)))) | |
1861 | ||
1862 | (provide 'rmailsum) | |
1863 | ||
a5e92116 GM |
1864 | ;; Local Variables: |
1865 | ;; generated-autoload-file: "rmail.el" | |
1866 | ;; End: | |
1867 | ||
537ab246 | 1868 | ;;; rmailsum.el ends here |