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.
33 (require 'elmo-signal
)
35 (defvar elmo-pipe-folder-copied-filename
"copied"
36 "Copied messages number set.")
40 (luna-define-class elmo-pipe-folder
(elmo-folder)
42 (luna-define-internal-accessors 'elmo-pipe-folder
))
44 (luna-define-method elmo-folder-initialize
((folder elmo-pipe-folder
)
46 (when (string-match "^\\([^|]*\\)|\\(:?\\)\\(.*\\)$" name
)
47 (elmo-pipe-folder-set-src-internal folder
49 (elmo-match-string 1 name
)))
50 (elmo-pipe-folder-set-dst-internal folder
52 (elmo-match-string 3 name
)))
53 (elmo-pipe-folder-set-copy-internal folder
55 (elmo-match-string 2 name
))))
56 (elmo-pipe-connect-signals folder
(elmo-pipe-folder-dst-internal folder
))
59 (defun elmo-pipe-connect-signals (folder destination
)
61 destination
'flag-changing folder
62 (elmo-define-signal-handler (folder dst number old-flags new-flags
)
63 (elmo-emit-signal 'flag-changing folder number old-flags new-flags
)))
65 destination
'flag-changed folder
66 (elmo-define-signal-handler (folder dst numbers
)
67 (elmo-emit-signal 'flag-changed folder numbers
)))
69 destination
'status-changed folder
70 (elmo-define-signal-handler (folder dst numbers
)
71 (elmo-emit-signal 'status-changed folder numbers
)))
73 destination
'update-overview folder
74 (elmo-define-signal-handler (folder dst number
)
75 (elmo-emit-signal 'update-overview folder number
))))
77 (luna-define-method elmo-folder-get-primitive-list
((folder elmo-pipe-folder
))
79 (elmo-folder-get-primitive-list (elmo-pipe-folder-src-internal folder
))
80 (elmo-folder-get-primitive-list (elmo-pipe-folder-dst-internal folder
))))
82 (luna-define-method elmo-folder-contains-type
((folder elmo-pipe-folder
)
84 (or (elmo-folder-contains-type (elmo-pipe-folder-src-internal folder
) type
)
85 (elmo-folder-contains-type (elmo-pipe-folder-dst-internal folder
) type
)))
87 (defun elmo-folder-append-messages-pipe-* (dst-folder
91 (elmo-folder-append-messages dst-folder
92 (elmo-pipe-folder-dst-internal src-folder
)
96 (defun elmo-folder-append-messages-*-pipe
(dst-folder
100 (elmo-folder-append-messages (elmo-pipe-folder-dst-internal dst-folder
)
105 (luna-define-method elmo-folder-append-buffer
((folder elmo-pipe-folder
)
106 &optional flag number
)
107 (elmo-folder-append-buffer (elmo-pipe-folder-dst-internal folder
)
110 (luna-define-method elmo-message-fetch
((folder elmo-pipe-folder
)
112 &optional unseen section
)
113 (elmo-message-fetch (elmo-pipe-folder-dst-internal folder
)
114 number strategy unseen section
))
116 (luna-define-method elmo-folder-clear
:after
((folder elmo-pipe-folder
)
117 &optional keep-killed
)
119 (elmo-pipe-folder-copied-list-save folder nil
)))
121 (luna-define-method elmo-folder-delete-messages
((folder elmo-pipe-folder
)
123 (elmo-folder-delete-messages (elmo-pipe-folder-dst-internal folder
)
126 (luna-define-method elmo-folder-detach-messages
((folder elmo-pipe-folder
)
128 (elmo-folder-detach-messages (elmo-pipe-folder-dst-internal folder
)
131 (defvar elmo-pipe-drained-hook nil
"A hook called when the pipe is flushed.")
133 (defsubst elmo-pipe-folder-list-target-messages
(src &optional ignore-list
)
134 (let ((killed (elmo-folder-killed-list-internal src
)))
135 (elmo-folder-set-killed-list-internal src ignore-list
)
137 (elmo-folder-list-messages src t
)
138 (elmo-folder-set-killed-list-internal src killed
))))
140 (defun elmo-pipe-drain (src dst
&optional copy ignore-list
)
141 "Move or copy all messages of SRC to DST."
142 (let ((elmo-inhibit-number-mapping (and (eq (elmo-folder-type-internal src
)
144 (not copy
)))) ; No need to use UIDL
145 (message "Checking %s..." (elmo-folder-name-internal src
))
146 (elmo-folder-open src
)
148 (let ((msgs (elmo-pipe-folder-list-target-messages src ignore-list
)))
149 (elmo-with-progress-display (elmo-folder-move-messages (length msgs
))
150 (if copy
"Copying messages" "Moving messages")
151 (elmo-folder-move-messages src msgs dst copy
))
152 (when (and copy msgs
)
153 (setq ignore-list
(elmo-number-set-append-list ignore-list msgs
))))
154 (elmo-folder-close src
))
155 (run-hooks 'elmo-pipe-drained-hook
)
158 (defun elmo-pipe-folder-copied-list-load (folder)
160 (expand-file-name elmo-pipe-folder-copied-filename
162 (elmo-replace-string-as-filename
163 (elmo-folder-name-internal folder
))
164 (expand-file-name "pipe" elmo-msgdb-directory
)))
167 (defun elmo-pipe-folder-copied-list-save (folder copied-list
)
169 (expand-file-name elmo-pipe-folder-copied-filename
171 (elmo-replace-string-as-filename
172 (elmo-folder-name-internal folder
))
173 (expand-file-name "pipe" elmo-msgdb-directory
)))
176 (luna-define-method elmo-folder-msgdb
((folder elmo-pipe-folder
))
177 (elmo-folder-msgdb (elmo-pipe-folder-dst-internal folder
)))
179 (luna-define-method elmo-folder-open-internal
((folder elmo-pipe-folder
))
180 (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder
)))
182 (luna-define-method elmo-folder-close-internal
((folder elmo-pipe-folder
))
183 (elmo-folder-close-internal (elmo-pipe-folder-dst-internal folder
)))
185 (luna-define-method elmo-folder-close
((folder elmo-pipe-folder
))
186 (elmo-generic-folder-close folder
)
187 (elmo-folder-close (elmo-pipe-folder-dst-internal folder
)))
189 (luna-define-method elmo-folder-list-messages
((folder elmo-pipe-folder
)
190 &optional visible-only in-msgdb
)
191 ;; Use target folder's killed-list in the pipe folder.
192 (elmo-folder-list-messages (elmo-pipe-folder-dst-internal
193 folder
) visible-only in-msgdb
))
195 (luna-define-method elmo-folder-diff
((folder elmo-pipe-folder
))
196 (elmo-folder-open-internal (elmo-pipe-folder-src-internal folder
))
197 (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder
))
198 (let* ((elmo-inhibit-number-mapping
199 (not (elmo-pipe-folder-copy-internal folder
)))
200 (src-length (length (elmo-pipe-folder-list-target-messages
201 (elmo-pipe-folder-src-internal folder
)
202 (elmo-pipe-folder-copied-list-load folder
))))
203 (dst-diff (elmo-folder-diff (elmo-pipe-folder-dst-internal folder
))))
206 ((consp (cdr dst-diff
)) ; new unread all
207 (mapcar (lambda (number) (+ number src-length
)) dst-diff
))
209 (cons (+ (or (car dst-diff
) 0) src-length
)
210 (+ (or (cdr dst-diff
) 0) src-length
))))
212 (elmo-folder-close-internal (elmo-pipe-folder-src-internal folder
))
213 (elmo-folder-close-internal (elmo-pipe-folder-dst-internal folder
)))))
215 (luna-define-method elmo-folder-exists-p
((folder elmo-pipe-folder
))
216 (and (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder
))
217 (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder
))))
219 (luna-define-method elmo-folder-expand-msgdb-path
((folder
221 ;; Share with destination...OK?
222 (elmo-folder-expand-msgdb-path (elmo-pipe-folder-dst-internal folder
)))
224 (luna-define-method elmo-folder-newsgroups
((folder elmo-pipe-folder
))
225 (elmo-folder-newsgroups (elmo-pipe-folder-src-internal folder
)))
227 (luna-define-method elmo-folder-creatable-p
((folder elmo-pipe-folder
))
229 (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder
))
230 (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder
)))
232 (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder
))
233 (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder
)))))
235 (luna-define-method elmo-folder-writable-p
((folder elmo-pipe-folder
))
236 (elmo-folder-writable-p (elmo-pipe-folder-dst-internal folder
)))
238 (luna-define-method elmo-folder-recover-messages
((folder elmo-pipe-folder
)
240 (elmo-folder-recover-messages
241 (elmo-pipe-folder-dst-internal folder
) numbers
))
243 (luna-define-method elmo-folder-create
((folder elmo-pipe-folder
))
244 (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder
)))
245 (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder
)))
246 (elmo-folder-create (elmo-pipe-folder-src-internal folder
)))
247 (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder
)))
248 (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder
)))
249 (elmo-folder-create (elmo-pipe-folder-dst-internal folder
))))
251 (luna-define-method elmo-folder-search
((folder elmo-pipe-folder
)
252 condition
&optional numlist
)
253 (elmo-folder-search (elmo-pipe-folder-dst-internal folder
)
256 (luna-define-method elmo-message-use-cache-p
((folder elmo-pipe-folder
) number
)
257 (elmo-message-use-cache-p (elmo-pipe-folder-dst-internal folder
) number
))
259 (luna-define-method elmo-folder-check
((folder elmo-pipe-folder
))
260 (elmo-folder-check (elmo-pipe-folder-dst-internal folder
)))
262 (luna-define-method elmo-folder-plugged-p
((folder elmo-pipe-folder
))
263 (and (elmo-folder-plugged-p (elmo-pipe-folder-src-internal folder
))
264 (elmo-folder-plugged-p (elmo-pipe-folder-dst-internal folder
))))
266 (luna-define-method elmo-folder-set-plugged
((folder elmo-pipe-folder
)
267 plugged
&optional add
)
268 (elmo-folder-set-plugged (elmo-pipe-folder-src-internal folder
)
270 (elmo-folder-set-plugged (elmo-pipe-folder-dst-internal folder
)
273 (luna-define-method elmo-folder-message-file-p
((folder elmo-pipe-folder
))
274 (elmo-folder-message-file-p (elmo-pipe-folder-dst-internal folder
)))
276 (luna-define-method elmo-message-file-p
((folder elmo-pipe-folder
) number
)
277 (elmo-message-file-p (elmo-pipe-folder-dst-internal folder
) number
))
279 (luna-define-method elmo-message-file-name
((folder elmo-pipe-folder
) number
)
280 (elmo-message-file-name (elmo-pipe-folder-dst-internal folder
) number
))
282 (luna-define-method elmo-folder-message-file-number-p
((folder
284 (elmo-folder-message-file-number-p (elmo-pipe-folder-dst-internal folder
)))
286 (luna-define-method elmo-folder-message-file-directory
((folder
288 (elmo-folder-message-file-directory
289 (elmo-pipe-folder-dst-internal folder
)))
291 (luna-define-method elmo-folder-message-make-temp-file-p
292 ((folder elmo-pipe-folder
))
293 (elmo-folder-message-make-temp-file-p
294 (elmo-pipe-folder-dst-internal folder
)))
296 (luna-define-method elmo-folder-message-make-temp-files
((folder
301 (elmo-folder-message-make-temp-files
302 (elmo-pipe-folder-dst-internal folder
) numbers start-number
))
304 (luna-define-method elmo-folder-set-flag
((folder elmo-pipe-folder
)
308 (elmo-folder-set-flag (elmo-pipe-folder-dst-internal folder
)
309 numbers flag is-local
))
311 (luna-define-method elmo-folder-unset-flag
((folder elmo-pipe-folder
)
315 (elmo-folder-unset-flag (elmo-pipe-folder-dst-internal folder
)
316 numbers flag is-local
))
318 (luna-define-method elmo-folder-pack-numbers
((folder elmo-pipe-folder
))
319 (elmo-folder-pack-numbers (elmo-pipe-folder-dst-internal folder
)))
321 (luna-define-method elmo-folder-rename
((folder elmo-pipe-folder
) new-name
)
322 (let* ((new-folder (elmo-get-folder new-name
)))
323 (unless (string= (elmo-folder-name-internal
324 (elmo-pipe-folder-src-internal folder
))
325 (elmo-folder-name-internal
326 (elmo-pipe-folder-src-internal new-folder
)))
327 (error "Source folder differ"))
328 (unless (eq (elmo-folder-type-internal
329 (elmo-pipe-folder-dst-internal folder
))
330 (elmo-folder-type-internal
331 (elmo-pipe-folder-dst-internal new-folder
)))
332 (error "Not same folder type"))
333 (elmo-folder-rename (elmo-pipe-folder-dst-internal folder
)
334 (elmo-folder-name-internal
335 (elmo-pipe-folder-dst-internal new-folder
)))
336 (elmo-global-flag-replace-referrer (elmo-folder-name-internal folder
)
338 (elmo-msgdb-rename-path folder new-folder
)))
340 (luna-define-method elmo-folder-synchronize
((folder elmo-pipe-folder
)
346 (let ((src-folder (elmo-pipe-folder-src-internal folder
))
347 (dst-folder (elmo-pipe-folder-dst-internal folder
)))
348 (when (and (elmo-folder-plugged-p src-folder
)
349 (elmo-folder-plugged-p dst-folder
))
350 (if (elmo-pipe-folder-copy-internal folder
)
351 (elmo-pipe-folder-copied-list-save
353 (elmo-pipe-drain src-folder
356 (elmo-pipe-folder-copied-list-load folder
)))
357 (elmo-pipe-drain src-folder dst-folder
))))
358 (elmo-folder-synchronize
359 (elmo-pipe-folder-dst-internal folder
)
360 disable-killed ignore-msgdb no-check mask
))
362 (luna-define-method elmo-folder-list-flagged
((folder elmo-pipe-folder
)
365 (elmo-folder-list-flagged
366 (elmo-pipe-folder-dst-internal folder
) flag in-msgdb
))
368 (luna-define-method elmo-folder-commit
((folder elmo-pipe-folder
))
369 (elmo-folder-commit (elmo-pipe-folder-dst-internal folder
)))
371 (luna-define-method elmo-folder-length
((folder elmo-pipe-folder
))
372 (elmo-folder-length (elmo-pipe-folder-dst-internal folder
)))
374 (luna-define-method elmo-message-flag-available-p
((folder elmo-pipe-folder
)
376 (elmo-message-flag-available-p
377 (elmo-pipe-folder-dst-internal folder
)
380 (luna-define-method elmo-folder-count-flags
((folder elmo-pipe-folder
))
381 (elmo-folder-count-flags (elmo-pipe-folder-dst-internal folder
)))
383 (luna-define-method elmo-message-flags
((folder elmo-pipe-folder
) number
)
384 (elmo-message-flags (elmo-pipe-folder-dst-internal folder
) number
))
386 (luna-define-method elmo-message-field
((folder elmo-pipe-folder
)
387 number field
&optional type
)
388 (elmo-message-field (elmo-pipe-folder-dst-internal folder
)
393 (luna-define-method elmo-message-killed-p
((folder elmo-pipe-folder
) number
)
394 (elmo-message-killed-p (elmo-pipe-folder-dst-internal folder
) number
))
396 (luna-define-method elmo-message-set-cached
((folder elmo-pipe-folder
)
398 (elmo-message-set-cached (elmo-pipe-folder-dst-internal folder
)
401 (luna-define-method elmo-find-fetch-strategy
((folder elmo-pipe-folder
)
406 (elmo-find-fetch-strategy (elmo-pipe-folder-dst-internal folder
)
411 (luna-define-method elmo-message-number
((folder elmo-pipe-folder
)
413 (elmo-message-number (elmo-pipe-folder-dst-internal folder
)
416 (luna-define-method elmo-message-entity
((folder elmo-pipe-folder
) key
)
417 (elmo-message-entity (elmo-pipe-folder-dst-internal folder
) key
))
419 (luna-define-method elmo-message-folder
((folder elmo-pipe-folder
)
421 (elmo-message-folder (elmo-pipe-folder-dst-internal folder
) number
))
424 (product-provide (provide 'elmo-pipe
) (require 'elmo-version
))
426 ;;; elmo-pipe.el ends here