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