File: modb-legacy.el

package info (click to toggle)
wl-beta 2.15.9%2B0.20190205-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,260 kB
  • sloc: lisp: 51,446; sh: 191; makefile: 141
file content (589 lines) | stat: -rw-r--r-- 19,221 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
;;; modb-legacy.el --- Legacy Implement of MODB.

;; Copyright (C) 2003 Yuuichi Teranishi <teranisi@gohome.org>

;; Author: Yuuichi Teranishi <teranisi@gohome.org>
;;	Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
;; Keywords: mail, net news

;; This file is part of ELMO (Elisp Library for Message Orchestration).

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;

;;; Commentary:
;;

;;; Code:
;;

(eval-when-compile (require 'cl))

(require 'elmo-util)
(require 'modb)

;;; legacy implement
;;

(defconst modb-legacy-new-mark "N"
  "Mark for new message.")

(defconst modb-legacy-unread-uncached-mark "U"
  "Mark for unread and uncached message.")

(defconst modb-legacy-unread-cached-mark "!"
  "Mark for unread but already cached message.")

(defconst modb-legacy-read-uncached-mark "u"
  "Mark for read but uncached message.")

(defconst modb-legacy-answered-cached-mark "&"
  "Mark for answered and cached message.")

(defconst modb-legacy-answered-uncached-mark "A"
  "Mark for answered but uncached message.")

(defconst modb-legacy-important-mark "$"
  "Mark for important message.")

(defconst modb-legacy-flag-list
  '(new unread important answered cached read uncached)
  "A list of flag symbol which is supported by legacy msgdb.")

(eval-and-compile
  (luna-define-class modb-legacy (modb-generic)
		     (overview number-alist mark-alist index))
  (luna-define-internal-accessors 'modb-legacy))

;; for internal use only
(defsubst elmo-msgdb-get-overview (msgdb)
  (modb-legacy-overview-internal msgdb))

(defsubst elmo-msgdb-get-number-alist (msgdb)
  (modb-legacy-number-alist-internal msgdb))

(defsubst elmo-msgdb-get-mark-alist (msgdb)
  (modb-legacy-mark-alist-internal msgdb))

(defsubst elmo-msgdb-get-index (msgdb)
  (modb-legacy-index-internal msgdb))

(defsubst elmo-msgdb-get-entity-hashtb (msgdb)
  (car (modb-legacy-index-internal msgdb)))

(defsubst elmo-msgdb-get-mark-hashtb (msgdb)
  (cdr (modb-legacy-index-internal msgdb)))

(defsubst elmo-msgdb-get-path (msgdb)
  (elmo-msgdb-location msgdb))

(defsubst elmo-msgdb-set-overview (msgdb overview)
  (modb-legacy-set-overview-internal msgdb overview))

(defsubst elmo-msgdb-set-number-alist (msgdb number-alist)
  (modb-legacy-set-number-alist-internal msgdb number-alist))

(defsubst elmo-msgdb-set-mark-alist (msgdb mark-alist)
  (modb-legacy-set-mark-alist-internal msgdb mark-alist))

(defsubst elmo-msgdb-set-index (msgdb index)
  (modb-legacy-set-index-internal msgdb index))

(defsubst elmo-msgdb-set-path (msgdb path)
  (modb-generic-set-location-internal msgdb path))

;;;
;; Internal use only (obsolete interface)
;;
(defsubst elmo-msgdb-overview-entity-get-id-internal (entity)
  (and entity (car entity)))

(defsubst elmo-msgdb-overview-entity-get-number-internal (entity)
  (and entity (aref (cdr entity) 0)))

;;; load & save
(defun elmo-msgdb-number-load (dir)
  (elmo-object-load
   (expand-file-name elmo-msgdb-number-filename dir)))

(defun elmo-msgdb-overview-load (dir)
  (elmo-object-load
   (expand-file-name elmo-msgdb-overview-filename dir)))

(defun elmo-msgdb-mark-load (dir)
  (elmo-object-load
   (expand-file-name elmo-msgdb-mark-filename dir)))

(defun elmo-msgdb-number-save (dir obj)
  (elmo-object-save
   (expand-file-name elmo-msgdb-number-filename dir)
   obj))

(defun elmo-msgdb-mark-save (dir obj)
  (elmo-object-save
   (expand-file-name elmo-msgdb-mark-filename dir)
   obj))

(defsubst elmo-msgdb-overview-save (dir overview)
  (elmo-object-save
   (expand-file-name elmo-msgdb-overview-filename dir)
   overview))

;;;

(defsubst modb-legacy-supported-flag-p (flag)
  (memq flag modb-legacy-flag-list))

(defvar modb-legacy-unread-marks-internal nil)
(defsubst modb-legacy-unread-marks ()
  "Return an unread mark list"
  (or modb-legacy-unread-marks-internal
      (setq modb-legacy-unread-marks-internal
	    (list modb-legacy-new-mark
		  modb-legacy-unread-uncached-mark
		  modb-legacy-unread-cached-mark))))

(defvar modb-legacy-answered-marks-internal nil)
(defsubst modb-legacy-answered-marks ()
  "Return an answered mark list"
  (or modb-legacy-answered-marks-internal
      (setq modb-legacy-answered-marks-internal
	    (list modb-legacy-answered-cached-mark
		  modb-legacy-answered-uncached-mark))))

(defvar modb-legacy-uncached-marks-internal nil)
(defsubst modb-legacy-uncached-marks ()
  (or modb-legacy-uncached-marks-internal
      (setq modb-legacy-uncached-marks-internal
	    (list modb-legacy-new-mark
		  modb-legacy-answered-uncached-mark
		  modb-legacy-unread-uncached-mark
		  modb-legacy-read-uncached-mark))))

(defsubst modb-legacy-mark-to-flags (mark)
  (append
   (and (string= mark modb-legacy-new-mark)
	'(new))
   (and (string= mark modb-legacy-important-mark)
	'(important))
   (and (member mark (modb-legacy-unread-marks))
	'(unread))
   (and (member mark (modb-legacy-answered-marks))
	'(answered))
   (and (not (member mark (modb-legacy-uncached-marks)))
	'(cached))))

(defsubst modb-legacy-flags-to-mark (flags)
  (cond ((memq 'new flags)
	 modb-legacy-new-mark)
	((memq 'important flags)
	 modb-legacy-important-mark)
	((memq 'answered flags)
	 (if (memq 'cached flags)
	     modb-legacy-answered-cached-mark
	   modb-legacy-answered-uncached-mark))
	((memq 'unread flags)
	 (if (memq 'cached flags)
	     modb-legacy-unread-cached-mark
	   modb-legacy-unread-uncached-mark))
	(t
	 (if (memq 'cached flags)
	     nil
	   modb-legacy-read-uncached-mark))))

(defsubst elmo-msgdb-get-mark (msgdb number)
  "Get mark string 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.
if MARK is nil, mark is removed."
  (let ((elem (elmo-get-hash-val (format "#%d" number)
				 (elmo-msgdb-get-mark-hashtb msgdb))))
    (if elem
	(if mark
	    ;; Set mark of the elem
	    (setcar (cdr elem) mark)
	  ;; Delete elem from mark-alist
	  (elmo-msgdb-set-mark-alist
	   msgdb
	   (delq elem (elmo-msgdb-get-mark-alist msgdb)))
	  (elmo-clear-hash-val (format "#%d" number)
			       (elmo-msgdb-get-mark-hashtb msgdb)))
      (when mark
	;; Append new element.
	(elmo-msgdb-set-mark-alist
	 msgdb
	 (nconc
	  (elmo-msgdb-get-mark-alist msgdb)
	  (list (setq elem (list number mark)))))
	(elmo-set-hash-val (format "#%d" number) elem
			   (elmo-msgdb-get-mark-hashtb msgdb))))
    (modb-generic-set-flag-modified-internal msgdb t)
    ;; return value.
    t))

(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 a list of message numbers which have duplicated message-ids."
  (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))))
	   duplicates)
      (while overview
	;; key is message-id
	(if (elmo-get-hash-val (caar overview) ehash) ; duplicated.
	    (setq duplicates (cons
			      (elmo-msgdb-overview-entity-get-number-internal
			       (car overview))
			      duplicates)))
	(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-internal
		  (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)
      duplicates)))

(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-internal
			 entity))
	   (elmo-clear-hash-val (format "#%d" number) ehash))
      (and (car entity) ;; message-id
	   (elmo-clear-hash-val (car entity) ehash)))
    (when (and entity mhash)
      (and (setq number (elmo-msgdb-overview-entity-get-number-internal
			 entity))
	   (elmo-clear-hash-val (format "#%d" number) mhash)))))

;;; Implement
;;
(luna-define-method elmo-msgdb-load ((msgdb modb-legacy))
  (let ((inhibit-quit t)
	(path (elmo-msgdb-location msgdb)))
    (when (file-exists-p (expand-file-name elmo-msgdb-mark-filename path))
      (modb-legacy-set-overview-internal
       msgdb
       (elmo-msgdb-overview-load path))
      (modb-legacy-set-number-alist-internal
       msgdb
       (elmo-msgdb-number-load path))
      (modb-legacy-set-mark-alist-internal
       msgdb
       (elmo-msgdb-mark-load path))
      (elmo-msgdb-make-index msgdb)
      t)))

(luna-define-method elmo-msgdb-save ((msgdb modb-legacy))
  (let ((path (elmo-msgdb-location msgdb)))
    (when (elmo-msgdb-message-modified-p msgdb)
      (elmo-msgdb-overview-save
       path
       (modb-legacy-overview-internal msgdb))
      (elmo-msgdb-number-save
       path
       (modb-legacy-number-alist-internal msgdb))
      (modb-generic-set-message-modified-internal msgdb nil))
    (when (elmo-msgdb-flag-modified-p msgdb)
      (elmo-msgdb-mark-save
       path
       (modb-legacy-mark-alist-internal msgdb))
      (modb-generic-set-flag-modified-internal msgdb nil))))

(luna-define-method elmo-msgdb-append :around ((msgdb modb-legacy)
					       msgdb-append)
  (if (eq (luna-class-name msgdb-append)
	  'modb-legacy)
      (let (duplicates)
	(elmo-msgdb-set-overview
	 msgdb
	 (nconc (elmo-msgdb-get-overview msgdb)
		(elmo-msgdb-get-overview msgdb-append)))
	(elmo-msgdb-set-number-alist
	 msgdb
	 (nconc (elmo-msgdb-get-number-alist msgdb)
		(elmo-msgdb-get-number-alist msgdb-append)))
	(elmo-msgdb-set-mark-alist
	 msgdb
	 (nconc (elmo-msgdb-get-mark-alist msgdb)
		(elmo-msgdb-get-mark-alist msgdb-append)))
	(setq duplicates (elmo-msgdb-make-index
			  msgdb
			  (elmo-msgdb-get-overview msgdb-append)
			  (elmo-msgdb-get-mark-alist msgdb-append)))
	(elmo-msgdb-set-path
	 msgdb
	 (or (elmo-msgdb-get-path msgdb)
	     (elmo-msgdb-get-path msgdb-append)))
	(modb-generic-set-message-modified-internal msgdb t)
	(modb-generic-set-flag-modified-internal msgdb t)
	duplicates)
    (luna-call-next-method)))

(luna-define-method elmo-msgdb-clear :after ((msgdb modb-legacy))
  (elmo-msgdb-set-overview msgdb nil)
  (elmo-msgdb-set-number-alist msgdb nil)
  (elmo-msgdb-set-mark-alist msgdb nil)
  (elmo-msgdb-set-index msgdb nil))

(luna-define-method elmo-msgdb-length ((msgdb modb-legacy))
  (length (modb-legacy-overview-internal msgdb)))

(luna-define-method elmo-msgdb-flag-available-p ((msgdb modb-legacy) flag)
  (modb-legacy-supported-flag-p flag))

(luna-define-method elmo-msgdb-flags ((msgdb modb-legacy) number)
  (modb-legacy-mark-to-flags (elmo-msgdb-get-mark msgdb number)))

(luna-define-method elmo-msgdb-set-flag ((msgdb modb-legacy)
					 number flag)
  (unless (modb-legacy-supported-flag-p flag)
    (error "Flag `%s' is not supported by this msgdb type"
	   (capitalize (symbol-name flag))))
  (case flag
    (read
     (elmo-msgdb-unset-flag msgdb number 'unread))
    (uncached
     (elmo-msgdb-unset-flag msgdb number 'cached))
    (t
     (let* ((cur-mark (elmo-msgdb-get-mark msgdb number))
	    (flags (modb-legacy-mark-to-flags cur-mark))
	    new-mark)
       (and (memq 'new flags)
	    (setq flags (delq 'new flags)))
       (or (memq flag flags)
	   (setq flags (cons flag flags)))
       (when (and (eq flag 'unread)
		  (memq 'answered flags))
	 (setq flags (delq 'answered flags)))
       (setq new-mark (modb-legacy-flags-to-mark flags))
       (unless (string= new-mark cur-mark)
	 (elmo-msgdb-set-mark msgdb number new-mark))))))

(luna-define-method elmo-msgdb-unset-flag ((msgdb modb-legacy)
					   number flag)
  (unless (or (modb-legacy-supported-flag-p flag)
	      (eq flag 'all))
    (error "Flag `%s' is not supported by this msgdb type"
	   (capitalize (symbol-name flag))))
  (case flag
    (read
     (elmo-msgdb-set-flag msgdb number 'unread))
    (uncached
     (elmo-msgdb-set-flag msgdb number 'cached))
    (all
     (elmo-msgdb-set-mark msgdb number nil))
    (t
     (let* ((cur-mark (elmo-msgdb-get-mark msgdb number))
	    (flags (modb-legacy-mark-to-flags cur-mark))
	    new-mark)
       (and (memq 'new flags)
	    (setq flags (delq 'new flags)))
       (and (memq flag flags)
	    (setq flags (delq flag flags)))
       (when (and (eq flag 'unread)
		  (memq 'answered flags))
	 (setq flags (delq 'answered flags)))
       (setq new-mark (modb-legacy-flags-to-mark flags))
       (unless (string= new-mark cur-mark)
	 (elmo-msgdb-set-mark msgdb number new-mark))))))

(luna-define-method elmo-msgdb-flag-count ((msgdb modb-legacy))
  (let ((new 0)
	(unread 0)
	(answered 0))
    (dolist (elem (elmo-msgdb-get-mark-alist msgdb))
      (cond
       ((string= (cadr elem) modb-legacy-new-mark)
	(incf new)
	(incf unread))
       ((member (cadr elem) (modb-legacy-unread-marks))
	(incf unread))
       ((member (cadr elem) (modb-legacy-answered-marks))
	(incf answered))))
    (list (cons 'new new)
	  (cons 'unread unread)
	  (cons 'answered answered))))

(luna-define-method elmo-msgdb-list-messages ((msgdb modb-legacy))
  (mapcar 'elmo-msgdb-overview-entity-get-number-internal
	  (elmo-msgdb-get-overview msgdb)))

(luna-define-method elmo-msgdb-list-flagged ((msgdb modb-legacy) flag)
  (let ((case-fold-search nil)
	mark-regexp matched)
    (case flag
      (new
       (setq mark-regexp (regexp-quote modb-legacy-new-mark)))
      (unread
       (setq mark-regexp (elmo-regexp-opt (modb-legacy-unread-marks))))
      (answered
       (setq mark-regexp (elmo-regexp-opt (modb-legacy-answered-marks))))
      (important
       (setq mark-regexp (regexp-quote modb-legacy-important-mark)))
      (read
       (setq mark-regexp (elmo-regexp-opt (modb-legacy-unread-marks))))
      (digest
       (setq mark-regexp (elmo-regexp-opt
			  (append (modb-legacy-unread-marks)
				  (list modb-legacy-important-mark)))))
      (any
       (setq mark-regexp (elmo-regexp-opt
			  (append
			   (modb-legacy-unread-marks)
			   (modb-legacy-answered-marks)
			   (list modb-legacy-important-mark))))))
    (when mark-regexp
      (if (eq flag 'read)
	  (dolist (number (elmo-msgdb-list-messages msgdb))
	    (let ((mark (elmo-msgdb-get-mark msgdb number)))
	      (unless (and mark (string-match mark-regexp mark))
		(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))

(luna-define-method elmo-msgdb-search ((msgdb modb-legacy)
				       condition &optional numbers)
  (if (vectorp condition)
      (let ((key (elmo-filter-key condition))
	    results)
	(cond
	 ((and (string= key "flag")
	       (eq (elmo-filter-type condition) 'match))
	  (setq results (elmo-msgdb-list-flagged
			 msgdb
			 (intern (elmo-filter-value condition))))
	  (if numbers
	      (elmo-list-filter numbers results)
	    results))
	 ((member key '("first" "last"))
	  (let* ((numbers (or numbers (elmo-msgdb-list-messages msgdb)))
		 (len (length numbers))
		 (lastp (string= key "last"))
		 (value (string-to-number (elmo-filter-value condition))))
	    (when (eq (elmo-filter-type condition) 'unmatch)
	      (setq lastp (not lastp)
		    value (- len value)))
	    (if lastp
		(nthcdr (max (- len value) 0) numbers)
	      (when (> value 0)
		(let* ((numbers (copy-sequence numbers))
		       (last (nthcdr (1- value) numbers)))
		  (when last
		    (setcdr last nil))
		  numbers)))))
	 (t
	  t)))
    t))

(luna-define-method elmo-msgdb-append-entity ((msgdb modb-legacy)
					      entity &optional flags)
  (when entity
    (let ((number (elmo-msgdb-overview-entity-get-number-internal entity))
	  (message-id (elmo-msgdb-overview-entity-get-id-internal entity))
	  mark cell)
      (when (and number message-id)
	(elmo-msgdb-set-overview
	 msgdb
	 (nconc (elmo-msgdb-get-overview msgdb)
		(list entity)))
	(elmo-msgdb-set-number-alist
	 msgdb
	 (nconc (elmo-msgdb-get-number-alist msgdb)
		(list (cons number message-id))))
	(modb-generic-set-message-modified-internal msgdb t)
	(when (setq mark (modb-legacy-flags-to-mark flags))
	  (setq cell (list number mark))
	  (elmo-msgdb-set-mark-alist
	   msgdb
	   (nconc (elmo-msgdb-get-mark-alist msgdb) (list cell)))
	  (modb-generic-set-flag-modified-internal msgdb t))
	(elmo-msgdb-make-index
	 msgdb
	 (list entity)
	 (and cell (list cell)))))))

(luna-define-method elmo-msgdb-delete-messages ((msgdb modb-legacy)
						numbers)
  (let* ((overview (elmo-msgdb-get-overview msgdb))
	 (number-alist (elmo-msgdb-get-number-alist msgdb))
	 (mark-alist (elmo-msgdb-get-mark-alist msgdb))
	 (index (elmo-msgdb-get-index msgdb))
	 ov-entity)
    ;; remove from current database.
    (dolist (number numbers)
      (setq overview
	    (delq
	     (setq ov-entity
		   (elmo-msgdb-message-entity msgdb number))
	     overview))
      (setq number-alist (delq (assq number number-alist) number-alist))
      (setq mark-alist (delq (assq number mark-alist) mark-alist))
      ;;
      (when index (elmo-msgdb-clear-index msgdb ov-entity)))
    (elmo-msgdb-set-overview msgdb overview)
    (elmo-msgdb-set-number-alist msgdb number-alist)
    (elmo-msgdb-set-mark-alist msgdb mark-alist)
    (elmo-msgdb-set-index msgdb index)
    (modb-generic-set-message-modified-internal msgdb t)
    (modb-generic-set-flag-modified-internal msgdb t)
    t)) ;return value

(luna-define-method elmo-msgdb-sort-entities ((msgdb modb-legacy)
					      predicate &optional app-data)
  (message "Sorting...")
  (let ((overview (elmo-msgdb-get-overview msgdb)))
    (elmo-msgdb-set-overview
     msgdb
     (sort overview (lambda (a b) (funcall predicate a b app-data))))
    (message "Sorting...done")
    msgdb))

(luna-define-method elmo-msgdb-message-entity ((msgdb modb-legacy) key)
  (when key
    (elmo-get-hash-val
     (cond ((stringp key) key)
	   ((numberp key) (format "#%d" key)))
     (elmo-msgdb-get-entity-hashtb msgdb))))

(require 'product)
(product-provide (provide 'modb-legacy) (require 'elmo-version))

;;; modb-legacy.el ends here