* elmo.el (elmo-folder-list-flagged): New generic function.
[elisp/wanderlust.git] / elmo / elmo-sendlog.el
1 ;;; elmo-sendlog.el --- Sendlog folder for ELMO.
2
3 ;; Copyright (C) 2001 Kenichi OKADA <okada@opaopa.org>
4
5 ;; Author: Kenichi OKADA <okada@opaopa.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-vars)
32 (require 'elmo-util)
33 (require 'elmo)
34 (require 'elmo-map)
35
36 (defvar elmo-sendlog-filename "sendlog")
37
38 ;;; ELMO sendlog folder
39 (eval-and-compile
40   (luna-define-class elmo-sendlog-folder (elmo-map-folder) (dir-name directory))
41   (luna-define-internal-accessors 'elmo-sendlog-folder))
42
43 (luna-define-method elmo-folder-initialize ((folder elmo-sendlog-folder)
44                                             name)
45   folder)
46
47 (luna-define-method elmo-folder-expand-msgdb-path ((folder elmo-sendlog-folder))
48   (expand-file-name "sendlog"
49                     (expand-file-name "internal"
50                                       elmo-msgdb-directory)))
51
52 (luna-define-method elmo-map-folder-list-message-locations
53   ((folder elmo-sendlog-folder))
54   (elmo-sendlog-folder-list-message-locations folder))
55
56 (defun elmo-sendlog-folder-list-message-locations (folder)
57   (let ((filename (expand-file-name elmo-sendlog-filename
58                                     elmo-msgdb-directory))
59         result)
60     (if (not (file-readable-p filename))
61         nil
62       (elmo-set-work-buf
63        (as-binary-input-file
64         (insert-file-contents filename))
65        (goto-char (point-min))
66        (catch 'done
67          (while t
68            (re-search-forward "id=\\([^@]+@[^@]+\\)$" (point-at-eol) t)
69            (setq result (append result (list (match-string 1))))
70            (if (eq (1+ (point-at-eol)) (point-max))
71                (throw 'done nil)
72              (beginning-of-line 2))))))
73     result))
74
75 (luna-define-method elmo-folder-message-file-p ((folder elmo-sendlog-folder))
76   t)
77
78 (luna-define-method elmo-message-file-name ((folder elmo-sendlog-folder)
79                                             number)
80   (elmo-file-cache-get-path
81    (elmo-map-message-location folder number)))
82
83 (luna-define-method elmo-folder-msgdb-create ((folder elmo-sendlog-folder)
84                                               numbers seen-list)
85   (let ((i 0)
86         (len (length numbers))
87         overview number-alist mark-alist entity message-id
88         num mark)
89     (message "Creating msgdb...")
90     (while numbers
91       (setq entity
92             (elmo-msgdb-create-overview-entity-from-file
93              (car numbers) (elmo-message-file-name folder (car numbers))))
94       (if (null entity)
95           (elmo-folder-set-killed-list-internal
96            folder
97            (nconc
98             (elmo-folder-killed-list-internal folder)
99             (list (car numbers))))
100         (setq num (elmo-msgdb-overview-entity-get-number entity))
101         (setq overview
102               (elmo-msgdb-append-element
103                overview entity))
104         (setq message-id (elmo-msgdb-overview-entity-get-id entity))
105         (setq number-alist
106               (elmo-msgdb-number-add number-alist
107                                      num
108                                      message-id))
109         (if (setq mark (or (elmo-msgdb-global-mark-get message-id)
110                            (if (member message-id seen-list) nil
111                              elmo-msgdb-new-mark)))
112             (setq mark-alist
113                   (elmo-msgdb-mark-append
114                    mark-alist
115                    num mark)))
116         (when (> len elmo-display-progress-threshold)
117           (setq i (1+ i))
118           (elmo-display-progress
119            'elmo-sendlog-folder-msgdb-create "Creating msgdb..."
120            (/ (* i 100) len))))
121       (setq numbers (cdr numbers)))
122     (message "Creating msgdb...done")
123     (list overview number-alist mark-alist)))
124
125 (luna-define-method elmo-message-fetch-with-cache-process
126   ((folder elmo-sendlog-folder) number strategy &optional section unseen)
127   ;; disbable cache process
128   (elmo-message-fetch-internal folder number strategy section unseen))
129
130 (luna-define-method elmo-map-message-fetch ((folder elmo-sendlog-folder)
131                                             location strategy
132                                             &optional section unseen)
133   (let ((filename (elmo-file-cache-get-path location)))
134     (if (file-exists-p filename)
135         (insert-file-contents-as-binary filename)
136       (error "Now this message is not cached. Please s all"))))
137
138 (luna-define-method elmo-folder-exists-p ((folder elmo-sendlog-folder))
139   t)
140
141 (luna-define-method elmo-folder-delete-messages ((folder elmo-sendlog-folder)
142                                                  numbers)
143   (let ((killed-list (elmo-folder-killed-list-internal folder)))
144     (dolist (number numbers)
145       (setq killed-list
146             (elmo-msgdb-set-as-killed killed-list number)))
147     (elmo-folder-set-killed-list-internal folder killed-list))
148   t)
149
150 (luna-define-method elmo-message-file-p ((folder elmo-sendlog-folder) number)
151   t)
152
153 (require 'product)
154 (product-provide (provide 'elmo-sendlog) (require 'elmo-version))
155
156 ;;; elmo-sendlog.el ends here