attached file in mail
Keiichi Suzuki
keiichi @ nanap.org
1999年 11月 1日 (月) 10:05:09 JST
;; emacs-mime-ja も登録済の address しか受け付けてくれないのですね。
>>>>> emacs-mime-ja の No. 00003
>>>>> Message-Id: <htxr9if946x.fsf @ mulelab3.etl.go.jp> で、
>>>>> "守岡" == tomo @ etl.go.jp (守岡 知彦 / MORIOKA Tomohiko)さま曰く...
とりあえず、実装してみたのですが、ちょっと疑問点がありますので、どうした
ら良いかご意見をお聞かせください。
圭一> Decode 済のものには text-property をつけるようにしましょうか?
守岡> そうですね。何が良いでしょうかね? mime-language? それとも『男らしく』
守岡> language とか。
守岡> ;; 他の関係各位(言語タグな人とか)と相談した方が良いような気もします
守岡> ;; が。
これはどうしましょうか?
;; 『男らしい』方も魅力的ではあります。 :-)
また、内容は symbol / string のどちらにしましょうか?
圭一> いろいろ考えてみたのですが、結果としては parameter の表現を現在の
圭一> (attribute-name . value)
圭一> という形式から、
圭一> (attribute-name . [language charset raw-value-alist encoded-value-cache])
圭一> member of raw-value-alist:
圭一> (section-number . (encoded . raw-value))
圭一> という形式に変更して、結合と encode は lazy に処理するというのが
圭一> 良いのではないかと思いますがいかがでしょうか?
守岡> よろしいんじゃないでしょうか?
守岡> あるいは、連想リストじゃなくて mime-parameter というような抽象型の
守岡> 集合(多分実装上は vector の list か hash (or obarray))に変更しちゃう
守岡> のが良いかも知れません。
守岡> ;; どうせ連想 list のままでも連想 list を直接いじる program は動かなく
守岡> ;; なるだろうし、mime-*-parameters で結合後の連想 list を返せば行儀の
守岡> ;; 良い program は救済できるだろうし。
パラメータってそんなにたくさんつくものだとも思えませんので、 hash よりも
連想 list のままの方が検索の cost が少なそうなのと、順序性が気になるのが
あって、連想 list のままという実装にしてあります。
それと、 mime-parse-Content-Type() / mime-parse-Content-Disposition() は、
doc string つき、しかもその中に返り値の形式まで記述されています。今回の
変更では、この形式が変更されてしまいますが、構わないでしょうか?
もし、まずいようであれば、 mime-parse-Content-*-internal() というものを
作って、現在 mime-parse-Content-*() を呼び出しているところは、こちらを呼
び出すようにしようと思います。
さらに、 mime-parse-parameter() は必要でしょうか? そうであれば別途新しい
実装に変更する必要があります。
--
鈴木圭一 / keiichi @ nanap.org
PGP finger print (DH/DSS)
0B32 B37E 6DE9 3BC1 68A4 4089 7AAF 2B03 ECBD 614B
-------------- next part --------------
Index: eword-decode.el
===================================================================
RCS file: /hare/cvs/root/flim/eword-decode.el,v
retrieving revision 1.15.2.1
diff -c -r1.15.2.1 eword-decode.el
*** eword-decode.el 1999/05/31 10:25:18 1.15.2.1
--- eword-decode.el 1999/11/01 00:24:28
***************
*** 61,66 ****
--- 61,67 ----
"\\("
mime-charset-regexp
"\\)"
+ "\\(\\*[^?]*\\)?"
(regexp-quote "?")
"\\([BbQq]\\)"
(regexp-quote "?")
***************
*** 228,234 ****
"\\(\n?[ \t]\\)+"
"\\(" eword-encoded-word-regexp "\\)")
nil t)
! (replace-match "\\1\\6")
(goto-char (point-min))
)
(while (re-search-forward eword-encoded-word-regexp nil t)
--- 229,235 ----
"\\(\n?[ \t]\\)+"
"\\(" eword-encoded-word-regexp "\\)")
nil t)
! (replace-match "\\1\\7")
(goto-char (point-min))
)
(while (re-search-forward eword-encoded-word-regexp nil t)
***************
*** 540,549 ****
)
(encoding
(upcase
! (substring word (match-beginning 2) (match-end 2))
))
(text
! (substring word (match-beginning 3) (match-end 3))
))
(condition-case err
(eword-decode-encoded-text charset encoding text must-unfold)
--- 541,550 ----
)
(encoding
(upcase
! (substring word (match-beginning 3) (match-end 3))
))
(text
! (substring word (match-beginning 4) (match-end 4))
))
(condition-case err
(eword-decode-encoded-text charset encoding text must-unfold)
Index: mime-def.el
===================================================================
RCS file: /hare/cvs/root/flim/mime-def.el,v
retrieving revision 1.49.2.14
diff -c -r1.49.2.14 mime-def.el
*** mime-def.el 1999/07/24 12:21:44 1.49.2.14
--- mime-def.el 1999/11/01 00:24:28
***************
*** 152,157 ****
--- 152,234 ----
;; (defconst eword-Q-encoding-and-encoded-text-regexp
;; (concat "\\(Q\\)\\?" eword-Q-encoded-text-regexp))
+ ;;; @ Parameter
+ ;;;
+
+ (defsubst make-mime-parameter (name &optional language charset
+ raw-values encoded-value)
+ (cons name
+ (vector language charset raw-values encoded-value))
+ )
+
+ (defsubst mime-parameter-language (parm)
+ (aref (cdr parm) 0)
+ )
+
+ (defsubst mime-parameter-set-language (parm language)
+ (aset (cdr parm) 0 language)
+ )
+
+ (defsubst mime-parameter-set-charset (parm mcs)
+ (aset (cdr parm) 1 mcs)
+ )
+
+ (defsubst mime-parameter-charset (parm)
+ (aref (cdr parm) 1)
+ )
+
+ (defsubst mime-parameter-raw-values (parm)
+ (aref (cdr parm) 2)
+ )
+
+ (defsubst mime-parameter-append-raw-value (parm no encoded raw-value)
+ (aset (cdr parm) 2 (cons (cons no (cons encoded raw-value))
+ (mime-parameter-raw-values parm)))
+ )
+
+ (defun mime-parameter-value (parm)
+ (when parm
+ (or (aref (cdr parm) 3)
+ (let* ((mcs (mime-parameter-charset parm))
+ (sorted-raw (sort (mime-parameter-raw-values parm)
+ (function (lambda (a b)
+ (< (car a) (car b))))))
+ (val
+ (if mcs
+ (with-temp-buffer
+ (let (s raw)
+ (while sorted-raw
+ (setq raw (cdar sorted-raw)
+ s (point))
+ (insert (cdr raw))
+ (when (car raw)
+ (goto-char s)
+ (while (re-search-forward "%\\([0-9a-z][0-9a-z]\\)"
+ nil t)
+ (replace-match
+ (char-to-string
+ (string-to-int (buffer-substring
+ (match-beginning 1)
+ (match-end 1))
+ 16))))
+ (goto-char (point-max)))
+ (setq sorted-raw (cdr sorted-raw)))
+ (decode-mime-charset-region (point-min) (point-max)
+ mcs)
+ (buffer-string)))
+ (mapconcat #'cddr sorted-raw ""))))
+ (aset (cdr parm) 3 val)
+ ))))
+
+ (defsubst mime-parameters (parms)
+ (mapcar (function (lambda (parm)
+ (cons (car parm)
+ (mime-parameter-value parm))))
+ parms))
+
+ (defsubst mime-parameter (parms name)
+ (let ((parm (assoc name parm)))
+ (cons (car parm) (mime-parameter-value parm))))
;;; @ Content-Type
;;;
***************
*** 172,182 ****
(defsubst mime-content-type-parameters (content-type)
"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))))
(defsubst mime-type/subtype-string (type &optional subtype)
--- 249,259 ----
(defsubst mime-content-type-parameters (content-type)
"Return primary-type of CONTENT-TYPE."
! (mime-parameters (cddr content-type)))
(defsubst mime-content-type-parameter (content-type parameter)
"Return PARAMETER value of CONTENT-TYPE."
! (mime-parameter-value (assoc parameter (cddr content-type))))
(defsubst mime-type/subtype-string (type &optional subtype)
***************
*** 196,206 ****
(defsubst mime-content-disposition-parameters (content-disposition)
"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."
--- 273,283 ----
(defsubst mime-content-disposition-parameters (content-disposition)
"Return disposition-parameters of CONTENT-DISPOSITION."
! (mime-parameters (cdr content-disposition)))
(defsubst mime-content-disposition-parameter (content-disposition parameter)
"Return PARAMETER value of CONTENT-DISPOSITION."
! (mime-parameter-value (assoc parameter (cdr content-disposition))))
(defsubst mime-content-disposition-filename (content-disposition)
"Return filename of CONTENT-DISPOSITION."
Index: mime-parse.el
===================================================================
RCS file: /hare/cvs/root/flim/mime-parse.el,v
retrieving revision 1.19.2.6
diff -c -r1.19.2.6 mime-parse.el
*** mime-parse.el 1999/07/28 04:54:16 1.19.2.6
--- mime-parse.el 1999/11/01 00:24:29
***************
*** 78,109 ****
std11-quoted-string-regexp
"\\|[^; \t\n]*\\)"))
(defconst mime::parameter-regexp
! (concat "^[ \t]*\;[ \t]*\\(" mime-token-regexp "\\)"
"[ \t]*=[ \t]*\\(" mime/content-parameter-value-regexp "\\)"))
-
- (defun mime-parse-parameter (str)
- (if (string-match mime::parameter-regexp str)
- (let ((e (match-end 2)))
- (cons
- (cons (downcase (substring str (match-beginning 1) (match-end 1)))
- (std11-strip-quoted-string
- (substring str (match-beginning 2) e))
- )
- (substring str e)
- ))))
;;; @ Content-Type
;;;
;;;###autoload
(defun mime-parse-Content-Type (string)
- "Parse STRING as field-body of Content-Type field.
- Return value is
- (PRIMARY-TYPE SUBTYPE (NAME1 . VALUE1)(NAME2 . VALUE2) ...)
- or nil. PRIMARY-TYPE and SUBTYPE are symbol and NAME_n and VALUE_n
- are string."
(setq string (std11-unfold-string string))
(if (string-match `,(concat "^\\(" mime-token-regexp
"\\)/\\(" mime-token-regexp "\\)") string)
--- 78,147 ----
std11-quoted-string-regexp
"\\|[^; \t\n]*\\)"))
+ (defconst mime::attribute-char-regexp "[^][*'%()<>@,;:\\\"/?=\000- ]")
+ (defconst mime::attribute-regexp (concat mime::attribute-char-regexp "+"))
+
+ (defconst mime::ext-octet-regexp "%[0-9a-f][0-9a-f]")
+ (defconst mime::extended-other-values-regexp
+ (concat "\\(" mime::attribute-char-regexp "\\|"
+ mime::ext-octet-regexp "\\)+"))
+ (defconst mime::extended-initial-value-regexp
+ (concat "\\(" mime-charset-regexp "\\)'\\(" mime-charset-regexp "\\)'\\("
+ mime::extended-other-values-regexp "\\)"))
+
(defconst mime::parameter-regexp
! (concat "[ \t]*\;[ \t]*\\(" mime::attribute-regexp "\\)"
! "\\(\\*\\([0-9]+\\)\\)?\\(\\*\\)?"
"[ \t]*=[ \t]*\\(" mime/content-parameter-value-regexp "\\)"))
+ (defun mime-parse-parameters (str)
+ (with-temp-buffer
+ (let (rest)
+ (insert str)
+ (goto-char (point-min))
+ (while (looking-at mime::parameter-regexp)
+ (let* ((name (buffer-substring (match-beginning 1) (match-end 1)))
+ (no (or (and (match-beginning 3)
+ (string-to-int
+ (buffer-substring (match-beginning 3)
+ (match-end 3))))
+ 0))
+ (encoded (and (match-beginning 4) t))
+ (next (match-end 0))
+ (parm (or (assoc name rest)
+ (car (setq rest
+ (cons (make-mime-parameter name) rest))))))
+ (mime-parameter-append-raw-value
+ parm
+ no
+ encoded
+ (if encoded
+ (if (and (eq no 0)
+ (progn
+ (goto-char (match-beginning 5))
+ (looking-at mime::extended-initial-value-regexp)))
+ (progn
+ (mime-parameter-set-charset
+ parm
+ (intern (downcase
+ (buffer-substring (match-beginning 1)
+ (match-end 1)))))
+ (mime-parameter-set-language
+ parm
+ (buffer-substring (match-beginning 2)
+ (match-end 2)))
+ (buffer-substring (match-beginning 3) (match-end 3)))
+ (buffer-substring (match-beginning 5) (match-end 5)))
+ (std11-strip-quoted-string
+ (buffer-substring (match-beginning 5) (match-end 5)))))
+ (goto-char next)))
+ rest)))
;;; @ Content-Type
;;;
;;;###autoload
(defun mime-parse-Content-Type (string)
(setq string (std11-unfold-string string))
(if (string-match `,(concat "^\\(" mime-token-regexp
"\\)/\\(" mime-token-regexp "\\)") string)
***************
*** 113,124 ****
(substring string (match-beginning 2) (match-end 2))))
ret dest)
(setq string (substring string (match-end 0)))
- (while (setq ret (mime-parse-parameter string))
- (setq dest (cons (car ret) dest)
- string (cdr ret))
- )
(make-mime-content-type (intern type)(intern subtype)
! (nreverse dest))
)))
;;;###autoload
--- 151,158 ----
(substring string (match-beginning 2) (match-end 2))))
ret dest)
(setq string (substring string (match-end 0)))
(make-mime-content-type (intern type)(intern subtype)
! (nreverse (mime-parse-parameters string)))
)))
;;;###autoload
***************
*** 149,160 ****
(type (downcase (substring string 0 e)))
ret dest)
(setq string (substring string e))
- (while (setq ret (mime-parse-parameter string))
- (setq dest (cons (car ret) dest)
- string (cdr ret))
- )
(cons (cons 'type (intern type))
! (nreverse dest))
)))
;;;###autoload
--- 183,190 ----
(type (downcase (substring string 0 e)))
ret dest)
(setq string (substring string e))
(cons (cons 'type (intern type))
! (nreverse (mime-parse-parameters string)))
)))
;;;###autoload
More information about the Emacs-mime-ja
mailing list