tm 7.20.
[elisp/tm.git] / tm-view.el
index 0d40908..88dd0c6 100644 (file)
@@ -14,7 +14,7 @@
 (require 'tl-list)
 (require 'tl-atype)
 (require 'tl-misc)
-(require 'tl-header)
+(require 'tl-822)
 (require 'mel)
 (require 'tm-ew-d)
 (require 'tm-def)
@@ -25,7 +25,7 @@
 ;;;
 
 (defconst mime-viewer/RCS-ID
-  "$Id: tm-view.el,v 7.9 1995/10/03 04:56:10 morioka Exp $")
+  "$Id: tm-view.el,v 7.20 1995/10/24 00:21:02 morioka Exp $")
 
 (defconst mime-viewer/version (get-version-string mime-viewer/RCS-ID))
 (defconst mime/viewer-version mime-viewer/version)
@@ -62,7 +62,7 @@
     ;;        "-e" "showexternal"
     ;;         'file '"access-type" '"name" '"site" '"directory"))
     ((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)
 ;;; @@ 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/insert-content-subject
-       cnum cinfo ctype params subj)
+       rcnum cinfo ctype params subj)
     ))
 
 (defvar mime-viewer/content-subject-function
     ("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/show-mode-old-window-configuration nil)
+(defvar mime/mother-buffer nil)
+
 (defvar mime::article/content-info nil)
 (defvar mime::article/preview-buffer nil)
 
@@ -278,14 +281,19 @@ 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."
-  (goto-char (point-min))
-  (if (re-search-forward "^X-Face:[ \t]*" nil t)
-      (let ((beg (match-end 0))
-           (end (message/field-end))
-           )
-       (call-process-region beg end "sh" nil 0 nil
-                            "-c" mime-viewer/x-face-command)
-       )))
+  ;; 1995/10/12 (c.f. tm-eng:130)
+  ;;   fixed by Eric Ding <ericding@San-Jose.ate.slb.com>
+  (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
@@ -358,7 +366,7 @@ 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::get-point-content-number beg cinfo))
+        (rcnum (mime::content-info/rcnum content))
         he e nb ne subj)
     (set-buffer ibuf)
     (goto-char beg)
@@ -370,34 +378,36 @@ The compressed face will be piped to this command.")
       )
     (save-restriction
       (narrow-to-region beg end)
-      (setq subj (mime-viewer/get-subject params encoding))
+      (setq subj
+           (mime-eword/decode-string
+            (mime-viewer/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)
+    (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))
@@ -424,7 +434,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)
@@ -435,7 +445,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)
          ))
       )))
 
@@ -466,10 +476,10 @@ The compressed face will be piped to this command.")
            ""))
     (let (ret)
       (or (and (setq ret (assoc "name" param))
-              (message/strip-quoted-string (cdr ret))
+              (rfc822/strip-quoted-string (cdr ret))
               )
          (and (setq ret (assoc "x-name" param))
-              (message/strip-quoted-string (cdr ret))
+              (rfc822/strip-quoted-string (cdr ret))
               )
          
          (save-excursion
@@ -481,8 +491,8 @@ The compressed face will be piped to this command.")
                                         )
                                    (point-max)))
              (or
-              (message/get-field-body "Content-Description")
-              (message/get-field-body "Subject")
+              (rfc822/get-field-body "Content-Description")
+              (rfc822/get-field-body "Subject")
               )))
          ""))
     ))
@@ -491,7 +501,7 @@ The compressed face will be piped to this command.")
 ;;; @ content information
 ;;;
 
-(defun mime::get-point-content-number (p &optional cinfo)
+(defun mime-article/point-content-number (p &optional cinfo)
   (or cinfo
       (setq cinfo mime::article/content-info)
       )
@@ -504,7 +514,7 @@ The compressed face will be piped to this command.")
              (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)))
                        )
@@ -513,6 +523,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)
@@ -575,13 +597,7 @@ The compressed face will be piped to this command.")
   (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)
-          ))
+    (mime/decode-region encoding beg end)
     (let* ((mode mime::preview/original-major-mode)
           (m (assq mode mime-viewer/code-converter-alist))
           )
@@ -595,7 +611,7 @@ The compressed face will be piped to this command.")
       (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)
@@ -724,7 +740,7 @@ listed in key order:
          cinfo)
       (switch-to-buffer (mime::preview-content-info/buffer pc))
       (setq cinfo (mime::preview-content-info/content-info pc))
-      (mime::get-point-content-number (mime::content-info/point-min cinfo))
+      (mime-article/point-content-number (mime::content-info/point-min cinfo))
       )))
 
 (defun mime-preview/cinfo-to-pcinfo (cinfo)
@@ -748,12 +764,6 @@ listed in key order:
     (mime-preview/decode-content)
     ))
 
-(defun mime-viewer/play-content-mouse (e)
-  (interactive "e")
-  (mouse-set-point e)
-  (mime-viewer/play-content)
-  )
-
 (defun mime-viewer/extract-content ()
   (interactive)
   (let ((mime-viewer/decoding-mode "extract"))
@@ -777,16 +787,15 @@ listed in key order:
   (interactive)
   (let ((pc (mime::point-preview-content (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::get-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)