tm 7.43.1.
[elisp/tm.git] / tm-view.el
index 7fc3b6a..99e6f9a 100644 (file)
@@ -2,12 +2,13 @@
 ;;; 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>
+;;; 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.28 $
+;;; Version: $Revision: 7.42 $
 ;;; Keywords: mail, news, MIME, multimedia
 ;;;
 ;;; This file is part of tm (Tools for MIME).
@@ -25,6 +26,8 @@
 ;;; 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)
@@ -41,7 +44,7 @@
 ;;;
 
 (defconst mime-viewer/RCS-ID
-  "$Id: tm-view.el,v 7.28 1995/12/04 00:24:19 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)
     ((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")
@@ -74,6 +77,8 @@
      (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))
   '("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"
+  '(".*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]")
@@ -124,6 +133,18 @@ Each elements are regexp of field-name. [tm-view.el]")
          (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)
       "\
@@ -211,8 +232,7 @@ Each elements are regexp of field-name. [tm-view.el]")
   (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
        rcnum cinfo ctype params subj)
     ))
@@ -224,18 +244,28 @@ Each elements are regexp of field-name. [tm-view.el]")
 ;;; @@ 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)
   )
 
@@ -270,15 +300,20 @@ Each elements are regexp of field-name. [tm-view.el]")
 ;;; @@ buffer local variables
 ;;;
 
-(defvar mime/show-mode-old-window-configuration nil)
-(defvar mime::preview/mother-buffer nil)
-
-(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
@@ -291,14 +326,20 @@ Each elements are regexp of field-name. [tm-view.el]")
 (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.")
@@ -339,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))
 
@@ -365,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")
@@ -404,7 +443,7 @@ The compressed face will be piped to this command.")
       (narrow-to-region beg end)
       (setq subj
            (mime-eword/decode-string
-            (mime-viewer/get-subject params encoding)))
+            (mime-article/get-subject params encoding)))
       )
     (set-buffer obuf)
     (setq nb (point))
@@ -415,6 +454,14 @@ The compressed face will be piped to this command.")
     (if (mime-viewer/header-visible-p rcnum cinfo ctype)
        (mime-viewer/display-header beg he obuf)
       )
+    (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
                                     rcnum cinfo ctype params subj encoding)
@@ -487,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))
                  )
@@ -498,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
 ;;;
 
@@ -587,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)
       )
@@ -622,9 +663,13 @@ The compressed face will be piped to this command.")
 (defun mime-preview/decode-text-region (beg end charset encoding)
   (mime/decode-region encoding beg end)
   (let* ((mode mime::preview/original-major-mode)
-        (m (assq mode mime-viewer/code-converter-alist))
+        (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 (setq m (cdr m))))
+    (if (and m (fboundp m))
        (funcall m beg (point-max) charset encoding)
       (mime-viewer/default-code-convert-region
        beg (point-max) charset encoding)
@@ -644,8 +689,11 @@ The compressed face will be piped to this command.")
       (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)
   )
@@ -654,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
@@ -686,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)
@@ -730,20 +829,17 @@ listed in key order:
          (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::preview/mother-buffer)
            (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
@@ -761,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))
@@ -810,7 +906,7 @@ 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))
        rcnum r)
     (switch-to-buffer (mime::preview-content-info/buffer pc))
@@ -883,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)
@@ -938,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)
+  (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)
@@ -970,3 +1084,5 @@ listed in key order:
 (provide 'tm-view)
 
 (run-hooks 'tm-view-load-hook)
+
+;;; tm-view.el ends here