\f
;;;; *** Rmail Mode ***
+(defvar rmail-enable-multibyte nil)
+
;;;###autoload
(defun rmail (&optional file-name-arg)
"Read and edit incoming mail.
(setq rmail-enable-mime nil))))
(let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
(existed (get-file-buffer file-name))
+ (rmail-enable-multibyte (default-value 'enable-multibyte-characters))
+ ;; Since the file may contain messages of different encodings
+ ;; at the tail (non-BYBYL part), we can't decode them at once
+ ;; on reading. So, at first, we read the file without text
+ ;; code conversion, then decode the messages one by one by
+ ;; rmail-decode-babyl-format or
+ ;; rmail-convert-to-babyl-format.
+ (coding-system-for-read (and rmail-enable-multibyte 'raw-text))
run-mail-hook msg-shown)
;; Like find-file, but in the case where a buffer existed
;; and the file was reverted, recompute the message-data.
(rmail-mode-2)
;; Convert all or part to Babyl file if possible.
(rmail-convert-file)
+ ;; As we have read a file by raw-text, the buffer is set to
+ ;; unibyte. We must make it multibyte if necessary.
+ (if (and rmail-enable-multibyte
+ (not enable-multibyte-characters))
+ (set-buffer-multibyte t))
(goto-char (point-max))
(if (null rmail-inbox-list)
(progn
;; Non-empty file in non-RMAIL format. Add header and convert.
(setq convert t)
(rmail-insert-rmail-file-header)))
- (if (and (not convert)
- (not rmail-enable-mime)
- rmail-file-coding-system)
- ;; Decode coding system of BABYL part at the head only. The
- ;; remaining non BABYL parts are decoded in
- ;; rmail-convert-to-babyl-format if necessary.
- (rmail-decode-babyl-format))
;; If file was not a Babyl file or if there are
;; Unix format messages added at the end,
;; convert file as necessary.
(search-forward "\n\^_" nil t)
(narrow-to-region (point) (point-max))
(rmail-convert-to-babyl-format)
- (message "Converting to Babyl format...done")))))
+ (message "Converting to Babyl format...done"))
+ (if (and (not rmail-enable-mime)
+ rmail-enable-multibyte)
+ ;; We still have to decode BABYL part.
+ (rmail-decode-babyl-format)))))
;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
;;; will not cause emacs 18.55 problems.
Note: it means the file has no messages in it.\n\^_")))
;; Decode Babyl formated part at the head of current buffer by
-;; rmail-file-coding-system.
+;; rmail-file-coding-system, or if it is nil, do auto conversion.
(defun rmail-decode-babyl-format ()
(let ((modifiedp (buffer-modified-p))
(buffer-read-only nil)
- pos)
+ from to)
(goto-char (point-min))
(search-forward "\n\^_" nil t) ; Skip BYBYL header.
- (setq pos (point))
- (message "Decoding messages...")
- (while (search-forward "\n\^_" nil t)
- (decode-coding-region pos (point) rmail-file-coding-system)
- (setq pos (point)))
- (message "Decoding messages...done")
- (set-buffer-file-coding-system rmail-file-coding-system)
- (set-buffer-modified-p modifiedp)))
+ (setq from (point))
+ (goto-char (point-max))
+ (search-backward "\n\^_" from 'mv)
+ (setq to (point))
+ (if (not (and rmail-file-coding-system
+ (coding-system-p rmail-file-coding-system)))
+ (setq rmail-file-coding-system (detect-coding-region from to t)))
+ (if (not (eq rmail-file-coding-system 'undecided))
+ (let ((count 1))
+ (goto-char from)
+ (while (search-forward "\n\^_" nil t)
+ (decode-coding-region from (1- (point)) rmail-file-coding-system)
+ (goto-char (point))
+ (setq from (point))
+ (if (= (% count 10) 0)
+ (message "Decoding messages (%d)..." count))
+ (setq count (1+ count)))
+ (message "Decoding messages (%d)...done" count)
+ (set-buffer-file-coding-system rmail-file-coding-system)
+ (set-buffer-modified-p modifiedp)))))
(if rmail-mode-map
nil
(setq buffer-undo-list nil))
(let ((all-files (if file-name (list file-name)
rmail-inbox-list))
+ (rmail-enable-multibyte (default-value 'enable-multibyte-characters))
found)
(unwind-protect
(progn
(skip-chars-forward " \t\n")
(point)))
(or rmail-enable-mime
- (not rmail-file-coding-system)
+ (not rmail-enable-multibyte)
(decode-coding-region start (point)
- rmail-file-coding-system))
+ (or rmail-file-coding-system
+ 'undecided)))
(narrow-to-region (point) (point-max)))
;;*** MMDF format
((let ((case-fold-search t))
(while (search-forward "\n\^_" nil t); single char "\^_"
(replace-match "\n^_")))); 2 chars: "^" and "_"
(or rmail-enable-mime
- (not enable-multibyte-characters)
+ (not rmail-enable-multibyte)
(decode-coding-region start (point) 'undecided))
(narrow-to-region (point) (point-max))
(setq count (1+ count)))
(replace-match "\n^_")))); 2 chars: "^" and "_"
(insert ?\^_)
(or rmail-enable-mime
- (not enable-multibyte-characters)
+ (not rmail-enable-multibyte)
(decode-coding-region start (point) 'undecided))
(narrow-to-region (point) (point-max)))
;;