-(defun mime-method-to-save (beg end cal)
- (goto-char beg)
- (let* ((name
- (save-restriction
- (narrow-to-region beg end)
- (mime-raw-get-filename cal)
- ))
- (encoding (cdr (assq 'encoding cal)))
- (filename
- (if (and name (not (string-equal name "")))
- (expand-file-name name
- (call-interactively
- (function
- (lambda (dir)
- (interactive "DDirectory: ")
- dir))))
- (call-interactively
- (function
- (lambda (file)
- (interactive "FFilename: ")
- (expand-file-name file))))))
- )
- (if (file-exists-p filename)
- (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
- (error "")))
- (re-search-forward "\n\n")
- (mime-write-decoded-region (match-end 0)(point-max) filename encoding)
- ))
+(defun mime-method-to-save (entity cal)
+ (let ((beg (mime-entity-point-min entity))
+ (end (mime-entity-point-max entity)))
+ (goto-char beg)
+ (let* ((name (save-restriction
+ (narrow-to-region beg end)
+ (mime-raw-get-filename cal)
+ ))
+ (encoding (or (cdr (assq 'encoding cal)) "7bit"))
+ (filename (if (and name (not (string-equal name "")))
+ (expand-file-name name
+ (save-window-excursion
+ (call-interactively
+ (function
+ (lambda (dir)
+ (interactive "DDirectory: ")
+ dir)))))
+ (save-window-excursion
+ (call-interactively
+ (function
+ (lambda (file)
+ (interactive "FFilename: ")
+ (expand-file-name file)))))))
+ )
+ (if (file-exists-p filename)
+ (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
+ (error "")))
+ (re-search-forward "\n\n")
+ (mime-write-decoded-region (match-end 0) end filename encoding)
+ )))
+
+
+;;; @ file detection
+;;;
+
+(defvar mime-file-content-type-alist
+ '(("JPEG" image jpeg)
+ ("GIF" image gif)
+ )
+ "*Alist of \"file\" output patterns vs. corresponding media-types.
+Each element looks like (REGEXP TYPE SUBTYPE).
+REGEXP is pattern for \"file\" command output.
+TYPE is symbol to indicate primary type of media-type.
+SUBTYPE is symbol to indicate subtype of media-type.")
+
+(defun mime-method-to-detect (entity situation)
+ (let ((beg (mime-entity-point-min entity))
+ (end (mime-entity-point-max entity)))
+ (goto-char beg)
+ (let* ((name (save-restriction
+ (narrow-to-region beg end)
+ (mime-raw-get-filename situation)
+ ))
+ (encoding (or (cdr (assq 'encoding situation)) "7bit"))
+ (filename (if (and name (not (string-equal name "")))
+ (expand-file-name name mime-temp-directory)
+ (make-temp-name
+ (expand-file-name "EMI" mime-temp-directory)))))
+ (mime-write-decoded-region (mime-entity-body-start entity) end
+ filename encoding)
+ (let (type subtype)
+ (with-temp-buffer
+ (call-process "file" nil t nil filename)
+ (goto-char (point-min))
+ (if (search-forward (concat filename ": ") nil t)
+ (let ((rest mime-file-content-type-alist))
+ (while (not (let ((cell (car rest)))
+ (if (looking-at (car cell))
+ (setq type (nth 1 cell)
+ subtype (nth 2 cell))
+ )))
+ (setq rest (cdr rest))))))
+ (if type
+ (mime-raw-play-entity
+ entity "play"
+ (put-alist 'type type
+ (put-alist 'subtype subtype
+ (mime-entity-situation entity))))
+ ))
+ )))