(modb-legacy-flag-list): New constant.
[elisp/wanderlust.git] / elmo / modb.el
1 ;;; modb.el --- Message Orchestration DataBase.
2
3 ;; Copyright (C) 2003 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;;      Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
7 ;; Keywords: mail, net news
8
9 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25 ;;
26
27 ;;; Commentary:
28 ;;
29
30 ;;; Code:
31 ;;
32
33 (eval-when-compile (require 'cl))
34
35 (require 'luna)
36 (require 'modb-entity)
37
38 (eval-and-compile
39   (luna-define-class modb-generic () (location         ; location for save.
40                                       message-modified ; message is modified.
41                                       flag-modified    ; flag is modified.
42                                       ))
43   (luna-define-internal-accessors 'modb-generic))
44
45 (luna-define-generic elmo-msgdb-load (msgdb)
46   "Load the MSGDB.")
47
48 (luna-define-generic elmo-msgdb-save (msgdb)
49   "Save the MSGDB.")
50
51 (luna-define-generic elmo-msgdb-location (msgdb)
52   "Return the location of MSGDB.")
53
54 (luna-define-generic elmo-msgdb-message-modified-p (msgdb)
55   "Return non-nil if message is modified.")
56
57 (luna-define-generic elmo-msgdb-flag-modified-p (msgdb)
58   "Return non-nil if flag is modified.")
59
60 (luna-define-generic elmo-msgdb-append (msgdb msgdb-append)
61   "Append the MSGDB-APPEND to the MSGDB.
62 Return a list of messages which have duplicated message-id.")
63
64 (luna-define-generic elmo-msgdb-clear (msgdb)
65   "Clear the MSGDB structure.")
66
67 (luna-define-generic elmo-msgdb-length (msgdb)
68   "Return number of messages in the MSGDB")
69
70 (luna-define-generic elmo-msgdb-flags (msgdb number)
71   "Return a list of flag which corresponds to the message with NUMBER.")
72
73 (luna-define-generic elmo-msgdb-set-flag (msgdb number flag)
74   "Set message flag.
75 MSGDB is the ELMO msgdb.
76 NUMBER is a message number to set flag.
77 FLAG is a symbol which is one of the following:
78   `new'       ... Message which is new.
79   `unread'    ... Message which is not read.
80   `important' ... Message which is important.
81   `answered'  ... Message which is answered.
82   `cached'    ... Message which is cached.
83 'sugar' flag:
84   `read'      ... Message which is already read.
85   `uncached'  ... Message which is not cached.")
86
87 (luna-define-generic elmo-msgdb-unset-flag (msgdb number flag)
88   "Unset message flag.
89 MSGDB is the ELMO msgdb.
90 NUMBER is a message number to set flag.
91 FLAG is a symbol which is one of the following:
92   `new'       ... Message which is new.
93   `unread'    ... Message which is not read.
94   `important' ... Message which is important.
95   `answered'  ... Message which is answered.
96   `cached'    ... Message which is cached.
97 'sugar' flag:
98   `read'      ... Message which is already read.
99   `uncached'  ... Message which is not cached.
100   `all'       ... Remove all flags.")
101
102 (luna-define-generic elmo-msgdb-flag-count (msgdb)
103   "Return a list of cons cell as (flag . count).
104 The count is number of message which is set flag in the MSGDB.")
105
106 (luna-define-generic elmo-msgdb-list-messages (msgdb)
107   "Return a list of message numbers in the MSGDB.")
108
109 (luna-define-generic elmo-msgdb-list-flagged (msgdb flag)
110   "Return a list of message numbers which is set FLAG in the MSGDB.")
111
112 (luna-define-generic elmo-msgdb-search (msgdb condition &optional numbers)
113   "Search and return list of message numbers.
114 MSGDB is the ELMO msgdb structure.
115 CONDITION is a condition structure for searching.
116 If optional argument NUMBERS is specified and is a list of message numbers,
117 messages are searched from the list.
118 Return t if the condition is unsupported.")
119
120 (luna-define-generic elmo-msgdb-match-condition (msgdb condition number
121                                                        &optional numbers)
122   "Check whether the condition of the message is satisfied or not.
123 MSGDB is the msgdb to search from.
124 CONDITION is the search condition.
125 NUMBER is the message number to check.
126 If optional argument NUMBERS is specified and is a list of message numbers,
127 messages are searched from the list.
128 Return CONDITION itself if no entity exists in msgdb.")
129
130 (luna-define-generic elmo-msgdb-append-entity (msgdb entity &optional flags)
131   "Append a ENTITY with FLAGS into the MSGDB.
132 Return non-nil if message-id of entity is duplicated.")
133
134 (luna-define-generic elmo-msgdb-delete-messages (msgdb numbers)
135   "Delete messages which are contained NUMBERS from MSGDB.
136 Return non-nil if messages is deleted successfully.")
137
138 (luna-define-generic elmo-msgdb-sort-entities (msgdb predicate
139                                                      &optional app-data)
140   "Sort entities of MSGDB, comparing with PREDICATE.
141 PREDICATE is called with two entities and APP-DATA.
142 Should return non-nil if the first entity is \"less\" than the second.")
143
144 (luna-define-generic elmo-msgdb-message-entity (msgdb key)
145   "Return the message-entity structure which matches to the KEY.
146 KEY is a number or a string.
147 A number is for message number in the MSGDB.
148 A string is for message-id of the message.")
149
150 (luna-define-generic elmo-msgdb-message-entity-handler (msgdb)
151   "Get modb entity handler instance which corresponds to the MSGDB.")
152
153 ;;; generic implement
154 ;;
155 (luna-define-method elmo-msgdb-load ((msgdb modb-generic))
156   t)
157
158 (luna-define-method elmo-msgdb-location ((msgdb modb-generic))
159   (modb-generic-location-internal msgdb))
160
161 (luna-define-method elmo-msgdb-message-modified-p ((msgdb modb-generic))
162   (modb-generic-message-modified-internal msgdb))
163
164 (luna-define-method elmo-msgdb-flag-modified-p ((msgdb modb-generic))
165   (modb-generic-flag-modified-internal msgdb))
166
167 (luna-define-method elmo-msgdb-append ((msgdb modb-generic) msgdb-append)
168   (let (duplicates)
169     (dolist (number (elmo-msgdb-list-messages msgdb-append))
170       (when (elmo-msgdb-append-entity
171              msgdb
172              (elmo-msgdb-message-entity msgdb-append number)
173              (elmo-msgdb-flags msgdb-append number))
174         (setq duplicates (cons number duplicates))))
175     duplicates))
176
177 (luna-define-method elmo-msgdb-clear ((msgdb modb-generic))
178   (modb-generic-set-message-modified-internal msgdb nil)
179   (modb-generic-set-flag-modified-internal msgdb nil))
180
181 (luna-define-method elmo-msgdb-length ((msgdb modb-generic))
182   0)
183
184 (luna-define-method elmo-msgdb-search ((msgdb modb-generic)
185                                        condition &optional numbers)
186   t)
187
188 (luna-define-method elmo-msgdb-match-condition ((msgdb modb-generic)
189                                                 condition
190                                                 number
191                                                 &optional numbers)
192   (let ((entity (elmo-msgdb-message-entity msgdb number)))
193     (if entity
194         (elmo-msgdb-message-match-condition
195          (elmo-msgdb-message-entity-handler msgdb)
196          condition
197          entity
198          (elmo-msgdb-flags msgdb number)
199          (or numbers (elmo-msgdb-list-messages msgdb)))
200       condition)))
201
202 (luna-define-method elmo-msgdb-message-entity-handler ((msgdb modb-generic))
203   (or modb-entity-default-cache-internal
204       (setq modb-entity-default-cache-internal
205             (luna-make-entity modb-entity-default-handler))))
206
207 ;; for on demand loading
208 (provide 'modb-generic)
209
210 (require 'product)
211 (product-provide (provide 'modb) (require 'elmo-version))
212
213 ;;; modb.el ends here