Move `eword-visible-field-p' to mmbuffer.el.
[elisp/flim.git] / mime.el
diff --git a/mime.el b/mime.el
index ba95a43..1b5888b 100644 (file)
--- a/mime.el
+++ b/mime.el
@@ -63,25 +63,14 @@ current-buffer, and return it.")
 ;;; @ Entity Representation and Implementation
 ;;;
 
-(defvar mime-entity-implementation-alist nil)
-
 (defsubst mime-find-function (service type)
   (let ((imps (cdr (assq type mime-entity-implementation-alist))))
     (if imps
-       (let ((func (cdr (assq service imps))))
-         (unless func
-           (setq func (intern (format "mm%s-%s" type service)))
-           (set-alist 'mime-entity-implementation-alist
-                      type (put-alist service func imps))
-           )
-         func)
-      (let ((prefix (format "mm%s" type)))
-       (require (intern prefix))
-       (let ((func (intern (format "%s-%s" prefix service))))
-         (set-alist 'mime-entity-implementation-alist
-                    type
-                    (list (cons service func)))
-         func)))))
+       (cdr (assq service imps))
+      (require (intern (format "mm%s" type)))
+      (cdr (assq service
+                (cdr (assq type mime-entity-implementation-alist))))
+      )))
 
 (defsubst mime-entity-function (entity service)
   (mime-find-function service
@@ -98,13 +87,11 @@ current-buffer, and return it.")
 TYPE is representation-type.
 LOCATION is location of entity.  Specification of it is depended on
 representation-type."
-  (funcall (mime-find-function 'open-entity type) location)
-  )
+  (funcall (mime-find-function 'open type) location))
 
 (defun mime-entity-cooked-p (entity)
   "Return non-nil if contents of ENTITY has been already code-converted."
-  (funcall (mime-entity-function entity 'cooked-p))
-  )
+  (mime-entity-send entity 'cooked-p))
 
 
 ;;; @ Entity as node of message
@@ -161,26 +148,26 @@ ENTITY is used."
       (mime-entity-send entity 'entity-buffer)))
 
 (defun mime-entity-point-min (entity)
-  (mime-entity-send entity 'entity-point-min))
+  (mime-entity-send entity 'point-min))
 
 (defun mime-entity-point-max (entity)
-  (mime-entity-send entity 'entity-point-max))
+  (mime-entity-send entity 'point-max))
 
 (defun mime-entity-header-start (entity)
   (or (mime-entity-header-start-internal entity)
-      (mime-entity-send entity 'entity-header-start)))
+      (mime-entity-send entity 'header-start)))
 
 (defun mime-entity-header-end (entity)
   (or (mime-entity-header-end-internal entity)
-      (mime-entity-send entity 'entity-header-end)))
+      (mime-entity-send entity 'header-end)))
 
 (defun mime-entity-body-start (entity)
   (or (mime-entity-body-start-internal entity)
-      (mime-entity-send entity 'entity-body-start)))
+      (mime-entity-send entity 'body-start)))
 
 (defun mime-entity-body-end (entity)
   (or (mime-entity-body-end-internal entity)
-      (mime-entity-send entity 'entity-body-end)))
+      (mime-entity-send entity 'body-end)))
 
 
 ;;; @ Entity Header
@@ -215,14 +202,15 @@ ENTITY is used."
                 entity disposition)
                disposition))))))
 
-(defun mime-entity-encoding (entity)
+(defun mime-entity-encoding (entity &optional default-encoding)
   (or (mime-entity-encoding-internal entity)
-      (let ((ret (mime-fetch-field 'Content-Transfer-Encoding entity)))
-       (if ret
-           (let ((encoding (mime-parse-Content-Transfer-Encoding ret)))
-             (when encoding
-               (mime-entity-set-encoding-internal entity encoding)
-               encoding))))))
+      (let ((encoding
+            (or (let ((ret (mime-fetch-field
+                            'Content-Transfer-Encoding entity)))
+                  (and ret (mime-parse-Content-Transfer-Encoding ret)))
+                default-encoding "7bit")))
+       (mime-entity-set-encoding-internal entity encoding)
+       encoding)))
 
 (defun mime-read-field (field-name &optional entity)
   (or (symbolp field-name)
@@ -269,82 +257,11 @@ ENTITY is used."
                    entity (put-alist field-name field header))
                   field)))))))
 
-(defun eword-visible-field-p (field-name visible-fields invisible-fields)
-  (or (catch 'found
-       (while visible-fields
-         (let ((regexp (car visible-fields)))
-           (if (string-match regexp field-name)
-               (throw 'found t)
-             ))
-         (setq visible-fields (cdr visible-fields))
-         ))
-      (catch 'found
-       (while invisible-fields
-         (let ((regexp (car invisible-fields)))
-           (if (string-match regexp field-name)
-               (throw 'found nil)
-             ))
-         (setq invisible-fields (cdr invisible-fields))
-         )
-       t)))
-
-(defun mime-insert-decoded-header (entity
-                                  &optional invisible-fields visible-fields
-                                  code-conversion)
+(defun mime-insert-decoded-header (entity &optional invisible-fields
+                                         visible-fields)
   "Insert before point a decoded header of ENTITY."
-  (let ((default-charset
-         (if code-conversion
-             (if (mime-charset-to-coding-system code-conversion)
-                 code-conversion
-               default-mime-charset))))
-    (save-restriction
-      (narrow-to-region (point)(point))
-      (let ((the-buf (current-buffer))
-           (src-buf (mime-entity-buffer entity))
-           (h-end (mime-entity-header-end entity))
-           beg p end field-name len field)
-       (save-excursion
-         (set-buffer src-buf)
-         (goto-char (mime-entity-header-start entity))
-         (save-restriction
-           (narrow-to-region (point) h-end)
-           (while (re-search-forward std11-field-head-regexp nil t)
-             (setq beg (match-beginning 0)
-                   p (match-end 0)
-                   field-name (buffer-substring beg (1- p))
-                   len (string-width field-name)
-                   end (std11-field-end))
-             (when (eword-visible-field-p field-name
-                                          visible-fields invisible-fields)
-               (setq field (intern (capitalize field-name)))
-               (save-excursion
-                 (set-buffer the-buf)
-                 (insert field-name)
-                 (insert ":")
-                 (cond ((memq field eword-decode-ignored-field-list)
-                        ;; Don't decode
-                        (insert-buffer-substring src-buf p end)
-                        )
-                       ((memq field eword-decode-structured-field-list)
-                        ;; Decode as structured field
-                        (let ((body (save-excursion
-                                      (set-buffer src-buf)
-                                      (buffer-substring p end)))
-                              (default-mime-charset default-charset))
-                          (insert (eword-decode-and-fold-structured-field
-                                   body (1+ len)))
-                          ))
-                       (t
-                        ;; Decode as unstructured field
-                        (let ((body (save-excursion
-                                      (set-buffer src-buf)
-                                      (buffer-substring p end)))
-                              (default-mime-charset default-charset))
-                          (insert (eword-decode-unstructured-field-body
-                                   body (1+ len)))
-                          )))
-                 (insert "\n")
-                 )))))))))
+  (mime-entity-send entity 'insert-decoded-header
+                   invisible-fields visible-fields))
 
 
 ;;; @ Entity Attributes
@@ -388,26 +305,20 @@ ENTITY is used."
 ;;;
 
 (defun mime-entity-content (entity)
-  (mime-entity-send entity 'entity-content))
+  "Return content of ENTITY as byte sequence (string)."
+  (mime-entity-send entity 'get-content))
 
 (defun mime-write-entity-content (entity filename)
   "Write content of ENTITY into FILENAME."
-  (mime-entity-send entity 'write-entity-content filename))
+  (mime-entity-send entity 'write-content filename))
 
 (defun mime-write-entity (entity filename)
-  "Write ENTITY into FILENAME."
-  (mime-entity-send entity 'write-entity filename))
+  "Write header and body of ENTITY into FILENAME."
+  (mime-entity-send entity 'write-with-header filename))
 
 (defun mime-write-entity-body (entity filename)
   "Write body of ENTITY into FILENAME."
-  (save-excursion
-    (set-buffer (mime-entity-buffer entity))
-    (if (mime-entity-cooked-p entity)
-       (write-region (mime-entity-body-start entity)
-                     (mime-entity-body-end entity) filename)
-      (write-region-as-binary (mime-entity-body-start entity)
-                             (mime-entity-body-end entity) filename)
-      )))
+  (mime-entity-send entity 'write-body filename))
 
 
 ;;; @ end