1 ;;; elmo-archive.el -- Archive folder of ELMO.
3 ;; Copyright 1998,1999,2000 OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
4 ;; Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Author: OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
7 ;; Keywords: mail, net news
8 ;; Created: Sep 13, 1998
9 ;; Revised: Dec 15, 1998
11 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
13 ;; This program is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
32 ;; [
\e$B%\%=
\e(B] append-msgs()
\e$B$,M_$7$$!J$1$I
\e(B multi-refile
\e$BIT2D!K!#
\e(B
33 ;; Info-Zip
\e$B@lMQ%(!<%8%'%s%H$rMQ$$$?F|K\8l8!:w!J
\e(BOS/2
\e$B@lMQ!K!#
\e(B
41 (eval-when-compile (require 'elmo-localdir))
44 (defconst elmo-archive-version "v0.18 [990729/alpha]")
47 (defvar elmo-archive-lha-dos-compatible
48 (memq system-type '(OS/2 emx windows-nt))
49 "*If non-nil, regard your LHA as compatible to DOS version.")
51 (defvar elmo-archive-use-izip-agent (memq system-type '(OS/2 emx))
52 "*If non-nil, use the special agent in fetching headers.")
54 (defvar elmo-archive-folder-path "~/Mail"
55 "*Base directory for archive folders.")
57 (defvar elmo-archive-basename "elmo-archive"
58 "*Common basename of archive folder file, w/o suffix.")
60 (defvar elmo-archive-cmdstr-max-length 8000 ; SASAKI Osamu's suggestion
61 "*Command line string limitation under OS/2, exactly 8190 bytes.")
63 (defvar elmo-archive-fetch-headers-volume 50
64 "*Quantity of article headers to fetch per once.")
66 (defvar elmo-archive-dummy-file ".elmo-archive"
67 "*Name of dummy file that will be appended when the folder is null.")
69 (defvar elmo-archive-check-existance-strict t
70 "*Check existance of archive contents if non-nil.")
72 (defvar elmo-archive-load-hook nil
73 "*Hook called after loading elmo-archive.el.")
75 (defvar elmo-archive-treat-file nil
76 "*Treat archive folder as a file if non-nil.")
78 ;;; MMDF parser -- info-zip agent w/ REXX
79 (defvar elmo-mmdf-delimiter "^\01\01\01\01$"
80 "*Regular expression of MMDF delimiter.")
82 (defvar elmo-unixmail-delimiter "^From \\([^ \t]+\\) \\(.+\\)"
83 "*Regular expression of UNIX Mail delimiter.")
85 (defvar elmo-archive-header-regexp "^[ \t]*[-=][-=][-=][-=]"
86 "*Common regexp of the delimiter in listing archive.") ;; marche
88 (defvar elmo-archive-file-regexp-alist
90 (if elmo-archive-lha-dos-compatible
91 '((lha . "^%s\\([0-9]+\\)$")) ; OS/2,DOS w/ "-x"
92 '((lha . "^.*[ \t]%s\\([0-9]+\\)$")))
93 '((zip . "^.*[ \t]%s\\([0-9]+\\)$")
94 (zoo . "^.*[ \t]%s\\([0-9]+\\)$")
95 (tar . "^%s\\([0-9]+\\)$") ; ok
96 (tgz . "^%s\\([0-9]+\\)$") ; ok
97 (rar . "^[ \t]%s\\([0-9]+\\)$"))))
99 (defvar elmo-archive-suffix-alist
100 '((lha . ".lzh") ; default
111 (defvar elmo-archive-lha-method-alist
112 (if elmo-archive-lha-dos-compatible
114 '((cp . ("lha" "u" "-x"))
115 (mv . ("lha" "m" "-x"))
117 (ls . ("lha" "l" "-x"))
118 (cat . ("lha" "p" "-n"))
119 (ext . ("lha" "x")) ; "-x"
127 (ext . ("lha" "x")))))
130 (defvar elmo-archive-zip-method-alist
131 '((cp . ("zip" "-9q"))
132 (cp-pipe . ("zip" "-9q@"))
133 (mv . ("zip" "-mDq9"))
134 (mv-pipe . ("zip" "-mDq9@"))
136 (rm-pipe . ("zip" "-dq@"))
137 (ls . ("unzip" "-lq"))
138 (cat . ("unzip" "-pq"))
140 (cat-headers . ("izwlagent" "--cat"))))
143 (defvar elmo-archive-zoo-method-alist
144 '((cp . ("zoo" "aq"))
145 (cp-pipe . ("zoo" "aqI"))
147 (mv-pipe . ("zoo" "aMqI"))
149 (ls . ("zoo" "l")) ; normal
150 (cat . ("zoo" "xpq"))
151 (ext . ("zoo" "xq"))))
154 (defvar elmo-archive-rar-method-alist
155 '((cp . ("rar" "u" "-m5"))
156 (mv . ("rar" "m" "-m5"))
159 (cat . ("rar" "p" "-inul"))
160 (ext . ("rar" "x"))))
163 (defvar elmo-archive-tar-method-alist
164 (if elmo-archive-lha-dos-compatible
165 '((ls . ("gtar" "-tf"))
166 (cat . ("gtar" "--posix Oxf"))
167 (ext . ("gtar" "-xf"))
168 ;;(rm . ("gtar" "--posix" "--delete" "-f")) ;; well not work
170 '((ls . ("gtar" "-tf"))
171 (cat . ("gtar" "-Oxf"))
172 (ext . ("gtar" "-xf"))
173 ;;(rm . ("gtar" "--delete" "-f")) ;; well not work
176 ;;; GNU tar (*.tar.gz, *.tar.Z, *.tar.bz2)
177 (defvar elmo-archive-tgz-method-alist
178 '((ls . ("gtar" "-ztf"))
179 (cat . ("gtar" "-Ozxf"))
180 (create . ("gtar" "-zcf"))
181 ;;(rm . elmo-archive-tgz-rm-func)
182 (cp . elmo-archive-tgz-cp-func)
183 (mv . elmo-archive-tgz-mv-func)
184 (ext . ("gtar" "-zxf"))
185 ;; tgz special method
186 (decompress . ("gzip" "-d"))
187 (compress . ("gzip"))
188 (append . ("gtar" "-uf"))
189 ;;(delete . ("gtar" "--delete" "-f")) ;; well not work
192 (defvar elmo-archive-method-list
193 '(elmo-archive-lha-method-alist
194 elmo-archive-zip-method-alist
195 elmo-archive-zoo-method-alist
196 ; elmo-archive-tar-method-alist
197 elmo-archive-tgz-method-alist
198 ; elmo-archive-arc-method-alist
199 ; elmo-archive-arj-method-alist
200 elmo-archive-rar-method-alist))
203 (defvar elmo-archive-method-alist nil)
204 (defvar elmo-archive-suffixes nil)
208 (defmacro elmo-archive-get-method (type action)
209 (` (cdr (assq (, action) (cdr (assq (, type)
210 elmo-archive-method-alist))))))
212 (defmacro elmo-archive-get-suffix (type)
213 (` (cdr (assq (, type)
214 elmo-archive-suffix-alist))))
216 (defmacro elmo-archive-get-regexp (type)
217 (` (cdr (assq (, type)
218 elmo-archive-file-regexp-alist))))
220 (defsubst elmo-archive-call-process (prog args &optional output)
221 (= (apply 'call-process prog nil output nil args) 0))
223 (defsubst elmo-archive-call-method (method args &optional output)
226 (funcall method args output))
228 (elmo-archive-call-process
229 (car method) (append (cdr method) args) output))))
231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
234 (defsubst elmo-archive-list-folder-subr (spec &optional nonsort)
235 "*Returns list of number-file(int, not string) in archive FILE.
236 TYPE specifies the archiver's symbol."
237 (let* ((type (nth 2 spec))
238 (prefix (nth 3 spec))
239 (file (elmo-archive-get-archive-name (nth 1 spec) type spec))
240 (method (elmo-archive-get-method type 'ls))
242 (file-regexp (format (elmo-archive-get-regexp type)
243 (elmo-concat-path (regexp-quote prefix) "")))
244 (killed (and elmo-use-killed-list
245 (elmo-msgdb-killed-list-load
246 (elmo-msgdb-expand-path spec))))
247 numbers buf file-list header-end)
248 (when (file-exists-p file)
250 (set-buffer (setq buf (get-buffer-create " *ELMO ARCHIVE ls*")))
251 (unless (elmo-archive-call-method method args t)
252 (error "%s exited abnormally!" method))
253 (goto-char (point-min))
254 (when (re-search-forward elmo-archive-header-regexp nil t)
256 (setq header-end (point))
257 (when (re-search-forward elmo-archive-header-regexp nil t)
259 (narrow-to-region header-end (point))
260 (goto-char (point-min))))
261 (while (and (re-search-forward file-regexp nil t)
262 (not (eobp))) ; for GNU tar 981010
263 (setq file-list (nconc file-list (list (string-to-int
264 (match-string 1))))))
267 (cons (or (elmo-max-of-list file-list) 0)
269 (- (length file-list)
270 (elmo-msgdb-killed-list-length killed))
272 (setq numbers (sort file-list '<))
273 (elmo-living-messages numbers killed))))
275 (defun elmo-archive-list-folder (spec)
276 (elmo-archive-list-folder-subr spec))
278 (defun elmo-archive-max-of-folder (spec)
279 (elmo-archive-list-folder-subr spec t))
282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
283 ;;; Folder related functions
285 (defsubst elmo-archive-get-archive-directory (name)
286 ;; allow fullpath. return format is "/foo/bar/".
287 (if (file-name-absolute-p name)
288 (if (find-file-name-handler name 'copy-file)
290 (expand-file-name name))
291 (expand-file-name name elmo-archive-folder-path)))
293 (defun elmo-archive-get-archive-name (folder type &optional spec)
294 (let ((dir (elmo-archive-get-archive-directory folder))
295 (suffix (elmo-archive-get-suffix type))
297 (if elmo-archive-treat-file
298 (if (string-match (concat (regexp-quote suffix) "$") folder)
301 elmo-archive-folder-path)
303 (concat folder suffix)
304 elmo-archive-folder-path))
305 (if (and (let ((handler (find-file-name-handler dir 'copy-file))) ; dir is local.
307 (if (featurep 'xemacs)
308 (eq handler 'dired-handler-fn))))
309 (or (not (file-exists-p dir))
310 (file-directory-p dir)))
312 (concat elmo-archive-basename suffix)
314 ;; for full-path specification.
315 (if (and (find-file-name-handler dir 'copy-file) ; ange-ftp, efs
318 (setq filename (expand-file-name
319 (concat elmo-archive-basename suffix)
320 (setq dbdir (elmo-msgdb-expand-path spec))))
321 (if (file-directory-p dbdir)
323 (if (file-exists-p dbdir)
324 (error "File %s already exists" dbdir)
325 (elmo-make-directory dbdir)))
326 (if (not (file-exists-p filename))
328 (if (file-directory-p dir)
330 (concat elmo-archive-basename suffix)
337 (defun elmo-archive-folder-exists-p (spec)
339 (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec) spec)))
341 (defun elmo-archive-folder-creatable-p (spec)
344 (defun elmo-archive-create-folder (spec)
345 (let* ((dir (directory-file-name ;; remove tail slash.
346 (elmo-archive-get-archive-directory (nth 1 spec))))
348 (arc (elmo-archive-get-archive-name (nth 1 spec) type)))
349 (if elmo-archive-treat-file
350 (setq dir (directory-file-name (file-name-directory dir))))
351 (cond ((and (file-exists-p dir)
352 (not (file-directory-p dir)))
354 (error "Create folder failed; File \"%s\" exists" dir))
355 ((file-directory-p dir)
356 (if (file-exists-p arc)
358 (elmo-archive-create-file arc type spec)))
360 (elmo-make-directory dir)
361 (elmo-archive-create-file arc type spec)
364 (defun elmo-archive-create-file (archive type spec)
366 (let* ((tmp-dir (directory-file-name
367 (elmo-msgdb-expand-path spec)))
368 (dummy elmo-archive-dummy-file)
369 (method (or (elmo-archive-get-method type 'create)
370 (elmo-archive-get-method type 'mv)))
371 (args (list archive dummy)))
374 (error "WARNING: read-only mode: %s (method undefined)" type))
376 ((file-directory-p tmp-dir)
378 ((file-exists-p tmp-dir)
380 (error "Create directory failed; File \"%s\" exists" tmp-dir))
382 (elmo-make-directory tmp-dir)))
385 (write-region (point) (point) dummy nil 'no-msg)
387 (elmo-archive-call-method method args)
388 (if (file-exists-p dummy)
389 (delete-file dummy)))
392 (defun elmo-archive-delete-folder (spec)
393 (let* ((arc (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec))))
394 (if (not (file-exists-p arc))
395 (error "no such file: %s" arc)
399 (defun elmo-archive-rename-folder (old-spec new-spec)
400 (let* ((old-arc (elmo-archive-get-archive-name
401 (nth 1 old-spec) (nth 2 old-spec)))
402 (new-arc (elmo-archive-get-archive-name
403 (nth 1 new-spec) (nth 2 new-spec))))
404 (unless (and (eq (nth 2 old-spec) (nth 2 new-spec))
405 (equal (nth 3 old-spec) (nth 3 new-spec)))
406 (error "not same archive type and prefix"))
407 (if (not (file-exists-p old-arc))
408 (error "no such file: %s" old-arc)
409 (if (file-exists-p new-arc)
410 (error "already exists: %s" new-arc)
411 (rename-file old-arc new-arc)
414 (defun elmo-archive-list-folders (spec &optional hierarchy)
415 (let ((folder (concat "$" (nth 1 spec)))
416 (elmo-localdir-folder-path elmo-archive-folder-path))
417 (if elmo-archive-treat-file
418 (let* ((path (elmo-localdir-get-folder-directory spec))
419 (base-folder (or (nth 1 spec) ""))
420 (suffix (nth 2 spec))
421 (prefix (if (string= (nth 3 spec) "")
422 "" (concat ";" (nth 3 spec))))
423 (dir (if (file-directory-p path)
424 path (file-name-directory path)))
425 (name (if (file-directory-p path)
426 "" (file-name-nondirectory path)))
427 (flist (and (file-directory-p dir)
428 (directory-files dir nil name nil)))
429 (regexp (format "^\\(.*\\)\\(%s\\)$"
431 '(lambda (x) (regexp-quote (cdr x)))
432 elmo-archive-suffix-alist
434 (if (string-match "\\(.*\\)/$" base-folder) ; ends with '/'.
435 (setq base-folder (elmo-match-string 1 base-folder))
436 (unless (file-directory-p path)
437 (setq base-folder (or (file-name-directory base-folder)
443 (when (and (string-match regexp x)
446 (rassoc (elmo-match-string 2 x)
447 elmo-archive-suffix-alist))))
449 (elmo-concat-path base-folder (elmo-match-string 1 x))
452 (elmo-localdir-list-folders-subr folder hierarchy))))
455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
456 ;;; Article file related functions
457 ;;; read(extract) / append(move) / delete(delete) / query(list)
459 (defun elmo-archive-read-msg (spec number outbuf)
461 (let* ((type (nth 2 spec))
462 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
463 (prefix (nth 3 spec))
464 (method (elmo-archive-get-method type 'cat))
465 (args (list arc (elmo-concat-path
466 prefix (int-to-string number)))))
469 (when (file-exists-p arc)
472 (elmo-archive-call-method method args t))
473 (elmo-delete-cr-get-content-type))))))
475 (defun elmo-archive-append-msg (spec string &optional msg no-see) ;;; verrrrrry slow!!
476 (let* ((type (nth 2 spec))
477 (prefix (nth 3 spec))
478 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
479 (method (elmo-archive-get-method type 'mv))
480 (tmp-buffer (get-buffer-create " *ELMO ARCHIVE mv*"))
482 (1+ (if (file-exists-p arc)
483 (car (elmo-archive-max-of-folder spec)) 0))))
484 (tmp-dir (elmo-msgdb-expand-path spec))
488 (error "WARNING: read-only mode: %s (method undefined)" type))
490 (set-buffer tmp-buffer)
492 (let ((tmp-dir (expand-file-name prefix tmp-dir)))
493 (when (not (file-directory-p tmp-dir))
494 (elmo-make-directory (directory-file-name tmp-dir))))
495 (setq newfile (elmo-concat-path
497 (int-to-string next-num)))
501 (if (and (or (functionp method) (car method))
502 (file-writable-p newfile))
505 (as-binary-output-file
506 (write-region (point-min) (point-max) newfile nil 'no-msg))
507 (elmo-archive-call-method method (list arc newfile)))
509 (kill-buffer tmp-buffer)))))
511 ;;; (localdir, maildir, localnews, archive) -> archive
512 (defun elmo-archive-copy-msgs (dst-spec msgs src-spec
513 &optional loc-alist same-number)
514 (let* ((dst-type (nth 2 dst-spec))
515 (arc (elmo-archive-get-archive-name (nth 1 dst-spec) dst-type))
516 (prefix (nth 3 dst-spec))
517 (p-method (elmo-archive-get-method dst-type 'mv-pipe))
518 (n-method (elmo-archive-get-method dst-type 'mv))
519 (new (unless same-number
520 (1+ (car (elmo-archive-max-of-folder dst-spec)))))
521 (src-dir (elmo-localdir-get-folder-directory src-spec))
523 (file-name-as-directory (elmo-msgdb-expand-path dst-spec)))
525 src tmp newfile tmp-msgs)
526 (when (not (elmo-archive-folder-exists-p dst-spec))
527 (elmo-archive-create-folder dst-spec))
528 (when (null (or p-method n-method))
530 (error "WARNING: read-only mode: %s (method undefined)" dst-type))
531 (when (and same-number
532 (not (eq (car src-spec) 'maildir))
533 (string-match (concat prefix "$") src-dir)
535 (elmo-archive-get-method dst-type 'cp-pipe)
536 (elmo-archive-get-method dst-type 'cp)))
537 (setq tmp-dir (substring src-dir 0 (match-beginning 0)))
538 (setq p-method (elmo-archive-get-method dst-type 'cp-pipe)
539 n-method (elmo-archive-get-method dst-type 'cp))
540 (setq tmp-msgs (mapcar '(lambda (x)
541 (elmo-concat-path prefix (int-to-string x)))
545 (let ((tmp-dir (expand-file-name prefix tmp-dir)))
546 (when (not (file-directory-p tmp-dir))
547 (elmo-make-directory (directory-file-name tmp-dir))))
549 (setq newfile (elmo-concat-path prefix (int-to-string
553 (setq tmp-msgs (nconc tmp-msgs (list newfile)))
556 (elmo-call-func src-spec "get-msg-filename" (car msgs) loc-alist)
558 (expand-file-name newfile tmp-dir))
559 (setq msgs (cdr msgs))
560 (unless same-number (setq new (1+ new)))))
565 ((functionp n-method)
566 (funcall n-method (cons arc tmp-msgs)))
568 (let ((p-prog (car p-method))
569 (p-prog-arg (cdr p-method)))
570 (elmo-archive-exec-msgs-subr1
571 p-prog (append p-prog-arg (list arc)) tmp-msgs)))
573 (let ((n-prog (car n-method))
574 (n-prog-arg (cdr n-method)))
575 (elmo-archive-exec-msgs-subr2
576 n-prog (append n-prog-arg (list arc)) tmp-msgs (length arc)))))))))
578 ;;; archive -> (localdir, localnews, archive)
579 (defun elmo-archive-copy-msgs-froms (dst-spec msgs src-spec
580 &optional loc-alist same-number)
581 (let* ((src-type (nth 2 src-spec))
582 (arc (elmo-archive-get-archive-name (nth 1 src-spec) src-type))
583 (prefix (nth 3 src-spec))
584 (p-method (elmo-archive-get-method src-type 'ext-pipe))
585 (n-method (elmo-archive-get-method src-type 'ext))
587 (file-name-as-directory (elmo-msgdb-expand-path src-spec)))
588 (tmp-msgs (mapcar '(lambda (x) (elmo-concat-path
601 ((functionp n-method)
602 (funcall n-method (cons arc tmp-msgs)))
604 (let ((p-prog (car p-method))
605 (p-prog-arg (cdr p-method)))
606 (elmo-archive-exec-msgs-subr1
607 p-prog (append p-prog-arg (list arc)) tmp-msgs)))
609 (let ((n-prog (car n-method))
610 (n-prog-arg (cdr n-method)))
611 (elmo-archive-exec-msgs-subr2
612 n-prog (append n-prog-arg (list arc)) tmp-msgs (length arc)))))))
613 ;; call elmo-*-copy-msgs of destination folder
614 (elmo-call-func dst-spec "copy-msgs"
615 msgs src-spec loc-alist same-number)))
620 (if (file-exists-p (car tmp-msgs))
621 (delete-file (car tmp-msgs)))
622 (setq tmp-msgs (cdr tmp-msgs))))
625 (defun elmo-archive-delete-msgs (spec msgs)
627 (let* ((type (nth 2 spec))
628 (prefix (nth 3 spec))
629 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
630 (p-method (elmo-archive-get-method type 'rm-pipe))
631 (n-method (elmo-archive-get-method type 'rm))
632 (msgs (mapcar '(lambda (x) (elmo-concat-path
636 (cond ((functionp n-method)
637 (funcall n-method (cons arc msgs)))
639 (let ((p-prog (car p-method))
640 (p-prog-arg (cdr p-method)))
641 (elmo-archive-exec-msgs-subr1
642 p-prog (append p-prog-arg (list arc)) msgs)))
644 (let ((n-prog (car n-method))
645 (n-prog-arg (cdr n-method)))
646 (elmo-archive-exec-msgs-subr2
647 n-prog (append n-prog-arg (list arc)) msgs (length arc))))
650 (error "WARNING: not delete: %s (method undefined)" type))) )))
652 (defun elmo-archive-exec-msgs-subr1 (prog args msgs)
653 (let ((buf (get-buffer-create " *ELMO ARCHIVE exec*")))
655 (insert (mapconcat 'concat msgs "\n")) ;string
658 (apply 'call-process-region (point-min) (point-max)
659 prog nil nil nil args))
662 (defun elmo-archive-exec-msgs-subr2 (prog args msgs arc-length)
663 (let ((max-len (- elmo-archive-cmdstr-max-length arc-length))
666 (setq rest msgs) ;string
670 (while (and rest (<= i n))
672 (let* ((len (length x))
673 (files (member x (reverse rest))))
674 ;; total(previous) + current + white space
675 (if (<= max-len (+ sum len 1))
678 (elmo-archive-call-process
679 prog (append args files))
681 (setq sum 0) ;; reset
682 (setq rest (nthcdr i rest)))
683 (setq sum (+ sum len 1)))
684 (setq i (1+ i)))) msgs))
687 (elmo-archive-call-process prog (append args rest))))
690 (defsubst elmo-archive-article-exists-p (arc msg type)
691 (if (not elmo-archive-check-existance-strict)
693 (save-excursion ;; added 980915
694 (let* ((method (elmo-archive-get-method type 'ls))
695 (args (list arc msg))
696 (buf (get-buffer-create " *ELMO ARCHIVE query*"))
697 (error-msg "\\(no file\\|0 files\\)")
701 (elmo-archive-call-method method args t)
702 ;; pointer: point-max
703 (setq ret-val (not (re-search-backward error-msg nil t)))
707 (defun elmo-archive-tgz-common-func (args exec-type &optional copy)
708 (let* ((arc (car args))
709 (tmp-msgs (cdr args))
710 (decompress (elmo-archive-get-method 'tgz 'decompress))
711 (compress (elmo-archive-get-method 'tgz 'compress))
712 (exec (elmo-archive-get-method 'tgz exec-type))
713 (suffix (elmo-archive-get-suffix 'tgz))
714 (tar-suffix (elmo-archive-get-suffix 'tar))
717 (when (null (and decompress compress exec))
719 (error "WARNING: special method undefined: %s of %s"
720 (or (if (null decompress) 'decompress)
721 (if (null compress) 'compress)
722 (if (null exec) exec-type))
726 (error "WARNING: `tar' suffix undefined"))
727 (if (string-match (concat (regexp-quote suffix) "$") arc)
729 (concat (substring arc 0 (match-beginning 0)) tar-suffix))
730 (error "%s: not match suffix [%s]" arc suffix))
733 (elmo-archive-call-process
734 (car decompress) (append (cdr decompress) (list arc)))
735 ;; append (or delete)
736 (elmo-archive-exec-msgs-subr2
737 (car exec) (append (cdr exec) (list arc-tar)) tmp-msgs (length arc-tar))
740 (elmo-archive-call-process
741 (car compress) (append (cdr compress) (list arc-tar)))))
742 ;; delete tmporary messages
744 (eq exec-type 'append))
746 (if (file-exists-p (car tmp-msgs))
747 (delete-file (car tmp-msgs)))
748 (setq tmp-msgs (cdr tmp-msgs))))
751 (defun elmo-archive-tgz-cp-func (args &optional output)
752 (elmo-archive-tgz-common-func args 'append t))
754 (defun elmo-archive-tgz-mv-func (args &optional output)
755 (elmo-archive-tgz-common-func args 'append))
757 (defun elmo-archive-tgz-rm-func (args &optional output)
758 (elmo-archive-tgz-common-func args 'delete))
760 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
761 ;;; MessageDB functions (from elmo-localdir.el)
763 (defsubst elmo-archive-msgdb-create-entity-subr (number)
765 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
766 (goto-char (point-min))
767 (if (re-search-forward "\\(^--.*$\\)\\|\\(\n\n\\)" nil t)
768 (setq header-end (point))
769 (setq header-end (point-max)))
770 (narrow-to-region (point-min) header-end)
771 (elmo-msgdb-create-overview-from-buffer number)))
773 (defsubst elmo-archive-msgdb-create-entity (method archive number type &optional prefix) ;; verrrry slow!!
774 (let* ((msg (elmo-concat-path prefix (int-to-string number)))
775 (arg-list (list archive msg)))
776 (when (elmo-archive-article-exists-p archive msg type)
779 (elmo-archive-call-method method arg-list t))
780 (elmo-archive-msgdb-create-entity-subr number))))
782 (defun elmo-archive-msgdb-create-as-numlist (spec numlist new-mark
783 already-mark seen-mark
784 important-mark seen-list)
786 (save-excursion ;; 981005
787 (if (and elmo-archive-use-izip-agent
788 (elmo-archive-get-method (nth 2 spec) 'cat-headers))
789 (elmo-archive-msgdb-create-as-numlist-subr2
790 spec numlist new-mark already-mark seen-mark important-mark
792 (elmo-archive-msgdb-create-as-numlist-subr1
793 spec numlist new-mark already-mark seen-mark important-mark
796 (defalias 'elmo-archive-msgdb-create 'elmo-archive-msgdb-create-as-numlist)
799 (defun elmo-archive-msgdb-create-as-numlist-subr1 (spec numlist new-mark
800 already-mark seen-mark
803 (let* ((type (nth 2 spec))
804 (file (elmo-archive-get-archive-name (nth 1 spec) type spec))
805 (method (elmo-archive-get-method type 'cat))
806 (tmp-buf (get-buffer-create " *ELMO ARCHIVE msgdb*"))
807 overview number-alist mark-alist entity
808 i percent num message-id seen gmark)
811 (setq num (length numlist))
813 (message "Creating msgdb...")
817 (elmo-archive-msgdb-create-entity
818 method file (car numlist) type (nth 3 spec)))
821 (elmo-msgdb-append-element
824 (elmo-msgdb-number-add
826 (elmo-msgdb-overview-entity-get-number entity)
828 (setq message-id (car entity))
829 (setq seen (member message-id seen-list))
831 (or (elmo-msgdb-global-mark-get message-id)
832 (if (elmo-cache-exists-p message-id) ; XXX
840 (elmo-msgdb-mark-append
842 (elmo-msgdb-overview-entity-get-number entity)
844 (when (> num elmo-display-progress-threshold)
846 (setq percent (/ (* i 100) num))
847 (elmo-display-progress
848 'elmo-archive-msgdb-create-as-numlist-subr1 "Creating msgdb..."
850 (setq numlist (cdr numlist)))
851 (kill-buffer tmp-buf)
852 (message "Creating msgdb...done.")
853 (list overview number-alist mark-alist)) ))
856 (defun elmo-archive-msgdb-create-as-numlist-subr2 (spec numlist new-mark
857 already-mark seen-mark
860 (let* ((buf (get-buffer-create " *ELMO ARCHIVE headers*"))
861 (delim1 elmo-mmdf-delimiter) ;; MMDF
862 (delim2 elmo-unixmail-delimiter) ;; UNIX Mail
864 (prefix (nth 3 spec))
865 (method (elmo-archive-get-method type 'cat-headers))
868 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
869 n i percent num result overview number-alist mark-alist
870 msgs case-fold-search)
872 (setq num (length numlist))
874 (message "Creating msgdb...")
876 (setq n (min (1- elmo-archive-fetch-headers-volume)
877 (1- (length numlist))))
878 (setq msgs (reverse (memq (nth n numlist) (reverse numlist))))
879 (setq numlist (nthcdr (1+ n) numlist))
884 (mapcar '(lambda (x) (elmo-concat-path prefix (int-to-string x))) msgs)
886 (message "Fetching headers...")
887 (as-binary-process (apply 'call-process-region
888 (point-min) (point-max)
889 prog t t nil (append args (list arc))))
890 (goto-char (point-min))
892 ((looking-at delim1) ;; MMDF
893 (setq result (elmo-archive-parse-mmdf msgs
895 already-mark seen-mark
897 (setq overview (append overview (nth 0 result)))
898 (setq number-alist (append number-alist (nth 1 result)))
899 (setq mark-alist (append mark-alist (nth 2 result))))
900 ; ((looking-at delim2) ;; UNIX MAIL
901 ; (setq result (elmo-archive-parse-unixmail msgs))
902 ; (setq overview (append overview (nth 0 result)))
903 ; (setq number-alist (append number-alist (nth 1 result)))
904 ; (setq mark-alist (append mark-alist (nth 2 result))))
906 (error "unknown format!")))
907 (when (> num elmo-display-progress-threshold)
909 (setq percent (/ (* i 100) num))
910 (elmo-display-progress
911 'elmo-archive-msgdb-create-as-numlist-subr2 "Creating msgdb..."
914 (list overview number-alist mark-alist)) )
916 (defun elmo-archive-parse-mmdf (msgs new-mark
920 (let ((delim elmo-mmdf-delimiter)
921 number sp ep rest entity overview number-alist mark-alist ret-val
922 message-id seen gmark)
923 (goto-char (point-min))
925 (while (and rest (re-search-forward delim nil t)
927 (setq number (car rest))
928 (setq sp (1+ (point)))
929 (setq ep (prog2 (re-search-forward delim)
930 (1+ (- (point) (length delim)))))
931 (if (>= sp ep) ; no article!
934 (narrow-to-region sp ep)
935 (setq entity (elmo-archive-msgdb-create-entity-subr number))
937 (elmo-msgdb-append-element
940 (elmo-msgdb-number-add
942 (elmo-msgdb-overview-entity-get-number entity)
944 (setq message-id (car entity))
945 (setq seen (member message-id seen-list))
947 (or (elmo-msgdb-global-mark-get message-id)
948 (if (elmo-cache-exists-p message-id) ; XXX
956 (elmo-msgdb-mark-append
958 (elmo-msgdb-overview-entity-get-number entity)
960 (setq ret-val (append ret-val (list overview number-alist mark-alist)))
963 (setq rest (cdr rest)))
967 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
970 (defsubst elmo-archive-field-condition-match (spec number number-list
973 (let* ((type (nth 2 spec))
974 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
975 (method (elmo-archive-get-method type 'cat))
976 (args (list arc (elmo-concat-path prefix (int-to-string number)))))
978 (when (file-exists-p arc)
980 (elmo-archive-call-method method args t))
981 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
982 (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
983 (elmo-buffer-field-condition-match condition number number-list))))))
985 (defun elmo-archive-search (spec condition &optional from-msgs)
986 (let* (;;(args (elmo-string-to-list key))
987 ;; XXX: I don't know whether `elmo-archive-list-folder'
988 ;; updates match-data.
989 ;; (msgs (or from-msgs (elmo-archive-list-folder spec)))
990 (msgs (or from-msgs (elmo-archive-list-folder spec)))
993 (case-fold-search nil)
995 (setq number-list msgs)
997 (if (elmo-archive-field-condition-match spec (car msgs) number-list
1000 (setq ret-val (cons (car msgs) ret-val)))
1001 (when (> num elmo-display-progress-threshold)
1003 (elmo-display-progress
1004 'elmo-archive-search "Searching..."
1006 (setq msgs (cdr msgs)))
1007 (nreverse ret-val)))
1010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1013 (defun elmo-archive-check-validity (spec validity-file)
1016 (defun elmo-archive-sync-validity (spec validity-file)
1021 (if (null elmo-archive-method-alist)
1022 (let ((mlist elmo-archive-method-list) ; from mew-highlight.el
1025 (setq method (car mlist))
1026 (setq mlist (cdr mlist))
1027 (setq str (symbol-name method))
1028 (string-match "elmo-archive-\\([^-].*\\)-method-alist$" str)
1029 (setq type (intern-soft
1030 (elmo-match-string 1 str)))
1031 (setq elmo-archive-method-alist
1033 (symbol-value method))
1034 elmo-archive-method-alist)))))
1036 ;;; valid suffix(list)
1037 (if (null elmo-archive-suffixes)
1038 (let ((slist elmo-archive-suffix-alist)
1041 (setq tmp (car slist))
1042 (setq elmo-archive-suffixes
1043 (nconc elmo-archive-suffixes (list (cdr tmp))))
1044 (setq slist (cdr slist)))))
1046 (defun elmo-archive-use-cache-p (spec number)
1047 elmo-archive-use-cache)
1049 (defun elmo-archive-local-file-p (spec number)
1052 (defun elmo-archive-get-msg-filename (spec number &optional loc-alist)
1053 (let ((tmp-dir (file-name-as-directory (elmo-msgdb-expand-path spec)))
1054 (prefix (nth 3 spec)))
1056 (elmo-concat-path prefix (int-to-string number))
1059 (defalias 'elmo-archive-sync-number-alist
1060 'elmo-generic-sync-number-alist)
1061 (defalias 'elmo-archive-list-folder-unread
1062 'elmo-generic-list-folder-unread)
1063 (defalias 'elmo-archive-list-folder-important
1064 'elmo-generic-list-folder-important)
1065 (defalias 'elmo-archive-commit 'elmo-generic-commit)
1066 (defalias 'elmo-archive-folder-diff 'elmo-generic-folder-diff)
1069 (run-hooks 'elmo-archive-load-hook)
1072 (product-provide (provide 'elmo-archive) (require 'elmo-version))
1074 ;;; elmo-archive.el ends here