X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mailcap.el;h=12eee8837929ea0a09ada7a39e4dd3fc9cda2e43;hb=e3747e8f4ecbf39d106d117fb494506089cc5c2a;hp=a27be3e1495b233fa7caea8b5980c660a9bc50b5;hpb=b21ceabe456aede7895ec414a5c93d6e6ab7d10c;p=elisp%2Fflim.git diff --git a/mailcap.el b/mailcap.el index a27be3e..12eee88 100644 --- a/mailcap.el +++ b/mailcap.el @@ -25,6 +25,9 @@ ;;; Code: +(require 'mime-def) + + ;;; @ comment ;;; @@ -99,19 +102,10 @@ ))) (defsubst mailcap-look-at-mtext () - (let ((p0 (point)) - dest) - (while (cond ((mailcap-look-at-qchar) - (setq dest - (concat dest - (buffer-substring p0 (- (point) 2)) - (char-to-string (char-before (point))) - ) - p0 (point)) - ) - ((mailcap-look-at-schar) - t))) - (concat dest (buffer-substring p0 (point))) + (let ((beg (point))) + (while (or (mailcap-look-at-qchar) + (mailcap-look-at-schar))) + (buffer-substring beg (point)) )) @@ -176,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. @@ -191,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 ;;;