X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mime-parse.el;fp=mime-parse.el;h=2741a04fbfa899a9c705e75af3761bb0a4ab9274;hb=e79eb9f77304888f141f743f2057692304f44176;hp=f3e696cdc944d4daad2140e8d75bfa033a395933;hpb=e5e4dc7567f4a43ac6d7dcb50137defe47c20acf;p=elisp%2Fsemi.git diff --git a/mime-parse.el b/mime-parse.el index f3e696c..2741a04 100644 --- a/mime-parse.el +++ b/mime-parse.el @@ -122,6 +122,10 @@ and return parsed it. Format of return value is as same as "Return primary-type of CONTENT-TYPE." (cddr content-type)) +(defsubst mime-content-type-parameter (content-type parameter) + "Return PARAMETER value of CONTENT-TYPE." + (cdr (assoc parameter (mime-content-type-parameters content-type)))) + ;;; @ Content-Disposition ;;; @@ -160,6 +164,14 @@ and return parsed it." "Return disposition-parameters of CONTENT-DISPOSITION." (cdr content-disposition)) +(defsubst mime-content-disposition-parameter (content-disposition parameter) + "Return PARAMETER value of CONTENT-DISPOSITION." + (cdr (assoc parameter (cdr content-disposition)))) + +(defsubst mime-content-disposition-filename (content-disposition) + "Return filename of CONTENT-DISPOSITION." + (mime-content-disposition-parameter content-disposition "filename")) + ;;; @ Content-Transfer-Encoding ;;; @@ -184,16 +196,18 @@ If is is not found, return DEFAULT-ENCODING." (defsubst make-mime-entity (node-id point-min point-max - content-type encoding children) + content-type content-disposition encoding + children) (vector node-id point-min point-max - content-type encoding children)) + content-type content-disposition encoding children)) -(defsubst mime-entity-node-id (entity-info) (aref entity-info 0)) -(defsubst mime-entity-point-min (entity-info) (aref entity-info 1)) -(defsubst mime-entity-point-max (entity-info) (aref entity-info 2)) -(defsubst mime-entity-content-type (entity-info) (aref entity-info 3)) -(defsubst mime-entity-encoding (entity-info) (aref entity-info 4)) -(defsubst mime-entity-children (entity-info) (aref entity-info 5)) +(defsubst mime-entity-node-id (entity) (aref entity 0)) +(defsubst mime-entity-point-min (entity) (aref entity 1)) +(defsubst mime-entity-point-max (entity) (aref entity 2)) +(defsubst mime-entity-content-type (entity) (aref entity 3)) +(defsubst mime-entity-content-disposition (entity) (aref entity 4)) +(defsubst mime-entity-encoding (entity) (aref entity 5)) +(defsubst mime-entity-children (entity) (aref entity 6)) (defsubst mime-entity-media-type (entity) (mime-content-type-primary-type (mime-entity-content-type entity))) @@ -205,9 +219,13 @@ If is is not found, return DEFAULT-ENCODING." (mime-type/subtype-string (mime-entity-media-type entity-info) (mime-entity-media-subtype entity-info))) -(defun mime-parse-multipart (boundary content-type encoding node-id) +(defun mime-parse-multipart (content-type content-disposition encoding node-id) (goto-char (point-min)) - (let* ((dash-boundary (concat "--" boundary)) + (let* ((dash-boundary + (concat "--" + (std11-strip-quoted-string + (cdr (assoc "boundary" + (mime-content-type-parameters content-type)))))) (delimiter (concat "\n" (regexp-quote dash-boundary))) (close-delimiter (concat delimiter "--[ \t]*$")) (beg (point-min)) @@ -249,7 +267,8 @@ If is is not found, return DEFAULT-ENCODING." (setq children (cons ret children)) ) (make-mime-entity node-id beg (point-max) - content-type encoding (nreverse children)) + content-type content-disposition encoding + (nreverse children)) )) (defun mime-parse-message (&optional default-ctl default-encoding node-id) @@ -258,21 +277,20 @@ DEFAULT-CTL is used when an entity does not have valid Content-Type field. Its format must be as same as return value of mime-{parse|read}-Content-Type." (let* ((content-type (or (mime-read-Content-Type) default-ctl)) - (encoding (mime-read-Content-Transfer-Encoding default-encoding)) - (boundary (assoc "boundary" - (mime-content-type-parameters content-type)))) - (cond (boundary - (setq boundary (std11-strip-quoted-string (cdr boundary))) - (mime-parse-multipart boundary content-type encoding node-id) + (content-disposition (mime-read-Content-Disposition)) + (primary-type (mime-content-type-primary-type content-type)) + (encoding (mime-read-Content-Transfer-Encoding default-encoding))) + (cond ((eq primary-type 'multipart) + (mime-parse-multipart content-type content-disposition encoding + node-id) ) - ((and (eq (mime-content-type-primary-type content-type) - 'message) + ((and (eq primary-type 'message) (memq (mime-content-type-subtype content-type) - '(rfc822 news)) - ) + '(rfc822 news) + )) (goto-char (point-min)) (make-mime-entity node-id (point-min) (point-max) - content-type encoding + content-type content-disposition encoding (save-restriction (narrow-to-region (if (re-search-forward "^$" nil t) @@ -286,7 +304,7 @@ mime-{parse|read}-Content-Type." ) (t (make-mime-entity node-id (point-min) (point-max) - content-type encoding nil) + content-type content-disposition encoding nil) )) ))