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