1 ;;; elmo-pipe.el --- PIPE Interface for 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.
34 (defvar elmo-pipe-folder-copied-filename "copied"
35 "Copied messages number set.")
39 (luna-define-class elmo-pipe-folder (elmo-folder)
41 (luna-define-internal-accessors 'elmo-pipe-folder))
43 (luna-define-method elmo-folder-initialize ((folder elmo-pipe-folder)
45 (when (string-match "^\\([^|]*\\)|\\(:?\\)\\(.*\\)$" name)
46 (elmo-pipe-folder-set-src-internal folder
48 (elmo-match-string 1 name)))
49 (elmo-pipe-folder-set-dst-internal folder
51 (elmo-match-string 3 name)))
52 (elmo-pipe-folder-set-copy-internal folder
53 (string= ":" (elmo-match-string 2 name))))
56 (luna-define-method elmo-folder-get-primitive-list ((folder elmo-pipe-folder))
59 'elmo-folder-get-primitive-list
60 (list (elmo-pipe-folder-src-internal folder)
61 (elmo-pipe-folder-dst-internal folder)))))
63 (luna-define-method elmo-folder-contains-type ((folder elmo-pipe-folder)
65 (or (elmo-folder-contains-type (elmo-pipe-folder-src-internal folder) type)
66 (elmo-folder-contains-type (elmo-pipe-folder-dst-internal folder) type)))
68 (luna-define-method elmo-folder-msgdb-create ((folder elmo-pipe-folder)
69 numlist new-mark already-mark
70 seen-mark important-mark
72 (elmo-folder-msgdb-create (elmo-pipe-folder-dst-internal folder)
73 numlist new-mark already-mark
74 seen-mark important-mark seen-list))
76 (luna-define-method elmo-folder-append-messages ((folder elmo-pipe-folder)
79 &optional same-number)
80 (elmo-folder-append-messages (elmo-pipe-folder-dst-internal folder)
85 (luna-define-method elmo-folder-append-buffer ((folder elmo-pipe-folder)
86 unread &optional number)
87 (elmo-folder-append-buffer (elmo-pipe-folder-dst-internal folder)
90 (luna-define-method elmo-message-fetch ((folder elmo-pipe-folder)
92 &optional section outbuf unseen)
93 (elmo-message-fetch (elmo-pipe-folder-dst-internal folder)
94 number strategy section outbuf unseen))
96 (luna-define-method elmo-folder-delete-messages ((folder elmo-pipe-folder)
98 (elmo-folder-delete-messages (elmo-pipe-folder-dst-internal folder)
101 (defvar elmo-pipe-drained-hook nil "A hook called when the pipe is flushed.")
103 (defsubst elmo-pipe-folder-list-target-messages (src &optional ignore-list)
106 (elmo-folder-set-killed-list-internal src ignore-list)
107 (elmo-folder-list-messages src))
108 (elmo-folder-set-killed-list-internal src nil)))
110 (defun elmo-pipe-drain (src dst &optional copy ignore-list)
111 "Move or copy all messages of SRC to DST."
112 (let ((elmo-inhibit-number-mapping (not copy)) ; No need to use UIDL
114 (message "Checking %s..." (elmo-folder-name-internal src))
115 ;; Warnnig: some function requires msgdb
116 ;; but elmo-folder-open-internal do not load msgdb.
117 (elmo-folder-open-internal src)
118 (setq msgs (elmo-pipe-folder-list-target-messages src ignore-list)
120 (when (> len elmo-display-progress-threshold)
121 (elmo-progress-set 'elmo-folder-move-messages
124 "Copying messages..."
125 "Moving messages...")))
127 (elmo-folder-move-messages src msgs dst
129 (elmo-progress-clear 'elmo-folder-move-messages))
130 (when (and copy msgs)
131 (setq ignore-list (elmo-number-set-append-list ignore-list
133 ;; Don't save msgdb here.
134 ;; Because summary view of original folder is not updated yet.
135 (elmo-folder-close-internal src)
136 (run-hooks 'elmo-pipe-drained-hook)
139 (defun elmo-pipe-folder-copied-list-load (folder)
141 (expand-file-name elmo-pipe-folder-copied-filename
143 (elmo-replace-string-as-filename
144 (elmo-folder-name-internal folder))
145 (expand-file-name "pipe" elmo-msgdb-directory)))
148 (defun elmo-pipe-folder-copied-list-save (folder copied-list)
150 (expand-file-name elmo-pipe-folder-copied-filename
152 (elmo-replace-string-as-filename
153 (elmo-folder-name-internal folder))
154 (expand-file-name "pipe" elmo-msgdb-directory)))
157 (luna-define-method elmo-folder-open-internal ((folder elmo-pipe-folder))
158 (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder))
159 (let ((src-folder (elmo-pipe-folder-src-internal folder))
160 (dst-folder (elmo-pipe-folder-dst-internal folder)))
161 (when (and (elmo-folder-plugged-p src-folder)
162 (elmo-folder-plugged-p dst-folder))
163 (if (elmo-pipe-folder-copy-internal folder)
164 (elmo-pipe-folder-copied-list-save
166 (elmo-pipe-drain src-folder
169 (elmo-pipe-folder-copied-list-load folder)))
170 (elmo-pipe-drain src-folder dst-folder)))))
172 (luna-define-method elmo-folder-close-internal ((folder elmo-pipe-folder))
173 (elmo-folder-close-internal(elmo-pipe-folder-dst-internal folder)))
175 (luna-define-method elmo-folder-list-messages-internal
176 ((folder elmo-pipe-folder) &optional nohide)
177 (elmo-folder-list-messages-internal (elmo-pipe-folder-dst-internal
180 (luna-define-method elmo-folder-list-unreads-internal
181 ((folder elmo-pipe-folder) unread-marks &optional mark-alist)
182 (elmo-folder-list-unreads-internal (elmo-pipe-folder-dst-internal folder)
183 unread-marks mark-alist))
185 (luna-define-method elmo-folder-list-importants-internal
186 ((folder elmo-pipe-folder) important-mark)
187 (elmo-folder-list-importants-internal (elmo-pipe-folder-dst-internal folder)
190 (luna-define-method elmo-folder-status ((folder elmo-pipe-folder))
191 (elmo-folder-open-internal (elmo-pipe-folder-src-internal folder))
192 (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder))
193 (let* ((elmo-inhibit-number-mapping
194 (not (elmo-pipe-folder-copy-internal folder)))
195 (src-length (length (elmo-pipe-folder-list-target-messages
196 (elmo-pipe-folder-src-internal folder)
197 (elmo-pipe-folder-copied-list-load folder))))
198 (dst-list (elmo-folder-list-messages
199 (elmo-pipe-folder-dst-internal folder))))
200 (prog1 (cons (+ src-length (elmo-max-of-list dst-list))
201 (+ src-length (length dst-list)))
203 (elmo-folder-close-internal (elmo-pipe-folder-src-internal folder))
204 (elmo-folder-close-internal (elmo-pipe-folder-dst-internal folder)))))
206 (luna-define-method elmo-folder-exists-p ((folder elmo-pipe-folder))
207 (and (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder))
208 (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder))))
210 (luna-define-method elmo-folder-expand-msgdb-path ((folder
212 ;; Share with destination...OK?
213 (elmo-folder-expand-msgdb-path (elmo-pipe-folder-dst-internal folder)))
215 (luna-define-method elmo-folder-newsgroups ((folder elmo-pipe-folder))
216 (elmo-folder-newsgroups (elmo-pipe-folder-src-internal folder)))
218 (luna-define-method elmo-folder-creatable-p ((folder elmo-pipe-folder))
219 (and (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder))
220 (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder))))
222 (luna-define-method elmo-folder-writable-p ((folder elmo-pipe-folder))
223 (elmo-folder-writable-p (elmo-pipe-folder-dst-internal folder)))
225 (luna-define-method elmo-folder-create ((folder elmo-pipe-folder))
226 (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder)))
227 (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder)))
228 (elmo-folder-create (elmo-pipe-folder-src-internal folder)))
229 (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder)))
230 (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder)))
231 (elmo-folder-create (elmo-pipe-folder-dst-internal folder))))
233 (luna-define-method elmo-folder-search ((folder elmo-pipe-folder)
234 condition &optional numlist)
235 (elmo-folder-search (elmo-pipe-folder-dst-internal folder)
238 (luna-define-method elmo-message-use-cache-p ((folder elmo-pipe-folder) number)
239 (elmo-message-use-cache-p (elmo-pipe-folder-dst-internal folder) number))
241 (luna-define-method elmo-folder-check ((folder elmo-pipe-folder))
242 (elmo-folder-close-internal folder)
243 (elmo-folder-open-internal folder))
245 (luna-define-method elmo-folder-plugged-p ((folder elmo-pipe-folder))
246 (and (elmo-folder-plugged-p (elmo-pipe-folder-src-internal folder))
247 (elmo-folder-plugged-p (elmo-pipe-folder-dst-internal folder))))
249 (luna-define-method elmo-folder-message-file-p ((folder elmo-pipe-folder))
250 (elmo-folder-message-file-p (elmo-pipe-folder-dst-internal folder)))
252 (luna-define-method elmo-message-file-p ((folder elmo-pipe-folder) number)
253 (elmo-message-file-p (elmo-pipe-folder-dst-internal folder) number))
255 (luna-define-method elmo-message-file-name ((folder elmo-pipe-folder) number)
256 (elmo-message-file-name (elmo-pipe-folder-dst-internal folder) number))
258 (luna-define-method elmo-folder-message-file-number-p ((folder
260 (elmo-folder-message-file-number-p (elmo-pipe-folder-dst-internal folder)))
262 (luna-define-method elmo-folder-message-file-directory ((folder
264 (elmo-folder-message-file-directory
265 (elmo-pipe-folder-dst-internal folder)))
267 (luna-define-method elmo-folder-message-make-temp-file-p
268 ((folder elmo-pipe-folder))
269 (elmo-folder-message-make-temp-file-p
270 (elmo-pipe-folder-dst-internal folder)))
272 (luna-define-method elmo-folder-message-make-temp-files ((folder
277 (elmo-folder-message-make-temp-files
278 (elmo-pipe-folder-dst-internal folder) numbers start-number))
280 (luna-define-method elmo-folder-mark-as-read ((folder elmo-pipe-folder)
282 (elmo-folder-mark-as-read (elmo-pipe-folder-dst-internal folder)
285 (luna-define-method elmo-folder-unmark-read ((folder elmo-pipe-folder)
287 (elmo-folder-unmark-read (elmo-pipe-folder-dst-internal folder)
290 (luna-define-method elmo-folder-unmark-important ((folder elmo-pipe-folder)
292 (elmo-folder-unmark-important (elmo-pipe-folder-dst-internal folder)
295 (luna-define-method elmo-folder-mark-as-important ((folder elmo-pipe-folder)
297 (elmo-folder-mark-as-important (elmo-pipe-folder-dst-internal folder)
300 (luna-define-method elmo-folder-pack-numbers ((folder elmo-pipe-folder))
301 (elmo-folder-pack-numbers (elmo-pipe-folder-dst-internal folder)))
304 (product-provide (provide 'elmo-pipe) (require 'elmo-version))
306 ;;; elmo-pipe.el ends here