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