X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=elmo%2Felmo-file.el;h=572528a934e4d347fa47c7ceb301f2c6d3f153b2;hb=refs%2Fheads%2Fmaster;hp=3a5acada58e2260b09f25781e141ade5cb7c768f;hpb=7f6e08e4f77e07def1bf4b57e7676da25b727b05;p=elisp%2Fwanderlust.git diff --git a/elmo/elmo-file.el b/elmo/elmo-file.el index 3a5acad..572528a 100644 --- a/elmo/elmo-file.el +++ b/elmo/elmo-file.el @@ -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'." @@ -48,11 +50,11 @@ :group 'elmo) (defcustom elmo-file-command-argument - `("-m" - ,(elmo-file-find - '("/usr/share/magic.mime" - "/usr/share/file/magic.mime" - "/cygwin/usr/share/file/magic.mime"))) + (let ((magic-file (elmo-file-find + '("/usr/share/magic.mime" + "/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\)" :type '(repeat string) @@ -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)) @@ -95,24 +98,26 @@ (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)))))) @@ -138,23 +143,14 @@ (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)) @@ -180,13 +176,14 @@ &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) @@ -202,7 +199,7 @@ (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)