* wl-template.el (wl-template-select): Reset draft config exec
[elisp/wanderlust.git] / elmo / elmo-file.el
index af09c0c..572528a 100644 (file)
@@ -28,6 +28,8 @@
 
 ;;; Code:
 ;;
+(eval-when-compile (require 'cl))
+
 (require 'elmo)
 (require 'elmo-map)
 (require 'mime-edit)
@@ -40,7 +42,7 @@
        (setq file (car files)
              files nil))
       (setq files (cdr files)))
-    file))
+    (and file (expand-file-name file))))
 
 (defcustom elmo-file-command (exec-installed-p "file")
   "*Program name of the file type detection command `file'."
@@ -51,7 +53,7 @@
   (let ((magic-file (elmo-file-find
                     '("/usr/share/magic.mime"
                       "/usr/share/file/magic.mime"
-                      "c:/cygwin/usr/share/file/magic.mime"))))
+                      "/cygwin/usr/share/file/magic.mime"))))
     (if magic-file (list "-m" magic-file)))
   "*Argument list for the `file' command.
 \(It should return the MIME content type\)"
@@ -64,7 +66,8 @@
   :group 'elmo)
 
 (eval-and-compile
-  (luna-define-class elmo-file-folder (elmo-map-folder) (file-path))
+  (luna-define-class elmo-file-folder (elmo-map-folder elmo-file-tag)
+                    (file-path))
   (luna-define-internal-accessors 'elmo-file-folder))
 
 (luna-define-method elmo-folder-initialize ((folder
@@ -86,7 +89,7 @@
     (concat (elmo-match-string 1 s) ", "
            (timezone-make-date-arpa-standard s (current-time-zone)))))
 
-(defun elmo-file-detect-format (file)
+(defun elmo-file-detect-content-type (file)
   "Return content-type of the FILE."
   (if (or (not (file-exists-p file))
          (file-directory-p file))
       (setq type (mime-find-file-type file))
       (if (and (string= (nth 0 type) "application")
               (string= (nth 1 type) "octet-stream"))
-         (if elmo-file-command
+         (if (and elmo-file-command
+                  elmo-file-command-argument)
              (with-temp-buffer
-               (when
-                   (zerop (apply 'call-process elmo-file-command
+               (if (zerop (apply 'call-process elmo-file-command
                                  nil `(,(current-buffer) nil)
                                  nil (append elmo-file-command-argument
                                              (list (expand-file-name file)))))
-                 (goto-char (point-min))
-                 (when (re-search-forward ": *" nil t)
-                   (setq type (buffer-substring (match-end 0)
-                                                (point-at-eol))))
-                 (cond
-                  ((string= "empty" type)
-                   "application/octet-stream")
-                  ((string-match "text" type)
-                   "text/plain")
-                  (t
-                   (car (split-string type))))))
+                   (progn
+                     (goto-char (point-min))
+                     (when (re-search-forward ": *" nil t)
+                       (setq type (buffer-substring (match-end 0)
+                                                    (point-at-eol))))
+                     (cond
+                      ((string= "empty" type)
+                       "application/octet-stream")
+                      ((string-match "text" type)
+                       "text/plain")
+                      (t
+                       (car (split-string type)))))
+                 "application/octet-stream"))
            (concat (nth 0 type) "/" (nth 1 type)))
        (concat (nth 0 type) "/" (nth 1 type))))))
 
 (luna-define-method elmo-folder-msgdb-create ((folder elmo-file-folder)
                                              numlist flag-table)
   (let ((new-msgdb (elmo-make-msgdb))
-       entity mark i percent num)
-    (setq num (length numlist))
-    (setq i 0)
-    (message "Creating msgdb...")
-    (while numlist
-      (setq entity
-           (elmo-file-msgdb-create-entity new-msgdb folder (car numlist)))
-      (when entity
-       (elmo-msgdb-append-entity new-msgdb entity '(new unread)))
-      (when (> num elmo-display-progress-threshold)
-       (setq i (1+ i))
-       (setq percent (/ (* i 100) num))
-       (elmo-display-progress
-        'elmo-folder-msgdb-create "Creating msgdb..."
-        percent))
-      (setq numlist (cdr numlist)))
-    (message "Creating msgdb...done")
+       entity)
+    (elmo-with-progress-display (elmo-folder-msgdb-create (length numlist))
+       "Creating msgdb"
+      (dolist (number numlist)
+       (setq entity (elmo-file-msgdb-create-entity new-msgdb folder number))
+       (when entity
+         (elmo-msgdb-append-entity new-msgdb entity '(new unread)))
+       (elmo-progress-notify 'elmo-folder-msgdb-create)))
     new-msgdb))
 
 (luna-define-method elmo-folder-message-file-p ((folder elmo-file-folder))
                                                         &optional
                                                         start-number)
   (let ((temp-dir (elmo-folder-make-temporary-directory folder))
-       (cur-number (if start-number 0)))
+       (cur-number (or start-number 0)))
     (dolist (number numbers)
       (elmo-copy-file
        (elmo-message-file-name folder number)
        (expand-file-name
-       (int-to-string (if start-number (incf cur-number) number))
-       temp-dir)))
+       (number-to-string (if start-number cur-number number))
+       temp-dir))
+      (incf cur-number))
     temp-dir))
 
 (luna-define-method elmo-map-message-fetch ((folder elmo-file-folder)
        (unless (or (std11-field-body "To")
                    (std11-field-body "Cc")
                    (std11-field-body "Subject"))
-         (setq guess (elmo-file-detect-format file))
+         (setq guess (elmo-file-detect-content-type file))
          (setq is-text (string-match "^text/" guess))
          (when is-text
            (set-buffer-multibyte t)