From 107c307c8be7235fd1d35a22107c4df7acd736fe Mon Sep 17 00:00:00 2001 From: teranisi Date: Sun, 27 Oct 2002 04:42:43 +0000 Subject: [PATCH] * elmo.el (elmo-folder-list-flagged): New generic function. (elmo-folder-list-importants): New implementation. (elmo-folder-list-answereds): Ditto. (elmo-folder-search-fast): Use 'flag' instead of 'mark'; Added 'digest'. (elmo-message-cached-p): New function. (elmo-message-set-flag): Ditto (no content). (elmo-message-unset-flag): Ditto. (elmo-folder-list-messages-mark-match): Abolish. * elmo-util.el (elmo-regexp-opt): New function. * elmo-msgdb.el (elmo-msgdb-get-cached): New function. (elmo-msgdb-match-condition-primitive): Use 'flag' instead of 'mark'; Added 'digest'. (elmo-msgdb-list-flagged): New function. * elmo-imap4.el (elmo-imap4-folder-list-digest-plugged): New function. (elmo-imap4-search-internal-primitive): Use 'flag' instead of 'mark'; Added 'digest'. * elmo-filter.el (elmo-folder-diff): Use 'flag' instead of 'mark'. --- elmo/ChangeLog | 25 ++++++++++++++ elmo/elmo-filter.el | 3 +- elmo/elmo-imap4.el | 7 +++- elmo/elmo-msgdb.el | 47 +++++++++++++++++++++++++- elmo/elmo-util.el | 12 +++++++ elmo/elmo.el | 91 ++++++++++++++++++++++++++++++++------------------- 6 files changed, 149 insertions(+), 36 deletions(-) diff --git a/elmo/ChangeLog b/elmo/ChangeLog index f30669c..040822d 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,3 +1,28 @@ +2002-10-27 Yuuichi Teranishi + + * elmo.el (elmo-folder-list-flagged): New generic function. + (elmo-folder-list-importants): New implementation. + (elmo-folder-list-answereds): Ditto. + (elmo-folder-search-fast): Use 'flag' instead of 'mark'; + Added 'digest'. + (elmo-message-cached-p): New function. + (elmo-message-set-flag): Ditto (no content). + (elmo-message-unset-flag): Ditto. + (elmo-folder-list-messages-mark-match): Abolish. + + * elmo-util.el (elmo-regexp-opt): New function. + + * elmo-msgdb.el (elmo-msgdb-get-cached): New function. + (elmo-msgdb-match-condition-primitive): Use 'flag' instead of 'mark'; + Added 'digest'. + (elmo-msgdb-list-flagged): New function. + + * elmo-imap4.el (elmo-imap4-folder-list-digest-plugged): New function. + (elmo-imap4-search-internal-primitive): Use 'flag' instead of 'mark'; + Added 'digest'. + + * elmo-filter.el (elmo-folder-diff): Use 'flag' instead of 'mark'. + 2002-10-26 Yuuichi Teranishi * elmo-version.el (elmo-version): Up to 2.11.0. diff --git a/elmo/elmo-filter.el b/elmo/elmo-filter.el index 33b9808..822e13a 100644 --- a/elmo/elmo-filter.el +++ b/elmo/elmo-filter.el @@ -216,8 +216,9 @@ diff) (if (vectorp condition) (cond - ((and (string= (elmo-filter-key condition) "mark") + ((and (string= (elmo-filter-key condition) "flag") (or (string= (elmo-filter-value condition) "any") + (string= (elmo-filter-value condition) "digest") (string= (elmo-filter-value condition) "unread"))) (setq diff (elmo-folder-diff (elmo-filter-folder-target-internal folder))) diff --git a/elmo/elmo-imap4.el b/elmo/elmo-imap4.el index 5e90a59..b3e62c7 100644 --- a/elmo/elmo-imap4.el +++ b/elmo/elmo-imap4.el @@ -1893,6 +1893,9 @@ Return nil if no complete line has arrived." (defun elmo-imap4-folder-list-any-plugged (folder) (elmo-imap4-list folder "or answered or unseen flagged")) +(defun elmo-imap4-folder-list-digest-plugged (folder) + (elmo-imap4-list folder "or unseen flagged")) + (luna-define-method elmo-folder-use-flag-p ((folder elmo-imap4-folder)) (not (string-match elmo-imap4-disuse-server-flag-mailbox-regexp (elmo-imap4-folder-mailbox-internal folder)))) @@ -2124,7 +2127,7 @@ If optional argument REMOVE is non-nil, remove FLAG." numbers))) (mapcar '(lambda (x) (delete x numbers)) rest) numbers)) - ((string= "mark" search-key) + ((string= "flag" search-key) (cond ((string= "unread" (elmo-filter-value filter)) (elmo-folder-list-unreads folder)) @@ -2132,6 +2135,8 @@ If optional argument REMOVE is non-nil, remove FLAG." (elmo-folder-list-importants folder)) ((string= "answered" (elmo-filter-value filter)) (elmo-folder-list-answereds folder)) + ((string= "digest" (elmo-filter-value filter)) + (elmo-imap4-folder-list-digest-plugged folder)) ((string= "any" (elmo-filter-value filter)) (elmo-imap4-folder-list-any-plugged folder)))) ((or (string= "since" search-key) diff --git a/elmo/elmo-msgdb.el b/elmo/elmo-msgdb.el index 7424186..bbe7d43 100644 --- a/elmo/elmo-msgdb.el +++ b/elmo/elmo-msgdb.el @@ -120,6 +120,11 @@ if MARK is nil, mark is removed." ;; return value. t)) +(defun elmo-msgdb-get-cached (msgdb number) + "Return non-nil if message is cached." + (not (member (elmo-msgdb-get-mark msgdb number) + (elmo-msgdb-uncached-marks)))) + (defun elmo-msgdb-set-cached (msgdb number cached use-cache) "Set message cache status. If mark is changed, return non-nil." @@ -637,12 +642,17 @@ header separator." entity) numbers))) (string-to-int (elmo-filter-value condition))))) - ((string= key "mark") + ((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)))) @@ -1171,6 +1181,41 @@ Return the updated INDEX." elmo-msgdb-location-filename dir) alist)) +(defun elmo-msgdb-list-flagged (msgdb flag) + (let ((case-fold-search nil) + mark-regexp matched) + (case flag + (new + (setq mark-regexp (regexp-quote elmo-msgdb-new-mark))) + (unread + (setq mark-regexp (elmo-regexp-opt (elmo-msgdb-unread-marks)))) + (answered + (setq mark-regexp (elmo-regexp-opt (elmo-msgdb-unread-marks)))) + (important + (setq mark-regexp (regexp-quote elmo-msgdb-important-mark))) + (read + (setq mark-regexp (elmo-regexp-opt (elmo-msgdb-unread-marks)))) + (digest + (setq mark-regexp (elmo-regexp-opt + (append (elmo-msgdb-unread-marks) + (list elmo-msgdb-important-mark))))) + (any + (setq mark-regexp (elmo-regexp-opt + (append + (elmo-msgdb-unread-marks) + (elmo-msgdb-answered-marks) + (list elmo-msgdb-important-mark)))))) + (when mark-regexp + (if (eq flag 'read) + (dolist (number (elmo-msgdb-get-number-alist msgdb)) + (unless (string-match mark-regexp (elmo-msgdb-get-mark + msgdb number)) + (setq matched (cons number matched)))) + (dolist (elem (elmo-msgdb-get-mark-alist msgdb)) + (if (string-match mark-regexp (cadr elem)) + (setq matched (cons (car elem) matched)))))) + matched)) + (put 'elmo-msgdb-do-each-entity 'lisp-indent-function '1) (def-edebug-spec elmo-msgdb-do-each-entity ((symbolp form &rest form) &rest form)) diff --git a/elmo/elmo-util.el b/elmo/elmo-util.el index 8e505ee..7d5a1de 100644 --- a/elmo/elmo-util.el +++ b/elmo/elmo-util.el @@ -1948,6 +1948,18 @@ If ALIST is nil, `elmo-obsolete-variable-alist' is used." elmo-msgdb-directory) elmo-dop-queue)) +(if (and (fboundp 'regexp-opt) + (not (featurep 'xemacs))) + (defalias 'elmo-regexp-opt 'regexp-opt) + (defun elmo-regexp-opt (strings &optional paren) + "Return a regexp to match a string in STRINGS. +Each string should be unique in STRINGS and should not contain any regexps, +quoted or not. If optional PAREN is non-nil, ensure that the returned regexp +is enclosed by at least one regexp grouping construct." + (let ((open-paren (if paren "\\(" "")) (close-paren (if paren "\\)" ""))) + (concat open-paren (mapconcat 'regexp-quote strings "\\|") + close-paren)))) + (require 'product) (product-provide (provide 'elmo-util) (require 'elmo-version)) diff --git a/elmo/elmo.el b/elmo/elmo.el index 2676cf0..f4e9849 100644 --- a/elmo/elmo.el +++ b/elmo/elmo.el @@ -124,8 +124,7 @@ If a folder name begins with PREFIX, use BACKEND." ;;;###autoload (defun elmo-make-folder (name &optional non-persistent) "Make an ELMO folder structure specified by NAME. -If optional argument NON-PERSISTENT is non-nil, folder is treated as - non-persistent." +If optional argument NON-PERSISTENT is non-nil, the folder msgdb is not saved." (let ((type (elmo-folder-type name)) prefix split class folder original) (setq original (elmo-string name)) @@ -229,14 +228,6 @@ If second optional IN-MSGDB is non-nil, only messages in the msgdb are listed." (luna-define-generic elmo-folder-list-answereds (folder) "Return a list of answered message numbers contained in FOLDER.") -(luna-define-method elmo-folder-list-unreads ((folder elmo-folder)) - (delq nil - (mapcar - (lambda (x) - (if (member (cadr x) (elmo-msgdb-unread-marks)) - (car x))) - (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder))))) - ;; TODO: Should reconsider the structure of global mark. (defun elmo-folder-list-messages-with-global-mark (folder mark) (let (entity msgs) @@ -255,19 +246,33 @@ If second optional IN-MSGDB is non-nil, only messages in the msgdb are listed." msgs)))) msgs)) +(luna-define-generic elmo-folder-list-flagged (folder flag &optional in-msgdb) + "List messages in the FOLDER with FLAG. +FLAG is a symbol which is one of the following: + `new' (new messages) + `unread' (unread messages (new messages are included)) + `answered' (answered or forwarded) + `important' (marked as important) +'sugar' flags: + `read' (not unread) + `digest' (unread + important) + `any' (digest + answered) + +If optional IN-MSGDB is non-nil, retrieve flag information from msgdb.") + +(luna-define-method elmo-folder-list-flagged ((folder elmo-folder) flag + &optional in-msgdb) + ;; Currently, only in-msgdb is implemented. + (elmo-msgdb-list-flagged (elmo-folder-msgdb folder) flag)) + +(luna-define-method elmo-folder-list-unreads ((folder elmo-folder)) + (elmo-msgdb-list-flagged (elmo-folder-msgdb folder) 'unread)) + (luna-define-method elmo-folder-list-importants ((folder elmo-folder)) - (elmo-folder-list-messages-mark-match folder - (regexp-quote - elmo-msgdb-important-mark))) + (elmo-msgdb-list-flagged (elmo-folder-msgdb folder) 'important)) (luna-define-method elmo-folder-list-answereds ((folder elmo-folder)) - (delq nil - (mapcar - (function - (lambda (x) - (if (member (cadr x) (elmo-msgdb-answered-marks)) - (car x)))) - (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder))))) + (elmo-msgdb-list-flagged (elmo-folder-msgdb folder) 'answered)) (luna-define-generic elmo-folder-list-messages-internal (folder &optional visible-only) @@ -731,7 +736,7 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-MARK-ALIST).") (when (and numbers (vectorp condition) (member (elmo-filter-key condition) '("first" "last" "mark"))) - (if (string= (elmo-filter-key condition) "mark") + (if (string= (elmo-filter-key condition) "flag") (let ((msgdb (elmo-folder-msgdb folder))) ;; msgdb should be synchronized at this point. (cond @@ -741,6 +746,9 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-MARK-ALIST).") (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) @@ -1109,17 +1117,44 @@ Return a cons cell of (NUMBER-CROSSPOSTS . NEW-MARK-ALIST).") folder (elmo-folder-expand-msgdb-path folder)))) +(defun elmo-message-cached-p (folder number) + "Get cache status of the message in the msgdb." + (elmo-msgdb-get-cached (elmo-folder-msgdb folder) number)) + (defun elmo-message-set-cached (folder number cached) - "Set cache status of the message mark. + "Set cache status of the message in the msgdb. FOLDER is the ELMO folder structure. NUMBER is a number of the message. -If CACHED is t, message mark is set as cached." +If CACHED is t, message is set as cached." (when (elmo-msgdb-set-cached (elmo-folder-msgdb folder) number cached (elmo-message-use-cache-p folder number)) (elmo-folder-set-mark-modified-internal folder t))) +(defun elmo-message-set-flag (folder number flag) + "Set message flag. +FOLDER is a ELMO folder structure. +NUMBER is a message number to set flag. + +FLAG is a symbol which is one of the following: + `unread' (set the message as unread) + `answered' (set the message as answered) + `important' (set the message as important) +'sugar' flag: + `read' (remove new and unread flags)") + +(defun elmo-message-unset-flag (folder number flag) + "Unset message flag. +FOLDER is a ELMO folder structure. +NUMBER is a message number to set flag. + +FLAG is a symbol which is one of the following: + `unread' (remove unread and new flag) + `answered' (remove answered flag) + `important' (remove important flag) +'sugar' flag: + `read' (set unread flag)") (defun elmo-message-mark (folder number) "Get mark of the message. @@ -1127,16 +1162,6 @@ FOLDER is the ELMO folder structure. NUMBER is a number of the message." (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" - (let ((case-fold-search nil) - matched) - (if mark-regexp - (dolist (elem (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder))) - (if (string-match mark-regexp (cadr elem)) - (setq matched (cons (car elem) matched))))) - matched)) - (defun elmo-message-field (folder number field) "Get message field value in the msgdb. FOLDER is the ELMO folder structure. -- 1.7.10.4