X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mime-text.el;h=8d3021f652cc428fb7601323a6821bdb15fa1a86;hb=9fe7cf94b373e21d85ae49b7267784444ed5a8f0;hp=748ab19596f4cdcddac2c3a9f6f7e7dce295ba93;hpb=4e31f5213308fa82ca6280dc5a7a2b888fd918c7;p=elisp%2Fsemi.git diff --git a/mime-text.el b/mime-text.el index 748ab19..8d3021f 100644 --- a/mime-text.el +++ b/mime-text.el @@ -64,8 +64,8 @@ See also variable `mime-charset-coding-system-alist'." (mime-text-decode-buffer charset) )) -(defun mime-text-decode-body (situation) - "Decode current buffer as text body. +(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 @@ -73,6 +73,9 @@ 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)) @@ -112,42 +115,55 @@ local variable `mime-text-decoder' and variable ) )) +(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-view-filter-for-text/plain (situation) - (mime-text-decode-body situation) - (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-view-filter-for-text/richtext (situation) - (let ((beg (point-min))) - (remove-text-properties beg (point-max) '(face nil)) - (mime-text-decode-body situation) - (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-view-filter-for-text/enriched (situation) - (let ((beg (point-min))) - (remove-text-properties beg (point-max) '(face nil)) - (mime-text-decode-body situation) - (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