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