* elmo.el (elmo-folder-reserve-status-p): New method.
authorteranisi <teranisi>
Wed, 6 Jun 2001 00:41:42 +0000 (00:41 +0000)
committerteranisi <teranisi>
Wed, 6 Jun 2001 00:41:42 +0000 (00:41 +0000)
* elmo-shimbun.el (elmo-shimbun-headers-cache): Abolish.
(elmo-shimbun-use-entire-index): New user option.
(shimbun-elmo-mua): New class.
(shimbun-mua-search-id): Define.
(shimbun-mua-use-entire-index): Ditto.
(elmo-shimbun-folder:last-check): New slot.
(elmo-shimbun-headers-cache-header-list): Abolish.
(elmo-shimbun-headers-cache-set-header-list): Ditto.
(elmo-shimbun-headers-cache-header-hash): Ditto.
(elmo-shimbun-headers-cache-set-header-hash): Ditto.
(elmo-shimbun-headers-cache-last-check): Ditto.
(elmo-shimbun-headers-cache-set-last-check): Ditto.
(elmo-shimbun-headers-check-p): Rewrite.
(elmo-shimbun-msgdb-to-headers): New function.
(elmo-shimbun-get-headers): Rewrite.
(elmo-folder-initialize): Set 1st argument of `shimbun-open'.
(elmo-folder-open-internal): Get headers only if
`elmo-shimbun-headers-check-p' is non-nil.
(elmo-folder-check): Check only if `elmo-shimbun-headers-check-p'
is non-nil.
(elmo-shimbun-msgdb-create-entity): Re-use old msgdb entities.
(elmo-quit): Removed.

* elmo-msgdb.el (elmo-msgdb-overview-entity-get-extra): New inline
function.
(elmo-msgdb-overview-entity-set-extra): Ditto.
(elmo-msgdb-make-overview-hashtb): Make hash if overview is non-nil.

* elmo-map.el (elmo-folder-status): Don't call
elmo-folder-close-internal if `elmo-folder-reserve-status-p'
is non-nil.

elmo/ChangeLog
elmo/elmo-map.el
elmo/elmo-msgdb.el
elmo/elmo-shimbun.el
elmo/elmo.el

index 7b0dfa5..8e79b6d 100644 (file)
@@ -1,3 +1,39 @@
+2001-06-06  Yuuichi Teranishi  <teranisi@gohome.org>
+
+       * elmo.el (elmo-folder-reserve-status-p): New method.
+
+       * elmo-shimbun.el (elmo-shimbun-headers-cache): Abolish.
+       (elmo-shimbun-use-entire-index): New user option.
+       (shimbun-elmo-mua): New class.
+       (shimbun-mua-search-id): Define.
+       (shimbun-mua-use-entire-index): Ditto.
+       (elmo-shimbun-folder:last-check): New slot.
+       (elmo-shimbun-headers-cache-header-list): Abolish.
+       (elmo-shimbun-headers-cache-set-header-list): Ditto.
+       (elmo-shimbun-headers-cache-header-hash): Ditto.
+       (elmo-shimbun-headers-cache-set-header-hash): Ditto.
+       (elmo-shimbun-headers-cache-last-check): Ditto.
+       (elmo-shimbun-headers-cache-set-last-check): Ditto.
+       (elmo-shimbun-headers-check-p): Rewrite.
+       (elmo-shimbun-msgdb-to-headers): New function.
+       (elmo-shimbun-get-headers): Rewrite.
+       (elmo-folder-initialize): Set 1st argument of `shimbun-open'.
+       (elmo-folder-open-internal): Get headers only if
+       `elmo-shimbun-headers-check-p' is non-nil.
+       (elmo-folder-check): Check only if `elmo-shimbun-headers-check-p'
+       is non-nil.
+       (elmo-shimbun-msgdb-create-entity): Re-use old msgdb entities.
+       (elmo-quit): Removed.
+
+       * elmo-msgdb.el (elmo-msgdb-overview-entity-get-extra): New inline
+       function.
+       (elmo-msgdb-overview-entity-set-extra): Ditto.
+       (elmo-msgdb-make-overview-hashtb): Make hash if overview is non-nil.
+
+       * elmo-map.el (elmo-folder-status): Don't call
+       elmo-folder-close-internal if `elmo-folder-reserve-status-p'
+       is non-nil.
+
 2001-06-05  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
 
        * elmo-msgdb.el (elmo-msgdb-search-internal): Call itself instead
index 85d87c0..b3e4612 100644 (file)
                      (elmo-map-folder-location-alist-internal folder))))
        (cons (elmo-max-of-list numbers)
              (length numbers)))
-    ;; No save.
-    (elmo-folder-close-internal folder)))
+    ;; Don't close after status.
+    (unless (elmo-folder-reserve-status-p folder)
+      (elmo-folder-close-internal folder))))
 
 (defun elmo-map-message-number (folder location)
   "Return number of the message in the FOLDER with LOCATION."
index 7c76117..1504237 100644 (file)
@@ -445,6 +445,13 @@ content of MSGDB is changed."
     (and extra
         (cdr (assoc field-name extra)))))
 
+(defsubst elmo-msgdb-overview-entity-get-extra (entity)
+  (and entity (aref (cdr entity) 8)))
+
+(defsubst elmo-msgdb-overview-entity-set-extra (entity extra)
+  (and entity (aset (cdr entity) 8 extra))
+  entity)
+
 (defun elmo-msgdb-overview-get-entity-by-number (database number)
   (when number
     (let ((db database)
@@ -459,7 +466,7 @@ content of MSGDB is changed."
 (defun elmo-msgdb-overview-get-entity (id msgdb)
   (when id
     (let ((ovht (elmo-msgdb-get-overviewht msgdb)))
-      (if ovht ;; use overview hash
+      (if ovht ; use overview hash
          (if (stringp id) ;; ID is message-id
              (elmo-get-hash-val id ovht)
            (elmo-get-hash-val (format "#%d" id) ovht))
@@ -714,7 +721,8 @@ Header region is supposed to be narrowed."
           (elmo-clear-hash-val (car entity) hashtb)))))
 
 (defun elmo-msgdb-make-overview-hashtb (overview &optional hashtb)
-  (if elmo-use-overview-hashtb
+  (if (and elmo-use-overview-hashtb
+          overview)
       (let ((hashtb (or hashtb ;; append
                        (elmo-make-hash (length overview)))))
        (while overview
index 6f7cb47..08e3046 100644 (file)
   :type 'integer
   :group 'elmo)
 
-;; Internal variable.
-;; A list of elements like:
-;; ("server.group" . [header-list header-hash last-check]).
-(defvar elmo-shimbun-headers-cache nil)
-
-(eval-and-compile
-  (luna-define-class elmo-shimbun-folder
-                    (elmo-map-folder) (shimbun headers header-hash group))
-  (luna-define-internal-accessors 'elmo-shimbun-folder))
-
-(defsubst elmo-shimbun-headers-cache-header-list (entry)
-  (aref entry 0))
-
-(defsubst elmo-shimbun-headers-cache-set-header-list (entry list)
-  (aset entry 0 list))
+(defcustom elmo-shimbun-use-entire-index nil
+  "*Nil means that shimbun check only the last index of articles."
+  :type 'boolean
+  :group 'elmo)
 
-(defsubst elmo-shimbun-headers-cache-header-hash (entry)
-  (aref entry 1))
+;; Shimbun mua.
+(eval-and-compile 
+  (luna-define-class shimbun-elmo-mua (shimbun-mua) (folder))
+  (luna-define-internal-accessors 'shimbun-elmo-mua))
 
-(defsubst elmo-shimbun-headers-cache-set-header-hash (entry hash)
-  (aset entry 1 hash))
+(luna-define-method shimbun-mua-search-id ((mua shimbun-elmo-mua) id)
+  (elmo-msgdb-overview-get-entity id 
+                                 (elmo-folder-msgdb
+                                  (shimbun-elmo-mua-folder-internal mua))))
 
-(defsubst elmo-shimbun-headers-cache-last-check (entry)
-  (aref entry 2))
+(luna-define-method shimbun-mua-use-entire-index ((mua shimbun-elmo-mua))
+  elmo-shimbun-use-entire-index)
 
-(defsubst elmo-shimbun-headers-cache-set-last-check (entry time)
-  (aset entry 2 time))
+(eval-and-compile
+  (luna-define-class elmo-shimbun-folder
+                    (elmo-map-folder) (shimbun headers header-hash
+                                               group last-check))
+  (luna-define-internal-accessors 'elmo-shimbun-folder))
 
 (defsubst elmo-shimbun-lapse-seconds (time)
   (let ((now (current-time)))
     (+ (* (- (car now) (car time)) 65536)
        (- (nth 1 now) (nth 1 time)))))
 
-(defsubst elmo-shimbun-headers-cache-check-p (cache)
-  (or (null (elmo-shimbun-headers-cache-last-check cache))
-      (and (elmo-shimbun-headers-cache-last-check cache)
+(defsubst elmo-shimbun-headers-check-p (folder)
+  (or (null (elmo-shimbun-folder-last-check-internal folder))
+      (and (elmo-shimbun-folder-last-check-internal folder)
           (> (elmo-shimbun-lapse-seconds
-              (elmo-shimbun-headers-cache-last-check cache))
+              (elmo-shimbun-folder-last-check-internal folder))
              elmo-shimbun-check-interval))))
 
+(defun elmo-shimbun-msgdb-to-headers (folder)
+  (let (headers)
+    (dolist (ov (elmo-msgdb-get-overview (elmo-folder-msgdb folder)))
+      (when (elmo-msgdb-overview-entity-get-extra-field ov "xref")
+       (setq headers
+             (cons (shimbun-make-header
+                    (elmo-msgdb-overview-entity-get-number ov)
+                    (shimbun-mime-encode-string
+                     (elmo-msgdb-overview-entity-get-subject ov))
+                    (shimbun-mime-encode-string
+                     (elmo-msgdb-overview-entity-get-from ov))
+                    (elmo-msgdb-overview-entity-get-date ov)
+                    (elmo-msgdb-overview-entity-get-id ov)
+                    (elmo-msgdb-overview-entity-get-references ov)
+                    0
+                    0
+                    (elmo-msgdb-overview-entity-get-extra-field ov "xref"))
+                   headers))))
+    (nreverse headers)))
+
 (defun elmo-shimbun-get-headers (folder)
   (shimbun-open-group
    (elmo-shimbun-folder-shimbun-internal folder)
         (key (concat (shimbun-server-internal shimbun)
                      "." (shimbun-current-group-internal shimbun)))
         (elmo-hash-minimum-size 0)
-        entry headers hash done)
-    (if (setq entry (cdr (assoc key elmo-shimbun-headers-cache)))
-       (unless (elmo-shimbun-headers-cache-check-p entry)
-         (elmo-shimbun-folder-set-headers-internal
-          folder
-          (elmo-shimbun-headers-cache-header-list entry))
+        entry headers hash)
+    ;; new headers.
+    (setq headers
+         (delq nil
+               (mapcar
+                (lambda (x)
+                  (unless (elmo-msgdb-overview-get-entity 
+                           (shimbun-header-id x)
+                           (elmo-folder-msgdb folder))
+                    x))
+                (shimbun-headers
+                 (elmo-shimbun-folder-shimbun-internal folder)))))
+    (elmo-shimbun-folder-set-headers-internal
+     folder
+     (nconc (elmo-shimbun-msgdb-to-headers folder)
+           headers))
+    (setq hash
          (elmo-shimbun-folder-set-header-hash-internal
           folder
-          (elmo-shimbun-headers-cache-header-hash entry))
-         (elmo-shimbun-headers-cache-header-list entry)
-         (setq done t)))
-    (unless done
-      (setq headers
-           (elmo-shimbun-folder-set-headers-internal
-            folder (shimbun-headers
-                    (elmo-shimbun-folder-shimbun-internal folder))))
-      (setq hash
-           (elmo-shimbun-folder-set-header-hash-internal
-            folder
-            (elmo-make-hash
-             (length (elmo-shimbun-folder-headers-internal folder)))))
-      ;; Set up header hash.
-      (dolist (header (elmo-shimbun-folder-headers-internal folder))
-       (elmo-set-hash-val
-        (shimbun-header-id header) header
-        (elmo-shimbun-folder-header-hash-internal folder)))
-      (if entry
-         (progn
-           (elmo-shimbun-headers-cache-set-header-list entry headers)
-           (elmo-shimbun-headers-cache-set-header-hash entry hash)
-           (elmo-shimbun-headers-cache-set-last-check entry (current-time)))
-       (setq elmo-shimbun-headers-cache
-             (cons (cons key (vector headers hash (current-time)))
-                   elmo-shimbun-headers-cache))))))
+          (elmo-make-hash
+           (length (elmo-shimbun-folder-headers-internal folder)))))
+    ;; Set up header hash.
+    (dolist (header (elmo-shimbun-folder-headers-internal folder))
+      (elmo-set-hash-val
+       (shimbun-header-id header) header
+       (elmo-shimbun-folder-header-hash-internal folder)))
+    (elmo-shimbun-folder-set-last-check-internal folder (current-time))))
 
 (luna-define-method elmo-folder-initialize ((folder
                                             elmo-shimbun-folder)
     (if (nth 0 server-group) ; server
        (elmo-shimbun-folder-set-shimbun-internal
         folder
-        (shimbun-open (nth 0 server-group))))
+        (shimbun-open (nth 0 server-group)
+                      (luna-make-entity 'shimbun-elmo-mua :folder folder))))
     (if (nth 1 server-group)
        (elmo-shimbun-folder-set-group-internal
         folder
 (luna-define-method elmo-folder-open-internal :before ((folder
                                                        elmo-shimbun-folder))
   (when (elmo-folder-plugged-p folder)
-    (elmo-shimbun-get-headers folder)))
+    (if (elmo-shimbun-headers-check-p folder)
+       (elmo-shimbun-get-headers folder))))
+
+(luna-define-method elmo-folder-reserve-status-p ((folder elmo-shimbun-folder))
+  t)
 
 (luna-define-method elmo-folder-close-internal :after ((folder
                                                        elmo-shimbun-folder))
 (luna-define-method elmo-folder-check :after ((folder elmo-shimbun-folder))
   (when (shimbun-current-group-internal 
         (elmo-shimbun-folder-shimbun-internal folder))
-    ;; Discard current headers information.
-    (elmo-folder-close-internal folder)
-    (elmo-folder-open-internal folder)))
+    (when (elmo-shimbun-headers-check-p folder)    
+      ;; Discard current headers information.
+      (elmo-folder-close-internal folder)
+      (elmo-folder-open-internal folder))))
 
 (luna-define-method elmo-folder-expand-msgdb-path ((folder
                                                    elmo-shimbun-folder))
 (defun elmo-shimbun-msgdb-create-entity (folder number)
   (let ((header (elmo-get-hash-val
                 (elmo-map-message-location folder number)
-                (elmo-shimbun-folder-header-hash-internal folder))))
+                (elmo-shimbun-folder-header-hash-internal folder)))
+       ov)
     (when header
       (with-temp-buffer
        (shimbun-header-insert
         (elmo-shimbun-folder-shimbun-internal folder)
         header)
-       (elmo-msgdb-create-overview-from-buffer number)))))
+       (setq ov (elmo-msgdb-create-overview-from-buffer number))
+       (elmo-msgdb-overview-entity-set-extra
+        ov
+        (nconc
+         (elmo-msgdb-overview-entity-get-extra ov)
+         (list (cons "xref" (shimbun-header-xref header)))))))))
 
 (luna-define-method elmo-folder-msgdb-create ((folder elmo-shimbun-folder)
                                              numlist new-mark
                                              numbers)
   t)
 
-(luna-define-method elmo-quit ((folder elmo-shimbun-folder))
-  (setq elmo-shimbun-headers-cache nil))
 (require 'product)
 (product-provide (provide 'elmo-shimbun) (require 'elmo-version))
 
index 2d81454..746ace3 100644 (file)
@@ -186,6 +186,9 @@ Return value is a cons cell of NEWS and MESSAGES.")
 (luna-define-generic elmo-folder-status (folder)
   "Returns a cons cell of (MAX-NUMBER . MESSAGES) in the FOLDER.")
 
+(luna-define-generic elmo-folder-reserve-status-p (folder)
+  "If non-nil, the folder should not close folder after `elmo-folder-status'.")
+
 (defun elmo-folder-list-messages (folder &optional visible-only)
   "Return a list of message numbers contained in FOLDER.
 If optional VISIBLE-ONLY is non-nil, killed messages are not listed."