diff options
| author | Kenichi Handa | 1998-02-20 01:45:50 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1998-02-20 01:45:50 +0000 |
| commit | 7d862e077989b7399efc184b35f4ea643c19b2e4 (patch) | |
| tree | b35122dd9332de844029d470c84b5a33c6cb377a | |
| parent | 295baf1f72c180c85447f042829844035e847195 (diff) | |
| download | emacs-7d862e077989b7399efc184b35f4ea643c19b2e4.tar.gz emacs-7d862e077989b7399efc184b35f4ea643c19b2e4.zip | |
(rmail-enable-multibyte): New variable
(rmail): Bind coding-system-for-read to raw-text. Set the buffer
multibyte if necessary.
(rmail-convert-file): Call rmail-decode-babyl-format only when we
don't have to call rmail-convert-to-babyl-format.
(rmail-decode-babyl-format): If rmail-file-coding-system is nil,
detect it.
(rmail-get-new-mail): Bind rmail-enable-multibyte locally.
(rmail-convert-to-babyl-format): Check the value of
rmail-enable-multibyte instead of enable-multibyte-characters.
| -rw-r--r-- | lisp/mail/rmail.el | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index 0371837b6a2..2eb712e9338 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el | |||
| @@ -429,6 +429,8 @@ is non-nil.") | |||
| 429 | 429 | ||
| 430 | ;;;; *** Rmail Mode *** | 430 | ;;;; *** Rmail Mode *** |
| 431 | 431 | ||
| 432 | (defvar rmail-enable-multibyte nil) | ||
| 433 | |||
| 432 | ;;;###autoload | 434 | ;;;###autoload |
| 433 | (defun rmail (&optional file-name-arg) | 435 | (defun rmail (&optional file-name-arg) |
| 434 | "Read and edit incoming mail. | 436 | "Read and edit incoming mail. |
| @@ -452,6 +454,14 @@ If `rmail-display-summary' is non-nil, make a summary for this RMAIL file." | |||
| 452 | (setq rmail-enable-mime nil)))) | 454 | (setq rmail-enable-mime nil)))) |
| 453 | (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name))) | 455 | (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name))) |
| 454 | (existed (get-file-buffer file-name)) | 456 | (existed (get-file-buffer file-name)) |
| 457 | (rmail-enable-multibyte (default-value 'enable-multibyte-characters)) | ||
| 458 | ;; Since the file may contain messages of different encodings | ||
| 459 | ;; at the tail (non-BYBYL part), we can't decode them at once | ||
| 460 | ;; on reading. So, at first, we read the file without text | ||
| 461 | ;; code conversion, then decode the messages one by one by | ||
| 462 | ;; rmail-decode-babyl-format or | ||
| 463 | ;; rmail-convert-to-babyl-format. | ||
| 464 | (coding-system-for-read (and rmail-enable-multibyte 'raw-text)) | ||
| 455 | run-mail-hook msg-shown) | 465 | run-mail-hook msg-shown) |
| 456 | ;; Like find-file, but in the case where a buffer existed | 466 | ;; Like find-file, but in the case where a buffer existed |
| 457 | ;; and the file was reverted, recompute the message-data. | 467 | ;; and the file was reverted, recompute the message-data. |
| @@ -478,6 +488,11 @@ If `rmail-display-summary' is non-nil, make a summary for this RMAIL file." | |||
| 478 | (rmail-mode-2) | 488 | (rmail-mode-2) |
| 479 | ;; Convert all or part to Babyl file if possible. | 489 | ;; Convert all or part to Babyl file if possible. |
| 480 | (rmail-convert-file) | 490 | (rmail-convert-file) |
| 491 | ;; As we have read a file by raw-text, the buffer is set to | ||
| 492 | ;; unibyte. We must make it multibyte if necessary. | ||
| 493 | (if (and rmail-enable-multibyte | ||
| 494 | (not enable-multibyte-characters)) | ||
| 495 | (set-buffer-multibyte t)) | ||
| 481 | (goto-char (point-max)) | 496 | (goto-char (point-max)) |
| 482 | (if (null rmail-inbox-list) | 497 | (if (null rmail-inbox-list) |
| 483 | (progn | 498 | (progn |
| @@ -531,13 +546,6 @@ If `rmail-display-summary' is non-nil, make a summary for this RMAIL file." | |||
| 531 | ;; Non-empty file in non-RMAIL format. Add header and convert. | 546 | ;; Non-empty file in non-RMAIL format. Add header and convert. |
| 532 | (setq convert t) | 547 | (setq convert t) |
| 533 | (rmail-insert-rmail-file-header))) | 548 | (rmail-insert-rmail-file-header))) |
| 534 | (if (and (not convert) | ||
| 535 | (not rmail-enable-mime) | ||
| 536 | rmail-file-coding-system) | ||
| 537 | ;; Decode coding system of BABYL part at the head only. The | ||
| 538 | ;; remaining non BABYL parts are decoded in | ||
| 539 | ;; rmail-convert-to-babyl-format if necessary. | ||
| 540 | (rmail-decode-babyl-format)) | ||
| 541 | ;; If file was not a Babyl file or if there are | 549 | ;; If file was not a Babyl file or if there are |
| 542 | ;; Unix format messages added at the end, | 550 | ;; Unix format messages added at the end, |
| 543 | ;; convert file as necessary. | 551 | ;; convert file as necessary. |
| @@ -556,7 +564,11 @@ If `rmail-display-summary' is non-nil, make a summary for this RMAIL file." | |||
| 556 | (search-forward "\n\^_" nil t) | 564 | (search-forward "\n\^_" nil t) |
| 557 | (narrow-to-region (point) (point-max)) | 565 | (narrow-to-region (point) (point-max)) |
| 558 | (rmail-convert-to-babyl-format) | 566 | (rmail-convert-to-babyl-format) |
| 559 | (message "Converting to Babyl format...done"))))) | 567 | (message "Converting to Babyl format...done")) |
| 568 | (if (and (not rmail-enable-mime) | ||
| 569 | rmail-enable-multibyte) | ||
| 570 | ;; We still have to decode BABYL part. | ||
| 571 | (rmail-decode-babyl-format))))) | ||
| 560 | 572 | ||
| 561 | ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line | 573 | ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line |
| 562 | ;;; will not cause emacs 18.55 problems. | 574 | ;;; will not cause emacs 18.55 problems. |
| @@ -571,22 +583,34 @@ Note: If you are seeing it in rmail, | |||
| 571 | Note: it means the file has no messages in it.\n\^_"))) | 583 | Note: it means the file has no messages in it.\n\^_"))) |
| 572 | 584 | ||
| 573 | ;; Decode Babyl formated part at the head of current buffer by | 585 | ;; Decode Babyl formated part at the head of current buffer by |
| 574 | ;; rmail-file-coding-system. | 586 | ;; rmail-file-coding-system, or if it is nil, do auto conversion. |
| 575 | 587 | ||
| 576 | (defun rmail-decode-babyl-format () | 588 | (defun rmail-decode-babyl-format () |
| 577 | (let ((modifiedp (buffer-modified-p)) | 589 | (let ((modifiedp (buffer-modified-p)) |
| 578 | (buffer-read-only nil) | 590 | (buffer-read-only nil) |
| 579 | pos) | 591 | from to) |
| 580 | (goto-char (point-min)) | 592 | (goto-char (point-min)) |
| 581 | (search-forward "\n\^_" nil t) ; Skip BYBYL header. | 593 | (search-forward "\n\^_" nil t) ; Skip BYBYL header. |
| 582 | (setq pos (point)) | 594 | (setq from (point)) |
| 583 | (message "Decoding messages...") | 595 | (goto-char (point-max)) |
| 584 | (while (search-forward "\n\^_" nil t) | 596 | (search-backward "\n\^_" from 'mv) |
| 585 | (decode-coding-region pos (point) rmail-file-coding-system) | 597 | (setq to (point)) |
| 586 | (setq pos (point))) | 598 | (if (not (and rmail-file-coding-system |
| 587 | (message "Decoding messages...done") | 599 | (coding-system-p rmail-file-coding-system))) |
| 588 | (set-buffer-file-coding-system rmail-file-coding-system) | 600 | (setq rmail-file-coding-system (detect-coding-region from to t))) |
| 589 | (set-buffer-modified-p modifiedp))) | 601 | (if (not (eq rmail-file-coding-system 'undecided)) |
| 602 | (let ((count 1)) | ||
| 603 | (goto-char from) | ||
| 604 | (while (search-forward "\n\^_" nil t) | ||
| 605 | (decode-coding-region from (1- (point)) rmail-file-coding-system) | ||
| 606 | (goto-char (point)) | ||
| 607 | (setq from (point)) | ||
| 608 | (if (= (% count 10) 0) | ||
| 609 | (message "Decoding messages (%d)..." count)) | ||
| 610 | (setq count (1+ count))) | ||
| 611 | (message "Decoding messages (%d)...done" count) | ||
| 612 | (set-buffer-file-coding-system rmail-file-coding-system) | ||
| 613 | (set-buffer-modified-p modifiedp))))) | ||
| 590 | 614 | ||
| 591 | (if rmail-mode-map | 615 | (if rmail-mode-map |
| 592 | nil | 616 | nil |
| @@ -1085,6 +1109,7 @@ It returns t if it got any new messages." | |||
| 1085 | (setq buffer-undo-list nil)) | 1109 | (setq buffer-undo-list nil)) |
| 1086 | (let ((all-files (if file-name (list file-name) | 1110 | (let ((all-files (if file-name (list file-name) |
| 1087 | rmail-inbox-list)) | 1111 | rmail-inbox-list)) |
| 1112 | (rmail-enable-multibyte (default-value 'enable-multibyte-characters)) | ||
| 1088 | found) | 1113 | found) |
| 1089 | (unwind-protect | 1114 | (unwind-protect |
| 1090 | (progn | 1115 | (progn |
| @@ -1396,9 +1421,10 @@ Optional DEFAULT is password to start with." | |||
| 1396 | (skip-chars-forward " \t\n") | 1421 | (skip-chars-forward " \t\n") |
| 1397 | (point))) | 1422 | (point))) |
| 1398 | (or rmail-enable-mime | 1423 | (or rmail-enable-mime |
| 1399 | (not rmail-file-coding-system) | 1424 | (not rmail-enable-multibyte) |
| 1400 | (decode-coding-region start (point) | 1425 | (decode-coding-region start (point) |
| 1401 | rmail-file-coding-system)) | 1426 | (or rmail-file-coding-system |
| 1427 | 'undecided))) | ||
| 1402 | (narrow-to-region (point) (point-max))) | 1428 | (narrow-to-region (point) (point-max))) |
| 1403 | ;;*** MMDF format | 1429 | ;;*** MMDF format |
| 1404 | ((let ((case-fold-search t)) | 1430 | ((let ((case-fold-search t)) |
| @@ -1414,7 +1440,7 @@ Optional DEFAULT is password to start with." | |||
| 1414 | (while (search-forward "\n\^_" nil t); single char "\^_" | 1440 | (while (search-forward "\n\^_" nil t); single char "\^_" |
| 1415 | (replace-match "\n^_")))); 2 chars: "^" and "_" | 1441 | (replace-match "\n^_")))); 2 chars: "^" and "_" |
| 1416 | (or rmail-enable-mime | 1442 | (or rmail-enable-mime |
| 1417 | (not enable-multibyte-characters) | 1443 | (not rmail-enable-multibyte) |
| 1418 | (decode-coding-region start (point) 'undecided)) | 1444 | (decode-coding-region start (point) 'undecided)) |
| 1419 | (narrow-to-region (point) (point-max)) | 1445 | (narrow-to-region (point) (point-max)) |
| 1420 | (setq count (1+ count))) | 1446 | (setq count (1+ count))) |
| @@ -1490,7 +1516,7 @@ Optional DEFAULT is password to start with." | |||
| 1490 | (replace-match "\n^_")))); 2 chars: "^" and "_" | 1516 | (replace-match "\n^_")))); 2 chars: "^" and "_" |
| 1491 | (insert ?\^_) | 1517 | (insert ?\^_) |
| 1492 | (or rmail-enable-mime | 1518 | (or rmail-enable-mime |
| 1493 | (not enable-multibyte-characters) | 1519 | (not rmail-enable-multibyte) |
| 1494 | (decode-coding-region start (point) 'undecided)) | 1520 | (decode-coding-region start (point) 'undecided)) |
| 1495 | (narrow-to-region (point) (point-max))) | 1521 | (narrow-to-region (point) (point-max))) |
| 1496 | ;; | 1522 | ;; |