- (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))))))
-
-(defun mime-read-field (field-name &optional entity)
- (or (symbolp field-name)
- (setq field-name (capitalize (capitalize field-name))))
- (or entity
- (setq entity mime-message-structure))
- (cond ((eq field-name 'Content-Type)
- (mime-entity-content-type entity)
- )
- ((eq field-name 'Content-Disposition)
- (mime-entity-content-disposition entity)
- )
- ((eq field-name 'Content-Transfer-Encoding)
- (mime-entity-encoding entity)
- )
- (t
- (let* ((header (mime-entity-parsed-header-internal entity))
- (field (cdr (assq field-name header))))
- (or field
- (let ((field-body (mime-fetch-field field-name entity)))
- (when field-body
- (cond ((memq field-name '(From Resent-From
- To Resent-To
- Cc Resent-Cc
- Bcc Resent-Bcc
- Reply-To Resent-Reply-To))
- (setq field (std11-parse-addresses
- (eword-lexical-analyze field-body)))
- )
- ((memq field-name '(Sender Resent-Sender))
- (setq field (std11-parse-address
- (eword-lexical-analyze field-body)))
- )
- ((memq field-name eword-decode-ignored-field-list)
- (setq field field-body))
- ((memq field-name eword-decode-structured-field-list)
- (setq field (eword-decode-structured-field-body
- field-body)))
- (t
- (setq field (eword-decode-unstructured-field-body
- field-body))
- ))
- (mime-entity-set-parsed-header-internal
- 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)
- "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")
- )))))))))
+ (let ((ret (mime-entity-fetch-field entity "Content-Transfer-Encoding")))
+ (mime-entity-set-encoding-internal
+ entity
+ (or (and ret (mime-parse-Content-Transfer-Encoding ret))
+ default-encoding "7bit"))
+ )))
+
+(defvar mime-field-parser-alist
+ '((Return-Path . std11-parse-route-addr)
+
+ (Reply-To . std11-parse-addresses)
+
+ (Sender . std11-parse-mailbox)
+ (From . std11-parse-addresses)
+
+ (Resent-Reply-To . std11-parse-addresses)
+
+ (Resent-Sender . std11-parse-mailbox)
+ (Resent-From . std11-parse-addresses)
+
+ (To . std11-parse-addresses)
+ (Resent-To . std11-parse-addresses)
+ (Cc . std11-parse-addresses)
+ (Resent-Cc . std11-parse-addresses)
+ (Bcc . std11-parse-addresses)
+ (Resent-Bcc . std11-parse-addresses)
+
+ (Message-Id . mime-parse-msg-id)
+ (Recent-Message-Id . mime-parse-msg-id)
+
+ (In-Reply-To . std11-parse-msg-ids)
+ (References . std11-parse-msg-ids)
+
+ (Content-Id . mime-parse-msg-id)
+ ))
+
+(defun mime-entity-read-field (entity field-name)
+ (let ((sym (if (symbolp field-name)
+ (prog1
+ field-name
+ (setq field-name (symbol-name field-name)))
+ (intern (capitalize field-name)))))
+ (cond ((eq sym 'Content-Type)
+ (mime-entity-content-type entity)
+ )
+ ((eq sym 'Content-Disposition)
+ (mime-entity-content-disposition entity)
+ )
+ ((eq sym 'Content-Transfer-Encoding)
+ (mime-entity-encoding entity)
+ )
+ (t
+ (let* ((header (mime-entity-parsed-header-internal entity))
+ (field (cdr (assq sym header))))
+ (or field
+ (let ((field-body (mime-entity-fetch-field entity field-name))
+ parser)
+ (when field-body
+ (setq parser
+ (cdr (assq sym mime-field-parser-alist)))
+ (setq field
+ (if parser
+ (funcall parser
+ (eword-lexical-analyze field-body))
+ (mime-decode-field-body field-body sym 'plain)
+ ))
+ (mime-entity-set-parsed-header-internal
+ entity (put-alist sym field header))
+ field))))))))
+
+;; (defun mime-read-field (field-name &optional entity)
+;; (or entity
+;; (setq entity mime-message-structure))
+;; (mime-entity-read-field entity field-name)
+;; )
+;; (make-obsolete 'mime-read-field 'mime-entity-read-field)
+
+(luna-define-generic mime-insert-header (entity &optional invisible-fields
+ visible-fields)
+ "Insert before point a decoded header of ENTITY.")