"Parse BUFFER as a MIME message.")
+;;; @ Entity Representation and Implementation
+;;;
+
+(defsubst mime-find-function (service type)
+ (let ((imps (cdr (assq type mime-entity-implementation-alist))))
+ (if imps
+ (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
+ (mime-entity-representation-type-internal entity)))
+
+(defsubst mime-entity-send (entity service &rest args)
+ (apply (mime-find-function
+ service (mime-entity-representation-type-internal entity))
+ entity
+ args))
+
+(defun mime-open-entity (type location)
+ "Open an entity 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 type) location))
+
+(defun mime-entity-cooked-p (entity)
+ "Return non-nil if contents of ENTITY has been already code-converted."
+ (mime-entity-send entity 'cooked-p))
+
+
;;; @ Entity as node of message
;;;
(defalias 'mime-entity-node-id 'mime-entity-node-id-internal)
-(defsubst mime-entity-number (entity)
+(defun mime-entity-number (entity)
+ "Return entity-number of ENTITY."
(reverse (mime-entity-node-id-internal entity)))
(defun mime-find-entity-from-number (entity-number &optional message)
))
)))
-(defsubst mime-find-entity-from-node-id (entity-node-id &optional message)
+(defun mime-find-entity-from-node-id (entity-node-id &optional message)
"Return entity from ENTITY-NODE-ID in MESSAGE.
If MESSAGE is not specified, `mime-message-structure' is used."
(mime-find-entity-from-number (reverse entity-node-id) message))
-(defsubst mime-entity-parent (entity &optional message)
+(defun mime-entity-parent (entity &optional message)
"Return mother entity of ENTITY.
If MESSAGE is not specified, `mime-message-structure' in the buffer of
ENTITY is used."
(set-buffer (mime-entity-buffer entity))
mime-message-structure))))
-(defsubst mime-root-entity-p (entity)
+(defun mime-root-entity-p (entity)
"Return t if ENTITY is root-entity (message)."
(null (mime-entity-node-id entity)))
;;; @ Entity Buffer
;;;
-(defalias 'mime-entity-buffer 'mime-entity-buffer-internal)
-(defalias 'mime-entity-point-min 'mime-entity-header-start-internal)
-(defalias 'mime-entity-point-max 'mime-entity-body-end-internal)
+(defun mime-entity-buffer (entity)
+ (or (mime-entity-buffer-internal entity)
+ (mime-entity-send entity 'entity-buffer)))
+
+(defun mime-entity-point-min (entity)
+ (mime-entity-send entity 'point-min))
+
+(defun mime-entity-point-max (entity)
+ (mime-entity-send entity 'point-max))
+
+(defun mime-entity-header-start (entity)
+ (or (mime-entity-header-start-internal entity)
+ (mime-entity-send entity 'header-start)))
+
+(defun mime-entity-header-end (entity)
+ (or (mime-entity-header-end-internal entity)
+ (mime-entity-send entity 'header-end)))
+
+(defun mime-entity-body-start (entity)
+ (or (mime-entity-body-start-internal entity)
+ (mime-entity-send entity 'body-start)))
+
+(defun mime-entity-body-end (entity)
+ (or (mime-entity-body-end-internal entity)
+ (mime-entity-send entity 'body-end)))
;;; @ Entity Header
;;;
-(defalias 'mime-entity-header-start 'mime-entity-header-start-internal)
-(defalias 'mime-entity-header-end 'mime-entity-header-end-internal)
-
(defun mime-fetch-field (field-name &optional entity)
(or (symbolp field-name)
(setq field-name (intern (capitalize (capitalize field-name)))))
(field-body (cdr (assq field-name header))))
(or field-body
(progn
- (if (save-excursion
- (set-buffer (mime-entity-buffer entity))
- (save-restriction
- (narrow-to-region (mime-entity-header-start entity)
- (mime-entity-header-end entity))
- (setq field-body
- (std11-fetch-field (symbol-name field-name)))
- ))
+ (if (setq field-body
+ (mime-entity-send entity 'fetch-field
+ (symbol-name field-name)))
(mime-entity-set-original-header-internal
entity (put-alist field-name field-body header))
)
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)
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 Content
-;;;
-
-(defalias 'mime-entity-body-start 'mime-entity-body-start-internal)
-(defalias 'mime-entity-body-end 'mime-entity-body-end-internal)
-
-(defun mime-entity-content (entity)
- (save-excursion
- (set-buffer (mime-entity-buffer entity))
- (mime-decode-string (buffer-substring (mime-entity-body-start entity)
- (mime-entity-body-end entity))
- (mime-entity-encoding entity))))
-
-
-;;; @ Another Entity Information
+;;; @ Entity Attributes
;;;
(defun mime-entity-uu-filename (entity)
(mime-entity-media-subtype entity-info)))
+;;; @ Entity Content
+;;;
+
+(defun mime-entity-content (entity)
+ "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-content filename))
+
+(defun mime-write-entity (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."
+ (mime-entity-send entity 'write-body filename))
+
+
;;; @ end
;;;