X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mime-text.el;h=8d3021f652cc428fb7601323a6821bdb15fa1a86;hb=9fe7cf94b373e21d85ae49b7267784444ed5a8f0;hp=b6d6e5344adc0235f0c972fc5b08fee51477da57;hpb=e7e2a797df095b5b92c33aadbd9d7c126433eb4a;p=elisp%2Fsemi.git diff --git a/mime-text.el b/mime-text.el index b6d6e53..8d3021f 100644 --- a/mime-text.el +++ b/mime-text.el @@ -1,13 +1,11 @@ ;;; mime-text.el --- mime-view content filter for text -;; Copyright (C) 1994,1995,1996,1997 Free Software Foundation, Inc. +;; Copyright (C) 1994,1995,1996,1997,1998 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko -;; Version: -;; $Id: mime-text.el,v 0.18 1997-03-16 00:01:21 morioka Exp $ ;; Keywords: text, MIME, multimedia, mail, news -;; This file is part of SEMI (SEMI is Emacs MIME Interfaces). +;; This file is part of SEMI (Suite of Emacs MIME Interfaces). ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as @@ -26,6 +24,9 @@ ;;; Code: +(require 'mime-view) + + ;;; @ buffer local variables in raw-buffer ;;; @@ -44,34 +45,55 @@ raw-buffer.") ;;; @ code conversion ;;; -(defvar mime-text-decoder-alist - '((mime/show-message-mode . mime-text-decode-buffer) - (mime-temp-message-mode . mime-text-decode-buffer) - (t . mime-charset/maybe-decode-buffer) - )) - (defun mime-text-decode-buffer (charset &optional encoding) + "Decode text of current buffer as CHARSET. +It code-converts current buffer from network representation specified +by MIME CHARSET to internal code. CHARSET is symbol of MIME charset. +See also variable `mime-charset-coding-system-alist'." (decode-mime-charset-region (point-min)(point-max) (or charset default-mime-charset)) ) -(defun mime-charset/maybe-decode-buffer (charset &optional encoding) +(defun mime-text-decode-buffer-maybe (charset &optional encoding) + "Decode text of current buffer as CHARSET if ENCODING is actual encoding. +It code-converts current buffer from network representation specified +by MIME CHARSET to internal code if ENCODING is not nil, \"7bit\", +\"8bit\" or \"binary\". CHARSET is symbol of MIME charset. +See also variable `mime-charset-coding-system-alist'." (or (member encoding '(nil "7bit" "8bit" "binary")) (mime-text-decode-buffer charset) )) -(defun mime-preview/decode-text-buffer (charset encoding) - (mime-decode-region (point-min) (point-max) encoding) - (let ((text-decoder - (save-excursion - (set-buffer mime::preview/article-buffer) - (or mime-text-decoder - (cdr (or (assq major-mode mime-text-decoder-alist) - (assq t mime-text-decoder-alist))) - )))) - (and (functionp text-decoder) - (funcall text-decoder charset encoding) - ))) +(defun mime-text-insert-decoded-body (entity situation) + "Insert text body of ENTITY in SITUATION. +It decodes MIME-encoding then code-converts as MIME-charset. +MIME-encoding is value of field 'encoding of SITUATION. It must be +'nil or string. MIME-charset is value of field \"charset\" of +SITUATION. It must be symbol. +This function calls text-decoder for MIME-charset specified by buffer +local variable `mime-text-decoder' and variable +`mime-text-decoder-alist'." + (insert-buffer-substring mime-raw-buffer + (mime-entity-body-start entity) + (mime-entity-body-end entity)) + (let ((encoding (cdr (assq 'encoding situation)))) + (mime-decode-region (point-min) (point-max) encoding) + (goto-char (point-min)) + (while (search-forward "\r\n" nil t) + (replace-match "\n") + ) + (let ((text-decoder + (save-excursion + (set-buffer mime-raw-buffer) + (or mime-text-decoder + (cdr (or (assq major-mode mime-text-decoder-alist) + (assq t mime-text-decoder-alist))) + )))) + (and (functionp text-decoder) + (funcall text-decoder (cdr (assoc "charset" situation)) encoding) + )) + (run-hooks 'mime-text-decode-hook) + )) ;;; @ for URL @@ -93,46 +115,55 @@ raw-buffer.") ) )) +(defsubst mime-text-add-url-buttons () + "Add URL-buttons for text body." + (goto-char (point-min)) + (while (re-search-forward mime-text-url-regexp nil t) + (let ((beg (match-beginning 0)) + (end (match-end 0))) + (mime-add-button beg end #'mime-text-browse-url + (list (buffer-substring beg end))) + ))) + +(defun mime-text-add-url-buttons-maybe () + "Add URL-buttons if 'browse-url-browser-function is not 'nil." + (if browse-url-browser-function + (mime-text-add-url-buttons) + )) + ;;; @ content filters for mime-text ;;; -(defun mime-preview/filter-for-text/plain (ctype params encoding) - (mime-preview/decode-text-buffer (cdr (assoc "charset" params)) encoding) - (goto-char (point-max)) - (if (not (eq (char-after (1- (point))) ?\n)) - (insert "\n") - ) - (if browse-url-browser-function - (progn - (goto-char (point-min)) - (while (re-search-forward mime-text-url-regexp nil t) - (let ((beg (match-beginning 0)) - (end (match-end 0))) - (mime-add-button beg end - (function mime-text-browse-url) - (list (buffer-substring beg end)))) - ))) - (run-hooks 'mime-view-plain-text-preview-hook) - ) - -(defun mime-preview/filter-for-text/richtext (ctype params encoding) - (let* ((charset (cdr (assoc "charset" params))) - (beg (point-min)) - ) - (remove-text-properties beg (point-max) '(face nil)) - (mime-preview/decode-text-buffer charset encoding) - (richtext-decode beg (point-max)) +(defun mime-preview-text/plain (entity situation) + (save-restriction + (narrow-to-region (point-max)(point-max)) + (mime-text-insert-decoded-body entity situation) + (goto-char (point-max)) + (if (not (eq (char-after (1- (point))) ?\n)) + (insert "\n") + ) + (mime-text-add-url-buttons) + (run-hooks 'mime-preview-text/plain-hook) )) -(defun mime-preview/filter-for-text/enriched (ctype params encoding) - (let* ((charset (cdr (assoc "charset" params))) - (beg (point-min)) - ) - (remove-text-properties beg (point-max) '(face nil)) - (mime-preview/decode-text-buffer charset encoding) - (enriched-decode beg (point-max)) - )) +(defun mime-preview-text/richtext (entity situation) + (save-restriction + (narrow-to-region (point-max)(point-max)) + (mime-text-insert-decoded-body entity situation) + (let ((beg (point-min))) + (remove-text-properties beg (point-max) '(face nil)) + (richtext-decode beg (point-max)) + ))) + +(defun mime-preview-text/enriched (entity situation) + (save-restriction + (narrow-to-region (point-max)(point-max)) + (mime-text-insert-decoded-body entity situation) + (let ((beg (point-min))) + (remove-text-properties beg (point-max) '(face nil)) + (enriched-decode beg (point-max)) + ))) ;;; @ end