* elmo/elmo-util.el (elmo-object-save): Bind print-level, print-length.
[elisp/wanderlust.git] / elmo / elmo-database.el
1 ;;; elmo-database.el --- Database module for ELMO.
2
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7
8 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14 ;;
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24 ;;
25
26 ;;; Commentary:
27 ;;
28
29 ;;; Code:
30 ;;
31 (require 'elmo-vars)
32 (require 'elmo-msgdb)
33
34 (defvar elmo-database-msgid nil)
35 (defvar elmo-database-msgid-filename "msgid")
36
37 (defun elmo-database-get (dbsym dbname)
38   (if (not (and (symbol-value dbsym)
39                 (database-live-p (symbol-value dbsym))))
40       (set dbsym (open-database (expand-file-name
41                                  dbname
42                                  elmo-msgdb-directory
43                                  )))
44     (symbol-value dbsym)))
45
46 (defun elmo-database-close ()
47   (and elmo-database-msgid
48        (database-live-p elmo-database-msgid)
49        (close-database elmo-database-msgid)))
50
51 (defun elmo-database-msgid-put (msgid folder number)
52   (let ((db (elmo-database-get 'elmo-database-msgid
53                                elmo-database-msgid-filename))
54         print-length)
55     (and msgid db
56          (progn
57            (remove-database msgid db)
58            (put-database msgid (prin1-to-string
59                                 (list folder number)) db)))))
60
61 (defun elmo-database-msgid-delete (msgid)
62   (remove-database msgid (elmo-database-get
63                           'elmo-database-msgid
64                           elmo-database-msgid-filename)))
65
66 (defun elmo-database-msgid-get (msgid)
67   (let ((match (get-database msgid (elmo-database-get
68                                     'elmo-database-msgid
69                                     elmo-database-msgid-filename))))
70     (and match (read match))))
71
72 (require 'product)
73 (product-provide (provide 'elmo-database) (require 'elmo-version))
74
75 ;;; elmo-database.el ends here