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