New inline function (Don't fetch file content if "first" or "last").
(elmo-file-field-condition-match): Use
elmo-file-field-primitive-condition-match.
* elmo-localdir.el (elmo-folder-search): Speed up simple "last" and
"first".
2001-06-11 Yuuichi Teranishi <teranisi@gohome.org>
+ * elmo-util.el (elmo-file-field-primitive-condition-match):
+ New inline function (Don't fetch file content if "first" or "last").
+ (elmo-file-field-condition-match): Use
+ elmo-file-field-primitive-condition-match.
+
+ * elmo-localdir.el (elmo-folder-search): Speed up simple "last" and
+ "first".
+
* elmo-pop3.el (elmo-pop3-process-filter): Don't use floor nor float.
(elmo-message-fetch-plugged): Fixed.
(expand-file-name (int-to-string number)
(elmo-localdir-folder-directory-internal folder))
condition number number-list))
-
+
(luna-define-method elmo-folder-search ((folder elmo-localdir-folder)
condition &optional numbers)
(let* ((msgs (or numbers (elmo-folder-list-messages folder)))
(num (length msgs))
(i 0)
- number-list case-fold-search ret-val)
- (setq number-list msgs)
- (while msgs
- (if (elmo-localdir-field-condition-match folder condition
- (car msgs) number-list)
- (setq ret-val (cons (car msgs) ret-val)))
- (when (> num elmo-display-progress-threshold)
- (setq i (1+ i))
- (elmo-display-progress
- 'elmo-localdir-search "Searching..."
- (/ (* i 100) num)))
- (setq msgs (cdr msgs)))
- (nreverse ret-val)))
+ last cur number-list case-fold-search ret-val)
+ (cond
+ ;; short cut.
+ ((and (vectorp condition)
+ (string= (elmo-filter-key condition) "last"))
+ (nthcdr (max (- (length msgs)
+ (string-to-int (elmo-filter-value condition)))
+ 0)
+ msgs))
+ ((and (vectorp condition)
+ (string= (elmo-filter-key condition) "first"))
+ (let ((rest (nthcdr (string-to-int (elmo-filter-value condition) )
+ msgs)))
+ (mapcar '(lambda (x)
+ (delete x msgs)) rest))
+ msgs)
+ (t
+ (setq number-list msgs)
+ (while msgs
+ (if (elmo-localdir-field-condition-match folder condition
+ (car msgs) number-list)
+ (setq ret-val (cons (car msgs) ret-val)))
+ (when (> num elmo-display-progress-threshold)
+ (setq i (1+ i))
+ (setq cur (/ (* i 100) num))
+ (unless (eq cur last)
+ (elmo-display-progress
+ 'elmo-localdir-search "Searching..."
+ cur)
+ (setq last cur)))
+ (setq msgs (cdr msgs)))
+ (nreverse ret-val)))))
(luna-define-method elmo-folder-pack-numbers ((folder elmo-localdir-folder))
(let* ((dir (elmo-localdir-folder-directory-internal folder))
(elmo-buffer-field-condition-match
(nth 2 condition) number number-list)))))
-(defsubst elmo-file-field-condition-match (file condition number number-list)
- (elmo-set-work-buf
- (as-binary-input-file (insert-file-contents file))
- (elmo-set-buffer-multibyte default-enable-multibyte-characters)
- ;; Should consider charset?
- (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
- (elmo-buffer-field-condition-match condition number number-list)))
+(defsubst elmo-file-field-primitive-condition-match (file
+ condition
+ number
+ number-list)
+ (let (result)
+ (goto-char (point-min))
+ (cond
+ ((string= (elmo-filter-key condition) "last")
+ (setq result (<= (length (memq number number-list))
+ (string-to-int (elmo-filter-value condition)))))
+ ((string= (elmo-filter-key condition) "first")
+ (setq result (< (- (length number-list)
+ (length (memq number number-list)))
+ (string-to-int (elmo-filter-value condition)))))
+ (t
+ (elmo-set-work-buf
+ (as-binary-input-file (insert-file-contents file))
+ (elmo-set-buffer-multibyte default-enable-multibyte-characters)
+ ;; Should consider charset?
+ (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
+ (setq result
+ (elmo-buffer-field-primitive-condition-match
+ condition number number-list)))))
+ (if (eq (elmo-filter-type condition) 'unmatch)
+ (setq result (not result)))
+ result))
+
+(defun elmo-file-field-condition-match (file condition number number-list)
+ (cond
+ ((vectorp condition)
+ (elmo-file-field-primitive-condition-match
+ file condition number number-list))
+ ((eq (car condition) 'and)
+ (and (elmo-file-field-condition-match
+ file (nth 1 condition) number number-list)
+ (elmo-file-field-condition-match
+ file (nth 2 condition) number number-list)))
+ ((eq (car condition) 'or)
+ (or (elmo-file-field-condition-match
+ file (nth 1 condition) number number-list)
+ (elmo-file-field-condition-match
+ file (nth 2 condition) number number-list)))))
(defmacro elmo-get-hash-val (string hashtable)
(let ((sym (list 'intern-soft string hashtable)))