* elmo.el (elmo-folder-list-flagged): New generic function.
[elisp/wanderlust.git] / elmo / elmo-mark.el
1 ;;; elmo-mark.el --- Global mark folder 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)
32 (require 'elmo-map)
33
34 (defcustom elmo-mark-default-mark "$"
35   "*Default global-mark for mark-folder."
36   :type 'string
37   :group 'elmo)
38
39 ;;; ELMO mark folder
40 (eval-and-compile
41   (luna-define-class elmo-mark-folder (elmo-map-folder) (mark))
42   (luna-define-internal-accessors 'elmo-mark-folder))
43
44 (luna-define-method elmo-folder-initialize ((folder
45                                              elmo-mark-folder)
46                                             name)
47   (elmo-mark-folder-set-mark-internal
48    folder
49    elmo-mark-default-mark)
50   folder)
51
52 (luna-define-method elmo-folder-have-subfolder-p ((folder elmo-mark-folder))
53   nil)
54
55 (luna-define-method elmo-folder-expand-msgdb-path ((folder
56                                                     elmo-mark-folder))
57   (expand-file-name "mark"
58                     (expand-file-name "internal"
59                                       elmo-msgdb-directory)))
60
61 (luna-define-method elmo-map-folder-list-message-locations
62   ((folder elmo-mark-folder))
63   (elmo-mark-folder-list-message-locations folder))
64
65 (defun elmo-mark-folder-list-message-locations (folder)
66   (let (result)
67     (dolist (pair (or elmo-msgdb-global-mark-alist
68                       (setq elmo-msgdb-global-mark-alist
69                             (elmo-object-load
70                              (expand-file-name
71                               elmo-msgdb-global-mark-filename
72                               elmo-msgdb-directory)))))
73       (if (string= (elmo-mark-folder-mark-internal folder)
74                    (cdr pair))
75           (setq result (cons (car pair) result))))
76     (nreverse result)))
77
78 (luna-define-method elmo-folder-message-file-p ((folder elmo-mark-folder))
79   t)
80
81 (luna-define-method elmo-message-file-name ((folder elmo-mark-folder)
82                                             number)
83   (elmo-file-cache-get-path
84    (elmo-map-message-location folder number)))
85
86 (luna-define-method elmo-folder-msgdb-create ((folder elmo-mark-folder)
87                                               numbers seen-list)
88   (elmo-mark-folder-msgdb-create folder numbers))
89
90 (defun elmo-mark-folder-msgdb-create (folder numbers)
91   (let ((i 0)
92         (len (length numbers))
93         overview number-alist mark-alist entity message-id
94         num)
95     (message "Creating msgdb...")
96     (while numbers
97       (setq entity
98             (elmo-msgdb-create-overview-entity-from-file
99              (car numbers) (elmo-message-file-name folder (car numbers))))
100       (if (null entity)
101           ()
102         (setq num (elmo-msgdb-overview-entity-get-number entity))
103         (setq overview
104               (elmo-msgdb-append-element
105                overview entity))
106         (setq message-id (elmo-msgdb-overview-entity-get-id entity))
107         (setq number-alist
108               (elmo-msgdb-number-add number-alist
109                                      num
110                                      message-id))
111         (setq mark-alist
112               (elmo-msgdb-mark-append
113                mark-alist
114                num (elmo-mark-folder-mark-internal folder))))
115       (when (> len elmo-display-progress-threshold)
116         (setq i (1+ i))
117         (elmo-display-progress
118          'elmo-mark-folder-msgdb-create "Creating msgdb..."
119          (/ (* i 100) len)))
120       (setq numbers (cdr numbers)))
121     (message "Creating msgdb...done")
122     (list overview number-alist mark-alist)))
123
124 (luna-define-method elmo-folder-append-buffer ((folder elmo-mark-folder)
125                                                unread &optional number)
126   (let* ((msgid (elmo-field-body "message-id"))
127          (path (elmo-file-cache-get-path msgid))
128          dir)
129     (when path
130       (setq dir (directory-file-name (file-name-directory path)))
131       (unless (file-exists-p dir)
132         (elmo-make-directory dir))
133       (when (file-writable-p path)
134         (write-region-as-binary (point-min) (point-max)
135                                 path nil 'no-msg)))
136     (elmo-msgdb-global-mark-set msgid
137                                 (elmo-mark-folder-mark-internal folder))))
138
139 (luna-define-method elmo-map-folder-delete-messages ((folder elmo-mark-folder)
140                                                      locations)
141   (dolist (location locations)
142     (elmo-msgdb-global-mark-delete location)))
143
144 (luna-define-method elmo-message-fetch-with-cache-process
145   ((folder elmo-mark-folder) number strategy &optional section unseen)
146   ;; disbable cache process
147   (elmo-message-fetch-internal folder number strategy section unseen))
148
149 (luna-define-method elmo-map-message-fetch ((folder elmo-mark-folder)
150                                             location strategy
151                                             &optional section unseen)
152   (let ((file (elmo-file-cache-get-path location)))
153     (when (file-exists-p file)
154       (insert-file-contents-as-binary file))))
155
156 (luna-define-method elmo-folder-exists-p ((folder elmo-mark-folder))
157   t)
158
159 (luna-define-method elmo-folder-writable-p ((folder elmo-mark-folder))
160   t)
161
162 (require 'product)
163 (product-provide (provide 'elmo-mark) (require 'elmo-version))
164
165 ;;; elmo-mark.el ends here