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.
38 (defun-maybe shimbun-servers-list ()))
40 (defcustom elmo-shimbun-check-interval 60
41 "*Check interval for shimbun."
45 (defcustom elmo-shimbun-default-index-range 2
46 "*Default value for the range of header indices."
47 :type '(choice (const :tag "all" all)
48 (const :tag "last" last)
49 (integer :tag "number"))
52 (defcustom elmo-shimbun-use-cache t
53 "*If non-nil, use cache for each article."
57 (defcustom elmo-shimbun-index-range-alist nil
58 "*Alist of FOLDER-REGEXP and RANGE.
59 FOLDER-REGEXP is the regexp for shimbun folder name.
60 RANGE is the range of the header indices .
61 See `shimbun-headers' for more detail about RANGE."
62 :type '(repeat (cons (regexp :tag "Folder Regexp")
63 (choice (const :tag "all" all)
64 (const :tag "last" last)
65 (integer :tag "number"))))
68 (defcustom elmo-shimbun-update-overview-folder-list 'all
69 "*List of FOLDER-REGEXP.
70 FOLDER-REGEXP is the regexp of shimbun folder name which should be
71 update overview when message is fetched.
72 If it is the symbol `all', update overview for all shimbun folders."
73 :type '(choice (const :tag "All shimbun folders" all)
74 (repeat (regexp :tag "Folder Regexp")))
78 (defsubst elmo-shimbun-header-extra-field (header field-name)
79 (let ((extra (and header (shimbun-header-extra header))))
81 (cdr (assoc field-name extra)))))
83 (defsubst elmo-shimbun-header-set-extra-field (header field-name value)
84 (let ((extras (and header (shimbun-header-extra header)))
86 (if (setq extra (assoc field-name extras))
88 (shimbun-header-set-extra
90 (cons (cons field-name value) extras)))))
94 (luna-define-class shimbun-elmo-mua (shimbun-mua) (folder))
95 (luna-define-internal-accessors 'shimbun-elmo-mua))
97 (luna-define-method shimbun-mua-search-id ((mua shimbun-elmo-mua) id)
98 (elmo-message-entity (shimbun-elmo-mua-folder-internal mua) id))
101 (luna-define-class elmo-shimbun-folder
102 (elmo-map-folder) (shimbun headers header-hash
104 group range last-check))
105 (luna-define-internal-accessors 'elmo-shimbun-folder))
107 (defun elmo-shimbun-folder-entity-hash (folder)
108 (or (elmo-shimbun-folder-entity-hash-internal folder)
109 (let ((overviews (elmo-folder-list-message-entities folder))
112 (setq hash (elmo-make-hash (length overviews)))
113 (dolist (entity overviews)
114 (elmo-set-hash-val (elmo-message-entity-field entity 'message-id)
116 (when (setq id (elmo-message-entity-field entity 'x-original-id))
117 (elmo-set-hash-val id entity hash)))
118 (elmo-shimbun-folder-set-entity-hash-internal folder hash)))))
120 (defsubst elmo-shimbun-folder-shimbun-header (folder location)
121 (let ((hash (elmo-shimbun-folder-header-hash-internal folder)))
122 (or (and hash (elmo-get-hash-val location hash))
123 (let ((entity (elmo-message-entity folder location))
124 (elmo-hash-minimum-size 63)
127 (setq header (elmo-shimbun-entity-to-header entity))
129 (elmo-shimbun-folder-set-header-hash-internal
131 (setq hash (elmo-make-hash))))
132 (elmo-set-hash-val (elmo-message-entity-field entity 'message-id)
137 (defsubst elmo-shimbun-lapse-seconds (time)
138 (let ((now (current-time)))
139 (+ (* (- (car now) (car time)) 65536)
140 (- (nth 1 now) (nth 1 time)))))
142 (defsubst elmo-shimbun-headers-check-p (folder)
143 (or (null (elmo-shimbun-folder-last-check-internal folder))
144 (and (elmo-shimbun-folder-last-check-internal folder)
145 (> (elmo-shimbun-lapse-seconds
146 (elmo-shimbun-folder-last-check-internal folder))
147 elmo-shimbun-check-interval))))
149 (defun elmo-shimbun-entity-to-header (entity)
150 (let (message-id shimbun-id)
151 (if (setq message-id (elmo-message-entity-field entity 'x-original-id))
152 (setq shimbun-id (elmo-message-entity-field entity 'message-id))
153 (setq message-id (elmo-message-entity-field entity 'message-id)
155 (elmo-with-enable-multibyte
156 (shimbun-create-header
157 (elmo-message-entity-number entity)
158 (elmo-message-entity-field entity 'subject)
159 (elmo-message-entity-field entity 'from)
160 (elmo-time-make-date-string
161 (elmo-message-entity-field entity 'date))
163 (elmo-message-entity-field entity 'references)
164 (elmo-message-entity-field entity 'size)
166 (elmo-message-entity-field entity 'xref)
168 (list (cons "x-shimbun-id" shimbun-id)))))))
170 (defsubst elmo-shimbun-folder-header-hash-setup (folder headers)
171 (let ((hash (or (elmo-shimbun-folder-header-hash-internal folder)
172 (elmo-make-hash (length headers)))))
173 (dolist (header headers)
174 (elmo-set-hash-val (shimbun-header-id header) header hash))
175 (elmo-shimbun-folder-set-header-hash-internal folder hash)))
177 (defun elmo-shimbun-get-headers (folder)
178 (let* ((shimbun (elmo-shimbun-folder-shimbun-internal folder))
179 (key (concat (shimbun-server shimbun)
180 "." (shimbun-current-group shimbun)))
181 (elmo-hash-minimum-size 63)
188 (unless (elmo-message-entity folder (shimbun-header-id x))
190 ;; This takes much time.
192 (elmo-shimbun-folder-shimbun-internal folder)
193 (elmo-shimbun-folder-range-internal folder)))))
194 (elmo-shimbun-folder-set-headers-internal folder headers)
196 (elmo-shimbun-folder-header-hash-setup folder headers))
197 (elmo-shimbun-folder-set-last-check-internal folder (current-time))))
199 (luna-define-method elmo-folder-initialize ((folder
202 (if (string= name "")
204 (let ((server-group (if (string-match "\\([^.]+\\)\\." name)
205 (list (elmo-match-string 1 name)
206 (substring name (match-end 0)))
208 (when (nth 0 server-group) ; server
209 (elmo-shimbun-folder-set-shimbun-internal
212 (shimbun-open (nth 0 server-group)
213 (luna-make-entity 'shimbun-elmo-mua :folder folder))
215 (luna-make-entity 'shimbun :server (nth 0 server-group))))))
216 (when (nth 1 server-group)
217 (elmo-shimbun-folder-set-group-internal
219 (nth 1 server-group)))
220 (elmo-shimbun-folder-set-range-internal
222 (or (cdr (elmo-string-matched-assoc (elmo-folder-name-internal folder)
223 elmo-shimbun-index-range-alist))
224 elmo-shimbun-default-index-range))
227 (luna-define-method elmo-folder-open-internal ((folder elmo-shimbun-folder))
228 (when (elmo-shimbun-folder-shimbun-internal folder)
230 (elmo-shimbun-folder-shimbun-internal folder)
231 (elmo-shimbun-folder-group-internal folder))
232 (let ((inhibit-quit t))
233 (unless (elmo-location-map-alist folder)
234 (elmo-location-map-setup
236 (elmo-msgdb-location-load (elmo-folder-msgdb-path folder))))
237 (when (and (elmo-folder-plugged-p folder)
238 (elmo-shimbun-headers-check-p folder))
239 (elmo-shimbun-get-headers folder)
240 (elmo-location-map-update
242 (elmo-map-folder-list-message-locations folder))))))
244 (luna-define-method elmo-folder-open-internal-p ((folder elmo-shimbun-folder))
245 (elmo-location-map-alist folder))
247 (luna-define-method elmo-folder-reserve-status-p ((folder elmo-shimbun-folder))
250 (luna-define-method elmo-folder-local-p ((folder elmo-shimbun-folder))
253 (luna-define-method elmo-message-use-cache-p ((folder elmo-shimbun-folder)
255 elmo-shimbun-use-cache)
257 (luna-define-method elmo-folder-close-internal :after ((folder
258 elmo-shimbun-folder))
260 (elmo-shimbun-folder-shimbun-internal folder))
261 (elmo-shimbun-folder-set-headers-internal
263 (elmo-shimbun-folder-set-header-hash-internal
265 (elmo-shimbun-folder-set-entity-hash-internal
267 (elmo-shimbun-folder-set-last-check-internal
270 (luna-define-method elmo-folder-plugged-p ((folder elmo-shimbun-folder))
271 (if (elmo-shimbun-folder-shimbun-internal folder)
274 (shimbun-server (elmo-shimbun-folder-shimbun-internal folder))
276 (shimbun-server (elmo-shimbun-folder-shimbun-internal folder)))
279 (luna-define-method elmo-folder-set-plugged ((folder elmo-shimbun-folder)
280 plugged &optional add)
281 (elmo-set-plugged plugged
284 (elmo-shimbun-folder-shimbun-internal folder))
287 (elmo-shimbun-folder-shimbun-internal folder))
290 (luna-define-method elmo-net-port-info ((folder elmo-shimbun-folder))
293 (elmo-shimbun-folder-shimbun-internal folder))
296 (luna-define-method elmo-folder-check :around ((folder elmo-shimbun-folder))
297 (when (shimbun-current-group
298 (elmo-shimbun-folder-shimbun-internal folder))
299 (when (and (elmo-folder-plugged-p folder)
300 (elmo-shimbun-headers-check-p folder))
301 (elmo-shimbun-get-headers folder)
302 (luna-call-next-method))))
304 (luna-define-method elmo-folder-clear :around ((folder elmo-shimbun-folder)
305 &optional keep-killed)
306 (elmo-shimbun-folder-set-headers-internal folder nil)
307 (elmo-shimbun-folder-set-header-hash-internal folder nil)
308 (elmo-shimbun-folder-set-entity-hash-internal folder nil)
309 (elmo-shimbun-folder-set-last-check-internal folder nil)
310 (luna-call-next-method))
312 (luna-define-method elmo-folder-expand-msgdb-path ((folder
313 elmo-shimbun-folder))
315 (concat (shimbun-server
316 (elmo-shimbun-folder-shimbun-internal folder))
318 (elmo-shimbun-folder-group-internal folder))
319 (expand-file-name "shimbun" elmo-msgdb-directory)))
321 (defun elmo-shimbun-msgdb-create-entity (folder number)
322 (let ((header (elmo-shimbun-folder-shimbun-header
324 (elmo-map-message-location folder number)))
328 (shimbun-header-insert
329 (elmo-shimbun-folder-shimbun-internal folder)
331 (setq ov (elmo-msgdb-create-message-entity-from-buffer
332 (elmo-msgdb-message-entity-handler
333 (elmo-folder-msgdb-internal folder)) number))
334 (elmo-message-entity-set-field
336 'xref (shimbun-header-xref header)))
339 (luna-define-method elmo-folder-msgdb-create ((folder elmo-shimbun-folder)
341 (let ((new-msgdb (elmo-make-msgdb))
343 (elmo-with-progress-display (elmo-folder-msgdb-create (length numlist))
345 (dolist (number numlist)
346 (setq entity (elmo-shimbun-msgdb-create-entity folder number))
348 (setq msgid (elmo-message-entity-field entity 'message-id)
349 flags (elmo-flag-table-get flag-table msgid))
350 (elmo-global-flags-set flags folder number msgid)
351 (elmo-msgdb-append-entity new-msgdb entity flags))
352 (elmo-progress-notify 'elmo-folder-msgdb-create)))
355 (luna-define-method elmo-folder-message-file-p ((folder elmo-shimbun-folder))
358 (defsubst elmo-shimbun-update-overview (folder entity shimbun-id header)
359 (let ((message-id (shimbun-header-id header))
361 (when (elmo-msgdb-update-entity
362 (elmo-folder-msgdb folder)
365 (unless (string= shimbun-id message-id)
366 (elmo-shimbun-header-set-extra-field
367 header "x-shimbun-id" shimbun-id)
368 (elmo-set-hash-val message-id
370 (elmo-shimbun-folder-entity-hash folder))
371 (elmo-set-hash-val shimbun-id
373 (elmo-shimbun-folder-entity-hash folder))
374 (list (cons 'x-original-id message-id)))
376 (cons 'from (shimbun-header-from header 'no-encode))
377 (cons 'subject (shimbun-header-subject header 'no-encode))
378 (cons 'date (shimbun-header-date header))
380 (elmo-msgdb-get-references-from-buffer)))))
381 (elmo-emit-signal 'update-overview folder
382 (elmo-message-entity-number entity)))))
384 (luna-define-method elmo-map-message-fetch ((folder elmo-shimbun-folder)
386 &optional section unseen)
387 (if (elmo-folder-plugged-p folder)
388 (let ((header (elmo-shimbun-folder-shimbun-header
392 (shimbun-article (elmo-shimbun-folder-shimbun-internal folder)
394 (when (or (eq elmo-shimbun-update-overview-folder-list 'all)
395 (elmo-string-match-member
396 (elmo-folder-name-internal folder)
397 elmo-shimbun-update-overview-folder-list))
398 (let ((entity (elmo-message-entity folder location)))
400 (elmo-shimbun-update-overview folder entity location header))))
401 (when (setq shimbun-id
402 (elmo-shimbun-header-extra-field header "x-shimbun-id"))
403 (goto-char (point-min))
404 (insert (format "X-Shimbun-Id: %s\n" shimbun-id)))
406 (error "Unplugged")))
408 (luna-define-method elmo-message-encache :around ((folder
410 number &optional read)
411 (if (elmo-folder-plugged-p folder)
412 (luna-call-next-method)
413 (if elmo-enable-disconnected-operation
414 (elmo-message-encache-dop folder number read)
415 (error "Unplugged"))))
417 (luna-define-method elmo-folder-list-messages-internal :around
418 ((folder elmo-shimbun-folder) &optional nohide)
419 (if (elmo-folder-plugged-p folder)
420 (luna-call-next-method)
423 (luna-define-method elmo-map-folder-list-message-locations
424 ((folder elmo-shimbun-folder))
425 (let ((expire-days (shimbun-article-expiration-days
426 (elmo-shimbun-folder-shimbun-internal folder))))
432 (when (and (elmo-message-entity-field ov 'xref)
434 (< (elmo-shimbun-lapse-seconds
435 (elmo-message-entity-field ov 'date))
436 (* expire-days 86400 ; seconds per day
439 (elmo-message-entity-field ov 'message-id)))
440 (elmo-folder-list-message-entities folder)))
443 (or (elmo-shimbun-header-extra-field header "x-shimbun-id")
444 (shimbun-header-id header)))
445 (elmo-shimbun-folder-headers-internal folder))))))
447 (luna-define-method elmo-folder-list-subfolders ((folder elmo-shimbun-folder)
449 (let ((prefix (elmo-folder-prefix-internal folder)))
450 (cond ((elmo-shimbun-folder-shimbun-internal folder)
451 (unless (elmo-shimbun-folder-group-internal folder)
456 (elmo-shimbun-folder-shimbun-internal folder))
458 (shimbun-groups (elmo-shimbun-folder-shimbun-internal folder)))))
459 ;; the rest are for "@/" group
462 (lambda (server) (list (concat prefix server)))
463 (shimbun-servers-list)))
466 (dolist (server (shimbun-servers-list))
470 (lambda (group) (concat prefix server "." group))
472 (elmo-shimbun-folder-shimbun-internal
473 (elmo-get-folder (concat prefix server))))))))
476 (luna-define-method elmo-folder-exists-p ((folder elmo-shimbun-folder))
477 (if (elmo-shimbun-folder-group-internal folder)
478 (if (fboundp 'shimbun-group-p)
479 (shimbun-group-p (elmo-shimbun-folder-shimbun-internal folder)
480 (elmo-shimbun-folder-group-internal folder))
482 (elmo-shimbun-folder-group-internal folder)
483 (shimbun-groups (elmo-shimbun-folder-shimbun-internal folder))))
486 (luna-define-method elmo-folder-delete-messages ((folder elmo-shimbun-folder)
488 (elmo-folder-kill-messages folder numbers)
491 (luna-define-method elmo-message-entity-parent ((folder elmo-shimbun-folder)
493 (let ((references (elmo-message-entity-field entity 'references)))
495 (elmo-get-hash-val references
496 (elmo-shimbun-folder-entity-hash folder)))))
499 (product-provide (provide 'elmo-shimbun) (require 'elmo-version))
501 ;;; elmo-shimbun.el ends here