* elmo-dop.el (elmo-folder-status-dop): If spool-folder is absent,
[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 new-mark
85                                               already-mark seen-mark
86                                               important-mark
87                                               seen-list)
88   (let ((i 0)
89         (len (length numbers))
90         overview number-alist mark-alist entity message-id
91         num mark)
92     (message "Creating msgdb...")
93     (while numbers
94       (setq entity
95             (elmo-msgdb-create-overview-entity-from-file
96              (car numbers) (elmo-message-file-name folder (car numbers))))
97       (if (null entity)
98           (elmo-folder-set-killed-list-internal
99            folder
100            (nconc
101             (elmo-folder-killed-list-internal folder)
102             (list (car numbers))))
103         (setq num (elmo-msgdb-overview-entity-get-number entity))
104         (setq overview
105               (elmo-msgdb-append-element
106                overview entity))
107         (setq message-id (elmo-msgdb-overview-entity-get-id entity))
108         (setq number-alist
109               (elmo-msgdb-number-add number-alist
110                                      num
111                                      message-id))
112         (if (setq mark (or (elmo-msgdb-global-mark-get message-id)
113                            (if (member message-id seen-list) nil new-mark)))
114             (setq mark-alist
115                   (elmo-msgdb-mark-append
116                    mark-alist
117                    num mark)))
118         (when (> len elmo-display-progress-threshold)
119           (setq i (1+ i))
120           (elmo-display-progress
121            'elmo-sendlog-folder-msgdb-create "Creating msgdb..."
122            (/ (* i 100) len))))
123       (setq numbers (cdr numbers)))
124     (message "Creating msgdb...done")
125     (list overview number-alist mark-alist)))
126
127 (luna-define-method elmo-message-fetch-with-cache-process
128   ((folder elmo-sendlog-folder) number strategy &optional section unseen)
129   ;; disbable cache process
130   (elmo-message-fetch-internal folder number strategy section unseen))
131
132 (luna-define-method elmo-map-message-fetch ((folder elmo-sendlog-folder)
133                                             location strategy
134                                             &optional section unseen)
135   (let ((filename (elmo-file-cache-get-path location)))
136     (if (file-exists-p filename)
137         (insert-file-contents-as-binary filename)
138       (error "Now this message is not cached. Please s all"))))
139
140 (luna-define-method elmo-folder-exists-p ((folder elmo-sendlog-folder))
141   t)
142
143 (luna-define-method elmo-folder-delete-messages ((folder elmo-sendlog-folder)
144                                                  numbers)
145   (let ((killed-list (elmo-folder-killed-list-internal folder)))
146     (dolist (number numbers)
147       (setq killed-list
148             (elmo-msgdb-set-as-killed killed-list number)))
149     (elmo-folder-set-killed-list-internal folder killed-list))
150   t)
151
152 (luna-define-method elmo-message-file-p ((folder elmo-sendlog-folder) number)
153   t)
154
155 ;;; To override elmo-map-folder methods.
156 (luna-define-method elmo-folder-list-unreads-internal
157   ((folder elmo-sendlog-folder) unread-marks &optional mark-alist)
158   t)
159
160 (luna-define-method elmo-folder-unmark-important ((folder elmo-sendlog-folder)
161                                                   numbers)
162   t)
163
164 (luna-define-method elmo-folder-mark-as-important ((folder elmo-sendlog-folder)
165                                                    numbers)
166   t)
167
168 (luna-define-method elmo-folder-unmark-read ((folder elmo-sendlog-folder)
169                                              numbers)
170   t)
171
172 (luna-define-method elmo-folder-mark-as-read ((folder elmo-sendlog-folder)
173                                               numbers)
174   t)
175
176 (require 'product)
177 (product-provide (provide 'elmo-sendlog) (require 'elmo-version))
178
179 ;;; elmo-sendlog.el ends here