(elmo-msgdb-match-condition): Ditto.
* modb-standard.el (elmo-msgdb-search): Define.
* modb-legacy.el (elmo-msgdb-search): Ditto.
* modb-entity.el (elmo-msgdb-message-match-condition): Renamed
from elmo-msgdb-match-condition-internal.
* elmo.el (elmo-folder-search-fast): Abolish.
(elmo-folder-search): Use elmo-msgdb-search and
elmo-with-progress-display.
* elmo-msgdb.el (elmo-msgdb-match-condition): Removed; redefined
as msgdb API.
2003-09-23 Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
- * elmo.el (luna-define-class): Remove slot message-modified and
+ * modb.el (elmo-msgdb-search): New API .
+ (elmo-msgdb-match-condition): Ditto.
+
+ * modb-standard.el (elmo-msgdb-search): Define.
+
+ * modb-legacy.el (elmo-msgdb-search): Ditto.
+
+ * modb-entity.el (elmo-msgdb-message-match-condition): Renamed
+ from elmo-msgdb-match-condition-internal.
+
+ * elmo.el (elmo-folder-search-fast): Abolish.
+ (elmo-folder-search): Use elmo-msgdb-search and
+ elmo-with-progress-display.
+
+ * elmo-msgdb.el (elmo-msgdb-match-condition): Removed; redefined
+ as msgdb API.
+
+ * elmo.el (elmo-folder): Remove slot message-modified and
flag-modified.
(elmo-folder-set-message-modified): Abolish.
(elmo-generic-folder-commit): Follow the change above.
(dolist (number (elmo-msgdb-list-flagged msgdb 'new))
(elmo-msgdb-unset-flag msgdb number 'new)))
-(defun elmo-msgdb-match-condition (msgdb condition number numbers)
- "Check whether the condition of the message is satisfied or not.
-MSGDB is the msgdb to search from.
-CONDITION is the search condition.
-NUMBER is the message number to check.
-NUMBERS is the target message number list.
-Return CONDITION itself if no entity exists in msgdb."
- (let ((entity (elmo-msgdb-message-entity msgdb number)))
- (if entity
- (elmo-msgdb-match-condition-internal msgdb
- condition
- entity
- (elmo-msgdb-flags msgdb number)
- numbers)
- condition)))
-
;;
;; deleted message handling
;;
(elmo-folder-send folder 'elmo-folder-rename-internal new-folder)
(elmo-msgdb-rename-path folder new-folder)))
-(defsubst elmo-folder-search-fast (folder condition numbers)
- "Search and return list of message numbers.
-Return t if CONDITION is not treated.
-FOLDER is the ELMO folder structure.
-CONDITION is a condition structure for searching.
-NUMBERS is a list of message numbers, messages are searched from the list."
- (if (and numbers
- (vectorp condition))
- (cond
- ((string= (elmo-filter-key condition) "flag")
- (let ((msgdb (elmo-folder-msgdb folder)))
- ;; msgdb should be synchronized at this point.
- (cond
- ((string= (elmo-filter-value condition) "unread")
- (elmo-folder-list-unreads folder))
- ((string= (elmo-filter-value condition) "important")
- (elmo-folder-list-importants folder))
- ((string= (elmo-filter-value condition) "answered")
- (elmo-folder-list-answereds folder))
- ((string= (elmo-filter-value condition) "digest")
- (nconc (elmo-folder-list-unreads folder)
- (elmo-folder-list-importants folder)))
- ((string= (elmo-filter-value condition) "any")
- (nconc (elmo-folder-list-unreads folder)
- (elmo-folder-list-importants folder)
- (elmo-folder-list-answereds folder))))))
- ((member (elmo-filter-key condition) '("first" "last"))
- (let ((len (length numbers))
- (lastp (string= (elmo-filter-key condition) "last"))
- (value (string-to-number (elmo-filter-value condition))))
- (when (eq (elmo-filter-type condition) 'unmatch)
- (setq lastp (not lastp)
- value (- len value)))
- (if lastp
- (nthcdr (max (- len value) 0) numbers)
- (when (> value 0)
- (let* ((numbers (copy-sequence numbers))
- (last (nthcdr (1- value) numbers)))
- (when last
- (setcdr last nil))
- numbers)))))
- (t
- t))
- t))
-
(luna-define-method elmo-folder-search ((folder elmo-folder)
condition
&optional numbers)
(let ((numbers (or numbers (elmo-folder-list-messages folder)))
+ (msgdb (elmo-folder-msgdb folder))
results)
- (if (listp (setq results (elmo-folder-search-fast folder
- condition
- numbers)))
+ (setq results (elmo-msgdb-search msgdb condition numbers))
+ (if (listp results)
results
- (let ((msgdb (elmo-folder-msgdb folder))
- (len (length numbers))
+ (let ((len (length numbers))
matched)
- (when (> len elmo-display-progress-threshold)
- (elmo-progress-set 'elmo-folder-search len "Searching..."))
- (unwind-protect
- (dolist (number numbers)
- (let (result)
- (setq result (elmo-msgdb-match-condition
- msgdb
- condition
- number
- numbers))
- (when (elmo-filter-condition-p result)
- (setq result (elmo-message-match-condition
- folder
- number
- condition
- numbers)))
- (when result
- (setq matched (cons number matched))))
- (elmo-progress-notify 'elmo-folder-search))
- (elmo-progress-clear 'elmo-folder-search))
+ (elmo-with-progress-display (> len elmo-display-progress-threshold)
+ (elmo-folder-search len "Searching...")
+ (dolist (number numbers)
+ (let (result)
+ (setq result (elmo-msgdb-match-condition msgdb
+ condition
+ number
+ numbers))
+ (when (elmo-filter-condition-p result)
+ (setq result (elmo-message-match-condition folder
+ number
+ condition
+ numbers)))
+ (when result
+ (setq matched (cons number matched))))
+ (elmo-progress-notify 'elmo-folder-search)))
+ (message "Searching...done")
(nreverse matched)))))
(luna-define-method elmo-message-match-condition ((folder elmo-folder)
Header region is supposed to be narrowed.")
;; Transitional interface.
-(luna-define-generic elmo-msgdb-match-condition-internal (handler
- condition
- entity
- flags
- numbers)
+(luna-define-generic elmo-msgdb-message-match-condition (handler
+ condition
+ entity
+ flags
+ numbers)
"Return non-nil when the entity matches the condition.")
;; Generic implementation.
(cons (car entity)
(copy-sequence (cdr entity))))
-(luna-define-method elmo-msgdb-match-condition-internal
+(luna-define-method elmo-msgdb-message-match-condition
((handler modb-legacy-entity-handler) condition entity flags numbers)
(cond
((vectorp condition)
(elmo-msgdb-match-condition-primitive condition entity flags numbers))
((eq (car condition) 'and)
- (let ((lhs (elmo-msgdb-match-condition-internal handler
- (nth 1 condition)
- entity flags numbers)))
+ (let ((lhs (elmo-msgdb-message-match-condition handler
+ (nth 1 condition)
+ entity flags numbers)))
(cond
((elmo-filter-condition-p lhs)
- (let ((rhs (elmo-msgdb-match-condition-internal
+ (let ((rhs (elmo-msgdb-message-match-condition
handler (nth 2 condition) entity flags numbers)))
(cond ((elmo-filter-condition-p rhs)
(list 'and lhs rhs))
(rhs
lhs))))
(lhs
- (elmo-msgdb-match-condition-internal handler (nth 2 condition)
- entity flags numbers)))))
+ (elmo-msgdb-message-match-condition handler (nth 2 condition)
+ entity flags numbers)))))
((eq (car condition) 'or)
- (let ((lhs (elmo-msgdb-match-condition-internal handler (nth 1 condition)
- entity flags numbers)))
+ (let ((lhs (elmo-msgdb-message-match-condition handler (nth 1 condition)
+ entity flags numbers)))
(cond
((elmo-filter-condition-p lhs)
- (let ((rhs (elmo-msgdb-match-condition-internal handler
- (nth 2 condition)
- entity flags numbers)))
+ (let ((rhs (elmo-msgdb-message-match-condition handler
+ (nth 2 condition)
+ entity flags numbers)))
(cond ((elmo-filter-condition-p rhs)
(list 'or lhs rhs))
(rhs
(lhs
t)
(t
- (elmo-msgdb-match-condition-internal handler
+ (elmo-msgdb-message-match-condition handler
(nth 2 condition)
entity flags numbers)))))))
(setq matched (cons (car elem) matched))))))
matched))
+(luna-define-method elmo-msgdb-search ((msgdb modb-legacy)
+ condition &optional numbers)
+ (if (vectorp condition)
+ (let ((key (elmo-filter-key condition))
+ results)
+ (cond
+ ((and (string= key "flag")
+ (eq (elmo-filter-type condition) 'match))
+ (setq results (elmo-msgdb-list-flagged
+ msgdb
+ (intern (elmo-filter-value condition))))
+ (if numbers
+ (elmo-list-filter numbers results)
+ results))
+ ((member key '("first" "last"))
+ (let* ((numbers (or numbers (elmo-msgdb-list-messages msgdb)))
+ (len (length numbers))
+ (lastp (string= key "last"))
+ (value (string-to-number (elmo-filter-value condition))))
+ (when (eq (elmo-filter-type condition) 'unmatch)
+ (setq lastp (not lastp)
+ value (- len value)))
+ (if lastp
+ (nthcdr (max (- len value) 0) numbers)
+ (when (> value 0)
+ (let* ((numbers (copy-sequence numbers))
+ (last (nthcdr (1- value) numbers)))
+ (when last
+ (setcdr last nil))
+ numbers)))))
+ (t
+ t)))
+ t))
+
(luna-define-method elmo-msgdb-append-entity ((msgdb modb-legacy)
entity &optional flags)
(when entity
(modb-standard-flag-map msgdb))))
matched))
+(luna-define-method elmo-msgdb-search ((msgdb modb-standard)
+ condition &optional numbers)
+ (if (vectorp condition)
+ (let ((key (elmo-filter-key condition))
+ results)
+ (cond
+ ((and (string= key "flag")
+ (eq (elmo-filter-type condition) 'match))
+ (setq results (elmo-msgdb-list-flagged
+ msgdb
+ (intern (elmo-filter-value condition))))
+ (if numbers
+ (elmo-list-filter numbers results)
+ results))
+ ((member key '("first" "last"))
+ (let* ((numbers (or numbers
+ (modb-standard-number-list-internal msgdb)))
+ (len (length numbers))
+ (lastp (string= key "last"))
+ (value (string-to-number (elmo-filter-value condition))))
+ (when (eq (elmo-filter-type condition) 'unmatch)
+ (setq lastp (not lastp)
+ value (- len value)))
+ (if lastp
+ (nthcdr (max (- len value) 0) numbers)
+ (when (> value 0)
+ (let* ((numbers (copy-sequence numbers))
+ (last (nthcdr (1- value) numbers)))
+ (when last
+ (setcdr last nil))
+ numbers)))))
+ (t
+ t)))
+ t))
+
(luna-define-method elmo-msgdb-append-entity ((msgdb modb-standard)
entity &optional flags)
(let ((number (elmo-msgdb-message-entity-number
(luna-define-generic elmo-msgdb-list-flagged (msgdb flag)
"Return a list of message numbers which is set FLAG in the MSGDB.")
-;;; (luna-define-generic elmo-msgdb-search (msgdb condition &optional numbers)
-;;; "Search and return list of message numbers.
-;;; MSGDB is the ELMO msgdb structure.
-;;; CONDITION is a condition structure for searching.
-;;; If optional argument NUMBERS is specified and is a list of message numbers,
-;;; messages are searched from the list.")
+(luna-define-generic elmo-msgdb-search (msgdb condition &optional numbers)
+ "Search and return list of message numbers.
+MSGDB is the ELMO msgdb structure.
+CONDITION is a condition structure for searching.
+If optional argument NUMBERS is specified and is a list of message numbers,
+messages are searched from the list.
+Return t if the condition is unsupported.")
+
+(luna-define-generic elmo-msgdb-match-condition (msgdb condition number
+ &optional numbers)
+ "Check whether the condition of the message is satisfied or not.
+MSGDB is the msgdb to search from.
+CONDITION is the search condition.
+NUMBER is the message number to check.
+If optional argument NUMBERS is specified and is a list of message numbers,
+messages are searched from the list.
+Return CONDITION itself if no entity exists in msgdb.")
(luna-define-generic elmo-msgdb-append-entity (msgdb entity &optional flags)
"Append a ENTITY with FLAGS into the MSGDB.
(luna-define-method elmo-msgdb-length ((msgdb modb-generic))
0)
+(luna-define-method elmo-msgdb-search ((msgdb modb-generic)
+ condition &optional numbers)
+ t)
+
+(luna-define-method elmo-msgdb-match-condition ((msgdb modb-generic)
+ condition
+ number
+ &optional numbers)
+ (let ((entity (elmo-msgdb-message-entity msgdb number)))
+ (if entity
+ (elmo-msgdb-message-match-condition
+ (elmo-msgdb-message-entity-handler msgdb)
+ condition
+ entity
+ (elmo-msgdb-flags msgdb number)
+ (or numbers (elmo-msgdb-list-messages msgdb)))
+ condition)))
(luna-define-method elmo-msgdb-message-entity-handler ((msgdb modb-generic))
(or modb-entity-default-cache-internal