From 081863a04cec8261ebd5c8628ad8055fab9e6fb7 Mon Sep 17 00:00:00 2001 From: hmurata Date: Sun, 18 Apr 2004 11:33:27 +0000 Subject: [PATCH] * elmo.el (elmo-folder): Add new slot `flag-table'. (elmo-folder-flag-table): New API. (elmo-folder-close-flag-table): Ditto. (elmo-folder-preserve-falgs): New function. (elmo-generic-folder-append-messages): Use `elmo-folder-flag-table' and `elmo-folder-close-flag-table'. Flag of a non-registered message, it sets to nil. Does not set flag to flag-table. * elmo-maildir.el (elmo-folder-append-buffer): Use `elmo-folder-preserve-falgs'. (elmo-folder-append-messages): Use `elmo-folder-flag-table' and `elmo-folder-close-flag-table'. * elmo-archive.el (elmo-folder-append-buffer): Fix interface. (elmo-archive-folder-append-buffer): Use `elmo-folder-preserve-falgs'. * elmo-cache.el (elmo-folder-append-buffer): Ditto. * elmo-imap4.el (elmo-folder-append-buffer): Ditto. * elmo-localdir.el (elmo-folder-append-buffer): Ditto. (elmo-folder-append-messages): Use `elmo-folder-flag-table' and `elmo-folder-close-flag-table'. --- elmo/ChangeLog | 26 ++++++++++++++++++++++++++ elmo/elmo-archive.el | 11 ++++++++--- elmo/elmo-cache.el | 1 + elmo/elmo-imap4.el | 3 +++ elmo/elmo-localdir.el | 12 ++++-------- elmo/elmo-maildir.el | 12 ++++-------- elmo/elmo.el | 48 +++++++++++++++++++++++++++++++++++++++++------- 7 files changed, 87 insertions(+), 26 deletions(-) diff --git a/elmo/ChangeLog b/elmo/ChangeLog index 19a2039..24527ae 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,5 +1,31 @@ 2004-04-18 Hiroya Murata + * elmo.el (elmo-folder): Add new slot `flag-table'. + (elmo-folder-flag-table): New API. + (elmo-folder-close-flag-table): Ditto. + (elmo-folder-preserve-falgs): New function. + (elmo-generic-folder-append-messages): Use + `elmo-folder-flag-table' and `elmo-folder-close-flag-table'. + Flag of a non-registered message, it sets to nil. + Does not set flag to flag-table. + + * elmo-maildir.el (elmo-folder-append-buffer): Use + `elmo-folder-preserve-falgs'. + (elmo-folder-append-messages): Use `elmo-folder-flag-table' and + `elmo-folder-close-flag-table'. + + * elmo-archive.el (elmo-folder-append-buffer): Fix interface. + (elmo-archive-folder-append-buffer): Use + `elmo-folder-preserve-falgs'. + + * elmo-cache.el (elmo-folder-append-buffer): Ditto. + + * elmo-imap4.el (elmo-folder-append-buffer): Ditto. + + * elmo-localdir.el (elmo-folder-append-buffer): Ditto. + (elmo-folder-append-messages): Use `elmo-folder-flag-table' and + `elmo-folder-close-flag-table'. + * elmo-version.el (elmo-version): Up to 2.11.26. 2004-04-18 Yoichi NAKAYAMA diff --git a/elmo/elmo-archive.el b/elmo/elmo-archive.el index 452ff4d..2156f3f 100644 --- a/elmo/elmo-archive.el +++ b/elmo/elmo-archive.el @@ -578,11 +578,11 @@ TYPE specifies the archiver's symbol." (elmo-archive-message-fetch-internal folder number)) (luna-define-method elmo-folder-append-buffer ((folder elmo-archive-folder) - &optional flag number) - (elmo-archive-folder-append-buffer folder flag number)) + &optional flags number) + (elmo-archive-folder-append-buffer folder flags number)) ;; verrrrrry slow!! -(defun elmo-archive-folder-append-buffer (folder flag number) +(defun elmo-archive-folder-append-buffer (folder flags number) (let* ((type (elmo-archive-folder-archive-type-internal folder)) (prefix (elmo-archive-folder-archive-prefix-internal folder)) (arc (elmo-archive-get-archive-name folder)) @@ -617,6 +617,11 @@ TYPE specifies the archiver's symbol." (as-binary-output-file (write-region (point-min) (point-max) newfile nil 'no-msg)) (elmo-archive-call-method method (list arc newfile)) + (elmo-folder-preserve-falgs + folder + (with-current-buffer src-buffer + (elmo-msgdb-get-message-id-from-buffer)) + flags) t) nil)))))) diff --git a/elmo/elmo-cache.el b/elmo/elmo-cache.el index 7ea9ae7..aeaf6d0 100644 --- a/elmo/elmo-cache.el +++ b/elmo/elmo-cache.el @@ -127,6 +127,7 @@ (not (file-exists-p file))) (write-region-as-binary (point-min) (point-max) file nil 'no-msg) + (elmo-folder-preserve-falgs folder msgid flags) t))))) (luna-define-method elmo-map-folder-delete-messages ((folder elmo-cache-folder) diff --git a/elmo/elmo-imap4.el b/elmo/elmo-imap4.el index 3f694d4..93c520c 100644 --- a/elmo/elmo-imap4.el +++ b/elmo/elmo-imap4.el @@ -2595,6 +2595,9 @@ If optional argument REMOVE is non-nil, remove FLAG." " () ") (elmo-imap4-buffer-literal send-buffer)))) (kill-buffer send-buffer)) + (when result + (elmo-folder-preserve-falgs + folder (elmo-msgdb-get-message-id-from-buffer) flags)) result) ;; Unplugged (if elmo-enable-disconnected-operation diff --git a/elmo/elmo-localdir.el b/elmo/elmo-localdir.el index fff92e8..1077733 100644 --- a/elmo/elmo-localdir.el +++ b/elmo/elmo-localdir.el @@ -206,12 +206,8 @@ (not (file-exists-p filename))) (write-region-as-binary (point-min) (point-max) filename nil 'no-msg) - (let* ((path (elmo-folder-msgdb-path folder)) - (table (elmo-flag-table-load path)) - (msgid (std11-field-body "message-id"))) - (when msgid - (elmo-flag-table-set table msgid flags) - (elmo-flag-table-save path table))) + (elmo-folder-preserve-falgs + folder (elmo-msgdb-get-message-id-from-buffer) flags) t))) (luna-define-method elmo-folder-append-messages :around @@ -220,7 +216,7 @@ (if (elmo-folder-message-file-p src-folder) (let ((src-msgdb-exists (not (zerop (elmo-folder-length src-folder)))) (dir (elmo-localdir-folder-directory-internal folder)) - (table (elmo-flag-table-load (elmo-folder-msgdb-path folder))) + (table (elmo-folder-flag-table folder)) (succeeds numbers) (next-num (1+ (car (elmo-folder-status folder)))) flags id) @@ -246,7 +242,7 @@ (1+ (car (elmo-folder-status folder))) (1+ next-num))))) (when (elmo-folder-persistent-p folder) - (elmo-flag-table-save (elmo-folder-msgdb-path folder) table)) + (elmo-folder-close-flag-table folder)) succeeds) (luna-call-next-method))) diff --git a/elmo/elmo-maildir.el b/elmo/elmo-maildir.el index e88906d..0c73c9e 100644 --- a/elmo/elmo-maildir.el +++ b/elmo/elmo-maildir.el @@ -411,12 +411,8 @@ file name for maildir directories." (expand-file-name (concat "new/" (file-name-nondirectory filename)) basedir)) - (let* ((path (elmo-folder-msgdb-path folder)) - (table (elmo-flag-table-load path)) - (msgid (std11-field-body "message-id"))) - (when msgid - (elmo-flag-table-set table msgid flags) - (elmo-flag-table-save path table))) + (elmo-folder-preserve-falgs + folder (elmo-msgdb-get-message-id-from-buffer) flags) t) ;; If an error occured, return nil. (error)))) @@ -455,7 +451,7 @@ file name for maildir directories." (if (elmo-folder-message-file-p src-folder) (let ((src-msgdb-exists (not (zerop (elmo-folder-length src-folder)))) (dir (elmo-maildir-folder-directory-internal folder)) - (table (elmo-flag-table-load (elmo-folder-msgdb-path folder))) + (table (elmo-folder-flag-table folder)) (succeeds numbers) filename flags id) (dolist (number numbers) @@ -476,7 +472,7 @@ file name for maildir directories." (elmo-flag-table-set table id flags)) (elmo-progress-notify 'elmo-folder-move-messages)) (when (elmo-folder-persistent-p folder) - (elmo-flag-table-save (elmo-folder-msgdb-path folder) table)) + (elmo-folder-close-flag-table folder)) succeeds) (luna-call-next-method))) diff --git a/elmo/elmo.el b/elmo/elmo.el index 3db2fcc..c56eddd 100644 --- a/elmo/elmo.el +++ b/elmo/elmo.el @@ -117,6 +117,7 @@ If a folder name begins with PREFIX, use BACKEND." path ; directory path for msgdb. msgdb ; msgdb (may be nil). killed-list ; killed list. + flag-table ; flag table. persistent ; non-nil if persistent. process-duplicates ; read or hide biff ; folder for biff @@ -375,8 +376,9 @@ FOLDER is the ELMO folder structure.") (luna-define-generic elmo-folder-append-buffer (folder &optional flags number) "Append current buffer as a new message. -FOLDER is the destination folder(ELMO folder structure). +FOLDER is the destination folder (ELMO folder structure). FLAGS is the status of appended message (list of symbols). +If it is nil, it is not that there is no flag and what is not defined is meant. If optional argument NUMBER is specified, the new message number is set \(if possible\). Return nil on failure.") @@ -827,6 +829,39 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-FLAG-ALIST).") (luna-define-method elmo-folder-have-subfolder-p ((folder elmo-folder)) t) +;; Flag table +(luna-define-generic elmo-folder-flag-table (folder &optional if-exists) + "Return the flag-table of FOLDER. +If optional argument IF-EXISTS is nil, load on demand. +\(For internal use only.\)") + +(luna-define-generic elmo-folder-close-flag-table (folder) + "Close flag-table of FOLDER.") + +(luna-define-method elmo-folder-flag-table ((folder elmo-folder) + &optional if-exists) + (or (elmo-folder-flag-table-internal folder) + (unless if-exists + (elmo-folder-set-flag-table-internal + folder + (elmo-flag-table-load (elmo-folder-msgdb-path folder)))))) + +(luna-define-method elmo-folder-close-flag-table ((folder elmo-folder)) + (elmo-flag-table-save (elmo-folder-msgdb-path folder) + (elmo-folder-flag-table folder)) + (elmo-folder-set-flag-table-internal folder nil)) + +(defun elmo-folder-preserve-falgs (folder msgid flags) + "Preserve FLAGS into FOLDER for a message that has MSGID." + (when (and msgid flags) + (let ((flag-table (elmo-folder-flag-table folder 'if-exists)) + load-now) + (when (setq load-now (null flag-table)) + (setq flag-table (elmo-folder-flag-table folder))) + (elmo-flag-table-set flag-table msgid flags) + (when load-now + (elmo-folder-close-flag-table folder))))) + ;;; Folder info ;; Folder info is a message number information cache (hashtable) (defsubst elmo-folder-get-info (folder &optional hashtb) @@ -975,7 +1010,7 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-FLAG-ALIST).") (let ((src-msgdb-exists (not (zerop (elmo-folder-length src-folder)))) unseen table flags succeed-numbers failure cache id) - (setq table (elmo-flag-table-load (elmo-folder-msgdb-path folder))) + (setq table (elmo-folder-flag-table folder)) (with-temp-buffer (set-buffer-multibyte nil) (while numbers @@ -983,7 +1018,8 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-FLAG-ALIST).") id (and src-msgdb-exists (elmo-message-field src-folder (car numbers) 'message-id)) - flags (elmo-message-flags src-folder (car numbers))) + flags (or (elmo-message-flags src-folder (car numbers)) + (and id '(read)))) (condition-case nil (setq cache (elmo-file-cache-get id) failure @@ -1007,18 +1043,16 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-FLAG-ALIST).") (> (buffer-size) 0) (elmo-folder-append-buffer folder - (or flags '(read)) + flags (if same-number (car numbers)))))) (error (setq failure t))) ;; FETCH & APPEND finished (unless failure - (when id - (elmo-flag-table-set table id flags)) (setq succeed-numbers (cons (car numbers) succeed-numbers))) (elmo-progress-notify 'elmo-folder-move-messages) (setq numbers (cdr numbers))) (when (elmo-folder-persistent-p folder) - (elmo-flag-table-save (elmo-folder-msgdb-path folder) table)) + (elmo-folder-close-flag-table folder)) succeed-numbers))) ;; Arguments should be reduced. -- 1.7.10.4