X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mailcap.el;h=12eee8837929ea0a09ada7a39e4dd3fc9cda2e43;hb=5aad1166a5731dc848a68cbb380bbcba6a23d063;hp=416b9771865cbb3dfd991e759434d375b81d1f1a;hpb=c976e21ec61da093ebac37b796fb8600b6400de5;p=elisp%2Fflim.git diff --git a/mailcap.el b/mailcap.el index 416b977..12eee88 100644 --- a/mailcap.el +++ b/mailcap.el @@ -25,6 +25,9 @@ ;;; Code: +(require 'mime-def) + + ;;; @ comment ;;; @@ -167,8 +170,11 @@ order. Otherwise result is not sorted." (t entries) )))) -(defvar mailcap-file "~/.mailcap" - "*File name of user's mailcap file.") + +(defcustom mailcap-file "~/.mailcap" + "*File name of user's mailcap file." + :group 'mime + :type 'file) (defun mailcap-parse-file (&optional filename order) "Parse FILENAME as a mailcap, and return the result. @@ -182,6 +188,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 ;;;