* elmo-util.el (elmo-condition-find-key-internal): New function.
authorteranisi <teranisi>
Tue, 3 Oct 2000 10:23:55 +0000 (10:23 +0000)
committerteranisi <teranisi>
Tue, 3 Oct 2000 10:23:55 +0000 (10:23 +0000)
(elmo-condition-find-key): Ditto.

* elmo-msgdb.el (elmo-msgdb-search-internal-primitive): New function.
(elmo-msgdb-search-internal): Ditto.
(elmo-msgdb-search): Ditto.

elmo/ChangeLog
elmo/elmo-msgdb.el
elmo/elmo-util.el

index 2b4e097..d498584 100644 (file)
@@ -1,3 +1,12 @@
+2000-10-03  Yuuichi Teranishi  <teranisi@gohome.org>
+
+       * elmo-util.el (elmo-condition-find-key-internal): New function.
+       (elmo-condition-find-key): Ditto.
+
+       * elmo-msgdb.el (elmo-msgdb-search-internal-primitive): New function.
+       (elmo-msgdb-search-internal): Ditto.
+       (elmo-msgdb-search): Ditto.
+
 2000-10-02  Yuuichi Teranishi  <teranisi@gohome.org>
 
        * elmo-util.el (elmo-cross-device-link-error-p): Abolished.
index b8f0c8e..90e5c3b 100644 (file)
@@ -407,6 +407,90 @@ header separator."
    (expand-file-name elmo-msgdb-overview-filename dir)
    overview))
 
+(defun elmo-msgdb-search-internal-primitive (condition entity number-list)
+  (let ((key (elmo-filter-key condition))
+       result)
+    (cond
+     ((string= key "last")
+      (setq result (<= (length (memq
+                               (elmo-msgdb-overview-entity-get-number entity)
+                               number-list))
+                      (string-to-int (elmo-filter-value condition)))))
+     ((string= key "first")
+      (setq result (< (- 
+                      (length number-list)
+                      (length (memq
+                               (elmo-msgdb-overview-entity-get-number entity)
+                               number-list)))
+                     (string-to-int (elmo-filter-value condition)))))
+     ((string= key "from")
+      (setq result (string-match 
+                   (elmo-filter-value condition)
+                   (elmo-msgdb-overview-entity-get-from entity))))
+     ((string= key "subject")
+      (setq result (string-match 
+                   (elmo-filter-value condition)
+                   (elmo-msgdb-overview-entity-get-subject entity))))
+     ((string= key "to")
+      (setq result (string-match
+                   (elmo-filter-value condition)
+                   (elmo-msgdb-overview-entity-get-to entity))))
+     ((string= key "cc")
+      (setq result (string-match
+                   (elmo-filter-value condition)
+                   (elmo-msgdb-overview-entity-get-cc entity))))
+     ((or (string= key "since")
+         (string= key "before"))
+      (let ((res (string< (elmo-date-make-sortable-string
+                          (elmo-date-get-datevec
+                           (elmo-msgdb-overview-entity-get-date entity)))
+                         (elmo-date-make-sortable-string
+                          (elmo-date-get-datevec
+                           (elmo-filter-value condition))))))
+       (setq result (if (string= key "since") res (not res))))))
+    (if (eq (elmo-filter-type condition) 'unmatch)
+       (setq result (not result)))
+    result))
+
+(defun elmo-msgdb-search-internal (condition entity number-list)
+  (cond
+   ((vectorp condition)
+    (elmo-msgdb-search-internal-primitive condition entity number-list))
+   ((eq (car condition) 'and)
+    (and (elmo-msgdb-search-internal-primitive
+         (nth 1 condition) entity number-list)
+        (elmo-msgdb-search-internal-primitive
+         (nth 2 condition) entity number-list)))
+   ((eq (car condition) 'or)
+    (or (elmo-msgdb-search-internal-primitive
+        (nth 1 condition) entity number-list)
+       (elmo-msgdb-search-internal-primitive
+        (nth 2 condition) entity number-list)))))
+
+(defun elmo-msgdb-search (folder condition msgdb)
+  "Search messages from MSGDB which satisfy CONDITION."
+  (let* ((condition (car (elmo-parse-search-condition condition)))
+        (overview (elmo-msgdb-get-overview msgdb))
+        (number-alist (elmo-msgdb-get-number-alist msgdb))
+        (number-list (mapcar 'car number-alist))
+        (length (length overview))
+        (i 0)
+        result)
+    (if (elmo-condition-find-key condition "body")
+       (elmo-search folder condition number-list)
+      (while overview
+       (if (elmo-msgdb-search-internal condition (car overview)
+                                       number-list)
+           (setq result
+                 (cons
+                  (elmo-msgdb-overview-entity-get-number (car overview))
+                  result)))
+       (setq i (1+ i))
+       (elmo-display-progress
+        'elmo-msgdb-search "Searching..." (/ (* i 100) length))
+       (setq overview (cdr overview)))
+      (nreverse result))))
+
 (defun elmo-msgdb-delete-msgs (folder msgs msgdb &optional reserve-cache)
   "Delete MSGS from FOLDER in MSGDB.
 content of MSGDB is changed."
index ca00605..4decd8f 100644 (file)
@@ -1260,6 +1260,20 @@ Otherwise treat \\ in NEWTEXT string as special:
        (setq result (not result)))
     result))
 
+(defun elmo-condition-find-key-internal (condition key)
+  (cond
+   ((vectorp condition)
+    (if (string= (elmo-filter-key condition) key)
+       (throw 'found t)))
+   ((or (eq (car condition) 'and)
+       (eq (car condition) 'or))
+    (elmo-condition-find-key-internal (nth 1 condition) key)
+    (elmo-condition-find-key-internal (nth 2 condition) key))))
+
+(defun elmo-condition-find-key (condition key)
+  (catch 'found
+    (elmo-condition-find-key-internal condition key)))
+
 (defun elmo-buffer-field-condition-match (condition number number-list)
   (cond
    ((vectorp condition)