* mmelmo-imap4-2.el (mmelmo-imap4-get-mime-entity):
[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
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 (require 'elmo-msgdb)
32
33 (defun elmo-filter-msgdb-create (spec numlist new-mark already-mark
34                                       seen-mark important-mark seen-list)
35   (if (eq (nth 2 spec) 'partial)
36       (elmo-msgdb-create (nth 2 spec)
37                          numlist
38                          new-mark
39                          already-mark
40                          seen-mark important-mark seen-list)
41     (elmo-msgdb-create-as-numlist (nth 2 spec)
42                                   numlist
43                                   new-mark
44                                   already-mark
45                                   seen-mark important-mark seen-list)))
46
47 (defun elmo-filter-msgdb-create-as-numlist (spec numlist new-mark already-mark
48                                                  seen-mark important-mark
49                                                  seen-list)
50   (elmo-msgdb-create-as-numlist (nth 2 spec)
51                                 numlist
52                                 new-mark
53                                 already-mark
54                                 seen-mark important-mark seen-list))
55   
56 (defun elmo-filter-list-folders (spec &optional hierarchy)
57   nil)
58
59 (defun elmo-filter-append-msg (spec string &optional msg no-see)
60   (elmo-call-func (nth 2 spec) "append" string))
61
62 (defun elmo-filter-read-msg (spec number outbuf)
63   (elmo-call-func (nth 2 spec) "read-msg" number outbuf))
64
65 (defun elmo-filter-delete-msgs (spec msgs)
66   (elmo-call-func (nth 2 spec) "delete-msgs" msgs))
67
68 (defun elmo-filter-list-folder (spec)
69   (let ((filter (nth 1 spec))
70         (folder (nth 2 spec))
71         numbers)
72     (cond
73      ((vectorp filter)
74       (cond ((string= (elmo-filter-key filter)
75                       "last")
76              (setq numbers (elmo-list-folder folder))
77              (nthcdr (max (- (length numbers)
78                              (string-to-int (elmo-filter-value filter)))
79                           0)
80                      numbers))
81             ((string= (elmo-filter-key filter)
82                       "first")
83              (setq numbers (elmo-list-folder folder))
84              (let ((rest (nthcdr (string-to-int (elmo-filter-value filter) )
85                                  numbers)))
86                (mapcar '(lambda (x)
87                           (delete x numbers)) rest))
88              numbers)))
89      ((listp filter)
90       (elmo-search folder filter)))))
91
92 (defun elmo-filter-list-folder-unread (spec mark-alist unread-marks)
93   (let ((filter (nth 1 spec))
94         (folder (nth 2 spec))
95         msgs pair)
96     (cond
97      ((vectorp filter)
98       (cond ((string= (elmo-filter-key filter)
99                       "last")
100              (setq msgs (elmo-list-folder-unread folder mark-alist
101                                                  unread-marks))
102              (nthcdr (max (- (length msgs)
103                              (string-to-int (elmo-filter-value filter)))
104                           0)
105                      msgs))
106             ((string= (elmo-filter-key filter)
107                       "first")
108              (setq msgs (elmo-list-folder-unread folder
109                                                  mark-alist
110                                                  unread-marks))
111              (let ((rest (nthcdr (string-to-int (elmo-filter-value filter) )
112                                  msgs)))
113                (mapcar '(lambda (x)
114                           (delete x msgs)) rest))
115              msgs)))
116      ((listp filter)
117       (elmo-list-filter
118        (elmo-search folder filter)
119        (elmo-list-folder-unread folder mark-alist unread-marks))))))
120
121 (defun elmo-filter-list-folder-important (spec overview)
122   (let ((filter (nth 1 spec))
123         (folder (nth 2 spec))
124         msgs pair)
125     (cond
126      ((vectorp filter)
127       (cond ((string= (elmo-filter-key filter)
128                       "last")
129              (setq msgs (elmo-list-folder-important folder overview))
130              (nthcdr (max (- (length msgs)
131                              (string-to-int (elmo-filter-value filter)))
132                           0)
133                      msgs))
134             ((string= (elmo-filter-key filter)
135                       "first")
136              (setq msgs (elmo-list-folder-important folder overview))
137              (let ((rest (nthcdr (string-to-int (elmo-filter-value filter) )
138                                  msgs)))
139                (mapcar '(lambda (x)
140                           (delete x msgs)) rest))
141              msgs)))
142      ((listp filter)
143       (elmo-list-filter
144        (mapcar
145         '(lambda (x) (elmo-msgdb-overview-entity-get-number x))
146         overview)
147        (elmo-list-folder-important folder overview))))))
148
149 (defun elmo-filter-max-of-folder (spec)
150   (elmo-max-of-folder (nth 2 spec)))
151
152 (defun elmo-filter-folder-exists-p (spec)
153   (elmo-folder-exists-p (nth 2 spec)))
154
155 (defun elmo-filter-folder-creatable-p (spec)
156   (elmo-call-func (nth 2 spec) "folder-creatable-p"))
157
158 (defun elmo-filter-create-folder (spec)
159   (elmo-create-folder (nth 2 spec)))
160
161 (defun elmo-filter-search (spec condition &optional numlist)
162   ;; search from messages in this folder
163   (elmo-list-filter
164    numlist
165    (elmo-call-func (nth 2 spec) "search" condition
166                    (elmo-filter-list-folder spec))))
167
168 (defun elmo-filter-use-cache-p (spec number)
169   (elmo-call-func (nth 2 spec) "use-cache-p" number))
170
171 (defun elmo-filter-local-file-p (spec number)
172   (elmo-call-func (nth 2 spec) "local-file-p" number))
173
174 (defun elmo-filter-commit (spec)
175   (elmo-commit (nth 2 spec)))
176
177 (defun elmo-filter-plugged-p (spec)
178   (elmo-folder-plugged-p (nth 2 spec)))
179
180 (defun elmo-filter-set-plugged (spec plugged add)
181   (elmo-folder-set-plugged (nth 2 spec) plugged add))
182
183 (defun elmo-filter-get-msg-filename (spec number &optional loc-alist)
184   ;; This function may be called when elmo-filter-local-file-p()
185   ;; returns t.
186   (elmo-call-func (nth 2 spec) "get-msg-filename" number loc-alist))
187
188 (defun elmo-filter-sync-number-alist (spec number-alist)
189   (elmo-call-func (nth 2 spec) "sync-number-alist" number-alist))
190
191 (defun elmo-filter-server-diff (spec)
192   (elmo-call-func (nth 2 spec) "server-diff"))
193
194 (provide 'elmo-filter)
195
196 ;;; elmo-filter.el ends here