Commit | Line | Data |
---|---|---|
76550a57 | 1 | ;;; rmailsum.el --- make summary buffers for the mail reader |
aae56ea7 | 2 | |
58285c3b | 3 | ;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001 |
36c5e617 | 4 | ;; Free Software Foundation, Inc. |
9750e079 | 5 | |
e5167999 | 6 | ;; Maintainer: FSF |
d7b4d18f | 7 | ;; Keywords: mail |
e5167999 | 8 | |
4d4d11cc JB |
9 | ;; This file is part of GNU Emacs. |
10 | ||
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 | |
e5167999 | 13 | ;; the Free Software Foundation; either version 2, or (at your option) |
4d4d11cc JB |
14 | ;; any later version. |
15 | ||
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. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
4d4d11cc | 25 | |
aae56ea7 ER |
26 | ;;; Commentary: |
27 | ||
d41d75fb RS |
28 | ;; Extended by Bob Weiner of Motorola |
29 | ;; Provided all commands from rmail-mode in rmail-summary-mode and made key | |
30 | ;; bindings in both modes wholly compatible. | |
31 | ||
aae56ea7 ER |
32 | ;;; Code: |
33 | ||
6e626f7e RS |
34 | ;; For rmail-select-summary |
35 | (require 'rmail) | |
36 | ||
be2e861f | 37 | ;;;###autoload |
0a01a04e RS |
38 | (defcustom rmail-summary-scroll-between-messages t |
39 | "*Non-nil means Rmail summary scroll commands move between messages." | |
40 | :type 'boolean | |
41 | :group 'rmail-summary) | |
be2e861f | 42 | |
ea7bddc4 | 43 | ;;;###autoload |
0a01a04e | 44 | (defcustom rmail-summary-line-count-flag t |
689421a9 | 45 | "*Non-nil means Rmail summary should show the number of lines in each message." |
0a01a04e RS |
46 | :type 'boolean |
47 | :group 'rmail-summary) | |
ea7bddc4 | 48 | |
1a6bc985 | 49 | (defvar rmail-summary-font-lock-keywords |
70d2f115 EZ |
50 | '(("^.....D.*" . font-lock-string-face) ; Deleted. |
51 | ("^.....-.*" . font-lock-type-face) ; Unread. | |
1a6bc985 | 52 | ;; Neither of the below will be highlighted if either of the above are: |
70d2f115 | 53 | ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face) ; Date. |
d8562b03 | 54 | ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face)) ; Labels. |
1a6bc985 RS |
55 | "Additional expressions to highlight in Rmail Summary mode.") |
56 | ||
d41d75fb | 57 | ;; Entry points for making a summary buffer. |
4d4d11cc | 58 | |
d41d75fb RS |
59 | ;; Regenerate the contents of the summary |
60 | ;; using the same selection criterion as last time. | |
61 | ;; M-x revert-buffer in a summary buffer calls this function. | |
62 | (defun rmail-update-summary (&rest ignore) | |
63 | (apply (car rmail-summary-redo) (cdr rmail-summary-redo))) | |
4d4d11cc | 64 | |
d2288651 | 65 | ;;;###autoload |
4d4d11cc JB |
66 | (defun rmail-summary () |
67 | "Display a summary of all messages, one line per message." | |
68 | (interactive) | |
d41d75fb | 69 | (rmail-new-summary "All" '(rmail-summary) nil)) |
4d4d11cc | 70 | |
d2288651 | 71 | ;;;###autoload |
4d4d11cc JB |
72 | (defun rmail-summary-by-labels (labels) |
73 | "Display a summary of all messages with one or more LABELS. | |
74 | LABELS should be a string containing the desired labels, separated by commas." | |
75 | (interactive "sLabels to summarize by: ") | |
76 | (if (string= labels "") | |
77 | (setq labels (or rmail-last-multi-labels | |
78 | (error "No label specified")))) | |
79 | (setq rmail-last-multi-labels labels) | |
80 | (rmail-new-summary (concat "labels " labels) | |
d41d75fb | 81 | (list 'rmail-summary-by-labels labels) |
4d4d11cc JB |
82 | 'rmail-message-labels-p |
83 | (concat ", \\(" (mail-comma-list-regexp labels) "\\),"))) | |
84 | ||
d2288651 | 85 | ;;;###autoload |
4d4d11cc JB |
86 | (defun rmail-summary-by-recipients (recipients &optional primary-only) |
87 | "Display a summary of all messages with the given RECIPIENTS. | |
88 | Normally checks the To, From and Cc fields of headers; | |
89 | but if PRIMARY-ONLY is non-nil (prefix arg given), | |
90 | only look in the To and From fields. | |
d41d75fb | 91 | RECIPIENTS is a string of regexps separated by commas." |
4d4d11cc JB |
92 | (interactive "sRecipients to summarize by: \nP") |
93 | (rmail-new-summary | |
94 | (concat "recipients " recipients) | |
d41d75fb | 95 | (list 'rmail-summary-by-recipients recipients primary-only) |
4d4d11cc JB |
96 | 'rmail-message-recipients-p |
97 | (mail-comma-list-regexp recipients) primary-only)) | |
98 | ||
d2288651 | 99 | ;;;###autoload |
4d4d11cc JB |
100 | (defun rmail-summary-by-regexp (regexp) |
101 | "Display a summary of all messages according to regexp REGEXP. | |
102 | If the regular expression is found in the header of the message | |
103 | \(including in the date and other lines, as well as the subject line), | |
104 | Emacs will list the header line in the RMAIL-summary." | |
105 | (interactive "sRegexp to summarize by: ") | |
106 | (if (string= regexp "") | |
107 | (setq regexp (or rmail-last-regexp | |
55535639 | 108 | (error "No regexp specified")))) |
4d4d11cc JB |
109 | (setq rmail-last-regexp regexp) |
110 | (rmail-new-summary (concat "regexp " regexp) | |
d41d75fb | 111 | (list 'rmail-summary-by-regexp regexp) |
4d4d11cc JB |
112 | 'rmail-message-regexp-p |
113 | regexp)) | |
114 | ||
d41d75fb RS |
115 | ;; rmail-summary-by-topic |
116 | ;; 1989 R.A. Schnitzler | |
117 | ||
d2288651 | 118 | ;;;###autoload |
d41d75fb RS |
119 | (defun rmail-summary-by-topic (subject &optional whole-message) |
120 | "Display a summary of all messages with the given SUBJECT. | |
121 | Normally checks the Subject field of headers; | |
a1506d29 | 122 | but if WHOLE-MESSAGE is non-nil (prefix arg given), |
d41d75fb RS |
123 | look in the whole message. |
124 | SUBJECT is a string of regexps separated by commas." | |
125 | (interactive "sTopics to summarize by: \nP") | |
126 | (rmail-new-summary | |
127 | (concat "about " subject) | |
128 | (list 'rmail-summary-by-topic subject whole-message) | |
129 | 'rmail-message-subject-p | |
130 | (mail-comma-list-regexp subject) whole-message)) | |
131 | ||
132 | (defun rmail-message-subject-p (msg subject &optional whole-message) | |
133 | (save-restriction | |
134 | (goto-char (rmail-msgbeg msg)) | |
10a0a250 | 135 | (search-forward "\n*** EOOH ***\n" (rmail-msgend msg) 'move) |
d41d75fb RS |
136 | (narrow-to-region |
137 | (point) | |
e90b6d92 | 138 | (progn (search-forward (if whole-message "\^_" "\n\n")) (point))) |
d41d75fb RS |
139 | (goto-char (point-min)) |
140 | (if whole-message (re-search-forward subject nil t) | |
4c1832e9 GM |
141 | (string-match subject (let ((subj (mail-fetch-field "Subject"))) |
142 | (if subj | |
143 | (funcall rmail-summary-line-decoder subj) | |
144 | "")))))) | |
cad1e93b | 145 | |
d2288651 | 146 | ;;;###autoload |
cad1e93b RS |
147 | (defun rmail-summary-by-senders (senders) |
148 | "Display a summary of all messages with the given SENDERS. | |
149 | SENDERS is a string of names separated by commas." | |
150 | (interactive "sSenders to summarize by: ") | |
151 | (rmail-new-summary | |
152 | (concat "senders " senders) | |
84fa8eb5 | 153 | (list 'rmail-summary-by-senders senders) |
cad1e93b RS |
154 | 'rmail-message-senders-p |
155 | (mail-comma-list-regexp senders))) | |
156 | ||
157 | (defun rmail-message-senders-p (msg senders) | |
158 | (save-restriction | |
159 | (goto-char (rmail-msgbeg msg)) | |
160 | (search-forward "\n*** EOOH ***\n") | |
161 | (narrow-to-region (point) (progn (search-forward "\n\n") (point))) | |
162 | (string-match senders (or (mail-fetch-field "From") "")))) | |
4d4d11cc | 163 | \f |
d41d75fb RS |
164 | ;; General making of a summary buffer. |
165 | ||
166 | (defvar rmail-summary-symbol-number 0) | |
167 | ||
168 | (defun rmail-new-summary (description redo-form function &rest args) | |
4d4d11cc JB |
169 | "Create a summary of selected messages. |
170 | DESCRIPTION makes part of the mode line of the summary buffer. | |
171 | For each message, FUNCTION is applied to the message number and ARGS... | |
172 | and if the result is non-nil, that message is included. | |
173 | nil for FUNCTION means all messages." | |
174 | (message "Computing summary lines...") | |
d41d75fb RS |
175 | (let (sumbuf mesg was-in-summary) |
176 | (save-excursion | |
177 | ;; Go to the Rmail buffer. | |
178 | (if (eq major-mode 'rmail-summary-mode) | |
67f2e119 GM |
179 | (setq was-in-summary t)) |
180 | (set-buffer rmail-buffer) | |
d41d75fb | 181 | ;; Find its summary buffer, or make one. |
deb5848d RS |
182 | (setq sumbuf |
183 | (if (and rmail-summary-buffer | |
184 | (buffer-name rmail-summary-buffer)) | |
185 | rmail-summary-buffer | |
186 | (generate-new-buffer (concat (buffer-name) "-summary")))) | |
d41d75fb | 187 | (setq mesg rmail-current-message) |
d41d75fb RS |
188 | ;; Filter the messages; make or get their summary lines. |
189 | (let ((summary-msgs ()) | |
190 | (new-summary-line-count 0)) | |
191 | (let ((msgnum 1) | |
36f41915 KH |
192 | (buffer-read-only nil) |
193 | (old-min (point-min-marker)) | |
194 | (old-max (point-max-marker))) | |
195 | ;; Can't use save-restriction here; that doesn't work if we | |
196 | ;; plan to modify text outside the original restriction. | |
197 | (save-excursion | |
198 | (widen) | |
199 | (goto-char (point-min)) | |
200 | (while (>= rmail-total-messages msgnum) | |
201 | (if (or (null function) | |
202 | (apply function (cons msgnum args))) | |
203 | (setq summary-msgs | |
204 | (cons (cons msgnum (rmail-make-summary-line msgnum)) | |
205 | summary-msgs))) | |
206 | (setq msgnum (1+ msgnum))) | |
207 | (setq summary-msgs (nreverse summary-msgs))) | |
208 | (narrow-to-region old-min old-max)) | |
deb5848d RS |
209 | ;; Temporarily, while summary buffer is unfinished, |
210 | ;; we "don't have" a summary. | |
211 | (setq rmail-summary-buffer nil) | |
67f2e119 GM |
212 | (if rmail-enable-mime |
213 | (with-current-buffer rmail-view-buffer | |
214 | (setq rmail-summary-buffer nil))) | |
deb5848d RS |
215 | (save-excursion |
216 | (let ((rbuf (current-buffer)) | |
db56d71e | 217 | (vbuf rmail-view-buffer) |
deb5848d RS |
218 | (total rmail-total-messages)) |
219 | (set-buffer sumbuf) | |
220 | ;; Set up the summary buffer's contents. | |
221 | (let ((buffer-read-only nil)) | |
222 | (erase-buffer) | |
223 | (while summary-msgs | |
224 | (princ (cdr (car summary-msgs)) sumbuf) | |
225 | (setq summary-msgs (cdr summary-msgs))) | |
226 | (goto-char (point-min))) | |
227 | ;; Set up the rest of its state and local variables. | |
228 | (setq buffer-read-only t) | |
229 | (rmail-summary-mode) | |
230 | (make-local-variable 'minor-mode-alist) | |
73d8f1de | 231 | (setq minor-mode-alist (list (list t (concat ": " description)))) |
deb5848d | 232 | (setq rmail-buffer rbuf |
db56d71e | 233 | rmail-view-buffer vbuf |
deb5848d RS |
234 | rmail-summary-redo redo-form |
235 | rmail-total-messages total)))) | |
236 | (setq rmail-summary-buffer sumbuf)) | |
d41d75fb RS |
237 | ;; Now display the summary buffer and go to the right place in it. |
238 | (or was-in-summary | |
6e626f7e RS |
239 | (progn |
240 | (if (and (one-window-p) | |
241 | pop-up-windows (not pop-up-frames)) | |
242 | ;; If there is just one window, put the summary on the top. | |
243 | (progn | |
244 | (split-window (selected-window) rmail-summary-window-size) | |
245 | (select-window (next-window (frame-first-window))) | |
246 | (pop-to-buffer sumbuf) | |
247 | ;; If pop-to-buffer did not use that window, delete that | |
248 | ;; window. (This can happen if it uses another frame.) | |
249 | (if (not (eq sumbuf (window-buffer (frame-first-window)))) | |
250 | (delete-other-windows))) | |
251 | (pop-to-buffer sumbuf)) | |
252 | (set-buffer rmail-buffer) | |
253 | ;; This is how rmail makes the summary buffer reappear. | |
254 | ;; We do this here to make the window the proper size. | |
255 | (rmail-select-summary nil) | |
256 | (set-buffer rmail-summary-buffer))) | |
d41d75fb | 257 | (rmail-summary-goto-msg mesg t t) |
88aabab3 | 258 | (rmail-summary-construct-io-menu) |
d41d75fb RS |
259 | (message "Computing summary lines...done"))) |
260 | \f | |
261 | ;; Low levels of generating a summary. | |
4d4d11cc JB |
262 | |
263 | (defun rmail-make-summary-line (msg) | |
264 | (let ((line (or (aref rmail-summary-vector (1- msg)) | |
265 | (progn | |
266 | (setq new-summary-line-count | |
267 | (1+ new-summary-line-count)) | |
268 | (if (zerop (% new-summary-line-count 10)) | |
269 | (message "Computing summary lines...%d" | |
270 | new-summary-line-count)) | |
271 | (rmail-make-summary-line-1 msg))))) | |
272 | ;; Fix up the part of the summary that says "deleted" or "unseen". | |
7271daf7 | 273 | (aset line 5 |
4d4d11cc JB |
274 | (if (rmail-message-deleted-p msg) ?\D |
275 | (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg)))) | |
276 | ?\- ?\ ))) | |
277 | line)) | |
278 | ||
db56d71e | 279 | ;;;###autoload |
0a01a04e | 280 | (defcustom rmail-summary-line-decoder (function identity) |
db56d71e KH |
281 | "*Function to decode summary-line. |
282 | ||
0a01a04e RS |
283 | By default, `identity' is set." |
284 | :type 'function | |
285 | :group 'rmail-summary) | |
db56d71e | 286 | |
4d4d11cc JB |
287 | (defun rmail-make-summary-line-1 (msg) |
288 | (goto-char (rmail-msgbeg msg)) | |
289 | (let* ((lim (save-excursion (forward-line 2) (point))) | |
290 | pos | |
291 | (labels | |
292 | (progn | |
293 | (forward-char 3) | |
294 | (concat | |
295 | ; (if (save-excursion (re-search-forward ",answered," lim t)) | |
296 | ; "*" "") | |
297 | ; (if (save-excursion (re-search-forward ",filed," lim t)) | |
298 | ; "!" "") | |
299 | (if (progn (search-forward ",,") (eolp)) | |
300 | "" | |
301 | (concat "{" | |
302 | (buffer-substring (point) | |
d8562b03 RS |
303 | (progn (end-of-line) |
304 | (backward-char) | |
305 | (if (looking-at ",") | |
306 | (point) | |
307 | (1+ (point))))) | |
308 | " } "))))) | |
4d4d11cc JB |
309 | (line |
310 | (progn | |
311 | (forward-line 1) | |
312 | (if (looking-at "Summary-line: ") | |
313 | (progn | |
314 | (goto-char (match-end 0)) | |
315 | (setq line | |
316 | (buffer-substring (point) | |
317 | (progn (forward-line 1) (point))))))))) | |
318 | ;; Obsolete status lines lacking a # should be flushed. | |
319 | (and line | |
320 | (not (string-match "#" line)) | |
321 | (progn | |
322 | (delete-region (point) | |
323 | (progn (forward-line -1) (point))) | |
324 | (setq line nil))) | |
325 | ;; If we didn't get a valid status line from the message, | |
326 | ;; make a new one and put it in the message. | |
327 | (or line | |
328 | (let* ((case-fold-search t) | |
329 | (next (rmail-msgend msg)) | |
330 | (beg (if (progn (goto-char (rmail-msgbeg msg)) | |
331 | (search-forward "\n*** EOOH ***\n" next t)) | |
332 | (point) | |
333 | (forward-line 1) | |
334 | (point))) | |
335 | (end (progn (search-forward "\n\n" nil t) (point)))) | |
336 | (save-restriction | |
337 | (narrow-to-region beg end) | |
338 | (goto-char beg) | |
339 | (setq line (rmail-make-basic-summary-line))) | |
340 | (goto-char (rmail-msgbeg msg)) | |
341 | (forward-line 2) | |
342 | (insert "Summary-line: " line))) | |
343 | (setq pos (string-match "#" line)) | |
344 | (aset rmail-summary-vector (1- msg) | |
db56d71e | 345 | (funcall rmail-summary-line-decoder |
7271daf7 | 346 | (concat (format "%5d " msg) |
db56d71e KH |
347 | (substring line 0 pos) |
348 | labels | |
349 | (substring line (1+ pos))))) | |
350 | )) | |
4d4d11cc | 351 | |
36c5e617 GM |
352 | ;;;###autoload |
353 | (defcustom rmail-user-mail-address-regexp nil | |
354 | "*Regexp matching user mail addresses. | |
355 | If non-nil, this variable is used to identify the correspondent | |
356 | when receiving new mail. If it matches the address of the sender, | |
357 | the recipient is taken as correspondent of a mail. | |
358 | If nil \(default value\), your `user-login-name' and `user-mail-address' | |
359 | are used to exclude yourself as correspondent. | |
360 | ||
361 | Usually you don't have to set this variable, except if you collect mails | |
362 | sent by you under different user names. | |
e91053e8 | 363 | Then it should be a regexp matching your mail addresses. |
36c5e617 GM |
364 | |
365 | Setting this variable has an effect only before reading a mail." | |
366 | :type '(choice (const :tag "None" nil) regexp) | |
367 | :group 'rmail-retrieve | |
368 | :version "21.1") | |
369 | ||
4d4d11cc JB |
370 | (defun rmail-make-basic-summary-line () |
371 | (goto-char (point-min)) | |
372 | (concat (save-excursion | |
373 | (if (not (re-search-forward "^Date:" nil t)) | |
374 | " " | |
375 | (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)" | |
376 | (save-excursion (end-of-line) (point)) t) | |
377 | (format "%2d-%3s" | |
027a4b6b JB |
378 | (string-to-number (buffer-substring |
379 | (match-beginning 2) | |
380 | (match-end 2))) | |
4d4d11cc JB |
381 | (buffer-substring |
382 | (match-beginning 4) (match-end 4)))) | |
383 | ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)" | |
384 | (save-excursion (end-of-line) (point)) t) | |
385 | (format "%2d-%3s" | |
027a4b6b JB |
386 | (string-to-number (buffer-substring |
387 | (match-beginning 4) | |
388 | (match-end 4))) | |
4d4d11cc JB |
389 | (buffer-substring |
390 | (match-beginning 2) (match-end 2)))) | |
15065a0f MB |
391 | ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)" |
392 | (save-excursion (end-of-line) (point)) t) | |
393 | (format "%2s%2s%2s" | |
394 | (buffer-substring | |
395 | (match-beginning 2) (match-end 2)) | |
396 | (buffer-substring | |
397 | (match-beginning 3) (match-end 3)) | |
398 | (buffer-substring | |
399 | (match-beginning 4) (match-end 4)))) | |
4d4d11cc JB |
400 | (t "??????")))) |
401 | " " | |
402 | (save-excursion | |
71f46c95 RS |
403 | (let* ((from (and (re-search-forward "^From:[ \t]*" nil t) |
404 | (mail-strip-quoted-names | |
405 | (buffer-substring | |
406 | (1- (point)) | |
407 | ;; Get all the lines of the From field | |
408 | ;; so that we get a whole comment if there is one, | |
409 | ;; so that mail-strip-quoted-names can discard it. | |
410 | (let ((opoint (point))) | |
411 | (while (progn (forward-line 1) | |
412 | (looking-at "[ \t]"))) | |
413 | ;; Back up over newline, then trailing spaces or tabs | |
414 | (forward-char -1) | |
415 | (skip-chars-backward " \t") | |
416 | (point)))))) | |
417 | len mch lo) | |
418 | (if (or (null from) | |
419 | (string-match | |
420 | (or rmail-user-mail-address-regexp | |
421 | (concat "^\\(" | |
422 | (regexp-quote (user-login-name)) | |
423 | "\\($\\|@\\)\\|" | |
424 | (regexp-quote | |
425 | ;; Don't lose if run from init file | |
426 | ;; where user-mail-address is not | |
427 | ;; set yet. | |
428 | (or user-mail-address | |
429 | (concat (user-login-name) "@" | |
430 | (or mail-host-address | |
431 | (system-name))))) | |
432 | "\\>\\)")) | |
433 | from)) | |
434 | ;; No From field, or it's this user. | |
435 | (save-excursion | |
436 | (goto-char (point-min)) | |
437 | (if (not (re-search-forward "^To:[ \t]*" nil t)) | |
438 | nil | |
439 | (setq from | |
440 | (concat "to: " | |
441 | (mail-strip-quoted-names | |
442 | (buffer-substring | |
443 | (point) | |
444 | (progn (end-of-line) | |
445 | (skip-chars-backward " \t") | |
446 | (point))))))))) | |
447 | (if (null from) | |
448 | " " | |
4d4d11cc JB |
449 | (setq len (length from)) |
450 | (setq mch (string-match "[@%]" from)) | |
451 | (format "%25s" | |
452 | (if (or (not mch) (<= len 25)) | |
453 | (substring from (max 0 (- len 25))) | |
454 | (substring from | |
95412165 RS |
455 | (setq lo (cond ((< (- mch 14) 0) 0) |
456 | ((< len (+ mch 11)) | |
4d4d11cc | 457 | (- len 25)) |
95412165 | 458 | (t (- mch 14)))) |
4d4d11cc | 459 | (min len (+ lo 25)))))))) |
4f21aa66 | 460 | (if rmail-summary-line-count-flag |
ea7bddc4 RS |
461 | (save-excursion |
462 | (save-restriction | |
463 | (widen) | |
464 | (let ((beg (rmail-msgbeg msgnum)) | |
465 | (end (rmail-msgend msgnum)) | |
466 | lines) | |
467 | (save-excursion | |
468 | (goto-char beg) | |
469 | ;; Count only lines in the reformatted header, | |
470 | ;; if we have reformatted it. | |
471 | (search-forward "\n*** EOOH ***\n" end t) | |
472 | (setq lines (count-lines (point) end))) | |
473 | (format (cond | |
474 | ((<= lines 9) " [%d]") | |
475 | ((<= lines 99) " [%d]") | |
476 | ((<= lines 999) " [%3d]") | |
477 | (t "[%d]")) | |
478 | lines)))) | |
479 | " ") | |
972a769b | 480 | " #" ;The # is part of the format. |
4d4d11cc JB |
481 | (if (re-search-forward "^Subject:" nil t) |
482 | (progn (skip-chars-forward " \t") | |
483 | (buffer-substring (point) | |
484 | (progn (end-of-line) | |
485 | (point)))) | |
486 | (re-search-forward "[\n][\n]+" nil t) | |
487 | (buffer-substring (point) (progn (end-of-line) (point)))) | |
488 | "\n")) | |
d41d75fb RS |
489 | \f |
490 | ;; Simple motion in a summary buffer. | |
4d4d11cc JB |
491 | |
492 | (defun rmail-summary-next-all (&optional number) | |
493 | (interactive "p") | |
bb694792 | 494 | (forward-line (if number number 1)) |
cc101382 RS |
495 | ;; It doesn't look nice to move forward past the last message line. |
496 | (and (eobp) (> number 0) | |
497 | (forward-line -1)) | |
bb694792 | 498 | (display-buffer rmail-buffer)) |
4d4d11cc JB |
499 | |
500 | (defun rmail-summary-previous-all (&optional number) | |
501 | (interactive "p") | |
bb694792 | 502 | (forward-line (- (if number number 1))) |
cc101382 RS |
503 | ;; It doesn't look nice to move forward past the last message line. |
504 | (and (eobp) (< number 0) | |
505 | (forward-line -1)) | |
bb694792 | 506 | (display-buffer rmail-buffer)) |
4d4d11cc JB |
507 | |
508 | (defun rmail-summary-next-msg (&optional number) | |
d41d75fb RS |
509 | "Display next non-deleted msg from rmail file. |
510 | With optional prefix argument NUMBER, moves forward this number of non-deleted | |
511 | messages, or backward if NUMBER is negative." | |
4d4d11cc JB |
512 | (interactive "p") |
513 | (forward-line 0) | |
b37767e7 | 514 | (and (> number 0) (end-of-line)) |
4d4d11cc JB |
515 | (let ((count (if (< number 0) (- number) number)) |
516 | (search (if (> number 0) 're-search-forward 're-search-backward)) | |
d41d75fb RS |
517 | (non-del-msg-found nil)) |
518 | (while (and (> count 0) (setq non-del-msg-found | |
682ac5eb | 519 | (or (funcall search "^....[^D]" nil t) |
d41d75fb | 520 | non-del-msg-found))) |
bb694792 | 521 | (setq count (1- count)))) |
b37767e7 | 522 | (beginning-of-line) |
689421a9 | 523 | (display-buffer rmail-view-buffer)) |
4d4d11cc JB |
524 | |
525 | (defun rmail-summary-previous-msg (&optional number) | |
689421a9 JPW |
526 | "Display previous non-deleted msg from rmail file. |
527 | With optional prefix argument NUMBER, moves backward this number of | |
528 | non-deleted messages." | |
4d4d11cc JB |
529 | (interactive "p") |
530 | (rmail-summary-next-msg (- (if number number 1)))) | |
531 | ||
d41d75fb | 532 | (defun rmail-summary-next-labeled-message (n labels) |
689421a9 | 533 | "Show next message with LABELS. Defaults to last labels used. |
d41d75fb RS |
534 | With prefix argument N moves forward N messages with these labels." |
535 | (interactive "p\nsMove to next msg with labels: ") | |
d69006df KH |
536 | (let (msg) |
537 | (save-excursion | |
538 | (set-buffer rmail-buffer) | |
539 | (rmail-next-labeled-message n labels) | |
540 | (setq msg rmail-current-message)) | |
541 | (rmail-summary-goto-msg msg))) | |
d41d75fb RS |
542 | |
543 | (defun rmail-summary-previous-labeled-message (n labels) | |
689421a9 | 544 | "Show previous message with LABELS. Defaults to last labels used. |
d41d75fb RS |
545 | With prefix argument N moves backward N messages with these labels." |
546 | (interactive "p\nsMove to previous msg with labels: ") | |
d69006df KH |
547 | (let (msg) |
548 | (save-excursion | |
549 | (set-buffer rmail-buffer) | |
550 | (rmail-previous-labeled-message n labels) | |
551 | (setq msg rmail-current-message)) | |
552 | (rmail-summary-goto-msg msg))) | |
71d97b56 RS |
553 | |
554 | (defun rmail-summary-next-same-subject (n) | |
555 | "Go to the next message in the summary having the same subject. | |
556 | With prefix argument N, do this N times. | |
557 | If N is negative, go backwards." | |
558 | (interactive "p") | |
559 | (let (subject search-regexp i found | |
560 | (forward (> n 0))) | |
561 | (save-excursion | |
562 | (set-buffer rmail-buffer) | |
563 | (setq subject (mail-fetch-field "Subject")) | |
71d97b56 RS |
564 | (setq i rmail-current-message)) |
565 | (if (string-match "Re:[ \t]*" subject) | |
566 | (setq subject (substring subject (match-end 0)))) | |
5be36e20 RS |
567 | (setq search-regexp (concat "^Subject: *\\(Re: *\\)?" |
568 | (regexp-quote subject) | |
569 | "\n")) | |
71d97b56 RS |
570 | (save-excursion |
571 | (while (and (/= n 0) | |
572 | (if forward | |
573 | (not (eobp)) | |
574 | (not (bobp)))) | |
575 | (let (done) | |
576 | (while (and (not done) | |
577 | (if forward | |
578 | (not (eobp)) | |
579 | (not (bobp)))) | |
580 | ;; Advance thru summary. | |
581 | (forward-line (if forward 1 -1)) | |
582 | ;; Get msg number of this line. | |
027a4b6b | 583 | (setq i (string-to-number |
71d97b56 | 584 | (buffer-substring (point) |
7271daf7 | 585 | (min (point-max) (+ 6 (point)))))) |
71d97b56 RS |
586 | ;; See if that msg has desired subject. |
587 | (save-excursion | |
588 | (set-buffer rmail-buffer) | |
589 | (save-restriction | |
590 | (widen) | |
591 | (goto-char (rmail-msgbeg i)) | |
592 | (search-forward "\n*** EOOH ***\n") | |
593 | (let ((beg (point)) end) | |
594 | (search-forward "\n\n") | |
595 | (setq end (point)) | |
596 | (goto-char beg) | |
597 | (setq done (re-search-forward search-regexp end t)))))) | |
598 | (if done (setq found i))) | |
599 | (setq n (if forward (1- n) (1+ n))))) | |
600 | (if found | |
601 | (rmail-summary-goto-msg found) | |
602 | (error "No %s message with same subject" | |
603 | (if forward "following" "previous"))))) | |
604 | ||
605 | (defun rmail-summary-previous-same-subject (n) | |
606 | "Go to the previous message in the summary having the same subject. | |
607 | With prefix argument N, do this N times. | |
608 | If N is negative, go forwards instead." | |
609 | (interactive "p") | |
610 | (rmail-summary-next-same-subject (- n))) | |
d41d75fb RS |
611 | \f |
612 | ;; Delete and undelete summary commands. | |
613 | ||
93cba994 | 614 | (defun rmail-summary-delete-forward (&optional count) |
d41d75fb RS |
615 | "Delete this message and move to next nondeleted one. |
616 | Deleted messages stay in the file until the \\[rmail-expunge] command is given. | |
93cba994 RS |
617 | A prefix argument serves as a repeat count; |
618 | a negative argument means to delete and move backward." | |
619 | (interactive "p") | |
ecb4dd9a | 620 | (unless (numberp count) (setq count 1)) |
93cba994 RS |
621 | (let (end del-msg |
622 | (backward (< count 0))) | |
623 | (while (/= count 0) | |
624 | (rmail-summary-goto-msg) | |
625 | (with-current-buffer rmail-buffer | |
626 | (rmail-delete-message) | |
627 | (setq del-msg rmail-current-message)) | |
92a38267 RS |
628 | (rmail-summary-mark-deleted del-msg) |
629 | (while (and (not (if backward (bobp) (eobp))) | |
94eeb96a | 630 | (save-excursion (beginning-of-line) |
7434015f | 631 | (looking-at " *[0-9]+D"))) |
cdbea8ca RS |
632 | (forward-line (if backward -1 1))) |
633 | ;; It looks ugly to move to the empty line at end of buffer. | |
634 | (and (eobp) (not backward) | |
93cba994 RS |
635 | (forward-line -1)) |
636 | (setq count | |
637 | (if (> count 0) (1- count) (1+ count)))))) | |
4d4d11cc | 638 | |
93cba994 | 639 | (defun rmail-summary-delete-backward (&optional count) |
d41d75fb | 640 | "Delete this message and move to previous nondeleted one. |
93cba994 RS |
641 | Deleted messages stay in the file until the \\[rmail-expunge] command is given. |
642 | A prefix argument serves as a repeat count; | |
643 | a negative argument means to delete and move forward." | |
644 | (interactive "p") | |
645 | (rmail-summary-delete-forward (- count))) | |
4d4d11cc | 646 | |
d41d75fb | 647 | (defun rmail-summary-mark-deleted (&optional n undel) |
85bd1ac6 | 648 | ;; Since third arg is t, this only alters the summary, not the Rmail buf. |
fedc33f7 RS |
649 | (and n (rmail-summary-goto-msg n t t)) |
650 | (or (eobp) | |
4fb6f90f | 651 | (not (overlay-get rmail-summary-overlay 'face)) |
fedc33f7 RS |
652 | (let ((buffer-read-only nil)) |
653 | (skip-chars-forward " ") | |
654 | (skip-chars-forward "[0-9]") | |
655 | (if undel | |
656 | (if (looking-at "D") | |
657 | (progn (delete-char 1) (insert " "))) | |
658 | (delete-char 1) | |
659 | (insert "D")))) | |
d41d75fb RS |
660 | (beginning-of-line)) |
661 | ||
662 | (defun rmail-summary-mark-undeleted (n) | |
663 | (rmail-summary-mark-deleted n t)) | |
664 | ||
665 | (defun rmail-summary-deleted-p (&optional n) | |
666 | (save-excursion | |
667 | (and n (rmail-summary-goto-msg n nil t)) | |
668 | (skip-chars-forward " ") | |
669 | (skip-chars-forward "[0-9]") | |
670 | (looking-at "D"))) | |
4d4d11cc | 671 | |
d41d75fb RS |
672 | (defun rmail-summary-undelete (&optional arg) |
673 | "Undelete current message. | |
674 | Optional prefix ARG means undelete ARG previous messages." | |
675 | (interactive "p") | |
676 | (if (/= arg 1) | |
677 | (rmail-summary-undelete-many arg) | |
5ed1243c RS |
678 | (let ((buffer-read-only nil) |
679 | (opoint (point))) | |
d41d75fb RS |
680 | (end-of-line) |
681 | (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t) | |
682 | (replace-match "\\1 ") | |
683 | (rmail-summary-goto-msg) | |
67f2e119 GM |
684 | (if rmail-enable-mime |
685 | (set-buffer rmail-buffer) | |
686 | (pop-to-buffer rmail-buffer)) | |
d41d75fb RS |
687 | (and (rmail-message-deleted-p rmail-current-message) |
688 | (rmail-undelete-previous-message)) | |
67f2e119 GM |
689 | (if rmail-enable-mime |
690 | (pop-to-buffer rmail-view-buffer)) | |
5ed1243c RS |
691 | (pop-to-buffer rmail-summary-buffer)) |
692 | (t (goto-char opoint)))))) | |
d41d75fb RS |
693 | |
694 | (defun rmail-summary-undelete-many (&optional n) | |
695 | "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs." | |
696 | (interactive "P") | |
697 | (save-excursion | |
698 | (set-buffer rmail-buffer) | |
699 | (let* ((init-msg (if n rmail-current-message rmail-total-messages)) | |
700 | (rmail-current-message init-msg) | |
701 | (n (or n rmail-total-messages)) | |
702 | (msgs-undeled 0)) | |
703 | (while (and (> rmail-current-message 0) | |
704 | (< msgs-undeled n)) | |
705 | (if (rmail-message-deleted-p rmail-current-message) | |
706 | (progn (rmail-set-attribute "deleted" nil) | |
707 | (setq msgs-undeled (1+ msgs-undeled)))) | |
708 | (setq rmail-current-message (1- rmail-current-message))) | |
709 | (set-buffer rmail-summary-buffer) | |
710 | (setq rmail-current-message init-msg msgs-undeled 0) | |
711 | (while (and (> rmail-current-message 0) | |
712 | (< msgs-undeled n)) | |
713 | (if (rmail-summary-deleted-p rmail-current-message) | |
714 | (progn (rmail-summary-mark-undeleted rmail-current-message) | |
715 | (setq msgs-undeled (1+ msgs-undeled)))) | |
716 | (setq rmail-current-message (1- rmail-current-message)))) | |
717 | (rmail-summary-goto-msg))) | |
718 | \f | |
4d4d11cc JB |
719 | ;; Rmail Summary mode is suitable only for specially formatted data. |
720 | (put 'rmail-summary-mode 'mode-class 'special) | |
721 | ||
722 | (defun rmail-summary-mode () | |
d41d75fb RS |
723 | "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary]. |
724 | As commands are issued in the summary buffer, they are applied to the | |
725 | corresponding mail messages in the rmail buffer. | |
726 | ||
727 | All normal editing commands are turned off. | |
9cd78473 RS |
728 | Instead, nearly all the Rmail mode commands are available, |
729 | though many of them move only among the messages in the summary. | |
d41d75fb | 730 | |
9cd78473 RS |
731 | These additional commands exist: |
732 | ||
733 | \\[rmail-summary-undelete-many] Undelete all or prefix arg deleted messages. | |
734 | \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer. | |
735 | ||
736 | Commands for sorting the summary: | |
737 | ||
738 | \\[rmail-summary-sort-by-date] Sort by date. | |
739 | \\[rmail-summary-sort-by-subject] Sort by subject. | |
740 | \\[rmail-summary-sort-by-author] Sort by author. | |
741 | \\[rmail-summary-sort-by-recipient] Sort by recipient. | |
742 | \\[rmail-summary-sort-by-correspondent] Sort by correspondent. | |
ebdf372b | 743 | \\[rmail-summary-sort-by-lines] Sort by lines. |
e15dbc43 | 744 | \\[rmail-summary-sort-by-labels] Sort by labels." |
4d4d11cc JB |
745 | (interactive) |
746 | (kill-all-local-variables) | |
4d4d11cc JB |
747 | (setq major-mode 'rmail-summary-mode) |
748 | (setq mode-name "RMAIL Summary") | |
4d4d11cc JB |
749 | (setq truncate-lines t) |
750 | (setq buffer-read-only t) | |
751 | (set-syntax-table text-mode-syntax-table) | |
d41d75fb | 752 | (make-local-variable 'rmail-buffer) |
db56d71e | 753 | (make-local-variable 'rmail-view-buffer) |
d41d75fb RS |
754 | (make-local-variable 'rmail-total-messages) |
755 | (make-local-variable 'rmail-current-message) | |
756 | (setq rmail-current-message nil) | |
757 | (make-local-variable 'rmail-summary-redo) | |
758 | (setq rmail-summary-redo nil) | |
759 | (make-local-variable 'revert-buffer-function) | |
d16df573 SM |
760 | (make-local-variable 'font-lock-defaults) |
761 | (setq font-lock-defaults '(rmail-summary-font-lock-keywords t)) | |
0732dfa5 | 762 | (rmail-summary-enable) |
4d4d11cc JB |
763 | (run-hooks 'rmail-summary-mode-hook)) |
764 | ||
0732dfa5 KH |
765 | ;; Summary features need to be disabled during edit mode. |
766 | (defun rmail-summary-disable () | |
56b25713 | 767 | (use-local-map text-mode-map) |
c28baa2a | 768 | (remove-hook 'post-command-hook 'rmail-summary-rmail-update t) |
56b25713 | 769 | (setq revert-buffer-function nil)) |
0732dfa5 KH |
770 | |
771 | (defun rmail-summary-enable () | |
56b25713 | 772 | (use-local-map rmail-summary-mode-map) |
c28baa2a | 773 | (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t) |
56b25713 | 774 | (setq revert-buffer-function 'rmail-update-summary)) |
0732dfa5 | 775 | |
5be36e20 RS |
776 | (defvar rmail-summary-put-back-unseen nil |
777 | "Used for communicating between calls to `rmail-summary-rmail-update'. | |
778 | If it moves to a message within an Incremental Search, and removes | |
779 | the `unseen' attribute from that message, it sets this flag | |
780 | so that if the next motion between messages is in the same Incremental | |
781 | Search, the `unseen' attribute is restored.") | |
782 | ||
bb694792 RS |
783 | ;; Show in Rmail the message described by the summary line that point is on, |
784 | ;; but only if the Rmail buffer is already visible. | |
d41d75fb RS |
785 | ;; This is a post-command-hook in summary buffers. |
786 | (defun rmail-summary-rmail-update () | |
10e09db4 KH |
787 | (let (buffer-read-only) |
788 | (save-excursion | |
789 | ;; If at end of buffer, pretend we are on the last text line. | |
790 | (if (eobp) | |
791 | (forward-line -1)) | |
792 | (beginning-of-line) | |
793 | (skip-chars-forward " ") | |
027a4b6b JB |
794 | (let ((msg-num (string-to-number (buffer-substring |
795 | (point) | |
796 | (progn (skip-chars-forward "0-9") | |
797 | (point)))))) | |
5be36e20 RS |
798 | ;; Always leave `unseen' removed |
799 | ;; if we get out of isearch mode. | |
800 | ;; Don't let a subsequent isearch restore that `unseen'. | |
801 | (if (not isearch-mode) | |
802 | (setq rmail-summary-put-back-unseen nil)) | |
803 | ||
10e09db4 | 804 | (or (eq rmail-current-message msg-num) |
8efaaf11 | 805 | (let ((window (get-buffer-window rmail-view-buffer t)) |
10e09db4 | 806 | (owin (selected-window))) |
5be36e20 RS |
807 | (if isearch-mode |
808 | (save-excursion | |
809 | (set-buffer rmail-buffer) | |
810 | ;; If we first saw the previous message in this search, | |
811 | ;; and we have gone to a different message while searching, | |
812 | ;; put back `unseen' on the former one. | |
1dbd9103 | 813 | (if rmail-summary-put-back-unseen |
c9aa3ef8 KH |
814 | (rmail-set-attribute "unseen" t |
815 | rmail-current-message)) | |
5be36e20 RS |
816 | ;; Arrange to do that later, for the new current message, |
817 | ;; if it still has `unseen'. | |
818 | (setq rmail-summary-put-back-unseen | |
819 | (rmail-message-labels-p msg-num ", ?\\(unseen\\),"))) | |
820 | (setq rmail-summary-put-back-unseen nil)) | |
821 | ||
822 | ;; Go to the desired message. | |
10e09db4 | 823 | (setq rmail-current-message msg-num) |
5be36e20 RS |
824 | |
825 | ;; Update the summary to show the message has been seen. | |
10e09db4 KH |
826 | (if (= (following-char) ?-) |
827 | (progn | |
828 | (delete-char 1) | |
829 | (insert " "))) | |
5be36e20 | 830 | |
10e09db4 KH |
831 | (if window |
832 | ;; Using save-window-excursion would cause the new value | |
980d43b6 RS |
833 | ;; of point to get lost. |
834 | (unwind-protect | |
835 | (progn | |
836 | (select-window window) | |
bc454f08 | 837 | (rmail-show-message msg-num t)) |
10e09db4 | 838 | (select-window owin)) |
dca46072 RS |
839 | (if (buffer-name rmail-buffer) |
840 | (save-excursion | |
841 | (set-buffer rmail-buffer) | |
4fb6f90f RS |
842 | (rmail-show-message msg-num t)))))) |
843 | (rmail-summary-update-highlight nil))))) | |
d41d75fb RS |
844 | \f |
845 | (defvar rmail-summary-mode-map nil) | |
846 | ||
847 | (if rmail-summary-mode-map | |
848 | nil | |
849 | (setq rmail-summary-mode-map (make-keymap)) | |
850 | (suppress-keymap rmail-summary-mode-map) | |
4ab455e6 RS |
851 | |
852 | (define-key rmail-summary-mode-map [mouse-2] 'rmail-summary-mouse-goto-message) | |
d41d75fb | 853 | (define-key rmail-summary-mode-map "a" 'rmail-summary-add-label) |
00f3d57d | 854 | (define-key rmail-summary-mode-map "b" 'rmail-summary-bury) |
d41d75fb RS |
855 | (define-key rmail-summary-mode-map "c" 'rmail-summary-continue) |
856 | (define-key rmail-summary-mode-map "d" 'rmail-summary-delete-forward) | |
857 | (define-key rmail-summary-mode-map "\C-d" 'rmail-summary-delete-backward) | |
858 | (define-key rmail-summary-mode-map "e" 'rmail-summary-edit-current-message) | |
859 | (define-key rmail-summary-mode-map "f" 'rmail-summary-forward) | |
860 | (define-key rmail-summary-mode-map "g" 'rmail-summary-get-new-mail) | |
861 | (define-key rmail-summary-mode-map "h" 'rmail-summary) | |
862 | (define-key rmail-summary-mode-map "i" 'rmail-summary-input) | |
863 | (define-key rmail-summary-mode-map "j" 'rmail-summary-goto-msg) | |
6d6c336c | 864 | (define-key rmail-summary-mode-map "\C-m" 'rmail-summary-goto-msg) |
d41d75fb RS |
865 | (define-key rmail-summary-mode-map "k" 'rmail-summary-kill-label) |
866 | (define-key rmail-summary-mode-map "l" 'rmail-summary-by-labels) | |
867 | (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary) | |
868 | (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels) | |
869 | (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients) | |
870 | (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp) | |
871 | (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic) | |
872 | (define-key rmail-summary-mode-map "m" 'rmail-summary-mail) | |
873 | (define-key rmail-summary-mode-map "\M-m" 'rmail-summary-retry-failure) | |
874 | (define-key rmail-summary-mode-map "n" 'rmail-summary-next-msg) | |
d41d75fb RS |
875 | (define-key rmail-summary-mode-map "\en" 'rmail-summary-next-all) |
876 | (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message) | |
877 | (define-key rmail-summary-mode-map "o" 'rmail-summary-output-to-rmail-file) | |
878 | (define-key rmail-summary-mode-map "\C-o" 'rmail-summary-output) | |
879 | (define-key rmail-summary-mode-map "p" 'rmail-summary-previous-msg) | |
d41d75fb RS |
880 | (define-key rmail-summary-mode-map "\ep" 'rmail-summary-previous-all) |
881 | (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message) | |
882 | (define-key rmail-summary-mode-map "q" 'rmail-summary-quit) | |
d5bafc55 | 883 | (define-key rmail-summary-mode-map "Q" 'rmail-summary-wipe) |
d41d75fb RS |
884 | (define-key rmail-summary-mode-map "r" 'rmail-summary-reply) |
885 | (define-key rmail-summary-mode-map "s" 'rmail-summary-expunge-and-save) | |
886 | (define-key rmail-summary-mode-map "\es" 'rmail-summary-search) | |
887 | (define-key rmail-summary-mode-map "t" 'rmail-summary-toggle-header) | |
888 | (define-key rmail-summary-mode-map "u" 'rmail-summary-undelete) | |
889 | (define-key rmail-summary-mode-map "\M-u" 'rmail-summary-undelete-many) | |
d41d75fb | 890 | (define-key rmail-summary-mode-map "x" 'rmail-summary-expunge) |
d5bafc55 | 891 | (define-key rmail-summary-mode-map "w" 'rmail-summary-output-body) |
d41d75fb RS |
892 | (define-key rmail-summary-mode-map "." 'rmail-summary-beginning-of-message) |
893 | (define-key rmail-summary-mode-map "<" 'rmail-summary-first-message) | |
894 | (define-key rmail-summary-mode-map ">" 'rmail-summary-last-message) | |
895 | (define-key rmail-summary-mode-map " " 'rmail-summary-scroll-msg-up) | |
896 | (define-key rmail-summary-mode-map "\177" 'rmail-summary-scroll-msg-down) | |
897 | (define-key rmail-summary-mode-map "?" 'describe-mode) | |
71d97b56 RS |
898 | (define-key rmail-summary-mode-map "\C-c\C-n" 'rmail-summary-next-same-subject) |
899 | (define-key rmail-summary-mode-map "\C-c\C-p" 'rmail-summary-previous-same-subject) | |
e45fce03 RS |
900 | (define-key rmail-summary-mode-map "\C-c\C-s\C-d" |
901 | 'rmail-summary-sort-by-date) | |
902 | (define-key rmail-summary-mode-map "\C-c\C-s\C-s" | |
903 | 'rmail-summary-sort-by-subject) | |
904 | (define-key rmail-summary-mode-map "\C-c\C-s\C-a" | |
905 | 'rmail-summary-sort-by-author) | |
906 | (define-key rmail-summary-mode-map "\C-c\C-s\C-r" | |
907 | 'rmail-summary-sort-by-recipient) | |
908 | (define-key rmail-summary-mode-map "\C-c\C-s\C-c" | |
909 | 'rmail-summary-sort-by-correspondent) | |
910 | (define-key rmail-summary-mode-map "\C-c\C-s\C-l" | |
911 | 'rmail-summary-sort-by-lines) | |
ebdf372b | 912 | (define-key rmail-summary-mode-map "\C-c\C-s\C-k" |
e15dbc43 | 913 | 'rmail-summary-sort-by-labels) |
d41d75fb RS |
914 | ) |
915 | \f | |
e7a00c25 RS |
916 | ;;; Menu bar bindings. |
917 | ||
918 | (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap)) | |
919 | ||
920 | (define-key rmail-summary-mode-map [menu-bar classify] | |
921 | (cons "Classify" (make-sparse-keymap "Classify"))) | |
922 | ||
dca46072 RS |
923 | (define-key rmail-summary-mode-map [menu-bar classify output-menu] |
924 | '("Output (Rmail Menu)..." . rmail-summary-output-menu)) | |
925 | ||
926 | (define-key rmail-summary-mode-map [menu-bar classify input-menu] | |
0e520d74 | 927 | '("Input Rmail File (menu)..." . rmail-input-menu)) |
dca46072 | 928 | |
aa138cb4 RS |
929 | (define-key rmail-summary-mode-map [menu-bar classify input-menu] |
930 | '(nil)) | |
931 | ||
932 | (define-key rmail-summary-mode-map [menu-bar classify output-menu] | |
933 | '(nil)) | |
934 | ||
d5bafc55 RS |
935 | (define-key rmail-summary-mode-map [menu-bar classify output-body] |
936 | '("Output (body)..." . rmail-summary-output-body)) | |
937 | ||
e7a00c25 | 938 | (define-key rmail-summary-mode-map [menu-bar classify output-inbox] |
29e6129e | 939 | '("Output (inbox)..." . rmail-summary-output)) |
e7a00c25 RS |
940 | |
941 | (define-key rmail-summary-mode-map [menu-bar classify output] | |
29e6129e | 942 | '("Output (Rmail)..." . rmail-summary-output-to-rmail-file)) |
e7a00c25 RS |
943 | |
944 | (define-key rmail-summary-mode-map [menu-bar classify kill-label] | |
29e6129e | 945 | '("Kill Label..." . rmail-summary-kill-label)) |
e7a00c25 RS |
946 | |
947 | (define-key rmail-summary-mode-map [menu-bar classify add-label] | |
29e6129e | 948 | '("Add Label..." . rmail-summary-add-label)) |
e7a00c25 RS |
949 | |
950 | (define-key rmail-summary-mode-map [menu-bar summary] | |
951 | (cons "Summary" (make-sparse-keymap "Summary"))) | |
952 | ||
c1046d18 RS |
953 | (define-key rmail-summary-mode-map [menu-bar summary senders] |
954 | '("By Senders..." . rmail-summary-by-senders)) | |
955 | ||
e7a00c25 | 956 | (define-key rmail-summary-mode-map [menu-bar summary labels] |
29e6129e | 957 | '("By Labels..." . rmail-summary-by-labels)) |
e7a00c25 RS |
958 | |
959 | (define-key rmail-summary-mode-map [menu-bar summary recipients] | |
29e6129e | 960 | '("By Recipients..." . rmail-summary-by-recipients)) |
e7a00c25 RS |
961 | |
962 | (define-key rmail-summary-mode-map [menu-bar summary topic] | |
29e6129e | 963 | '("By Topic..." . rmail-summary-by-topic)) |
e7a00c25 RS |
964 | |
965 | (define-key rmail-summary-mode-map [menu-bar summary regexp] | |
29e6129e | 966 | '("By Regexp..." . rmail-summary-by-regexp)) |
e7a00c25 RS |
967 | |
968 | (define-key rmail-summary-mode-map [menu-bar summary all] | |
969 | '("All" . rmail-summary)) | |
970 | ||
971 | (define-key rmail-summary-mode-map [menu-bar mail] | |
972 | (cons "Mail" (make-sparse-keymap "Mail"))) | |
973 | ||
e76bca6c | 974 | (define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail] |
b0d3522a RS |
975 | '("Get New Mail" . rmail-summary-get-new-mail)) |
976 | ||
c0d133a6 | 977 | (define-key rmail-summary-mode-map [menu-bar mail lambda] |
b0d3522a | 978 | '("----")) |
aba6cc35 | 979 | |
e7a00c25 RS |
980 | (define-key rmail-summary-mode-map [menu-bar mail continue] |
981 | '("Continue" . rmail-summary-continue)) | |
982 | ||
b0d3522a | 983 | (define-key rmail-summary-mode-map [menu-bar mail resend] |
4986bd38 | 984 | '("Re-send..." . rmail-summary-resend)) |
b0d3522a | 985 | |
e7a00c25 RS |
986 | (define-key rmail-summary-mode-map [menu-bar mail forward] |
987 | '("Forward" . rmail-summary-forward)) | |
988 | ||
989 | (define-key rmail-summary-mode-map [menu-bar mail retry] | |
990 | '("Retry" . rmail-summary-retry-failure)) | |
991 | ||
992 | (define-key rmail-summary-mode-map [menu-bar mail reply] | |
993 | '("Reply" . rmail-summary-reply)) | |
994 | ||
995 | (define-key rmail-summary-mode-map [menu-bar mail mail] | |
996 | '("Mail" . rmail-summary-mail)) | |
997 | ||
998 | (define-key rmail-summary-mode-map [menu-bar delete] | |
999 | (cons "Delete" (make-sparse-keymap "Delete"))) | |
1000 | ||
1001 | (define-key rmail-summary-mode-map [menu-bar delete expunge/save] | |
1002 | '("Expunge/Save" . rmail-summary-expunge-and-save)) | |
1003 | ||
1004 | (define-key rmail-summary-mode-map [menu-bar delete expunge] | |
1005 | '("Expunge" . rmail-summary-expunge)) | |
1006 | ||
1007 | (define-key rmail-summary-mode-map [menu-bar delete undelete] | |
1008 | '("Undelete" . rmail-summary-undelete)) | |
1009 | ||
1010 | (define-key rmail-summary-mode-map [menu-bar delete delete] | |
1011 | '("Delete" . rmail-summary-delete-forward)) | |
1012 | ||
1013 | (define-key rmail-summary-mode-map [menu-bar move] | |
1014 | (cons "Move" (make-sparse-keymap "Move"))) | |
1015 | ||
1016 | (define-key rmail-summary-mode-map [menu-bar move search-back] | |
29e6129e | 1017 | '("Search Back..." . rmail-summary-search-backward)) |
e7a00c25 RS |
1018 | |
1019 | (define-key rmail-summary-mode-map [menu-bar move search] | |
29e6129e | 1020 | '("Search..." . rmail-summary-search)) |
e7a00c25 RS |
1021 | |
1022 | (define-key rmail-summary-mode-map [menu-bar move previous] | |
1023 | '("Previous Nondeleted" . rmail-summary-previous-msg)) | |
1024 | ||
1025 | (define-key rmail-summary-mode-map [menu-bar move next] | |
1026 | '("Next Nondeleted" . rmail-summary-next-msg)) | |
1027 | ||
1028 | (define-key rmail-summary-mode-map [menu-bar move last] | |
1029 | '("Last" . rmail-summary-last-message)) | |
1030 | ||
1031 | (define-key rmail-summary-mode-map [menu-bar move first] | |
1032 | '("First" . rmail-summary-first-message)) | |
1033 | ||
1034 | (define-key rmail-summary-mode-map [menu-bar move previous] | |
1035 | '("Previous" . rmail-summary-previous-all)) | |
1036 | ||
1037 | (define-key rmail-summary-mode-map [menu-bar move next] | |
1038 | '("Next" . rmail-summary-next-all)) | |
1039 | \f | |
4197af8a | 1040 | (defvar rmail-summary-overlay nil) |
212daf13 | 1041 | (put 'rmail-summary-overlay 'permanent-local t) |
4197af8a | 1042 | |
4ab455e6 RS |
1043 | (defun rmail-summary-mouse-goto-message (event) |
1044 | "Select the message whose summary line you click on." | |
1045 | (interactive "@e") | |
1046 | (goto-char (posn-point (event-end event))) | |
1047 | (rmail-summary-goto-msg)) | |
85bd1ac6 | 1048 | |
d41d75fb | 1049 | (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail) |
4ab455e6 RS |
1050 | "Go to message N in the summary buffer and the Rmail buffer. |
1051 | If N is nil, use the message corresponding to point in the summary | |
1052 | and move to that message in the Rmail buffer. | |
1053 | ||
1054 | If NOWARN, don't say anything if N is out of range. | |
1055 | If SKIP-RMAIL, don't do anything to the Rmail buffer." | |
4d4d11cc JB |
1056 | (interactive "P") |
1057 | (if (consp n) (setq n (prefix-numeric-value n))) | |
1058 | (if (eobp) (forward-line -1)) | |
1059 | (beginning-of-line) | |
132ad564 RS |
1060 | (let* ((obuf (current-buffer)) |
1061 | (buf rmail-buffer) | |
1062 | (cur (point)) | |
1063 | message-not-found | |
027a4b6b | 1064 | (curmsg (string-to-number |
132ad564 | 1065 | (buffer-substring (point) |
7271daf7 | 1066 | (min (point-max) (+ 6 (point)))))) |
132ad564 | 1067 | (total (save-excursion (set-buffer buf) rmail-total-messages))) |
4197af8a RS |
1068 | ;; If message number N was specified, find that message's line |
1069 | ;; or set message-not-found. | |
1070 | ;; If N wasn't specified or that message can't be found. | |
1071 | ;; set N by default. | |
4d4d11cc JB |
1072 | (if (not n) |
1073 | (setq n curmsg) | |
1074 | (if (< n 1) | |
1075 | (progn (message "No preceding message") | |
1076 | (setq n 1))) | |
867bae0b EZ |
1077 | (if (and (> n total) |
1078 | (> total 0)) | |
4d4d11cc JB |
1079 | (progn (message "No following message") |
1080 | (goto-char (point-max)) | |
85bd1ac6 | 1081 | (rmail-summary-goto-msg nil nowarn skip-rmail))) |
4d4d11cc | 1082 | (goto-char (point-min)) |
7271daf7 | 1083 | (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t)) |
4d4d11cc JB |
1084 | (progn (or nowarn (message "Message %d not found" n)) |
1085 | (setq n curmsg) | |
4197af8a | 1086 | (setq message-not-found t) |
4d4d11cc JB |
1087 | (goto-char cur)))) |
1088 | (beginning-of-line) | |
1089 | (skip-chars-forward " ") | |
1090 | (skip-chars-forward "0-9") | |
1091 | (save-excursion (if (= (following-char) ?-) | |
1092 | (let ((buffer-read-only nil)) | |
1093 | (delete-char 1) | |
1094 | (insert " ")))) | |
4fb6f90f | 1095 | (rmail-summary-update-highlight message-not-found) |
4d4d11cc | 1096 | (beginning-of-line) |
d41d75fb RS |
1097 | (if skip-rmail |
1098 | nil | |
857ff384 RS |
1099 | (let ((selwin (selected-window))) |
1100 | (unwind-protect | |
1101 | (progn (pop-to-buffer buf) | |
1102 | (rmail-show-message n)) | |
c7b5ca27 RS |
1103 | (select-window selwin) |
1104 | ;; The actions above can alter the current buffer. Preserve it. | |
1105 | (set-buffer obuf)))))) | |
4fb6f90f RS |
1106 | |
1107 | ;; Update the highlighted line in an rmail summary buffer. | |
1108 | ;; That should be current. We highlight the line point is on. | |
1109 | ;; If NOT-FOUND is non-nil, we turn off highlighting. | |
1110 | (defun rmail-summary-update-highlight (not-found) | |
1111 | ;; Make sure we have an overlay to use. | |
1112 | (or rmail-summary-overlay | |
1113 | (progn | |
1114 | (make-local-variable 'rmail-summary-overlay) | |
1115 | (setq rmail-summary-overlay (make-overlay (point) (point))))) | |
1116 | ;; If this message is in the summary, use the overlay to highlight it. | |
1117 | ;; Otherwise, don't highlight anything. | |
1118 | (if not-found | |
1119 | (overlay-put rmail-summary-overlay 'face nil) | |
1120 | (move-overlay rmail-summary-overlay | |
1121 | (save-excursion (beginning-of-line) | |
1122 | (skip-chars-forward " ") | |
1123 | (point)) | |
1124 | (save-excursion (end-of-line) (point))) | |
1125 | (overlay-put rmail-summary-overlay 'face 'highlight))) | |
d41d75fb | 1126 | \f |
4d4d11cc | 1127 | (defun rmail-summary-scroll-msg-up (&optional dist) |
3753ab6f RS |
1128 | "Scroll the Rmail window forward. |
1129 | If the Rmail window is displaying the end of a message, | |
1130 | advance to the next message." | |
4d4d11cc | 1131 | (interactive "P") |
3753ab6f RS |
1132 | (if (eq dist '-) |
1133 | (rmail-summary-scroll-msg-down nil) | |
db56d71e | 1134 | (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer))) |
3753ab6f RS |
1135 | (if rmail-buffer-window |
1136 | (if (let ((rmail-summary-window (selected-window))) | |
1137 | (select-window rmail-buffer-window) | |
1138 | (prog1 | |
1139 | ;; Is EOB visible in the buffer? | |
1140 | (save-excursion | |
1141 | (let ((ht (window-height (selected-window)))) | |
1142 | (move-to-window-line (- ht 2)) | |
1143 | (end-of-line) | |
1144 | (eobp))) | |
1145 | (select-window rmail-summary-window))) | |
be2e861f RS |
1146 | (if (not rmail-summary-scroll-between-messages) |
1147 | (error "End of buffer") | |
1148 | (rmail-summary-next-msg (or dist 1))) | |
db56d71e | 1149 | (let ((other-window-scroll-buffer rmail-view-buffer)) |
3753ab6f | 1150 | (scroll-other-window dist))) |
37eb1878 RS |
1151 | ;; If it isn't visible at all, show the beginning. |
1152 | (rmail-summary-beginning-of-message))))) | |
4d4d11cc JB |
1153 | |
1154 | (defun rmail-summary-scroll-msg-down (&optional dist) | |
3753ab6f | 1155 | "Scroll the Rmail window backward. |
37eb1878 RS |
1156 | If the Rmail window is now displaying the beginning of a message, |
1157 | move to the previous message." | |
4d4d11cc | 1158 | (interactive "P") |
3753ab6f RS |
1159 | (if (eq dist '-) |
1160 | (rmail-summary-scroll-msg-up nil) | |
67f2e119 | 1161 | (let ((rmail-buffer-window (get-buffer-window rmail-view-buffer))) |
3753ab6f RS |
1162 | (if rmail-buffer-window |
1163 | (if (let ((rmail-summary-window (selected-window))) | |
1164 | (select-window rmail-buffer-window) | |
1165 | (prog1 | |
1166 | ;; Is BOB visible in the buffer? | |
1167 | (save-excursion | |
1168 | (move-to-window-line 0) | |
1169 | (beginning-of-line) | |
1170 | (bobp)) | |
1171 | (select-window rmail-summary-window))) | |
be2e861f RS |
1172 | (if (not rmail-summary-scroll-between-messages) |
1173 | (error "Beginning of buffer") | |
1174 | (rmail-summary-previous-msg (or dist 1))) | |
67f2e119 | 1175 | (let ((other-window-scroll-buffer rmail-view-buffer)) |
3753ab6f | 1176 | (scroll-other-window-down dist))) |
37eb1878 RS |
1177 | ;; If it isn't visible at all, show the beginning. |
1178 | (rmail-summary-beginning-of-message))))) | |
d41d75fb RS |
1179 | |
1180 | (defun rmail-summary-beginning-of-message () | |
1181 | "Show current message from the beginning." | |
1182 | (interactive) | |
37eb1878 RS |
1183 | (if (and (one-window-p) (not pop-up-frames)) |
1184 | ;; If there is just one window, put the summary on the top. | |
67f2e119 | 1185 | (let ((buffer rmail-view-buffer)) |
37eb1878 RS |
1186 | (split-window (selected-window) rmail-summary-window-size) |
1187 | (select-window (frame-first-window)) | |
67f2e119 | 1188 | (pop-to-buffer rmail-view-buffer) |
37eb1878 RS |
1189 | ;; If pop-to-buffer did not use that window, delete that |
1190 | ;; window. (This can happen if it uses another frame.) | |
1191 | (or (eq buffer (window-buffer (next-window (frame-first-window)))) | |
1192 | (delete-other-windows))) | |
67f2e119 | 1193 | (pop-to-buffer rmail-view-buffer)) |
d41d75fb RS |
1194 | (beginning-of-buffer) |
1195 | (pop-to-buffer rmail-summary-buffer)) | |
4d4d11cc | 1196 | |
00f3d57d RS |
1197 | (defun rmail-summary-bury () |
1198 | "Bury the Rmail buffer and the Rmail summary buffer." | |
1199 | (interactive) | |
1200 | (let ((buffer-to-bury (current-buffer))) | |
1201 | (let (window) | |
1202 | (while (setq window (get-buffer-window rmail-buffer)) | |
1203 | (set-window-buffer window (other-buffer rmail-buffer))) | |
1204 | (bury-buffer rmail-buffer)) | |
1205 | (switch-to-buffer (other-buffer buffer-to-bury)) | |
1206 | (bury-buffer buffer-to-bury))) | |
1207 | ||
4d4d11cc | 1208 | (defun rmail-summary-quit () |
d41d75fb | 1209 | "Quit out of Rmail and Rmail summary." |
4d4d11cc | 1210 | (interactive) |
d41d75fb | 1211 | (rmail-summary-wipe) |
4d4d11cc JB |
1212 | (rmail-quit)) |
1213 | ||
d41d75fb RS |
1214 | (defun rmail-summary-wipe () |
1215 | "Kill and wipe away Rmail summary, remaining within Rmail." | |
4d4d11cc | 1216 | (interactive) |
d41d75fb | 1217 | (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil)) |
67f2e119 | 1218 | (let ((local-rmail-buffer rmail-view-buffer)) |
d41d75fb RS |
1219 | (kill-buffer (current-buffer)) |
1220 | ;; Delete window if not only one. | |
1221 | (if (not (eq (selected-window) (next-window nil 'no-minibuf))) | |
1222 | (delete-window)) | |
9cd78473 RS |
1223 | ;; Switch windows to the rmail buffer, or switch to it in this window. |
1224 | (pop-to-buffer local-rmail-buffer))) | |
d41d75fb RS |
1225 | |
1226 | (defun rmail-summary-expunge () | |
1227 | "Actually erase all deleted messages and recompute summary headers." | |
1228 | (interactive) | |
1229 | (save-excursion | |
1230 | (set-buffer rmail-buffer) | |
09cefa66 | 1231 | (when (rmail-expunge-confirmed) |
d2bf5afe | 1232 | (rmail-only-expunge))) |
d41d75fb RS |
1233 | (rmail-update-summary)) |
1234 | ||
1235 | (defun rmail-summary-expunge-and-save () | |
1236 | "Expunge and save RMAIL file." | |
1237 | (interactive) | |
1238 | (save-excursion | |
1239 | (set-buffer rmail-buffer) | |
09cefa66 | 1240 | (when (rmail-expunge-confirmed) |
d2bf5afe | 1241 | (rmail-only-expunge))) |
b37767e7 RS |
1242 | (rmail-update-summary) |
1243 | (save-excursion | |
980d43b6 | 1244 | (set-buffer rmail-buffer) |
ccc341de KH |
1245 | (save-buffer)) |
1246 | (set-buffer-modified-p nil)) | |
d41d75fb | 1247 | |
3198a3d5 RS |
1248 | (defun rmail-summary-get-new-mail (&optional file-name) |
1249 | "Get new mail and recompute summary headers. | |
1250 | ||
1251 | Optionally you can specify the file to get new mail from. In this case, | |
1252 | the file of new mail is not changed or deleted. Noninteractively, you can | |
1253 | pass the inbox file name as an argument. Interactively, a prefix | |
1254 | argument says to read a file name and use that file as the inbox." | |
1255 | (interactive | |
1256 | (list (if current-prefix-arg | |
1257 | (read-file-name "Get new mail from file: ")))) | |
b37767e7 RS |
1258 | (let (msg) |
1259 | (save-excursion | |
1260 | (set-buffer rmail-buffer) | |
3198a3d5 | 1261 | (rmail-get-new-mail file-name) |
b37767e7 RS |
1262 | ;; Get the proper new message number. |
1263 | (setq msg rmail-current-message)) | |
1264 | ;; Make sure that message is displayed. | |
8d908f84 RS |
1265 | (or (zerop msg) |
1266 | (rmail-summary-goto-msg msg)))) | |
d41d75fb RS |
1267 | |
1268 | (defun rmail-summary-input (filename) | |
1269 | "Run Rmail on file FILENAME." | |
1270 | (interactive "FRun rmail on RMAIL file: ") | |
b37767e7 RS |
1271 | ;; We switch windows here, then display the other Rmail file there. |
1272 | (pop-to-buffer rmail-buffer) | |
1273 | (rmail filename)) | |
d41d75fb RS |
1274 | |
1275 | (defun rmail-summary-first-message () | |
1276 | "Show first message in Rmail file from summary buffer." | |
1277 | (interactive) | |
1278 | (beginning-of-buffer)) | |
1279 | ||
1280 | (defun rmail-summary-last-message () | |
1281 | "Show last message in Rmail file from summary buffer." | |
1282 | (interactive) | |
1283 | (end-of-buffer) | |
1284 | (forward-line -1)) | |
1285 | ||
1286 | (defvar rmail-summary-edit-map nil) | |
1287 | (if rmail-summary-edit-map | |
1288 | nil | |
1289 | (setq rmail-summary-edit-map | |
ae06ea79 | 1290 | (nconc (make-sparse-keymap) text-mode-map)) |
d41d75fb RS |
1291 | (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit) |
1292 | (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit)) | |
1293 | ||
1294 | (defun rmail-summary-edit-current-message () | |
1295 | "Edit the contents of this message." | |
1296 | (interactive) | |
1297 | (pop-to-buffer rmail-buffer) | |
1298 | (rmail-edit-current-message) | |
1299 | (use-local-map rmail-summary-edit-map)) | |
1300 | ||
1301 | (defun rmail-summary-cease-edit () | |
1302 | "Finish editing message, then go back to Rmail summary buffer." | |
1303 | (interactive) | |
1304 | (rmail-cease-edit) | |
1305 | (pop-to-buffer rmail-summary-buffer)) | |
1306 | ||
1307 | (defun rmail-summary-abort-edit () | |
1308 | "Abort edit of current message; restore original contents. | |
1309 | Go back to summary buffer." | |
1310 | (interactive) | |
1311 | (rmail-abort-edit) | |
1312 | (pop-to-buffer rmail-summary-buffer)) | |
1313 | ||
e7a00c25 RS |
1314 | (defun rmail-summary-search-backward (regexp &optional n) |
1315 | "Show message containing next match for REGEXP. | |
1316 | Prefix argument gives repeat count; negative argument means search | |
1317 | backwards (through earlier messages). | |
1318 | Interactively, empty argument means use same regexp used last time." | |
1319 | (interactive | |
1320 | (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0)) | |
1321 | (prompt | |
1322 | (concat (if reversep "Reverse " "") "Rmail search (regexp): ")) | |
1323 | regexp) | |
1324 | (if rmail-search-last-regexp | |
1325 | (setq prompt (concat prompt | |
1326 | "(default " | |
1327 | rmail-search-last-regexp | |
1328 | ") "))) | |
1329 | (setq regexp (read-string prompt)) | |
1330 | (cond ((not (equal regexp "")) | |
1331 | (setq rmail-search-last-regexp regexp)) | |
1332 | ((not rmail-search-last-regexp) | |
1333 | (error "No previous Rmail search string"))) | |
1334 | (list rmail-search-last-regexp | |
1335 | (prefix-numeric-value current-prefix-arg)))) | |
1336 | ;; Don't use save-excursion because that prevents point from moving | |
1337 | ;; properly in the summary buffer. | |
1338 | (let ((buffer (current-buffer))) | |
1339 | (unwind-protect | |
1340 | (progn | |
1341 | (set-buffer rmail-buffer) | |
1342 | (rmail-search regexp (- n))) | |
1343 | (set-buffer buffer)))) | |
1344 | ||
d41d75fb RS |
1345 | (defun rmail-summary-search (regexp &optional n) |
1346 | "Show message containing next match for REGEXP. | |
1347 | Prefix argument gives repeat count; negative argument means search | |
1348 | backwards (through earlier messages). | |
1349 | Interactively, empty argument means use same regexp used last time." | |
1350 | (interactive | |
1351 | (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0)) | |
1352 | (prompt | |
1353 | (concat (if reversep "Reverse " "") "Rmail search (regexp): ")) | |
1354 | regexp) | |
1355 | (if rmail-search-last-regexp | |
1356 | (setq prompt (concat prompt | |
1357 | "(default " | |
1358 | rmail-search-last-regexp | |
1359 | ") "))) | |
1360 | (setq regexp (read-string prompt)) | |
1361 | (cond ((not (equal regexp "")) | |
1362 | (setq rmail-search-last-regexp regexp)) | |
1363 | ((not rmail-search-last-regexp) | |
1364 | (error "No previous Rmail search string"))) | |
1365 | (list rmail-search-last-regexp | |
1366 | (prefix-numeric-value current-prefix-arg)))) | |
e7a00c25 RS |
1367 | ;; Don't use save-excursion because that prevents point from moving |
1368 | ;; properly in the summary buffer. | |
1369 | (let ((buffer (current-buffer))) | |
1370 | (unwind-protect | |
1371 | (progn | |
1372 | (set-buffer rmail-buffer) | |
1373 | (rmail-search regexp n)) | |
1374 | (set-buffer buffer)))) | |
d41d75fb RS |
1375 | |
1376 | (defun rmail-summary-toggle-header () | |
1377 | "Show original message header if pruned header currently shown, or vice versa." | |
1378 | (interactive) | |
67f2e119 | 1379 | (save-window-excursion |
d41d75fb | 1380 | (set-buffer rmail-buffer) |
387f203c RS |
1381 | (rmail-toggle-header)) |
1382 | ;; Inside save-excursion, some changes to point in the RMAIL buffer are lost. | |
1383 | ;; Set point to point-min in the RMAIL buffer, if it is visible. | |
67f2e119 | 1384 | (let ((window (get-buffer-window rmail-view-buffer))) |
387f203c RS |
1385 | (if window |
1386 | ;; Using save-window-excursion would lose the new value of point. | |
1387 | (let ((owin (selected-window))) | |
1388 | (unwind-protect | |
1389 | (progn | |
1390 | (select-window window) | |
1391 | (goto-char (point-min))) | |
1392 | (select-window owin)))))) | |
1393 | ||
d41d75fb RS |
1394 | |
1395 | (defun rmail-summary-add-label (label) | |
1396 | "Add LABEL to labels associated with current Rmail message. | |
1397 | Completion is performed over known labels when reading." | |
980d43b6 RS |
1398 | (interactive (list (save-excursion |
1399 | (set-buffer rmail-buffer) | |
1400 | (rmail-read-label "Add label")))) | |
d41d75fb RS |
1401 | (save-excursion |
1402 | (set-buffer rmail-buffer) | |
1403 | (rmail-add-label label))) | |
1404 | ||
1405 | (defun rmail-summary-kill-label (label) | |
1406 | "Remove LABEL from labels associated with current Rmail message. | |
1407 | Completion is performed over known labels when reading." | |
980d43b6 RS |
1408 | (interactive (list (save-excursion |
1409 | (set-buffer rmail-buffer) | |
1410 | (rmail-read-label "Kill label")))) | |
d41d75fb RS |
1411 | (save-excursion |
1412 | (set-buffer rmail-buffer) | |
1413 | (rmail-set-label label nil))) | |
1414 | \f | |
1415 | ;;;; *** Rmail Summary Mailing Commands *** | |
1416 | ||
58285c3b | 1417 | (defun rmail-summary-override-mail-send-and-exit () |
689421a9 | 1418 | "Replace bindings to `mail-send-and-exit' with `rmail-summary-send-and-exit'." |
58285c3b GM |
1419 | (use-local-map (copy-keymap (current-local-map))) |
1420 | (dolist (key (where-is-internal 'mail-send-and-exit)) | |
1421 | (define-key (current-local-map) key 'rmail-summary-send-and-exit))) | |
1422 | ||
d41d75fb RS |
1423 | (defun rmail-summary-mail () |
1424 | "Send mail in another window. | |
1425 | While composing the message, use \\[mail-yank-original] to yank the | |
1426 | original message into it." | |
1427 | (interactive) | |
4c11ca80 RS |
1428 | (let ((window (get-buffer-window rmail-buffer))) |
1429 | (if window | |
1430 | (select-window window) | |
1431 | (set-buffer rmail-buffer))) | |
1432 | (rmail-start-mail nil nil nil nil nil (current-buffer)) | |
58285c3b | 1433 | (rmail-summary-override-mail-send-and-exit)) |
d41d75fb RS |
1434 | |
1435 | (defun rmail-summary-continue () | |
1436 | "Continue composing outgoing message previously being composed." | |
1437 | (interactive) | |
4c11ca80 RS |
1438 | (let ((window (get-buffer-window rmail-buffer))) |
1439 | (if window | |
1440 | (select-window window) | |
1441 | (set-buffer rmail-buffer))) | |
db1d3cf7 | 1442 | (rmail-start-mail t)) |
d41d75fb RS |
1443 | |
1444 | (defun rmail-summary-reply (just-sender) | |
1445 | "Reply to the current message. | |
1446 | Normally include CC: to all other recipients of original message; | |
db1d3cf7 KH |
1447 | prefix argument means ignore them. While composing the reply, |
1448 | use \\[mail-yank-original] to yank the original message into it." | |
d41d75fb | 1449 | (interactive "P") |
67f2e119 | 1450 | (let ((window (get-buffer-window rmail-view-buffer))) |
4c11ca80 RS |
1451 | (if window |
1452 | (select-window window) | |
67f2e119 | 1453 | (set-buffer rmail-view-buffer))) |
db1d3cf7 | 1454 | (rmail-reply just-sender) |
58285c3b | 1455 | (rmail-summary-override-mail-send-and-exit)) |
d41d75fb RS |
1456 | |
1457 | (defun rmail-summary-retry-failure () | |
1458 | "Edit a mail message which is based on the contents of the current message. | |
1459 | For a message rejected by the mail system, extract the interesting headers and | |
1460 | the body of the original message; otherwise copy the current message." | |
1461 | (interactive) | |
4c11ca80 RS |
1462 | (let ((window (get-buffer-window rmail-buffer))) |
1463 | (if window | |
1464 | (select-window window) | |
1465 | (set-buffer rmail-buffer))) | |
db1d3cf7 | 1466 | (rmail-retry-failure) |
58285c3b | 1467 | (rmail-summary-override-mail-send-and-exit)) |
d41d75fb RS |
1468 | |
1469 | (defun rmail-summary-send-and-exit () | |
1470 | "Send mail reply and return to summary buffer." | |
1471 | (interactive) | |
1472 | (mail-send-and-exit t)) | |
1473 | ||
18e90c58 RS |
1474 | (defun rmail-summary-forward (resend) |
1475 | "Forward the current message to another user. | |
1476 | With prefix argument, \"resend\" the message instead of forwarding it; | |
1477 | see the documentation of `rmail-resend'." | |
1478 | (interactive "P") | |
d41d75fb | 1479 | (save-excursion |
4c11ca80 RS |
1480 | (let ((window (get-buffer-window rmail-buffer))) |
1481 | (if window | |
1482 | (select-window window) | |
1483 | (set-buffer rmail-buffer))) | |
18e90c58 | 1484 | (rmail-forward resend) |
58285c3b | 1485 | (rmail-summary-override-mail-send-and-exit))) |
4986bd38 RS |
1486 | |
1487 | (defun rmail-summary-resend () | |
689421a9 | 1488 | "Resend current message using `rmail-resend'." |
4986bd38 RS |
1489 | (interactive) |
1490 | (save-excursion | |
4c11ca80 RS |
1491 | (let ((window (get-buffer-window rmail-buffer))) |
1492 | (if window | |
1493 | (select-window window) | |
1494 | (set-buffer rmail-buffer))) | |
4986bd38 | 1495 | (call-interactively 'rmail-resend))) |
d41d75fb RS |
1496 | \f |
1497 | ;; Summary output commands. | |
1498 | ||
48afa9cd | 1499 | (defun rmail-summary-output-to-rmail-file (&optional file-name n) |
d41d75fb RS |
1500 | "Append the current message to an Rmail file named FILE-NAME. |
1501 | If the file does not exist, ask if it should be created. | |
1502 | If file is being visited, the message is appended to the Emacs | |
05422245 KH |
1503 | buffer visiting that file. |
1504 | ||
1505 | A prefix argument N says to output N consecutive messages | |
1506 | starting with the current one. Deleted messages are skipped and don't count." | |
f9e3db55 RS |
1507 | (interactive |
1508 | (progn (require 'rmailout) | |
1509 | (list (rmail-output-read-rmail-file-name) | |
1510 | (prefix-numeric-value current-prefix-arg)))) | |
f256f63e | 1511 | (let ((i 0) prev-msg) |
a1506d29 | 1512 | (while |
f256f63e KH |
1513 | (and (< i n) |
1514 | (progn (rmail-summary-goto-msg) | |
1515 | (not (eq prev-msg | |
1516 | (setq prev-msg | |
a1506d29 | 1517 | (with-current-buffer rmail-buffer |
f256f63e | 1518 | rmail-current-message)))))) |
f9e3db55 | 1519 | (setq i (1+ i)) |
f9e3db55 RS |
1520 | (with-current-buffer rmail-buffer |
1521 | (let ((rmail-delete-after-output nil)) | |
1522 | (rmail-output-to-rmail-file file-name 1))) | |
1523 | (if rmail-delete-after-output | |
1524 | (rmail-summary-delete-forward nil) | |
1525 | (if (< i n) | |
1526 | (rmail-summary-next-msg 1)))))) | |
1527 | ||
1528 | (defun rmail-summary-output (&optional file-name n) | |
1529 | "Append this message to Unix mail file named FILE-NAME. | |
1530 | ||
1531 | A prefix argument N says to output N consecutive messages | |
1532 | starting with the current one. Deleted messages are skipped and don't count." | |
1533 | (interactive | |
1534 | (progn (require 'rmailout) | |
1535 | (list (rmail-output-read-file-name) | |
1536 | (prefix-numeric-value current-prefix-arg)))) | |
5a7a27be RS |
1537 | (let ((i 0) prev-msg) |
1538 | (while | |
1539 | (and (< i n) | |
1540 | (progn (rmail-summary-goto-msg) | |
1541 | (not (eq prev-msg | |
1542 | (setq prev-msg | |
1543 | (with-current-buffer rmail-buffer | |
1544 | rmail-current-message)))))) | |
f9e3db55 RS |
1545 | (setq i (1+ i)) |
1546 | (with-current-buffer rmail-buffer | |
1547 | (let ((rmail-delete-after-output nil)) | |
1548 | (rmail-output file-name 1))) | |
1549 | (if rmail-delete-after-output | |
1550 | (rmail-summary-delete-forward nil) | |
1551 | (if (< i n) | |
1552 | (rmail-summary-next-msg 1)))))) | |
d41d75fb | 1553 | |
dca46072 RS |
1554 | (defun rmail-summary-output-menu () |
1555 | "Output current message to another Rmail file, chosen with a menu. | |
1556 | Also set the default for subsequent \\[rmail-output-to-rmail-file] commands. | |
1557 | The variables `rmail-secondary-file-directory' and | |
1558 | `rmail-secondary-file-regexp' control which files are offered in the menu." | |
1559 | (interactive) | |
1560 | (save-excursion | |
1561 | (set-buffer rmail-buffer) | |
1562 | (let ((rmail-delete-after-output nil)) | |
1563 | (call-interactively 'rmail-output-menu))) | |
1564 | (if rmail-delete-after-output | |
1565 | (rmail-summary-delete-forward nil))) | |
1566 | ||
aa138cb4 RS |
1567 | (defun rmail-summary-construct-io-menu () |
1568 | (let ((files (rmail-find-all-files rmail-secondary-file-directory))) | |
cb4903bc | 1569 | (if files |
aa138cb4 RS |
1570 | (progn |
1571 | (define-key rmail-summary-mode-map [menu-bar classify input-menu] | |
a1506d29 JB |
1572 | (cons "Input Rmail File" |
1573 | (rmail-list-to-menu "Input Rmail File" | |
cb4903bc | 1574 | files |
aa138cb4 RS |
1575 | 'rmail-summary-input))) |
1576 | (define-key rmail-summary-mode-map [menu-bar classify output-menu] | |
a1506d29 JB |
1577 | (cons "Output Rmail File" |
1578 | (rmail-list-to-menu "Output Rmail File" | |
cb4903bc RS |
1579 | files |
1580 | 'rmail-summary-output-to-rmail-file)))) | |
1581 | (define-key rmail-summary-mode-map [menu-bar classify input-menu] | |
1582 | '("Input Rmail File" . rmail-disable-menu)) | |
1583 | (define-key rmail-summary-mode-map [menu-bar classify output-menu] | |
1584 | '("Output Rmail File" . rmail-disable-menu))))) | |
aa138cb4 | 1585 | |
d5bafc55 RS |
1586 | (defun rmail-summary-output-body (&optional file-name) |
1587 | "Write this message body to the file FILE-NAME. | |
1588 | FILE-NAME defaults, interactively, from the Subject field of the message." | |
1589 | (interactive) | |
1590 | (save-excursion | |
1591 | (set-buffer rmail-buffer) | |
1592 | (let ((rmail-delete-after-output nil)) | |
1593 | (if file-name | |
1594 | (rmail-output-body-to-file file-name) | |
1595 | (call-interactively 'rmail-output-body-to-file)))) | |
1596 | (if rmail-delete-after-output | |
1597 | (rmail-summary-delete-forward nil))) | |
e45fce03 RS |
1598 | \f |
1599 | ;; Sorting messages in Rmail Summary buffer. | |
1600 | ||
1601 | (defun rmail-summary-sort-by-date (reverse) | |
1602 | "Sort messages of current Rmail summary by date. | |
1603 | If prefix argument REVERSE is non-nil, sort them in reverse order." | |
1604 | (interactive "P") | |
1605 | (rmail-sort-from-summary (function rmail-sort-by-date) reverse)) | |
1606 | ||
1607 | (defun rmail-summary-sort-by-subject (reverse) | |
1608 | "Sort messages of current Rmail summary by subject. | |
1609 | If prefix argument REVERSE is non-nil, sort them in reverse order." | |
1610 | (interactive "P") | |
1611 | (rmail-sort-from-summary (function rmail-sort-by-subject) reverse)) | |
1612 | ||
1613 | (defun rmail-summary-sort-by-author (reverse) | |
1614 | "Sort messages of current Rmail summary by author. | |
1615 | If prefix argument REVERSE is non-nil, sort them in reverse order." | |
1616 | (interactive "P") | |
1617 | (rmail-sort-from-summary (function rmail-sort-by-author) reverse)) | |
1618 | ||
1619 | (defun rmail-summary-sort-by-recipient (reverse) | |
1620 | "Sort messages of current Rmail summary by recipient. | |
1621 | If prefix argument REVERSE is non-nil, sort them in reverse order." | |
1622 | (interactive "P") | |
1623 | (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse)) | |
1624 | ||
1625 | (defun rmail-summary-sort-by-correspondent (reverse) | |
1626 | "Sort messages of current Rmail summary by other correspondent. | |
1627 | If prefix argument REVERSE is non-nil, sort them in reverse order." | |
1628 | (interactive "P") | |
1629 | (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse)) | |
1630 | ||
1631 | (defun rmail-summary-sort-by-lines (reverse) | |
1632 | "Sort messages of current Rmail summary by lines of the message. | |
1633 | If prefix argument REVERSE is non-nil, sort them in reverse order." | |
1634 | (interactive "P") | |
1635 | (rmail-sort-from-summary (function rmail-sort-by-lines) reverse)) | |
1636 | ||
e15dbc43 GM |
1637 | (defun rmail-summary-sort-by-labels (reverse labels) |
1638 | "Sort messages of current Rmail summary by labels. | |
ebdf372b KH |
1639 | If prefix argument REVERSE is non-nil, sort them in reverse order. |
1640 | KEYWORDS is a comma-separated list of labels." | |
1641 | (interactive "P\nsSort by labels: ") | |
1642 | (rmail-sort-from-summary | |
1643 | (function (lambda (reverse) | |
e15dbc43 | 1644 | (rmail-sort-by-labels reverse labels))) |
ebdf372b KH |
1645 | reverse)) |
1646 | ||
e45fce03 RS |
1647 | (defun rmail-sort-from-summary (sortfun reverse) |
1648 | "Sort Rmail messages from Summary buffer and update it after sorting." | |
1649 | (require 'rmailsort) | |
2a527e48 KH |
1650 | (let ((selwin (selected-window))) |
1651 | (unwind-protect | |
1652 | (progn (pop-to-buffer rmail-buffer) | |
1653 | (funcall sortfun reverse)) | |
1654 | (select-window selwin)))) | |
c88ab9ce | 1655 | |
020c9ca5 DL |
1656 | (provide 'rmailsum) |
1657 | ||
ab5796a9 | 1658 | ;;; arch-tag: 556079ee-75c1-47f5-9884-2e0a0bc6c5a1 |
c88ab9ce | 1659 | ;;; rmailsum.el ends here |