-;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
+;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
;; Copyright (C) 1985,86,87,88,93,94,95,96,97,98,2000, 2001
;; Free Software Foundation, Inc.
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
+;;; Commentary:
+
;;; Code:
;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
;;
(require 'mail-utils)
+(eval-when-compile (require 'mule-util)) ; for detect-coding-with-priority
; These variables now declared in paths.el.
;(defvar rmail-spool-directory "/usr/spool/mail/"
;;;###autoload
(defcustom rmail-dont-reply-to-names nil "\
-*A regexp specifying names to prune of reply to messages.
-A value of nil means exclude your own login name as an address
+*A regexp specifying addresses to prune from a reply message.
+A value of nil means exclude your own email address as an address
plus whatever is specified by `rmail-default-dont-reply-to-names'."
:type '(choice regexp (const :tag "Your Name" nil))
:group 'rmail-reply)
A regular expression specifying part of the value of the default value of
the variable `rmail-dont-reply-to-names', for when the user does not set
`rmail-dont-reply-to-names' explicitly. (The other part of the default
-value is the user's name.)
+value is the user's email address and name.)
It is useful to set this variable in the site customization file.")
;;;###autoload
(other :tag "when asked" ask))
:group 'rmail)
+(defvar rmail-enable-mime-composing nil
+ "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")
+
;;;###autoload
(defvar rmail-show-mime-function nil
"Function to show MIME decoded message of RMAIL file.
;;;###autoload
(defvar rmail-insert-mime-forwarded-message-function nil
"Function to insert a message in MIME format so it can be forwarded.
-This function is called if `rmail-enable-mime' is non-nil.
+This function is called if `rmail-enable-mime' or
+`rmail-enable-mime-composing' is non-nil.
It is called with one argument FORWARD-BUFFER, which is a
buffer containing the message to forward. The current buffer
is the outgoing mail buffer.")
(list (read-file-name "Run rmail on RMAIL file: "))))
(rmail-require-mime-maybe)
(let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
- (existed (get-file-buffer file-name))
- ;; This binding is necessary because we much decide if we
+ ;; Use find-buffer-visiting, not get-file-buffer, for those users
+ ;; who have find-file-visit-truename set to t.
+ (existed (find-buffer-visiting file-name))
+ ;; This binding is necessary because we must decide if we
;; need code conversion while the buffer is unibyte
;; (i.e. enable-multibyte-characters is nil).
(rmail-enable-multibyte
(setq to (point))
(unless (and coding-system
(coding-system-p coding-system))
- (setq coding-system (detect-coding-region from to t)))
+ (setq coding-system
+ ;; Emacs 21.1 and later writes RMAIL files in emacs-mule, but
+ ;; earlier versions did that with the current buffer's encoding.
+ ;; So we want to favor detection of emacs-mule (whose normal
+ ;; priority is quite low), but still allow detection of other
+ ;; encodings if emacs-mule won't fit. The call to
+ ;; detect-coding-with-priority below achieves that.
+ (car (detect-coding-with-priority
+ from to
+ '((coding-category-emacs-mule . emacs-mule))))))
(unless (memq coding-system
'(undecided undecided-unix))
(set-buffer-modified-p t) ; avoid locking when decoding
- (decode-coding-region from to coding-system)
+ (let ((buffer-undo-list t))
+ (decode-coding-region from to coding-system))
(setq coding-system last-coding-system-used))
(set-buffer-modified-p modifiedp)
(setq buffer-file-coding-system nil)
(goto-char beg)
(forward-line 1)
(if (/= (following-char) ?0)
- (error "Bad format in RMAIL file."))
+ (error "Bad format in RMAIL file"))
(let ((inhibit-read-only t)
(delta (- (buffer-size) end)))
(delete-char 1)
(recenter old-screen-line)
(if (and all-headers-visible
(not (= (window-start) (point-min))))
- (let ((lines-offscreen (rmail-count-screen-lines
- (point-min)
- (window-start window))))
- (recenter (min (+ old-screen-line lines-offscreen)
- ;; last line of window
- (- (window-height) 2))))))))))
+ (recenter (- (window-height) 2))))))))
(rmail-highlight-headers))))
(defun rmail-narrow-to-non-pruned-header ()
(search-forward "\n*** EOOH ***\n" end t)
(narrow-to-region (point) end)))
(goto-char (point-min))
+ (walk-windows
+ (function (lambda (window)
+ (if (eq (window-buffer window) (current-buffer))
+ (set-window-point window (point)))))
+ nil t)
(rmail-display-labels)
(if (eq rmail-enable-mime t)
(funcall rmail-show-mime-function)
(or (eq major-mode 'rmail-mode)
(switch-to-buffer rmail-buffer))
(save-excursion
- (unwind-protect
- (let ((msgbeg (rmail-msgbeg rmail-current-message))
- (msgend (rmail-msgend rmail-current-message))
- x-coding-header)
- (narrow-to-region msgbeg msgend)
- (goto-char (point-min))
- (when (search-forward "\n*** EOOH ***\n" (point-max) t)
- (narrow-to-region msgbeg (point)))
- (goto-char (point-min))
- (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t)
- (let ((old-coding (intern (match-string 1)))
- (buffer-read-only nil))
- (check-coding-system old-coding)
- ;; Make sure the new coding system uses the same EOL
- ;; conversion, to prevent ^M characters from popping
- ;; up all over the place.
- (setq coding
- (coding-system-change-eol-conversion
- coding
- (coding-system-eol-type old-coding)))
- (setq x-coding-header (point-marker))
- (narrow-to-region msgbeg msgend)
- (encode-coding-region (point) msgend old-coding)
- (decode-coding-region (point) msgend coding)
- (setq last-coding-system-used coding)
- ;; Rewrite the coding-system header according
- ;; to what we did.
- (goto-char x-coding-header)
- (delete-region (point)
- (save-excursion
- (beginning-of-line)
- (point)))
- (insert "X-Coding-System: "
- (symbol-name last-coding-system-used))
- (set-marker x-coding-header nil)
- (rmail-show-message))
- (error "No X-Coding-System header found")))))))
+ (let ((pruned (rmail-msg-is-pruned)))
+ (unwind-protect
+ (let ((msgbeg (rmail-msgbeg rmail-current-message))
+ (msgend (rmail-msgend rmail-current-message))
+ x-coding-header)
+ ;; We need the message headers pruned (we later restore
+ ;; the pruned stat to what it was, see the end of
+ ;; unwind-protect form).
+ (or pruned
+ (rmail-toggle-header 1))
+ (narrow-to-region msgbeg msgend)
+ (goto-char (point-min))
+ (when (search-forward "\n*** EOOH ***\n" (point-max) t)
+ (narrow-to-region msgbeg (point)))
+ (goto-char (point-min))
+ (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t)
+ (let ((old-coding (intern (match-string 1)))
+ (buffer-read-only nil))
+ (check-coding-system old-coding)
+ ;; Make sure the new coding system uses the same EOL
+ ;; conversion, to prevent ^M characters from popping
+ ;; up all over the place.
+ (setq coding
+ (coding-system-change-eol-conversion
+ coding
+ (coding-system-eol-type old-coding)))
+ (setq x-coding-header (point-marker))
+ (narrow-to-region msgbeg msgend)
+ (encode-coding-region (point) msgend old-coding)
+ (decode-coding-region (point) msgend coding)
+ (setq last-coding-system-used coding)
+ ;; Rewrite the coding-system header according
+ ;; to what we did.
+ (goto-char x-coding-header)
+ (delete-region (point)
+ (save-excursion
+ (beginning-of-line)
+ (point)))
+ (insert "X-Coding-System: "
+ (symbol-name last-coding-system-used))
+ (set-marker x-coding-header nil)
+ (rmail-show-message))
+ (error "No X-Coding-System header found")))
+ (or pruned
+ (rmail-toggle-header 0)))))))
;; Find all occurrences of certain fields, and highlight them.
(defun rmail-highlight-headers ()
(save-excursion
;; Insert after header separator--before signature if any.
(goto-char (mail-text-start))
- (if rmail-enable-mime
+ (if (or rmail-enable-mime rmail-enable-mime-composing)
(funcall rmail-insert-mime-forwarded-message-function
forward-buffer)
(insert "------- Start of forwarded message -------\n")
(if (and (not (vectorp mail-abbrevs))
(file-exists-p mail-personal-alias-file))
(build-mail-abbrevs))
+ (unless mail-abbrev-syntax-table
+ (mail-abbrev-make-syntax-table))
(set-syntax-table mail-abbrev-syntax-table)
(goto-char before)
(while (and (< (point) end)
(defun rmail-fontify-buffer-function ()
;; This function's symbol is bound to font-lock-fontify-buffer-function.
- (make-local-hook 'rmail-show-message-hook)
(add-hook 'rmail-show-message-hook 'rmail-fontify-message nil t)
;; If we're already showing a message, fontify it now.
(if rmail-current-message (rmail-fontify-message))