Rename `mime-raw-coding-system-alist' ->
[elisp/semi.git] / mime-view.el
index ca75591..1b176f4 100644 (file)
 
 (defvar mime-raw-message-info
   "Information about structure of message.
-Please use reference function `mime-entity-SLOT' to get value of
-SLOT.
+Please use reference function `mime-entity-SLOT' to get value of SLOT.
 
 Following is a list of slots of the structure:
 
-node-id                reversed entity-number (list of integers or t)
+node-id                reversed entity-number (list of integers)
 point-min      beginning point of region in raw-buffer
 point-max      end point of region in raw-buffer
 type           media-type (symbol)
@@ -67,8 +66,8 @@ encoding      Content-Transfer-Encoding (string or nil)
 children       entities included in this entity (list of content-infos)
 
 If an entity includes other entities in its body, such as multipart or
-message/rfc822, entity-infos of other entities are included in
-`children', so entity-info become a tree.")
+message/rfc822, `mime-entity' structures of them are included in
+`children', so the `mime-entity' structure become a tree.")
 (make-variable-buffer-local 'mime-raw-message-info)
 
 (defvar mime-preview-buffer nil
@@ -164,7 +163,7 @@ Please redefine this function if you want to change default setting."
             (or (eq media-subtype 'x-selection)
                 (and (eq media-subtype 'octet-stream)
                      (let ((mother-entity
-                            (mime-raw-entity-node-id-to-entity-info
+                            (mime-raw-find-entity-from-node-id
                              (cdr entity-node-id) message-info)))
                        (and (eq (mime-entity-media-type mother-entity)
                                 'multipart)
@@ -189,7 +188,7 @@ Please redefine this function if you want to change default setting."
   (let ((entity-node-id (mime-entity-node-id entity)))
     (or (null entity-node-id)
        (member (mime-entity-type/subtype
-                (mime-raw-entity-node-id-to-entity-info
+                (mime-raw-find-entity-from-node-id
                  (cdr entity-node-id) message-info))
                mime-view-childrens-header-showing-Content-Type-list)
        )))
@@ -285,8 +284,7 @@ Each elements are string of TYPE/SUBTYPE, e.g. \"text/plain\".")
     (and (member ctype mime-view-visible-media-type-list)
         (if (and (eq media-type 'application)
                  (eq media-subtype 'octet-stream))
-            (member (mime-entity-encoding entity-info)
-                    '(nil "7bit" "8bit"))
+            (member (mime-entity-encoding entity) '(nil "7bit" "8bit"))
           t))))
 
 
@@ -303,16 +301,17 @@ Each element looks like (TYPE/SUBTYPE . FUNCTION) or (t . FUNCTION).
 TYPE/SUBTYPE is a string of media-type and FUNCTION is a filter
 function.  t means default media-type.")
 
-(defun mime-view-display-body (beg end entity-node-id cinfo
-                                  ctype params subj encoding)
+(defun mime-view-display-body (start end entity message-info subj)
   (save-restriction
     (narrow-to-region (point-max)(point-max))
-    (insert-buffer-substring mime-raw-buffer beg end)
-    (let ((f (cdr (or (assoc ctype mime-view-content-filter-alist)
-                     (assq t mime-view-content-filter-alist)))))
+    (insert-buffer-substring mime-raw-buffer start end)
+    (let* ((ctype (mime-entity-type/subtype entity))
+          (params (mime-entity-parameters entity))
+          (encoding (mime-entity-encoding entity))
+          (f (cdr (or (assoc ctype mime-view-content-filter-alist)
+                      (assq t mime-view-content-filter-alist)))))
       (and (functionp f)
-          (funcall f ctype params encoding)
-          )
+          (funcall f ctype params encoding))
       )))
 
 (defvar mime-view-announcement-for-message/partial
@@ -480,6 +479,10 @@ The compressed face will be piped to this command.")
 
 (defvar mime-view-uuencode-encoding-name-list '("x-uue" "x-uuencode"))
 
+(defvar mime-raw-buffer-coding-system-alist
+  `((mh-show-mode . no-conversion)
+    (t . ,(mime-charset-to-coding-system default-mime-charset)))
+  "Alist of major-mode vs. corresponding coding-system of `mime-raw-buffer'.")
 
 
 ;;; @ buffer setup
@@ -496,8 +499,8 @@ The compressed face will be piped to this command.")
   (or mime-view-redisplay
       (setq mime-raw-message-info (mime-parse-message ctl encoding))
       )
-  (let* ((cinfo mime-raw-message-info)
-        (pcl (mime-raw-flatten-message-info cinfo))
+  (let* ((message-info mime-raw-message-info)
+        (pcl (mime-raw-flatten-message-info message-info))
         (the-buf (current-buffer))
         (mode major-mode)
         )
@@ -513,7 +516,7 @@ The compressed face will be piped to this command.")
       (setq major-mode 'mime-view-mode)
       (setq mode-name "MIME-View")
       (while pcl
-       (mime-view-display-entity (car pcl) cinfo the-buf obuf)
+       (mime-view-display-entity (car pcl) message-info the-buf obuf)
        (setq pcl (cdr pcl))
        )
       (set-buffer-modified-p nil)
@@ -568,9 +571,7 @@ The compressed face will be piped to this command.")
          (mime-view-insert-entity-button entity message-info subj)
          ))
     (cond ((mime-view-body-visible-p entity message-info)
-          (mime-view-display-body he end
-                                  entity-node-id message-info
-                                  ctype params subj encoding)
+          (mime-view-display-body he end entity message-info subj)
           )
          ((and (eq media-type 'message)(eq media-subtype 'partial))
           (mime-view-insert-message/partial-button)
@@ -585,7 +586,7 @@ The compressed face will be piped to this command.")
     (setq ne (point-max))
     (widen)
     (put-text-property nb ne 'mime-view-raw-buffer ibuf)
-    (put-text-property nb ne 'mime-view-entity-info entity)
+    (put-text-property nb ne 'mime-view-entity entity)
     (goto-char ne)
     ))
 
@@ -620,47 +621,15 @@ The compressed face will be piped to this command.")
 ;;; @ entity information
 ;;;
 
-(defun mime-raw-point-to-entity-number (position &optional message-info)
-  "Return entity-number from POTION in mime-raw-buffer.
-If optional argument MESSAGE-INFO is not specified,
-`mime-raw-message-info' is used."
-  (or message-info
-      (setq message-info mime-raw-message-info))
-  (let ((b (mime-entity-point-min message-info))
-       (e (mime-entity-point-max message-info))
-       (c (mime-entity-children message-info))
-       )
-    (if (and (<= b position)(<= position e))
-       (or (let (co ret (sn 0))
-             (catch 'tag
-               (while c
-                 (setq co (car c))
-                 (setq ret (mime-raw-point-to-entity-number position co))
-                 (cond ((eq ret t) (throw 'tag (list sn)))
-                       (ret (throw 'tag (cons sn ret)))
-                       )
-                 (setq c (cdr c))
-                 (setq sn (1+ sn))
-                 )))
-           t))))
-
-(defun mime-raw-point-to-entity-node-id (position &optional message-info)
-  "Return entity-node-id from POTION in mime-raw-buffer.
-If optional argument MESSAGE-INFO is not specified,
-`mime-raw-message-info' is used."
-  (reverse (mime-raw-point-to-entity-number position message-info)))
-
-(defsubst mime-raw-entity-node-id-to-entity-info (entity-node-id
-                                                 &optional message-info)
-  "Return entity-info from ENTITY-NODE-ID in mime-raw-buffer.
+(defsubst mime-raw-find-entity-from-node-id (entity-node-id
+                                            &optional message-info)
+  "Return entity from ENTITY-NODE-ID in mime-raw-buffer.
 If optional argument MESSAGE-INFO is not specified,
 `mime-raw-message-info' is used."
-  (mime-raw-entity-number-to-entity-info (reverse entity-node-id)
-                                        message-info))
+  (mime-raw-find-entity-from-number (reverse entity-node-id) message-info))
 
-(defun mime-raw-entity-number-to-entity-info (entity-number
-                                             &optional message-info)
-  "Return entity-info from ENTITY-NUMBER in mime-raw-buffer.
+(defun mime-raw-find-entity-from-number (entity-number &optional message-info)
+  "Return entity from ENTITY-NUMBER in mime-raw-buffer.
 If optional argument MESSAGE-INFO is not specified,
 `mime-raw-message-info' is used."
   (or message-info
@@ -672,12 +641,43 @@ If optional argument MESSAGE-INFO is not specified,
          message-info
        (let ((rc (nth sn (mime-entity-children message-info))))
          (if rc
-             (mime-raw-entity-number-to-entity-info (cdr entity-number) rc)
+             (mime-raw-find-entity-from-number (cdr entity-number) rc)
            ))
        ))))
 
+(defun mime-raw-find-entity-from-point (point &optional message-info)
+  "Return entity from POINT in mime-raw-buffer.
+If optional argument MESSAGE-INFO is not specified,
+`mime-raw-message-info' is used."
+  (or message-info
+      (setq message-info mime-raw-message-info))
+  (if (and (<= (mime-entity-point-min message-info) point)
+          (<= point (mime-entity-point-max message-info)))
+      (let ((children (mime-entity-children message-info)))
+       (catch 'tag
+         (while children
+           (let ((ret
+                  (mime-raw-find-entity-from-point point (car children))))
+             (if ret
+                 (throw 'tag ret)
+               ))
+           (setq children (cdr children)))
+         message-info))))
+
+(defsubst mime-raw-point-to-entity-node-id (point &optional message-info)
+  "Return entity-node-id from POINT in mime-raw-buffer.
+If optional argument MESSAGE-INFO is not specified,
+`mime-raw-message-info' is used."
+  (mime-entity-node-id (mime-raw-find-entity-from-point point message-info)))
+
+(defsubst mime-raw-point-to-entity-number (point &optional message-info)
+  "Return entity-number from POINT in mime-raw-buffer.
+If optional argument MESSAGE-INFO is not specified,
+`mime-raw-message-info' is used."
+  (reverse (mime-raw-point-to-entity-node-id point message-id)))
+
 (defun mime-raw-flatten-message-info (&optional message-info)
-  "Return list of entity-infos in mime-raw-buffer.
+  "Return list of entity in mime-raw-buffer.
 If optional argument MESSAGE-INFO is not specified,
 `mime-raw-message-info' is used."
   (or message-info
@@ -864,7 +864,8 @@ button-2    Move to point under the mouse cursor
            (setq mime-mother-buffer mother)
            ))
       (mime-view-define-keymap default-keymap-or-function)
-      (let ((point (next-single-property-change (point-min) 'mime-view-entity-info)))
+      (let ((point
+            (next-single-property-change (point-min) 'mime-view-entity)))
        (if point
            (goto-char point)
          (goto-char (point-min))
@@ -918,14 +919,14 @@ of the mother-buffer."
 It calls following-method selected from variable
 `mime-view-following-method-alist'."
   (interactive)
-  (let ((message-info (get-text-property (point-min) 'mime-view-entity-info))
+  (let ((message-info (get-text-property (point-min) 'mime-view-entity))
        entity)
     (while (null (setq entity
-                      (get-text-property (point) 'mime-view-entity-info)))
+                      (get-text-property (point) 'mime-view-entity)))
       (backward-char)
       )
     (let* ((p-beg
-           (previous-single-property-change (point) 'mime-view-entity-info))
+           (previous-single-property-change (point) 'mime-view-entity))
           p-end
           (entity-node-id (mime-entity-node-id entity))
           (len (length entity-node-id))
@@ -933,16 +934,16 @@ It calls following-method selected from variable
       (cond ((null p-beg)
             (setq p-beg
                   (if (eq (next-single-property-change (point-min)
-                                                       'mime-view-entity-info)
+                                                       'mime-view-entity)
                           (point))
                       (point)
                     (point-min)))
             )
-           ((eq (next-single-property-change p-beg 'mime-view-entity-info)
+           ((eq (next-single-property-change p-beg 'mime-view-entity)
                 (point))
             (setq p-beg (point))
             ))
-      (setq p-end (next-single-property-change p-beg 'mime-view-entity-info))
+      (setq p-end (next-single-property-change p-beg 'mime-view-entity))
       (cond ((null p-end)
             (setq p-end (point-max))
             )
@@ -956,11 +957,11 @@ It calls following-method selected from variable
                 (let (e)
                   (while (setq e
                                (next-single-property-change
-                                (point) 'mime-view-entity-info))
+                                (point) 'mime-view-entity))
                     (goto-char e)
                     (let ((rc (mime-entity-node-id
                                (get-text-property (point)
-                                                  'mime-view-entity-info))))
+                                                  'mime-view-entity))))
                       (or (equal entity-node-id
                                  (nthcdr (- (length rc) len) rc))
                           (throw 'tag nil)
@@ -999,8 +1000,7 @@ It calls following-method selected from variable
                        (set-buffer a-buf)
                        (setq
                         ci
-                        (mime-raw-entity-node-id-to-entity-info
-                         entity-node-id))
+                        (mime-raw-find-entity-from-node-id entity-node-id))
                        (save-restriction
                          (narrow-to-region
                           (mime-entity-point-min ci)
@@ -1073,18 +1073,18 @@ If there is no upper entity, call function `mime-preview-quit'."
   (interactive)
   (let (cinfo)
     (while (null (setq cinfo
-                      (get-text-property (point) 'mime-view-entity-info)))
+                      (get-text-property (point) 'mime-view-entity)))
       (backward-char)
       )
-    (let ((r (mime-raw-entity-node-id-to-entity-info
+    (let ((r (mime-raw-find-entity-from-node-id
              (cdr (mime-entity-node-id cinfo))
-             (get-text-property 1 'mime-view-entity-info)))
+             (get-text-property 1 'mime-view-entity)))
          point)
       (catch 'tag
        (while (setq point (previous-single-property-change
-                           (point) 'mime-view-entity-info))
+                           (point) 'mime-view-entity))
          (goto-char point)
-         (if (eq r (get-text-property (point) 'mime-view-entity-info))
+         (if (eq r (get-text-property (point) 'mime-view-entity))
              (throw 'tag t)
            )
          )
@@ -1096,11 +1096,11 @@ If there is no upper entity, call function `mime-preview-quit'."
 If there is no previous entity, it calls function registered in
 variable `mime-view-over-to-previous-method-alist'."
   (interactive)
-  (while (null (get-text-property (point) 'mime-view-entity-info))
+  (while (null (get-text-property (point) 'mime-view-entity))
     (backward-char)
     )
   (let ((point
-        (previous-single-property-change (point) 'mime-view-entity-info)))
+        (previous-single-property-change (point) 'mime-view-entity)))
     (if point
        (goto-char point)
       (let ((f (assq mime-preview-original-major-mode
@@ -1115,7 +1115,7 @@ variable `mime-view-over-to-previous-method-alist'."
 If there is no previous entity, it calls function registered in
 variable `mime-view-over-to-next-method-alist'."
   (interactive)
-  (let ((point (next-single-property-change (point) 'mime-view-entity-info)))
+  (let ((point (next-single-property-change (point) 'mime-view-entity)))
     (if point
        (goto-char point)
       (let ((f (assq mime-preview-original-major-mode
@@ -1140,7 +1140,7 @@ If reached to (point-max), it calls function registered in variable
             (funcall (cdr f))
           ))
     (let ((point
-          (or (next-single-property-change (point) 'mime-view-entity-info)
+          (or (next-single-property-change (point) 'mime-view-entity)
               (point-max))))
       (forward-line h)
       (if (> (point) point)
@@ -1168,7 +1168,7 @@ If reached to (point-min), it calls function registered in variable
          (while (> (point) 1)
            (if (setq point
                      (previous-single-property-change (point)
-                                                      'mime-view-entity-info))
+                                                      'mime-view-entity))
                (throw 'tag t)
              )
            (backward-char)