1 ;;; elmo-internal.el -- Internal Interface for ELMO.
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
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)
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.
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.
31 (require 'elmo-localdir)
33 (defsubst elmo-internal-list-folder-subr (spec &optional nonsort)
34 (let* ((directive (nth 1 spec))
36 (flist (elmo-list-folder-by-location
38 (elmo-internal-list-location directive arg)))
39 (killed (and elmo-use-killed-list
40 (elmo-msgdb-killed-list-load
41 (elmo-msgdb-expand-path spec))))
44 (cons (or (elmo-max-of-list flist) 0)
47 (elmo-msgdb-killed-list-length killed))
49 (setq numbers (sort flist '<))
50 (elmo-living-messages numbers killed))))
52 (defun elmo-internal-list-folder (spec)
53 (elmo-internal-list-folder-subr spec))
55 (defun elmo-internal-list-folder-by-location (spec location &optional msgdb)
56 (let* ((path (elmo-msgdb-expand-path spec))
59 (elmo-msgdb-get-location msgdb)
60 (elmo-msgdb-location-load path)))
63 location-max modified)
65 (or (elmo-max-of-list (mapcar 'car location-alist)) 0))
68 (if (setq pair (rassoc (car location) location-alist))
71 (list (cons (car pair) (car location)))))
73 (setq result (append result
75 (cons (+ location-max i) (car location))))))
76 (setq location (cdr location))))
77 (setq result (sort result '(lambda (x y)
79 (if (not (equal result location-alist))
82 (elmo-msgdb-location-save path result))
83 (mapcar 'car result)))
85 (defun elmo-internal-list-location (directive arg)
87 (or elmo-msgdb-global-mark-alist
88 (setq elmo-msgdb-global-mark-alist
89 (elmo-object-load (expand-file-name
90 elmo-msgdb-global-mark-filename
93 (mapcar (function (lambda (x)
94 (setq result (cons (car x) result))))
98 (defun elmo-internal-msgdb-create-entity (number loc-alist)
99 (elmo-localdir-msgdb-create-overview-entity-from-file
101 (elmo-cache-get-path (cdr (assq number loc-alist)))))
103 (defun elmo-internal-msgdb-create (spec numlist new-mark
104 already-mark seen-mark
109 (let* ((directive (nth 1 spec))
111 (loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
112 (elmo-msgdb-location-load (elmo-msgdb-expand-path
114 (loc-list (elmo-internal-list-location directive arg))
115 overview number-alist mark-alist entity
116 i percent num location pair)
117 (setq num (length numlist))
119 (message "Creating msgdb...")
122 (elmo-internal-msgdb-create-entity
123 (car numlist) loc-alist))
127 (elmo-msgdb-append-element
130 (elmo-msgdb-number-add number-alist
131 (elmo-msgdb-overview-entity-get-number
133 (elmo-msgdb-overview-entity-get-id
135 (setq location (cdr (assq (car numlist) loc-alist)))
136 (unless (memq location seen-list)
138 (elmo-msgdb-mark-append
140 (elmo-msgdb-overview-entity-get-number
143 (or (elmo-msgdb-global-mark-get
144 (elmo-msgdb-overview-entity-get-id
146 (if (elmo-cache-exists-p
147 (elmo-msgdb-overview-entity-get-id
151 (when (> num elmo-display-progress-threshold)
153 (setq percent (/ (* i 100) num))
154 (elmo-display-progress
155 'elmo-internal-msgdb-create "Creating msgdb..."
157 (setq numlist (cdr numlist)))
158 (message "Creating msgdb...done")
159 (list overview number-alist mark-alist loc-alist))))
161 (defalias 'elmo-internal-msgdb-create-as-numlist 'elmo-internal-msgdb-create)
163 (defun elmo-internal-list-folders (spec &optional hierarchy)
165 (unless (nth 1 spec) ; toplevel.
166 (list (list "'cache") "'mark")))
168 (defvar elmo-internal-mark "$")
170 (defun elmo-internal-append-msg (spec string &optional msg no-see)
173 (let* ((msgid (elmo-field-body "message-id"))
174 (path (elmo-cache-get-path msgid))
177 (setq dir (directory-file-name (file-name-directory path)))
178 (if (not (file-exists-p dir))
179 (elmo-make-directory dir))
180 (as-binary-output-file (write-region (point-min) (point-max)
182 (elmo-msgdb-global-mark-set msgid elmo-internal-mark))))
184 (defun elmo-internal-delete-msgs (spec msgs &optional msgdb)
185 (let ((loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
186 (elmo-msgdb-location-load (elmo-msgdb-expand-path
188 (mapcar '(lambda (msg) (elmo-internal-delete-msg spec msg
192 (defun elmo-internal-delete-msg (spec number loc-alist)
193 (let ((pair (assq number loc-alist)))
194 (elmo-msgdb-global-mark-delete (cdr pair))))
196 (defun elmo-internal-read-msg (spec number outbuf &optional msgdb)
198 (let* ((loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
199 (elmo-msgdb-location-load (elmo-msgdb-expand-path
201 (file (elmo-cache-get-path (cdr (assq number loc-alist)))))
204 (when (file-exists-p file)
205 (as-binary-input-file (insert-file-contents file))
206 (elmo-delete-cr-get-content-type)))))
208 (defun elmo-internal-max-of-folder (spec)
209 (elmo-internal-list-folder-subr spec t))
211 (defun elmo-internal-check-validity (spec)
214 (defun elmo-internal-sync-validity (spec)
217 (defun elmo-internal-folder-exists-p (spec)
220 (defun elmo-internal-folder-creatable-p (spec)
223 (defun elmo-internal-create-folder (spec)
226 (defun elmo-internal-search (spec condition &optional from-msgs msgdb)
228 (or elmo-msgdb-global-mark-alist
229 (setq elmo-msgdb-global-mark-alist
230 (elmo-object-load (expand-file-name
231 elmo-msgdb-global-mark-filename
233 (loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
234 (elmo-msgdb-location-load (elmo-msgdb-expand-path
236 (number-list (mapcar 'car loc-alist))
241 (setq num (length loc-alist))
244 (if (and (setq cache-file (elmo-cache-exists-p (cdr (car loc-alist))))
245 (elmo-file-field-condition-match cache-file
247 (car (car loc-alist))
249 (setq ret-val (append ret-val (list (car (car loc-alist))))))
251 (setq percent (/ (* i 100) num))
252 (elmo-display-progress
253 'elmo-internal-search "Searching..."
255 (setq loc-alist (cdr loc-alist)))
258 (defun elmo-internal-use-cache-p (spec number)
261 (defun elmo-internal-local-file-p (spec number)
265 (defalias 'elmo-internal-sync-number-alist 'elmo-generic-sync-number-alist)
266 (defalias 'elmo-internal-list-folder-unread
267 'elmo-generic-list-folder-unread)
268 (defalias 'elmo-internal-list-folder-important
269 'elmo-generic-list-folder-important)
270 (defalias 'elmo-internal-commit 'elmo-generic-commit)
271 (defalias 'elmo-internal-folder-diff 'elmo-generic-folder-diff)
274 (product-provide (provide 'elmo-internal) (require 'elmo-version))
276 ;;; elmo-internal.el ends here