From db0c79dbf84aba8cd087793299d734bdbc381051 Mon Sep 17 00:00:00 2001 From: teranisi Date: Wed, 1 May 2002 03:23:53 +0000 Subject: [PATCH] * elmo-imap4.el (elmo-folder-open): Fix. * elmo.el (elmo-message-mark): Rewrite. (elmo-message-field): Ditto. (elmo-message-set-mark): Ditto. (elmo-folder-replace-marks): New function. (elmo-generic-folder-append-msgdb): Removed third argument for elmo-msgdb-append. (elmo-folder-synchronize): Use elmo-msgdb-seen-list. (elmo-msgdb-load): New implementation. * elmo-vars.el (elmo-use-overview-hashtb): Removed. * elmo-util.el (elmo-list-insert): New implementation. * elmo-multi.el (elmo-multi-folder-append-msgdb): Removed third argument for elmo-msgdb-append. * elmo-msgdb.el (elmo-load-msgdb): New function. (elmo-make-msgdb): Ditto. (elmo-msgdb-get-index): New inline function. (elmo-msgdb-set-index): Ditto. (elmo-msgdb-get-entity-hashtb): Ditto. (elmo-msgdb-get-mark-hashtb): Ditto. (elmo-msgdb-get-mark): Ditto. (elmo-msgdb-set-mark): Ditto. (elmo-msgdb-count-marks): Ditto. (elmo-msgdb-get-number): Ditto. (elmo-msgdb-get-field): Ditto. (elmo-msgdb-seen-list): Ditto. (elmo-msgdb-mark-alist-set): Renamed from elmo-msgdb-mark-set. (elmo-msgdb-delete-msgs): Follow the changes above. (elmo-msgdb-overview-get-entity): Ditto. (elmo-msgdb-add-msgs-to-seen-list): Ditto. (elmo-msgdb-clear-index): Renamed from elmo-msgdb-clear-overview-hastb and rewritten. (elmo-msgdb-make-index): Likewise. (elmo-msgdb-append): Removed third argument. (elmo-msgdb-clear): Clear index as nil. (elmo-folder-set-info-hashtb): Removed. (elmo-folder-set-info-max-by-numdb): Ditto. (elmo-folder-info-make-hashtb): Ditto. * elmo-localdir.el (elmo-folder-pack-numbers): Use elmo-make-msgdb. * elmo-map.el (elmo-folder-pack-number): Ditto. --- elmo/ChangeLog | 50 +++++++ elmo/elmo-imap4.el | 32 +++-- elmo/elmo-localdir.el | 10 +- elmo/elmo-map.el | 7 +- elmo/elmo-msgdb.el | 364 ++++++++++++++++++++++++++++--------------------- elmo/elmo-multi.el | 2 +- elmo/elmo-util.el | 17 +-- elmo/elmo-vars.el | 3 - elmo/elmo.el | 68 ++++----- 9 files changed, 330 insertions(+), 223 deletions(-) diff --git a/elmo/ChangeLog b/elmo/ChangeLog index d90ca05..f66f7be 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,3 +1,53 @@ +2002-05-01 Yuuichi Teranishi + + * elmo-imap4.el (elmo-folder-open): Fix. + + * elmo.el (elmo-message-mark): Rewrite. + (elmo-message-field): Ditto. + (elmo-message-set-mark): Ditto. + (elmo-folder-replace-marks): New function. + (elmo-generic-folder-append-msgdb): Removed third argument for + elmo-msgdb-append. + (elmo-folder-synchronize): Use elmo-msgdb-seen-list. + (elmo-msgdb-load): New implementation. + + * elmo-vars.el (elmo-use-overview-hashtb): Removed. + + * elmo-util.el (elmo-list-insert): New implementation. + + * elmo-multi.el (elmo-multi-folder-append-msgdb): Removed third + argument for elmo-msgdb-append. + + + * elmo-msgdb.el (elmo-load-msgdb): New function. + (elmo-make-msgdb): Ditto. + (elmo-msgdb-get-index): New inline function. + (elmo-msgdb-set-index): Ditto. + (elmo-msgdb-get-entity-hashtb): Ditto. + (elmo-msgdb-get-mark-hashtb): Ditto. + (elmo-msgdb-get-mark): Ditto. + (elmo-msgdb-set-mark): Ditto. + (elmo-msgdb-count-marks): Ditto. + (elmo-msgdb-get-number): Ditto. + (elmo-msgdb-get-field): Ditto. + (elmo-msgdb-seen-list): Ditto. + (elmo-msgdb-mark-alist-set): Renamed from elmo-msgdb-mark-set. + (elmo-msgdb-delete-msgs): Follow the changes above. + (elmo-msgdb-overview-get-entity): Ditto. + (elmo-msgdb-add-msgs-to-seen-list): Ditto. + (elmo-msgdb-clear-index): Renamed from elmo-msgdb-clear-overview-hastb + and rewritten. + (elmo-msgdb-make-index): Likewise. + (elmo-msgdb-append): Removed third argument. + (elmo-msgdb-clear): Clear index as nil. + (elmo-folder-set-info-hashtb): Removed. + (elmo-folder-set-info-max-by-numdb): Ditto. + (elmo-folder-info-make-hashtb): Ditto. + + * elmo-localdir.el (elmo-folder-pack-numbers): Use elmo-make-msgdb. + + * elmo-map.el (elmo-folder-pack-number): Ditto. + 2002-04-30 Yuuichi Teranishi * elmo-version.el (elmo-version): Up to 2.9.10. diff --git a/elmo/elmo-imap4.el b/elmo/elmo-imap4.el index 72946a6..8c8221f 100644 --- a/elmo/elmo-imap4.el +++ b/elmo/elmo-imap4.el @@ -2363,7 +2363,7 @@ If optional argument REMOVE is non-nil, remove FLAG." (luna-define-method elmo-folder-open :around ((folder elmo-imap4-folder) &optional load-msgdb) (if (elmo-folder-plugged-p folder) - (let (session mailbox msgdb response tag) + (let (session mailbox msgdb result response tag) (condition-case err (progn (setq session (elmo-imap4-get-session folder) @@ -2372,12 +2372,32 @@ If optional argument REMOVE is non-nil, remove FLAG." (list "select " (elmo-imap4-mailbox mailbox)))) + (message "Selecting %s..." + (elmo-folder-name-internal folder)) (if load-msgdb - (setq msgdb (elmo-msgdb-load folder))) + (setq msgdb (elmo-msgdb-load folder 'silent))) (elmo-folder-set-killed-list-internal folder (elmo-msgdb-killed-list-load (elmo-folder-msgdb-path folder))) - (setq response (elmo-imap4-read-response session tag))) + (if (setq result (elmo-imap4-response-ok-p + (setq response + (elmo-imap4-read-response session tag)))) + (progn + (elmo-imap4-session-set-current-mailbox-internal + session mailbox) + (elmo-imap4-session-set-read-only-internal + session + (nth 1 (assq 'read-only (assq 'ok response))))) + (elmo-imap4-session-set-current-mailbox-internal session nil) + (if (elmo-imap4-response-bye-p response) + (elmo-imap4-process-bye session) + (error (or + (elmo-imap4-response-error-text response) + (format "Select %s failed" mailbox))))) + (message "Selecting %s...done" + (elmo-folder-name-internal folder)) + (elmo-folder-set-msgdb-internal + folder msgdb)) (quit (if response (elmo-imap4-session-set-current-mailbox-internal @@ -2391,11 +2411,7 @@ If optional argument REMOVE is non-nil, remove FLAG." session mailbox) (and session (elmo-imap4-session-set-current-mailbox-internal - session nil))))) - (if load-msgdb - (elmo-folder-set-msgdb-internal - folder - (or msgdb (elmo-msgdb-load folder))))) + session nil)))))) (luna-call-next-method))) ;; elmo-folder-open-internal: do nothing. diff --git a/elmo/elmo-localdir.el b/elmo/elmo-localdir.el index f9e5c2f..b85d9c9 100644 --- a/elmo/elmo-localdir.el +++ b/elmo/elmo-localdir.el @@ -363,12 +363,10 @@ (message "Packing...done") (elmo-folder-set-msgdb-internal folder - (list (elmo-msgdb-get-overview msgdb) - onum-alist - new-mark-alist - ;; remake hash table - (elmo-msgdb-make-overview-hashtb - (elmo-msgdb-get-overview msgdb)))))) + (elmo-make-msgdb + (elmo-msgdb-get-overview msgdb) + onum-alist + new-mark-alist)))) (luna-define-method elmo-folder-message-file-p ((folder elmo-localdir-folder)) t) diff --git a/elmo/elmo-map.el b/elmo/elmo-map.el index 6391cf4..cb13519 100644 --- a/elmo/elmo-map.el +++ b/elmo/elmo-map.el @@ -150,10 +150,9 @@ (elmo-map-folder-location-setup folder (nreverse location)) (elmo-folder-set-msgdb-internal folder - (list overview - (nreverse number-alist) - (nreverse mark-alist) - (elmo-msgdb-make-overview-hashtb overview))))) + (elmo-make-msgdb overview + (nreverse number-alist) + (nreverse mark-alist))))) (defun elmo-map-folder-location-setup (folder locations) (elmo-map-folder-set-location-alist-internal diff --git a/elmo/elmo-msgdb.el b/elmo/elmo-msgdb.el index 357c7d5..bfe4b9f 100644 --- a/elmo/elmo-msgdb.el +++ b/elmo/elmo-msgdb.el @@ -37,6 +37,128 @@ (require 'emu) (require 'std11) +;;; MSGDB interface. +(defun elmo-load-msgdb (path) + "Load the MSGDB from PATH." + (let ((inhibit-quit t)) + (elmo-make-msgdb (elmo-msgdb-overview-load path) + (elmo-msgdb-number-load path) + (elmo-msgdb-mark-load path)))) + +(defun elmo-make-msgdb (&optional overview number-alist mark-alist) + "Make a MSGDB." + (let ((msgdb (list overview number-alist mark-alist nil))) + (elmo-msgdb-make-index msgdb) + msgdb)) + +(defsubst elmo-msgdb-get-mark (msgdb number) + "Get mark from MSGDB which corresponds to the message with NUMBER." + (cadr (elmo-get-hash-val (format "#%d" number) + (elmo-msgdb-get-mark-hashtb msgdb)))) + +(defsubst elmo-msgdb-set-mark (msgdb number mark) + "Set MARK of the message with NUMBER in the MSGDB." + (elmo-msgdb-set-mark-alist + msgdb + (elmo-msgdb-mark-alist-set (elmo-msgdb-get-mark-alist msgdb) + number + mark msgdb)) + (unless mark + (elmo-clear-hash-val (format "#%d" number) + (elmo-msgdb-get-mark-hashtb msgdb)))) + +(defsubst elmo-msgdb-count-marks (msgdb new-mark unread-marks) + (let ((new 0) + (unreads 0)) + (dolist (elem (elmo-msgdb-get-mark-alist msgdb)) + (cond + ((string= (cadr elem) new-mark) + (incf new)) + ((member (cadr elem) unread-marks) + (incf unreads)))) + (cons new unreads))) + +(defsubst elmo-msgdb-get-number (msgdb message-id) + "Get number of the message which corrensponds to MESSAGE-ID from MSGDB." + (elmo-msgdb-overview-entity-get-number + (elmo-msgdb-overview-get-entity message-id msgdb))) + +(defsubst elmo-msgdb-get-field (msgdb number field) + "Get FIELD value of the message with NUMBER from MSGDB." + (case field + (message-id (elmo-msgdb-overview-entity-get-id + (elmo-msgdb-overview-get-entity + number msgdb))) + (subject (elmo-msgdb-overview-entity-get-subject + (elmo-msgdb-overview-get-entity + number msgdb))) + (size (elmo-msgdb-overview-entity-get-size + (elmo-msgdb-overview-get-entity + number msgdb))) + (date (elmo-msgdb-overview-entity-get-date + (elmo-msgdb-overview-get-entity + number msgdb))) + (to (elmo-msgdb-overview-entity-get-to + (elmo-msgdb-overview-get-entity + number msgdb))) + (cc (elmo-msgdb-overview-entity-get-cc + (elmo-msgdb-overview-get-entity + number msgdb))))) + +(defsubst elmo-msgdb-append (msgdb msgdb-append) + (list + (nconc (car msgdb) (car msgdb-append)) + (nconc (cadr msgdb) (cadr msgdb-append)) + (nconc (caddr msgdb) (caddr msgdb-append)) + (elmo-msgdb-make-index + msgdb + (elmo-msgdb-get-overview msgdb-append) + (elmo-msgdb-get-mark-alist msgdb-append)))) + +(defsubst elmo-msgdb-clear (&optional msgdb) + (if msgdb + (list + (setcar msgdb nil) + (setcar (cdr msgdb) nil) + (setcar (cddr msgdb) nil) + (setcar (nthcdr 3 msgdb) nil)) + (list nil nil nil nil))) + +(defun elmo-msgdb-delete-msgs (msgdb msgs) + "Delete MSGS from MSGDB +content of MSGDB is changed." + (let* ((overview (car msgdb)) + (number-alist (cadr msgdb)) + (mark-alist (caddr msgdb)) + (index (elmo-msgdb-get-index msgdb)) + (newmsgdb (list overview number-alist mark-alist index)) + ov-entity) + ;; remove from current database. + (while msgs + (setq overview + (delq + (setq ov-entity + (elmo-msgdb-overview-get-entity (car msgs) newmsgdb)) + overview)) + (setq number-alist (delq (assq (car msgs) number-alist) number-alist)) + (setq mark-alist (delq (assq (car msgs) mark-alist) mark-alist)) + ;; + (when index (elmo-msgdb-clear-index msgdb ov-entity)) + (setq msgs (cdr msgs))) + (setcar msgdb overview) + (setcar (cdr msgdb) number-alist) + (setcar (cddr msgdb) mark-alist) + (setcar (nthcdr 3 msgdb) index) + t)) ;return value + +(defun elmo-msgdb-sort-by-date (msgdb) + (message "Sorting...") + (let ((overview (elmo-msgdb-get-overview msgdb))) + (setq overview (elmo-msgdb-overview-sort-by-date overview)) + (message "Sorting...done") + (list overview (nth 1 msgdb)(nth 2 msgdb)))) + +;;; (defsubst elmo-msgdb-append-element (list element) (if list ;;; (append list (list element)) @@ -52,9 +174,16 @@ (caddr msgdb)) ;(defsubst elmo-msgdb-get-location (msgdb) ; (cadddr msgdb)) -(defsubst elmo-msgdb-get-overviewht (msgdb) + +(defsubst elmo-msgdb-get-index (msgdb) (nth 3 msgdb)) +(defsubst elmo-msgdb-get-entity-hashtb (msgdb) + (car (nth 3 msgdb))) + +(defsubst elmo-msgdb-get-mark-hashtb (msgdb) + (cdr (nth 3 msgdb))) + ;; ;; number <-> Message-ID handling ;; @@ -109,7 +238,7 @@ ;;; ;; persistent mark handling ;; (for each folder) -(defun elmo-msgdb-mark-set (alist id mark) +(defun elmo-msgdb-mark-alist-set (alist id mark msgdb) (let ((ret-val alist) entity) (setq entity (assq id alist)) @@ -119,9 +248,12 @@ (setq ret-val (delq entity alist)) ;; set mark (setcar (cdr entity) mark)) - (if mark - (setq ret-val (elmo-msgdb-append-element ret-val - (list id mark))))) + (when mark + (setq ret-val (elmo-msgdb-append-element ret-val + (setq entity + (list id mark)))) + (elmo-set-hash-val (format "#%d" id) entity + (elmo-msgdb-get-mark-hashtb msgdb)))) ret-val)) (defun elmo-msgdb-mark-append (alist id mark) @@ -129,18 +261,23 @@ (setq alist (elmo-msgdb-append-element alist (list id mark)))) -(defun elmo-msgdb-mark-alist-to-seen-list (number-alist mark-alist seen-marks) - "Make seen-list from MARK-ALIST." - (let ((seen-mark-list (string-to-char-list seen-marks)) - ret-val ent) - (while number-alist - (if (setq ent (assq (car (car number-alist)) mark-alist)) - (if (and (cadr ent) - (memq (string-to-char (cadr ent)) seen-mark-list)) - (setq ret-val (cons (cdr (car number-alist)) ret-val))) - (setq ret-val (cons (cdr (car number-alist)) ret-val))) - (setq number-alist (cdr number-alist))) - ret-val)) +(defun elmo-msgdb-seen-list (msgdb seen-marks) + "Get SEEN-MSGID-LIST from MSGDB." + (let ((ov (elmo-msgdb-get-overview msgdb)) + mark seen-list) + (while ov + (if (setq mark (elmo-msgdb-get-mark + msgdb + (elmo-msgdb-overview-entity-get-number (car ov)))) + (if (and mark (member mark seen-marks)) + (setq seen-list (cons + (elmo-msgdb-overview-entity-get-id (car ov)) + seen-list))) + (setq seen-list (cons + (elmo-msgdb-overview-entity-get-id (car ov)) + seen-list))) + (setq ov (cdr ov))) + seen-list)) ;; ;; mime decode cache @@ -373,37 +510,6 @@ header separator." (elmo-msgdb-match-condition (nth 2 condition) entity numbers))))))) -(defun elmo-msgdb-delete-msgs (msgdb msgs) - "Delete MSGS from MSGDB -content of MSGDB is changed." - (save-excursion - (let* (;(msgdb (elmo-folder-msgdb folder)) - (overview (car msgdb)) - (number-alist (cadr msgdb)) - (mark-alist (caddr msgdb)) - (hashtb (elmo-msgdb-get-overviewht msgdb)) - (newmsgdb (list overview number-alist mark-alist hashtb)) - ov-entity) - ;; remove from current database. - (while msgs - (setq overview - (delq - (setq ov-entity - (elmo-msgdb-overview-get-entity (car msgs) newmsgdb)) - overview)) - (when (and elmo-use-overview-hashtb hashtb) - (elmo-msgdb-clear-overview-hashtb ov-entity hashtb)) - (setq number-alist - (delq (assq (car msgs) number-alist) number-alist)) - (setq mark-alist (delq (assq (car msgs) mark-alist) mark-alist)) - (setq msgs (cdr msgs))) - ;(elmo-folder-set-message-modified-internal folder t) - (setcar msgdb overview) - (setcar (cdr msgdb) number-alist) - (setcar (cddr msgdb) mark-alist) - (setcar (nthcdr 3 msgdb) hashtb)) - t)) ;return value - (defsubst elmo-msgdb-set-overview (msgdb overview) (setcar msgdb overview)) @@ -413,6 +519,9 @@ content of MSGDB is changed." (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-overview-entity-get-references (entity) (and entity (aref (cdr entity) 1))) @@ -520,21 +629,11 @@ content of MSGDB is changed." (defun elmo-msgdb-overview-get-entity (id msgdb) (when id - (let ((ovht (elmo-msgdb-get-overviewht msgdb))) - (if ovht ; use overview hash + (let ((ht (elmo-msgdb-get-entity-hashtb msgdb))) + (if ht (if (stringp id) ;; ID is message-id - (elmo-get-hash-val id ovht) - (elmo-get-hash-val (format "#%d" id) ovht)) - (let* ((overview (elmo-msgdb-get-overview msgdb)) - (number-alist (elmo-msgdb-get-number-alist msgdb)) - (message-id (if (stringp id) - id ;; ID is message-id - (cdr (assq id number-alist)))) - entity) - (if message-id - (assoc message-id overview) - ;; ID is number. message-id is nil or no exists in number-alist. - (elmo-msgdb-overview-get-entity-by-number overview id))))))) + (elmo-get-hash-val id ht) + (elmo-get-hash-val (format "#%d" id) ht)))))) ;; ;; deleted message handling @@ -637,17 +736,19 @@ content of MSGDB is changed." (defun elmo-msgdb-add-msgs-to-seen-list (msgs msgdb unread-marks seen-list) ;; Add to seen list. - (let* ((number-alist (elmo-msgdb-get-number-alist msgdb)) - (mark-alist (elmo-msgdb-get-mark-alist msgdb)) - ent) + (let (mark) (while msgs - (if (setq ent (assq (car msgs) mark-alist)) - (unless (member (cadr ent) unread-marks) ;; not unread mark + (if (setq mark (elmo-msgdb-get-mark msgdb (car msgs))) + (unless (member mark unread-marks) ;; not unread mark (setq seen-list - (cons (cdr (assq (car msgs) number-alist)) seen-list))) + (cons + (elmo-msgdb-get-field msgdb (car msgs) 'message-id) + seen-list))) ;; no mark ... seen... (setq seen-list - (cons (cdr (assq (car msgs) number-alist)) seen-list))) + (cons + (elmo-msgdb-get-field msgdb (car msgs) 'message-id) + seen-list))) (setq msgs (cdr msgs))) seen-list)) @@ -753,80 +854,55 @@ Header region is supposed to be narrowed." (elmo-msgdb-overview-entity-get-date y))) (error)))))) -(defun elmo-msgdb-sort-by-date (msgdb) - (message "Sorting...") - (let ((overview (elmo-msgdb-get-overview msgdb))) - (setq overview (elmo-msgdb-overview-sort-by-date overview)) - (message "Sorting...done") - (list overview (nth 1 msgdb)(nth 2 msgdb)))) - -(defun elmo-msgdb-clear-overview-hashtb (entity hashtb) - (let (number) - (when (and entity - elmo-use-overview-hashtb - hashtb) +(defun elmo-msgdb-clear-index (msgdb entity) + (let ((ehash (elmo-msgdb-get-entity-hashtb msgdb)) + (mhash (elmo-msgdb-get-mark-hashtb msgdb)) + number) + (when (and entity ehash) (and (setq number (elmo-msgdb-overview-entity-get-number entity)) - (elmo-clear-hash-val (format "#%d" number) hashtb)) + (elmo-clear-hash-val (format "#%d" number) ehash)) (and (car entity) ;; message-id - (elmo-clear-hash-val (car entity) hashtb))))) - -(defun elmo-msgdb-make-overview-hashtb (overview &optional hashtb) - (if (and elmo-use-overview-hashtb - overview) - (let ((hashtb (or hashtb ;; append - (elmo-make-hash (length overview))))) - (while overview - ;; key is message-id - (if (caar overview) - (elmo-set-hash-val (caar overview) (car overview) hashtb)) - ;; key is number - (elmo-set-hash-val - (format "#%d" (elmo-msgdb-overview-entity-get-number (car overview))) - (car overview) hashtb) - (setq overview (cdr overview))) - hashtb) - nil)) - -(defsubst elmo-msgdb-append (msgdb msgdb-append &optional set-hash) - (list - (nconc (car msgdb) (car msgdb-append)) - (nconc (cadr msgdb) (cadr msgdb-append)) - (nconc (caddr msgdb) (caddr msgdb-append)) - (and set-hash - (elmo-msgdb-make-overview-hashtb (car msgdb-append) (nth 3 msgdb))))) - -(defsubst elmo-msgdb-clear (&optional msgdb) - (if msgdb - (list - (setcar msgdb nil) - (setcar (cdr msgdb) nil) - (setcar (cddr msgdb) nil) - (setcar (nthcdr 3 msgdb) (elmo-msgdb-make-overview-hashtb nil))) - (list nil nil nil (elmo-msgdb-make-overview-hashtb nil)))) + (elmo-clear-hash-val (car entity) ehash))) + (when (and entity mhash) + (and (setq number (elmo-msgdb-overview-entity-get-number entity)) + (elmo-clear-hash-val (format "#%d" number) mhash))))) + +(defun elmo-msgdb-make-index (msgdb &optional overview mark-alist) + "Append OVERVIEW and MARK-ALIST to the index of MSGDB. +If OVERVIEW and MARK-ALIST are nil, make index for current MSGDB. +Return the updated INDEX." + (when msgdb + (let* ((overview (or overview (elmo-msgdb-get-overview msgdb))) + (mark-alist (or mark-alist (elmo-msgdb-get-mark-alist msgdb))) + (index (elmo-msgdb-get-index msgdb)) + (ehash (or (car index) ;; append + (elmo-make-hash (length overview)))) + (mhash (or (cdr index) ;; append + (elmo-make-hash (length overview))))) + (while overview + ;; key is message-id + (if (caar overview) + (elmo-set-hash-val (caar overview) (car overview) ehash)) + ;; key is number + (elmo-set-hash-val + (format "#%d" + (elmo-msgdb-overview-entity-get-number (car overview))) + (car overview) ehash) + (setq overview (cdr overview))) + (while mark-alist + ;; key is number + (elmo-set-hash-val + (format "#%d" (car (car mark-alist))) + (car mark-alist) mhash) + (setq mark-alist (cdr mark-alist))) + (setq index (or index (cons ehash mhash))) + (elmo-msgdb-set-index msgdb index) + index))) (defsubst elmo-folder-get-info (folder &optional hashtb) (elmo-get-hash-val folder (or hashtb elmo-folder-info-hashtb))) -(defun elmo-folder-set-info-hashtb (folder max numbers &optional new unread) - (let ((info (elmo-folder-get-info folder))) - (when info - (or new (setq new (nth 0 info))) - (or unread (setq unread (nth 1 info))) - (or numbers (setq numbers (nth 2 info))) - (or max (setq max (nth 3 info)))) - (elmo-set-hash-val folder - (list new unread numbers max) - elmo-folder-info-hashtb))) - -(defun elmo-folder-set-info-max-by-numdb (folder msgdb-number) - (let ((num-db (sort (mapcar 'car msgdb-number) '<))) - (elmo-folder-set-info-hashtb - folder - (or (nth (max 0 (1- (length num-db))) num-db) 0) - nil ;;(length num-db) - ))) - (defun elmo-folder-get-info-max (folder) "Get folder info from cache." (nth 3 (elmo-folder-get-info folder))) @@ -837,22 +913,6 @@ Header region is supposed to be narrowed." (defun elmo-folder-get-info-unread (folder) (nth 1 (elmo-folder-get-info folder))) -(defun elmo-folder-info-make-hashtb (info-alist hashtb) - (let* ((hashtb (or hashtb - (elmo-make-hash (length info-alist))))) - (mapcar - '(lambda (x) - (let ((info (cadr x))) - (and (intern-soft (car x) hashtb) - (elmo-set-hash-val (car x) - (list (nth 2 info) ;; new - (nth 3 info) ;; unread - (nth 1 info) ;; length - (nth 0 info)) ;; max - hashtb)))) - info-alist) - (setq elmo-folder-info-hashtb hashtb))) - (defsubst elmo-msgdb-location-load (dir) (elmo-object-load (expand-file-name diff --git a/elmo/elmo-multi.el b/elmo/elmo-multi.el index 800cf34..627db8c 100644 --- a/elmo/elmo-multi.el +++ b/elmo/elmo-multi.el @@ -237,7 +237,7 @@ (elmo-folder-set-msgdb-internal folder (elmo-msgdb-append (elmo-folder-msgdb folder) - append-msgdb t)) + append-msgdb)) (length to-be-deleted)) 0)) diff --git a/elmo/elmo-util.el b/elmo/elmo-util.el index 6fe0b61..90cc8be 100644 --- a/elmo/elmo-util.el +++ b/elmo/elmo-util.el @@ -335,17 +335,12 @@ Return value is a cons cell of (STRUCTURE . REST)" lst) (defun elmo-list-insert (list element after) - "Insert an ELEMENT to the LIST, just after AFTER." - (let ((li list) - (curn 0) - p pn) - (while li - (if (eq (car li) after) - (setq p li pn curn li nil) - (incf curn)) - (setq li (cdr li))) - (if pn - (setcdr (nthcdr pn list) (cons element (cdr p))) + (let* ((match (memq after list)) + (rest (and match (cdr (memq after list))))) + (if match + (progn + (setcdr match (list element)) + (nconc list rest)) (nconc list (list element))))) (defun elmo-string-partial-p (string) diff --git a/elmo/elmo-vars.el b/elmo/elmo-vars.el index 2a6e0ae..37076ab 100644 --- a/elmo/elmo-vars.el +++ b/elmo/elmo-vars.el @@ -377,9 +377,6 @@ Arguments for this function are NAME, BUFFER, HOST and SERVICE.") (defvar elmo-use-decoded-cache (featurep 'xemacs) "Use cache of decoded mime charset string.") -(defvar elmo-use-overview-hashtb t - "Use hash table of overview.") - (defvar elmo-display-progress-threshold 20 "*Displaying progress gauge if number of messages are more than this value.") diff --git a/elmo/elmo.el b/elmo/elmo.el index 8b3c07a..547c88d 100644 --- a/elmo/elmo.el +++ b/elmo/elmo.el @@ -1091,7 +1091,7 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-MARK-ALIST).") "Get mark of the message. FOLDER is the ELMO folder structure. NUMBER is a number of the message." - (cadr (assq number (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder))))) + (elmo-msgdb-get-mark (elmo-folder-msgdb folder) number)) (defun elmo-folder-list-messages-mark-match (folder mark-regexp) "List messages in the FOLDER which have a mark that matches MARK-REGEXP" @@ -1108,33 +1108,13 @@ NUMBER is a number of the message." FOLDER is the ELMO folder structure. NUMBER is a number of the message. FIELD is a symbol of the field." - (case field - (message-id (elmo-msgdb-overview-entity-get-id - (elmo-msgdb-overview-get-entity - number (elmo-folder-msgdb folder)))) - (subject (elmo-msgdb-overview-entity-get-subject - (elmo-msgdb-overview-get-entity - number (elmo-folder-msgdb folder)))) - (size (elmo-msgdb-overview-entity-get-size - (elmo-msgdb-overview-get-entity - number (elmo-folder-msgdb folder)))) - (date (elmo-msgdb-overview-entity-get-date - (elmo-msgdb-overview-get-entity - number (elmo-folder-msgdb folder)))) - (to (elmo-msgdb-overview-entity-get-to - (elmo-msgdb-overview-get-entity - number (elmo-folder-msgdb folder)))) - (cc (elmo-msgdb-overview-entity-get-cc - (elmo-msgdb-overview-get-entity - number (elmo-folder-msgdb folder)))))) + (elmo-msgdb-get-field (elmo-folder-msgdb folder) number field)) (defun elmo-message-set-mark (folder number mark) "Set mark for the message in the FOLDER with NUMBER as MARK." - (elmo-msgdb-set-mark-alist + (elmo-msgdb-set-mark (elmo-folder-msgdb folder) - (elmo-msgdb-mark-set - (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder)) - number mark))) + number mark)) (luna-define-method elmo-message-use-cache-p ((folder elmo-folder) number) nil) ; default is not use cache. @@ -1161,6 +1141,19 @@ FIELD is a symbol of the field." ;; Do nothing. ) +(defsubst elmo-folder-replace-marks (folder alist) + "Replace marks of the FOLDER according to ALIST." + (let (pair) + (dolist (elem (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder))) + (when (setq pair (assoc (cadr elem) alist)) + (if (elmo-message-use-cache-p folder (car elem)) + (elmo-msgdb-set-mark (elmo-folder-msgdb folder) + (car elem) + (cdr pair)) + (elmo-msgdb-set-mark (elmo-folder-msgdb folder) + (car elem) + nil)))))) + (defun elmo-generic-folder-append-msgdb (folder append-msgdb) (if append-msgdb (let* ((number-alist (elmo-msgdb-get-number-alist append-msgdb)) @@ -1200,7 +1193,7 @@ FIELD is a symbol of the field." (elmo-folder-set-msgdb-internal folder (elmo-msgdb-append (elmo-folder-msgdb folder) - append-msgdb t)) + append-msgdb)) (length to-be-deleted)) 0)) @@ -1332,9 +1325,9 @@ If update process is interrupted, return nil." (if ignore-msgdb (progn (setq seen-list (nconc - (elmo-msgdb-mark-alist-to-seen-list - number-alist mark-alist - (concat important-mark read-uncached-mark)) + (elmo-msgdb-seen-list + (elmo-folder-msgdb folder) + (list important-mark read-uncached-mark)) seen-list)) (elmo-folder-clear folder (eq ignore-msgdb 'visible-only)))) (unless no-check (elmo-folder-check folder)) @@ -1406,19 +1399,18 @@ If update process is interrupted, return nil." (elmo-folder-msgdb folder)))) ;;; -(defun elmo-msgdb-load (folder) - (message "Loading msgdb for %s..." (elmo-folder-name-internal folder)) - (let* ((path (elmo-folder-msgdb-path folder)) - (overview (elmo-msgdb-overview-load path)) - (msgdb (list overview - (elmo-msgdb-number-load path) - (elmo-msgdb-mark-load path) - (elmo-msgdb-make-overview-hashtb overview)))) - (message "Loading msgdb for %s...done" (elmo-folder-name-internal folder)) +(defun elmo-msgdb-load (folder &optional silent) + (unless silent + (message "Loading msgdb for %s..." (elmo-folder-name-internal folder))) + (let ((msgdb (elmo-load-msgdb (elmo-folder-msgdb-path folder)))) (elmo-folder-set-info-max-by-numdb folder (elmo-msgdb-get-number-alist msgdb)) + + (unless silent + (message "Loading msgdb for %s...done" + (elmo-folder-name-internal folder))) msgdb)) - + (defun elmo-msgdb-delete-path (folder) (let ((path (elmo-folder-msgdb-path folder))) (if (file-directory-p path) -- 1.7.10.4