1 ;;; elmo-dop.el -- Modules for Disconnected Operations on ELMO.
3 ;; Copyright (C) 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.
38 (defvar elmo-dop-queue nil
39 "A list of (folder-name function-to-be-called argument-list).
40 Automatically loaded/saved.")
42 (defvar elmo-dop-folder (concat "+" (expand-file-name "dop"
44 "A folder for `elmo-folder-append-messages' disconnected operations.")
46 (defmacro elmo-make-dop-queue (fname method arguments)
48 (` (vector (, fname) (, method) (, arguments))))
50 (defmacro elmo-dop-queue-fname (queue)
51 "Return the folder name string of the QUEUE."
52 (` (aref (, queue) 0)))
54 (defmacro elmo-dop-queue-method (queue)
55 "Return the method symbol of the QUEUE."
56 (` (aref (, queue) 1)))
58 (defmacro elmo-dop-queue-arguments (queue)
59 "Return the arguments of the QUEUE."
60 (` (aref (, queue) 2)))
62 (defun elmo-dop-queue-append (fname method arguments)
63 "Append to disconnected operation queue."
64 (let ((queue (elmo-make-dop-queue fname method arguments)))
65 (setq elmo-dop-queue (nconc elmo-dop-queue (list queue)))))
67 (defun elmo-dop-queue-flush (&optional force)
68 "Flush disconnected operations.
69 If optional argument FORCE is non-nil, try flushing all operation queues
70 even an operation concerns the unplugged folder."
71 (elmo-dop-queue-merge)
72 (let ((queue elmo-dop-queue)
76 (if (or force (elmo-folder-plugged-p (elmo-make-folder (caar queue))))
77 (setq count (1+ count)))
78 (setq queue (cdr queue)))
81 (format "%d pending operation(s) exists. Perform now? " count)
82 (not elmo-dop-flush-confirm) t)
86 (let ((queue elmo-dop-queue)
89 (num (length elmo-dop-queue))
92 ;; now perform pending processes.
95 (message "Flushing queue....%d/%d." i num)
97 (apply (elmo-dop-queue-method (car queue))
98 (elmo-dop-queue-fname (car queue))
99 (elmo-dop-queue-arguments queue))
100 (quit (setq failure t))
101 (error (setq failure err)))
104 (setq elmo-dop-queue (delq (car queue) elmo-dop-queue))
105 (setq performed (+ 1 performed)))
106 (setq queue (cdr queue)))
107 (message "%d/%d operation(s) are performed successfully."
110 (elmo-dop-queue-save)))
111 (if (elmo-y-or-n-p "Clear all pending operations? "
112 (not elmo-dop-flush-confirm) t)
114 (setq elmo-dop-queue nil)
115 (message "All pending operations are cleared.")
116 (elmo-dop-queue-save))
120 (defvar elmo-dop-merge-funcs nil)
121 (defun elmo-dop-queue-merge ()
122 (let ((queue elmo-dop-queue)
123 new-queue match-queue que)
124 (while (setq que (car queue))
126 (member (cadr que) elmo-dop-merge-funcs)
132 (string= (car que) (car new-queue))
133 (string= (cadr que) (cadr new-queue)))
136 (setcar (cddr match-queue)
137 (append (nth 2 match-queue) (nth 2 que)))
138 (setq new-queue (append new-queue (list que))))
139 (setq queue (cdr queue)))
140 (setq elmo-dop-queue new-queue)))
143 ;;; Execution is delayed.
147 ;; If appended message is local file or cached, it is saved in
148 ;; .elmo/dop/1 2 3 4 ...
149 ;; then msgdb-path/append file is created and contain message number list.
152 (defun elmo-folder-append-buffer-dop (folder unread &optional number)
155 (defun elmo-folder-delete-messages-dop (folder numbers)
158 (defun elmo-folder-encache-dop (folder numbers)
161 (defun elmo-create-folder-dop (folder)
164 ;;; Execute as subsutitute for plugged operation.
165 (defun elmo-folder-status-dop (folder)
166 (let* ((number-alist (elmo-msgdb-number-load
167 (elmo-folder-msgdb-path folder)))
168 (number-list (mapcar 'car number-alist))
171 ;; number of messages which are queued as append should be added
172 ;; to max-num and length.
174 (or (nth (max (- (length number-list) 1) 0) number-list)
176 (cons max-num number-list)))
179 (product-provide (provide 'elmo-dop) (require 'elmo-version))
181 ;;; elmo-dop.el ends here