-(defun elmo-msgdb-number-save (dir obj)
- (elmo-object-save
- (expand-file-name elmo-msgdb-number-filename dir)
- obj))
-
-(defun elmo-msgdb-mark-save (dir obj)
- (elmo-object-save
- (expand-file-name elmo-msgdb-mark-filename dir)
- obj))
-
-(defun elmo-msgdb-change-mark (msgdb before after)
- "Set the BEFORE marks to AFTER."
- (let ((mark-alist (elmo-msgdb-get-mark-alist msgdb))
- entity)
- (while mark-alist
- (setq entity (car mark-alist))
- (when (string= (cadr entity) before)
- (setcar (cdr entity) after))
- (setq mark-alist (cdr mark-alist)))))
-
-(defsubst elmo-msgdb-mark (flag cached &optional new)
- (if new
- (case flag
- (read
- (if cached
- nil
- elmo-msgdb-read-uncached-mark))
- (important
- elmo-msgdb-important-mark)
- (answered
- (if cached
- elmo-msgdb-answered-cached-mark
- elmo-msgdb-answered-uncached-mark))
- (t
- (if cached
- elmo-msgdb-unread-cached-mark
- elmo-msgdb-new-mark)))
- (case flag
- (unread
- (if cached
- elmo-msgdb-unread-cached-mark
- elmo-msgdb-unread-uncached-mark))
- (important
- elmo-msgdb-important-mark)
- (answered
- (if cached
- elmo-msgdb-answered-cached-mark
- elmo-msgdb-answered-uncached-mark)))))
-
-(defsubst elmo-msgdb-overview-save (dir overview)
- (elmo-object-save
- (expand-file-name elmo-msgdb-overview-filename dir)
- overview))
-
-(defun elmo-msgdb-match-condition-primitive (condition mark entity numbers)
- (catch 'unresolved
- (let ((key (elmo-filter-key condition))
- (case-fold-search t)
- result)
- (cond
- ((string= key "last")
- (setq result (<= (length (memq
- (elmo-msgdb-overview-entity-get-number
- entity)
- numbers))
- (string-to-int (elmo-filter-value condition)))))
- ((string= key "first")
- (setq result (< (-
- (length numbers)
- (length (memq
- (elmo-msgdb-overview-entity-get-number
- entity)
- numbers)))
- (string-to-int (elmo-filter-value condition)))))
- ((string= key "flag")
- (setq result
- (cond
- ((string= (elmo-filter-value condition) "any")
- (not (or (null mark)
- (string= mark elmo-msgdb-read-uncached-mark))))
- ((string= (elmo-filter-value condition) "digest")
- (not (or (null mark)
- (string= mark elmo-msgdb-read-uncached-mark)
- (string= mark elmo-msgdb-answered-cached-mark)
- (string= mark elmo-msgdb-answered-uncached-mark))))
-;; (member mark (append (elmo-msgdb-answered-marks)
-;; (list elmo-msgdb-important-mark)
-;; (elmo-msgdb-unread-marks))))
- ((string= (elmo-filter-value condition) "unread")
- (member mark (elmo-msgdb-unread-marks)))
- ((string= (elmo-filter-value condition) "important")
- (string= mark elmo-msgdb-important-mark))
- ((string= (elmo-filter-value condition) "answered")
- (member mark (elmo-msgdb-answered-marks))))))
- ((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 ((field-date (elmo-date-make-sortable-string
- (timezone-fix-time
- (elmo-msgdb-overview-entity-get-date entity)
- (current-time-zone) nil)))
- (specified-date
- (elmo-date-make-sortable-string
- (elmo-date-get-datevec
- (elmo-filter-value condition)))))
- (setq result (if (string= key "since")
- (or (string= specified-date field-date)
- (string< specified-date field-date))
- (string< field-date specified-date)))))
- ((member key elmo-msgdb-extra-fields)
- (let ((extval (elmo-msgdb-overview-entity-get-extra-field entity key)))
- (when (stringp extval)
- (setq result (string-match
- (elmo-filter-value condition)
- extval)))))
- (t
- (throw 'unresolved condition)))
- (if (eq (elmo-filter-type condition) 'unmatch)
- (not result)
- result))))
-
-(defun elmo-msgdb-match-condition-internal (condition mark entity numbers)
- (cond
- ((vectorp condition)
- (elmo-msgdb-match-condition-primitive condition mark entity numbers))
- ((eq (car condition) 'and)
- (let ((lhs (elmo-msgdb-match-condition-internal (nth 1 condition)
- mark entity numbers)))
- (cond
- ((elmo-filter-condition-p lhs)
- (let ((rhs (elmo-msgdb-match-condition-internal
- (nth 2 condition) mark entity numbers)))
- (cond ((elmo-filter-condition-p rhs)
- (list 'and lhs rhs))
- (rhs
- lhs))))
- (lhs
- (elmo-msgdb-match-condition-internal (nth 2 condition)
- mark entity numbers)))))
- ((eq (car condition) 'or)
- (let ((lhs (elmo-msgdb-match-condition-internal (nth 1 condition)
- mark entity numbers)))
- (cond
- ((elmo-filter-condition-p lhs)
- (let ((rhs (elmo-msgdb-match-condition-internal (nth 2 condition)
- mark entity numbers)))
- (cond ((elmo-filter-condition-p rhs)
- (list 'or lhs rhs))
- (rhs
- t)
- (t
- lhs))))
- (lhs
- t)
- (t
- (elmo-msgdb-match-condition-internal (nth 2 condition)
- mark entity numbers)))))))
-
-(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-overview-get-entity number msgdb)))
- (if entity
- (elmo-msgdb-match-condition-internal condition
- (elmo-msgdb-get-mark msgdb number)
- entity numbers)
- condition)))
-
-(defsubst elmo-msgdb-set-overview (msgdb overview)
- (setcar msgdb overview))
-
-(defsubst elmo-msgdb-set-number-alist (msgdb number-alist)
- (setcar (cdr msgdb) number-alist))
-
-(defsubst elmo-msgdb-set-mark-alist (msgdb mark-alist)
- (setcar (cddr msgdb) mark-alist))
-
-(defsubst elmo-msgdb-set-index (msgdb index)
- (setcar (cdddr msgdb) index))
-
-(defsubst elmo-msgdb-set-path (msgdb path)
- (setcar (cddddr msgdb) path))
-
-(defsubst elmo-msgdb-overview-entity-get-references (entity)
- (and entity (aref (cdr entity) 1)))
-
-(defsubst elmo-msgdb-overview-entity-set-references (entity references)
- (and entity (aset (cdr entity) 1 references))
- entity)
-
-;; entity -> parent-entity
-(defsubst elmo-msgdb-overview-get-parent-entity (entity database)
- (setq entity (elmo-msgdb-overview-entity-get-references entity))
- ;; entity is parent-id.
- (and entity (assoc entity database)))
-
-(defsubst elmo-msgdb-get-parent-entity (entity msgdb)
- (setq entity (elmo-msgdb-overview-entity-get-references entity))
- ;; entity is parent-id.
- (and entity (elmo-msgdb-overview-get-entity entity msgdb)))
-
-(defsubst elmo-msgdb-overview-entity-get-number (entity)
- (and entity (aref (cdr entity) 0)))
-
-(defsubst elmo-msgdb-overview-entity-get-from-no-decode (entity)
- (and entity (aref (cdr entity) 2)))
-
-(defsubst elmo-msgdb-overview-entity-get-from (entity)
- (and entity
- (aref (cdr entity) 2)
- (elmo-msgdb-get-decoded-cache (aref (cdr entity) 2))))
-
-(defsubst elmo-msgdb-overview-entity-set-number (entity number)
- (and entity (aset (cdr entity) 0 number))
- entity)
-;;;(setcar (cadr entity) number) entity)
-
-(defsubst elmo-msgdb-overview-entity-set-from (entity from)
- (and entity (aset (cdr entity) 2 from))
- entity)
-
-(defsubst elmo-msgdb-overview-entity-get-subject (entity)
- (and entity
- (aref (cdr entity) 3)
- (elmo-msgdb-get-decoded-cache (aref (cdr entity) 3))))
-
-(defsubst elmo-msgdb-overview-entity-get-subject-no-decode (entity)
- (and entity (aref (cdr entity) 3)))
-
-(defsubst elmo-msgdb-overview-entity-set-subject (entity subject)
- (and entity (aset (cdr entity) 3 subject))
- entity)
-
-(defsubst elmo-msgdb-overview-entity-get-date (entity)
- (and entity (aref (cdr entity) 4)))
-
-(defsubst elmo-msgdb-overview-entity-set-date (entity date)
- (and entity (aset (cdr entity) 4 date))
- entity)
-
-(defsubst elmo-msgdb-overview-entity-get-to (entity)
- (and entity (aref (cdr entity) 5)))
-
-(defsubst elmo-msgdb-overview-entity-get-cc (entity)
- (and entity (aref (cdr entity) 6)))
-
-(defsubst elmo-msgdb-overview-entity-get-size (entity)
- (and entity (aref (cdr entity) 7)))
-
-(defsubst elmo-msgdb-overview-entity-set-size (entity size)
- (and entity (aset (cdr entity) 7 size))
- entity)
-
-(defsubst elmo-msgdb-overview-entity-get-id (entity)
- (and entity (car entity)))
-
-(defsubst elmo-msgdb-overview-entity-get-extra-field (entity field-name)
- (let ((field-name (downcase field-name))
- (extra (and entity (aref (cdr entity) 8))))
- (and extra
- (cdr (assoc field-name extra)))))
-
-(defsubst elmo-msgdb-overview-entity-set-extra-field (entity field-name value)
- (let ((field-name (downcase field-name))
- (extras (and entity (aref (cdr entity) 8)))
- extra)
- (if (setq extra (assoc field-name extras))
- (setcdr extra value)
- (elmo-msgdb-overview-entity-set-extra
- entity
- (cons (cons field-name value) extras)))))
-
-(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)
-
-;;; New APIs
-(defsubst elmo-msgdb-message-entity (msgdb key)
- (elmo-get-hash-val
- (cond ((stringp key) key)
- ((numberp key) (format "#%d" key)))
- (elmo-msgdb-get-entity-hashtb msgdb)))
-
-(defun elmo-msgdb-make-message-entity (&rest args)
- "Make an message entity."
- (cons (plist-get args :message-id)
- (vector (plist-get args :number)
- (plist-get args :references)
- (plist-get args :from)
- (plist-get args :subject)
- (plist-get args :date)
- (plist-get args :to)
- (plist-get args :cc)
- (plist-get args :size)
- (plist-get args :extra))))
-
-(defsubst elmo-msgdb-message-entity-field (entity field &optional decode)
- (and entity
- (let ((field-value
- (case field
- (to (aref (cdr entity) 5))
- (cc (aref (cdr entity) 6))
- (date (aref (cdr entity) 4))
- (subject (aref (cdr entity) 3))
- (from (aref (cdr entity) 2))
- (message-id (car entity))
- (references (aref (cdr entity) 1))
- (size (aref (cdr entity) 7))
- (t (cdr (assoc (symbol-name field) (aref (cdr entity) 8)))))))
- (if decode
- (elmo-msgdb-get-decoded-cache field-value)
- field-value))))
-
-(defsubst elmo-msgdb-message-entity-set-field (entity field value)
- (and entity
- (case field
- (to (aset (cdr entity) 5 value))
- (cc (aset (cdr entity) 6 value))
- (date (aset (cdr entity) 4 value))
- (subject (aset (cdr entity) 3 value))
- (from (aset (cdr entity) 2 value))
- (message-id (setcar entity value))
- (references (aset (cdr entity) 1 value))
- (size (aset (cdr entity) 7 value))
- (t
- (let ((extras (and entity (aref (cdr entity) 8)))
- extra)
- (if (setq extra (assoc field extras))
- (setcdr extra value)
- (aset (cdr entity) 8 (cons (cons (symbol-name field)
- value) extras))))))))
-
-;;;
-(defun elmo-msgdb-overview-get-entity (id msgdb)
- (when id
- (let ((ht (elmo-msgdb-get-entity-hashtb msgdb)))
- (if ht
- (if (stringp id) ;; ID is message-id
- (elmo-get-hash-val id ht)
- (elmo-get-hash-val (format "#%d" id) ht))))))