X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mailcap.el;h=76b3812934ee5c2416eb946129e6e1a1cfa5a840;hb=0ebff22ece95b526c9a783557828a05d3c954681;hp=416b9771865cbb3dfd991e759434d375b81d1f1a;hpb=95d4aba4224d3360bffa09b7379b69d46ecbe227;p=elisp%2Fflim.git diff --git a/mailcap.el b/mailcap.el index 416b977..76b3812 100644 --- a/mailcap.el +++ b/mailcap.el @@ -25,6 +25,9 @@ ;;; Code: +(require 'mime-def) + + ;;; @ comment ;;; @@ -182,6 +185,78 @@ order. Otherwise result is not sorted." (mailcap-parse-buffer (current-buffer) order) )) +(defun mailcap-format-command (mtext situation) + "Return formated command string from MTEXT and SITUATION. + +MTEXT is a command text of mailcap specification, such as +view-command. + +SITUATION is an association-list about information of entity. Its key +may be: + + 'type primary media-type + 'subtype media-subtype + 'filename filename + STRING parameter of Content-Type field" + (let ((i 0) + (len (length mtext)) + (p 0) + dest) + (while (< i len) + (let ((chr (aref mtext i))) + (cond ((eq chr ?%) + (setq i (1+ i) + chr (aref mtext i)) + (cond ((eq chr ?s) + (let ((file (cdr (assq 'filename situation)))) + (if (null file) + (error "'filename is not specified in situation.") + (setq dest (concat dest + (substring mtext p (1- i)) + file) + i (1+ i) + p i) + ))) + ((eq chr ?t) + (let ((type (or (mime-type/subtype-string + (cdr (assq 'type situation)) + (cdr (assq 'subtype situation))) + "text/plain"))) + (setq dest (concat dest + (substring mtext p (1- i)) + type) + i (1+ i) + p i) + )) + ((eq chr ?\{) + (setq i (1+ i)) + (if (not (string-match "}" mtext i)) + (error "parse error!!!") + (let* ((me (match-end 0)) + (attribute (substring mtext i (1- me))) + (parameter (cdr (assoc attribute situation)))) + (if (null parameter) + (error "\"%s\" is not specified in situation." + attribute) + (setq dest (concat dest + (substring mtext p (- i 2)) + parameter) + i me + p i) + ) + ))) + (t (error "Invalid sequence `%%%c'." chr)) + )) + ((eq chr ?\\) + (setq dest (concat dest (substring mtext p i)) + p (1+ i) + i (+ i 2)) + ) + (t (setq i (1+ i))) + ))) + (concat dest (substring mtext p)) + )) + ;;; @ end ;;;