]> code.delx.au - gnu-emacs/blob - lisp/mail/rmail.el
(mail-hist-put-headers-into-history)
[gnu-emacs] / lisp / mail / rmail.el
1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
2
3 ;; Copyright (C) 1985,86,87,88,93,94 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: mail
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Code:
25
26 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
27 ;; New features include attribute and keyword support, message
28 ;; selection by dispatch table, summary by attributes and keywords,
29 ;; expunging by dispatch table, sticky options for file commands.
30
31 ;; Extended by Bob Weiner of Motorola
32 ;; New features include: rmail and rmail-summary buffers remain
33 ;; synchronized and key bindings basically operate the same way in both
34 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
35 ;; variable, and a bury rmail buffer (wipe) command.
36 ;;
37
38 (require 'mail-utils)
39
40 ;; For Emacs V18 compatibility
41 (and (not (fboundp 'buffer-disable-undo))
42 (fboundp 'buffer-flush-undo)
43 (defalias 'buffer-disable-undo 'buffer-flush-undo))
44
45 ; These variables now declared in paths.el.
46 ;(defvar rmail-spool-directory "/usr/spool/mail/"
47 ; "This is the name of the directory used by the system mailer for\n\
48 ;delivering new mail. It's name should end with a slash.")
49 ;(defvar rmail-file-name
50 ; (expand-file-name "~/RMAIL")
51 ; "")
52
53 (defvar rmail-movemail-program nil
54 "If non-nil, name of program for fetching new mail.")
55
56 ;;;###autoload
57 (defvar rmail-dont-reply-to-names nil "\
58 *A regexp specifying names to prune of reply to messages.
59 A value of nil means exclude your own name only.")
60
61 ;;;###autoload
62 (defvar rmail-default-dont-reply-to-names "info-" "\
63 A regular expression specifying part of the value of the default value of
64 the variable `rmail-dont-reply-to-names', for when the user does not set
65 `rmail-dont-reply-to-names' explicitly. (The other part of the default
66 value is the user's name.)
67 It is useful to set this variable in the site customization file.")
68
69 ;;;###autoload
70 (defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:\\|^\\(resent-\\|\\)message-id:\\|^summary-line:" "\
71 ^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|\
72 ^x400-mts-identifier:\\|^x400-content-type:\\|^message-id:\\|^summary-line:"
73 "*Regexp to match Header fields that Rmail should normally hide.")
74
75 ;;;###autoload
76 (defvar rmail-retry-ignored-headers nil "\
77 *Headers that should be stripped when retrying a failed message.")
78
79 ;;;###autoload
80 (defvar rmail-highlighted-headers "^From:\\|^Subject:" "\
81 *Regexp to match Header fields that Rmail should normally highlight.
82 A value of nil means don't highlight.
83 See also `rmail-highlight-face'.")
84
85 ;;;###autoload
86 (defvar rmail-highlight-face nil "\
87 *Face used by Rmail for highlighting headers.")
88
89 ;;;###autoload
90 (defvar rmail-delete-after-output nil "\
91 *Non-nil means automatically delete a message that is copied to a file.")
92
93 ;;;###autoload
94 (defvar rmail-primary-inbox-list nil "\
95 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
96 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
97 \(the name varies depending on the operating system,
98 and the value of the environment variable MAIL overrides it).")
99
100 ;;;###autoload
101 (defvar rmail-mail-new-frame nil
102 "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
103
104 ;;;###autoload
105 (defvar rmail-secondary-file-directory "~/"
106 "*Directory for additional secondary Rmail files.")
107 ;;;###autoload
108 (defvar rmail-secondary-file-regexp "\\.xmail$"
109 "*Regexp for which files are secondary Rmail files.")
110
111 ;; These may be altered by site-init.el to match the format of mmdf files
112 ;; delimiting used on a given host (delim1 and delim2 from the config
113 ;; files).
114
115 (defvar mmdf-delim1 "^\001\001\001\001\n"
116 "Regexp marking the start of an mmdf message")
117 (defvar mmdf-delim2 "^\001\001\001\001\n"
118 "Regexp marking the end of an mmdf message")
119
120 (defvar rmail-message-filter nil
121 "If non nil, a filter function for new messages in RMAIL.
122 Called with region narrowed to the message, including headers.")
123
124 (defvar rmail-reply-prefix "Re: "
125 "String to prepend to Subject line when replying to a message.")
126
127 (defvar rmail-display-summary nil
128 "If non nil, the summary buffer is always displayed.")
129
130 (defvar rmail-mode-map nil)
131
132 (defvar rmail-inbox-list nil)
133 (defvar rmail-keywords nil)
134
135 ;; Message counters and markers. Deleted flags.
136
137 (defvar rmail-current-message nil)
138 (defvar rmail-total-messages nil)
139 (defvar rmail-message-vector nil)
140 (defvar rmail-deleted-vector nil)
141
142 (defvar rmail-overlay-list nil)
143
144 (defvar rmail-font-lock-keywords
145 '(("^\\(From\\|Sender\\):" . font-lock-function-name-face)
146 ("^Reply-To:.*$" . font-lock-function-name-face)
147 ("^Subject:" . font-lock-comment-face)
148 ("^\\(To\\|Apparently-To\\|Cc\\):" . font-lock-keyword-face)
149 ("^[ \t]*\\sw*[>|}].*$" . font-lock-reference-face) ; Citation.
150 ("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\|Date\\):.*$" . font-lock-string-face))
151 "Additional expressions to highlight in Rmail mode.")
152
153 ;; These are used by autoloaded rmail-summary.
154
155 (defvar rmail-summary-buffer nil)
156 (defvar rmail-summary-vector nil)
157
158 ;; `Sticky' default variables.
159
160 ;; Last individual label specified to a or k.
161 (defvar rmail-last-label nil)
162 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
163 (defvar rmail-last-multi-labels nil)
164 (defvar rmail-last-regexp nil)
165 (defvar rmail-default-file nil
166 "*Default file name for \\[rmail-output].")
167 (defvar rmail-default-rmail-file (expand-file-name "~/XMAIL")
168 "*Default file name for \\[rmail-output-to-rmail-file].")
169
170 ;;; Regexp matching the delimiter of messages in UNIX mail format
171 ;;; (UNIX From lines), minus the initial ^. Note that if you change
172 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
173 ;;; that knows the exact ordering of the \\( \\) subexpressions.
174 (defvar rmail-unix-mail-delimiter
175 (let ((time-zone-regexp
176 (concat "\\([A-Z]?[A-Z][A-Z][A-Z]\\( DST\\)?"
177 "\\|[-+]?[0-9][0-9][0-9][0-9]"
178 "\\|"
179 "\\) *")))
180 (concat
181 "From "
182
183 ;; Username, perhaps with a quoted section that can contain spaces.
184 "\\("
185 "[^ \n]*"
186 "\\(\\|\".*\"[^ \n]*\\)"
187 "\\) ?"
188
189 ;; The time the message was sent.
190 "\\([^ \n]*\\) *" ; day of the week
191 "\\([^ ]*\\) *" ; month
192 "\\([0-9]*\\) *" ; day of month
193 "\\([0-9:]*\\) *" ; time of day
194
195 ;; Perhaps a time zone, specified by an abbreviation, or by a
196 ;; numeric offset.
197 time-zone-regexp
198
199 ;; The year.
200 " [0-9][0-9]\\([0-9]*\\) *"
201
202 ;; On some systems the time zone can appear after the year, too.
203 time-zone-regexp
204
205 ;; Old uucp cruft.
206 "\\(remote from .*\\)?"
207
208 "\n"))
209 nil)
210
211 ;; Perform BODY in the summary buffer
212 ;; in such a way that its cursor is properly updated in its own window.
213 (defmacro rmail-select-summary (&rest body)
214 (` (let ((total rmail-total-messages))
215 (if (rmail-summary-displayed)
216 (let ((window (selected-window)))
217 (save-excursion
218 (unwind-protect
219 (progn
220 (pop-to-buffer rmail-summary-buffer)
221 ;; rmail-total-messages is a buffer-local var
222 ;; in the rmail buffer.
223 ;; This way we make it available for the body
224 ;; even tho the rmail buffer is not current.
225 (let ((rmail-total-messages total))
226 (,@ body)))
227 (select-window window))))
228 (save-excursion
229 (set-buffer rmail-summary-buffer)
230 (let ((rmail-total-messages total))
231 (,@ body))))
232 (rmail-maybe-display-summary))))
233 \f
234 ;;;; *** Rmail Mode ***
235
236 ;;;###autoload
237 (defun rmail (&optional file-name-arg)
238 "Read and edit incoming mail.
239 Moves messages into file named by `rmail-file-name' (a babyl format file)
240 and edits that file in RMAIL Mode.
241 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
242
243 May be called with file name as argument; then performs rmail editing on
244 that file, but does not copy any new mail into the file.
245 Interactively, if you supply a prefix argument, then you
246 have a chance to specify a file name with the minibuffer.
247
248 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
249 (interactive (if current-prefix-arg
250 (list (read-file-name "Run rmail on RMAIL file: "
251 nil nil t))))
252 (or rmail-default-file
253 (setq rmail-default-file (expand-file-name "~/xmail")))
254 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
255 (existed (get-file-buffer file-name)))
256 ;; Like find-file, but in the case where a buffer existed
257 ;; and the file was reverted, recompute the message-data.
258 (if (and existed (not (verify-visited-file-modtime existed)))
259 (progn
260 ;; Don't be confused by apparent local-variables spec
261 ;; in the last message in the RMAIL file.
262 (let ((enable-local-variables nil))
263 (find-file file-name))
264 (if (and (verify-visited-file-modtime existed)
265 (eq major-mode 'rmail-mode))
266 (progn (rmail-forget-messages)
267 (rmail-set-message-counters))))
268 (let ((enable-local-variables nil))
269 (find-file file-name)))
270 (if (eq major-mode 'rmail-edit-mode)
271 (error "Exit Rmail Edit mode before getting new mail."))
272 (if (and existed (> (buffer-size) 0))
273 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
274 (or (eq major-mode 'rmail-mode)
275 (rmail-mode-2))
276 (rmail-mode-2)
277 ;; Convert all or part to Babyl file if possible.
278 (rmail-convert-file)
279 (goto-char (point-max))
280 (if (null rmail-inbox-list)
281 (progn
282 (rmail-set-message-counters)
283 (rmail-show-message))))
284 (let ((existing-unseen (rmail-first-unseen-message)))
285 (or file-name-arg
286 (rmail-get-new-mail))
287 ;; Show the first unseen message, which might be from a previous session
288 ;; or might have been just read in by rmail-get-new-mail. Must
289 ;; determine already unseen messages first, as rmail-get-new-mail
290 ;; positions on the first new message, thus marking it as seen.
291 (rmail-show-message existing-unseen))
292 (if rmail-display-summary (rmail-summary))
293 (rmail-construct-io-menu)))
294
295 ;; Given the value of MAILPATH, return a list of inbox file names.
296 ;; This is turned off because it is not clear that the user wants
297 ;; all these inboxes to feed into the primary rmail file.
298 ; (defun rmail-convert-mailpath (string)
299 ; (let (idx list)
300 ; (while (setq idx (string-match "[%:]" string))
301 ; (let ((this (substring string 0 idx)))
302 ; (setq string (substring string (1+ idx)))
303 ; (setq list (cons (if (string-match "%" this)
304 ; (substring this 0 (string-match "%" this))
305 ; this)
306 ; list))))
307 ; list))
308
309 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
310 ; will not cause emacs 18.55 problems.
311
312 (defun rmail-convert-file ()
313 (let (convert)
314 (widen)
315 (goto-char (point-min))
316 ;; If file doesn't start like a Babyl file,
317 ;; convert it to one, by adding a header and converting each message.
318 (cond ((looking-at "BABYL OPTIONS:"))
319 ((looking-at "Version: 5\n")
320 ;; Losing babyl file made by old version of Rmail.
321 ;; Just fix the babyl file header; don't make a new one,
322 ;; so we don't lose the Labels: file attribute, etc.
323 (let ((buffer-read-only nil))
324 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
325 ((equal (point-min) (point-max))
326 ;; Empty RMAIL file. Just insert the header.
327 (rmail-insert-rmail-file-header))
328 (t
329 ;; Non-empty file in non-RMAIL format. Add header and convert.
330 (setq convert t)
331 (rmail-insert-rmail-file-header)))
332 ;; If file was not a Babyl file or if there are
333 ;; Unix format messages added at the end,
334 ;; convert file as necessary.
335 (if (or convert
336 (save-excursion
337 (goto-char (point-max))
338 (search-backward "\^_")
339 (forward-char 1)
340 (looking-at "\n*From ")))
341 (let ((buffer-read-only nil))
342 (message "Converting to Babyl format...")
343 ;; If file needs conversion, convert it all,
344 ;; except for the BABYL header.
345 ;; (rmail-convert-to-babyl-format would delete the header.)
346 (goto-char (point-min))
347 (search-forward "\n\^_" nil t)
348 (narrow-to-region (point) (point-max))
349 (rmail-convert-to-babyl-format)
350 (message "Converting to Babyl format...done")))))
351
352 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
353 ;;; will not cause emacs 18.55 problems.
354
355 (defun rmail-insert-rmail-file-header ()
356 (let ((buffer-read-only nil))
357 (insert "BABYL OPTIONS: -*- rmail -*-
358 Version: 5
359 Labels:
360 Note: This is the header of an rmail file.
361 Note: If you are seeing it in rmail,
362 Note: it means the file has no messages in it.\n\^_")))
363
364 (if rmail-mode-map
365 nil
366 (setq rmail-mode-map (make-keymap))
367 (suppress-keymap rmail-mode-map)
368 (define-key rmail-mode-map "a" 'rmail-add-label)
369 (define-key rmail-mode-map "b" 'rmail-bury)
370 (define-key rmail-mode-map "c" 'rmail-continue)
371 (define-key rmail-mode-map "d" 'rmail-delete-forward)
372 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)
373 (define-key rmail-mode-map "e" 'rmail-edit-current-message)
374 (define-key rmail-mode-map "f" 'rmail-forward)
375 (define-key rmail-mode-map "g" 'rmail-get-new-mail)
376 (define-key rmail-mode-map "h" 'rmail-summary)
377 (define-key rmail-mode-map "i" 'rmail-input)
378 (define-key rmail-mode-map "j" 'rmail-show-message)
379 (define-key rmail-mode-map "k" 'rmail-kill-label)
380 (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
381 (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
382 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
383 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
384 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
385 (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
386 (define-key rmail-mode-map "m" 'rmail-mail)
387 (define-key rmail-mode-map "\em" 'rmail-retry-failure)
388 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
389 (define-key rmail-mode-map "\en" 'rmail-next-message)
390 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
391 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
392 (define-key rmail-mode-map "\C-o" 'rmail-output)
393 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
394 (define-key rmail-mode-map "\ep" 'rmail-previous-message)
395 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
396 (define-key rmail-mode-map "q" 'rmail-quit)
397 (define-key rmail-mode-map "r" 'rmail-reply)
398 ;; I find I can't live without the default M-r command -- rms.
399 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
400 (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
401 (define-key rmail-mode-map "\es" 'rmail-search)
402 (define-key rmail-mode-map "t" 'rmail-toggle-header)
403 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
404 (define-key rmail-mode-map "w" 'rmail-edit-current-message)
405 (define-key rmail-mode-map "x" 'rmail-expunge)
406 (define-key rmail-mode-map "." 'rmail-beginning-of-message)
407 (define-key rmail-mode-map "<" 'rmail-first-message)
408 (define-key rmail-mode-map ">" 'rmail-last-message)
409 (define-key rmail-mode-map " " 'scroll-up)
410 (define-key rmail-mode-map "\177" 'scroll-down)
411 (define-key rmail-mode-map "?" 'describe-mode)
412 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
413 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
414 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
415 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
416 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
417 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
418 (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-keywords)
419 )
420 \f
421 (define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
422
423 (define-key rmail-mode-map [menu-bar classify]
424 (cons "Classify" (make-sparse-keymap "Classify")))
425
426 (define-key rmail-mode-map [menu-bar classify input-menu]
427 nil)
428
429 (define-key rmail-mode-map [menu-bar classify output-menu]
430 nil)
431
432 (define-key rmail-mode-map [menu-bar classify output-inbox]
433 '("Output (inbox)..." . rmail-output))
434
435 (define-key rmail-mode-map [menu-bar classify output]
436 '("Output (Rmail)..." . rmail-output-to-rmail-file))
437
438 (define-key rmail-mode-map [menu-bar classify kill-label]
439 '("Kill Label..." . rmail-kill-label))
440
441 (define-key rmail-mode-map [menu-bar classify add-label]
442 '("Add Label..." . rmail-add-label))
443
444 (define-key rmail-mode-map [menu-bar summary]
445 (cons "Summary" (make-sparse-keymap "Summary")))
446
447 (define-key rmail-mode-map [menu-bar summary labels]
448 '("By Labels..." . rmail-summary-by-labels))
449
450 (define-key rmail-mode-map [menu-bar summary recipients]
451 '("By Recipients..." . rmail-summary-by-recipients))
452
453 (define-key rmail-mode-map [menu-bar summary topic]
454 '("By Topic..." . rmail-summary-by-topic))
455
456 (define-key rmail-mode-map [menu-bar summary regexp]
457 '("By Regexp..." . rmail-summary-by-regexp))
458
459 (define-key rmail-mode-map [menu-bar summary all]
460 '("All" . rmail-summary))
461
462 (define-key rmail-mode-map [menu-bar mail]
463 (cons "Mail" (make-sparse-keymap "Mail")))
464
465 (define-key rmail-mode-map [menu-bar mail rmail-get-new-mail]
466 '("Get New Mail" . rmail-get-new-mail))
467
468 (define-key rmail-mode-map [menu-bar mail lambda]
469 '("----"))
470
471 (define-key rmail-mode-map [menu-bar mail continue]
472 '("Continue" . rmail-continue))
473
474 (define-key rmail-mode-map [menu-bar mail resend]
475 '("Re-send..." . rmail-resend))
476
477 (define-key rmail-mode-map [menu-bar mail forward]
478 '("Forward" . rmail-forward))
479
480 (define-key rmail-mode-map [menu-bar mail retry]
481 '("Retry" . rmail-retry-failure))
482
483 (define-key rmail-mode-map [menu-bar mail reply]
484 '("Reply" . rmail-reply))
485
486 (define-key rmail-mode-map [menu-bar mail mail]
487 '("Mail" . rmail-mail))
488
489 (define-key rmail-mode-map [menu-bar delete]
490 (cons "Delete" (make-sparse-keymap "Delete")))
491
492 (define-key rmail-mode-map [menu-bar delete expunge/save]
493 '("Expunge/Save" . rmail-expunge-and-save))
494
495 (define-key rmail-mode-map [menu-bar delete expunge]
496 '("Expunge" . rmail-expunge))
497
498 (define-key rmail-mode-map [menu-bar delete undelete]
499 '("Undelete" . rmail-undelete-previous-message))
500
501 (define-key rmail-mode-map [menu-bar delete delete]
502 '("Delete" . rmail-delete-forward))
503
504 (define-key rmail-mode-map [menu-bar move]
505 (cons "Move" (make-sparse-keymap "Move")))
506
507 (define-key rmail-mode-map [menu-bar move search-back]
508 '("Search Back..." . rmail-search-backward))
509
510 (define-key rmail-mode-map [menu-bar move search]
511 '("Search..." . rmail-search))
512
513 (define-key rmail-mode-map [menu-bar move previous]
514 '("Previous Nondeleted" . rmail-previous-undeleted-message))
515
516 (define-key rmail-mode-map [menu-bar move next]
517 '("Next Nondeleted" . rmail-next-undeleted-message))
518
519 (define-key rmail-mode-map [menu-bar move last]
520 '("Last" . rmail-last-message))
521
522 (define-key rmail-mode-map [menu-bar move first]
523 '("First" . rmail-first-message))
524
525 (define-key rmail-mode-map [menu-bar move previous]
526 '("Previous" . rmail-previous-message))
527
528 (define-key rmail-mode-map [menu-bar move next]
529 '("Next" . rmail-next-message))
530 \f
531 ;; Rmail mode is suitable only for specially formatted data.
532 (put 'rmail-mode 'mode-class 'special)
533
534 (defun rmail-mode-kill-summary ()
535 (if rmail-summary-buffer (kill-buffer rmail-summary-buffer)))
536
537 ;;;###autoload
538 (defun rmail-mode ()
539 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
540 All normal editing commands are turned off.
541 Instead, these commands are available:
542
543 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
544 \\[scroll-up] Scroll to next screen of this message.
545 \\[scroll-down] Scroll to previous screen of this message.
546 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
547 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
548 \\[rmail-next-message] Move to Next message whether deleted or not.
549 \\[rmail-previous-message] Move to Previous message whether deleted or not.
550 \\[rmail-first-message] Move to the first message in Rmail file.
551 \\[rmail-last-message] Move to the last message in Rmail file.
552 \\[rmail-show-message] Jump to message specified by numeric position in file.
553 \\[rmail-search] Search for string and show message it is found in.
554 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
555 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
556 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
557 till a deleted message is found.
558 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
559 \\[rmail-expunge] Expunge deleted messages.
560 \\[rmail-expunge-and-save] Expunge and save the file.
561 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
562 \\[save-buffer] Save without expunging.
563 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
564 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
565 \\[rmail-continue] Continue composing outgoing message started before.
566 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
567 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
568 \\[rmail-forward] Forward this message to another user.
569 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
570 \\[rmail-output] Output this message to a Unix-format mail file (append it).
571 \\[rmail-input] Input Rmail file. Run Rmail on that file.
572 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
573 \\[rmail-kill-label] Kill label. Remove a label from current message.
574 \\[rmail-next-labeled-message] Move to Next message with specified label
575 (label defaults to last one specified).
576 Standard labels: filed, unseen, answered, forwarded, deleted.
577 Any other label is present only if you add it with \\[rmail-add-label].
578 \\[rmail-previous-labeled-message] Move to Previous message with specified label
579 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
580 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
581 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
582 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
583 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
584 \\[rmail-toggle-header] Toggle display of complete header."
585 (interactive)
586 (rmail-mode-2)
587 (rmail-set-message-counters)
588 (rmail-show-message rmail-total-messages))
589
590 (defun rmail-mode-2 ()
591 (kill-all-local-variables)
592 (rmail-mode-1)
593 (rmail-variables)
594 (run-hooks 'rmail-mode-hook))
595
596 (defun rmail-mode-1 ()
597 (setq major-mode 'rmail-mode)
598 (setq mode-name "RMAIL")
599 (setq buffer-read-only t)
600 ;; No need to auto save RMAIL files in normal circumstances
601 ;; because they contain no info except attribute changes
602 ;; and deletion of messages.
603 ;; The one exception is when messages are copied into an Rmail mode buffer.
604 ;; rmail-output-to-rmail-file enables auto save when you do that.
605 (setq buffer-auto-save-file-name nil)
606 (if (boundp 'mode-line-modified)
607 (setq mode-line-modified "--- ")
608 (setq mode-line-format
609 (cons "--- " (cdr (default-value 'mode-line-format)))))
610 (use-local-map rmail-mode-map)
611 (set-syntax-table text-mode-syntax-table)
612 (setq local-abbrev-table text-mode-abbrev-table))
613
614 (defun rmail-variables ()
615 (make-local-variable 'revert-buffer-function)
616 (setq revert-buffer-function 'rmail-revert)
617 (make-local-variable 'font-lock-keywords)
618 (setq font-lock-keywords rmail-font-lock-keywords)
619 (make-local-variable 'rmail-last-label)
620 (make-local-variable 'rmail-last-regexp)
621 (make-local-variable 'rmail-deleted-vector)
622 (make-local-variable 'rmail-summary-buffer)
623 (make-local-variable 'rmail-summary-vector)
624 (make-local-variable 'rmail-current-message)
625 (make-local-variable 'rmail-total-messages)
626 (make-local-variable 'require-final-newline)
627 (setq require-final-newline nil)
628 (make-local-variable 'rmail-overlay-list)
629 (setq rmail-overlay-list nil)
630 (make-local-variable 'version-control)
631 (setq version-control 'never)
632 (make-local-variable 'kill-buffer-hook)
633 (add-hook 'kill-buffer-hook 'rmail-mode-kill-summary)
634 (make-local-variable 'file-precious-flag)
635 (setq file-precious-flag t)
636 (make-local-variable 'rmail-message-vector)
637 (make-local-variable 'rmail-inbox-list)
638 (setq rmail-inbox-list (rmail-parse-file-inboxes))
639 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
640 (and (null rmail-inbox-list)
641 (or (equal buffer-file-name (expand-file-name rmail-file-name))
642 (equal buffer-file-truename
643 (abbreviate-file-name (file-truename rmail-file-name))))
644 (setq rmail-inbox-list
645 (or rmail-primary-inbox-list
646 (list (or (getenv "MAIL")
647 (concat rmail-spool-directory
648 (user-login-name)))))))
649 (make-local-variable 'rmail-keywords)
650 ;; this gets generated as needed
651 (setq rmail-keywords nil))
652
653 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
654 (defun rmail-revert (arg noconfirm)
655 (let (revert-buffer-function)
656 ;; Call our caller again, but this time it does the default thing.
657 (if (revert-buffer arg noconfirm)
658 ;; If the user said "yes", and we changed something,
659 ;; reparse the messages.
660 (progn
661 (rmail-convert-file)
662 (goto-char (point-max))
663 (rmail-set-message-counters)
664 (rmail-show-message)))))
665
666 ;; Return a list of files from this buffer's Mail: option.
667 ;; Does not assume that messages have been parsed.
668 ;; Just returns nil if buffer does not look like Babyl format.
669 (defun rmail-parse-file-inboxes ()
670 (save-excursion
671 (save-restriction
672 (widen)
673 (goto-char 1)
674 (cond ((looking-at "BABYL OPTIONS:")
675 (search-forward "\n\^_" nil 'move)
676 (narrow-to-region 1 (point))
677 (goto-char 1)
678 (if (search-forward "\nMail:" nil t)
679 (progn
680 (narrow-to-region (point) (progn (end-of-line) (point)))
681 (goto-char (point-min))
682 (mail-parse-comma-list))))))))
683
684 (defun rmail-expunge-and-save ()
685 "Expunge and save RMAIL file."
686 (interactive)
687 (rmail-expunge)
688 (save-buffer)
689 (if (rmail-summary-exists)
690 (rmail-select-summary (set-buffer-modified-p nil))))
691
692 (defun rmail-quit ()
693 "Quit out of RMAIL."
694 (interactive)
695 (rmail-expunge-and-save)
696 ;; Don't switch to the summary buffer even if it was recently visible.
697 (if rmail-summary-buffer
698 (progn
699 (replace-buffer-in-windows rmail-summary-buffer)
700 (bury-buffer rmail-summary-buffer)))
701 (let ((obuf (current-buffer)))
702 (replace-buffer-in-windows obuf)
703 (bury-buffer obuf)))
704
705 ;;;###autoload
706 (defun rmail-input (filename)
707 "Run Rmail on file FILENAME."
708 (interactive "FRun rmail on RMAIL file: ")
709 (rmail filename))
710
711 (defun rmail-find-all-files (start)
712 (if (file-accessible-directory-p start)
713 (let ((files (directory-files start nil
714 rmail-secondary-file-regexp))
715 (ret nil))
716 (while files
717 (setq file (car files))
718 (setq files (cdr files))
719 (setq ret (cons
720 (rmail-find-all-files (concat start "/" file))
721 ret)))
722 (cons (file-name-nondirectory start) ret))
723 (file-name-nondirectory start)))
724
725 (defun rmail-list-to-menu (menu-name l action &optional full-name)
726 (let ((menu (make-sparse-keymap menu-name)))
727 (mapcar
728 (function (lambda (item)
729 (if (consp item)
730 (progn
731 (setq command
732 (rmail-list-to-menu (car item) (cdr item)
733 action
734 (if full-name
735 (concat full-name "/"
736 (car item))
737 (car item))))
738 (setq name (car item)))
739 (progn
740 (setq name item)
741 (setq command
742 (list 'lambda () '(interactive)
743 (list action
744 (expand-file-name
745 (if full-name
746 (concat full-name "/" item)
747 item)
748 rmail-secondary-file-directory))))))
749 (define-key menu (vector (intern name))
750 (cons name command))))
751 l)
752 menu))
753
754 (defun rmail-construct-io-menu ()
755 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
756 (if (listp files)
757 (progn
758 (define-key rmail-mode-map [menu-bar classify input-menu]
759 (cons "Input Rmail File"
760 (rmail-list-to-menu "Input Rmail File"
761 (cdr files)
762 'rmail-input)))
763 (define-key rmail-mode-map [menu-bar classify output-menu]
764 (cons "Output Rmail File"
765 (rmail-list-to-menu "Output Rmail File"
766 (cdr files)
767 'rmail-output-to-rmail-file)))))))
768
769 \f
770 ;;;; *** Rmail input ***
771
772 ;; RLK feature not added in this version:
773 ;; argument specifies inbox file or files in various ways.
774
775 (defun rmail-get-new-mail (&optional file-name)
776 "Move any new mail from this RMAIL file's inbox files.
777 The inbox files can be specified with the file's Mail: option. The
778 variable `rmail-primary-inbox-list' specifies the inboxes for your
779 primary RMAIL file if it has no Mail: option. By default, this is
780 your /usr/spool/mail/$USER.
781
782 You can also specify the file to get new mail from. In this case, the
783 file of new mail is not changed or deleted. Noninteractively, you can
784 pass the inbox file name as an argument. Interactively, a prefix
785 argument causes us to read a file name and use that file as the inbox.
786
787 This function runs `rmail-get-new-mail-hook' before saving the updated file."
788 (interactive
789 (list (if current-prefix-arg
790 (read-file-name "Get new mail from file: "))))
791 (or (verify-visited-file-modtime (current-buffer))
792 (progn
793 (find-file (buffer-file-name))
794 (setq buffer-read-only t)
795 (if (verify-visited-file-modtime (current-buffer))
796 (rmail-forget-messages))))
797 (rmail-maybe-set-message-counters)
798 (widen)
799 ;; Get rid of all undo records for this buffer.
800 (or (eq buffer-undo-list t)
801 (setq buffer-undo-list nil))
802 (unwind-protect
803 (let ((opoint (point))
804 (new-messages 0)
805 (delete-files ())
806 ;; If buffer has not changed yet, and has not been saved yet,
807 ;; don't replace the old backup file now.
808 (make-backup-files (and make-backup-files (buffer-modified-p)))
809 (buffer-read-only nil)
810 ;; Don't make undo records for what we do in getting mail.
811 (buffer-undo-list t))
812 (goto-char (point-max))
813 (skip-chars-backward " \t\n") ; just in case of brain damage
814 (delete-region (point) (point-max)) ; caused by require-final-newline
815 (save-excursion
816 (save-restriction
817 (narrow-to-region (point) (point))
818 ;; Read in the contents of the inbox files,
819 ;; renaming them as necessary,
820 ;; and adding to the list of files to delete eventually.
821 (if file-name
822 (rmail-insert-inbox-text (list file-name) nil)
823 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
824 ;; Scan the new text and convert each message to babyl format.
825 (goto-char (point-min))
826 (save-excursion
827 (setq new-messages (rmail-convert-to-babyl-format)))
828 (or (zerop new-messages)
829 (let (success)
830 (widen)
831 (search-backward "\n\^_" nil t)
832 (narrow-to-region (point) (point-max))
833 (goto-char (1+ (point-min)))
834 (rmail-count-new-messages)
835 (run-hooks 'rmail-get-new-mail-hook)
836 (save-buffer)))
837 ;; Delete the old files, now that babyl file is saved.
838 (while delete-files
839 (condition-case ()
840 ;; First, try deleting.
841 (condition-case ()
842 (delete-file (car delete-files))
843 (file-error
844 ;; If we can't delete it, truncate it.
845 (write-region (point) (point) (car delete-files))))
846 (file-error nil))
847 (setq delete-files (cdr delete-files)))))
848 (if (= new-messages 0)
849 (progn (goto-char opoint)
850 (if (or file-name rmail-inbox-list)
851 (message "(No new mail has arrived)")))
852 (if (rmail-summary-exists)
853 (rmail-select-summary
854 (rmail-update-summary)))
855 (message "%d new message%s read"
856 new-messages (if (= 1 new-messages) "" "s"))
857 (and (boundp 'display-time-string)
858 (stringp display-time-string)
859 (string-match " Mail" display-time-string)
860 (setq display-time-string
861 (concat
862 (substring display-time-string 0 (match-beginning 0))
863 (substring display-time-string (match-end 0))))
864 (force-mode-line-update 'all))))
865 ;; Don't leave the buffer screwed up if we get a disk-full error.
866 (rmail-show-message)))
867
868 (defun rmail-insert-inbox-text (files renamep)
869 (let (file tofile delete-files movemail popmail)
870 (while files
871 (setq file (file-truename
872 (expand-file-name (substitute-in-file-name (car files))))
873 ;;>> un*x specific <<
874 ;; The "+" used to be "~", which is an extremely poor choice;
875 ;; it might accidentally be deleted when space is low
876 ;; (as happened to me!).
877 tofile (concat file "+"))
878 ;; If getting from mail spool directory,
879 ;; use movemail to move rather than just renaming,
880 ;; so as to interlock with the mailer.
881 (setq movemail (string= (file-name-directory file)
882 (file-truename rmail-spool-directory))
883 popmail (string-match "^po:" (file-name-nondirectory file)))
884 (if popmail (setq file (file-name-nondirectory file)
885 renamep t))
886 (if movemail
887 (progn
888 (setq tofile (expand-file-name
889 ;; Generate name to move to from inbox name,
890 ;; in case of multiple inboxes that need moving.
891 (concat ".newmail-" (file-name-nondirectory file))
892 ;; Use the directory of this rmail file
893 ;; because it's a nuisance to use the homedir
894 ;; if that is on a full disk and this rmail
895 ;; file isn't.
896 (file-name-directory
897 (expand-file-name buffer-file-name))))
898 ;; On some systems, /usr/spool/mail/foo is a directory
899 ;; and the actual inbox is /usr/spool/mail/foo/foo.
900 (if (file-directory-p file)
901 (setq file (expand-file-name (user-login-name)
902 file)))))
903 (if popmail
904 (message "Getting mail from post office ...")
905 (if (or (and (file-exists-p tofile)
906 (/= 0 (nth 7 (file-attributes tofile))))
907 (and (file-exists-p file)
908 (/= 0 (nth 7 (file-attributes file)))))
909 (message "Getting mail from %s..." file)))
910 ;; Set TOFILE if have not already done so, and
911 ;; rename or copy the file FILE to TOFILE if and as appropriate.
912 (cond ((not renamep)
913 (setq tofile file))
914 ((or (file-exists-p tofile) (and (not popmail)
915 (not (file-exists-p file))))
916 nil)
917 ((and (not movemail) (not popmail))
918 ;; Try copying. If that fails (perhaps no space),
919 ;; rename instead.
920 (condition-case nil
921 (copy-file file tofile nil)
922 (error
923 ;; Third arg is t so we can replace existing file TOFILE.
924 (rename-file file tofile t)))
925 ;; Make the real inbox file empty.
926 ;; Leaving it deleted could cause lossage
927 ;; because mailers often won't create the file.
928 (condition-case ()
929 (write-region (point) (point) file)
930 (file-error nil)))
931 (t
932 (let ((errors nil))
933 (unwind-protect
934 (save-excursion
935 (setq errors (generate-new-buffer " *rmail loss*"))
936 (buffer-disable-undo errors)
937 (call-process
938 (or rmail-movemail-program
939 (expand-file-name "movemail" exec-directory))
940 nil errors nil file tofile)
941 (if (not (buffer-modified-p errors))
942 ;; No output => movemail won
943 nil
944 (set-buffer errors)
945 (subst-char-in-region (point-min) (point-max)
946 ?\n ?\ )
947 (goto-char (point-max))
948 (skip-chars-backward " \t")
949 (delete-region (point) (point-max))
950 (goto-char (point-min))
951 (if (looking-at "movemail: ")
952 (delete-region (point-min) (match-end 0)))
953 (beep t)
954 (message (concat "movemail: "
955 (buffer-substring (point-min)
956 (point-max))))
957 (sit-for 3)
958 nil))
959 (if errors (kill-buffer errors))))))
960 ;; At this point, TOFILE contains the name to read:
961 ;; Either the alternate name (if we renamed)
962 ;; or the actual inbox (if not renaming).
963 (if (file-exists-p tofile)
964 (let (size)
965 (goto-char (point-max))
966 (setq size (nth 1 (insert-file-contents tofile)))
967 (goto-char (point-max))
968 (or (= (preceding-char) ?\n)
969 (zerop size)
970 (insert ?\n))
971 (setq delete-files (cons tofile delete-files))))
972 (message "")
973 (setq files (cdr files)))
974 delete-files))
975
976 ;; the rmail-break-forwarded-messages feature is not implemented
977 (defun rmail-convert-to-babyl-format ()
978 (let ((count 0) start
979 (case-fold-search nil)
980 (invalid-input-resync
981 (function (lambda ()
982 (message "Invalid Babyl format in inbox!")
983 (sit-for 1)
984 ;; Try to get back in sync with a real message.
985 (if (re-search-forward
986 (concat mmdf-delim1 "\\|^From") nil t)
987 (beginning-of-line)
988 (goto-char (point-max)))))))
989 (goto-char (point-min))
990 (save-restriction
991 (while (not (eobp))
992 (cond ((looking-at "BABYL OPTIONS:");Babyl header
993 (if (search-forward "\n\^_" nil t)
994 ;; If we find the proper terminator, delete through there.
995 (delete-region (point-min) (point))
996 (funcall invalid-input-resync)
997 (delete-region (point-min) (point))))
998 ;; Babyl format message
999 ((looking-at "\^L")
1000 (or (search-forward "\n\^_" nil t)
1001 (funcall invalid-input-resync))
1002 (setq count (1+ count))
1003 ;; Make sure there is no extra white space after the ^_
1004 ;; at the end of the message.
1005 ;; Narrowing will make sure that whatever follows the junk
1006 ;; will be treated properly.
1007 (delete-region (point)
1008 (save-excursion
1009 (skip-chars-forward " \t\n")
1010 (point)))
1011 (narrow-to-region (point) (point-max)))
1012 ;;*** MMDF format
1013 ((let ((case-fold-search t))
1014 (looking-at mmdf-delim1))
1015 (let ((case-fold-search t))
1016 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1017 (setq start (point))
1018 (re-search-forward mmdf-delim2 nil t)
1019 (replace-match "\^_"))
1020 (save-excursion
1021 (save-restriction
1022 (narrow-to-region start (1- (point)))
1023 (goto-char (point-min))
1024 (while (search-forward "\n\^_" nil t); single char "\^_"
1025 (replace-match "\n^_")))); 2 chars: "^" and "_"
1026 (narrow-to-region (point) (point-max))
1027 (setq count (1+ count)))
1028 ;;*** Mail format
1029 ((looking-at "^From ")
1030 (setq start (point))
1031 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1032 (rmail-nuke-pinhead-header)
1033 ;; If this message has a Content-Length field,
1034 ;; skip to the end of the contents.
1035 (let* ((header-end (save-excursion
1036 (and (re-search-forward "\n\n" nil t)
1037 (1- (point)))))
1038 (case-fold-search t)
1039 (size
1040 ;; Get the numeric value from the Content-Length field.
1041 (save-excursion
1042 ;; Back up to end of prev line,
1043 ;; in case the Content-Length field comes first.
1044 (forward-char -1)
1045 (and (search-forward "\ncontent-length: "
1046 header-end t)
1047 (let ((beg (point))
1048 (eol (progn (end-of-line) (point))))
1049 (string-to-int (buffer-substring beg eol)))))))
1050 (and size
1051 (if (and (natnump size)
1052 (<= (+ header-end size) (point-max))
1053 ;; Make sure this would put us at a position
1054 ;; that we could continue from.
1055 (save-excursion
1056 (goto-char (+ header-end size))
1057 (skip-chars-forward "\n")
1058 (or (eobp)
1059 (and (looking-at "BABYL OPTIONS:")
1060 (search-forward "\n\^_" nil t))
1061 (and (looking-at "\^L")
1062 (search-forward "\n\^_" nil t))
1063 (let ((case-fold-search t))
1064 (looking-at mmdf-delim1))
1065 (looking-at "From "))))
1066 (goto-char (+ header-end size))
1067 (message "Ignoring invalid Content-Length field")
1068 (sit-for 1 0 t))))
1069
1070 (if (re-search-forward
1071 (concat "^[\^_]?\\("
1072 rmail-unix-mail-delimiter
1073 "\\|"
1074 mmdf-delim1 "\\|"
1075 "^BABYL OPTIONS:\\|"
1076 "\^L\n[01],\\)") nil t)
1077 (goto-char (match-beginning 1))
1078 (goto-char (point-max)))
1079 (setq count (1+ count))
1080 (save-excursion
1081 (save-restriction
1082 (narrow-to-region start (point))
1083 (goto-char (point-min))
1084 (while (search-forward "\n\^_" nil t); single char
1085 (replace-match "\n^_")))); 2 chars: "^" and "_"
1086 (insert ?\^_)
1087 (narrow-to-region (point) (point-max)))
1088 ;;
1089 ;; This kludge is because some versions of sendmail.el
1090 ;; insert an extra newline at the beginning that shouldn't
1091 ;; be there. sendmail.el has been fixed, but old versions
1092 ;; may still be in use. -- rms, 7 May 1993.
1093 ((eolp) (delete-char 1))
1094 (t (error "Cannot convert to babyl format")))))
1095 count))
1096
1097 ;; Delete the "From ..." line, creating various other headers with
1098 ;; information from it if they don't already exist. Now puts the
1099 ;; original line into a mail-from: header line for debugging and for
1100 ;; use by the rmail-output function.
1101 (defun rmail-nuke-pinhead-header ()
1102 (save-excursion
1103 (save-restriction
1104 (let ((start (point))
1105 (end (progn
1106 (condition-case ()
1107 (search-forward "\n\n")
1108 (error
1109 (goto-char (point-max))
1110 (insert "\n\n")))
1111 (point)))
1112 has-from has-date)
1113 (narrow-to-region start end)
1114 (let ((case-fold-search t))
1115 (goto-char start)
1116 (setq has-from (search-forward "\nFrom:" nil t))
1117 (goto-char start)
1118 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
1119 (goto-char start))
1120 (let ((case-fold-search nil))
1121 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
1122 (replace-match
1123 (concat
1124 "Mail-from: \\&"
1125 ;; Keep and reformat the date if we don't
1126 ;; have a Date: field.
1127 (if has-date
1128 ""
1129 (concat
1130 "Date: \\3, \\5 \\4 \\9 \\6 "
1131
1132 ;; The timezone could be matched by group 7 or group 10.
1133 ;; If neither of them matched, assume EST, since only
1134 ;; Easterners would be so sloppy.
1135 ;; It's a shame the substitution can't use "\\10".
1136 (cond
1137 ((/= (match-beginning 7) (match-end 7)) "\\7")
1138 ((/= (match-beginning 10) (match-end 10))
1139 (buffer-substring (match-beginning 10)
1140 (match-end 10)))
1141 (t "EST"))
1142 "\n"))
1143 ;; Keep and reformat the sender if we don't
1144 ;; have a From: field.
1145 (if has-from
1146 ""
1147 "From: \\1\n"))
1148 t)))))))
1149 \f
1150 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1151
1152 (defun rmail-reformat-message (beg end)
1153 (goto-char beg)
1154 (forward-line 1)
1155 (if (/= (following-char) ?0)
1156 (error "Bad format in RMAIL file."))
1157 (let ((buffer-read-only nil)
1158 (delta (- (buffer-size) end)))
1159 (delete-char 1)
1160 (insert ?1)
1161 (forward-line 1)
1162 (let ((case-fold-search t))
1163 (while (looking-at "Summary-line:\\|Mail-From:")
1164 (forward-line 1)))
1165 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1166 (delete-region (point)
1167 (progn (forward-line 1) (point))))
1168 (let ((str (buffer-substring (point)
1169 (save-excursion (search-forward "\n\n" end 'move)
1170 (point)))))
1171 (insert str "*** EOOH ***\n")
1172 (narrow-to-region (point) (- (buffer-size) delta)))
1173 (goto-char (point-min))
1174 (if rmail-message-filter (funcall rmail-message-filter))
1175 (if rmail-ignored-headers (rmail-clear-headers))))
1176
1177 (defun rmail-clear-headers (&optional ignored-headers)
1178 (or ignored-headers (setq ignored-headers rmail-ignored-headers))
1179 (if (search-forward "\n\n" nil t)
1180 (save-restriction
1181 (narrow-to-region (point-min) (point))
1182 (let ((buffer-read-only nil))
1183 (while (let ((case-fold-search t))
1184 (goto-char (point-min))
1185 (re-search-forward ignored-headers nil t))
1186 (beginning-of-line)
1187 (delete-region (point)
1188 (progn (re-search-forward "\n[^ \t]")
1189 (forward-char -1)
1190 (point))))))))
1191
1192 (defun rmail-toggle-header ()
1193 "Show original message header if pruned header currently shown, or vice versa."
1194 (interactive)
1195 (rmail-maybe-set-message-counters)
1196 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1197 (let ((buffer-read-only nil))
1198 (goto-char (point-min))
1199 (forward-line 1)
1200 (if (= (following-char) ?1)
1201 (progn (delete-char 1)
1202 (insert ?0)
1203 (forward-line 1)
1204 (let ((case-fold-search t))
1205 (while (looking-at "Summary-Line:\\|Mail-From:")
1206 (forward-line 1)))
1207 (insert "*** EOOH ***\n")
1208 (forward-char -1)
1209 (search-forward "\n*** EOOH ***\n")
1210 (forward-line -1)
1211 (let ((temp (point)))
1212 (and (search-forward "\n\n" nil t)
1213 (delete-region temp (point))))
1214 (goto-char (point-min))
1215 (search-forward "\n*** EOOH ***\n")
1216 (narrow-to-region (point) (point-max)))
1217 (rmail-reformat-message (point-min) (point-max))))
1218 (rmail-highlight-headers))
1219 \f
1220 ;;;; *** Rmail Attributes and Keywords ***
1221
1222 ;; Make a string describing current message's attributes and keywords
1223 ;; and set it up as the name of a minor mode
1224 ;; so it will appear in the mode line.
1225 (defun rmail-display-labels ()
1226 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1227 (save-excursion
1228 (unwind-protect
1229 (progn
1230 (widen)
1231 (goto-char (rmail-msgbeg rmail-current-message))
1232 (forward-line 1)
1233 (if (looking-at "[01],")
1234 (progn
1235 (narrow-to-region (point) (progn (end-of-line) (point)))
1236 ;; Truly valid BABYL format requires a space before each
1237 ;; attribute or keyword name. Put them in if missing.
1238 (let (buffer-read-only)
1239 (goto-char (point-min))
1240 (while (search-forward "," nil t)
1241 (or (looking-at "[ ,]") (eobp)
1242 (insert " "))))
1243 (goto-char (point-max))
1244 (if (search-backward ",," nil 'move)
1245 (progn
1246 (if (> (point) (1+ (point-min)))
1247 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
1248 (if (> (- (point-max) (point)) 2)
1249 (setq blurb
1250 (concat blurb
1251 ";"
1252 (buffer-substring (+ (point) 3)
1253 (1- (point-max)))))))))))
1254 ;; Note: we don't use save-restriction because that does not work right
1255 ;; if changes are made outside the saved restriction
1256 ;; before that restriction is restored.
1257 (narrow-to-region beg end)
1258 (set-marker beg nil)
1259 (set-marker end nil)))
1260 (while (string-match " +," blurb)
1261 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1262 (substring blurb (match-end 0)))))
1263 (while (string-match ", +" blurb)
1264 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1265 (substring blurb (match-end 0)))))
1266 (setq mode-line-process
1267 (concat " " rmail-current-message "/" rmail-total-messages
1268 blurb))))
1269
1270 ;; Turn an attribute of a message on or off according to STATE.
1271 ;; ATTR is the name of the attribute, as a string.
1272 ;; MSGNUM is message number to change; nil means current message.
1273 (defun rmail-set-attribute (attr state &optional msgnum)
1274 (let ((omax (point-max-marker))
1275 (omin (point-min-marker))
1276 (buffer-read-only nil))
1277 (or msgnum (setq msgnum rmail-current-message))
1278 (if (> msgnum 0)
1279 (unwind-protect
1280 (save-excursion
1281 (widen)
1282 (goto-char (+ 3 (rmail-msgbeg msgnum)))
1283 (let ((curstate
1284 (not
1285 (null (search-backward (concat ", " attr ",")
1286 (prog1 (point) (end-of-line)) t)))))
1287 (or (eq curstate (not (not state)))
1288 (if curstate
1289 (delete-region (point) (1- (match-end 0)))
1290 (beginning-of-line)
1291 (forward-char 2)
1292 (insert " " attr ","))))
1293 (if (string= attr "deleted")
1294 (rmail-set-message-deleted-p msgnum state)))
1295 ;; Note: we don't use save-restriction because that does not work right
1296 ;; if changes are made outside the saved restriction
1297 ;; before that restriction is restored.
1298 (narrow-to-region omin omax)
1299 (set-marker omin nil)
1300 (set-marker omax nil)
1301 (if (= msgnum rmail-current-message)
1302 (rmail-display-labels))))))
1303
1304 ;; Return t if the attributes/keywords line of msg number MSG
1305 ;; contains a match for the regexp LABELS.
1306 (defun rmail-message-labels-p (msg labels)
1307 (save-excursion
1308 (save-restriction
1309 (widen)
1310 (goto-char (rmail-msgbeg msg))
1311 (forward-char 3)
1312 (re-search-backward labels (prog1 (point) (end-of-line)) t))))
1313 \f
1314 ;;;; *** Rmail Message Selection And Support ***
1315
1316 (defun rmail-msgend (n)
1317 (marker-position (aref rmail-message-vector (1+ n))))
1318
1319 (defun rmail-msgbeg (n)
1320 (marker-position (aref rmail-message-vector n)))
1321
1322 (defun rmail-widen-to-current-msgbeg (function)
1323 "Call FUNCTION with point at start of internal data of current message.
1324 Assumes that bounds were previously narrowed to display the message in Rmail.
1325 The bounds are widened enough to move point where desired, then narrowed
1326 again afterward.
1327
1328 FUNCTION may not change the visible text of the message, but it may
1329 change the invisible header text."
1330 (save-excursion
1331 (let ((obeg (- (point-max) (point-min))))
1332 (unwind-protect
1333 (progn
1334 (narrow-to-region (rmail-msgbeg rmail-current-message)
1335 (point-max))
1336 (goto-char (point-min))
1337 (funcall function))
1338 ;; Note: we don't use save-restriction because that does not work right
1339 ;; if changes are made outside the saved restriction
1340 ;; before that restriction is restored.
1341 ;; Here we assume that changes made by FUNCTION
1342 ;; occur before the visible region of the message.
1343 (narrow-to-region (- (point-max) obeg) (point-max))))))
1344
1345 (defun rmail-forget-messages ()
1346 (unwind-protect
1347 (if (vectorp rmail-message-vector)
1348 (let* ((i 0)
1349 (v rmail-message-vector)
1350 (n (length v)))
1351 (while (< i n)
1352 (move-marker (aref v i) nil)
1353 (setq i (1+ i)))))
1354 (setq rmail-message-vector nil)
1355 (setq rmail-deleted-vector nil)))
1356
1357 (defun rmail-maybe-set-message-counters ()
1358 (if (not (and rmail-deleted-vector
1359 rmail-message-vector
1360 rmail-current-message
1361 rmail-total-messages))
1362 (rmail-set-message-counters)))
1363
1364 (defun rmail-count-new-messages (&optional nomsg)
1365 (let* ((case-fold-search nil)
1366 (total-messages 0)
1367 (messages-head nil)
1368 (deleted-head nil))
1369 (or nomsg (message "Counting new messages..."))
1370 (goto-char (point-max))
1371 ;; Put at the end of messages-head
1372 ;; the entry for message N+1, which marks
1373 ;; the end of message N. (N = number of messages).
1374 (search-backward "\n\^_")
1375 (forward-char 1)
1376 (setq messages-head (list (point-marker)))
1377 (rmail-set-message-counters-counter (point-min))
1378 (setq rmail-current-message (1+ rmail-total-messages))
1379 (setq rmail-total-messages
1380 (+ rmail-total-messages total-messages))
1381 (setq rmail-message-vector
1382 (vconcat rmail-message-vector (cdr messages-head)))
1383 (aset rmail-message-vector
1384 rmail-current-message (car messages-head))
1385 (setq rmail-deleted-vector
1386 (concat rmail-deleted-vector deleted-head))
1387 (setq rmail-summary-vector
1388 (vconcat rmail-summary-vector (make-vector total-messages nil)))
1389 (goto-char (point-min))
1390 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
1391
1392 (defun rmail-set-message-counters ()
1393 (rmail-forget-messages)
1394 (save-excursion
1395 (save-restriction
1396 (widen)
1397 (let* ((point-save (point))
1398 (total-messages 0)
1399 (messages-after-point)
1400 (case-fold-search nil)
1401 (messages-head nil)
1402 (deleted-head nil))
1403 (message "Counting messages...")
1404 (goto-char (point-max))
1405 ;; Put at the end of messages-head
1406 ;; the entry for message N+1, which marks
1407 ;; the end of message N. (N = number of messages).
1408 (search-backward "\n\^_" nil t)
1409 (if (/= (point) (point-max)) (forward-char 1))
1410 (setq messages-head (list (point-marker)))
1411 (rmail-set-message-counters-counter (min (point) point-save))
1412 (setq messages-after-point total-messages)
1413 (rmail-set-message-counters-counter)
1414 (setq rmail-total-messages total-messages)
1415 (setq rmail-current-message
1416 (min total-messages
1417 (max 1 (- total-messages messages-after-point))))
1418 (setq rmail-message-vector
1419 (apply 'vector (cons (point-min-marker) messages-head))
1420 rmail-deleted-vector (concat "D" deleted-head)
1421 rmail-summary-vector (make-vector rmail-total-messages nil))
1422 (message "Counting messages...done")))))
1423
1424 (defun rmail-set-message-counters-counter (&optional stop)
1425 (while (search-backward "\n\^_\^L\n" stop t)
1426 (forward-char 1)
1427 (setq messages-head (cons (point-marker) messages-head))
1428 (save-excursion
1429 (setq deleted-head
1430 (cons (if (search-backward ", deleted,"
1431 (prog1 (point)
1432 (forward-line 2))
1433 t)
1434 ?D ?\ )
1435 deleted-head)))
1436 (if (zerop (% (setq total-messages (1+ total-messages)) 20))
1437 (message "Counting messages...%d" total-messages))))
1438
1439 (defun rmail-beginning-of-message ()
1440 "Show current message starting from the beginning."
1441 (interactive)
1442 (rmail-show-message rmail-current-message))
1443
1444 (defun rmail-show-message (&optional n)
1445 "Show message number N (prefix argument), counting from start of file.
1446 If summary buffer is currently displayed, update current message there also."
1447 (interactive "p")
1448 (rmail-maybe-set-message-counters)
1449 (widen)
1450 (if (zerop rmail-total-messages)
1451 (progn (narrow-to-region (point-min) (1- (point-max)))
1452 (goto-char (point-min))
1453 (setq mode-line-process nil))
1454 (let (blurb)
1455 (if (not n)
1456 (setq n rmail-current-message)
1457 (cond ((<= n 0)
1458 (setq n 1
1459 rmail-current-message 1
1460 blurb "No previous message"))
1461 ((> n rmail-total-messages)
1462 (setq n rmail-total-messages
1463 rmail-current-message rmail-total-messages
1464 blurb "No following message"))
1465 (t
1466 (setq rmail-current-message n))))
1467 (let ((beg (rmail-msgbeg n))
1468 (end (rmail-msgend n)))
1469 (goto-char beg)
1470 (forward-line 1)
1471 (if (= (following-char) ?0)
1472 (progn
1473 (rmail-reformat-message beg end)
1474 (rmail-set-attribute "unseen" nil))
1475 (search-forward "\n*** EOOH ***\n" end t)
1476 (narrow-to-region (point) end))
1477 (goto-char (point-min))
1478 (rmail-display-labels)
1479 (rmail-highlight-headers)
1480 (if transient-mark-mode (deactivate-mark))
1481 (run-hooks 'rmail-show-message-hook)
1482 ;; If there is a summary buffer, try to move to this message
1483 ;; in that buffer. But don't complain if this message
1484 ;; is not mentioned in the summary.
1485 (if (rmail-summary-exists)
1486 (let ((curr-msg rmail-current-message))
1487 (rmail-select-summary
1488 (rmail-summary-goto-msg curr-msg t t))))
1489 (if blurb
1490 (message blurb))))))
1491
1492 ;; Find all occurrences of certain fields, and highlight them.
1493 (defun rmail-highlight-headers ()
1494 ;; Do this only if the system supports faces.
1495 (if (and (fboundp 'internal-find-face)
1496 rmail-highlighted-headers)
1497 (save-excursion
1498 (search-forward "\n\n" nil 'move)
1499 (save-restriction
1500 (narrow-to-region (point-min) (point))
1501 (let ((case-fold-search t)
1502 (inhibit-read-only t)
1503 ;; Highlight with boldface if that is available.
1504 ;; Otherwise use the `highlight' face.
1505 (face (or rmail-highlight-face
1506 (if (face-differs-from-default-p 'bold)
1507 'bold 'highlight)))
1508 ;; List of overlays to reuse.
1509 (overlays rmail-overlay-list))
1510 (goto-char (point-min))
1511 (while (re-search-forward rmail-highlighted-headers nil t)
1512 (skip-chars-forward " \t")
1513 (let ((beg (point))
1514 overlay)
1515 (while (progn (forward-line 1)
1516 (looking-at "[ \t]")))
1517 ;; Back up over newline, then trailing spaces or tabs
1518 (forward-char -1)
1519 (while (member (preceding-char) '(? ?\t))
1520 (forward-char -1))
1521 (if overlays
1522 ;; Reuse an overlay we already have.
1523 (progn
1524 (setq overlay (car overlays)
1525 overlays (cdr overlays))
1526 (overlay-put overlay 'face face)
1527 (move-overlay overlay beg (point)))
1528 ;; Make a new overlay and add it to
1529 ;; rmail-overlay-list.
1530 (setq overlay (make-overlay beg (point)))
1531 (overlay-put overlay 'face face)
1532 (setq rmail-overlay-list
1533 (cons overlay rmail-overlay-list))))))))))
1534
1535 (defun rmail-next-message (n)
1536 "Show following message whether deleted or not.
1537 With prefix arg N, moves forward N messages, or backward if N is negative."
1538 (interactive "p")
1539 (rmail-maybe-set-message-counters)
1540 (rmail-show-message (+ rmail-current-message n)))
1541
1542 (defun rmail-previous-message (n)
1543 "Show previous message whether deleted or not.
1544 With prefix arg N, moves backward N messages, or forward if N is negative."
1545 (interactive "p")
1546 (rmail-next-message (- n)))
1547
1548 (defun rmail-next-undeleted-message (n)
1549 "Show following non-deleted message.
1550 With prefix arg N, moves forward N non-deleted messages,
1551 or backward if N is negative.
1552
1553 Returns t if a new message is being shown, nil otherwise."
1554 (interactive "p")
1555 (rmail-maybe-set-message-counters)
1556 (let ((lastwin rmail-current-message)
1557 (current rmail-current-message))
1558 (while (and (> n 0) (< current rmail-total-messages))
1559 (setq current (1+ current))
1560 (if (not (rmail-message-deleted-p current))
1561 (setq lastwin current n (1- n))))
1562 (while (and (< n 0) (> current 1))
1563 (setq current (1- current))
1564 (if (not (rmail-message-deleted-p current))
1565 (setq lastwin current n (1+ n))))
1566 (if (/= lastwin rmail-current-message)
1567 (progn (rmail-show-message lastwin)
1568 t)
1569 (if (< n 0)
1570 (message "No previous nondeleted message"))
1571 (if (> n 0)
1572 (message "No following nondeleted message"))
1573 nil)))
1574
1575 (defun rmail-previous-undeleted-message (n)
1576 "Show previous non-deleted message.
1577 With prefix argument N, moves backward N non-deleted messages,
1578 or forward if N is negative."
1579 (interactive "p")
1580 (rmail-next-undeleted-message (- n)))
1581
1582 (defun rmail-first-message ()
1583 "Show first message in file."
1584 (interactive)
1585 (rmail-maybe-set-message-counters)
1586 (rmail-show-message 1))
1587
1588 (defun rmail-last-message ()
1589 "Show last message in file."
1590 (interactive)
1591 (rmail-maybe-set-message-counters)
1592 (rmail-show-message rmail-total-messages))
1593
1594 (defun rmail-what-message ()
1595 (let ((where (point))
1596 (low 1)
1597 (high rmail-total-messages)
1598 (mid (/ rmail-total-messages 2)))
1599 (while (> (- high low) 1)
1600 (if (>= where (rmail-msgbeg mid))
1601 (setq low mid)
1602 (setq high mid))
1603 (setq mid (+ low (/ (- high low) 2))))
1604 (if (>= where (rmail-msgbeg high)) high low)))
1605
1606 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
1607 (save-restriction
1608 (goto-char (rmail-msgbeg msg))
1609 (search-forward "\n*** EOOH ***\n")
1610 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
1611 (or (string-match recipients (or (mail-fetch-field "To") ""))
1612 (string-match recipients (or (mail-fetch-field "From") ""))
1613 (if (not primary-only)
1614 (string-match recipients (or (mail-fetch-field "Cc") ""))))))
1615
1616 (defun rmail-message-regexp-p (msg regexp)
1617 "Return t, if for message number MSG, regexp REGEXP matches in the header."
1618 (goto-char (rmail-msgbeg msg))
1619 (let ((end
1620 (save-excursion
1621 (search-forward "*** EOOH ***" (point-max)) (point))))
1622 (re-search-forward regexp end t)))
1623
1624 (defun rmail-search-backward (regexp &optional n)
1625 "Show message containing next match for REGEXP.
1626 Prefix argument gives repeat count; negative argument means search
1627 backwards (through earlier messages).
1628 Interactively, empty argument means use same regexp used last time."
1629 (interactive
1630 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1631 (prompt
1632 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1633 regexp)
1634 (if rmail-search-last-regexp
1635 (setq prompt (concat prompt
1636 "(default "
1637 rmail-search-last-regexp
1638 ") ")))
1639 (setq regexp (read-string prompt))
1640 (cond ((not (equal regexp ""))
1641 (setq rmail-search-last-regexp regexp))
1642 ((not rmail-search-last-regexp)
1643 (error "No previous Rmail search string")))
1644 (list rmail-search-last-regexp
1645 (prefix-numeric-value current-prefix-arg))))
1646 (rmail-search regexp (- n)))
1647
1648 (defvar rmail-search-last-regexp nil)
1649 (defun rmail-search (regexp &optional n)
1650 "Show message containing next match for REGEXP.
1651 Prefix argument gives repeat count; negative argument means search
1652 backwards (through earlier messages).
1653 Interactively, empty argument means use same regexp used last time."
1654 (interactive
1655 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1656 (prompt
1657 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1658 regexp)
1659 (if rmail-search-last-regexp
1660 (setq prompt (concat prompt
1661 "(default "
1662 rmail-search-last-regexp
1663 ") ")))
1664 (setq regexp (read-string prompt))
1665 (cond ((not (equal regexp ""))
1666 (setq rmail-search-last-regexp regexp))
1667 ((not rmail-search-last-regexp)
1668 (error "No previous Rmail search string")))
1669 (list rmail-search-last-regexp
1670 (prefix-numeric-value current-prefix-arg))))
1671 (or n (setq n 1))
1672 (message "%sRmail search for %s..."
1673 (if (< n 0) "Reverse " "")
1674 regexp)
1675 (rmail-maybe-set-message-counters)
1676 (let ((omin (point-min))
1677 (omax (point-max))
1678 (opoint (point))
1679 win
1680 (reversep (< n 0))
1681 (msg rmail-current-message))
1682 (unwind-protect
1683 (progn
1684 (widen)
1685 (while (/= n 0)
1686 ;; Check messages one by one, advancing message number up or down
1687 ;; but searching forward through each message.
1688 (if reversep
1689 (while (and (null win) (> msg 1))
1690 (goto-char (rmail-msgbeg (setq msg (1- msg))))
1691 (setq win (re-search-forward
1692 regexp (rmail-msgend msg) t)))
1693 (while (and (null win) (< msg rmail-total-messages))
1694 (goto-char (rmail-msgbeg (setq msg (1+ msg))))
1695 (setq win (re-search-forward regexp (rmail-msgend msg) t))))
1696 (setq n (+ n (if reversep 1 -1)))))
1697 (if win
1698 (progn
1699 ;; If this is a reverse search and we found a message,
1700 ;; search backward thru this message to position point.
1701 (if reversep
1702 (progn
1703 (goto-char (rmail-msgend msg))
1704 (re-search-backward
1705 regexp (rmail-msgbeg msg) t)))
1706 (setq win (point))
1707 (rmail-show-message msg)
1708 (message "%sRmail search for %s...done"
1709 (if reversep "Reverse " "")
1710 regexp)
1711 (goto-char win))
1712 (goto-char opoint)
1713 (narrow-to-region omin omax)
1714 (ding)
1715 (message "Search failed: %s" regexp)))))
1716
1717 (defun rmail-search-backwards (regexp &optional n)
1718 "Show message containing previous match for REGEXP.
1719 Prefix argument gives repeat count; negative argument means search
1720 forward (through later messages).
1721 Interactively, empty argument means use same regexp used last time."
1722 (interactive
1723 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1724 (prompt
1725 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1726 regexp)
1727 (if rmail-search-last-regexp
1728 (setq prompt (concat prompt
1729 "(default "
1730 rmail-search-last-regexp
1731 ") ")))
1732 (setq regexp (read-string prompt))
1733 (cond ((not (equal regexp ""))
1734 (setq rmail-search-last-regexp regexp))
1735 ((not rmail-search-last-regexp)
1736 (error "No previous Rmail search string")))
1737 (list rmail-search-last-regexp
1738 (prefix-numeric-value current-prefix-arg))))
1739 (rmail-search regexp (- (or n -1))))
1740
1741 ;; Show the first message which has the `unseen' attribute.
1742 (defun rmail-first-unseen-message ()
1743 (rmail-maybe-set-message-counters)
1744 (let ((current 1)
1745 found)
1746 (save-restriction
1747 (widen)
1748 (while (and (not found) (< current rmail-total-messages))
1749 (if (rmail-message-labels-p current ", ?\\(unseen\\),")
1750 (setq found current))
1751 (setq current (1+ current))))
1752 ;; Let the caller show the message.
1753 ;; (if found
1754 ;; (rmail-show-message found))
1755 found))
1756 \f
1757 ;;;; *** Rmail Message Deletion Commands ***
1758
1759 (defun rmail-message-deleted-p (n)
1760 (= (aref rmail-deleted-vector n) ?D))
1761
1762 (defun rmail-set-message-deleted-p (n state)
1763 (aset rmail-deleted-vector n (if state ?D ?\ )))
1764
1765 (defun rmail-delete-message ()
1766 "Delete this message and stay on it."
1767 (interactive)
1768 (rmail-set-attribute "deleted" t))
1769
1770 (defun rmail-undelete-previous-message ()
1771 "Back up to deleted message, select it, and undelete it."
1772 (interactive)
1773 (let ((msg rmail-current-message))
1774 (while (and (> msg 0)
1775 (not (rmail-message-deleted-p msg)))
1776 (setq msg (1- msg)))
1777 (if (= msg 0)
1778 (error "No previous deleted message")
1779 (if (/= msg rmail-current-message)
1780 (rmail-show-message msg))
1781 (rmail-set-attribute "deleted" nil)
1782 (if (rmail-summary-exists)
1783 (save-excursion
1784 (set-buffer rmail-summary-buffer)
1785 (rmail-summary-mark-undeleted msg)))
1786 (rmail-maybe-display-summary))))
1787
1788 (defun rmail-delete-forward (&optional backward)
1789 "Delete this message and move to next nondeleted one.
1790 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
1791 With prefix argument, delete and move backward.
1792
1793 Returns t if a new message is displayed after the delete, or nil otherwise."
1794 (interactive "P")
1795 (rmail-set-attribute "deleted" t)
1796 (let ((del-msg rmail-current-message))
1797 (if (rmail-summary-exists)
1798 (rmail-select-summary
1799 (rmail-summary-mark-deleted del-msg)))
1800 (prog1 (rmail-next-undeleted-message (if backward -1 1))
1801 (rmail-maybe-display-summary))))
1802
1803 (defun rmail-delete-backward ()
1804 "Delete this message and move to previous nondeleted one.
1805 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
1806 (interactive)
1807 (rmail-delete-forward t))
1808
1809 ;; Compute the message number a given message would have after expunging.
1810 ;; The present number of the message is OLDNUM.
1811 ;; DELETEDVEC should be rmail-deleted-vector.
1812 ;; The value is nil for a message that would be deleted.
1813 (defun rmail-msg-number-after-expunge (deletedvec oldnum)
1814 (if (or (null oldnum) (= (aref deletedvec oldnum) ?D))
1815 nil
1816 (let ((i 0)
1817 (newnum 0))
1818 (while (< i oldnum)
1819 (if (/= (aref deletedvec i) ?D)
1820 (setq newnum (1+ newnum)))
1821 (setq i (1+ i)))
1822 newnum)))
1823
1824 (defun rmail-only-expunge ()
1825 "Actually erase all deleted messages in the file."
1826 (interactive)
1827 (message "Expunging deleted messages...")
1828 ;; Discard all undo records for this buffer.
1829 (or (eq buffer-undo-list t)
1830 (setq buffer-undo-list nil))
1831 (rmail-maybe-set-message-counters)
1832 (let* ((omax (- (buffer-size) (point-max)))
1833 (omin (- (buffer-size) (point-min)))
1834 (opoint (if (and (> rmail-current-message 0)
1835 (rmail-message-deleted-p rmail-current-message))
1836 0
1837 (- (point) (point-min))))
1838 (messages-head (cons (aref rmail-message-vector 0) nil))
1839 (messages-tail messages-head)
1840 ;; Don't make any undo records for the expunging.
1841 (buffer-undo-list t)
1842 (win))
1843 (unwind-protect
1844 (save-excursion
1845 (widen)
1846 (goto-char (point-min))
1847 (let ((counter 0)
1848 (number 1)
1849 (total rmail-total-messages)
1850 (new-message-number rmail-current-message)
1851 (new-summary nil)
1852 (rmailbuf (current-buffer))
1853 (buffer-read-only nil)
1854 (messages rmail-message-vector)
1855 (deleted rmail-deleted-vector)
1856 (summary rmail-summary-vector))
1857 (setq rmail-total-messages nil
1858 rmail-current-message nil
1859 rmail-message-vector nil
1860 rmail-deleted-vector nil
1861 rmail-summary-vector nil)
1862
1863 ;; Find each sendmail buffer that is set to reply
1864 ;; to a message in this buffer, and update its
1865 ;; message number.
1866 (let ((bufs (buffer-list)))
1867 (while bufs
1868 (save-excursion
1869 (set-buffer (car bufs))
1870 (and (boundp 'rmail-send-actions-rmail-buffer)
1871 (eq rmail-send-actions-rmail-buffer rmailbuf)
1872 (setq rmail-send-actions-rmail-msg-number
1873 (rmail-msg-number-after-expunge
1874 deleted
1875 rmail-send-actions-rmail-msg-number))))
1876 (setq bufs (cdr bufs))))
1877
1878 (while (<= number total)
1879 (if (= (aref deleted number) ?D)
1880 (progn
1881 (delete-region
1882 (marker-position (aref messages number))
1883 (marker-position (aref messages (1+ number))))
1884 (move-marker (aref messages number) nil)
1885 (if (> new-message-number counter)
1886 (setq new-message-number (1- new-message-number))))
1887 (setq counter (1+ counter))
1888 (setq messages-tail
1889 (setcdr messages-tail
1890 (cons (aref messages number) nil)))
1891 (setq new-summary
1892 (cons (if (= counter number) (aref summary (1- number)))
1893 new-summary)))
1894 (if (zerop (% (setq number (1+ number)) 20))
1895 (message "Expunging deleted messages...%d" number)))
1896 (setq messages-tail
1897 (setcdr messages-tail
1898 (cons (aref messages number) nil)))
1899 (setq rmail-current-message new-message-number
1900 rmail-total-messages counter
1901 rmail-message-vector (apply 'vector messages-head)
1902 rmail-deleted-vector (make-string (1+ counter) ?\ )
1903 rmail-summary-vector (vconcat (nreverse new-summary))
1904 win t)))
1905 (message "Expunging deleted messages...done")
1906 (if (not win)
1907 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
1908 (rmail-show-message
1909 (if (zerop rmail-current-message) 1 nil))
1910 (forward-char opoint))))
1911
1912 (defun rmail-expunge ()
1913 "Erase deleted messages from Rmail file and summary buffer."
1914 (interactive)
1915 (rmail-only-expunge)
1916 (if (rmail-summary-exists)
1917 (rmail-select-summary
1918 (rmail-update-summary))))
1919 \f
1920 ;;;; *** Rmail Mailing Commands ***
1921
1922 (defun rmail-start-mail (&rest args)
1923 (if (and window-system rmail-mail-new-frame)
1924 (prog1
1925 (apply 'mail-other-frame args)
1926 (modify-frame-parameters (selected-frame)
1927 '((dedicated . t))))
1928 (apply 'mail-other-window args)))
1929
1930 (defun rmail-mail ()
1931 "Send mail in another window.
1932 While composing the message, use \\[mail-yank-original] to yank the
1933 original message into it."
1934 (interactive)
1935 (rmail-start-mail nil nil nil nil nil (current-buffer)))
1936
1937 (defun rmail-continue ()
1938 "Continue composing outgoing message previously being composed."
1939 (interactive)
1940 (rmail-start-mail t))
1941
1942 (defun rmail-reply (just-sender)
1943 "Reply to the current message.
1944 Normally include CC: to all other recipients of original message;
1945 prefix argument means ignore them. While composing the reply,
1946 use \\[mail-yank-original] to yank the original message into it."
1947 (interactive "P")
1948 (let (from reply-to cc subject date to message-id resent-reply-to
1949 (msgnum rmail-current-message)
1950 (rmail-buffer (current-buffer)))
1951 (save-excursion
1952 (save-restriction
1953 (widen)
1954 (goto-char (rmail-msgbeg rmail-current-message))
1955 (forward-line 1)
1956 (if (= (following-char) ?0)
1957 (narrow-to-region
1958 (progn (forward-line 2)
1959 (point))
1960 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
1961 'move)
1962 (point)))
1963 (narrow-to-region (point)
1964 (progn (search-forward "\n*** EOOH ***\n")
1965 (beginning-of-line) (point))))
1966 (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
1967 from (mail-fetch-field "from")
1968 reply-to (or resent-reply-to
1969 (mail-fetch-field "reply-to" nil t)
1970 from)
1971 cc (cond (just-sender nil)
1972 (resent-reply-to (mail-fetch-field "resent-cc" t))
1973 (t (mail-fetch-field "cc" nil t)))
1974 subject (or (and resent-reply-to
1975 (mail-fetch-field "resent-subject" t))
1976 (mail-fetch-field "subject"))
1977 date (or (and resent-reply-to
1978 (mail-fetch-field "resent-date" t))
1979 (mail-fetch-field "date"))
1980 to (cond (resent-reply-to
1981 (or (mail-fetch-field "resent-to" t)) "")
1982 ((mail-fetch-field "to" nil t))
1983 ;((mail-fetch-field "apparently-to")) ack gag barf
1984 (t ""))
1985 message-id (cond (resent-reply-to
1986 (mail-fetch-field "resent-message-id" t))
1987 ((mail-fetch-field "message-id"))))))
1988 (and (stringp subject)
1989 (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
1990 subject)
1991 (setq subject (concat rmail-reply-prefix subject))))
1992 (rmail-start-mail nil
1993 (mail-strip-quoted-names reply-to)
1994 subject
1995 (rmail-make-in-reply-to-field from date message-id)
1996 (if just-sender
1997 nil
1998 (let* ((cc-list (rmail-dont-reply-to
1999 (mail-strip-quoted-names
2000 (if (null cc) to (concat to ", " cc))))))
2001 (if (string= cc-list "") nil cc-list)))
2002 (current-buffer)
2003 (list (list '(lambda ()
2004 (let ((msgnum rmail-send-actions-rmail-msg-number))
2005 (save-excursion
2006 (set-buffer rmail-send-actions-rmail-buffer)
2007 (if msgnum
2008 (rmail-set-attribute "answered" t msgnum))))))))
2009 ;; We keep the rmail buffer and message number in these
2010 ;; buffer-local vars in the sendmail buffer,
2011 ;; so that rmail-only-expunge can relocate the message number.
2012 (make-local-variable 'rmail-send-actions-rmail-buffer)
2013 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2014 (setq rmail-send-actions-rmail-buffer rmail-buffer)
2015 (setq rmail-send-actions-rmail-msg-number msgnum)))
2016
2017 (defun rmail-make-in-reply-to-field (from date message-id)
2018 (cond ((not from)
2019 (if message-id
2020 message-id
2021 nil))
2022 (mail-use-rfc822
2023 (require 'rfc822)
2024 (let ((tem (car (rfc822-addresses from))))
2025 (if message-id
2026 (if (string-match
2027 (regexp-quote (if (string-match "@[^@]*\\'" tem)
2028 (substring tem 0 (match-beginning 0))
2029 tem))
2030 message-id)
2031 ;; Message-ID is sufficiently informative
2032 message-id
2033 (concat message-id " (" tem ")"))
2034 ;; Copy TEM, discarding text properties.
2035 (setq tem (copy-sequence tem))
2036 (set-text-properties 0 (length tem) nil tem)
2037 (setq tem (copy-sequence tem))
2038 ;; Use prin1 to fake RFC822 quoting
2039 (let ((field (prin1-to-string tem)))
2040 (if date
2041 (concat field "'s message of " date)
2042 field)))))
2043 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
2044 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
2045 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
2046 (or (string-match (concat "\\`[ \t]*\\(" bar
2047 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
2048 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
2049 from)
2050 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
2051 bar "\\))[ \t]*\\'")
2052 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
2053 from)))
2054 (let ((start (match-beginning 1))
2055 (end (match-end 1)))
2056 ;; Trim whitespace which above regexp match allows
2057 (while (and (< start end)
2058 (memq (aref from start) '(?\t ?\ )))
2059 (setq start (1+ start)))
2060 (while (and (< start end)
2061 (memq (aref from (1- end)) '(?\t ?\ )))
2062 (setq end (1- end)))
2063 (let ((field (substring from start end)))
2064 (if date (setq field (concat "message from " field " on " date)))
2065 (if message-id
2066 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
2067 (concat message-id " (" field ")")
2068 field))))
2069 (t
2070 ;; If we can't kludge it simply, do it correctly
2071 (let ((mail-use-rfc822 t))
2072 (rmail-make-in-reply-to-field from date message-id)))))
2073
2074 (defun rmail-forward (resend)
2075 "Forward the current message to another user.
2076 With prefix argument, \"resend\" the message instead of forwarding it;
2077 see the documentation of `rmail-resend'."
2078 (interactive "P")
2079 (if resend
2080 (call-interactively 'rmail-resend)
2081 (let ((forward-buffer (current-buffer))
2082 (msgnum rmail-current-message)
2083 (subject (concat "["
2084 (let ((from (or (mail-fetch-field "From")
2085 (mail-fetch-field ">From"))))
2086 (if from
2087 (concat (mail-strip-quoted-names from) ": ")
2088 ""))
2089 (or (mail-fetch-field "Subject") "")
2090 "]")))
2091 ;; If only one window, use it for the mail buffer.
2092 ;; Otherwise, use another window for the mail buffer
2093 ;; so that the Rmail buffer remains visible
2094 ;; and sending the mail will get back to it.
2095 (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
2096 (function mail)
2097 (function rmail-start-mail))
2098 nil nil subject nil nil nil
2099 (list (list (function
2100 (lambda ()
2101 (let ((msgnum
2102 rmail-send-actions-rmail-msg-number))
2103 (save-excursion
2104 (set-buffer rmail-send-actions-rmail-buffer)
2105 (if msgnum
2106 (rmail-set-attribute
2107 "forwarded" t msgnum)))))))))
2108 ;; The mail buffer is now current.
2109 (save-excursion
2110 ;; We keep the rmail buffer and message number in these
2111 ;; buffer-local vars in the sendmail buffer,
2112 ;; so that rmail-only-expunge can relocate the message number.
2113 (make-local-variable 'rmail-send-actions-rmail-buffer)
2114 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2115 (setq rmail-send-actions-rmail-buffer forward-buffer)
2116 (setq rmail-send-actions-rmail-msg-number msgnum)
2117 ;; Insert after header separator--before signature if any.
2118 (goto-char (point-min))
2119 (search-forward-regexp
2120 (concat "^" (regexp-quote mail-header-separator) "$"))
2121 (forward-line 1)
2122 (insert "------- Start of forwarded message -------\n")
2123 (insert-buffer-substring forward-buffer)
2124 (insert "------- End of forwarded message -------\n")
2125 (push-mark))))))
2126
2127 (defun rmail-resend (address &optional from comment mail-alias-file)
2128 "Resend current message to ADDRESSES.
2129 ADDRESSES should be a single address, a string consisting of several
2130 addresses separated by commas, or a list of addresses.
2131
2132 Optional FROM is the address to resend the message from, and
2133 defaults to the username of the person redistributing the message.
2134 Optional COMMENT is a string that will be inserted as a comment in the
2135 resent message.
2136 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2137 typically for purposes of moderating a list."
2138 (interactive "sResend to: ")
2139 (require 'sendmail)
2140 (require 'mailalias)
2141 (if (not from) (setq from (user-login-name)))
2142 (let ((tembuf (generate-new-buffer " sendmail temp"))
2143 (mail-header-separator "")
2144 (case-fold-search nil)
2145 (mailbuf (current-buffer)))
2146 (unwind-protect
2147 (save-excursion
2148 ;;>> Copy message into temp buffer
2149 (set-buffer tembuf)
2150 (insert-buffer-substring mailbuf)
2151 (goto-char (point-min))
2152 ;; Delete any Sender field, since that's not specifyable.
2153 ; Only delete Sender fields in the actual header.
2154 (re-search-forward "^$" nil 'move)
2155 ; Using "while" here rather than "if" because some buggy mail
2156 ; software may have inserted multiple Sender fields.
2157 (while (re-search-backward "^Sender:" nil t)
2158 (let (beg)
2159 (setq beg (point))
2160 (forward-line 1)
2161 (while (looking-at "[ \t]")
2162 (forward-line 1))
2163 (delete-region beg (point))))
2164 ; Go back to the beginning of the buffer so the Resent- fields
2165 ; are inserted there.
2166 (goto-char (point-min))
2167 ;;>> Insert resent-from:
2168 (insert "Resent-From: " from "\n")
2169 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2170 ;;>> Insert resent-to: and bcc if need be.
2171 (let ((before (point)))
2172 (if mail-self-blind
2173 (insert "Resent-Bcc: " (user-login-name) "\n"))
2174 (insert "Resent-To: " (if (stringp address)
2175 address
2176 (mapconcat 'identity address ",\n\t"))
2177 "\n")
2178 (save-excursion
2179 (expand-mail-aliases before (point))))
2180 ;;>> Set up comment, if any.
2181 (if (and (sequencep comment) (not (zerop (length comment))))
2182 (let ((before (point))
2183 after)
2184 (insert comment)
2185 (or (eolp) (insert "\n"))
2186 (setq after (point))
2187 (goto-char before)
2188 (while (< (point) after)
2189 (insert "Resent-Comment: ")
2190 (forward-line 1))))
2191 ;; Don't expand aliases in the destination fields
2192 ;; of the original message.
2193 (let (mail-aliases)
2194 (funcall send-mail-function)))
2195 (kill-buffer tembuf))
2196 (rmail-set-attribute "resent" t rmail-current-message)))
2197
2198 (defvar mail-unsent-separator
2199 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
2200 "^ *---+ +Returned message +---+ *$\\|"
2201 "^ *---+ +Original message +---+ *$\\|"
2202 "^ *--+ +begin message +--+ *$\\|"
2203 "^ *---+ +Original message follows +---+ *$\\|"
2204 "^|? *---+ +Message text follows: +---+ *|?$")
2205 "A regexp that matches the separator before the text of a failed message.")
2206
2207 (defun rmail-retry-failure ()
2208 "Edit a mail message which is based on the contents of the current message.
2209 For a message rejected by the mail system, extract the interesting headers and
2210 the body of the original message.
2211 The variable `mail-unsent-separator' should match the string that
2212 delimits the returned original message.
2213 The variable `rmail-retry-ignored-headers' is a regular expression
2214 specifying headers which should not be copied into the new message."
2215 (interactive)
2216 (require 'mail-utils)
2217 (let (mail-buffer bounce-start bounce-end resending)
2218 (save-excursion
2219 ;; Narrow down to just the quoted original message
2220 (rmail-beginning-of-message)
2221 (let ((case-fold-search t))
2222 (or (re-search-forward mail-unsent-separator nil t)
2223 (error "Cannot parse this as a failure message")))
2224 (save-restriction
2225 (let ((old-end (point-max)))
2226 ;; One message contained a few random lines before the old
2227 ;; message header. The first line of the message started with
2228 ;; two hyphens. A blank line follows these random lines.
2229 (skip-chars-forward "\n")
2230 (if (looking-at "^--")
2231 (progn
2232 (search-forward "\n\n")
2233 (skip-chars-forward "\n")))
2234 (beginning-of-line)
2235 (narrow-to-region (point) (point-max))
2236 (setq mail-buffer (current-buffer)
2237 bounce-start (point)
2238 bounce-end (point-max))
2239 (or (search-forward "\n\n" nil t)
2240 (error "Cannot find end of header in failed message")))))
2241 ;; Start sending a new message; default header fields from the original.
2242 ;; Turn off the usual actions for initializing the message body
2243 ;; because we want to get only the text from the failure message.
2244 (let (mail-signature mail-setup-hook)
2245 (if (rmail-start-mail nil nil nil nil nil mail-buffer)
2246 ;; Insert original text as initial text of new draft message.
2247 (progn
2248 (erase-buffer)
2249 (insert-buffer-substring mail-buffer bounce-start bounce-end)
2250 (goto-char (point-min))
2251 (rmail-clear-headers rmail-retry-ignored-headers)
2252 (rmail-clear-headers "^sender:")
2253 (goto-char (point-min))
2254 (save-restriction
2255 (search-forward "\n\n")
2256 (forward-line -1)
2257 (narrow-to-region (point-min) (point))
2258 (setq resending (mail-fetch-field "resent-to"))
2259 (if mail-self-blind
2260 (if resending
2261 (insert "Resent-Bcc: " (user-login-name) "\n")
2262 (insert "BCC: " (user-login-name) "\n"))))
2263 (insert mail-header-separator)
2264 (mail-position-on-field (if resending "Resent-To" "To") t)
2265 (set-buffer mail-buffer)
2266 (rmail-beginning-of-message))))))
2267
2268 (defun rmail-bury ()
2269 "Bury current Rmail buffer and its summary buffer."
2270 (interactive)
2271 ;; This let var was called rmail-buffer, but that interfered
2272 ;; with the buffer-local var used in summary buffers.
2273 (let ((buffer-to-bury (current-buffer)))
2274 (if (rmail-summary-exists)
2275 (let (window)
2276 (while (setq window (get-buffer-window rmail-summary-buffer))
2277 (set-window-buffer window (other-buffer rmail-summary-buffer)))
2278 (bury-buffer rmail-summary-buffer)))
2279 (switch-to-buffer (other-buffer (current-buffer)))
2280 (bury-buffer buffer-to-bury)))
2281
2282 (defun rmail-summary-exists ()
2283 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
2284 In fact, the non-nil value returned is the summary buffer itself."
2285 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2286 rmail-summary-buffer))
2287
2288 (defun rmail-summary-displayed ()
2289 "t iff in RMAIL buffer and an associated summary buffer is displayed."
2290 (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
2291
2292 (defvar rmail-redisplay-summary nil
2293 "*Non-nil means Rmail should show the summary when it changes.
2294 This has an effect only if a summary buffer exists.")
2295
2296 (defvar rmail-summary-window-size nil
2297 "*Non-nil means specify the height for an Rmail summary window.")
2298
2299 ;; Put the summary buffer back on the screen, if user wants that.
2300 (defun rmail-maybe-display-summary ()
2301 (let ((selected (selected-window))
2302 window)
2303 ;; If requested, make sure the summary is displayed.
2304 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2305 rmail-redisplay-summary
2306 (if (get-buffer-window rmail-summary-buffer 0)
2307 ;; It's already in some frame; show that one.
2308 (let ((frame (window-frame
2309 (get-buffer-window rmail-summary-buffer 0))))
2310 (make-frame-visible frame)
2311 (raise-frame frame))
2312 (display-buffer rmail-summary-buffer)))
2313 ;; If requested, set the height of the summary window.
2314 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2315 rmail-summary-window-size
2316 (setq window (get-buffer-window rmail-summary-buffer))
2317 ;; Don't try to change the size if just one window in frame.
2318 (not (eq window (frame-root-window (window-frame window))))
2319 (unwind-protect
2320 (progn
2321 (select-window window)
2322 (enlarge-window (- rmail-summary-window-size
2323 (window-height))))
2324 (select-window selected)))))
2325 \f
2326 ;;;; *** Rmail Specify Inbox Files ***
2327
2328 (autoload 'set-rmail-inbox-list "rmailmsc"
2329 "Set the inbox list of the current RMAIL file to FILE-NAME.
2330 This may be a list of file names separated by commas.
2331 If FILE-NAME is empty, remove any inbox list."
2332 t)
2333
2334 ;;;; *** Rmail Commands for Labels ***
2335
2336 (autoload 'rmail-add-label "rmailkwd"
2337 "Add LABEL to labels associated with current RMAIL message.
2338 Completion is performed over known labels when reading."
2339 t)
2340
2341 (autoload 'rmail-kill-label "rmailkwd"
2342 "Remove LABEL from labels associated with current RMAIL message.
2343 Completion is performed over known labels when reading."
2344 t)
2345
2346 (autoload 'rmail-next-labeled-message "rmailkwd"
2347 "Show next message with LABEL. Defaults to last label used.
2348 With prefix argument N moves forward N messages with this label."
2349 t)
2350
2351 (autoload 'rmail-previous-labeled-message "rmailkwd"
2352 "Show previous message with LABEL. Defaults to last label used.
2353 With prefix argument N moves backward N messages with this label."
2354 t)
2355
2356 (autoload 'rmail-read-label "rmailkwd"
2357 "PROMPT and read with completion an Rmail message label."
2358 t)
2359
2360 ;;;; *** Rmail Edit Mode ***
2361
2362 (autoload 'rmail-edit-current-message "rmailedit"
2363 "Edit the contents of the current message"
2364 t)
2365
2366 ;;;; *** Rmail Sorting ***
2367
2368 (autoload 'rmail-sort-by-date "rmailsort"
2369 "Sort messages of current Rmail file by date.
2370 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2371
2372 (autoload 'rmail-sort-by-subject "rmailsort"
2373 "Sort messages of current Rmail file by subject.
2374 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2375
2376 (autoload 'rmail-sort-by-author "rmailsort"
2377 "Sort messages of current Rmail file by author.
2378 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2379
2380 (autoload 'rmail-sort-by-recipient "rmailsort"
2381 "Sort messages of current Rmail file by recipient.
2382 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2383
2384 (autoload 'rmail-sort-by-correspondent "rmailsort"
2385 "Sort messages of current Rmail file by other correspondent.
2386 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2387
2388 (autoload 'rmail-sort-by-lines "rmailsort"
2389 "Sort messages of current Rmail file by number of lines.
2390 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2391
2392 (autoload 'rmail-sort-by-keywords "rmailsort"
2393 "Sort messages of current Rmail file by labels.
2394 If prefix argument REVERSE is non-nil, sort them in reverse order.
2395 KEYWORDS is a comma-separated list of labels." t)
2396 \f
2397 ;;;; *** Rmail Summary Mode ***
2398
2399 (autoload 'rmail-summary "rmailsum"
2400 "Display a summary of all messages, one line per message."
2401 t)
2402
2403 (autoload 'rmail-summary-by-labels "rmailsum"
2404 "Display a summary of all messages with one or more LABELS.
2405 LABELS should be a string containing the desired labels, separated by commas."
2406 t)
2407
2408 (autoload 'rmail-summary-by-recipients "rmailsum"
2409 "Display a summary of all messages with the given RECIPIENTS.
2410 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
2411 is non-nil (prefix arg given), only look in the To and From fields.
2412 RECIPIENTS is a string of regexps separated by commas."
2413 t)
2414
2415 (autoload 'rmail-summary-by-regexp "rmailsum"
2416 "Display a summary of all messages according to regexp REGEXP.
2417 If the regular expression is found in the header of the message
2418 \(including in the date and other lines, as well as the subject line),
2419 Emacs will list the header line in the RMAIL-summary."
2420 t)
2421
2422 (autoload 'rmail-summary-by-topic "rmailsum"
2423 "Display a summary of all messages with the given SUBJECT.
2424 Normally checks the Subject field of headers;
2425 but if WHOLE-MESSAGE is non-nil (prefix arg given),
2426 look in the whole message.
2427 SUBJECT is a string of regexps separated by commas."
2428 t)
2429 \f
2430 ;;;; *** Rmail output messages to files ***
2431
2432 (autoload 'rmail-output-to-rmail-file "rmailout"
2433 "Append the current message to an Rmail file named FILE-NAME.
2434 If the file does not exist, ask if it should be created.
2435 If file is being visited, the message is appended to the Emacs
2436 buffer visiting that file."
2437 t)
2438
2439 (autoload 'rmail-output "rmailout"
2440 "Append this message to Unix mail file named FILE-NAME."
2441 t)
2442
2443 ;;;; *** Rmail undigestification ***
2444
2445 (autoload 'undigestify-rmail-message "undigest"
2446 "Break up a digest message into its constituent messages.
2447 Leaves original message, deleted, before the undigestified messages."
2448 t)
2449
2450 (provide 'rmail)
2451
2452 ;;; rmail.el ends here