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