X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=tm-view.el;h=767e49bda8b402eee4d0b48f9f7c87e8ea4594df;hb=f94c46d394e1304bcc35fee20db5523746cf7a7a;hp=0eb936951723cbb4428e218d2e3a0fce524deed9;hpb=7ea8c7377706103d8f9afc39e3f29e5454ef6404;p=elisp%2Ftm.git diff --git a/tm-view.el b/tm-view.el index 0eb9369..767e49b 100644 --- a/tm-view.el +++ b/tm-view.el @@ -1,58 +1,70 @@ ;;; -;;; A MIME viewer for GNU Emacs +;;; tm-view.el --- interactive MIME viewer for GNU Emacs ;;; -;;; by Morioka Tomohiko, 1994/07/13 - -(provide 'tm-view) - - -;;; @ require modules +;;; Copyright (C) 1995 Free Software Foundation, Inc. +;;; Copyright (C) 1994,1995 MORIOKA Tomohiko +;;; +;;; Author: MORIOKA Tomohiko +;;; modified by Steven L. Baur +;;; Maintainer: MORIOKA Tomohiko +;;; Created: 1994/7/13 (1994/8/31 obsolete tm-body.el) +;;; Version: $Revision: 7.32.1.2 $ +;;; Keywords: mail, news, MIME, multimedia ;;; +;;; This file is part of tm (Tools for MIME). +;;; +;;; This program is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation; either version 2, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with This program. If not, write to the Free Software +;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +;;; +;;; Code: (require 'tl-str) (require 'tl-list) -(require 'tl-header) -(require 'tiny-mime) -(require 'tm-misc) +(require 'tl-atype) +(require 'tl-misc) +(require 'tl-822) +(require 'mel) +(require 'tm-ew-d) +(require 'tm-def) +(require 'tm-parse) ;;; @ version ;;; -(defconst mime/viewer-RCS-ID - "$Id: tm-view.el,v 5.19 1994/11/08 11:13:12 morioka Exp $") +(defconst mime-viewer/RCS-ID + "$Id: tm-view.el,v 7.32.1.2 1995/12/10 20:29:06 morioka Exp $") -(defconst mime/viewer-version (get-version-string mime/viewer-RCS-ID)) - - -;;; @ constants -;;; - -(defconst mime/tspecials "\000-\040()<>@,;:\\\"/[\093?.=") -(defconst mime/token-regexp - (concat "[^" mime/tspecials "]*")) -(defconst mime/content-type-subtype-regexp - (concat mime/token-regexp "/" mime/token-regexp)) -(defconst mime/content-parameter-value-regexp - (concat "\\(" - message/quoted-string-regexp - "\\|[^; \t\n]*\\)")) - -(defconst mime/output-buffer-name "*MIME-out*") -(defconst mime/decoding-buffer-name "*MIME-decoding*") +(defconst mime-viewer/version (get-version-string mime-viewer/RCS-ID)) +(defconst mime/viewer-version mime-viewer/version) ;;; @ variables ;;; (defvar mime/content-decoding-condition -;;(setq mime/content-decoding-condition '(((type . "text/plain") (method "tm-plain" nil 'file 'type 'encoding 'mode 'name)) - ((type . "text/x-latex") - (method "tm-latex" nil 'file 'type 'encoding 'mode 'name)) + ((type . "text/html") + (method "tm-html" nil 'file 'type 'encoding 'mode 'name) + (mode . "play")) + ((type . "text/x-rot13-47") + (method . mime-article/decode-caesar)) + ((type . "audio/basic") (method "tm-au" nil 'file 'type 'encoding 'mode 'name)) + ((type . "image/gif") (method "tm-image" nil 'file 'type 'encoding 'mode 'name)) ((type . "image/jpeg") @@ -65,640 +77,595 @@ (method "tm-image" nil 'file 'type 'encoding 'mode 'name)) ((type . "image/x-pic") (method "tm-image" nil 'file 'type 'encoding 'mode 'name)) + ((type . "video/mpeg") (method "tm-mpeg" nil 'file 'type 'encoding 'mode 'name)) + ((type . "application/octet-stream") (method "tm-file" nil 'file 'type 'encoding 'mode 'name)) + ;;((type . "message/external-body") ;; (method "xterm" nil ;; "-e" "showexternal" ;; 'file '"access-type" '"name" '"site" '"directory")) + ((type . "message/rfc822") + (method . mime-article/view-message/rfc822)) ((type . "message/partial") - (method . mime/decode-message/partial-region)) + (method . mime-article/decode-message/partial)) + ((method "metamail" t "-m" "tm" "-x" "-d" "-z" "-e" 'file)(mode . "play")) + ((method "tm-file" nil 'file 'type 'encoding 'mode 'name) + (mode . "extract")) )) -(defvar mime/content-filter-alist - '(("text/plain" . mime/decode-text/plain))) - -(defvar mime/make-content-subject-function - (function - (lambda (cid subj ctype) - (insert - (format "[%s %s (%s)]\n" - (if (listp cid) - (mapconcat (function - (lambda (num) - (format "%s" (+ num 1)) - )) - cid ".") - "0") - subj (car ctype))) - ))) - -(defvar mime/make-content-header-filter -;;(setq mime/make-content-header-filter - (function - (lambda (cid) - (if (listp cid) - (delete-region (goto-char (point-min)) - (or (and (re-search-forward "^$" nil t) - (match-end 0)) - (point-max)) - ) - ) - ))) - -(defvar mime/default-showing-Content-Type-list -;;(setq mime/default-showing-Content-Type-list - '("text/plain" "text/richtext" "text/enriched" "text/x-latex" nil)) - -(defvar mime/go-to-top-node-method-alist -;;(setq mime/go-to-top-node-method-alist - '((gnus-article-mode . (lambda () - (mime/exit-view-mode) - (delete-other-windows) - (gnus-article-show-summary) - )) - (rmail-mode . (lambda () - (mime/exit-view-mode) - (rmail-summary) - (delete-other-windows) - )) - (mh-show-mode . (lambda () - (let ((win (get-buffer-window - mime/output-buffer-name)) - (buf - (nth 2 (car mime/preview-flat-content-list))) - ) - (if win - (delete-window win) - ) - (mime/exit-view-mode) - (pop-to-buffer - (let ((name (buffer-name buf))) - (string-match "show-" name) - (substring name (match-end 0)) - )) - ))) - (mime/show-message-mode . (lambda () - (set-window-configuration - mime/show-mode-old-window-configuration) - (let ((mother mime/mother-buffer)) - (kill-buffer - (nth 2 (car - mime/preview-flat-content-list))) - (mime/exit-view-mode) - (pop-to-buffer mother) - (goto-char (point-min)) - (mime/up-content) - ))) +(defvar mime-viewer/childrens-header-showing-Content-Type-list + '("message/rfc822" "message/news")) + +(defvar mime-viewer/default-showing-Content-Type-list + '("text/plain" "text/richtext" "text/enriched" + "text/x-latex" "application/x-latex" + "application/octet-stream" nil + "application/pgp" + "application/x-selection" "application/x-comment")) + +(defvar mime-viewer/content-subject-omitting-Content-Type-list + '("application/x-selection")) + +(defvar mime-viewer/content-subject-showing-Content-Type-list + '("application/pgp")) + +(defvar mime-viewer/uuencode-encoding-name-list '("x-uue" "x-uuencode")) + +(defvar mime-viewer/ignored-field-list + '(".*Received" "Return-Path" "Replied" "Errors-To" + "Lines" "Sender" "Path" "Nntp-Posting-Host" + "Content-Type" "Precedence" "X-Face" + "Status" "X-VM-.*") + "All fields that match this list will be hidden in MIME preview buffer. +Each elements are regexp of field-name. [tm-view.el]") + +(defvar mime-viewer/ignored-field-regexp + (concat "^" + (apply (function regexp-or) mime-viewer/ignored-field-list) + ":")) + +(defvar mime-viewer/announcement-for-message/partial + (if (and (>= emacs-major-version 19) window-system) + "\ +\[[ This is message/partial style split message. ]] +\[[ Please press `v' key in this buffer ]] +\[[ or click here by mouse button-2. ]]" + "\ +\[[ This is message/partial style split message. ]] +\[[ Please press `v' key in this buffer. ]]" )) -(defvar mime/use-internal-decoder nil) -(defvar mime/body-decoding-mode "play" "MIME body decoding mode") +;;; @@ predicate functions +;;; +(defun mime-viewer/header-visible-p (rcnum cinfo &optional ctype) + (or (null rcnum) + (progn + (setq ctype + (mime::content-info/type + (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo) + )) + (member ctype mime-viewer/childrens-header-showing-Content-Type-list) + ))) + +(defun mime-viewer/body-visible-p (rcnum cinfo &optional ctype) + (let (ccinfo) + (or ctype + (setq ctype + (mime::content-info/type + (setq ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo)) + )) + ) + (and (member ctype mime-viewer/default-showing-Content-Type-list) + (if (string-equal ctype "application/octet-stream") + (progn + (or ccinfo + (setq ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo)) + ) + (member (mime::content-info/encoding ccinfo) + '(nil "7bit" "8bit")) + ) + t)) + )) -;;; @ parser + +;;; @@ content subject ;;; -(defun mime/parse-contents () - (save-excursion - (save-restriction - (goto-char (point-min)) - (let* ((ctl (mime/Content-Type)) - (ctype (car ctl)) - (boundary (assoc "boundary" (cdr ctl))) - beg end dest) - (if (stringp ctype) - (setq ctype (downcase ctype)) - ) - (search-forward "\n\n" nil t) - (cond (boundary - (let ((sep (concat "\n--" - (setq boundary - (message/strip-quoted-string - (cdr boundary))) - "\n")) - cb ce ct ret ncb) - (setq beg (match-end 0)) - (search-forward (concat "\n--" boundary "--\n") nil t) - (setq end (match-beginning 0)) +(defun mime-viewer/insert-content-subject + (rcnum cinfo ctype params subj) + (save-restriction + (narrow-to-region (point)(point)) + (insert + (let ((access-type (assoc "access-type" params)) + (num (or (assoc-value "x-part-number" params) + (if (consp rcnum) + (mapconcat (function + (lambda (num) + (format "%s" (1+ num)) + )) + (reverse rcnum) ".") + "0")) + )) + (if access-type + (let ((server (assoc "server" params))) + (setq access-type (cdr access-type)) + (if server + (format "[%s %s ([%s] %s)]\n" num subj + access-type (cdr server)) + (let ((site (assoc-value "site" params)) + (dir (assoc-value "directory" params)) + ) + (format "[%s %s ([%s] %s:%s)]\n" num subj + access-type site dir) + ))) + (format "[%s %s (%s)]\n" num subj ctype) + ))) + (tm:add-button (point-min)(1- (point-max)) + (function mime-viewer/play-content)) + )) + +(defun mime-viewer/default-content-subject-function + (rcnum cinfo ctype params subj) + (if (and (consp rcnum) + (not (member + ctype + mime-viewer/content-subject-omitting-Content-Type-list))) + (mime-viewer/insert-content-subject + rcnum cinfo ctype params subj) + )) + +(defvar mime-viewer/content-subject-function + (function mime-viewer/default-content-subject-function)) + + +;;; @@ content header filter +;;; + +(defun mime-viewer/default-content-header-filter () + (goto-char (point-min)) + (while (and (re-search-forward mime-viewer/ignored-field-regexp nil t) + (progn + (delete-region + (match-beginning 0) (save-excursion - (save-restriction - (narrow-to-region beg end) - (goto-char (point-min)) - (search-forward (concat "--" boundary "\n") nil t) - (setq cb (match-end 0)) - (while (search-forward sep nil t) - (setq ce (match-beginning 0)) - (setq ncb (match-end 0)) - (save-excursion - (save-restriction - (narrow-to-region cb ce) - (setq ret (mime/parse-contents)) - )) - (setq dest (nconc dest (list ret))) - (goto-char (nth 1 ret)) - (search-forward (concat "--" boundary "\n") nil t) - (goto-char (setq cb (match-end 0))) - ) - (setq ce (point-max)) - (save-excursion - (save-restriction - (narrow-to-region cb ce) - (setq ret (mime/parse-contents)) - )) - (setq dest (append dest (list ret))) - )) - (setq beg (point-min)) - (goto-char beg) - (search-forward (concat "\n--" boundary "--\n") nil t) - (setq end (match-beginning 0)) - )) - ((string= ctype "message/rfc822") - (save-excursion - (save-restriction - (narrow-to-region (match-end 0) (point-max)) - (setq dest (list (mime/parse-contents))) - )) - (setq beg (point-min)) - (setq end (point-max)) - ) - (t (setq beg (point-min)) - (setq end (point-max)) - )) - (list beg end dest) - )))) + (and + (re-search-forward "^\\([^ \t]\\|$\\)" nil t) + (match-beginning 0) + ))) + t))) + (mime/decode-message-header) + ) -(defun mime/Content-Type () - (save-excursion - (save-restriction - (if (and (re-search-forward "^Content-Type:[ \t]*" nil t) - (progn - (narrow-to-region - (point) - (and (re-search-forward ".*\\(\n[ \t].*\\)*" nil t) - (match-end 0)) - ) - (goto-char (point-min)) - (re-search-forward mime/content-type-subtype-regexp nil t) - )) - (let ((ctype - (downcase - (buffer-substring (match-beginning 0) (match-end 0)) - )) - dest attribute value) - (while (and (re-search-forward "[ \t\n]*;[ \t\n]*" nil t) - (re-search-forward mime/token-regexp nil t) - ) - (setq attribute - (downcase - (buffer-substring (match-beginning 0) (match-end 0)) - )) - (if (and (re-search-forward "=[ \t\n]*" nil t) - (re-search-forward mime/content-parameter-value-regexp - nil t) - ) - (setq dest - (put-alist attribute - (message/strip-quoted-string - (buffer-substring (match-beginning 0) - (match-end 0))) - dest)) - ) - ) - (cons ctype dest) - ))))) +(defvar mime-viewer/content-header-filter-alist nil) -(defun mime/Content-Transfer-Encoding (&optional default-encoding) - (save-excursion - (save-restriction - (if (and (re-search-forward "^Content-Transfer-Encoding:[ \t]*" nil t) - (re-search-forward mime/token-regexp nil t) - ) - (downcase (buffer-substring (match-beginning 0) (match-end 0))) - default-encoding) - ))) -(defun mime/get-subject (param) - (save-excursion - (save-restriction - (let (ret) - (or (and (setq ret (assoc "name" param)) - (message/strip-quoted-string (cdr ret)) - ) - (and (setq ret (assoc "x-name" param)) - (message/strip-quoted-string (cdr ret)) - ) - (progn - (narrow-to-region (point-min) - (or (and (search-forward "\n\n" nil t) - (match-beginning 0) - ) - (point-max))) - (or - (message/get-field-body "Content-Description") - (message/get-field-body "Subject") - )) - "")) - ))) +;;; @@ content filter +;;; + +(defvar mime-viewer/content-filter-alist + '(("text/plain" . mime-viewer/filter-text/plain) + ("application/pgp" . mime-viewer/filter-text/plain) + (nil . mime-viewer/filter-text/plain))) -(defun mime/get-name (param) - (replace-as-filename (mime/get-subject param)) +(defun mime-viewer/default-content-filter (rcnum cinfo ctype params subj) ) -(defun mime/make-preview-buffer (&optional buf cl obuf) - (let ((the-buf (current-buffer)) fcl) - (if (null buf) - (setq buf (current-buffer)) - (setq buf (get-buffer buf)) + +;;; @@ content separator +;;; + +(defun mime-viewer/default-content-separator (rcnum cinfo ctype params subj) + (if (and (not (mime-viewer/header-visible-p rcnum cinfo ctype)) + (not (mime-viewer/body-visible-p rcnum cinfo ctype)) + ) + (progn + (goto-char (point-max)) + (insert "\n") + ))) + + +;;; @@ buffer local variables +;;; + +;; for XEmacs +(defvar mime::article/preview-buffer nil) +(defvar mime::article/code-converter nil) + +(make-variable-buffer-local 'mime::article/content-info) +(make-variable-buffer-local 'mime::article/preview-buffer) +(make-variable-buffer-local 'mime::article/code-converter) + +(make-variable-buffer-local 'mime::preview/mother-buffer) +(make-variable-buffer-local 'mime::preview/content-list) +(make-variable-buffer-local 'mime::preview/article-buffer) +(make-variable-buffer-local 'mime::preview/original-major-mode) +(make-variable-buffer-local 'mime::preview/original-window-configuration) + + +;;; @@ quitting method +;;; + +(defvar mime-viewer/quitting-method-alist + '((mime/show-message-mode + . mime-viewer/quitting-method-for-mime/show-message-mode))) + +(defvar mime-viewer/over-to-previous-method-alist nil) +(defvar mime-viewer/over-to-next-method-alist nil) + + +;;; @@ X-Face +;;; + +;; hack from Gnus 5.0.4. + +(defvar mime-viewer/x-face-command + "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -" + "String to be executed to display an X-Face field. +The command will be executed in a sub-shell asynchronously. +The compressed face will be piped to this command.") + +(defun mime-viewer/x-face-function () + "Function to display X-Face field. You can redefine to customize." + ;; 1995/10/12 (c.f. tm-eng:130) + ;; fixed by Eric Ding + (save-restriction + (narrow-to-region (point-min) (re-search-forward "^$" nil t)) + ;; end + (goto-char (point-min)) + (if (re-search-forward "^X-Face:[ \t]*" nil t) + (let ((beg (match-end 0)) + (end (rfc822/field-end)) + ) + (call-process-region beg end "sh" nil 0 nil + "-c" mime-viewer/x-face-command) + )))) + + +;;; @ data structures +;;; + +;;; @@ preview-content-info +;;; + +(define-structure mime::preview-content-info + point-min point-max buffer content-info) + + +;;; @ buffer setup +;;; + +(defun mime-viewer/setup-buffer (&optional ctl encoding ibuf obuf) + (if ibuf + (progn + (get-buffer ibuf) + (set-buffer ibuf) + )) + (setq mime::article/content-info (mime/parse-message ctl encoding)) + (let ((ret (mime-viewer/make-preview-buffer obuf))) + (setq mime::article/preview-buffer (car ret)) + ret)) + +(defun mime-viewer/make-preview-buffer (&optional obuf) + (let ((cinfo mime::article/content-info) + (the-buf (current-buffer)) + (mode major-mode) + pcl dest) + (or obuf + (setq obuf (concat "*Preview-" (buffer-name the-buf) "*")) + ) + (setq pcl (mime/flatten-content-info cinfo)) + (let ((bf (get-buffer obuf))) + (if bf + (progn + (set-buffer obuf) + (setq buffer-read-only nil) + (erase-buffer) + ) + (setq bf (get-buffer-create obuf)) + (set-buffer obuf) + )) + (setq mime::preview/article-buffer the-buf) + (setq mime::preview/original-major-mode mode) + (setq major-mode 'mime/viewer-mode) + (setq mode-name "MIME-View") + (setq dest + (mapcar + (function + (lambda (content) + (mime-viewer/display-content content cinfo the-buf obuf) + )) + pcl)) + (set-buffer-modified-p nil) + (setq buffer-read-only t) + (set-buffer the-buf) + (list obuf dest) + )) + +(defun mime-viewer/display-content (content cinfo ibuf obuf) + (let* ((beg (mime::content-info/point-min content)) + (end (mime::content-info/point-max content)) + (ctype (mime::content-info/type content)) + (params (mime::content-info/parameters content)) + (encoding (mime::content-info/encoding content)) + (rcnum (mime::content-info/rcnum content)) + he e nb ne subj) + (set-buffer ibuf) + (goto-char beg) + (setq he (if (re-search-forward "^$" nil t) + (1+ (match-end 0)) + end)) + (if (> he end) + (setq he end) ) - (if (null cl) - (progn - (switch-to-buffer buf) - (setq cl mime/content-list) - )) - (if (null obuf) - (setq obuf (concat "*Preview-" (buffer-name buf) "*")) + (save-restriction + (narrow-to-region beg end) + (setq subj + (mime-eword/decode-string + (mime-viewer/get-subject params encoding))) ) - (setq fcl (mime/make-flat-content-list cl)) - (if (get-buffer obuf) - (kill-buffer obuf) + (set-buffer obuf) + (setq nb (point)) + (narrow-to-region nb nb) + (funcall mime-viewer/content-subject-function + rcnum cinfo ctype params subj) + (set-buffer ibuf) + (if (mime-viewer/header-visible-p rcnum cinfo ctype) + (mime-viewer/display-header beg he obuf) ) - (let ((r fcl) cell cid ctype beg end e nb ne subj dest str) - (while r - (setq cell (car r)) - (setq beg (car cell)) - (setq end (nth 1 cell)) - (setq cid (mime/get-point-content-number beg cl)) - (switch-to-buffer buf) + (if (and (null rcnum) + (member + ctype mime-viewer/content-subject-showing-Content-Type-list)) (save-excursion - (save-restriction - (narrow-to-region beg end) - (goto-char beg) - (setq ctype (mime/Content-Type)) - (setq e - (if (not (member (car ctype) - mime/default-showing-Content-Type-list)) - (progn - (goto-char beg) - (search-forward "\n\n" nil t) - (match-end 0) - ) - (+ end 1) - )) - )) - (if (> e (point-max)) - (setq e (point-max)) + (set-buffer obuf) + (goto-char (point-max)) + (mime-viewer/insert-content-subject rcnum cinfo ctype params subj) + )) + (cond ((mime-viewer/body-visible-p rcnum cinfo ctype) + (mime-viewer/display-body he end obuf + rcnum cinfo ctype params subj encoding) + ) + ((equal ctype "message/partial") + (mime-viewer/display-message/partial obuf) + ) + ((and (null rcnum) + (null (mime::content-info/children cinfo)) + ) + (set-buffer obuf) + (goto-char (point-max)) + (mime-viewer/insert-content-subject rcnum cinfo ctype params subj) + ) + (t (set-buffer obuf)) ) - (setq str (buffer-substring beg e)) - (switch-to-buffer obuf) - (setq nb (point)) - (insert str) - (setq ne (point)) - (save-excursion - (save-restriction - (narrow-to-region nb ne) - (mime/decode-message-header) - (setq subj (mime/get-subject (cdr ctype))) - (let ((f (cdr (assoc (car ctype) mime/content-filter-alist)))) - (if (and f (fboundp f)) - (funcall f ctype) - )) - (funcall mime/make-content-header-filter cid) - (goto-char nb) - (funcall mime/make-content-subject-function cid subj ctype) - (setq ne (point-max)) - (setq dest (nconc dest (list (list nb (- ne 1) buf beg end)))) - )) - (goto-char ne) - (setq r (cdr r)) + (mime-viewer/default-content-separator rcnum cinfo ctype params subj) + (prog1 + (progn + (setq ne (point-max)) + (widen) + (mime::preview-content-info/create nb (1- ne) ibuf content) + ) + (goto-char ne) + ))) + +(defun mime-viewer/display-header (beg end obuf) + (let ((str (buffer-substring beg end)) + (f (assq major-mode mime-viewer/content-header-filter-alist)) ) - (set-buffer-modified-p nil) - (setq buffer-read-only t) - (switch-to-buffer the-buf) - (list obuf dest) + (save-excursion + (set-buffer obuf) + (save-restriction + (narrow-to-region (point)(point)) + (insert str) + (if (and f (setq f (cdr f))) + (funcall f) + (mime-viewer/default-content-header-filter) + ) + (run-hooks 'mime-viewer/content-header-filter-hook) + )))) + +(defun mime-viewer/display-body (beg end obuf + rcnum cinfo ctype params subj encoding) + (let ((str (buffer-substring beg end)) + be) + (set-buffer obuf) + (save-restriction + (setq be (point-max)) + (narrow-to-region be be) + (insert str) + (let ((f (assoc-value ctype mime-viewer/content-filter-alist))) + (if (and f (fboundp f)) + (funcall f ctype params encoding) + (mime-viewer/default-content-filter rcnum cinfo ctype params subj) + )) ))) -(defun mime/parse-message () - (interactive) - (make-variable-buffer-local 'mime/content-list) - (setq mime/content-list (mime/parse-contents)) - (let ((ret (mime/make-preview-buffer))) - (make-variable-buffer-local 'mime/preview-buffer) - (setq mime/preview-buffer (car ret)) - ret)) +(defun mime-viewer/display-message/partial (obuf) + (set-buffer obuf) + (save-restriction + (goto-char (point-max)) + (if (not (search-backward "\n\n" nil t)) + (insert "\n") + ) + (let ((be (point-max))) + (narrow-to-region be be) + (insert mime-viewer/announcement-for-message/partial) + (tm:add-button (point-min)(point-max) + (function mime-viewer/play-content)) + ))) +(defun mime-viewer/get-subject (param &optional encoding) + (if (member (or encoding + (cdr (assq 'encoding param)) + ) + mime-viewer/uuencode-encoding-name-list) + (save-excursion + (or (if (re-search-forward "^begin [0-9]+ " nil t) + (if (looking-at ".+$") + (buffer-substring (match-beginning 0)(match-end 0)) + )) + "")) + (let (ret) + (or (and (setq ret (assoc "name" param)) + (rfc822/strip-quoted-string (cdr ret)) + ) + (and (setq ret (assoc "x-name" param)) + (rfc822/strip-quoted-string (cdr ret)) + ) + + (save-excursion + (save-restriction + (goto-char (point-min)) + (narrow-to-region (point-min) + (or (and (search-forward "\n\n" nil t) + (match-beginning 0) + ) + (point-max))) + (or + (rfc822/get-field-body "Content-Description") + (rfc822/get-field-body "Subject") + ))) + "")) + )) + + ;;; @ content information ;;; -(defun mime/get-point-content-number (p &optional cl) - (if (null cl) - (setq cl mime/content-list) - ) - (let ((b (car cl)) - (e (nth 1 cl)) - (c (nth 2 cl)) +(defun mime-article/point-content-number (p &optional cinfo) + (or cinfo + (setq cinfo mime::article/content-info) + ) + (let ((b (mime::content-info/point-min cinfo)) + (e (mime::content-info/point-max cinfo)) + (c (mime::content-info/children cinfo)) ) (if (and (<= b p)(<= p e)) (or (let (co ret (sn 0)) (catch 'tag (while c (setq co (car c)) - (setq ret (mime/get-point-content-number p co)) + (setq ret (mime-article/point-content-number p co)) (cond ((eq ret t) (throw 'tag (list sn))) (ret (throw 'tag (cons sn ret))) ) (setq c (cdr c)) - (setq sn (+ sn 1)) + (setq sn (1+ sn)) ))) t)))) -(defun mime/get-content-region (cn &optional cl) - (if (null cl) - (setq cl mime/content-list) - ) +(defun mime-article/rcnum-to-cinfo (rcnum &optional cinfo) + (or cinfo + (setq cinfo mime::article/content-info) + ) + (some-element + (function + (lambda (ci) + (equal (mime::content-info/rcnum ci) rcnum) + )) + (mime/flatten-content-info cinfo) + )) + +(defun mime-article/cnum-to-cinfo (cn &optional cinfo) + (or cinfo + (setq cinfo mime::article/content-info) + ) (if (eq cn t) - cl + cinfo (let ((sn (car cn))) (if (null sn) - cl - (let ((rcl (nth sn (nth 2 cl)))) - (if rcl - (mime/get-content-region (cdr cn) rcl) + cinfo + (let ((rc (nth sn (mime::content-info/children cinfo)))) + (if rc + (mime-article/cnum-to-cinfo (cdr cn) rc) )) )))) -(defun mime/make-flat-content-list (&optional cl) - (if (null cl) - (setq cl mime/content-list) - ) - (let ((dest (list cl)) - (rcl (nth 2 cl)) +(defun mime/flatten-content-info (&optional cinfo) + (or cinfo + (setq cinfo mime::article/content-info) + ) + (let ((dest (list cinfo)) + (rcl (mime::content-info/children cinfo)) ) (while rcl - (setq dest (append dest (mime/make-flat-content-list (car rcl)))) + (setq dest (nconc dest (mime/flatten-content-info (car rcl)))) (setq rcl (cdr rcl)) ) dest)) -(defun mime/get-point-preview-content (p &optional fcl) - (if (null fcl) - (setq fcl mime/preview-flat-content-list) - ) +(defun mime-preview/point-pcinfo (p &optional pcl) + (or pcl + (setq pcl mime::preview/content-list) + ) (catch 'tag - (let ((r fcl) cell) + (let ((r pcl) cell) (while r (setq cell (car r)) - (if (and (<= (car cell) p)(<= p (nth 1 cell))) + (if (and (<= (mime::preview-content-info/point-min cell) p) + (<= p (mime::preview-content-info/point-max cell)) + ) (throw 'tag cell) ) (setq r (cdr r)) )) - (car (last fcl)) + (car (last pcl)) )) -;;; @ decoder +;;; @ content filter ;;; -(defun mime/Quoted-Printable-decode-region (beg end) - (interactive "*r") - (save-excursion - (save-restriction - (narrow-to-region beg end) - (goto-char (point-min)) - (while (re-search-forward "=\n" nil t) - (replace-match "") - ) - (goto-char (point-min)) - (let (b e str) - (while (re-search-forward mime/Quoted-Printable-octet-regexp nil t) - (setq b (match-beginning 0)) - (setq e (match-end 0)) - (setq str (buffer-substring b e)) - (delete-region b e) - (insert (mime/Quoted-Printable-decode-string str)) - )) - ))) - -(defun mime/Base64-decode-region (beg end) - (interactive "*r") - (save-excursion - (save-restriction - (narrow-to-region beg end) - (goto-char (point-min)) - (while (search-forward "\n" nil t) - (replace-match "") - ) - (let ((str (buffer-substring (point-min)(point-max)))) - (delete-region (point-min)(point-max)) - (insert (mime/base64-decode-string str)) - )))) - -(defun mime/make-method-args (cal format) - (mapcar (function - (lambda (arg) - (if (stringp arg) - arg - (let ((ret (cdr (assoc (eval arg) cal)))) - (if ret - ret - "") - )) - )) - format)) - -(defun mime/start-external-method-region (beg end cal) - (let ((e end)) - (if (< end (point-max)) - (setq e (+ end 1)) - ) - (save-excursion - (save-restriction - (narrow-to-region beg e) - (goto-char beg) - (let ((method (cdr (assoc 'method cal))) - (name (mime/get-name cal)) - ) - (if method - (let ((file (make-temp-name - (expand-file-name "TM" mime/tmp-dir))) - b args) - (if (nth 1 method) - (setq b beg) - (search-forward "\n\n" nil t) - (setq b (match-end 0)) - ) - (goto-char b) - (write-region b e file) - (setq cal (put-alist - 'name (replace-as-filename name) cal)) - (setq cal (put-alist 'file file cal)) - (setq args (nconc - (list (car method) - mime/output-buffer-name (car method) - ) - (mime/make-method-args cal (cdr (cdr method))) - )) - (apply (function start-process) args) - (mime/show-output-buffer) - )))))) - ) - -(defun mime/decode-message/partial-region (beg end cal) - (goto-char beg) - (let* ((root-dir (expand-file-name - (concat "m-prts-" (user-login-name)) mime/tmp-dir)) - (id (cdr (assoc "id" cal))) - (number (cdr (assoc "number" cal))) - (total (cdr (assoc "total" cal))) - (the-buf (current-buffer)) - file - (mother mime/preview-buffer)) - (if (not (file-exists-p root-dir)) - (shell-command (concat "mkdir " root-dir)) - ) - (setq id (replace-as-filename id)) - (setq root-dir (concat root-dir "/" id)) - (if (not (file-exists-p root-dir)) - (shell-command (concat "mkdir " root-dir)) - ) - (setq file (concat root-dir "/FULL")) - (if (not (file-exists-p file)) - (progn - (re-search-forward "^$") - (goto-char (+ (match-end 0) 1)) - (setq file (concat root-dir "/" number)) - (write-region (point) (point-max) file) - (if (get-buffer "*MIME-temp*") - (kill-buffer "*MIME-temp*") - ) - (switch-to-buffer "*MIME-temp*") - (let ((i 1) - (max (string-to-int total)) - ) - (catch 'tag - (while (<= i max) - (setq file (concat root-dir "/" (int-to-string i))) - (if (not (file-exists-p file)) - (progn - (switch-to-buffer the-buf) - (throw 'tag nil) - )) - (insert-file-contents file) - (goto-char (point-max)) - (setq i (+ i 1)) - ) - (delete-other-windows) - (write-file (concat root-dir "/FULL")) - (setq major-mode 'mime/show-message-mode) - (mime/viewer-mode mother) - (pop-to-buffer (current-buffer)) - )) - ) - (progn - (delete-other-windows) - (find-file file) - (setq major-mode 'mime/show-message-mode) - (mime/viewer-mode mother) - (pop-to-buffer (current-buffer)) - )) - )) - -(defun mime/get-content-decoding-alist (al) - (get-unified-alist mime/content-decoding-condition al) +(defvar mime-viewer/code-converter-alist + '((mime/show-message-mode . mime/code-convert-region-to-emacs)) ) -(defun mime/decode-content-region (beg end) - (interactive "*r") - (let (ctl encoding) - (save-excursion - (save-restriction - (narrow-to-region beg end) - (and (goto-char beg) - (setq ctl (mime/Content-Type)) - (goto-char beg) - (setq encoding (mime/Content-Transfer-Encoding "7bit")) - ))) - (if ctl - (let ((ctype (downcase (car ctl))) method cal ret) - (setq ctl (cdr ctl)) - (setq cal (nconc (list (cons 'type ctype) - (cons 'encoding encoding) - ) - ctl)) - (if mime/body-decoding-mode - (setq cal (cons - (cons 'mode mime/body-decoding-mode) - cal)) - ) - (setq ret (mime/get-content-decoding-alist cal)) - (setq method (cdr (assoc 'method ret))) - (cond ((and (symbolp method) - (fboundp method)) - (funcall method beg end ret) - ) - ((and (listp method)(stringp (car method))) - (mime/start-external-method-region beg end ret) - ) - (t (mime/show-output-buffer - "No method are specified for %s\n" ctype) - )) - )) +(defun mime-viewer/default-code-convert-region + (beg end charset &optional encoding) + (if (member encoding '("quoted-printable" "base64")) + (mime/code-convert-region-to-emacs beg (point-max) charset) )) -(defun mime/show-output-buffer (&rest forms) - (let ((the-buf (current-buffer))) - (if (null (get-buffer-window mime/output-buffer-name)) - (split-window-vertically (/ (* (window-height) 3) 4)) - ) - (pop-to-buffer mime/output-buffer-name) - (goto-char (point-max)) - (if forms - (insert (apply (function format) forms)) - ) - (pop-to-buffer the-buf) - )) - - -;;; @ content filter -;;; +(defun mime-preview/decode-text-region (beg end charset encoding) + (mime/decode-region encoding beg end) + (let* ((mode mime::preview/original-major-mode) + (m (or (save-excursion + (set-buffer mime::preview/article-buffer) + mime::article/code-converter) + (cdr (assq mode mime-viewer/code-converter-alist)) + )) + ) + (if (and m (fboundp m)) + (funcall m beg (point-max) charset encoding) + (mime-viewer/default-code-convert-region + beg (point-max) charset encoding) + ))) -(defun mime/decode-text/plain (ctl) - (interactive) - (save-excursion - (save-restriction - (let ((charset (cdr (assoc "charset" (cdr ctl)))) - (encoding - (save-excursion - (save-restriction - (goto-char (point-min)) - (narrow-to-region (point-min) - (or (and (search-forward "\n\n" nil t) - (match-beginning 0)) - (point-max))) - (goto-char (point-min)) - (mime/Content-Transfer-Encoding "7bit") - ))) - (beg (point-min)) (end (point-max)) - ) +(defun mime-viewer/filter-text/plain (ctype params encoding) + (let ((charset (cdr (assoc "charset" params))) + (beg (point-min)) (end (point-max)) + ) + (mime-preview/decode-text-region beg end charset 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)) - (if (search-forward "\n\n" nil t) - (setq beg (match-end 0)) - ) - (if (cond ((string= encoding "quoted-printable") - (mime/Quoted-Printable-decode-region beg end) - t) - ((string= encoding "base64") - (mime/Base64-decode-region beg end) - t)) - (mime/code-convert-region-to-emacs beg (point-max) charset) - ) - )))) + (while (re-search-forward tm:URL-regexp nil t) + (tm:add-button (match-beginning 0)(match-end 0) + (function tm:browse-url)) + ))) + (run-hooks 'mime-viewer/plain-text-preview-hook) + ) ;;; @ MIME viewer mode @@ -709,228 +676,361 @@ (progn (setq mime/viewer-mode-map (make-keymap)) (suppress-keymap mime/viewer-mode-map) - (define-key mime/viewer-mode-map "u" 'mime/up-content) - (define-key mime/viewer-mode-map "p" 'mime/previous-content) - (define-key mime/viewer-mode-map "n" 'mime/next-content) - (define-key mime/viewer-mode-map " " 'mime/scroll-up-content) - (define-key mime/viewer-mode-map "\M- " 'mime/scroll-down-content) - (define-key mime/viewer-mode-map "\177" 'mime/scroll-down-content) - (define-key mime/viewer-mode-map "\C-m" 'mime/next-line-content) - (define-key mime/viewer-mode-map "\C-\M-m" 'mime/previous-line-content) - (define-key mime/viewer-mode-map "v" 'mime/play-content) - (define-key mime/viewer-mode-map "e" 'mime/extract-content) - (define-key mime/viewer-mode-map "\C-c\C-p" 'mime/print-content) - (define-key mime/viewer-mode-map "q" 'mime/quit-view-mode) - (define-key mime/viewer-mode-map "\C-c\C-x" 'mime/exit-view-mode) + (define-key mime/viewer-mode-map + "u" (function mime-viewer/up-content)) + (define-key mime/viewer-mode-map + "p" (function mime-viewer/previous-content)) + (define-key mime/viewer-mode-map + "n" (function mime-viewer/next-content)) + (define-key mime/viewer-mode-map + " " (function mime-viewer/scroll-up-content)) + (define-key mime/viewer-mode-map + "\M- " (function mime-viewer/scroll-down-content)) + (define-key mime/viewer-mode-map + "\177" (function mime-viewer/scroll-down-content)) + (define-key mime/viewer-mode-map + "\C-m" (function mime-viewer/next-line-content)) + (define-key mime/viewer-mode-map + "\C-\M-m" (function mime-viewer/previous-line-content)) + (define-key mime/viewer-mode-map + "v" (function mime-viewer/play-content)) + (define-key mime/viewer-mode-map + "e" (function mime-viewer/extract-content)) + (define-key mime/viewer-mode-map + "\C-c\C-p" (function mime-viewer/print-content)) + (define-key mime/viewer-mode-map + "f" (function mime-viewer/display-x-face)) + (define-key mime/viewer-mode-map + "q" (function mime-viewer/quit)) + (define-key mime/viewer-mode-map + "\C-c\C-x" (function mime-viewer/kill-buffer)) + (define-key mime/viewer-mode-map + "<" (function beginning-of-buffer)) + (define-key mime/viewer-mode-map + ">" (function end-of-buffer)) + (if mouse-button-2 + (define-key mime/viewer-mode-map + mouse-button-2 (function tm:button-dispatcher)) + ) + (if mouse-button-3 + (define-key mime/viewer-mode-map + mouse-button-3 (function mime-viewer/popup-menu)) + ) )) -(defun mime/viewer-mode (&optional mother) +(defvar mime-viewer/popup-menu-title "MIME Viewer Commands") +(defvar mime-viewer/popup-menu-items + '(("Move to upper content" . mime-viewer/up-content) + ("Move to previous content" . mime-viewer/previous-content) + ("Move to next content" . mime-viewer/next-content) + ("Scroll to previous content" . mime-viewer/scroll-down-content) + ("Scroll to next content" . mime-viewer/scroll-up-content) + ("Play Content" . mime-viewer/play-content) + ("Extract Content" . mime-viewer/extract-content) + ("Print" . mime-viewer/print-content) + ("Show X Face" . mime-viewer/display-x-face) + ) + "Popup Menu for MIME Viewer") + +(cond ((string-match "XEmacs\\|Lucid" emacs-version) + (defvar mime-viewer/popup-menu + (cons mime-viewer/popup-menu-title + (mapcar (function + (lambda (item) + (vector (car item)(cdr item) t) + )) + mime-viewer/popup-menu-items))) + (defun mime-viewer/popup-menu (event) + "Popup the menu in the MIME Viewer buffer" + (interactive "e") + (select-window (event-window event)) + (set-buffer (event-buffer event)) + (popup-menu 'mime-viewer/popup-menu)) + ) + ((>= emacs-major-version 19) + (defun mime-viewer/popup-menu (event) + (interactive "e") + (mouse-set-point event) + (let ((menu + (cons mime-viewer/popup-menu-title + (list (cons "Menu Items" mime-viewer/popup-menu-items)) + ))) + (let ((func (x-popup-menu event menu))) + (if func + (funcall func) + )) + )) + )) + + +(defun mime/viewer-mode (&optional mother ctl encoding ibuf obuf) "Major mode for viewing MIME message. -u Move to upper content -p Move to previous content -n Move to next content -SPC Scroll up -M-SPC Scroll down -DEL Scroll down -RET Move to next line -M-RET Move to previous line -v Decode the content as `play mode' -e Decode the content as `extract mode' -C-c C-p Decode the content as `print mode' -q Quit +Here is a list of the standard keys for mime/viewer-mode. + +key feature +--- ------- + +u Move to upper content +p Move to previous content +n Move to next content +SPC Scroll up or move to next content +M-SPC Scroll down or move to previous content +DEL Scroll down or move to previous content +RET Move to next line +M-RET Move to previous line +v Decode current content as `play mode' +e Decode current content as `extract mode' +C-c C-p Decode current content as `print mode' +f Display X-Face +q Quit +button-2 Move to point under the mouse cursor + and decode current content as `play mode' + + +Here are all the commands with their current binding, +listed in key order: + +\\{mime/viewer-mode-map} " (interactive) - (let ((buf (get-buffer mime/output-buffer-name)) - (the-buf (current-buffer)) - ) + (let ((buf (get-buffer mime/output-buffer-name))) (if buf - (progn - (switch-to-buffer buf) + (save-excursion + (set-buffer buf) (erase-buffer) - (switch-to-buffer the-buf) ))) - (let ((ret (mime/parse-message)) - (mode major-mode)) - (switch-to-buffer (car ret)) - (setq major-mode 'mime/viewer-mode) - (setq mode-name "MIME-View") - (make-variable-buffer-local 'mime/viewer-original-major-mode) - (setq mime/viewer-original-major-mode - (if mother - (progn - (make-variable-buffer-local - 'mime/show-mode-old-window-configuration) - (setq mime/show-mode-old-window-configuration - (current-window-configuration)) - (make-variable-buffer-local 'mime/mother-buffer) - (setq mime/mother-buffer mother) - 'mime/show-message-mode) - mode)) - (use-local-map mime/viewer-mode-map) - (make-variable-buffer-local 'mime/preview-flat-content-list) - (setq mime/preview-flat-content-list (nth 1 ret)) - (goto-char - (let ((ce (nth 1 (car mime/preview-flat-content-list))) - e) - (goto-char (point-min)) - (search-forward "\n\n" nil t) - (setq e (match-end 0)) - (if (<= e ce) - e - ce))) - (run-hooks 'mime/viewer-mode-hook) - )) + (let ((ret (mime-viewer/setup-buffer ctl encoding ibuf obuf)) + (win-conf (current-window-configuration)) + ) + (prog1 + (switch-to-buffer (car ret)) + (setq mime::preview/original-window-configuration win-conf) + (if mother + (progn + (setq mime::preview/mother-buffer mother) + )) + (use-local-map mime/viewer-mode-map) + (setq mime::preview/content-list (nth 1 ret)) + (goto-char + (let ((ce (mime::preview-content-info/point-max + (car mime::preview/content-list) + )) + e) + (goto-char (point-min)) + (search-forward "\n\n" nil t) + (setq e (match-end 0)) + (if (<= e ce) + e + ce))) + (run-hooks 'mime/viewer-mode-hook) + ))) + +(defun mime-preview/point-content-number (point) + (save-window-excursion + (let ((pc (mime-preview/point-pcinfo (point))) + cinfo) + (switch-to-buffer (mime::preview-content-info/buffer pc)) + (setq cinfo (mime::preview-content-info/content-info pc)) + (mime-article/point-content-number (mime::content-info/point-min cinfo)) + ))) + +(defun mime-preview/cinfo-to-pcinfo (cinfo) + (let ((rpcl mime::preview/content-list) cell) + (catch 'tag + (while rpcl + (setq cell (car rpcl)) + (if (eq cinfo (mime::preview-content-info/content-info cell)) + (throw 'tag cell) + ) + (setq rpcl (cdr rpcl)) + )))) -(defun mime/decode-content () +(autoload 'mime-preview/decode-content "tm-play") + +(defvar mime-viewer/decoding-mode "play" "MIME body decoding mode") + +(defun mime-viewer/play-content () (interactive) - (let ((pc (mime/get-point-preview-content (point)))) - (if pc - (let ((the-buf (current-buffer))) - (switch-to-buffer (nth 2 pc)) - (mime/decode-content-region (nth 3 pc)(nth 4 pc)) - (if (eq (current-buffer) (nth 2 pc)) - (switch-to-buffer the-buf) - ) - )))) + (let ((mime-viewer/decoding-mode "play")) + (mime-preview/decode-content) + )) -(defun mime/play-content () +(defun mime-viewer/extract-content () (interactive) - (let ((mime/body-decoding-mode "play")) - (mime/decode-content) + (let ((mime-viewer/decoding-mode "extract")) + (mime-preview/decode-content) )) -(defun mime/extract-content () +(defun mime-viewer/print-content () (interactive) - (let ((mime/body-decoding-mode "extract")) - (mime/decode-content) + (let ((mime-viewer/decoding-mode "print")) + (mime-preview/decode-content) )) -(defun mime/print-content () +(defun mime-viewer/display-x-face () (interactive) - (let ((mime/body-decoding-mode "print")) - (mime/decode-content) + (save-window-excursion + (set-buffer mime::preview/article-buffer) + (mime-viewer/x-face-function) )) -(defun mime/up-content () +(defun mime-viewer/up-content () (interactive) - (let ((pc (mime/get-point-preview-content (point))) + (let ((pc (mime-preview/point-pcinfo (point))) cinfo (the-buf (current-buffer)) - cn r) - (switch-to-buffer (nth 2 pc)) - (setq cn (mime/get-point-content-number (nth 3 pc))) - (if (eq cn t) - (mime/quit-view-mode the-buf (nth 2 pc)) - (setq r (mime/get-content-region (butlast cn))) + rcnum r) + (switch-to-buffer (mime::preview-content-info/buffer pc)) + (setq cinfo (mime::preview-content-info/content-info pc)) + (setq rcnum (mime::content-info/rcnum cinfo)) + (if (null rcnum) + (mime-viewer/quit the-buf + (mime::preview-content-info/buffer pc) + ) + (setq r (mime-article/rcnum-to-cinfo (cdr rcnum))) (switch-to-buffer the-buf) (catch 'tag - (let ((rfcl mime/preview-flat-content-list) cell) - (while rfcl - (setq cell (car rfcl)) - (if (and (= (car r)(nth 3 cell)) - (= (nth 1 r)(nth 4 cell)) - ) + (let ((rpcl mime::preview/content-list) cell) + (while rpcl + (setq cell (car rpcl)) + (if (eq r (mime::preview-content-info/content-info cell)) (progn - (goto-char (nth 0 cell)) + (goto-char (mime::preview-content-info/point-min cell)) (throw 'tag nil) )) - (setq rfcl (cdr rfcl)) + (setq rpcl (cdr rpcl)) ))) ))) -(defun mime/previous-content () +(defun mime-viewer/previous-content () (interactive) - (let* ((fcl mime/preview-flat-content-list) + (let* ((pcl mime::preview/content-list) (p (point)) - (i (- (length fcl) 1)) - ) + (i (- (length pcl) 1)) + beg) (catch 'tag (while (>= i 0) - (if (> p (car (nth i fcl))) - (throw 'tag (goto-char (car (nth i fcl)))) + (setq beg (mime::preview-content-info/point-min (nth i pcl))) + (if (> p beg) + (throw 'tag (goto-char beg)) ) (setq i (- i 1)) - )) + ) + (let ((f (assq mime::preview/original-major-mode + mime-viewer/over-to-previous-method-alist))) + (if f + (funcall (cdr f)) + )) + ) )) -(defun mime/next-content () +(defun mime-viewer/next-content () (interactive) - (let ((fcl mime/preview-flat-content-list) + (let ((pcl mime::preview/content-list) (p (point)) - ) + beg) (catch 'tag - (while fcl - (if (< p (car (car fcl))) - (throw 'tag (goto-char (car (car fcl)))) + (while pcl + (setq beg (mime::preview-content-info/point-min (car pcl))) + (if (< p beg) + (throw 'tag (goto-char beg)) ) - (setq fcl (cdr fcl)) - )) + (setq pcl (cdr pcl)) + ) + (let ((f (assq mime::preview/original-major-mode + mime-viewer/over-to-next-method-alist))) + (if f + (funcall (cdr f)) + )) + ) )) -(defun mime/scroll-up-content (&optional h) +(defun mime-viewer/scroll-up-content (&optional h) (interactive) - (if (null h) + (or h (setq h (- (window-height) 1)) - ) - (let ((fcl mime/preview-flat-content-list) - (p (point)) - np) - (setq np (or (catch 'tag - (while fcl - (if (< p (car (car fcl))) - (throw 'tag (car (car fcl))) - ) - (setq fcl (cdr fcl)) - )) - (point-max))) - (forward-line h) - (if (> (point) np) - (goto-char np) - ))) + ) + (if (= (point) (point-max)) + (let ((f (assq mime::preview/original-major-mode + mime-viewer/over-to-next-method-alist))) + (if f + (funcall (cdr f)) + )) + (let ((pcl mime::preview/content-list) + (p (point)) + np beg) + (setq np + (or (catch 'tag + (while pcl + (setq beg (mime::preview-content-info/point-min (car pcl))) + (if (< p beg) + (throw 'tag beg) + ) + (setq pcl (cdr pcl)) + )) + (point-max))) + (forward-line h) + (if (> (point) np) + (goto-char np) + ) + ;;(show-subtree) + )) + ) -(defun mime/scroll-down-content (&optional h) +(defun mime-viewer/scroll-down-content (&optional h) (interactive) - (if (null h) + (or h (setq h (- (window-height) 1)) - ) - (let ((fcl mime/preview-flat-content-list) - (p (point)) - pp) - (setq pp (or (let ((i (- (length fcl) 1))) - (catch 'tag - (while (> i 0) - (if (> p (nth 1 (nth i fcl))) - (throw 'tag (nth 1 (nth i fcl))) - ) - (setq i (- i 1)) - ))) - (point-min))) - (forward-line (- h)) - (if (< (point) pp) - (goto-char pp) - ))) + ) + (if (= (point) (point-min)) + (let ((f (assq mime::preview/original-major-mode + mime-viewer/over-to-previous-method-alist))) + (if f + (funcall (cdr f)) + )) + (let ((pcl mime::preview/content-list) + (p (point)) + pp beg) + (setq pp + (or (let ((i (- (length pcl) 1))) + (catch 'tag + (while (> i 0) + (setq beg (mime::preview-content-info/point-min + (nth i pcl))) + (if (> p beg) + (throw 'tag beg) + ) + (setq i (- i 1)) + ))) + (point-min))) + (forward-line (- h)) + (if (< (point) pp) + (goto-char pp) + ))) + ) -(defun mime/next-line-content () +(defun mime-viewer/next-line-content () (interactive) - (mime/scroll-up-content 1) + (mime-viewer/scroll-up-content 1) ) -(defun mime/previous-line-content () +(defun mime-viewer/previous-line-content () (interactive) - (mime/scroll-down-content 1) + (mime-viewer/scroll-down-content 1) ) -(defun mime/quit-view-mode (&optional the-buf buf) +(defun mime-viewer/quit (&optional the-buf buf) (interactive) - (if (null the-buf) + (or the-buf (setq the-buf (current-buffer)) - ) - (if (null buf) - (setq buf (nth 2 (mime/get-point-preview-content (point)))) - ) + ) + (or buf + (setq buf (mime::preview-content-info/buffer + (mime-preview/point-pcinfo (point)))) + ) (let ((r (progn (switch-to-buffer buf) - (assoc major-mode mime/go-to-top-node-method-alist) + (assq major-mode mime-viewer/quitting-method-alist) ))) (if r (progn @@ -939,11 +1039,15 @@ q Quit )) )) -(defun mime/exit-view-mode () +(defun mime-viewer/kill-buffer () (interactive) (kill-buffer (current-buffer)) ) -(fset 'mime/view-mode 'mime/viewer-mode) + +;;; @ end +;;; + +(provide 'tm-view) (run-hooks 'tm-view-load-hook)