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