-(defun mime-article/get-original-filename (param &optional encoding)
- (or (mime-article/get-uu-filename param encoding)
- (let (ret)
- (or (if (or (and (setq ret (mime/Content-Disposition))
- (setq ret (assoc "filename" (cdr ret)))
- )
- (setq ret (assoc "name" param))
- (setq ret (assoc "x-name" param))
- )
- (std11-strip-quoted-string (cdr ret))
- )
- (if (setq ret
- (std11-find-field-body '("Content-Description"
- "Subject")))
- (if (or (string-match mime-view-file-name-regexp-1 ret)
- (string-match mime-view-file-name-regexp-2 ret))
- (substring ret (match-beginning 0)(match-end 0))
- ))
- ))
- ))
-
-(defun mime-article/get-filename (param)
- (replace-as-filename (mime-article/get-original-filename param))
- )
+(defun mime-entity-safe-filename (entity)
+ (let ((filename
+ (or (mime-entity-filename entity)
+ (let ((subj
+ (or (mime-entity-read-field entity 'Content-Description)
+ (mime-entity-read-field entity 'Subject))))
+ (if (and subj
+ (or (string-match mime-view-file-name-regexp-1 subj)
+ (string-match mime-view-file-name-regexp-2 subj)))
+ (substring subj (match-beginning 0)(match-end 0))
+ )))))
+ (if filename
+ (replace-as-filename filename)
+ )))
+
+
+;;; @ file extraction
+;;;
+
+(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)))