* elmo-util.el (elmo-file-field-primitive-condition-match):
[elisp/wanderlust.git] / elmo / elmo-cache.el
index 604bcb6..993b7d7 100644 (file)
@@ -1,10 +1,10 @@
 ;;; elmo-cache.el -- Cache modules for Elmo.
 
-;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
-;; Copyright 2000 Kenichi OKADA <okada@opaopa.org>
+;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 2000 Kenichi OKADA <okada@opaopa.org>
 
 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
-;;         Kenichi OKADA <okada@opaopa.org>
+;;     Kenichi OKADA <okada@opaopa.org>
 ;; Keywords: mail, net news
 
 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
@@ -51,7 +51,7 @@
             (setq message-id
                   (elmo-cache-to-msgid (file-name-nondirectory path))))
            (member message-id locked))
-       nil ;; Don't delete caches with mark (or locked message).
+       nil;; Don't delete caches with mark (or locked message).
       (if (and path
               (file-directory-p path))
          (progn
@@ -81,7 +81,7 @@
                    (delete-directory path1))))))))
 
 (defun elmo-cache-read (msgid &optional folder number outbuf)
-  "Read cache contents to outbuf"
+  "Read cache contents to OUTBUF."
   (save-excursion
     (let ((path (elmo-cache-exists-p msgid folder number)))
       (when path
@@ -133,7 +133,7 @@ If KBYTES is kilo bytes (This value must be float)."
                    (expand-file-name
                     elmo-cache-dirname elmo-msgdb-dir)) Kbytes))
     (setq beginning total)
-    (message "Checking disk usage...done.")
+    (message "Checking disk usage...done")
     (let ((cfl (elmo-cache-get-sorted-cache-file-list))
          (deleted 0)
          oldest
@@ -141,11 +141,7 @@ If KBYTES is kilo bytes (This value must be float)."
       (while (and (<= size total)
                  (setq oldest (elmo-cache-get-oldest-cache-file-entity cfl)))
        (setq cur-file (expand-file-name (car (cdr oldest)) (car oldest)))
-       (if (file-directory-p cur-file)
-           (setq cur-size (elmo-disk-usage cur-file))
-         (setq cur-size
-               (/ (float (nth 7 (file-attributes cur-file)))
-                  Kbytes)))
+       (setq cur-size (/ (elmo-disk-usage cur-file) Kbytes))
        (when (elmo-cache-force-delete cur-file locked)
          (setq count (+ count 1))
          (message "%d cache(s) are expired." count))
@@ -166,7 +162,7 @@ If KBYTES is kilo bytes (This value must be float)."
                                   (cons (car (car cfl))
                                         (car flist)))))
       (setq cfl (cdr cfl)))
-;    (prin1 firsts)
+;;; (prin1 firsts)
     (while firsts
       (if (and (not oldest-entity)
               (cdr (cdr (car firsts))))
@@ -208,7 +204,7 @@ If KBYTES is kilo bytes (This value must be float)."
         'elmo-cache-get-sorted-cache-file-list "Collecting cache info..."
         (/ (* i 100) num)))
       (setq dirs (cdr dirs)))
-    (message "Collecting cache info...done.")
+    (message "Collecting cache info...done")
     ret-val))
 
 (defun elmo-cache-expire-by-age (&optional days)
@@ -243,22 +239,22 @@ If KBYTES is kilo bytes (This value must be float)."
       (setq dirs (cdr dirs)))))
 
 (defun elmo-cache-save (msgid partial folder number &optional inbuf)
-  "If partial is non-nil, save current buffer (or INBUF) as partial cache."
+  "If PARTIAL is non-nil, save current buffer (or INBUF) as partial cache."
   (condition-case nil
-  (save-excursion
-    (let* ((path (if partial
-                    (elmo-cache-get-path msgid folder number)
-                  (elmo-cache-get-path msgid)))
-          dir tmp-buf)
-      (when path
-       (setq dir (directory-file-name (file-name-directory path)))
-       (if (not (file-exists-p dir))
-           (elmo-make-directory dir))
-       (if inbuf (set-buffer inbuf))
-       (goto-char (point-min))
-       (as-binary-output-file (write-region (point-min) (point-max)
-                                            path nil 'no-msg)))))
-  (error)))
+      (save-excursion
+       (let* ((path (if partial
+                        (elmo-cache-get-path msgid folder number)
+                      (elmo-cache-get-path msgid)))
+              dir tmp-buf)
+         (when path
+           (setq dir (directory-file-name (file-name-directory path)))
+           (if (not (file-exists-p dir))
+               (elmo-make-directory dir))
+           (if inbuf (set-buffer inbuf))
+           (goto-char (point-min))
+           (as-binary-output-file (write-region (point-min) (point-max)
+                                                path nil 'no-msg)))))
+    (error)))
 
 (defun elmo-cache-exists-p (msgid &optional folder number)
   "Returns the path if the cache exists."
@@ -311,7 +307,7 @@ If KBYTES is kilo bytes (This value must be float)."
     ret-val))
 
 (defun elmo-cache-collect-sub-directories (init dir &optional recursively)
-  "Collect subdirectories under 'dir'"
+  "Collect subdirectories under DIR."
   (let ((dirs
         (delete (expand-file-name elmo-cache-dirname
                                   elmo-msgdb-dir)
@@ -362,13 +358,13 @@ If KBYTES is kilo bytes (This value must be float)."
   
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; buffer cache module
+;; buffer cache module
 
 (defconst elmo-buffer-cache-name " *elmo cache*")
 
 (defvar elmo-buffer-cache nil
-  "Message cache. (old ... new) order alist with association
- ((\"folder\" message \"message-id\") . cache-buffer)")
+  "Message cache.  (old ... new) order alist.
+With association ((\"folder\" message \"message-id\") . cache-buffer).")
 
 (defmacro elmo-buffer-cache-buffer-get (entry)
   (` (cdr (, entry))))
@@ -398,7 +394,7 @@ If KBYTES is kilo bytes (This value must be float)."
     (setq elmo-buffer-cache (cdr top))))
 
 (defun elmo-buffer-cache-add (fld-msg-id)
-  "Adding (fld-msg-id . buf) to the top of \"elmo-buffer-cache\".
+  "Adding (FLD-MSG-ID . buf) to the top of `elmo-buffer-cache'.
 Returning its cache buffer."
   (let ((len (length elmo-buffer-cache))
        (buf nil))
@@ -431,9 +427,9 @@ Returning its cache buffer."
       (setq n (1+ n))))
   (setq elmo-buffer-cache nil))
 
-;;;
-;;; cache backend by Kenichi OKADA <okada@opaopa.org>
-;;;
+;;
+;; cache backend by Kenichi OKADA <okada@opaopa.org>
+;;
 
 (defsubst elmo-cache-get-folder-directory (spec)
   (if (file-name-absolute-p (nth 1 spec))
@@ -461,7 +457,7 @@ Returning its cache buffer."
   (defsubst elmo-cache-insert-header (file)
     "Insert the header of the article."
     (let ((beg 0)
-         insert-file-contents-pre-hook   ; To avoid autoconv-xmas...
+         insert-file-contents-pre-hook ; To avoid autoconv-xmas...
          insert-file-contents-post-hook
          format-alist)
       (when (file-exists-p file)
@@ -547,7 +543,7 @@ Returning its cache buffer."
           'elmo-cache-msgdb-create-as-numlist "Creating msgdb..."
           percent))
        (setq numlist (cdr numlist)))
-      (message "Creating msgdb...done.")
+      (message "Creating msgdb...done")
       (list overview number-alist mark-alist))))
 
 (defalias 'elmo-cache-msgdb-create 'elmo-cache-msgdb-create-as-numlist)
@@ -566,7 +562,7 @@ Returning its cache buffer."
                (expand-file-name
                 (nth 1 (elmo-folder-get-spec folder))
                 (expand-file-name elmo-cache-dirname elmo-msgdb-dir)))
-         (if (string-match "^[+=$!]$" folder) ;; localdir, archive, localnews
+         (if (string-match "^[+=$!]$" folder) ; localdir, archive, localnews
              (setq subprefix folder)
            (setq subprefix (concat folder elmo-path-sep)))
            ;; include parent
@@ -642,7 +638,7 @@ Returning its cache buffer."
     ;; return nil if failed.
     (elmo-cache-force-delete file locked)))
 
-(defun elmo-cache-read-msg (spec number outbuf &optional set-mark)
+(defun elmo-cache-read-msg (spec number outbuf &optional msgdb unread)
   (save-excursion
     (let* ((dir (elmo-cache-get-folder-directory spec))
           (file (expand-file-name
@@ -659,7 +655,7 @@ Returning its cache buffer."
               (mapcar '(lambda (msg) (elmo-cache-delete-msg spec msg locked))
                       msgs)))))
 
-(defun elmo-cache-list-folder (spec); called by elmo-cache-search()
+(defun elmo-cache-list-folder (spec)   ; called by elmo-cache-search()
   (let ((killed (and elmo-use-killed-list
                     (elmo-msgdb-killed-list-load
                      (elmo-msgdb-expand-path spec))))
@@ -726,7 +722,7 @@ Returning its cache buffer."
        (expand-file-name
        (elmo-msgid-to-cache
         (cdr (assq (if same-number (car msgs) next-num) number-alist)))
-        dst-dir))
+       dst-dir))
       (if (and (setq msgs (cdr msgs))
               (not same-number))
          (setq next-num (1+ next-num))))