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
54 (elmo-match-string 2 name))))
57 (luna-define-method elmo-folder-get-primitive-list ((folder elmo-pipe-folder))
60 'elmo-folder-get-primitive-list
61 (list (elmo-pipe-folder-src-internal folder)
62 (elmo-pipe-folder-dst-internal folder)))))
64 (luna-define-method elmo-folder-contains-type ((folder elmo-pipe-folder)
66 (or (elmo-folder-contains-type (elmo-pipe-folder-src-internal folder) type)
67 (elmo-folder-contains-type (elmo-pipe-folder-dst-internal folder) type)))
69 (luna-define-method elmo-folder-msgdb-create ((folder elmo-pipe-folder)
71 (elmo-folder-msgdb-create (elmo-pipe-folder-dst-internal folder)
74 (luna-define-method elmo-folder-append-messages ((folder elmo-pipe-folder)
76 &optional same-number)
77 (elmo-folder-append-messages (elmo-pipe-folder-dst-internal folder)
81 (luna-define-method elmo-folder-append-buffer ((folder elmo-pipe-folder)
82 unread &optional number)
83 (elmo-folder-append-buffer (elmo-pipe-folder-dst-internal folder)
86 (luna-define-method elmo-message-fetch ((folder elmo-pipe-folder)
88 &optional section outbuf unseen)
89 (elmo-message-fetch (elmo-pipe-folder-dst-internal folder)
90 number strategy section outbuf unseen))
92 (luna-define-method elmo-folder-delete-messages ((folder elmo-pipe-folder)
94 (elmo-folder-delete-messages (elmo-pipe-folder-dst-internal folder)
97 (defvar elmo-pipe-drained-hook nil "A hook called when the pipe is flushed.")
99 (defsubst elmo-pipe-folder-list-target-messages (src &optional ignore-list)
102 (elmo-folder-set-killed-list-internal src ignore-list)
103 (elmo-folder-list-messages src))
104 (elmo-folder-set-killed-list-internal src nil)))
106 (defun elmo-pipe-drain (src dst &optional copy ignore-list)
107 "Move or copy all messages of SRC to DST."
108 (let ((elmo-inhibit-number-mapping (not copy)) ; No need to use UIDL
110 (message "Checking %s..." (elmo-folder-name-internal src))
111 ;; Warnnig: some function requires msgdb
112 ;; but elmo-folder-open-internal do not load msgdb.
113 (elmo-folder-open-internal src)
114 (setq msgs (elmo-pipe-folder-list-target-messages src ignore-list)
116 (when (> len elmo-display-progress-threshold)
117 (elmo-progress-set 'elmo-folder-move-messages
120 "Copying messages..."
121 "Moving messages...")))
123 (elmo-folder-move-messages src msgs dst
125 (elmo-progress-clear 'elmo-folder-move-messages))
126 (when (and copy msgs)
127 (setq ignore-list (elmo-number-set-append-list ignore-list
129 ;; Don't save msgdb here.
130 ;; Because summary view of original folder is not updated yet.
131 (elmo-folder-close-internal src)
132 (run-hooks 'elmo-pipe-drained-hook)
135 (defun elmo-pipe-folder-copied-list-load (folder)
137 (expand-file-name elmo-pipe-folder-copied-filename
139 (elmo-replace-string-as-filename
140 (elmo-folder-name-internal folder))
141 (expand-file-name "pipe" elmo-msgdb-directory)))
144 (defun elmo-pipe-folder-copied-list-save (folder copied-list)
146 (expand-file-name elmo-pipe-folder-copied-filename
148 (elmo-replace-string-as-filename
149 (elmo-folder-name-internal folder))
150 (expand-file-name "pipe" elmo-msgdb-directory)))
153 (luna-define-method elmo-folder-open-internal ((folder elmo-pipe-folder))
154 (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder))
155 (let ((src-folder (elmo-pipe-folder-src-internal folder))
156 (dst-folder (elmo-pipe-folder-dst-internal folder)))
157 (when (and (elmo-folder-plugged-p src-folder)
158 (elmo-folder-plugged-p dst-folder))
159 (if (elmo-pipe-folder-copy-internal folder)
160 (elmo-pipe-folder-copied-list-save
162 (elmo-pipe-drain src-folder
165 (elmo-pipe-folder-copied-list-load folder)))
166 (elmo-pipe-drain src-folder dst-folder)))))
168 (luna-define-method elmo-folder-close-internal ((folder elmo-pipe-folder))
169 (elmo-folder-close-internal(elmo-pipe-folder-dst-internal folder)))
171 (luna-define-method elmo-folder-list-messages-internal
172 ((folder elmo-pipe-folder) &optional nohide)
173 (elmo-folder-list-messages-internal (elmo-pipe-folder-dst-internal
176 (luna-define-method elmo-folder-list-unreads ((folder elmo-pipe-folder))
177 (elmo-folder-list-unreads (elmo-pipe-folder-dst-internal folder)))
179 (luna-define-method elmo-folder-list-importants ((folder elmo-pipe-folder))
180 (elmo-folder-list-importants (elmo-pipe-folder-dst-internal folder)))
182 (luna-define-method elmo-folder-list-answereds ((folder elmo-pipe-folder))
183 (elmo-folder-list-answereds (elmo-pipe-folder-dst-internal folder)))
185 (luna-define-method elmo-folder-status ((folder elmo-pipe-folder))
186 (elmo-folder-open-internal (elmo-pipe-folder-src-internal folder))
187 (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder))
188 (let* ((elmo-inhibit-number-mapping
189 (not (elmo-pipe-folder-copy-internal folder)))
190 (src-length (length (elmo-pipe-folder-list-target-messages
191 (elmo-pipe-folder-src-internal folder)
192 (elmo-pipe-folder-copied-list-load folder))))
193 (dst-list (elmo-folder-list-messages
194 (elmo-pipe-folder-dst-internal folder))))
195 (prog1 (cons (+ src-length (elmo-max-of-list dst-list))
196 (+ src-length (length dst-list)))
198 (elmo-folder-close-internal (elmo-pipe-folder-src-internal folder))
199 (elmo-folder-close-internal (elmo-pipe-folder-dst-internal folder)))))
201 (luna-define-method elmo-folder-exists-p ((folder elmo-pipe-folder))
202 (and (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder))
203 (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder))))
205 (luna-define-method elmo-folder-expand-msgdb-path ((folder
207 ;; Share with destination...OK?
208 (elmo-folder-expand-msgdb-path (elmo-pipe-folder-dst-internal folder)))
210 (luna-define-method elmo-folder-newsgroups ((folder elmo-pipe-folder))
211 (elmo-folder-newsgroups (elmo-pipe-folder-src-internal folder)))
213 (luna-define-method elmo-folder-creatable-p ((folder elmo-pipe-folder))
214 (and (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder))
215 (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder))))
217 (luna-define-method elmo-folder-writable-p ((folder elmo-pipe-folder))
218 (elmo-folder-writable-p (elmo-pipe-folder-dst-internal folder)))
220 (luna-define-method elmo-folder-create ((folder elmo-pipe-folder))
221 (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder)))
222 (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder)))
223 (elmo-folder-create (elmo-pipe-folder-src-internal folder)))
224 (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder)))
225 (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder)))
226 (elmo-folder-create (elmo-pipe-folder-dst-internal folder))))
228 (luna-define-method elmo-folder-search ((folder elmo-pipe-folder)
229 condition &optional numlist)
230 (elmo-folder-search (elmo-pipe-folder-dst-internal folder)
233 (luna-define-method elmo-message-use-cache-p ((folder elmo-pipe-folder) number)
234 (elmo-message-use-cache-p (elmo-pipe-folder-dst-internal folder) number))
236 (luna-define-method elmo-folder-check ((folder elmo-pipe-folder))
237 (elmo-folder-close-internal folder)
238 (elmo-folder-open-internal folder))
240 (luna-define-method elmo-folder-plugged-p ((folder elmo-pipe-folder))
241 (and (elmo-folder-plugged-p (elmo-pipe-folder-src-internal folder))
242 (elmo-folder-plugged-p (elmo-pipe-folder-dst-internal folder))))
244 (luna-define-method elmo-folder-message-file-p ((folder elmo-pipe-folder))
245 (elmo-folder-message-file-p (elmo-pipe-folder-dst-internal folder)))
247 (luna-define-method elmo-message-file-p ((folder elmo-pipe-folder) number)
248 (elmo-message-file-p (elmo-pipe-folder-dst-internal folder) number))
250 (luna-define-method elmo-message-file-name ((folder elmo-pipe-folder) number)
251 (elmo-message-file-name (elmo-pipe-folder-dst-internal folder) number))
253 (luna-define-method elmo-folder-message-file-number-p ((folder
255 (elmo-folder-message-file-number-p (elmo-pipe-folder-dst-internal folder)))
257 (luna-define-method elmo-folder-message-file-directory ((folder
259 (elmo-folder-message-file-directory
260 (elmo-pipe-folder-dst-internal folder)))
262 (luna-define-method elmo-folder-message-make-temp-file-p
263 ((folder elmo-pipe-folder))
264 (elmo-folder-message-make-temp-file-p
265 (elmo-pipe-folder-dst-internal folder)))
267 (luna-define-method elmo-folder-message-make-temp-files ((folder
272 (elmo-folder-message-make-temp-files
273 (elmo-pipe-folder-dst-internal folder) numbers start-number))
275 (luna-define-method elmo-folder-mark-as-read ((folder elmo-pipe-folder)
276 numbers &optional ignore-flag)
277 (elmo-folder-mark-as-read (elmo-pipe-folder-dst-internal folder)
278 numbers ignore-flag))
280 (luna-define-method elmo-folder-unmark-read ((folder elmo-pipe-folder)
282 &optional ignore-flag)
283 (elmo-folder-unmark-read (elmo-pipe-folder-dst-internal folder)
284 numbers ignore-flag))
286 (luna-define-method elmo-folder-unmark-important ((folder elmo-pipe-folder)
288 (elmo-folder-unmark-important (elmo-pipe-folder-dst-internal folder)
291 (luna-define-method elmo-folder-mark-as-important ((folder elmo-pipe-folder)
293 (elmo-folder-mark-as-important (elmo-pipe-folder-dst-internal folder)
296 (luna-define-method elmo-folder-pack-numbers ((folder elmo-pipe-folder))
297 (elmo-folder-pack-numbers (elmo-pipe-folder-dst-internal folder)))
300 (product-provide (provide 'elmo-pipe) (require 'elmo-version))
302 ;;; elmo-pipe.el ends here