1 ;;; elmo-shimbun.el -- Shimbun interface for ELMO.
3 ;; Copyright (C) 2001 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
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)
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.
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.
36 (defcustom elmo-shimbun-check-interval 60
37 "*Check interval for shimbun."
41 (defcustom elmo-shimbun-default-index-range 2
42 "*Default value for the range of header indices."
43 :type '(choice (const :tag "all" all)
44 (const :tag "last" last)
45 (integer :tag "number"))
48 (defcustom elmo-shimbun-use-cache t
49 "*If non-nil, use cache for each article."
53 (defcustom elmo-shimbun-index-range-alist nil
54 "*Alist of FOLDER-REGEXP and RANGE.
55 FOLDER-REGEXP is the regexp for shimbun folder name.
56 RANGE is the range of the header indices .
57 See `shimbun-headers' for more detail about RANGE."
58 :type '(repeat (cons (regexp :tag "Folder Regexp")
59 (choice (const :tag "all" all)
60 (const :tag "last" last)
61 (integer :tag "number"))))
66 (luna-define-class shimbun-elmo-mua (shimbun-mua) (folder))
67 (luna-define-internal-accessors 'shimbun-elmo-mua))
69 (luna-define-method shimbun-mua-search-id ((mua shimbun-elmo-mua) id)
70 (elmo-msgdb-overview-get-entity id
72 (shimbun-elmo-mua-folder-internal mua))))
75 (luna-define-class elmo-shimbun-folder
76 (elmo-map-folder) (shimbun headers header-hash
77 group range last-check))
78 (luna-define-internal-accessors 'elmo-shimbun-folder))
80 (defsubst elmo-shimbun-lapse-seconds (time)
81 (let ((now (current-time)))
82 (+ (* (- (car now) (car time)) 65536)
83 (- (nth 1 now) (nth 1 time)))))
85 (defun elmo-shimbun-parse-time-string (string)
86 "Parse the time-string STRING and return its time as Emacs style."
88 (let ((x (timezone-fix-time string nil nil)))
89 (encode-time (aref x 5) (aref x 4) (aref x 3)
90 (aref x 2) (aref x 1) (aref x 0)
93 (defsubst elmo-shimbun-headers-check-p (folder)
94 (or (null (elmo-shimbun-folder-last-check-internal folder))
95 (and (elmo-shimbun-folder-last-check-internal folder)
96 (> (elmo-shimbun-lapse-seconds
97 (elmo-shimbun-folder-last-check-internal folder))
98 elmo-shimbun-check-interval))))
100 (defun elmo-shimbun-msgdb-to-headers (folder expire-days)
102 (dolist (ov (elmo-msgdb-get-overview (elmo-folder-msgdb folder)))
103 (when (and (elmo-msgdb-overview-entity-get-extra-field ov "xref")
105 (< (elmo-shimbun-lapse-seconds
106 (elmo-shimbun-parse-time-string
107 (elmo-msgdb-overview-entity-get-date ov)))
108 (* expire-days 86400 ; seconds per day
112 (cons (shimbun-make-header
113 (elmo-msgdb-overview-entity-get-number ov)
114 (shimbun-mime-encode-string
115 (elmo-msgdb-overview-entity-get-subject ov))
116 (shimbun-mime-encode-string
117 (elmo-msgdb-overview-entity-get-from ov))
118 (elmo-msgdb-overview-entity-get-date ov)
119 (elmo-msgdb-overview-entity-get-id ov)
120 (elmo-msgdb-overview-entity-get-references ov)
123 (elmo-msgdb-overview-entity-get-extra-field ov "xref"))
127 (defun elmo-shimbun-folder-setup (folder)
128 ;; Resume headers from existing msgdb.
129 (elmo-shimbun-folder-set-headers-internal
131 (elmo-shimbun-msgdb-to-headers folder nil))
132 (elmo-shimbun-folder-set-header-hash-internal
135 (length (elmo-shimbun-folder-headers-internal folder))))
136 (dolist (header (elmo-shimbun-folder-headers-internal folder))
138 (shimbun-header-id header) header
139 (elmo-shimbun-folder-header-hash-internal folder))))
141 (defun elmo-shimbun-get-headers (folder)
143 (elmo-shimbun-folder-shimbun-internal folder)
144 (elmo-shimbun-folder-group-internal folder))
145 (let* ((shimbun (elmo-shimbun-folder-shimbun-internal folder))
146 (key (concat (shimbun-server-internal shimbun)
147 "." (shimbun-current-group-internal shimbun)))
148 (elmo-hash-minimum-size 0)
155 (unless (elmo-msgdb-overview-get-entity
156 (shimbun-header-id x)
157 (elmo-folder-msgdb folder))
159 ;; This takes much time.
161 (elmo-shimbun-folder-shimbun-internal folder)
162 (elmo-shimbun-folder-range-internal folder)))))
163 (elmo-shimbun-folder-set-headers-internal
165 (nconc (elmo-shimbun-msgdb-to-headers
166 folder (shimbun-article-expiration-days
167 (elmo-shimbun-folder-shimbun-internal folder)))
170 (elmo-shimbun-folder-set-header-hash-internal
173 (length (elmo-shimbun-folder-headers-internal folder)))))
174 ;; Set up header hash.
175 (dolist (header (elmo-shimbun-folder-headers-internal folder))
177 (shimbun-header-id header) header
178 (elmo-shimbun-folder-header-hash-internal folder)))
179 (elmo-shimbun-folder-set-last-check-internal folder (current-time))))
181 (luna-define-method elmo-folder-initialize ((folder
184 (let ((server-group (if (string-match "\\([^.]+\\)\\." name)
185 (list (elmo-match-string 1 name)
186 (substring name (match-end 0)))
188 (when (nth 0 server-group) ; server
189 (elmo-shimbun-folder-set-shimbun-internal
191 (shimbun-open (nth 0 server-group)
192 (luna-make-entity 'shimbun-elmo-mua :folder folder))))
193 (when (nth 1 server-group)
194 (elmo-shimbun-folder-set-group-internal
196 (nth 1 server-group)))
197 (elmo-shimbun-folder-set-range-internal
199 (or (cdr (elmo-string-matched-assoc (elmo-folder-name-internal folder)
200 elmo-shimbun-index-range-alist))
201 elmo-shimbun-default-index-range))
204 (luna-define-method elmo-folder-open-internal ((folder elmo-shimbun-folder))
205 (when (elmo-folder-plugged-p folder)
206 (when (elmo-shimbun-headers-check-p folder)
207 (let ((inhibit-quit t))
208 (elmo-map-folder-location-setup
210 (elmo-msgdb-location-load (elmo-folder-msgdb-path folder)))
211 ;; Resume headers from existing msgdb.
212 (elmo-shimbun-folder-setup folder))
213 (elmo-shimbun-get-headers folder))
214 (elmo-map-folder-update-locations
216 (elmo-map-folder-list-message-locations folder))))
218 (luna-define-method elmo-folder-reserve-status-p ((folder elmo-shimbun-folder))
221 (luna-define-method elmo-message-use-cache-p ((folder elmo-shimbun-folder)
223 elmo-shimbun-use-cache)
225 (luna-define-method elmo-folder-close-internal :after ((folder
226 elmo-shimbun-folder))
228 (elmo-shimbun-folder-shimbun-internal folder))
229 (elmo-shimbun-folder-set-headers-internal
231 (elmo-shimbun-folder-set-header-hash-internal
233 (elmo-shimbun-folder-set-last-check-internal
236 (luna-define-method elmo-folder-plugged-p ((folder elmo-shimbun-folder))
239 (shimbun-server-internal (elmo-shimbun-folder-shimbun-internal folder))
241 (shimbun-server-internal (elmo-shimbun-folder-shimbun-internal folder))))
243 (luna-define-method elmo-folder-set-plugged ((folder elmo-shimbun-folder)
244 plugged &optional add)
245 (elmo-set-plugged plugged
247 (shimbun-server-internal
248 (elmo-shimbun-folder-shimbun-internal folder))
250 (shimbun-server-internal
251 (elmo-shimbun-folder-shimbun-internal folder))
254 (luna-define-method elmo-net-port-info ((folder elmo-shimbun-folder))
256 (shimbun-server-internal
257 (elmo-shimbun-folder-shimbun-internal folder))
260 (luna-define-method elmo-folder-check :around ((folder elmo-shimbun-folder))
261 (when (shimbun-current-group-internal
262 (elmo-shimbun-folder-shimbun-internal folder))
263 (when (and (elmo-folder-plugged-p folder)
264 (elmo-shimbun-headers-check-p folder))
265 (elmo-shimbun-get-headers folder)
266 (luna-call-next-method))))
268 (luna-define-method elmo-folder-clear :around ((folder elmo-shimbun-folder)
269 &optional keep-killed)
270 (elmo-shimbun-folder-set-headers-internal folder nil)
271 (elmo-shimbun-folder-set-header-hash-internal folder nil)
272 (elmo-shimbun-folder-set-last-check-internal folder nil)
273 (luna-call-next-method))
275 (luna-define-method elmo-folder-expand-msgdb-path ((folder
276 elmo-shimbun-folder))
278 (concat (shimbun-server-internal
279 (elmo-shimbun-folder-shimbun-internal folder))
281 (elmo-shimbun-folder-group-internal folder))
282 (expand-file-name "shimbun" elmo-msgdb-dir)))
284 (defun elmo-shimbun-msgdb-create-entity (folder number)
285 (let ((header (elmo-get-hash-val
286 (elmo-map-message-location folder number)
287 (elmo-shimbun-folder-header-hash-internal folder)))
291 (shimbun-header-insert
292 (elmo-shimbun-folder-shimbun-internal folder)
294 (setq ov (elmo-msgdb-create-overview-from-buffer number))
295 (elmo-msgdb-overview-entity-set-extra
298 (elmo-msgdb-overview-entity-get-extra ov)
299 (list (cons "xref" (shimbun-header-xref header)))))))))
301 (luna-define-method elmo-folder-msgdb-create ((folder elmo-shimbun-folder)
303 already-mark seen-mark
306 (let* (overview number-alist mark-alist entity
307 i percent number length pair msgid gmark seen)
308 (setq length (length numlist))
310 (message "Creating msgdb...")
313 (elmo-shimbun-msgdb-create-entity
314 folder (car numlist)))
317 (elmo-msgdb-append-element
319 (setq number (elmo-msgdb-overview-entity-get-number entity))
320 (setq msgid (elmo-msgdb-overview-entity-get-id entity))
322 (elmo-msgdb-number-add number-alist
324 (setq seen (member msgid seen-list))
325 (if (setq gmark (or (elmo-msgdb-global-mark-get msgid)
326 (if (elmo-file-cache-status
327 (elmo-file-cache-get msgid))
328 (if seen nil already-mark)
330 (if elmo-shimbun-use-cache
334 (elmo-msgdb-mark-append mark-alist
336 (when (> length elmo-display-progress-threshold)
338 (setq percent (/ (* i 100) length))
339 (elmo-display-progress
340 'elmo-folder-msgdb-create "Creating msgdb..."
342 (setq numlist (cdr numlist)))
343 (message "Creating msgdb...done.")
344 (elmo-msgdb-sort-by-date
345 (list overview number-alist mark-alist))))
347 (luna-define-method elmo-folder-message-file-p ((folder elmo-shimbun-folder))
350 (luna-define-method elmo-map-message-fetch ((folder elmo-shimbun-folder)
352 &optional section unseen)
353 (shimbun-article (elmo-shimbun-folder-shimbun-internal folder)
356 (elmo-shimbun-folder-header-hash-internal folder))))
358 (luna-define-method elmo-message-encache :around ((folder
360 number &optional read)
361 (if (elmo-folder-plugged-p folder)
362 (luna-call-next-method)
363 (if elmo-enable-disconnected-operation
364 (elmo-message-encache-dop folder number read)
365 (error "Unplugged"))))
367 (luna-define-method elmo-folder-list-messages-internal :around
368 ((folder elmo-shimbun-folder) &optional nohide)
369 (if (elmo-folder-plugged-p folder)
370 (luna-call-next-method)
373 (luna-define-method elmo-map-folder-list-message-locations
374 ((folder elmo-shimbun-folder))
376 (function shimbun-header-id)
377 (elmo-shimbun-folder-headers-internal folder)))
379 (luna-define-method elmo-folder-list-subfolders ((folder elmo-shimbun-folder)
381 (unless (elmo-shimbun-folder-group-internal folder)
384 (concat (elmo-folder-prefix-internal folder)
385 (shimbun-server-internal
386 (elmo-shimbun-folder-shimbun-internal folder))
389 (shimbun-groups (elmo-shimbun-folder-shimbun-internal folder)))))
391 (luna-define-method elmo-folder-exists-p ((folder elmo-shimbun-folder))
392 (if (elmo-shimbun-folder-group-internal folder)
395 (elmo-shimbun-folder-group-internal folder)
396 (shimbun-groups (elmo-shimbun-folder-shimbun-internal
400 (luna-define-method elmo-folder-search ((folder elmo-shimbun-folder)
401 condition &optional from-msgs)
404 ;;; To override elmo-map-folder methods.
405 (luna-define-method elmo-folder-list-unreads-internal
406 ((folder elmo-shimbun-folder) unread-marks &optional mark-alist)
409 (luna-define-method elmo-folder-unmark-important ((folder elmo-shimbun-folder)
413 (luna-define-method elmo-folder-mark-as-important ((folder elmo-shimbun-folder)
417 (luna-define-method elmo-folder-unmark-read ((folder elmo-shimbun-folder)
421 (luna-define-method elmo-folder-mark-as-read ((folder elmo-shimbun-folder)
426 (product-provide (provide 'elmo-shimbun) (require 'elmo-version))
428 ;;; elmo-shimbun.el ends here