1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
3 ;; Copyright (C) 1985,86,87,88,93,94,95,96 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
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.
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.
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))
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")
54 (defvar rmail-movemail-program nil
55 "If non-nil, name of program for fetching new mail.")
57 (defvar rmail-pop-password nil
58 "*Password to use when reading mail from a POP server, if required.")
60 (defvar rmail-pop-password-required nil
61 "*Non-nil if a password is required when reading mail using POP.")
63 (defvar rmail-preserve-inbox nil
64 "*Non-nil if incoming mail should be left in the user's inbox,
65 rather than deleted, after it is retrieved.")
68 (defvar rmail-dont-reply-to-names nil "\
69 *A regexp specifying names to prune of reply to messages.
70 A value of nil means exclude your own name only.")
73 (defvar rmail-default-dont-reply-to-names "info-" "\
74 A regular expression specifying part of the value of the default value of
75 the variable `rmail-dont-reply-to-names', for when the user does not set
76 `rmail-dont-reply-to-names' explicitly. (The other part of the default
77 value is the user's name.)
78 It is useful to set this variable in the site customization file.")
81 (defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^x-mailer:"
82 "*Regexp to match header fields that Rmail should normally hide.")
85 (defvar rmail-displayed-headers nil
86 "*Regexp to match Header fields that Rmail should display.
87 If nil, display all header fields except those matched by
88 `rmail-ignored-headers'.")
91 (defvar rmail-retry-ignored-headers nil "\
92 *Headers that should be stripped when retrying a failed message.")
95 (defvar rmail-highlighted-headers "^From:\\|^Subject:" "\
96 *Regexp to match Header fields that Rmail should normally highlight.
97 A value of nil means don't highlight.
98 See also `rmail-highlight-face'.")
101 (defvar rmail-highlight-face nil "\
102 *Face used by Rmail for highlighting headers.")
105 (defvar rmail-delete-after-output nil "\
106 *Non-nil means automatically delete a message that is copied to a file.")
109 (defvar rmail-primary-inbox-list nil "\
110 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
111 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
112 \(the name varies depending on the operating system,
113 and the value of the environment variable MAIL overrides it).")
116 (defvar rmail-mail-new-frame nil
117 "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
120 (defvar rmail-secondary-file-directory "~/"
121 "*Directory for additional secondary Rmail files.")
123 (defvar rmail-secondary-file-regexp "\\.xmail$"
124 "*Regexp for which files are secondary Rmail files.")
127 (defvar rmail-mode-hook nil
128 "List of functions to call when Rmail is invoked.")
131 (defvar rmail-get-new-mail-hook nil
132 "List of functions to call when Rmail has retrieved new mail.")
135 (defvar rmail-show-message-hook nil
136 "List of functions to call when Rmail displays a message.")
139 (defvar rmail-delete-message-hook nil
140 "List of functions to call when Rmail deletes a message.
141 When the hooks are called, the message has been marked deleted but is
142 still the current message in the Rmail buffer.")
144 ;; These may be altered by site-init.el to match the format of mmdf files
145 ;; delimiting used on a given host (delim1 and delim2 from the config
148 (defvar mmdf-delim1 "^\001\001\001\001\n"
149 "Regexp marking the start of an mmdf message")
150 (defvar mmdf-delim2 "^\001\001\001\001\n"
151 "Regexp marking the end of an mmdf message")
153 (defvar rmail-message-filter nil
154 "If non-nil, a filter function for new messages in RMAIL.
155 Called with region narrowed to the message, including headers,
156 before obeying `rmail-ignored-headers'.")
158 (defvar rmail-reply-prefix "Re: "
159 "String to prepend to Subject line when replying to a message.")
161 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]".
162 ;; This pattern should catch all the common variants.
163 (defvar rmail-reply-regexp "\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
164 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
166 (defvar rmail-display-summary nil
167 "If non-nil, Rmail always displays the summary buffer.")
169 (defvar rmail-mode-map nil)
171 (defvar rmail-inbox-list nil)
172 (defvar rmail-keywords nil)
174 ;; Message counters and markers. Deleted flags.
176 (defvar rmail-current-message nil)
177 (defvar rmail-total-messages nil)
178 (defvar rmail-message-vector nil)
179 (defvar rmail-deleted-vector nil)
181 (defvar rmail-overlay-list nil)
183 (defvar rmail-font-lock-keywords
185 (let* ((cite-chars "[>|}]")
186 (cite-prefix "A-Za-z")
187 (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
188 (list '("^\\(From\\|Sender\\):" . font-lock-function-name-face)
189 '("^Reply-To:.*$" . font-lock-function-name-face)
190 '("^Subject:" . font-lock-comment-face)
191 '("^\\(To\\|Apparently-To\\|Cc\\):" . font-lock-keyword-face)
192 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
194 (,(concat "\\=[ \t]*"
195 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
197 (beginning-of-line) (end-of-line)
198 (0 font-lock-reference-face)))
199 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\|Date\\):.*$"
200 . font-lock-string-face))))
201 "Additional expressions to highlight in Rmail mode.")
203 ;; These are used by autoloaded rmail-summary.
205 (defvar rmail-summary-buffer nil)
206 (defvar rmail-summary-vector nil)
208 ;; `Sticky' default variables.
210 ;; Last individual label specified to a or k.
211 (defvar rmail-last-label nil)
212 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
213 (defvar rmail-last-multi-labels nil)
214 (defvar rmail-last-regexp nil)
215 (defvar rmail-default-file "~/xmail"
216 "*Default file name for \\[rmail-output].")
217 (defvar rmail-default-rmail-file "~/XMAIL"
218 "*Default file name for \\[rmail-output-to-rmail-file].")
220 ;;; Regexp matching the delimiter of messages in UNIX mail format
221 ;;; (UNIX From lines), minus the initial ^. Note that if you change
222 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
223 ;;; that knows the exact ordering of the \\( \\) subexpressions.
224 (defvar rmail-unix-mail-delimiter
225 (let ((time-zone-regexp
226 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
227 "\\|[-+]?[0-9][0-9][0-9][0-9]"
233 ;; Many things can happen to an RFC 822 mailbox before it is put into
234 ;; a `From' line. The leading phrase can be stripped, e.g.
235 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
236 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
237 ;; can be removed, e.g.
238 ;; From: joe@y.z (Joe K
240 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
243 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
244 ;; The mailbox can be removed or be replaced by white space, e.g.
245 ;; From: "Joe User"{space}{tab}
247 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
248 ;; where {space} and {tab} represent the Ascii space and tab characters.
249 ;; We want to match the results of any of these manglings.
250 ;; The following regexp rejects names whose first characters are
251 ;; obviously bogus, but after that anything goes.
252 "\\([^\0-\b\n-\r\^?].*\\)? "
254 ;; The time the message was sent.
255 "\\([^\0-\r \^?]+\\) +" ; day of the week
256 "\\([^\0-\r \^?]+\\) +" ; month
257 "\\([0-3]?[0-9]\\) +" ; day of month
258 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
260 ;; Perhaps a time zone, specified by an abbreviation, or by a
265 " \\([0-9][0-9]+\\) *"
267 ;; On some systems the time zone can appear after the year, too.
271 "\\(remote from .*\\)?"
276 ;; Perform BODY in the summary buffer
277 ;; in such a way that its cursor is properly updated in its own window.
278 (defmacro rmail-select-summary (&rest body)
279 (` (let ((total rmail-total-messages))
280 (if (rmail-summary-displayed)
281 (let ((window (selected-window)))
285 (pop-to-buffer rmail-summary-buffer)
286 ;; rmail-total-messages is a buffer-local var
287 ;; in the rmail buffer.
288 ;; This way we make it available for the body
289 ;; even tho the rmail buffer is not current.
290 (let ((rmail-total-messages total))
292 (select-window window))))
294 (set-buffer rmail-summary-buffer)
295 (let ((rmail-total-messages total))
297 (rmail-maybe-display-summary))))
299 ;;;; *** Rmail Mode ***
302 (defun rmail (&optional file-name-arg)
303 "Read and edit incoming mail.
304 Moves messages into file named by `rmail-file-name' (a babyl format file)
305 and edits that file in RMAIL Mode.
306 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
308 May be called with file name as argument; then performs rmail editing on
309 that file, but does not copy any new mail into the file.
310 Interactively, if you supply a prefix argument, then you
311 have a chance to specify a file name with the minibuffer.
313 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
314 (interactive (if current-prefix-arg
315 (list (read-file-name "Run rmail on RMAIL file: "))))
316 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
317 (existed (get-file-buffer file-name))
319 ;; Like find-file, but in the case where a buffer existed
320 ;; and the file was reverted, recompute the message-data.
321 (if (and existed (not (verify-visited-file-modtime existed)))
323 ;; Don't be confused by apparent local-variables spec
324 ;; in the last message in the RMAIL file.
325 (let ((enable-local-variables nil))
326 (find-file file-name))
327 (if (and (verify-visited-file-modtime existed)
328 (eq major-mode 'rmail-mode))
329 (progn (rmail-forget-messages)
330 (rmail-set-message-counters))))
331 (let ((enable-local-variables nil))
332 (find-file file-name)))
333 (if (eq major-mode 'rmail-edit-mode)
334 (error "Exit Rmail Edit mode before getting new mail."))
335 (if (and existed (> (buffer-size) 0))
336 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
337 (or (eq major-mode 'rmail-mode)
338 (progn (rmail-mode-2)
339 (setq run-mail-hook t)))
340 (setq run-mail-hook t)
342 ;; Convert all or part to Babyl file if possible.
344 (goto-char (point-max))
345 (if (null rmail-inbox-list)
347 (rmail-set-message-counters)
348 (rmail-show-message))))
349 (or (and (null file-name-arg)
350 (rmail-get-new-mail))
351 (rmail-show-message (rmail-first-unseen-message)))
352 (if rmail-display-summary (rmail-summary))
353 (rmail-construct-io-menu)
355 (run-hooks 'rmail-mode-hook))))
357 ;; Given the value of MAILPATH, return a list of inbox file names.
358 ;; This is turned off because it is not clear that the user wants
359 ;; all these inboxes to feed into the primary rmail file.
360 ; (defun rmail-convert-mailpath (string)
362 ; (while (setq idx (string-match "[%:]" string))
363 ; (let ((this (substring string 0 idx)))
364 ; (setq string (substring string (1+ idx)))
365 ; (setq list (cons (if (string-match "%" this)
366 ; (substring this 0 (string-match "%" this))
371 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
372 ; will not cause emacs 18.55 problems.
374 (defun rmail-convert-file ()
377 (goto-char (point-min))
378 ;; If file doesn't start like a Babyl file,
379 ;; convert it to one, by adding a header and converting each message.
380 (cond ((looking-at "BABYL OPTIONS:"))
381 ((looking-at "Version: 5\n")
382 ;; Losing babyl file made by old version of Rmail.
383 ;; Just fix the babyl file header; don't make a new one,
384 ;; so we don't lose the Labels: file attribute, etc.
385 (let ((buffer-read-only nil))
386 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
387 ((equal (point-min) (point-max))
388 ;; Empty RMAIL file. Just insert the header.
389 (rmail-insert-rmail-file-header))
391 ;; Non-empty file in non-RMAIL format. Add header and convert.
393 (rmail-insert-rmail-file-header)))
394 ;; If file was not a Babyl file or if there are
395 ;; Unix format messages added at the end,
396 ;; convert file as necessary.
399 (goto-char (point-max))
400 (search-backward "\n\^_")
402 (looking-at "\n*From ")))
403 (let ((buffer-read-only nil))
404 (message "Converting to Babyl format...")
405 ;; If file needs conversion, convert it all,
406 ;; except for the BABYL header.
407 ;; (rmail-convert-to-babyl-format would delete the header.)
408 (goto-char (point-min))
409 (search-forward "\n\^_" nil t)
410 (narrow-to-region (point) (point-max))
411 (rmail-convert-to-babyl-format)
412 (message "Converting to Babyl format...done")))))
414 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
415 ;;; will not cause emacs 18.55 problems.
417 (defun rmail-insert-rmail-file-header ()
418 (let ((buffer-read-only nil))
419 (insert "BABYL OPTIONS: -*- rmail -*-
422 Note: This is the header of an rmail file.
423 Note: If you are seeing it in rmail,
424 Note: it means the file has no messages in it.\n\^_")))
428 (setq rmail-mode-map (make-keymap))
429 (suppress-keymap rmail-mode-map)
430 (define-key rmail-mode-map "a" 'rmail-add-label)
431 (define-key rmail-mode-map "b" 'rmail-bury)
432 (define-key rmail-mode-map "c" 'rmail-continue)
433 (define-key rmail-mode-map "d" 'rmail-delete-forward)
434 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)
435 (define-key rmail-mode-map "e" 'rmail-edit-current-message)
436 (define-key rmail-mode-map "f" 'rmail-forward)
437 (define-key rmail-mode-map "g" 'rmail-get-new-mail)
438 (define-key rmail-mode-map "h" 'rmail-summary)
439 (define-key rmail-mode-map "i" 'rmail-input)
440 (define-key rmail-mode-map "j" 'rmail-show-message)
441 (define-key rmail-mode-map "k" 'rmail-kill-label)
442 (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
443 (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
444 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
445 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
446 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
447 (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
448 (define-key rmail-mode-map "m" 'rmail-mail)
449 (define-key rmail-mode-map "\em" 'rmail-retry-failure)
450 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
451 (define-key rmail-mode-map "\en" 'rmail-next-message)
452 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
453 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
454 (define-key rmail-mode-map "\C-o" 'rmail-output)
455 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
456 (define-key rmail-mode-map "\ep" 'rmail-previous-message)
457 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
458 (define-key rmail-mode-map "q" 'rmail-quit)
459 (define-key rmail-mode-map "r" 'rmail-reply)
460 ;; I find I can't live without the default M-r command -- rms.
461 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
462 (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
463 (define-key rmail-mode-map "\es" 'rmail-search)
464 (define-key rmail-mode-map "t" 'rmail-toggle-header)
465 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
466 (define-key rmail-mode-map "w" 'rmail-edit-current-message)
467 (define-key rmail-mode-map "x" 'rmail-expunge)
468 (define-key rmail-mode-map "." 'rmail-beginning-of-message)
469 (define-key rmail-mode-map "<" 'rmail-first-message)
470 (define-key rmail-mode-map ">" 'rmail-last-message)
471 (define-key rmail-mode-map " " 'scroll-up)
472 (define-key rmail-mode-map "\177" 'scroll-down)
473 (define-key rmail-mode-map "?" 'describe-mode)
474 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
475 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
476 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
477 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
478 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
479 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
480 (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-keywords)
481 (define-key rmail-mode-map "\C-c\C-n" 'rmail-next-same-subject)
482 (define-key rmail-mode-map "\C-c\C-p" 'rmail-previous-same-subject)
485 (define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
487 (define-key rmail-mode-map [menu-bar classify]
488 (cons "Classify" (make-sparse-keymap "Classify")))
490 (define-key rmail-mode-map [menu-bar classify input-menu]
493 (define-key rmail-mode-map [menu-bar classify output-menu]
496 (define-key rmail-mode-map [menu-bar classify output-inbox]
497 '("Output (inbox)..." . rmail-output))
499 (define-key rmail-mode-map [menu-bar classify output]
500 '("Output (Rmail)..." . rmail-output-to-rmail-file))
502 (define-key rmail-mode-map [menu-bar classify kill-label]
503 '("Kill Label..." . rmail-kill-label))
505 (define-key rmail-mode-map [menu-bar classify add-label]
506 '("Add Label..." . rmail-add-label))
508 (define-key rmail-mode-map [menu-bar summary]
509 (cons "Summary" (make-sparse-keymap "Summary")))
511 (define-key rmail-mode-map [menu-bar summary senders]
512 '("By Senders..." . rmail-summary-by-senders))
514 (define-key rmail-mode-map [menu-bar summary labels]
515 '("By Labels..." . rmail-summary-by-labels))
517 (define-key rmail-mode-map [menu-bar summary recipients]
518 '("By Recipients..." . rmail-summary-by-recipients))
520 (define-key rmail-mode-map [menu-bar summary topic]
521 '("By Topic..." . rmail-summary-by-topic))
523 (define-key rmail-mode-map [menu-bar summary regexp]
524 '("By Regexp..." . rmail-summary-by-regexp))
526 (define-key rmail-mode-map [menu-bar summary all]
527 '("All" . rmail-summary))
529 (define-key rmail-mode-map [menu-bar mail]
530 (cons "Mail" (make-sparse-keymap "Mail")))
532 (define-key rmail-mode-map [menu-bar mail rmail-get-new-mail]
533 '("Get New Mail" . rmail-get-new-mail))
535 (define-key rmail-mode-map [menu-bar mail lambda]
538 (define-key rmail-mode-map [menu-bar mail continue]
539 '("Continue" . rmail-continue))
541 (define-key rmail-mode-map [menu-bar mail resend]
542 '("Re-send..." . rmail-resend))
544 (define-key rmail-mode-map [menu-bar mail forward]
545 '("Forward" . rmail-forward))
547 (define-key rmail-mode-map [menu-bar mail retry]
548 '("Retry" . rmail-retry-failure))
550 (define-key rmail-mode-map [menu-bar mail reply]
551 '("Reply" . rmail-reply))
553 (define-key rmail-mode-map [menu-bar mail mail]
554 '("Mail" . rmail-mail))
556 (define-key rmail-mode-map [menu-bar delete]
557 (cons "Delete" (make-sparse-keymap "Delete")))
559 (define-key rmail-mode-map [menu-bar delete expunge/save]
560 '("Expunge/Save" . rmail-expunge-and-save))
562 (define-key rmail-mode-map [menu-bar delete expunge]
563 '("Expunge" . rmail-expunge))
565 (define-key rmail-mode-map [menu-bar delete undelete]
566 '("Undelete" . rmail-undelete-previous-message))
568 (define-key rmail-mode-map [menu-bar delete delete]
569 '("Delete" . rmail-delete-forward))
571 (define-key rmail-mode-map [menu-bar move]
572 (cons "Move" (make-sparse-keymap "Move")))
574 (define-key rmail-mode-map [menu-bar move search-back]
575 '("Search Back..." . rmail-search-backwards))
577 (define-key rmail-mode-map [menu-bar move search]
578 '("Search..." . rmail-search))
580 (define-key rmail-mode-map [menu-bar move previous]
581 '("Previous Nondeleted" . rmail-previous-undeleted-message))
583 (define-key rmail-mode-map [menu-bar move next]
584 '("Next Nondeleted" . rmail-next-undeleted-message))
586 (define-key rmail-mode-map [menu-bar move last]
587 '("Last" . rmail-last-message))
589 (define-key rmail-mode-map [menu-bar move first]
590 '("First" . rmail-first-message))
592 (define-key rmail-mode-map [menu-bar move previous]
593 '("Previous" . rmail-previous-message))
595 (define-key rmail-mode-map [menu-bar move next]
596 '("Next" . rmail-next-message))
598 ;; Rmail mode is suitable only for specially formatted data.
599 (put 'rmail-mode 'mode-class 'special)
601 (defun rmail-mode-kill-summary ()
602 (if rmail-summary-buffer (kill-buffer rmail-summary-buffer)))
606 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
607 All normal editing commands are turned off.
608 Instead, these commands are available:
610 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
611 \\[scroll-up] Scroll to next screen of this message.
612 \\[scroll-down] Scroll to previous screen of this message.
613 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
614 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
615 \\[rmail-next-message] Move to Next message whether deleted or not.
616 \\[rmail-previous-message] Move to Previous message whether deleted or not.
617 \\[rmail-first-message] Move to the first message in Rmail file.
618 \\[rmail-last-message] Move to the last message in Rmail file.
619 \\[rmail-show-message] Jump to message specified by numeric position in file.
620 \\[rmail-search] Search for string and show message it is found in.
621 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
622 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
623 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
624 till a deleted message is found.
625 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
626 \\[rmail-expunge] Expunge deleted messages.
627 \\[rmail-expunge-and-save] Expunge and save the file.
628 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
629 \\[save-buffer] Save without expunging.
630 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
631 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
632 \\[rmail-continue] Continue composing outgoing message started before.
633 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
634 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
635 \\[rmail-forward] Forward this message to another user.
636 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
637 \\[rmail-output] Output this message to a Unix-format mail file (append it).
638 \\[rmail-input] Input Rmail file. Run Rmail on that file.
639 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
640 \\[rmail-kill-label] Kill label. Remove a label from current message.
641 \\[rmail-next-labeled-message] Move to Next message with specified label
642 (label defaults to last one specified).
643 Standard labels: filed, unseen, answered, forwarded, deleted.
644 Any other label is present only if you add it with \\[rmail-add-label].
645 \\[rmail-previous-labeled-message] Move to Previous message with specified label
646 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
647 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
648 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
649 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
650 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
651 \\[rmail-toggle-header] Toggle display of complete header."
654 (rmail-set-message-counters)
655 (rmail-show-message rmail-total-messages)
656 (run-hooks 'rmail-mode-hook))
658 (defun rmail-mode-2 ()
659 (kill-all-local-variables)
663 (defun rmail-mode-1 ()
664 (setq major-mode 'rmail-mode)
665 (setq mode-name "RMAIL")
666 (setq buffer-read-only t)
667 ;; No need to auto save RMAIL files in normal circumstances
668 ;; because they contain no info except attribute changes
669 ;; and deletion of messages.
670 ;; The one exception is when messages are copied into an Rmail mode buffer.
671 ;; rmail-output-to-rmail-file enables auto save when you do that.
672 (setq buffer-auto-save-file-name nil)
673 (if (boundp 'mode-line-modified)
674 (setq mode-line-modified "--- ")
675 (setq mode-line-format
676 (cons "--- " (cdr (default-value 'mode-line-format)))))
677 (use-local-map rmail-mode-map)
678 (set-syntax-table text-mode-syntax-table)
679 (setq local-abbrev-table text-mode-abbrev-table))
681 (defun rmail-variables ()
682 (make-local-variable 'revert-buffer-function)
683 (setq revert-buffer-function 'rmail-revert)
684 (make-local-variable 'font-lock-defaults)
685 (setq font-lock-defaults
686 '(rmail-font-lock-keywords t nil nil nil
687 (font-lock-maximum-size . nil)
688 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function)
689 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function)
690 (font-lock-inhibit-thing-lock . (lazy-lock-mode fast-lock-mode))))
691 (make-local-variable 'rmail-last-label)
692 (make-local-variable 'rmail-last-regexp)
693 (make-local-variable 'rmail-deleted-vector)
694 (make-local-variable 'rmail-summary-buffer)
695 (make-local-variable 'rmail-summary-vector)
696 (make-local-variable 'rmail-current-message)
697 (make-local-variable 'rmail-total-messages)
698 (make-local-variable 'require-final-newline)
699 (setq require-final-newline nil)
700 (make-local-variable 'rmail-overlay-list)
701 (setq rmail-overlay-list nil)
702 (make-local-variable 'version-control)
703 (setq version-control 'never)
704 (make-local-variable 'kill-buffer-hook)
705 (add-hook 'kill-buffer-hook 'rmail-mode-kill-summary)
706 (make-local-variable 'file-precious-flag)
707 (setq file-precious-flag t)
708 (make-local-variable 'rmail-message-vector)
709 (make-local-variable 'rmail-inbox-list)
710 (setq rmail-inbox-list (rmail-parse-file-inboxes))
711 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
712 (and (null rmail-inbox-list)
713 (or (equal buffer-file-name (expand-file-name rmail-file-name))
714 (equal buffer-file-truename
715 (abbreviate-file-name (file-truename rmail-file-name))))
716 (setq rmail-inbox-list
717 (or rmail-primary-inbox-list
718 (list (or (getenv "MAIL")
719 (concat rmail-spool-directory
720 (user-login-name)))))))
721 (make-local-variable 'rmail-keywords)
722 ;; this gets generated as needed
723 (setq rmail-keywords nil))
725 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
726 (defun rmail-revert (arg noconfirm)
727 (let ((revert-buffer-function (default-value 'revert-buffer-function)))
728 ;; Call our caller again, but this time it does the default thing.
729 (if (revert-buffer arg noconfirm)
730 ;; If the user said "yes", and we changed something,
731 ;; reparse the messages.
734 (goto-char (point-max))
737 ;; Return a list of files from this buffer's Mail: option.
738 ;; Does not assume that messages have been parsed.
739 ;; Just returns nil if buffer does not look like Babyl format.
740 (defun rmail-parse-file-inboxes ()
745 (cond ((looking-at "BABYL OPTIONS:")
746 (search-forward "\n\^_" nil 'move)
747 (narrow-to-region 1 (point))
749 (if (search-forward "\nMail:" nil t)
751 (narrow-to-region (point) (progn (end-of-line) (point)))
752 (goto-char (point-min))
753 (mail-parse-comma-list))))))))
755 (defun rmail-expunge-and-save ()
756 "Expunge and save RMAIL file."
760 (if (rmail-summary-exists)
761 (rmail-select-summary (set-buffer-modified-p nil))))
766 (rmail-expunge-and-save)
767 ;; Don't switch to the summary buffer even if it was recently visible.
768 (if rmail-summary-buffer
770 (replace-buffer-in-windows rmail-summary-buffer)
771 (bury-buffer rmail-summary-buffer)))
772 (let ((obuf (current-buffer)))
773 (replace-buffer-in-windows obuf)
777 "Bury current Rmail buffer and its summary buffer."
779 ;; This let var was called rmail-buffer, but that interfered
780 ;; with the buffer-local var used in summary buffers.
781 (let ((buffer-to-bury (current-buffer)))
782 (if (rmail-summary-exists)
784 (while (setq window (get-buffer-window rmail-summary-buffer))
785 (set-window-buffer window (other-buffer rmail-summary-buffer)))
786 (bury-buffer rmail-summary-buffer)))
787 (switch-to-buffer (other-buffer (current-buffer)))
788 (bury-buffer buffer-to-bury)))
790 (defun rmail-duplicate-message ()
791 "Create a duplicated copy of the current message.
792 The duplicate copy goes into the Rmail file just after the
796 (let ((buffer-read-only nil)
797 (number rmail-current-message)
798 (string (buffer-substring (rmail-msgbeg rmail-current-message)
799 (rmail-msgend rmail-current-message))))
800 (goto-char (rmail-msgend rmail-current-message))
802 (rmail-forget-messages)
803 (rmail-show-message number)
804 (message "Message duplicated")))
807 (defun rmail-input (filename)
808 "Run Rmail on file FILENAME."
809 (interactive "FRun rmail on RMAIL file: ")
813 ;; This used to scan subdirectories recursively, but someone pointed out
814 ;; that if the user wants that, person can put all the files in one dir.
815 ;; And the recursive scan was slow. So I took it out.
817 (defun rmail-find-all-files (start)
818 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
819 (if (file-accessible-directory-p start)
821 (let* ((case-fold-search t)
822 (files (directory-files start t rmail-secondary-file-regexp)))
823 ;; Sort here instead of in directory-files
824 ;; because this list is usually much shorter.
825 (sort files 'string<))))
827 (defun rmail-list-to-menu (menu-name l action &optional full-name)
828 (let ((menu (make-sparse-keymap menu-name)))
830 (function (lambda (item)
835 (rmail-list-to-menu (car item) (cdr item)
838 (concat full-name "/"
841 (setq name (car item)))
845 (list 'lambda () '(interactive)
849 (concat full-name "/" item)
851 rmail-secondary-file-directory))))))
852 (define-key menu (vector (intern name))
853 (cons name command)))))
857 ;; This command is always "disabled" when it appears in a menu.
858 (put 'rmail-disable-menu 'menu-enable ''nil)
860 (defun rmail-construct-io-menu ()
861 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
864 (define-key rmail-mode-map [menu-bar classify input-menu]
865 (cons "Input Rmail File"
866 (rmail-list-to-menu "Input Rmail File"
869 (define-key rmail-mode-map [menu-bar classify output-menu]
870 (cons "Output Rmail File"
871 (rmail-list-to-menu "Output Rmail File"
873 'rmail-output-to-rmail-file))))
875 (define-key rmail-mode-map [menu-bar classify input-menu]
876 '("Input Rmail File" . rmail-disable-menu))
877 (define-key rmail-mode-map [menu-bar classify output-menu]
878 '("Output Rmail File" . rmail-disable-menu)))))
881 ;;;; *** Rmail input ***
883 ;; RLK feature not added in this version:
884 ;; argument specifies inbox file or files in various ways.
886 (defun rmail-get-new-mail (&optional file-name)
887 "Move any new mail from this RMAIL file's inbox files.
888 The inbox files can be specified with the file's Mail: option. The
889 variable `rmail-primary-inbox-list' specifies the inboxes for your
890 primary RMAIL file if it has no Mail: option. By default, this is
891 your /usr/spool/mail/$USER.
893 You can also specify the file to get new mail from. In this case, the
894 file of new mail is not changed or deleted. Noninteractively, you can
895 pass the inbox file name as an argument. Interactively, a prefix
896 argument causes us to read a file name and use that file as the inbox.
898 If the variable `rmail-preserve-inbox' is non-nil, new mail will
899 always be left in inbox files rather than deleted.
901 This function runs `rmail-get-new-mail-hook' before saving the updated file.
902 It returns t if it got any new messages."
904 (list (if current-prefix-arg
905 (read-file-name "Get new mail from file: "))))
906 (run-hooks 'rmail-before-get-new-mail-hook)
907 ;; If the disk file has been changed from under us,
908 ;; revert to it before we get new mail.
909 (or (verify-visited-file-modtime (current-buffer))
910 (find-file (buffer-file-name)))
911 (rmail-maybe-set-message-counters)
913 ;; Get rid of all undo records for this buffer.
914 (or (eq buffer-undo-list t)
915 (setq buffer-undo-list nil))
916 (let ((all-files (if file-name (list file-name)
921 (let ((opoint (point))
924 ;; If buffer has not changed yet, and has not been saved yet,
925 ;; don't replace the old backup file now.
926 (make-backup-files (and make-backup-files (buffer-modified-p)))
927 (buffer-read-only nil)
928 ;; Don't make undo records for what we do in getting mail.
931 ;; Files to insert this time around.
933 ;; Last names of those files.
935 ;; Pull files off all-files onto files
936 ;; as long as there is no name conflict.
937 ;; A conflict happens when two inbox file names
938 ;; have the same last component.
939 (while (and all-files
940 (not (member (file-name-nondirectory (car all-files))
942 (setq files (cons (car all-files) files)
944 (cons (file-name-nondirectory (car all-files)) files))
945 (setq all-files (cdr all-files)))
946 ;; Put them back in their original order.
947 (setq files (nreverse files))
949 (goto-char (point-max))
950 (skip-chars-backward " \t\n") ; just in case of brain damage
951 (delete-region (point) (point-max)) ; caused by require-final-newline
954 (narrow-to-region (point) (point))
955 ;; Read in the contents of the inbox files,
956 ;; renaming them as necessary,
957 ;; and adding to the list of files to delete eventually.
959 (rmail-insert-inbox-text files nil)
960 (setq delete-files (rmail-insert-inbox-text files t)))
961 ;; Scan the new text and convert each message to babyl format.
962 (goto-char (point-min))
965 (setq new-messages (rmail-convert-to-babyl-format)
967 ;; If we could not convert the file's inboxes,
968 ;; rename the files we tried to read
969 ;; so we won't over and over again.
970 (if (and (not file-name) (not success))
971 (let ((delfiles delete-files)
974 (while (file-exists-p (format "RMAILOSE.%d" count))
975 (setq count (1+ count)))
976 (rename-file (car delfiles)
977 (format "RMAILOSE.%d" count))
978 (setq delfiles (cdr delfiles))))))
979 (or (zerop new-messages)
982 (search-backward "\n\^_" nil t)
983 (narrow-to-region (point) (point-max))
984 (goto-char (1+ (point-min)))
985 (rmail-count-new-messages)
986 (run-hooks 'rmail-get-new-mail-hook)
988 ;; Delete the old files, now that babyl file is saved.
991 ;; First, try deleting.
993 (delete-file (car delete-files))
995 ;; If we can't delete it, truncate it.
996 (write-region (point) (point) (car delete-files))))
998 (setq delete-files (cdr delete-files)))))
999 (if (= new-messages 0)
1000 (progn (goto-char opoint)
1001 (if (or file-name rmail-inbox-list)
1002 (message "(No new mail has arrived)")))
1003 (if (rmail-summary-exists)
1004 (rmail-select-summary
1005 (rmail-update-summary)))
1006 (message "%d new message%s read"
1007 new-messages (if (= 1 new-messages) "" "s"))
1008 ;; Move to the first new message
1009 ;; unless we have other unseen messages before it.
1010 (rmail-show-message (rmail-first-unseen-message))
1011 (run-hooks 'rmail-after-get-new-mail-hook)
1014 ;; Don't leave the buffer screwed up if we get a disk-full error.
1015 (rmail-show-message))))
1017 (defun rmail-insert-inbox-text (files renamep)
1018 ;; Detect a locked file now, so that we avoid moving mail
1019 ;; out of the real inbox file. (That could scare people.)
1020 (or (memq (file-locked-p buffer-file-name) '(nil t))
1021 (error "RMAIL file %s is locked"
1022 (file-name-nondirectory buffer-file-name)))
1023 (let (file tofile delete-files movemail popmail)
1025 (setq file (file-truename
1026 (expand-file-name (substitute-in-file-name (car files))))
1027 tofile (expand-file-name
1028 ;; Generate name to move to from inbox name,
1029 ;; in case of multiple inboxes that need moving.
1030 (concat ".newmail-" (file-name-nondirectory file))
1031 ;; Use the directory of this rmail file
1032 ;; because it's a nuisance to use the homedir
1033 ;; if that is on a full disk and this rmail
1035 (file-name-directory
1036 (expand-file-name buffer-file-name))))
1037 ;; Always use movemail to rename the file,
1038 ;; since there can be mailboxes in various directories.
1040 ;;; ;; If getting from mail spool directory,
1041 ;;; ;; use movemail to move rather than just renaming,
1042 ;;; ;; so as to interlock with the mailer.
1043 ;;; (setq movemail (string= file
1045 ;;; (concat rmail-spool-directory
1046 ;;; (file-name-nondirectory file)))))
1047 (setq popmail (string-match "^po:" (file-name-nondirectory file)))
1048 (if popmail (setq file (file-name-nondirectory file)
1052 ;; On some systems, /usr/spool/mail/foo is a directory
1053 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1054 (if (file-directory-p file)
1055 (setq file (expand-file-name (user-login-name)
1058 (if (and rmail-pop-password-required (not rmail-pop-password))
1059 (setq rmail-pop-password
1061 (format "Password for %s: "
1062 (substring file (+ popmail 3))))))
1063 (if (eq system-type 'windows-nt)
1064 ;; cannot have "po:" in file name
1067 (concat ".newmail-pop-" (substring file (+ popmail 3)))
1068 (file-name-directory
1069 (expand-file-name buffer-file-name)))))
1070 (message "Getting mail from post office ..."))
1071 ((and (file-exists-p tofile)
1072 (/= 0 (nth 7 (file-attributes tofile))))
1073 (message "Getting mail from %s..." tofile))
1074 ((and (file-exists-p file)
1075 (/= 0 (nth 7 (file-attributes file))))
1076 (message "Getting mail from %s..." file)))
1077 ;; Set TOFILE if have not already done so, and
1078 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1079 (cond ((not renamep)
1081 ((or (file-exists-p tofile) (and (not popmail)
1082 (not (file-exists-p file))))
1084 ((and (not movemail) (not popmail))
1085 ;; Try copying. If that fails (perhaps no space) and
1086 ;; we're allowed to blow away the inbox, rename instead.
1087 (if rmail-preserve-inbox
1088 (copy-file file tofile nil)
1090 (copy-file file tofile nil)
1092 ;; Third arg is t so we can replace existing file TOFILE.
1093 (rename-file file tofile t))))
1094 ;; Make the real inbox file empty.
1095 ;; Leaving it deleted could cause lossage
1096 ;; because mailers often won't create the file.
1097 (if (not rmail-preserve-inbox)
1099 (write-region (point) (point) file)
1105 (setq errors (generate-new-buffer " *rmail loss*"))
1106 (buffer-disable-undo errors)
1109 (list (or rmail-movemail-program
1110 (expand-file-name "movemail"
1113 (if rmail-preserve-inbox
1117 (if rmail-pop-password
1118 (list rmail-pop-password)
1120 (apply 'call-process args))
1121 (if (not (buffer-modified-p errors))
1122 ;; No output => movemail won
1125 (subst-char-in-region (point-min) (point-max)
1127 (goto-char (point-max))
1128 (skip-chars-backward " \t")
1129 (delete-region (point) (point-max))
1130 (goto-char (point-min))
1131 (if (looking-at "movemail: ")
1132 (delete-region (point-min) (match-end 0)))
1134 (message "movemail: %s"
1135 (buffer-substring (point-min)
1139 (if errors (kill-buffer errors))))))
1140 ;; At this point, TOFILE contains the name to read:
1141 ;; Either the alternate name (if we renamed)
1142 ;; or the actual inbox (if not renaming).
1143 (if (file-exists-p tofile)
1145 (goto-char (point-max))
1146 (setq size (nth 1 (insert-file-contents tofile)))
1147 (goto-char (point-max))
1148 (or (= (preceding-char) ?\n)
1151 (if (not (and rmail-preserve-inbox (string= file tofile)))
1152 (setq delete-files (cons tofile delete-files)))))
1154 (setq files (cdr files)))
1157 (defun rmail-read-passwd (prompt &optional default)
1158 "Read a password, echoing `.' for each character typed.
1159 End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line.
1160 Optional DEFAULT is password to start with."
1161 (let ((pass (if default default ""))
1164 (cursor-in-echo-area t))
1165 (while (progn (message "%s%s"
1167 (make-string (length pass) ?.))
1168 (setq c (read-char))
1169 (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
1172 (if (and (/= c ?\b) (/= c ?\177))
1173 (setq pass (concat pass (char-to-string c)))
1174 (if (> (length pass) 0)
1175 (setq pass (substring pass 0 -1))))))
1180 ;; the rmail-break-forwarded-messages feature is not implemented
1181 (defun rmail-convert-to-babyl-format ()
1182 (let ((count 0) start
1183 (case-fold-search nil)
1184 (invalid-input-resync
1185 (function (lambda ()
1186 (message "Invalid Babyl format in inbox!")
1188 ;; Try to get back in sync with a real message.
1189 (if (re-search-forward
1190 (concat mmdf-delim1 "\\|^From") nil t)
1192 (goto-char (point-max)))))))
1193 (goto-char (point-min))
1196 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1197 (if (search-forward "\n\^_" nil t)
1198 ;; If we find the proper terminator, delete through there.
1199 (delete-region (point-min) (point))
1200 (funcall invalid-input-resync)
1201 (delete-region (point-min) (point))))
1202 ;; Babyl format message
1204 (or (search-forward "\n\^_" nil t)
1205 (funcall invalid-input-resync))
1206 (setq count (1+ count))
1207 ;; Make sure there is no extra white space after the ^_
1208 ;; at the end of the message.
1209 ;; Narrowing will make sure that whatever follows the junk
1210 ;; will be treated properly.
1211 (delete-region (point)
1213 (skip-chars-forward " \t\n")
1215 (narrow-to-region (point) (point-max)))
1217 ((let ((case-fold-search t))
1218 (looking-at mmdf-delim1))
1219 (let ((case-fold-search t))
1220 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1221 (setq start (point))
1222 (re-search-forward mmdf-delim2 nil t)
1223 (replace-match "\^_"))
1226 (narrow-to-region start (1- (point)))
1227 (goto-char (point-min))
1228 (while (search-forward "\n\^_" nil t); single char "\^_"
1229 (replace-match "\n^_")))); 2 chars: "^" and "_"
1230 (narrow-to-region (point) (point-max))
1231 (setq count (1+ count)))
1233 ((looking-at "^From ")
1234 (setq start (point))
1235 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1236 (rmail-nuke-pinhead-header)
1237 ;; If this message has a Content-Length field,
1238 ;; skip to the end of the contents.
1239 (let* ((header-end (save-excursion
1240 (and (re-search-forward "\n\n" nil t)
1242 (case-fold-search t)
1244 ;; Get the numeric value from the Content-Length field.
1246 ;; Back up to end of prev line,
1247 ;; in case the Content-Length field comes first.
1249 (and (search-forward "\ncontent-length: "
1252 (eol (progn (end-of-line) (point))))
1253 (string-to-int (buffer-substring beg eol)))))))
1255 (if (and (natnump size)
1256 (<= (+ header-end size) (point-max))
1257 ;; Make sure this would put us at a position
1258 ;; that we could continue from.
1260 (goto-char (+ header-end size))
1261 (skip-chars-forward "\n")
1263 (and (looking-at "BABYL OPTIONS:")
1264 (search-forward "\n\^_" nil t))
1265 (and (looking-at "\^L")
1266 (search-forward "\n\^_" nil t))
1267 (let ((case-fold-search t))
1268 (looking-at mmdf-delim1))
1269 (looking-at "From "))))
1270 (goto-char (+ header-end size))
1271 (message "Ignoring invalid Content-Length field")
1274 (if (re-search-forward
1275 (concat "^[\^_]?\\("
1276 rmail-unix-mail-delimiter
1279 "^BABYL OPTIONS:\\|"
1280 "\^L\n[01],\\)") nil t)
1281 (goto-char (match-beginning 1))
1282 (goto-char (point-max)))
1283 (setq count (1+ count))
1286 (narrow-to-region start (point))
1287 (goto-char (point-min))
1288 (while (search-forward "\n\^_" nil t); single char
1289 (replace-match "\n^_")))); 2 chars: "^" and "_"
1291 (narrow-to-region (point) (point-max)))
1293 ;; This kludge is because some versions of sendmail.el
1294 ;; insert an extra newline at the beginning that shouldn't
1295 ;; be there. sendmail.el has been fixed, but old versions
1296 ;; may still be in use. -- rms, 7 May 1993.
1297 ((eolp) (delete-char 1))
1298 (t (error "Cannot convert to babyl format")))))
1301 ;; Delete the "From ..." line, creating various other headers with
1302 ;; information from it if they don't already exist. Now puts the
1303 ;; original line into a mail-from: header line for debugging and for
1304 ;; use by the rmail-output function.
1305 (defun rmail-nuke-pinhead-header ()
1308 (let ((start (point))
1311 (search-forward "\n\n")
1313 (goto-char (point-max))
1317 (narrow-to-region start end)
1318 (let ((case-fold-search t))
1320 (setq has-from (search-forward "\nFrom:" nil t))
1322 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
1324 (let ((case-fold-search nil))
1325 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
1329 ;; Keep and reformat the date if we don't
1330 ;; have a Date: field.
1334 "Date: \\2, \\4 \\3 \\9 \\5 "
1336 ;; The timezone could be matched by group 7 or group 10.
1337 ;; If neither of them matched, assume EST, since only
1338 ;; Easterners would be so sloppy.
1339 ;; It's a shame the substitution can't use "\\10".
1341 ((/= (match-beginning 7) (match-end 7)) "\\7")
1342 ((/= (match-beginning 10) (match-end 10))
1343 (buffer-substring (match-beginning 10)
1347 ;; Keep and reformat the sender if we don't
1348 ;; have a From: field.
1354 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1356 (defun rmail-reformat-message (beg end)
1359 (if (/= (following-char) ?0)
1360 (error "Bad format in RMAIL file."))
1361 (let ((buffer-read-only nil)
1362 (delta (- (buffer-size) end)))
1366 (let ((case-fold-search t))
1367 (while (looking-at "Summary-line:\\|Mail-From:")
1369 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1370 (delete-region (point)
1371 (progn (forward-line 1) (point))))
1372 (let ((str (buffer-substring (point)
1373 (save-excursion (search-forward "\n\n" end 'move)
1375 (insert str "*** EOOH ***\n")
1376 (narrow-to-region (point) (- (buffer-size) delta)))
1377 (goto-char (point-min))
1378 (if rmail-message-filter (funcall rmail-message-filter))
1379 (if (or rmail-displayed-headers rmail-ignored-headers)
1380 (rmail-clear-headers))))
1382 (defun rmail-clear-headers (&optional ignored-headers)
1383 "Delete all header fields that Rmail should not show.
1384 If the optional argument IGNORED-HEADERS is non-nil,
1385 delete all header fields whose names match that regexp.
1386 Otherwise, if `rmail-displayed-headers' is non-nil,
1387 delete all header fields *except* those whose names match that regexp.
1388 Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
1389 (if (search-forward "\n\n" nil t)
1390 (let ((case-fold-search t)
1391 (buffer-read-only nil))
1392 (if (and rmail-displayed-headers (null ignored-headers))
1394 (narrow-to-region (point-min) (point))
1396 (goto-char (point-min))
1397 (while (save-excursion
1398 (re-search-forward "\n[^ \t]")
1400 (setq lim (1- (point)))))
1402 (re-search-forward rmail-displayed-headers lim t))
1404 (delete-region (point) lim))))
1405 (goto-char (point-min)))
1406 (or ignored-headers (setq ignored-headers rmail-ignored-headers))
1408 (narrow-to-region (point-min) (point))
1410 (goto-char (point-min))
1411 (re-search-forward ignored-headers nil t))
1413 (delete-region (point)
1414 (progn (re-search-forward "\n[^ \t]")
1415 (1- (point))))))))))
1417 (defun rmail-msg-is-pruned ()
1418 (rmail-maybe-set-message-counters)
1421 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1422 (goto-char (point-min))
1424 (= (following-char) ?1))))
1426 (defun rmail-toggle-header (&optional arg)
1427 "Show original message header if pruned header currently shown, or vice versa.
1428 With argument ARG, show the message header pruned if ARG is greater than zero;
1429 otherwise, show it in full."
1431 (let* ((buffer-read-only nil)
1432 (pruned (rmail-msg-is-pruned))
1434 (> (prefix-numeric-value arg) 0)
1436 (if (eq pruned prune)
1438 (rmail-maybe-set-message-counters)
1439 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1441 (progn (goto-char (point-min))
1446 (let ((case-fold-search t))
1447 (while (looking-at "Summary-Line:\\|Mail-From:")
1449 (insert "*** EOOH ***\n")
1451 (search-forward "\n*** EOOH ***\n")
1453 (let ((temp (point)))
1454 (and (search-forward "\n\n" nil t)
1455 (delete-region temp (point))))
1456 (goto-char (point-min))
1457 (search-forward "\n*** EOOH ***\n")
1458 (narrow-to-region (point) (point-max)))
1459 (rmail-reformat-message (point-min) (point-max)))
1460 (rmail-highlight-headers))))
1462 ;;;; *** Rmail Attributes and Keywords ***
1464 ;; Make a string describing current message's attributes and keywords
1465 ;; and set it up as the name of a minor mode
1466 ;; so it will appear in the mode line.
1467 (defun rmail-display-labels ()
1468 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1473 (goto-char (rmail-msgbeg rmail-current-message))
1475 (if (looking-at "[01],")
1477 (narrow-to-region (point) (progn (end-of-line) (point)))
1478 ;; Truly valid BABYL format requires a space before each
1479 ;; attribute or keyword name. Put them in if missing.
1480 (let (buffer-read-only)
1481 (goto-char (point-min))
1482 (while (search-forward "," nil t)
1483 (or (looking-at "[ ,]") (eobp)
1485 (goto-char (point-max))
1486 (if (search-backward ",," nil 'move)
1488 (if (> (point) (1+ (point-min)))
1489 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
1490 (if (> (- (point-max) (point)) 2)
1494 (buffer-substring (+ (point) 3)
1495 (1- (point-max)))))))))))
1496 ;; Note: we don't use save-restriction because that does not work right
1497 ;; if changes are made outside the saved restriction
1498 ;; before that restriction is restored.
1499 (narrow-to-region beg end)
1500 (set-marker beg nil)
1501 (set-marker end nil)))
1502 (while (string-match " +," blurb)
1503 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1504 (substring blurb (match-end 0)))))
1505 (while (string-match ", +" blurb)
1506 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1507 (substring blurb (match-end 0)))))
1508 (setq mode-line-process
1510 rmail-current-message rmail-total-messages blurb))))
1512 ;; Turn an attribute of a message on or off according to STATE.
1513 ;; ATTR is the name of the attribute, as a string.
1514 ;; MSGNUM is message number to change; nil means current message.
1515 (defun rmail-set-attribute (attr state &optional msgnum)
1516 (let ((omax (point-max-marker))
1517 (omin (point-min-marker))
1518 (buffer-read-only nil))
1519 (or msgnum (setq msgnum rmail-current-message))
1524 (goto-char (+ 3 (rmail-msgbeg msgnum)))
1527 (null (search-backward (concat ", " attr ",")
1528 (prog1 (point) (end-of-line)) t)))))
1529 (or (eq curstate (not (not state)))
1531 (delete-region (point) (1- (match-end 0)))
1534 (insert " " attr ","))))
1535 (if (string= attr "deleted")
1536 (rmail-set-message-deleted-p msgnum state)))
1537 ;; Note: we don't use save-restriction because that does not work right
1538 ;; if changes are made outside the saved restriction
1539 ;; before that restriction is restored.
1540 (narrow-to-region omin omax)
1541 (set-marker omin nil)
1542 (set-marker omax nil)
1543 (if (= msgnum rmail-current-message)
1544 (rmail-display-labels))))))
1546 ;; Return t if the attributes/keywords line of msg number MSG
1547 ;; contains a match for the regexp LABELS.
1548 (defun rmail-message-labels-p (msg labels)
1552 (goto-char (rmail-msgbeg msg))
1554 (re-search-backward labels (prog1 (point) (end-of-line)) t))))
1556 ;;;; *** Rmail Message Selection And Support ***
1558 (defun rmail-msgend (n)
1559 (marker-position (aref rmail-message-vector (1+ n))))
1561 (defun rmail-msgbeg (n)
1562 (marker-position (aref rmail-message-vector n)))
1564 (defun rmail-widen-to-current-msgbeg (function)
1565 "Call FUNCTION with point at start of internal data of current message.
1566 Assumes that bounds were previously narrowed to display the message in Rmail.
1567 The bounds are widened enough to move point where desired, then narrowed
1570 FUNCTION may not change the visible text of the message, but it may
1571 change the invisible header text."
1573 (let ((obeg (- (point-max) (point-min))))
1576 (narrow-to-region (rmail-msgbeg rmail-current-message)
1578 (goto-char (point-min))
1580 ;; Note: we don't use save-restriction because that does not work right
1581 ;; if changes are made outside the saved restriction
1582 ;; before that restriction is restored.
1583 ;; Here we assume that changes made by FUNCTION
1584 ;; occur before the visible region of the message.
1585 (narrow-to-region (- (point-max) obeg) (point-max))))))
1587 (defun rmail-forget-messages ()
1589 (if (vectorp rmail-message-vector)
1591 (v rmail-message-vector)
1594 (move-marker (aref v i) nil)
1596 (setq rmail-message-vector nil)
1597 (setq rmail-deleted-vector nil)))
1599 (defun rmail-maybe-set-message-counters ()
1600 (if (not (and rmail-deleted-vector
1601 rmail-message-vector
1602 rmail-current-message
1603 rmail-total-messages))
1604 (rmail-set-message-counters)))
1606 (defun rmail-count-new-messages (&optional nomsg)
1607 (let* ((case-fold-search nil)
1611 (or nomsg (message "Counting new messages..."))
1612 (goto-char (point-max))
1613 ;; Put at the end of messages-head
1614 ;; the entry for message N+1, which marks
1615 ;; the end of message N. (N = number of messages).
1616 (search-backward "\n\^_")
1618 (setq messages-head (list (point-marker)))
1619 (rmail-set-message-counters-counter (point-min))
1620 (setq rmail-current-message (1+ rmail-total-messages))
1621 (setq rmail-total-messages
1622 (+ rmail-total-messages total-messages))
1623 (setq rmail-message-vector
1624 (vconcat rmail-message-vector (cdr messages-head)))
1625 (aset rmail-message-vector
1626 rmail-current-message (car messages-head))
1627 (setq rmail-deleted-vector
1628 (concat rmail-deleted-vector deleted-head))
1629 (setq rmail-summary-vector
1630 (vconcat rmail-summary-vector (make-vector total-messages nil)))
1631 (goto-char (point-min))
1632 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
1634 (defun rmail-set-message-counters ()
1635 (rmail-forget-messages)
1639 (let* ((point-save (point))
1641 (messages-after-point)
1642 (case-fold-search nil)
1645 (message "Counting messages...")
1646 (goto-char (point-max))
1647 ;; Put at the end of messages-head
1648 ;; the entry for message N+1, which marks
1649 ;; the end of message N. (N = number of messages).
1650 (search-backward "\n\^_" nil t)
1651 (if (/= (point) (point-max)) (forward-char 1))
1652 (setq messages-head (list (point-marker)))
1653 (rmail-set-message-counters-counter (min (point) point-save))
1654 (setq messages-after-point total-messages)
1655 (rmail-set-message-counters-counter)
1656 (setq rmail-total-messages total-messages)
1657 (setq rmail-current-message
1659 (max 1 (- total-messages messages-after-point))))
1660 (setq rmail-message-vector
1661 (apply 'vector (cons (point-min-marker) messages-head))
1662 rmail-deleted-vector (concat "D" deleted-head)
1663 rmail-summary-vector (make-vector rmail-total-messages nil))
1664 (message "Counting messages...done")))))
1666 (defun rmail-set-message-counters-counter (&optional stop)
1667 (while (search-backward "\n\^_\^L\n" stop t)
1669 (setq messages-head (cons (point-marker) messages-head))
1672 (cons (if (search-backward ", deleted,"
1678 (if (zerop (% (setq total-messages (1+ total-messages)) 20))
1679 (message "Counting messages...%d" total-messages))))
1681 (defun rmail-beginning-of-message ()
1682 "Show current message starting from the beginning."
1684 (rmail-show-message rmail-current-message))
1686 (defun rmail-show-message (&optional n no-summary)
1687 "Show message number N (prefix argument), counting from start of file.
1688 If summary buffer is currently displayed, update current message there also."
1690 (rmail-maybe-set-message-counters)
1692 (if (zerop rmail-total-messages)
1693 (progn (narrow-to-region (point-min) (1- (point-max)))
1694 (goto-char (point-min))
1695 (setq mode-line-process nil))
1698 (setq n rmail-current-message)
1701 rmail-current-message 1
1702 blurb "No previous message"))
1703 ((> n rmail-total-messages)
1704 (setq n rmail-total-messages
1705 rmail-current-message rmail-total-messages
1706 blurb "No following message"))
1708 (setq rmail-current-message n))))
1709 (let ((beg (rmail-msgbeg n)))
1712 ;; Clear the "unseen" attribute when we show a message.
1713 (rmail-set-attribute "unseen" nil)
1714 ;; Reformat the header, or else find the reformatted header.
1715 (let ((end (rmail-msgend n)))
1716 (if (= (following-char) ?0)
1717 (rmail-reformat-message beg end)
1718 (search-forward "\n*** EOOH ***\n" end t)
1719 (narrow-to-region (point) end)))
1720 (goto-char (point-min))
1721 (rmail-display-labels)
1722 (rmail-highlight-headers)
1723 (if transient-mark-mode (deactivate-mark))
1724 (run-hooks 'rmail-show-message-hook)
1725 ;; If there is a summary buffer, try to move to this message
1726 ;; in that buffer. But don't complain if this message
1727 ;; is not mentioned in the summary.
1728 ;; Don't do this at all if we were called on behalf
1729 ;; of cursor motion in the summary buffer.
1730 (and (rmail-summary-exists) (not no-summary)
1731 (let ((curr-msg rmail-current-message))
1732 (rmail-select-summary
1733 (rmail-summary-goto-msg curr-msg t t))))
1735 (message blurb))))))
1737 ;; Find all occurrences of certain fields, and highlight them.
1738 (defun rmail-highlight-headers ()
1739 ;; Do this only if the system supports faces.
1740 (if (and (fboundp 'internal-find-face)
1741 rmail-highlighted-headers)
1743 (search-forward "\n\n" nil 'move)
1745 (narrow-to-region (point-min) (point))
1746 (let ((case-fold-search t)
1747 (inhibit-read-only t)
1748 ;; Highlight with boldface if that is available.
1749 ;; Otherwise use the `highlight' face.
1750 (face (or rmail-highlight-face
1751 (if (face-differs-from-default-p 'bold)
1753 ;; List of overlays to reuse.
1754 (overlays rmail-overlay-list))
1755 (goto-char (point-min))
1756 (while (re-search-forward rmail-highlighted-headers nil t)
1757 (skip-chars-forward " \t")
1760 (while (progn (forward-line 1)
1761 (looking-at "[ \t]")))
1762 ;; Back up over newline, then trailing spaces or tabs
1764 (while (member (preceding-char) '(? ?\t))
1767 ;; Reuse an overlay we already have.
1769 (setq overlay (car overlays)
1770 overlays (cdr overlays))
1771 (overlay-put overlay 'face face)
1772 (move-overlay overlay beg (point)))
1773 ;; Make a new overlay and add it to
1774 ;; rmail-overlay-list.
1775 (setq overlay (make-overlay beg (point)))
1776 (overlay-put overlay 'face face)
1777 (setq rmail-overlay-list
1778 (cons overlay rmail-overlay-list))))))))))
1780 (defun rmail-next-message (n)
1781 "Show following message whether deleted or not.
1782 With prefix arg N, moves forward N messages, or backward if N is negative."
1784 (rmail-maybe-set-message-counters)
1785 (rmail-show-message (+ rmail-current-message n)))
1787 (defun rmail-previous-message (n)
1788 "Show previous message whether deleted or not.
1789 With prefix arg N, moves backward N messages, or forward if N is negative."
1791 (rmail-next-message (- n)))
1793 (defun rmail-next-undeleted-message (n)
1794 "Show following non-deleted message.
1795 With prefix arg N, moves forward N non-deleted messages,
1796 or backward if N is negative.
1798 Returns t if a new message is being shown, nil otherwise."
1800 (rmail-maybe-set-message-counters)
1801 (let ((lastwin rmail-current-message)
1802 (current rmail-current-message))
1803 (while (and (> n 0) (< current rmail-total-messages))
1804 (setq current (1+ current))
1805 (if (not (rmail-message-deleted-p current))
1806 (setq lastwin current n (1- n))))
1807 (while (and (< n 0) (> current 1))
1808 (setq current (1- current))
1809 (if (not (rmail-message-deleted-p current))
1810 (setq lastwin current n (1+ n))))
1811 (if (/= lastwin rmail-current-message)
1812 (progn (rmail-show-message lastwin)
1815 (message "No previous nondeleted message"))
1817 (message "No following nondeleted message"))
1820 (defun rmail-previous-undeleted-message (n)
1821 "Show previous non-deleted message.
1822 With prefix argument N, moves backward N non-deleted messages,
1823 or forward if N is negative."
1825 (rmail-next-undeleted-message (- n)))
1827 (defun rmail-first-message ()
1828 "Show first message in file."
1830 (rmail-maybe-set-message-counters)
1831 (rmail-show-message 1))
1833 (defun rmail-last-message ()
1834 "Show last message in file."
1836 (rmail-maybe-set-message-counters)
1837 (rmail-show-message rmail-total-messages))
1839 (defun rmail-what-message ()
1840 (let ((where (point))
1842 (high rmail-total-messages)
1843 (mid (/ rmail-total-messages 2)))
1844 (while (> (- high low) 1)
1845 (if (>= where (rmail-msgbeg mid))
1848 (setq mid (+ low (/ (- high low) 2))))
1849 (if (>= where (rmail-msgbeg high)) high low)))
1851 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
1853 (goto-char (rmail-msgbeg msg))
1854 (search-forward "\n*** EOOH ***\n")
1855 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
1856 (or (string-match recipients (or (mail-fetch-field "To") ""))
1857 (string-match recipients (or (mail-fetch-field "From") ""))
1858 (if (not primary-only)
1859 (string-match recipients (or (mail-fetch-field "Cc") ""))))))
1861 (defun rmail-message-regexp-p (msg regexp)
1862 "Return t, if for message number MSG, regexp REGEXP matches in the header."
1863 (goto-char (rmail-msgbeg msg))
1866 (search-forward "*** EOOH ***" (point-max)) (point))))
1867 (re-search-forward regexp end t)))
1869 (defvar rmail-search-last-regexp nil)
1870 (defun rmail-search (regexp &optional n)
1871 "Show message containing next match for REGEXP (but not the current msg).
1872 Prefix argument gives repeat count; negative argument means search
1873 backwards (through earlier messages).
1874 Interactively, empty argument means use same regexp used last time."
1876 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1878 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1880 (if rmail-search-last-regexp
1881 (setq prompt (concat prompt
1883 rmail-search-last-regexp
1885 (setq regexp (read-string prompt))
1886 (cond ((not (equal regexp ""))
1887 (setq rmail-search-last-regexp regexp))
1888 ((not rmail-search-last-regexp)
1889 (error "No previous Rmail search string")))
1890 (list rmail-search-last-regexp
1891 (prefix-numeric-value current-prefix-arg))))
1893 (message "%sRmail search for %s..."
1894 (if (< n 0) "Reverse " "")
1896 (rmail-maybe-set-message-counters)
1897 (let ((omin (point-min))
1902 (msg rmail-current-message))
1907 ;; Check messages one by one, advancing message number up or down
1908 ;; but searching forward through each message.
1910 (while (and (null win) (> msg 1))
1911 (goto-char (rmail-msgbeg (setq msg (1- msg))))
1912 (setq win (re-search-forward
1913 regexp (rmail-msgend msg) t)))
1914 (while (and (null win) (< msg rmail-total-messages))
1915 (goto-char (rmail-msgbeg (setq msg (1+ msg))))
1916 (setq win (re-search-forward regexp (rmail-msgend msg) t))))
1917 (setq n (+ n (if reversep 1 -1)))))
1920 ;; If this is a reverse search and we found a message,
1921 ;; search backward thru this message to position point.
1924 (goto-char (rmail-msgend msg))
1926 regexp (rmail-msgbeg msg) t)))
1928 (rmail-show-message msg)
1929 (message "%sRmail search for %s...done"
1930 (if reversep "Reverse " "")
1934 (narrow-to-region omin omax)
1936 (message "Search failed: %s" regexp)))))
1938 (defun rmail-search-backwards (regexp &optional n)
1939 "Show message containing previous match for REGEXP.
1940 Prefix argument gives repeat count; negative argument means search
1941 forward (through later messages).
1942 Interactively, empty argument means use same regexp used last time."
1944 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1946 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1948 (if rmail-search-last-regexp
1949 (setq prompt (concat prompt
1951 rmail-search-last-regexp
1953 (setq regexp (read-string prompt))
1954 (cond ((not (equal regexp ""))
1955 (setq rmail-search-last-regexp regexp))
1956 ((not rmail-search-last-regexp)
1957 (error "No previous Rmail search string")))
1958 (list rmail-search-last-regexp
1959 (prefix-numeric-value current-prefix-arg))))
1960 (rmail-search regexp (- (or n 1))))
1962 ;; Show the first message which has the `unseen' attribute.
1963 (defun rmail-first-unseen-message ()
1964 (rmail-maybe-set-message-counters)
1969 (while (and (not found) (<= current rmail-total-messages))
1970 (if (rmail-message-labels-p current ", ?\\(unseen\\),")
1971 (setq found current))
1972 (setq current (1+ current))))
1973 ;; Let the caller show the message.
1975 ;; (rmail-show-message found))
1978 (defun rmail-next-same-subject (n)
1979 "Go to the next mail message having the same subject header.
1980 With prefix argument N, do this N times.
1981 If N is negative, go backwards instead."
1983 (let ((subject (mail-fetch-field "Subject"))
1985 (i rmail-current-message)
1986 search-regexp found)
1987 (if (string-match "Re:[ \t]*" subject)
1988 (setq subject (substring subject (match-end 0))))
1989 (setq search-regexp (concat "^Subject: *\\(Re: *\\)?"
1990 (regexp-quote subject)
1995 (while (and (/= n 0)
1997 (< i rmail-total-messages)
2000 (while (and (not done)
2002 (< i rmail-total-messages)
2004 (setq i (if forward (1+ i) (1- i)))
2005 (goto-char (rmail-msgbeg i))
2006 (search-forward "\n*** EOOH ***\n")
2007 (let ((beg (point)) end)
2008 (search-forward "\n\n")
2011 (setq done (re-search-forward search-regexp end t))))
2012 (if done (setq found i)))
2013 (setq n (if forward (1- n) (1+ n))))))
2015 (rmail-show-message found)
2016 (error "No %s message with same subject"
2017 (if forward "following" "previous")))))
2019 (defun rmail-previous-same-subject (n)
2020 "Go to the previous mail message having the same subject header.
2021 With prefix argument N, do this N times.
2022 If N is negative, go forwards instead."
2024 (rmail-next-same-subject (- n)))
2026 ;;;; *** Rmail Message Deletion Commands ***
2028 (defun rmail-message-deleted-p (n)
2029 (= (aref rmail-deleted-vector n) ?D))
2031 (defun rmail-set-message-deleted-p (n state)
2032 (aset rmail-deleted-vector n (if state ?D ?\ )))
2034 (defun rmail-delete-message ()
2035 "Delete this message and stay on it."
2037 (rmail-set-attribute "deleted" t)
2038 (run-hooks 'rmail-delete-message-hook))
2040 (defun rmail-undelete-previous-message ()
2041 "Back up to deleted message, select it, and undelete it."
2043 (let ((msg rmail-current-message))
2044 (while (and (> msg 0)
2045 (not (rmail-message-deleted-p msg)))
2046 (setq msg (1- msg)))
2048 (error "No previous deleted message")
2049 (if (/= msg rmail-current-message)
2050 (rmail-show-message msg))
2051 (rmail-set-attribute "deleted" nil)
2052 (if (rmail-summary-exists)
2054 (set-buffer rmail-summary-buffer)
2055 (rmail-summary-mark-undeleted msg)))
2056 (rmail-maybe-display-summary))))
2058 (defun rmail-delete-forward (&optional backward)
2059 "Delete this message and move to next nondeleted one.
2060 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
2061 With prefix argument, delete and move backward.
2063 Returns t if a new message is displayed after the delete, or nil otherwise."
2065 (rmail-set-attribute "deleted" t)
2066 (run-hooks 'rmail-delete-message-hook)
2067 (let ((del-msg rmail-current-message))
2068 (if (rmail-summary-exists)
2069 (rmail-select-summary
2070 (rmail-summary-mark-deleted del-msg)))
2071 (prog1 (rmail-next-undeleted-message (if backward -1 1))
2072 (rmail-maybe-display-summary))))
2074 (defun rmail-delete-backward ()
2075 "Delete this message and move to previous nondeleted one.
2076 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
2078 (rmail-delete-forward t))
2080 ;; Compute the message number a given message would have after expunging.
2081 ;; The present number of the message is OLDNUM.
2082 ;; DELETEDVEC should be rmail-deleted-vector.
2083 ;; The value is nil for a message that would be deleted.
2084 (defun rmail-msg-number-after-expunge (deletedvec oldnum)
2085 (if (or (null oldnum) (= (aref deletedvec oldnum) ?D))
2090 (if (/= (aref deletedvec i) ?D)
2091 (setq newnum (1+ newnum)))
2095 (defun rmail-only-expunge ()
2096 "Actually erase all deleted messages in the file."
2098 (message "Expunging deleted messages...")
2099 ;; Discard all undo records for this buffer.
2100 (or (eq buffer-undo-list t)
2101 (setq buffer-undo-list nil))
2102 (rmail-maybe-set-message-counters)
2103 (let* ((omax (- (buffer-size) (point-max)))
2104 (omin (- (buffer-size) (point-min)))
2105 (opoint (if (and (> rmail-current-message 0)
2106 (rmail-message-deleted-p rmail-current-message))
2108 (- (point) (point-min))))
2109 (messages-head (cons (aref rmail-message-vector 0) nil))
2110 (messages-tail messages-head)
2111 ;; Don't make any undo records for the expunging.
2112 (buffer-undo-list t)
2117 (goto-char (point-min))
2120 (total rmail-total-messages)
2121 (new-message-number rmail-current-message)
2123 (rmailbuf (current-buffer))
2124 (buffer-read-only nil)
2125 (messages rmail-message-vector)
2126 (deleted rmail-deleted-vector)
2127 (summary rmail-summary-vector))
2128 (setq rmail-total-messages nil
2129 rmail-current-message nil
2130 rmail-message-vector nil
2131 rmail-deleted-vector nil
2132 rmail-summary-vector nil)
2134 ;; Find each sendmail buffer that is set to reply
2135 ;; to a message in this buffer, and update its
2137 (let ((bufs (buffer-list)))
2140 (set-buffer (car bufs))
2141 (and (boundp 'rmail-send-actions-rmail-buffer)
2142 (eq rmail-send-actions-rmail-buffer rmailbuf)
2143 (setq rmail-send-actions-rmail-msg-number
2144 (rmail-msg-number-after-expunge
2146 rmail-send-actions-rmail-msg-number))))
2147 (setq bufs (cdr bufs))))
2149 (while (<= number total)
2150 (if (= (aref deleted number) ?D)
2153 (marker-position (aref messages number))
2154 (marker-position (aref messages (1+ number))))
2155 (move-marker (aref messages number) nil)
2156 (if (> new-message-number counter)
2157 (setq new-message-number (1- new-message-number))))
2158 (setq counter (1+ counter))
2160 (setcdr messages-tail
2161 (cons (aref messages number) nil)))
2163 (cons (if (= counter number) (aref summary (1- number)))
2165 (if (zerop (% (setq number (1+ number)) 20))
2166 (message "Expunging deleted messages...%d" number)))
2168 (setcdr messages-tail
2169 (cons (aref messages number) nil)))
2170 (setq rmail-current-message new-message-number
2171 rmail-total-messages counter
2172 rmail-message-vector (apply 'vector messages-head)
2173 rmail-deleted-vector (make-string (1+ counter) ?\ )
2174 rmail-summary-vector (vconcat (nreverse new-summary))
2176 (message "Expunging deleted messages...done")
2178 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
2180 (if (zerop rmail-current-message) 1 nil))
2181 (forward-char opoint))))
2183 (defun rmail-expunge ()
2184 "Erase deleted messages from Rmail file and summary buffer."
2186 (rmail-only-expunge)
2187 (if (rmail-summary-exists)
2188 (rmail-select-summary
2189 (rmail-update-summary))))
2191 ;;;; *** Rmail Mailing Commands ***
2193 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
2194 replybuffer sendactions same-window others)
2197 (setq yank-action (list 'insert-buffer replybuffer)))
2198 (setq others (cons (cons "cc" cc) others))
2199 (setq others (cons (cons "in-reply-to" in-reply-to) others))
2201 (compose-mail to subject others
2203 yank-action sendactions)
2204 (if (and window-system rmail-mail-new-frame)
2206 (compose-mail to subject others
2207 noerase 'switch-to-buffer-other-frame
2208 yank-action sendactions)
2209 ;; This is not a standard frame parameter;
2210 ;; nothing except sendmail.el looks at it.
2211 (modify-frame-parameters (selected-frame)
2212 '((mail-dedicated-frame . t))))
2213 (compose-mail to subject others
2214 noerase 'switch-to-buffer-other-window
2215 yank-action sendactions)))))
2217 (defun rmail-mail ()
2218 "Send mail in another window.
2219 While composing the message, use \\[mail-yank-original] to yank the
2220 original message into it."
2222 (rmail-start-mail nil nil nil nil nil (current-buffer)))
2224 (defun rmail-continue ()
2225 "Continue composing outgoing message previously being composed."
2227 (rmail-start-mail t))
2229 (put 'rmail-send-actions-rmail-buffer 'permanent-local t)
2230 (put 'rmail-send-actions-rmail-msg-number 'permanent-local t)
2232 (defun rmail-reply (just-sender)
2233 "Reply to the current message.
2234 Normally include CC: to all other recipients of original message;
2235 prefix argument means ignore them. While composing the reply,
2236 use \\[mail-yank-original] to yank the original message into it."
2238 (let (from reply-to cc subject date to message-id references
2239 resent-to resent-cc resent-reply-to
2240 (msgnum rmail-current-message)
2241 (rmail-buffer (current-buffer)))
2245 (goto-char (rmail-msgbeg rmail-current-message))
2247 (if (= (following-char) ?0)
2249 (progn (forward-line 2)
2251 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
2254 (narrow-to-region (point)
2255 (progn (search-forward "\n*** EOOH ***\n")
2256 (beginning-of-line) (point))))
2257 (setq from (mail-fetch-field "from")
2258 reply-to (or (mail-fetch-field "reply-to" nil t)
2260 cc (and (not just-sender)
2261 (mail-fetch-field "cc" nil t))
2262 subject (mail-fetch-field "subject")
2263 date (mail-fetch-field "date")
2264 to (or (mail-fetch-field "to" nil t) "")
2265 message-id (mail-fetch-field "message-id")
2266 references (mail-fetch-field "references" nil nil t)
2267 resent-reply-to (mail-fetch-field "resent-reply-to" nil t)
2268 resent-cc (and (not just-sender)
2269 (mail-fetch-field "resent-cc" nil t))
2270 resent-to (or (mail-fetch-field "resent-to" nil t) "")
2271 ;;; resent-subject (mail-fetch-field "resent-subject")
2272 ;;; resent-date (mail-fetch-field "resent-date")
2273 ;;; resent-message-id (mail-fetch-field "resent-message-id")
2275 ;; Merge the resent-to and resent-cc into the to and cc.
2276 (if (and resent-to (not (equal resent-to "")))
2277 (if (not (equal to ""))
2278 (setq to (concat to ", " resent-to))
2279 (setq to resent-to)))
2280 (if (and resent-cc (not (equal resent-cc "")))
2281 (if (not (equal cc ""))
2282 (setq cc (concat cc ", " resent-cc))
2283 (setq cc resent-cc)))
2284 ;; Add `Re: ' to subject if not there already.
2285 (and (stringp subject)
2287 (concat rmail-reply-prefix
2288 (if (string-match rmail-reply-regexp subject)
2289 (substring subject (match-end 0))
2291 (rmail-start-mail nil
2292 (mail-strip-quoted-names reply-to)
2294 (rmail-make-in-reply-to-field from date message-id)
2297 (let* ((cc-list (rmail-dont-reply-to
2298 (mail-strip-quoted-names
2299 (if (null cc) to (concat to ", " cc))))))
2300 (if (string= cc-list "") nil cc-list)))
2302 (list (list '(lambda ()
2303 (let ((msgnum rmail-send-actions-rmail-msg-number))
2305 (set-buffer rmail-send-actions-rmail-buffer)
2307 (rmail-set-attribute "answered" t msgnum)))))))
2309 (cons (cons "References" message-id)
2310 (mapcar (function (lambda (elt)
2311 (cons "References" elt)))
2313 ;; We keep the rmail buffer and message number in these
2314 ;; buffer-local vars in the sendmail buffer,
2315 ;; so that rmail-only-expunge can relocate the message number.
2316 (make-local-variable 'rmail-send-actions-rmail-buffer)
2317 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2318 (setq rmail-send-actions-rmail-buffer rmail-buffer)
2319 (setq rmail-send-actions-rmail-msg-number msgnum)))
2321 (defun rmail-make-in-reply-to-field (from date message-id)
2328 (let ((tem (car (rfc822-addresses from))))
2331 (regexp-quote (if (string-match "@[^@]*\\'" tem)
2332 (substring tem 0 (match-beginning 0))
2335 ;; Message-ID is sufficiently informative
2337 (concat message-id " (" tem ")"))
2338 ;; Copy TEM, discarding text properties.
2339 (setq tem (copy-sequence tem))
2340 (set-text-properties 0 (length tem) nil tem)
2341 (setq tem (copy-sequence tem))
2342 ;; Use prin1 to fake RFC822 quoting
2343 (let ((field (prin1-to-string tem)))
2345 (concat field "'s message of " date)
2347 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
2348 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
2349 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
2350 (or (string-match (concat "\\`[ \t]*\\(" bar
2351 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
2352 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
2354 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
2355 bar "\\))[ \t]*\\'")
2356 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
2358 (let ((start (match-beginning 1))
2359 (end (match-end 1)))
2360 ;; Trim whitespace which above regexp match allows
2361 (while (and (< start end)
2362 (memq (aref from start) '(?\t ?\ )))
2363 (setq start (1+ start)))
2364 (while (and (< start end)
2365 (memq (aref from (1- end)) '(?\t ?\ )))
2366 (setq end (1- end)))
2367 (let ((field (substring from start end)))
2368 (if date (setq field (concat "message from " field " on " date)))
2370 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
2371 (concat message-id " (" field ")")
2374 ;; If we can't kludge it simply, do it correctly
2375 (let ((mail-use-rfc822 t))
2376 (rmail-make-in-reply-to-field from date message-id)))))
2378 (defun rmail-forward (resend)
2379 "Forward the current message to another user.
2380 With prefix argument, \"resend\" the message instead of forwarding it;
2381 see the documentation of `rmail-resend'."
2384 (call-interactively 'rmail-resend)
2385 (let ((forward-buffer (current-buffer))
2386 (msgnum rmail-current-message)
2387 (subject (concat "["
2388 (let ((from (or (mail-fetch-field "From")
2389 (mail-fetch-field ">From"))))
2391 (concat (mail-strip-quoted-names from) ": ")
2393 (or (mail-fetch-field "Subject") "")
2395 (if (rmail-start-mail
2396 nil nil subject nil nil nil
2397 (list (list (function
2400 rmail-send-actions-rmail-msg-number))
2402 (set-buffer rmail-send-actions-rmail-buffer)
2404 (rmail-set-attribute
2405 "forwarded" t msgnum))))))))
2406 ;; If only one window, use it for the mail buffer.
2407 ;; Otherwise, use another window for the mail buffer
2408 ;; so that the Rmail buffer remains visible
2409 ;; and sending the mail will get back to it.
2410 (and (not rmail-mail-new-frame) (one-window-p t)))
2411 ;; The mail buffer is now current.
2413 ;; We keep the rmail buffer and message number in these
2414 ;; buffer-local vars in the sendmail buffer,
2415 ;; so that rmail-only-expunge can relocate the message number.
2416 (make-local-variable 'rmail-send-actions-rmail-buffer)
2417 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2418 (setq rmail-send-actions-rmail-buffer forward-buffer)
2419 (setq rmail-send-actions-rmail-msg-number msgnum)
2420 ;; Insert after header separator--before signature if any.
2421 (goto-char (point-min))
2422 (search-forward-regexp
2423 (concat "^" (regexp-quote mail-header-separator) "$"))
2425 (insert "------- Start of forwarded message -------\n")
2426 ;; Quote lines with `- ' if they start with `-'.
2427 (let ((beg (point)) end)
2428 (setq end (point-marker))
2429 (set-marker-insertion-type end t)
2430 (insert-buffer-substring forward-buffer)
2432 (while (re-search-forward "^-" nil t)
2437 (skip-chars-backward "\n")
2440 (delete-region (point) end)
2441 (set-marker end nil))
2442 (insert "------- End of forwarded message -------\n")
2445 (defun rmail-resend (address &optional from comment mail-alias-file)
2446 "Resend current message to ADDRESSES.
2447 ADDRESSES should be a single address, a string consisting of several
2448 addresses separated by commas, or a list of addresses.
2450 Optional FROM is the address to resend the message from, and
2451 defaults to the username of the person redistributing the message.
2452 Optional COMMENT is a string that will be inserted as a comment in the
2454 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2455 typically for purposes of moderating a list."
2456 (interactive "sResend to: ")
2458 (require 'mailalias)
2459 (if (not from) (setq from (user-login-name)))
2460 (let ((tembuf (generate-new-buffer " sendmail temp"))
2461 (mail-header-separator "")
2462 (case-fold-search nil)
2463 (mailbuf (current-buffer)))
2466 ;;>> Copy message into temp buffer
2468 (insert-buffer-substring mailbuf)
2469 (goto-char (point-min))
2470 ;; Delete any Sender field, since that's not specifiable.
2471 ; Only delete Sender fields in the actual header.
2472 (re-search-forward "^$" nil 'move)
2473 ; Using "while" here rather than "if" because some buggy mail
2474 ; software may have inserted multiple Sender fields.
2475 (while (re-search-backward "^Sender:" nil t)
2479 (while (looking-at "[ \t]")
2481 (delete-region beg (point))))
2482 ; Go back to the beginning of the buffer so the Resent- fields
2483 ; are inserted there.
2484 (goto-char (point-min))
2485 ;;>> Insert resent-from:
2486 (insert "Resent-From: " from "\n")
2487 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2488 ;;>> Insert resent-to: and bcc if need be.
2489 (let ((before (point)))
2491 (insert "Resent-Bcc: " (user-login-name) "\n"))
2492 (insert "Resent-To: " (if (stringp address)
2494 (mapconcat 'identity address ",\n\t"))
2496 ;; Expand abbrevs in the recipients.
2498 (if (featurep 'mailabbrev)
2499 (let ((end (point-marker))
2500 (local-abbrev-table mail-abbrevs)
2501 (old-syntax-table (syntax-table)))
2502 (if (and (not (vectorp mail-abbrevs))
2503 (file-exists-p mail-personal-alias-file))
2504 (build-mail-abbrevs))
2505 (set-syntax-table mail-abbrev-syntax-table)
2507 (while (and (< (point) end)
2508 (progn (forward-word 1)
2511 (set-syntax-table old-syntax-table))
2512 (expand-mail-aliases before (point)))))
2513 ;;>> Set up comment, if any.
2514 (if (and (sequencep comment) (not (zerop (length comment))))
2515 (let ((before (point))
2518 (or (eolp) (insert "\n"))
2519 (setq after (point))
2521 (while (< (point) after)
2522 (insert "Resent-Comment: ")
2524 ;; Don't expand aliases in the destination fields
2525 ;; of the original message.
2527 (funcall send-mail-function)))
2528 (kill-buffer tembuf))
2529 (rmail-set-attribute "resent" t rmail-current-message)))
2531 (defvar mail-unsent-separator
2532 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
2533 "^ *---+ +Returned message +---+ *$\\|"
2534 "^Start of returned message$\\|"
2535 "^ *---+ +Original message +---+ *$\\|"
2536 "^ *--+ +begin message +--+ *$\\|"
2537 "^ *---+ +Original message follows +---+ *$\\|"
2538 "^|? *---+ +Message text follows: +---+ *|?$")
2539 "A regexp that matches the separator before the text of a failed message.")
2541 (defun rmail-retry-failure ()
2542 "Edit a mail message which is based on the contents of the current message.
2543 For a message rejected by the mail system, extract the interesting headers and
2544 the body of the original message.
2545 The variable `mail-unsent-separator' should match the string that
2546 delimits the returned original message.
2547 The variable `rmail-retry-ignored-headers' is a regular expression
2548 specifying headers which should not be copied into the new message."
2550 (require 'mail-utils)
2551 (let ((rmail-buffer (current-buffer))
2552 (msgnum rmail-current-message)
2553 bounce-start bounce-end bounce-indent resending)
2555 ;; Narrow down to just the quoted original message
2556 (rmail-beginning-of-message)
2557 (let ((case-fold-search t))
2558 (if (search-forward "This is a MIME-encapsulated message\n\n--" nil t)
2560 (buffer-substring (progn (beginning-of-line) (point))
2561 (progn (end-of-line) (point)))))
2562 (or (re-search-forward mail-unsent-separator nil t)
2563 (error "Cannot find beginning of header in failed message"))
2564 (or (and (search-forward codestring nil t)
2565 (search-forward "\n\n" nil t))
2566 (error "Cannot find end of Mime data in failed message"))
2567 (setq bounce-start (point))
2569 (goto-char (point-max))
2570 (search-backward codestring)
2571 (setq bounce-end (point)))
2572 (or (search-forward "\n\n" nil t)
2573 (error "Cannot find end of header in failed message")))
2574 (or (re-search-forward mail-unsent-separator nil t)
2575 (error "Cannot parse this as a failure message"))
2576 (skip-chars-forward "\n")
2577 ;; Support a style of failure message in which the original
2578 ;; message is indented, and included within lines saying
2579 ;; `Start of returned message' and `End of returned message'.
2580 (if (looking-at " +Received:")
2582 (setq bounce-start (point))
2583 (skip-chars-forward " ")
2584 (setq bounce-indent (- (current-column)))
2585 (goto-char (point-max))
2586 (re-search-backward "^End of returned message$" nil t)
2587 (setq bounce-end (point)))
2588 ;; One message contained a few random lines before the old
2589 ;; message header. The first line of the message started with
2590 ;; two hyphens. A blank line followed these random lines.
2591 ;; The same line beginning with two hyphens was possibly
2592 ;; marking the end of the message.
2593 (if (looking-at "^--")
2594 (let ((boundary (buffer-substring-no-properties
2596 (progn (end-of-line) (point)))))
2597 (search-forward "\n\n")
2598 (skip-chars-forward "\n")
2599 (setq bounce-start (point))
2600 (goto-char (point-max))
2601 (search-backward (concat "\n\n" boundary) bounce-start t)
2602 (setq bounce-end (point)))
2603 (setq bounce-start (point)
2604 bounce-end (point-max)))
2605 (or (search-forward "\n\n" nil t)
2606 (error "Cannot find end of header in failed message"))
2608 ;; Start sending a new message; default header fields from the original.
2609 ;; Turn off the usual actions for initializing the message body
2610 ;; because we want to get only the text from the failure message.
2612 ;; This function will be called when the user sends the retry.
2613 ;; It will mark the bounce message as "retried".
2614 (function (lambda ()
2615 (let ((msgnum rmail-send-actions-rmail-msg-number))
2617 (set-buffer rmail-send-actions-rmail-buffer)
2619 (rmail-set-attribute "retried" t msgnum)))))))
2620 mail-signature mail-setup-hook)
2621 (if (rmail-start-mail nil nil nil nil nil rmail-buffer
2622 (list (list action)))
2623 ;; Insert original text as initial text of new draft message.
2624 ;; Bind inhibit-read-only since the header delimiter
2625 ;; of the previous message was probably read-only.
2626 (let ((inhibit-read-only t))
2627 ;; We keep the rmail buffer and message number in these
2628 ;; buffer-local vars in the sendmail buffer,
2629 ;; so that the rmail-only-expunge can relocate the message number.
2630 (make-local-variable 'rmail-send-actions-rmail-buffer)
2631 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2632 (setq rmail-send-actions-rmail-buffer rmail-buffer)
2633 (setq rmail-send-actions-rmail-msg-number msgnum)
2635 (insert-buffer-substring rmail-buffer bounce-start bounce-end)
2636 (goto-char (point-min))
2638 (indent-rigidly (point-min) (point-max) bounce-indent))
2639 (rmail-clear-headers rmail-retry-ignored-headers)
2640 (rmail-clear-headers "^sender:\\|^from:\\|^return-path:")
2641 (goto-char (point-min))
2643 (search-forward "\n\n")
2645 (narrow-to-region (point-min) (point))
2646 (setq resending (mail-fetch-field "resent-to"))
2649 (insert "Resent-Bcc: " (user-login-name) "\n")
2650 (insert "BCC: " (user-login-name) "\n"))))
2651 (insert mail-header-separator)
2652 (mail-position-on-field (if resending "Resent-To" "To") t)
2653 (set-buffer rmail-buffer)
2654 (rmail-beginning-of-message))))))
2656 (defun rmail-summary-exists ()
2657 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
2658 In fact, the non-nil value returned is the summary buffer itself."
2659 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2660 rmail-summary-buffer))
2662 (defun rmail-summary-displayed ()
2663 "t iff in RMAIL buffer and an associated summary buffer is displayed."
2664 (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
2666 (defvar rmail-redisplay-summary nil
2667 "*Non-nil means Rmail should show the summary when it changes.
2668 This has an effect only if a summary buffer exists.")
2670 (defvar rmail-summary-window-size nil
2671 "*Non-nil means specify the height for an Rmail summary window.")
2673 ;; Put the summary buffer back on the screen, if user wants that.
2674 (defun rmail-maybe-display-summary ()
2675 (let ((selected (selected-window))
2677 ;; If requested, make sure the summary is displayed.
2678 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2679 rmail-redisplay-summary
2680 (if (get-buffer-window rmail-summary-buffer 0)
2681 ;; It's already in some frame; show that one.
2682 (let ((frame (window-frame
2683 (get-buffer-window rmail-summary-buffer 0))))
2684 (make-frame-visible frame)
2685 (raise-frame frame))
2686 (display-buffer rmail-summary-buffer)))
2687 ;; If requested, set the height of the summary window.
2688 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2689 rmail-summary-window-size
2690 (setq window (get-buffer-window rmail-summary-buffer))
2691 ;; Don't try to change the size if just one window in frame.
2692 (not (eq window (frame-root-window (window-frame window))))
2695 (select-window window)
2696 (enlarge-window (- rmail-summary-window-size (window-height))))
2697 (select-window selected)))))
2699 ;;;; *** Rmail Local Fontification ***
2701 (defun rmail-fontify-buffer-function ()
2702 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
2703 (make-local-hook 'rmail-show-message-hook)
2704 (add-hook 'rmail-show-message-hook 'rmail-fontify-message nil t)
2705 ;; If we're already showing a message, fontify it now.
2706 (if rmail-current-message (rmail-fontify-message))
2707 ;; Prevent Font Lock mode from kicking in.
2708 (setq font-lock-fontified t))
2710 (defun rmail-unfontify-buffer-function ()
2711 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
2712 (let ((modified (buffer-modified-p))
2713 (buffer-undo-list t) (inhibit-read-only t)
2714 before-change-functions after-change-functions
2715 buffer-file-name buffer-file-truename)
2718 (remove-hook 'rmail-show-message-hook 'rmail-fontify-message t)
2719 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil))
2720 (font-lock-default-unfontify-buffer)
2721 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
2723 (defun rmail-fontify-message ()
2724 ;; Fontify the current message if it is not already fontified.
2725 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil)
2726 (let ((modified (buffer-modified-p))
2727 (buffer-undo-list t) (inhibit-read-only t)
2728 before-change-functions after-change-functions
2729 buffer-file-name buffer-file-truename)
2732 (add-text-properties (point-min) (point-max) '(rmail-fontified t))
2733 (font-lock-fontify-region (point-min) (point-max))
2734 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))))
2738 ;;; rmail.el ends here