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))))
40 (cons (or (elmo-max-of-list flist) 0)
44 (defun elmo-internal-list-folder (spec)
45 (let ((killed (and elmo-use-killed-list
46 (elmo-msgdb-killed-list-load
47 (elmo-msgdb-expand-path nil spec))))
49 (setq numbers (elmo-internal-list-folder-subr spec))
52 (mapcar (lambda (number)
53 (unless (memq number killed) number))
57 (defun elmo-internal-list-folder-by-location (spec location &optional msgdb)
58 (let* ((path (elmo-msgdb-expand-path nil spec))
61 (elmo-msgdb-get-location msgdb)
62 (elmo-msgdb-location-load path)))
65 location-max modified)
67 (or (elmo-max-of-list (mapcar 'car location-alist)) 0))
70 (if (setq pair (rassoc (car location) location-alist))
73 (list (cons (car pair) (car location)))))
75 (setq result (append result
77 (cons (+ location-max i) (car location))))))
78 (setq location (cdr location))))
79 (setq result (sort result '(lambda (x y)
81 (if (not (equal result location-alist))
84 (elmo-msgdb-location-save path result))
85 (mapcar 'car result)))
87 (defun elmo-internal-list-location (directive arg)
89 (or elmo-msgdb-global-mark-alist
90 (setq elmo-msgdb-global-mark-alist
91 (elmo-object-load (expand-file-name
92 elmo-msgdb-global-mark-filename
95 (mapcar (function (lambda (x)
96 (setq result (cons (car x) result))))
100 (defun elmo-internal-msgdb-create-entity (number loc-alist)
101 (elmo-localdir-msgdb-create-overview-entity-from-file
103 (elmo-cache-get-path (cdr (assq number loc-alist)))))
105 (defun elmo-internal-msgdb-create (spec numlist new-mark
106 already-mark seen-mark
111 (let* ((directive (nth 1 spec))
113 (loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
114 (elmo-msgdb-location-load (elmo-msgdb-expand-path
116 (loc-list (elmo-internal-list-location directive arg))
117 overview number-alist mark-alist entity
118 i percent num location pair)
119 (setq num (length numlist))
121 (message "Creating msgdb...")
124 (elmo-internal-msgdb-create-entity
125 (car numlist) loc-alist))
129 (elmo-msgdb-append-element
132 (elmo-msgdb-number-add number-alist
133 (elmo-msgdb-overview-entity-get-number
135 (elmo-msgdb-overview-entity-get-id
137 (setq location (cdr (assq (car numlist) loc-alist)))
138 (unless (memq location seen-list)
140 (elmo-msgdb-mark-append
142 (elmo-msgdb-overview-entity-get-number
145 (or (elmo-msgdb-global-mark-get
146 (elmo-msgdb-overview-entity-get-id
148 (if (elmo-cache-exists-p
149 (elmo-msgdb-overview-entity-get-id
153 (when (> num elmo-display-progress-threshold)
155 (setq percent (/ (* i 100) num))
156 (elmo-display-progress
157 'elmo-internal-msgdb-create "Creating msgdb..."
159 (setq numlist (cdr numlist)))
160 (message "Creating msgdb...done.")
161 (list overview number-alist mark-alist loc-alist))))
163 (defalias 'elmo-internal-msgdb-create-as-numlist 'elmo-internal-msgdb-create)
165 (defun elmo-internal-list-folders (spec &optional hierarchy)
167 (unless (nth 1 spec) ; toplevel.
168 (list (list "'cache") "'mark")))
170 (defvar elmo-internal-mark "$")
172 (defun elmo-internal-append-msg (spec string &optional msg no-see)
175 (let* ((msgid (elmo-field-body "message-id"))
176 (path (elmo-cache-get-path msgid))
179 (setq dir (directory-file-name (file-name-directory path)))
180 (if (not (file-exists-p dir))
181 (elmo-make-directory dir))
182 (as-binary-output-file (write-region (point-min) (point-max)
184 (elmo-msgdb-global-mark-set msgid elmo-internal-mark))))
186 (defun elmo-internal-delete-msgs (spec msgs &optional msgdb)
187 (let ((loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
188 (elmo-msgdb-location-load (elmo-msgdb-expand-path
190 (mapcar '(lambda (msg) (elmo-internal-delete-msg spec msg
194 (defun elmo-internal-delete-msg (spec number loc-alist)
195 (let ((pair (assq number loc-alist)))
196 (elmo-msgdb-global-mark-delete (cdr pair))))
198 (defun elmo-internal-read-msg (spec number outbuf &optional msgdb)
200 (let* ((loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
201 (elmo-msgdb-location-load (elmo-msgdb-expand-path
203 (file (elmo-cache-get-path (cdr (assq number loc-alist)))))
206 (when (file-exists-p file)
207 (as-binary-input-file (insert-file-contents file))
208 (elmo-delete-cr-get-content-type)))))
210 (defun elmo-internal-max-of-folder (spec)
211 (elmo-internal-list-folder-subr spec t))
213 (defun elmo-internal-check-validity (spec)
216 (defun elmo-internal-sync-validity (spec)
219 (defun elmo-internal-folder-exists-p (spec)
222 (defun elmo-internal-folder-creatable-p (spec)
225 (defun elmo-internal-create-folder (spec)
228 (defun elmo-internal-search (spec condition &optional from-msgs msgdb)
230 (or elmo-msgdb-global-mark-alist
231 (setq elmo-msgdb-global-mark-alist
232 (elmo-object-load (expand-file-name
233 elmo-msgdb-global-mark-filename
235 (loc-alist (if msgdb (elmo-msgdb-get-location msgdb)
236 (elmo-msgdb-location-load (elmo-msgdb-expand-path
242 (setq num (length loc-alist))
245 (if (and (setq cache-file (elmo-cache-exists-p (cdr (car loc-alist))))
246 (elmo-file-field-condition-match cache-file
248 (setq ret-val (append ret-val (list (car (car loc-alist))))))
250 (setq percent (/ (* i 100) num))
251 (elmo-display-progress
252 'elmo-internal-search "Searching..."
254 (setq loc-alist (cdr loc-alist)))
257 (defun elmo-internal-use-cache-p (spec number)
260 (defun elmo-internal-local-file-p (spec number)
264 (defalias 'elmo-internal-sync-number-alist 'elmo-generic-sync-number-alist)
265 (defalias 'elmo-internal-list-folder-unread
266 'elmo-generic-list-folder-unread)
267 (defalias 'elmo-internal-list-folder-important
268 'elmo-generic-list-folder-important)
269 (defalias 'elmo-internal-commit 'elmo-generic-commit)
271 (provide 'elmo-internal)
273 ;;; elmo-internal.el ends here