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