From 71202990200db28ddd3120d8ebfefc35cc2944c3 Mon Sep 17 00:00:00 2001 From: hmurata Date: Tue, 23 Sep 2003 12:23:33 +0000 Subject: [PATCH] * 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/ChangeLog | 19 ++++++++++- elmo/elmo-msgdb.el | 16 --------- elmo/elmo.el | 91 ++++++++++++------------------------------------- elmo/modb-entity.el | 36 +++++++++---------- elmo/modb-legacy.el | 34 ++++++++++++++++++ elmo/modb-standard.el | 35 +++++++++++++++++++ elmo/modb.el | 40 ++++++++++++++++++---- 7 files changed, 160 insertions(+), 111 deletions(-) diff --git a/elmo/ChangeLog b/elmo/ChangeLog index 90968bc..6f5287f 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,6 +1,23 @@ 2003-09-23 Hiroya Murata - * 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. diff --git a/elmo/elmo-msgdb.el b/elmo/elmo-msgdb.el index 79b33ad..d044099 100644 --- a/elmo/elmo-msgdb.el +++ b/elmo/elmo-msgdb.el @@ -254,22 +254,6 @@ header separator." (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 ;; diff --git a/elmo/elmo.el b/elmo/elmo.el index 09dc513..d5b2ebe 100644 --- a/elmo/elmo.el +++ b/elmo/elmo.el @@ -715,83 +715,34 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-FLAG-ALIST).") (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) diff --git a/elmo/modb-entity.el b/elmo/modb-entity.el index 0a98a99..e7dccfb 100644 --- a/elmo/modb-entity.el +++ b/elmo/modb-entity.el @@ -104,11 +104,11 @@ Rest of the ARGS is a plist of message entity field for initial value. 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. @@ -295,34 +295,34 @@ Header region is supposed to be narrowed.") (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 @@ -332,7 +332,7 @@ Header region is supposed to be narrowed.") (lhs t) (t - (elmo-msgdb-match-condition-internal handler + (elmo-msgdb-message-match-condition handler (nth 2 condition) entity flags numbers))))))) diff --git a/elmo/modb-legacy.el b/elmo/modb-legacy.el index bbd7a21..a804025 100644 --- a/elmo/modb-legacy.el +++ b/elmo/modb-legacy.el @@ -519,6 +519,40 @@ Return a list of message numbers which have duplicated message-ids." (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 diff --git a/elmo/modb-standard.el b/elmo/modb-standard.el index 3af28eb..e996b2d 100644 --- a/elmo/modb-standard.el +++ b/elmo/modb-standard.el @@ -354,6 +354,41 @@ (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 diff --git a/elmo/modb.el b/elmo/modb.el index 49046ea..4011c41 100644 --- a/elmo/modb.el +++ b/elmo/modb.el @@ -98,12 +98,23 @@ FLAG is a symbol which is one of the following: (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. @@ -158,6 +169,23 @@ A string is for message-id of the message.") (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 -- 1.7.10.4