Import 1.x.
[elisp/wanderlust.git] / elmo / elmo-filter.el
1 ;;; elmo-filter.el -- Filtered Folder Interface for ELMO.
2
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7 ;; Time-stamp: <00/03/13 18:58:42 teranisi>
8
9 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25 ;;
26
27 ;;; Commentary:
28 ;; 
29
30 ;;; Code:
31 ;; 
32 (require 'elmo-msgdb)
33
34 (defun elmo-filter-msgdb-create (spec numlist new-mark already-mark 
35                                       seen-mark important-mark seen-list)
36   (if (eq (nth 2 spec) 'partial)
37       (elmo-msgdb-create (nth 2 spec)
38                          numlist 
39                          new-mark
40                          already-mark
41                          seen-mark important-mark seen-list)
42     (elmo-msgdb-create-as-numlist (nth 2 spec)
43                                   numlist
44                                   new-mark
45                                   already-mark
46                                   seen-mark important-mark seen-list)))
47
48 (defun elmo-filter-msgdb-create-as-numlist (spec numlist new-mark already-mark
49                                                  seen-mark important-mark 
50                                                  seen-list)
51   (elmo-msgdb-create-as-numlist (nth 2 spec)
52                                 numlist
53                                 new-mark
54                                 already-mark
55                                 seen-mark important-mark seen-list))
56   
57 (defun elmo-filter-list-folders (spec &optional hierarchy)
58   nil)
59
60 (defun elmo-filter-append-msg (spec string &optional msg no-see)
61   (elmo-call-func (nth 2 spec) "append" string))
62
63 (defun elmo-filter-read-msg (spec number outbuf)
64   (elmo-call-func (nth 2 spec) "read-msg" number outbuf))
65
66 (defun elmo-filter-delete-msgs (spec msgs)
67   (elmo-call-func (nth 2 spec) "delete-msgs" msgs))
68
69 (defun elmo-filter-list-folder (spec)
70   (let ((filter (nth 1 spec))
71         (folder (nth 2 spec))
72         msgs)
73     (cond 
74      ((vectorp filter)
75       (cond ((string= (elmo-filter-key filter)
76                       "last")
77              (setq msgs (elmo-list-folder folder))
78              (nthcdr (max (- (length msgs) 
79                              (string-to-int (elmo-filter-value filter)))
80                           0)
81                      msgs))
82             ((string= (elmo-filter-key filter)
83                       "first")
84              (setq msgs (elmo-list-folder folder))
85              (let ((rest (nthcdr (string-to-int (elmo-filter-value filter) )
86                                  msgs)))
87                (mapcar '(lambda (x) 
88                           (delete x msgs)) rest))
89              msgs)))
90      ((listp filter)
91       (elmo-search folder filter)))))
92
93 (defun elmo-filter-list-folder-unread (spec mark-alist unread-marks)
94   (let ((filter (nth 1 spec))
95         (folder (nth 2 spec))
96         msgs pair)
97     (cond 
98      ((vectorp filter)
99       (cond ((string= (elmo-filter-key filter)
100                       "last")
101              (setq msgs (elmo-list-folder-unread folder mark-alist 
102                                                  unread-marks))
103              (nthcdr (max (- (length msgs) 
104                              (string-to-int (elmo-filter-value filter)))
105                           0)
106                      msgs))
107             ((string= (elmo-filter-key filter)
108                       "first")
109              (setq msgs (elmo-list-folder-unread folder
110                                                  mark-alist
111                                                  unread-marks))
112              (let ((rest (nthcdr (string-to-int (elmo-filter-value filter) )
113                                  msgs)))
114                (mapcar '(lambda (x) 
115                           (delete x msgs)) rest))
116              msgs)))
117      ((listp filter)
118       (elmo-list-filter 
119        (elmo-search folder filter)
120        (elmo-list-folder-unread folder mark-alist unread-marks))))))
121
122 (defun elmo-filter-list-folder-important (spec overview)
123   (let ((filter (nth 1 spec))
124         (folder (nth 2 spec))
125         msgs pair)
126     (cond 
127      ((vectorp filter)
128       (cond ((string= (elmo-filter-key filter)
129                       "last")
130              (setq msgs (elmo-list-folder-important folder overview))
131              (nthcdr (max (- (length msgs) 
132                              (string-to-int (elmo-filter-value filter)))
133                           0)
134                      msgs))
135             ((string= (elmo-filter-key filter)
136                       "first")
137              (setq msgs (elmo-list-folder-important folder overview))
138              (let ((rest (nthcdr (string-to-int (elmo-filter-value filter) )
139                                  msgs)))
140                (mapcar '(lambda (x) 
141                           (delete x msgs)) rest))
142              msgs)))
143      ((listp filter)
144       (elmo-list-filter 
145        (mapcar
146         '(lambda (x) (elmo-msgdb-overview-entity-get-number x))
147         overview)
148        (elmo-list-folder-important folder overview))))))
149
150 (defun elmo-filter-max-of-folder (spec)
151   (elmo-max-of-folder (nth 2 spec)))
152
153 (defun elmo-filter-folder-exists-p (spec)
154   (elmo-folder-exists-p (nth 2 spec)))
155
156 (defun elmo-filter-folder-creatable-p (spec)
157   (elmo-call-func (nth 2 spec) "folder-creatable-p"))
158
159 (defun elmo-filter-create-folder (spec)
160   (elmo-create-folder (nth 2 spec)))
161
162 (defun elmo-filter-search (spec condition &optional numlist)
163   ;; search from messages in this folder
164   (elmo-list-filter 
165    numlist 
166    (elmo-call-func (nth 2 spec) "search" condition 
167                    (elmo-filter-list-folder spec))))
168
169 (defun elmo-filter-use-cache-p (spec number)
170   (elmo-call-func (nth 2 spec) "use-cache-p" number))
171
172 (defun elmo-filter-local-file-p (spec number)
173   (elmo-call-func (nth 2 spec) "local-file-p" number))
174
175 (defun elmo-filter-commit (spec)
176   (elmo-commit (nth 2 spec)))
177
178 (defun elmo-filter-plugged-p (spec)
179   (elmo-folder-plugged-p (nth 2 spec)))
180
181 (defun elmo-filter-set-plugged (spec plugged add)
182   (elmo-folder-set-plugged (nth 2 spec) plugged add))
183
184 (defun elmo-filter-get-msg-filename (spec number &optional loc-alist)
185   ;; This function may be called when elmo-filter-local-file-p()
186   ;; returns t.
187   (elmo-call-func (nth 2 spec) "get-msg-filename" number loc-alist))
188
189 (defun elmo-filter-sync-number-alist (spec number-alist)
190   (elmo-call-func (nth 2 spec) "sync-number-alist" number-alist))
191
192 (defun elmo-filter-server-diff (spec)
193   (elmo-call-func (nth 2 spec) "server-diff"))
194
195 (provide 'elmo-filter)
196
197 ;;; elmo-filter.el ends here