* wl-expire.el (wl-summary-archive): Fixed;
[elisp/wanderlust.git] / elmo / elmo-pipe.el
1 ;;; elmo-pipe.el -- PIPE Interface for ELMO.
2
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7
8 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
9
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)
13 ;; any later version.
14 ;;
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.
19 ;;
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.
24 ;;
25
26 ;;; Commentary:
27 ;; 
28
29 ;;; Code:
30 ;; 
31
32 (require 'elmo)
33
34 ;;; ELMO pipe folder
35 (eval-and-compile
36   (luna-define-class elmo-pipe-folder (elmo-folder)
37                      (src dst))
38   (luna-define-internal-accessors 'elmo-pipe-folder))
39
40 (luna-define-method elmo-folder-initialize ((folder elmo-pipe-folder)
41                                             name)
42   (when (string-match "^\\([^|]*\\)|\\(.*\\)$" name)
43     (elmo-pipe-folder-set-src-internal folder
44                                        (elmo-make-folder
45                                         (elmo-match-string 1 name)))
46     (elmo-pipe-folder-set-dst-internal folder
47                                        (elmo-make-folder
48                                         (elmo-match-string 2 name))))
49   folder)
50
51 (luna-define-method elmo-folder-get-primitive-list ((folder elmo-pipe-folder))
52   (elmo-flatten
53    (mapcar
54     'elmo-folder-get-primitive-list
55     (list (elmo-pipe-folder-src-internal folder)
56           (elmo-pipe-folder-dst-internal folder)))))
57
58 (luna-define-method elmo-folder-contains-type ((folder elmo-pipe-folder)
59                                                type)
60   (or (elmo-folder-contains-type (elmo-pipe-folder-src-internal folder) type)
61       (elmo-folder-contains-type (elmo-pipe-folder-dst-internal folder) type)))
62
63 (luna-define-method elmo-folder-msgdb-create ((folder elmo-pipe-folder)
64                                               numlist new-mark already-mark
65                                               seen-mark important-mark
66                                               seen-list)
67   (elmo-folder-msgdb-create (elmo-pipe-folder-dst-internal folder)
68                             numlist new-mark already-mark
69                             seen-mark important-mark seen-list))
70
71 (luna-define-method elmo-folder-append-messages ((folder elmo-pipe-folder)
72                                                  src-folder numbers
73                                                  unread-marks
74                                                  &optional same-number)
75   (elmo-folder-append-messages (elmo-pipe-folder-dst-internal folder)
76                                src-folder numbers
77                                unread-marks
78                                same-number))
79
80 (luna-define-method elmo-folder-append-buffer ((folder elmo-pipe-folder)
81                                                unread &optional number)
82   (elmo-folder-append-buffer (elmo-pipe-folder-dst-internal folder)
83                              unread number))
84
85 (luna-define-method elmo-message-fetch ((folder elmo-pipe-folder)
86                                         number strategy
87                                         &optional section outbuf unseen)
88   (elmo-message-fetch (elmo-pipe-folder-dst-internal folder)
89                       number strategy section outbuf unseen))
90
91 (luna-define-method elmo-folder-delete-messages ((folder elmo-pipe-folder)
92                                                  numbers)
93   (elmo-folder-delete-messages (elmo-pipe-folder-dst-internal folder)
94                                numbers))
95
96 (defvar elmo-pipe-drained-hook nil "A hook called when the pipe is flushed.")
97
98 (defun elmo-pipe-drain (src dst)
99   "Move all messages of SRC to DST."
100   (let ((elmo-inhibit-number-mapping t) ; No need to use UIDL
101         msgs len)
102     (message "Checking %s..." (elmo-folder-name-internal src))
103     (elmo-folder-open-internal src)
104     (setq msgs (elmo-folder-list-messages src)
105           len (length msgs))
106     (when (> len elmo-display-progress-threshold)
107       (elmo-progress-set 'elmo-folder-move-messages
108                          len "Moving messages..."))
109     (elmo-folder-move-messages src msgs dst)
110     (elmo-progress-clear 'elmo-folder-move-messages))
111   ;; Don't save msgdb here.
112   ;; Because summary view of original folder is not updated yet.
113   (elmo-folder-close-internal src)
114   (run-hooks 'elmo-pipe-drained-hook))
115
116 (luna-define-method elmo-folder-open-internal ((folder elmo-pipe-folder))
117   (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder))
118   (let ((src-folder (elmo-pipe-folder-src-internal folder))
119         (dst-folder (elmo-pipe-folder-dst-internal folder)))
120     (when (and (elmo-folder-plugged-p src-folder)
121                (elmo-folder-plugged-p dst-folder))
122       (elmo-pipe-drain src-folder dst-folder))))
123
124 (luna-define-method elmo-folder-close-internal ((folder elmo-pipe-folder))
125   (elmo-folder-close-internal(elmo-pipe-folder-dst-internal folder)))
126
127 (luna-define-method elmo-folder-list-messages-internal
128   ((folder elmo-pipe-folder) &optional nohide)
129   (elmo-folder-list-messages-internal (elmo-pipe-folder-dst-internal
130                                        folder) nohide))
131
132 (luna-define-method elmo-folder-list-unreads-internal
133   ((folder elmo-pipe-folder) unread-marks &optional mark-alist)
134   (elmo-folder-list-unreads-internal (elmo-pipe-folder-dst-internal folder)
135                                      unread-marks mark-alist))
136   
137 (luna-define-method elmo-folder-list-importants-internal
138   ((folder elmo-pipe-folder) important-mark)
139   (elmo-folder-list-importants-internal (elmo-pipe-folder-dst-internal folder)
140                                         important-mark))
141
142 (luna-define-method elmo-folder-status ((folder elmo-pipe-folder))
143   (elmo-folder-open-internal (elmo-pipe-folder-src-internal folder))
144   (elmo-folder-open-internal (elmo-pipe-folder-dst-internal folder))
145   (let* ((elmo-inhibit-number-mapping t)
146          (src-length (length (elmo-folder-list-messages
147                               (elmo-pipe-folder-src-internal folder))))
148          (dst-list (elmo-folder-list-messages
149                     (elmo-pipe-folder-dst-internal folder))))
150     (prog1 (cons (+ src-length (elmo-max-of-list dst-list))
151                  (+ src-length (length dst-list)))
152       ;; No save.
153       (elmo-folder-close-internal (elmo-pipe-folder-src-internal folder))
154       (elmo-folder-close-internal (elmo-pipe-folder-dst-internal folder)))))
155
156 (luna-define-method elmo-folder-exists-p ((folder elmo-pipe-folder))
157   (and (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder))
158        (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder))))
159
160 (luna-define-method elmo-folder-expand-msgdb-path ((folder
161                                                     elmo-pipe-folder))
162   ;; Share with destination...OK?
163   (elmo-folder-expand-msgdb-path (elmo-pipe-folder-dst-internal folder)))
164
165 (luna-define-method elmo-folder-creatable-p ((folder elmo-pipe-folder))
166   (and (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder))
167        (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder))))
168
169 (luna-define-method elmo-folder-writable-p ((folder elmo-pipe-folder))
170   (elmo-folder-writable-p (elmo-pipe-folder-dst-internal folder)))
171
172 (luna-define-method elmo-folder-create ((folder elmo-pipe-folder))
173   (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-src-internal folder)))
174            (elmo-folder-creatable-p (elmo-pipe-folder-src-internal folder)))
175       (elmo-folder-create (elmo-pipe-folder-src-internal folder)))
176   (if (and (not (elmo-folder-exists-p (elmo-pipe-folder-dst-internal folder)))
177            (elmo-folder-creatable-p (elmo-pipe-folder-dst-internal folder)))
178       (elmo-folder-create (elmo-pipe-folder-dst-internal folder))))
179
180 (luna-define-method elmo-folder-search ((folder elmo-pipe-folder)
181                                         condition &optional numlist)
182   (elmo-folder-search (elmo-pipe-folder-dst-internal folder)
183                       condition numlist))
184
185 (luna-define-method elmo-message-use-cache-p ((folder elmo-pipe-folder) number)
186   (elmo-message-use-cache-p (elmo-pipe-folder-dst-internal folder) number))
187
188 (luna-define-method elmo-folder-check ((folder elmo-pipe-folder))
189   (elmo-folder-close-internal folder)
190   (elmo-folder-open-internal folder))
191
192 (luna-define-method elmo-folder-plugged-p ((folder elmo-pipe-folder))
193   (and (elmo-folder-plugged-p (elmo-pipe-folder-src-internal folder))
194        (elmo-folder-plugged-p (elmo-pipe-folder-dst-internal folder))))
195
196 (luna-define-method elmo-folder-message-file-p ((folder elmo-pipe-folder))
197   (elmo-folder-message-file-p (elmo-pipe-folder-dst-internal folder)))
198
199 (luna-define-method elmo-message-file-p ((folder elmo-pipe-folder) number)
200   (elmo-message-file-p (elmo-pipe-folder-dst-internal folder) number))
201
202 (luna-define-method elmo-message-file-name ((folder elmo-pipe-folder) number)
203   (elmo-message-file-name (elmo-pipe-folder-dst-internal folder) number))
204
205 (luna-define-method elmo-folder-message-file-number-p ((folder
206                                                         elmo-pipe-folder))
207   (elmo-folder-message-file-number-p (elmo-pipe-folder-dst-internal folder)))
208
209 (luna-define-method elmo-folder-message-file-directory ((folder
210                                                          elmo-pipe-folder))
211   (elmo-folder-message-file-directory 
212    (elmo-pipe-folder-dst-internal folder)))
213
214 (luna-define-method elmo-folder-message-make-temp-file-p
215   ((folder elmo-pipe-folder))
216   (elmo-folder-message-make-temp-file-p
217    (elmo-pipe-folder-dst-internal folder)))
218
219 (luna-define-method elmo-folder-message-make-temp-files ((folder
220                                                           elmo-pipe-folder)
221                                                          numbers
222                                                          &optional
223                                                          start-number)
224   (elmo-folder-message-make-temp-files
225    (elmo-pipe-folder-dst-internal folder) numbers start-number))
226
227 (luna-define-method elmo-folder-mark-as-read ((folder elmo-pipe-folder)
228                                               numbers)
229   (elmo-folder-mark-as-read (elmo-pipe-folder-dst-internal folder)
230                             numbers))
231
232 (luna-define-method elmo-folder-unmark-read ((folder elmo-pipe-folder)
233                                               numbers)
234   (elmo-folder-unmark-read (elmo-pipe-folder-dst-internal folder)
235                            numbers))
236
237 (luna-define-method elmo-folder-unmark-important ((folder elmo-pipe-folder)
238                                                   numbers)
239   (elmo-folder-unmark-important (elmo-pipe-folder-dst-internal folder)
240                                 numbers))
241
242 (luna-define-method elmo-folder-mark-as-important ((folder elmo-pipe-folder)
243                                                    numbers)
244   (elmo-folder-mark-as-important (elmo-pipe-folder-dst-internal folder)
245                                  numbers))
246
247 (luna-define-method elmo-folder-pack-numbers ((folder elmo-pipe-folder))
248   (elmo-folder-pack-numbers (elmo-pipe-folder-dst-internal folder)))
249
250 (require 'product)
251 (product-provide (provide 'elmo-pipe) (require 'elmo-version))
252
253 ;;; elmo-pipe.el ends here