-(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)
- )))
+(defun mime-save-content (entity situation)
+ (let ((name (or (mime-entity-safe-filename entity)
+ (format "%s" (mime-entity-media-type entity))))
+ (dir (if (eq t mime-save-directory)
+ default-directory
+ mime-save-directory))
+ filename)
+ (setq filename (read-file-name
+ (concat "File name: (default "
+ (file-name-nondirectory name) ") ")
+ dir
+ (concat (file-name-as-directory dir)
+ (file-name-nondirectory name))))
+ (if (file-directory-p filename)
+ (setq filename (concat (file-name-as-directory filename)
+ (file-name-nondirectory name))))
+ (if (file-exists-p filename)
+ (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
+ (error "")))
+ (mime-write-entity-content entity (expand-file-name filename))
+ ))
+
+
+;;; @ file detection
+;;;
+
+(defvar mime-magic-type-alist
+ '(("^\377\330\377[\340\356]..JFIF" image jpeg)
+ ("^\211PNG" image png)
+ ("^GIF8[79]" image gif)
+ ("^II\\*\000" image tiff)
+ ("^MM\000\\*" image tiff)
+ ("^MThd" audio midi)
+ ("^\000\000\001\263" video mpeg)
+ )
+ "*Alist of regexp about magic-number vs. corresponding media-types.
+Each element looks like (REGEXP TYPE SUBTYPE).
+REGEXP is a regular expression to match against the beginning of the
+content of entity.
+TYPE is symbol to indicate primary type of media-type.
+SUBTYPE is symbol to indicate subtype of media-type.")
+
+(defun mime-detect-content (entity situation)
+ (let (type subtype)
+ (let ((mdata (mime-entity-content entity))
+ (rest mime-magic-type-alist))
+ (while (not (let ((cell (car rest)))
+ (if cell
+ (if (string-match (car cell) mdata)
+ (setq type (nth 1 cell)
+ subtype (nth 2 cell))
+ )
+ t)))
+ (setq rest (cdr rest))))
+ (setq situation (del-alist 'method (copy-alist situation)))
+ (mime-play-entity entity
+ (if type
+ (put-alist 'type type
+ (put-alist 'subtype subtype
+ situation))
+ situation)
+ 'mime-detect-content)))