add iso-8859-14 also
[elisp/semi.git] / mime-play.el
index a3bf086..a96934e 100644 (file)
@@ -346,6 +346,24 @@ It is registered to variable `mime-preview-quitting-method-alist'."
 ;;; @ message/partial
 ;;;
 
+(defun mime-require-safe-directory (dir)
+  "Create a directory DIR safely.
+The permission of the created directory becomes `700' (for the owner only).
+If the directory already exists and is writable by other users, an error
+occurs."
+  (let ((attr (file-attributes dir))
+       (orig-modes (default-file-modes)))
+    (if (and attr (eq (car attr) t)) ; directory already exists.
+       (unless (or (memq system-type '(windows-nt ms-dos OS/2 emx))
+                   (and (eq (nth 2 attr) (user-real-uid))
+                        (eq (file-modes dir) 448)))
+         (error "Invalid owner or permission for %s" dir))
+      (unwind-protect
+         (progn
+           (set-default-file-modes 448)
+           (make-directory dir))
+       (set-default-file-modes orig-modes)))))
+
 (defun mime-store-message/partial-piece (entity cal)
   (let* ((root-dir
          (expand-file-name
@@ -355,7 +373,8 @@ It is registered to variable `mime-preview-quitting-method-alist'."
         (total (cdr (assoc "total" cal)))
         file
         (mother (current-buffer))
-        orig-modes (default-file-modes))
+        (orig-modes (default-file-modes)))
+    (mime-require-safe-directory root-dir)
     (or (file-exists-p root-dir)
        (unwind-protect
            (progn