tm 7.43.1.
[elisp/tm.git] / tm-view.el
index 8d17373..99e6f9a 100644 (file)
@@ -2,13 +2,32 @@
 ;;; tm-view.el --- interactive MIME viewer for GNU Emacs
 ;;;
 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
-;;; Copyright (C) 1994,1995 MORIOKA Tomohiko
+;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
 ;;;
-;;; Author:   MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;; modified by Steven L. Baur <steve@miranova.com>
+;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;; Created: 1994/7/13 (1994/8/31 obsolete tm-body.el)
+;;; Version: $Revision: 7.42 $
 ;;; 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)
@@ -25,7 +44,7 @@
 ;;;
 
 (defconst mime-viewer/RCS-ID
-  "$Id: tm-view.el,v 7.15 1995/10/13 08:43:49 morioka Exp $")
+  "$Id: tm-view.el,v 7.42 1996/02/13 06:28:37 morioka Exp $")
 
 (defconst mime-viewer/version (get-version-string mime-viewer/RCS-ID))
 (defconst mime/viewer-version mime-viewer/version)
 (defvar 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")
      (method "tm-image" nil 'file 'type 'encoding 'mode 'name))
+    ((type . "image/gif")
+     (method "tm-image" nil 'file 'type 'encoding 'mode 'name))
     ((type . "image/tiff")
      (method "tm-image" nil 'file 'type 'encoding 'mode 'name))
     ((type . "image/x-tiff")
      (method "tm-image" nil 'file 'type 'encoding 'mode 'name))
     ((type . "image/x-pic")
      (method "tm-image" nil 'file 'type 'encoding 'mode 'name))
+    ((type . "image/x-mag")
+     (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)
   '("message/rfc822" "message/news"))
 
 (defvar mime-viewer/default-showing-Content-Type-list
-  '("text/plain" "text/richtext" "text/enriched"
+  '("text/plain" nil "text/richtext" "text/enriched"
     "text/x-latex" "application/x-latex"
-    "application/octet-stream" nil
-    "application/pgp"
+    "application/pgp" "text/x-pgp"
+    "application/octet-stream"
     "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"))
-
-(defvar mime-viewer/ignored-field-regexp)
+  '(".*Received" ".*Path" ".*Id" "References"
+    "Replied" "Errors-To"
+    "Lines" "Sender" ".*Host" "Xref"
+    "Content-Type" "Precedence"
+    "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/visible-field-list
+  '("Dnas.*")
+  "All fields that match this list will be displayed in MIME preview buffer.
+Each elements are regexp of field-name. [tm-view.el]")
+
+(defvar mime-viewer/visible-field-regexp
+  (concat "^"
+         (apply (function regexp-or) mime-viewer/visible-field-list)
+         ":"))
+
+(defvar mime-viewer/redisplay nil)
 
 (defvar mime-viewer/announcement-for-message/partial
   (if (and (>= emacs-major-version 19) window-system)
 ;;; @@ predicate functions
 ;;;
 
-(defun mime-viewer/header-visible-p (cnum cinfo &optional ctype)
-  (or (eq cnum t)
+(defun mime-viewer/header-visible-p (rcnum cinfo &optional ctype)
+  (or (null rcnum)
       (progn
        (setq ctype
              (mime::content-info/type
-              (mime-article/cnum-to-cinfo (butlast cnum) cinfo)
+              (mime-article/rcnum-to-cinfo (cdr rcnum) cinfo)
               ))
        (member ctype mime-viewer/childrens-header-showing-Content-Type-list)
        )))
 
-(defun mime-viewer/body-visible-p (cnum cinfo &optional ctype)
+(defun mime-viewer/body-visible-p (rcnum cinfo &optional ctype)
   (let (ccinfo)
     (or ctype
        (setq ctype
              (mime::content-info/type
-              (setq ccinfo (mime-article/cnum-to-cinfo cnum cinfo))
+              (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/cnum-to-cinfo cnum cinfo))
+                  (setq ccinfo (mime-article/rcnum-to-cinfo rcnum cinfo))
                   )
               (member (mime::content-info/encoding ccinfo)
                       '(nil "7bit" "8bit"))
 ;;;
 
 (defun mime-viewer/insert-content-subject
-  (cnum cinfo ctype params subj)
+  (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 (listp cnum)
+                   (if (consp rcnum)
                        (mapconcat (function
                                    (lambda (num)
                                      (format "%s" (1+ num))
                                      ))
-                                  cnum ".")
+                                  (reverse rcnum) ".")
                      "0"))
                ))
        (if access-type
     ))
 
 (defun mime-viewer/default-content-subject-function
-  (cnum cinfo ctype params subj)
-  (if (and (listp cnum)
+  (rcnum cinfo ctype params subj)
+  (if (and (consp rcnum)
           (not (member
                 ctype
-                mime-viewer/content-subject-omitting-Content-Type-list))
-          )
+                mime-viewer/content-subject-omitting-Content-Type-list)))
       (mime-viewer/insert-content-subject
-       cnum cinfo ctype params subj)
+       rcnum cinfo ctype params subj)
     ))
 
 (defvar mime-viewer/content-subject-function
 ;;; @@ content header filter
 ;;;
 
-(defun mime-viewer/default-content-header-filter ()
+(defun mime-preview/cut-header ()
   (goto-char (point-min))
-  (while (and (re-search-forward mime-viewer/ignored-field-regexp nil t)
-             (progn
+  (while (and
+         (re-search-forward mime-viewer/ignored-field-regexp nil t)
+         (let* ((beg (match-beginning 0))
+                (end (match-end 0))
+                (name (buffer-substring beg end))
+                )
+           (if (not (string-match mime-viewer/visible-field-regexp name))
                (delete-region
-                (match-beginning 0)
+                beg
                 (save-excursion
                   (and
                    (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
                    (match-beginning 0)
                    )))
-               t)))
+             )
+           t)))
+  )
+
+(defun mime-viewer/default-content-header-filter ()
+  (mime-preview/cut-header)
   (mime/decode-message-header)
   )
 
     ("application/pgp" . mime-viewer/filter-text/plain)
     (nil . mime-viewer/filter-text/plain)))
 
-(defun mime-viewer/default-content-filter (cnum cinfo ctype params subj)
+(defun mime-viewer/default-content-filter (rcnum cinfo ctype params subj)
   )
 
 
 ;;; @@ content separator
 ;;;
 
-(defun mime-viewer/default-content-separator (cnum cinfo ctype params subj)
-  (if (and (not (mime-viewer/header-visible-p cnum cinfo ctype))
-          (not (mime-viewer/body-visible-p cnum cinfo ctype))
+(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))
 ;;; @@ buffer local variables
 ;;;
 
-(defvar mime::article/content-info nil)
+;; for XEmacs
 (defvar mime::article/preview-buffer nil)
-
+(defvar mime::article/code-converter nil)
 (defvar mime::preview/article-buffer nil)
-(defvar mime::preview/content-list nil)
-(defvar mime::preview/original-major-mode 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
-     . (lambda ()
-        (set-window-configuration
-         mime/show-mode-old-window-configuration)
-        (let ((mother mime/mother-buffer))
-          (kill-buffer
-           (mime::preview-content-info/buffer
-            (car mime::preview/content-list)))
-          (mime-viewer/kill-buffer)
-          (pop-to-buffer mother)
-          (goto-char (point-min))
-          (mime-viewer/up-content)
-          )))
-    ))
+     . 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)
+
+(defvar mime-viewer/show-summary-method nil)
 
 
 ;;; @@ X-Face
 
 ;; hack from Gnus 5.0.4.
 
+(defvar mime-viewer/x-face-to-pbm-command
+  "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm")
+
 (defvar mime-viewer/x-face-command
-  "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
+  (concat mime-viewer/x-face-to-pbm-command
+         " | 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.")
@@ -312,10 +380,10 @@ The compressed face will be piped to this command.")
        (get-buffer ibuf)
        (set-buffer ibuf)
        ))
-  (make-variable-buffer-local 'mime::article/content-info)
-  (setq mime::article/content-info (mime/parse-message ctl encoding))
+  (or mime-viewer/redisplay
+      (setq mime::article/content-info (mime/parse-message ctl encoding))
+      )
   (let ((ret (mime-viewer/make-preview-buffer obuf)))
-    (make-variable-buffer-local 'mime::article/preview-buffer)
     (setq mime::article/preview-buffer (car ret))
     ret))
 
@@ -338,9 +406,7 @@ The compressed face will be piped to this command.")
        (setq bf (get-buffer-create obuf))
        (set-buffer obuf)
        ))
-    (make-variable-buffer-local 'mime::preview/article-buffer)
     (setq mime::preview/article-buffer the-buf)
-    (make-variable-buffer-local 'mime::preview/original-major-mode)
     (setq mime::preview/original-major-mode mode)
     (setq major-mode 'mime/viewer-mode)
     (setq mode-name "MIME-View")
@@ -363,12 +429,8 @@ The compressed face will be piped to this command.")
         (ctype (mime::content-info/type content))
         (params (mime::content-info/parameters content))
         (encoding (mime::content-info/encoding content))
-        (cnum (mime::content-info/rcnum content))
+        (rcnum (mime::content-info/rcnum content))
         he e nb ne subj)
-    (setq cnum
-         (if cnum
-             (reverse cnum)
-           t))
     (set-buffer ibuf)
     (goto-char beg)
     (setq he (if (re-search-forward "^$" nil t)
@@ -380,35 +442,43 @@ The compressed face will be piped to this command.")
     (save-restriction
       (narrow-to-region beg end)
       (setq subj
-           (mime/decode-encoded-words-string
-            (mime-viewer/get-subject params encoding)))
+           (mime-eword/decode-string
+            (mime-article/get-subject params encoding)))
       )
     (set-buffer obuf)
     (setq nb (point))
     (narrow-to-region nb nb)
     (funcall mime-viewer/content-subject-function
-            cnum cinfo ctype params subj)
+            rcnum cinfo ctype params subj)
     (set-buffer ibuf)
-    (if (mime-viewer/header-visible-p cnum cinfo ctype)
+    (if (mime-viewer/header-visible-p rcnum cinfo ctype)
        (mime-viewer/display-header beg he obuf)
       )
-    (cond ((mime-viewer/body-visible-p cnum cinfo ctype)
+    (if (and (null rcnum)
+            (member
+             ctype mime-viewer/content-subject-showing-Content-Type-list))
+       (save-excursion
+         (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
-                                    cnum cinfo ctype params subj encoding)
+                                    rcnum cinfo ctype params subj encoding)
           )
          ((equal ctype "message/partial")
           (mime-viewer/display-message/partial obuf)
           )
-         ((and (eq cnum t)
+         ((and (null rcnum)
                (null (mime::content-info/children cinfo))
                )
           (set-buffer obuf)
           (goto-char (point-max))
-          (mime-viewer/insert-content-subject cnum cinfo ctype params subj)
+          (mime-viewer/insert-content-subject rcnum cinfo ctype params subj)
           )
          (t (set-buffer obuf))
          )
-    (mime-viewer/default-content-separator cnum cinfo ctype params subj)
+    (mime-viewer/default-content-separator rcnum cinfo ctype params subj)
     (prog1
        (progn
          (setq ne (point-max))
@@ -435,7 +505,7 @@ The compressed face will be piped to this command.")
        ))))
 
 (defun mime-viewer/display-body (beg end obuf
-                                    cnum cinfo ctype params subj encoding)
+                                    rcnum cinfo ctype params subj encoding)
   (let ((str (buffer-substring beg end))
        be)
     (set-buffer obuf)
@@ -446,7 +516,7 @@ The compressed face will be piped to this command.")
       (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 cnum cinfo ctype params subj)
+         (mime-viewer/default-content-filter rcnum cinfo ctype params subj)
          ))
       )))
 
@@ -464,7 +534,7 @@ The compressed face will be piped to this command.")
                     (function mime-viewer/play-content))
       )))
 
-(defun mime-viewer/get-subject (param &optional encoding)
+(defun mime-article/get-uu-filename (param &optional encoding)
   (if (member (or encoding
                  (cdr (assq 'encoding param))
                  )
@@ -475,30 +545,24 @@ The compressed face will be piped to this command.")
                    (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")
-              )))
-         ""))
     ))
 
-  
+(defun mime-article/get-subject (param &optional encoding)
+  (or (rfc822/get-field-body "Content-Description")
+      (rfc822/get-field-body "Subject")
+      (let (ret)
+       (if (or (and (setq ret (mime/Content-Disposition))
+                    (setq ret (assoc "filename" (cdr ret)))
+                    )
+               (setq ret (assoc "name" param))
+               (setq ret (assoc "x-name" param))
+               )
+           (rfc822/strip-quoted-string (cdr ret))
+         ))
+      (mime-article/get-uu-filename param encoding)
+      ""))
+
+
 ;;; @ content information
 ;;;
 
@@ -524,6 +588,18 @@ The compressed face will be piped to this command.")
                  )))
            t))))
 
+(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)
@@ -552,7 +628,7 @@ The compressed face will be piped to this command.")
       )
     dest))
 
-(defun mime::point-preview-content (p &optional pcl)
+(defun mime-preview/point-pcinfo (p &optional pcl)
   (or pcl
       (setq pcl mime::preview/content-list)
       )
@@ -574,7 +650,9 @@ The compressed face will be piped to this command.")
 ;;; @ content filter
 ;;;
 
-(defvar mime-viewer/code-converter-alist nil)
+(defvar mime-viewer/code-converter-alist
+  '((mime/show-message-mode . mime/code-convert-region-to-emacs))
+  )
 
 (defun mime-viewer/default-code-convert-region
   (beg end charset &optional encoding)
@@ -582,35 +660,40 @@ The compressed face will be piped to this command.")
       (mime/code-convert-region-to-emacs beg (point-max) charset)
     ))
 
+(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-viewer/filter-text/plain (ctype params encoding)
   (let ((charset (cdr (assoc "charset" params)))
        (beg (point-min)) (end (point-max))
        )
-    (goto-char (point-min))
-    (cond ((string= encoding "quoted-printable")
-          (quoted-printable-decode-region beg end)
-          )
-         ((string= encoding "base64")
-          (base64-decode-region beg end)
-          ))
-    (let* ((mode mime::preview/original-major-mode)
-          (m (assq mode mime-viewer/code-converter-alist))
-          )
-      (if (and m (fboundp (setq m (cdr m))))
-         (funcall m beg (point-max) charset encoding)
-       (mime-viewer/default-code-convert-region beg (point-max)
-                                                charset encoding)
-       )))
+    (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
-      (save-excursion
+      (progn
        (goto-char (point-min))
        (while (re-search-forward tm:URL-regexp nil t)
-         (tm:add-button (match-beginning 0)(match-end 0)
-                        (function tm:browse-url))
+         (let ((beg (match-beginning 0))
+               (end (match-end 0)))
+           (tm:add-button beg end
+                          (function tm:browse-url)
+                          (list (buffer-substring beg end))))
          )))
   (run-hooks 'mime-viewer/plain-text-preview-hook)
   )
@@ -619,6 +702,20 @@ The compressed face will be piped to this command.")
 ;;; @ MIME viewer mode
 ;;;
 
+(defconst mime-viewer/menu-title "MIME-View")
+(defconst mime-viewer/menu-list
+  '((up                 "Move to upper content"      mime-viewer/up-content)
+    (previous   "Move to previous content"   mime-viewer/previous-content)
+    (next       "Move to next content"       mime-viewer/next-content)
+    (scroll-down "Scroll to previous content" mime-viewer/scroll-down-content)
+    (scroll-up  "Scroll to next content"     mime-viewer/scroll-up-content)
+    (play       "Play Content"               mime-viewer/play-content)
+    (extract    "Extract Content"            mime-viewer/extract-content)
+    (print      "Print"                      mime-viewer/print-content)
+    (x-face     "Show X Face"                mime-viewer/display-x-face)
+    )
+  "Menu for MIME Viewer")
+
 (defvar mime/viewer-mode-map nil)
 (if (null mime/viewer-mode-map)
     (progn
@@ -651,11 +748,48 @@ The compressed face will be piped to this command.")
       (define-key mime/viewer-mode-map
        "q"        (function mime-viewer/quit))
       (define-key mime/viewer-mode-map
+       "h"        (function mime-viewer/show-summary))
+      (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))
        )
+      (cond ((string-match "XEmacs\\|Lucid" emacs-version)
+            (defvar mime-viewer/xemacs-popup-menu
+              (cons mime-viewer/menu-title
+                    (mapcar (function
+                             (lambda (item)
+                               (vector (nth 1 item)(nth 2 item) t)
+                               ))
+                            mime-viewer/menu-list)))
+            (defun mime-viewer/xemacs-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/xemacs-popup-menu))
+            (define-key mime/viewer-mode-map
+              mouse-button-3 (function mime-viewer/xemacs-popup-menu))
+            )
+           ((>= emacs-major-version 19)
+            (define-key mime/viewer-mode-map [menu-bar mime-view]
+              (cons mime-viewer/menu-title
+                    (make-sparse-keymap mime-viewer/menu-title)))
+            (mapcar (function
+                     (lambda (item)
+                       (define-key mime/viewer-mode-map
+                         (vector 'menu-bar 'mime-view (car item))
+                         (cons (nth 1 item)(nth 2 item))
+                         )
+                       ))
+                    (reverse mime-viewer/menu-list)
+                    )
+            ))
       ))
 
 (defun mime/viewer-mode (&optional mother ctl encoding ibuf obuf)
@@ -689,31 +823,23 @@ listed in key order:
 \\{mime/viewer-mode-map}
 "
   (interactive)
-  (setq mime-viewer/ignored-field-regexp
-       (concat "^\\("
-               (mapconcat (function regexp-quote)
-                          mime-viewer/ignored-field-list "\\|")
-               "\\):"))
   (let ((buf (get-buffer mime/output-buffer-name)))
     (if buf
        (save-excursion
          (set-buffer buf)
          (erase-buffer)
          )))
-  (let ((ret (mime-viewer/setup-buffer ctl encoding ibuf obuf))) 
+  (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
-           (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)
+           (setq mime::preview/mother-buffer mother)
            ))
       (use-local-map mime/viewer-mode-map)
-      (make-variable-buffer-local 'mime::preview/content-list)
       (setq mime::preview/content-list (nth 1 ret))
       (goto-char
        (let ((ce (mime::preview-content-info/point-max
@@ -731,7 +857,7 @@ listed in key order:
 
 (defun mime-preview/point-content-number (point)
   (save-window-excursion
-    (let ((pc (mime::point-preview-content (point)))
+    (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))
@@ -780,18 +906,17 @@ listed in key order:
 
 (defun mime-viewer/up-content ()
   (interactive)
-  (let ((pc (mime::point-preview-content (point))) cinfo
+  (let ((pc (mime-preview/point-pcinfo (point))) cinfo
        (the-buf (current-buffer))
-       cn r)
+       rcnum r)
     (switch-to-buffer (mime::preview-content-info/buffer pc))
     (setq cinfo (mime::preview-content-info/content-info pc))
-    (setq cn (mime-article/point-content-number
-             (mime::content-info/point-min cinfo)))
-    (if (eq cn t)
+    (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/cnum-to-cinfo (butlast cn)))
+      (setq r (mime-article/rcnum-to-cinfo (cdr rcnum)))
       (switch-to-buffer the-buf)
       (catch 'tag
        (let ((rpcl mime::preview/content-list) cell)
@@ -819,7 +944,13 @@ listed in key order:
            (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-viewer/next-content ()
@@ -834,7 +965,13 @@ listed in key order:
            (throw 'tag (goto-char beg))
          )
        (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-viewer/scroll-up-content (&optional h)
@@ -842,50 +979,64 @@ listed in key order:
   (or h
       (setq h (- (window-height) 1))
       )
-  (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)
-    ))
+  (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-viewer/scroll-down-content (&optional h)
   (interactive)
   (or h
       (setq h (- (window-height) 1))
       )
-  (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)
-      )))
+  (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-viewer/next-line-content ()
   (interactive)
@@ -897,25 +1048,29 @@ listed in key order:
   (mime-viewer/scroll-down-content 1)
   )
 
-(defun mime-viewer/quit (&optional the-buf buf)
+(defun mime-viewer/quit ()
   (interactive)
-  (or the-buf
-      (setq the-buf (current-buffer))
-      )
-  (or buf
-      (setq buf (mime::preview-content-info/buffer
-                (mime::point-preview-content (point))))
-      )
-  (let ((r (progn
-            (switch-to-buffer buf)
-            (assoc major-mode mime-viewer/quitting-method-alist)
+  (let ((r (save-excursion
+            (set-buffer (mime::preview-content-info/buffer
+                         (mime-preview/point-pcinfo (point))))
+            (assq major-mode mime-viewer/quitting-method-alist)
             )))
     (if r
-       (progn
-         (switch-to-buffer the-buf)
-         (funcall (cdr r))
-         ))
-    ))
+       (funcall (cdr r))
+      )))
+
+(defun mime-viewer/show-summary ()
+  (interactive)
+  (let ((r (save-excursion
+            (set-buffer
+             (mime::preview-content-info/buffer
+              (mime-preview/point-pcinfo (point)))
+             )
+            (assq major-mode mime-viewer/show-summary-method)
+            )))
+    (if r
+       (funcall (cdr r))
+      )))
 
 (defun mime-viewer/kill-buffer ()
   (interactive)
@@ -929,3 +1084,5 @@ listed in key order:
 (provide 'tm-view)
 
 (run-hooks 'tm-view-load-hook)
+
+;;; tm-view.el ends here