* wl-vars.el: Changed file coding system to ISO-2022-JP.
[elisp/wanderlust.git] / elmo / elmo-internal.el
index 2f7a27f..1c5b66b 100644 (file)
@@ -1,6 +1,6 @@
 ;;; elmo-internal.el -- Internal Interface for ELMO.
 
-;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
 
 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
 ;; Keywords: mail, net news
         (arg (nth 2 spec))
         (flist (elmo-list-folder-by-location
                 spec
-                (elmo-internal-list-location directive arg))))
+                (elmo-internal-list-location directive arg)))
+        (killed (and elmo-use-killed-list
+                     (elmo-msgdb-killed-list-load
+                      (elmo-msgdb-expand-path spec))))
+        numbers)
     (if nonsort
        (cons (or (elmo-max-of-list flist) 0)
-             (length flist))
-      (sort flist '<))))
+             (if killed
+                 (- (length flist)
+                    (elmo-msgdb-killed-list-length killed))
+               (length flist)))
+      (setq numbers (sort flist '<))
+      (elmo-living-messages numbers killed))))
 
-(defun elmo-internal-list-folder (spec)
+(defun elmo-internal-list-folder (spec &optional nohide)
   (elmo-internal-list-folder-subr spec))
 
 (defun elmo-internal-list-folder-by-location (spec location &optional msgdb)
-  (let* ((path (elmo-msgdb-expand-path nil spec))
-        (location-alist 
+  (let* ((path (elmo-msgdb-expand-path spec))
+        (location-alist
          (if msgdb
              (elmo-msgdb-get-location msgdb)
            (elmo-msgdb-location-load path)))
@@ -63,7 +71,7 @@
                          (list (cons (car pair) (car location)))))
          (setq i (1+ i))
          (setq result (append result
-                              (list 
+                              (list
                                (cons (+ location-max i) (car location))))))
        (setq location (cdr location))))
     (setq result (sort result '(lambda (x y)
     (mapcar 'car result)))
 
 (defun elmo-internal-list-location (directive arg)
-  (let ((mark-alist 
+  (let ((mark-alist
         (or elmo-msgdb-global-mark-alist
             (setq elmo-msgdb-global-mark-alist
-                  (elmo-object-load (expand-file-name 
+                  (elmo-object-load (expand-file-name
                                      elmo-msgdb-global-mark-filename
                                      elmo-msgdb-dir)))))
        result)
    number
    (elmo-cache-get-path (cdr (assq number loc-alist)))))
 
-(defun elmo-internal-msgdb-create (spec numlist new-mark 
-                                      already-mark seen-mark 
-                                      important-mark 
+(defun elmo-internal-msgdb-create (spec numlist new-mark
+                                      already-mark seen-mark
+                                      important-mark
                                       seen-list
                                       &optional msgdb)
   (when numlist
     (let* ((directive (nth 1 spec))
           (arg       (nth 2 spec))
           (loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
-                       (elmo-msgdb-location-load (elmo-msgdb-expand-path 
-                                                  nil spec))))
+                       (elmo-msgdb-location-load (elmo-msgdb-expand-path
+                                                  spec))))
           (loc-list (elmo-internal-list-location directive arg))
           overview number-alist mark-alist entity
           i percent num location pair)
               (car numlist) loc-alist))
        (if (null entity)
            ()
-         (setq overview 
+         (setq overview
                (elmo-msgdb-append-element
                 overview entity))
          (setq number-alist
          (unless (memq location seen-list)
            (setq mark-alist
                  (elmo-msgdb-mark-append
-                  mark-alist 
+                  mark-alist
                   (elmo-msgdb-overview-entity-get-number
                    entity)
-                                       ;(nth 0 entity)
-                  (or (elmo-msgdb-global-mark-get 
+;;;               (nth 0 entity)
+                  (or (elmo-msgdb-global-mark-get
                        (elmo-msgdb-overview-entity-get-id
                         entity))
-                      (if (elmo-cache-exists-p 
+                      (if (elmo-cache-exists-p
                            (elmo-msgdb-overview-entity-get-id
                             entity))
                           already-mark
                         new-mark))))))
-       (setq i (1+ i))
-       (setq percent (/ (* i 100) num))
-       (elmo-display-progress
-        'elmo-internal-msgdb-create "Creating msgdb..."
-        percent)
+       (when (> num elmo-display-progress-threshold)
+         (setq i (1+ i))
+         (setq percent (/ (* i 100) num))
+         (elmo-display-progress
+          'elmo-internal-msgdb-create "Creating msgdb..."
+          percent))
        (setq numlist (cdr numlist)))
-      (message "Creating msgdb...done.")
+      (message "Creating msgdb...done")
       (list overview number-alist mark-alist loc-alist))))
 
 (defalias 'elmo-internal-msgdb-create-as-numlist 'elmo-internal-msgdb-create)
    (let* ((msgid (elmo-field-body "message-id"))
          (path (elmo-cache-get-path msgid))
          dir)
-     (when path 
+     (when path
        (setq dir (directory-file-name (file-name-directory path)))
        (if (not (file-exists-p dir))
           (elmo-make-directory dir))
 
 (defun elmo-internal-delete-msgs (spec msgs &optional msgdb)
   (let ((loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
-                    (elmo-msgdb-location-load (elmo-msgdb-expand-path 
-                                               nil spec)))))
+                    (elmo-msgdb-location-load (elmo-msgdb-expand-path
+                                               spec)))))
     (mapcar '(lambda (msg) (elmo-internal-delete-msg spec msg
                                                     loc-alist))
            msgs)))
   (let ((pair (assq number loc-alist)))
     (elmo-msgdb-global-mark-delete (cdr pair))))
 
-(defun elmo-internal-read-msg (spec number outbuf &optional msgdb)
+(defun elmo-internal-read-msg (spec number outbuf &optional msgdb unread)
   (save-excursion
     (let* ((loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
-                       (elmo-msgdb-location-load (elmo-msgdb-expand-path 
-                                                  nil spec))))
+                       (elmo-msgdb-location-load (elmo-msgdb-expand-path
+                                                  spec))))
           (file (elmo-cache-get-path (cdr (assq number loc-alist)))))
       (set-buffer outbuf)
       (erase-buffer)
   nil)
 
 (defun elmo-internal-search (spec condition &optional from-msgs msgdb)
-  (let* ((mark-alist 
-        (or elmo-msgdb-global-mark-alist
-            (setq elmo-msgdb-global-mark-alist
-                  (elmo-object-load (expand-file-name 
-                                     elmo-msgdb-global-mark-filename
-                                     elmo-msgdb-dir)))))
+  (let* ((msgs (or from-msgs (elmo-internal-list-folder spec)))
         (loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
-                     (elmo-msgdb-location-load (elmo-msgdb-expand-path 
-                                                nil spec))))    
+                     (elmo-msgdb-location-load (elmo-msgdb-expand-path
+                                                spec))))
+        (number-list (mapcar 'car loc-alist))
+        (i 0)
+        (num (length msgs))
         cache-file
-        ret-val
-        case-fold-search msg
-        percent i num)
-    (setq num (length loc-alist))
-    (setq i 0)
-    (while loc-alist
-      (if (and (setq cache-file (elmo-cache-exists-p (cdr (car loc-alist))))
+        matched
+        case-fold-search)
+    (setq num (length msgs))
+    (while msgs
+      (if (and (setq cache-file (elmo-cache-get-path (cdr (assq (car msgs)
+                                                               loc-alist))))
+              (file-exists-p cache-file)
               (elmo-file-field-condition-match cache-file
-                                               condition))
-         (setq ret-val (append ret-val (list (car (car loc-alist))))))
-      (setq i (1+ i))
-      (setq percent (/ (* i 100) num))
+                                               condition
+                                               (car msgs)
+                                               number-list))
+         (setq matched (nconc matched (list (car msgs)))))
       (elmo-display-progress
        'elmo-internal-search "Searching..."
-       percent)
-      (setq loc-alist (cdr loc-alist)))
-    ret-val))
+       (/ (* (setq i (1+ i)) 100) num))
+      (setq msgs (cdr msgs)))
+    matched))
 
 (defun elmo-internal-use-cache-p (spec number)
   nil)
   )
 
 (defalias 'elmo-internal-sync-number-alist 'elmo-generic-sync-number-alist)
-(defalias 'elmo-internal-list-folder-unread 
+(defalias 'elmo-internal-list-folder-unread
   'elmo-generic-list-folder-unread)
 (defalias 'elmo-internal-list-folder-important
   'elmo-generic-list-folder-important)
 (defalias 'elmo-internal-commit 'elmo-generic-commit)
+(defalias 'elmo-internal-folder-diff 'elmo-generic-folder-diff)
 
-(provide 'elmo-internal)
+(require 'product)
+(product-provide (provide 'elmo-internal) (require 'elmo-version))
 
 ;;; elmo-internal.el ends here