From c86849118c60f1f0a0f44f0685d05ec144ccf580 Mon Sep 17 00:00:00 2001 From: keiichi Date: Thu, 21 Jan 1999 08:25:18 +0000 Subject: [PATCH] (lbt-to-string): New inline function. (encode-mime-charset-region): Add new optional argument `lbt'. (encode-mime-charset-string): Ditto. (decode-mime-charset-region): Use `lbt-to-string'. (decode-mime-charset-string): Ditto. --- mcs-om.el | 70 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/mcs-om.el b/mcs-om.el index bff4150..eb71891 100644 --- a/mcs-om.el +++ b/mcs-om.el @@ -26,22 +26,38 @@ (require 'poem) -(defun encode-mime-charset-region (start end charset) +(defsubst lbt-to-string (lbt) + (cdr (assq lbt '((nil . nil) + (CRLF . "\r\n") + (CR . "\r") + (dos . "\r\n") + (mac . "\r")))) + ) + +(defun encode-mime-charset-region (start end charset &optional lbt) "Encode the text between START and END as MIME CHARSET." - (let ((cs (mime-charset-to-coding-system charset))) + (let ((cs (mime-charset-to-coding-system charset lbt))) (if cs (code-convert start end *internal* cs) - ))) + (if (and lbt (setq cs (mime-charset-to-coding-system charset))) + (let ((newline (lbt-to-string lbt))) + (save-excursion + (save-restriction + (narrow-to-region start end) + (code-convert (point-min) (point-max) *internal* cs) + (if newline + (goto-char (point-min)) + (while (search-forward "\n" nil t) + (replace-match newline)))))))))) (defun decode-mime-charset-region (start end charset &optional lbt) "Decode the text between START and END as MIME CHARSET." - (let ((cs (mime-charset-to-coding-system charset lbt)) - newline) + (let ((cs (mime-charset-to-coding-system charset lbt))) (if cs (code-convert start end cs *internal*) (if (and lbt (setq cs (mime-charset-to-coding-system charset))) - (progn - (if (setq newline (cdr (assq lbt '((CRLF . "\r\n") (CR . "\r"))))) + (let ((newline (lbt-to-string lbt))) + (if newline (save-excursion (save-restriction (narrow-to-region start end) @@ -51,29 +67,39 @@ (code-convert (point-min) (point-max) cs *internal*)) (code-convert start end cs *internal*))))))) -(defun encode-mime-charset-string (string charset) +(defun encode-mime-charset-string (string charset &optional lbt) "Encode the STRING as MIME CHARSET." - (let ((cs (mime-charset-to-coding-system charset))) + (let ((cs (mime-charset-to-coding-system charset lbt))) (if cs (code-convert-string string *internal* cs) - string))) + (if (and lbt (setq cs (mime-charset-to-coding-system charset))) + (let ((newline (lbt-to-string lbt))) + (if newline + (with-temp-buffer + (insert string) + (code-convert (point-min) (point-max) *internal* cs) + (goto-char (point-min)) + (while (search-forward "\n" nil t) + (replace-match newline)) + (buffer-string)) + (decode-coding-string string cs))) + string)))) (defun decode-mime-charset-string (string charset &optional lbt) "Decode the STRING which is encoded in MIME CHARSET." - (let ((cs (mime-charset-to-coding-system charset lbt)) - newline) + (let ((cs (mime-charset-to-coding-system charset lbt))) (if cs (decode-coding-string string cs) (if (and lbt (setq cs (mime-charset-to-coding-system charset))) - (progn - (if (setq newline (cdr (assq lbt '((CRLF . "\r\n") (CR . "\r"))))) + (let ((newline (lbt-to-string lbt))) + (if newline (with-temp-buffer - (insert string) - (goto-char (point-min)) - (while (search-forward newline nil t) - (replace-match "\n")) - (code-convert (point-min) (point-max) cs *internal*) - (buffer-string)) + (insert string) + (goto-char (point-min)) + (while (search-forward newline nil t) + (replace-match "\n")) + (code-convert (point-min) (point-max) cs *internal*) + (buffer-string)) (decode-coding-string string cs))) string)))) @@ -119,6 +145,10 @@ )) (defsubst mime-charset-to-coding-system (charset &optional lbt) + "Return coding-system corresponding with CHARSET. +CHARSET is a symbol whose name is MIME charset. +If optional argument LBT (`CRLF', `LF', `CR', `unix', `dos' or `mac') +is specified, it is used as line break code type of coding-system." (if (stringp charset) (setq charset (intern (downcase charset))) ) -- 1.7.10.4