1 ;;; modb.el --- Message Orchestration DataBase.
3 ;; Copyright (C) 2003 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
7 ;; Keywords: mail, net news
9 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
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)
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.
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.
33 (eval-when-compile (require 'cl))
36 (require 'modb-entity)
39 (luna-define-class modb-generic () (location ; location for save.
40 message-modified ; message is modified.
41 flag-modified ; flag is modified.
43 (luna-define-internal-accessors 'modb-generic))
45 (luna-define-generic elmo-msgdb-load (msgdb)
48 (luna-define-generic elmo-msgdb-save (msgdb)
51 (luna-define-generic elmo-msgdb-location (msgdb)
52 "Return the location of MSGDB.")
54 (luna-define-generic elmo-msgdb-message-modified-p (msgdb)
55 "Return non-nil if message is modified.")
57 (luna-define-generic elmo-msgdb-flag-modified-p (msgdb)
58 "Return non-nil if flag is modified.")
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.")
64 (luna-define-generic elmo-msgdb-clear (msgdb)
65 "Clear the MSGDB structure.")
67 (luna-define-generic elmo-msgdb-length (msgdb)
68 "Return number of messages in the MSGDB")
70 (luna-define-generic elmo-msgdb-flags (msgdb number)
71 "Return a list of flag which corresponds to the message with NUMBER.")
73 (luna-define-generic elmo-msgdb-set-flag (msgdb number 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 `read' ... Message which is already read.
80 `important' ... Message which is important.
81 `answered' ... Message which is answered.
82 `cached' ... Message which is cached.")
84 (luna-define-generic elmo-msgdb-unset-flag (msgdb number flag)
86 MSGDB is the ELMO msgdb.
87 NUMBER is a message number to set flag.
88 FLAG is a symbol which is one of the following:
89 `new' ... Message which is new.
90 `read' ... Message which is already read.
91 `important' ... Message which is important.
92 `answered' ... Message which is answered.
93 `cached' ... Message which is cached.")
95 (luna-define-generic elmo-msgdb-flag-count (msgdb)
96 "Return a list of cons cell as (flag . count).
97 The count is number of message which is set flag in the MSGDB.")
99 (luna-define-generic elmo-msgdb-list-messages (msgdb)
100 "Return a list of message numbers in the MSGDB.")
102 (luna-define-generic elmo-msgdb-list-flagged (msgdb flag)
103 "Return a list of message numbers which is set FLAG in the MSGDB.")
105 (luna-define-generic elmo-msgdb-search (msgdb condition &optional numbers)
106 "Search and return list of message numbers.
107 MSGDB is the ELMO msgdb structure.
108 CONDITION is a condition structure for searching.
109 If optional argument NUMBERS is specified and is a list of message numbers,
110 messages are searched from the list.
111 Return t if the condition is unsupported.")
113 (luna-define-generic elmo-msgdb-match-condition (msgdb condition number
115 "Check whether the condition of the message is satisfied or not.
116 MSGDB is the msgdb to search from.
117 CONDITION is the search condition.
118 NUMBER is the message number to check.
119 If optional argument NUMBERS is specified and is a list of message numbers,
120 messages are searched from the list.
121 Return CONDITION itself if no entity exists in msgdb.")
123 (luna-define-generic elmo-msgdb-append-entity (msgdb entity &optional flags)
124 "Append a ENTITY with FLAGS into the MSGDB.
125 Return non-nil if message-id of entity is duplicated.")
127 (luna-define-generic elmo-msgdb-delete-messages (msgdb numbers)
128 "Delete messages which are contained NUMBERS from MSGDB.
129 Return non-nil if messages is deleted successfully.")
131 (luna-define-generic elmo-msgdb-sort-entities (msgdb predicate
133 "Sort entities of MSGDB, comparing with PREDICATE.
134 PREDICATE is called with two entities and APP-DATA.
135 Should return non-nil if the first entity is \"less\" than the second.")
137 (luna-define-generic elmo-msgdb-message-entity (msgdb key)
138 "Return the message-entity structure which matches to the KEY.
139 KEY is a number or a string.
140 A number is for message number in the MSGDB.
141 A string is for message-id of the message.")
143 (luna-define-generic elmo-msgdb-message-entity-handler (msgdb)
144 "Get modb entity handler instance which corresponds to the MSGDB.")
146 ;;; generic implement
148 (luna-define-method elmo-msgdb-load ((msgdb modb-generic))
151 (luna-define-method elmo-msgdb-location ((msgdb modb-generic))
152 (modb-generic-location-internal msgdb))
154 (luna-define-method elmo-msgdb-message-modified-p ((msgdb modb-generic))
155 (modb-generic-message-modified-internal msgdb))
157 (luna-define-method elmo-msgdb-flag-modified-p ((msgdb modb-generic))
158 (modb-generic-flag-modified-internal msgdb))
160 (luna-define-method elmo-msgdb-append ((msgdb modb-generic) msgdb-append)
162 (dolist (number (elmo-msgdb-list-messages msgdb-append))
163 (when (elmo-msgdb-append-entity
165 (elmo-msgdb-message-entity msgdb-append number)
166 (elmo-msgdb-flags msgdb-append number))
167 (setq duplicates (cons number duplicates))))
170 (luna-define-method elmo-msgdb-clear ((msgdb modb-generic))
171 (modb-generic-set-message-modified-internal msgdb nil)
172 (modb-generic-set-flag-modified-internal msgdb nil))
174 (luna-define-method elmo-msgdb-length ((msgdb modb-generic))
177 (luna-define-method elmo-msgdb-search ((msgdb modb-generic)
178 condition &optional numbers)
181 (luna-define-method elmo-msgdb-match-condition ((msgdb modb-generic)
185 (let ((entity (elmo-msgdb-message-entity msgdb number)))
187 (elmo-msgdb-message-match-condition
188 (elmo-msgdb-message-entity-handler msgdb)
191 (elmo-msgdb-flags msgdb number)
192 (or numbers (elmo-msgdb-list-messages msgdb)))
195 (luna-define-method elmo-msgdb-message-entity-handler ((msgdb modb-generic))
196 (or modb-entity-default-cache-internal
197 (setq modb-entity-default-cache-internal
198 (luna-make-entity modb-entity-default-handler))))
200 ;; for on demand loading
201 (provide 'modb-generic)
204 (product-provide (provide 'modb) (require 'elmo-version))
206 ;;; modb.el ends here