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 (file type prefix &optional nonsort)
235 "*Returns list of number-file(int, not string) in archive FILE.
236 TYPE specifies the archiver's symbol."
237 (let* ((method (elmo-archive-get-method type 'ls))
239 (file-regexp (format (elmo-archive-get-regexp type)
240 (elmo-concat-path (regexp-quote prefix) "")))
241 buf file-list header-end)
242 (when (file-exists-p file)
244 (set-buffer (setq buf (get-buffer-create " *ELMO ARCHIVE ls*")))
245 (unless (elmo-archive-call-method method args t)
246 (error "%s exited abnormally!" method))
247 (goto-char (point-min))
248 (when (re-search-forward elmo-archive-header-regexp nil t)
250 (setq header-end (point))
251 (when (re-search-forward elmo-archive-header-regexp nil t)
253 (narrow-to-region header-end (point))
254 (goto-char (point-min))))
255 (while (and (re-search-forward file-regexp nil t)
256 (not (eobp))) ; for GNU tar 981010
257 (setq file-list (nconc file-list (list (string-to-int
258 (match-string 1))))))
261 (cons (or (elmo-max-of-list file-list) 0) (length file-list))
262 (sort file-list '<))))
264 (defun elmo-archive-list-folder (spec)
265 (let* ((type (nth 2 spec))
266 (prefix (nth 3 spec))
267 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec)))
268 (elmo-archive-list-folder-subr arc type prefix)))
270 (defun elmo-archive-max-of-folder (spec)
271 (let* ((type (nth 2 spec))
272 (prefix (nth 3 spec))
273 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec)))
274 (elmo-archive-list-folder-subr arc type prefix t)))
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278 ;;; Folder related functions
280 (defsubst elmo-archive-get-archive-directory (name)
281 ;; allow fullpath. return format is "/foo/bar/".
282 (if (file-name-absolute-p name)
283 (if (find-file-name-handler name 'copy-file)
285 (expand-file-name name))
286 (expand-file-name name elmo-archive-folder-path)))
288 (defun elmo-archive-get-archive-name (folder type &optional spec)
289 (let ((dir (elmo-archive-get-archive-directory folder))
290 (suffix (elmo-archive-get-suffix type))
292 (if elmo-archive-treat-file
293 (if (string-match (concat (regexp-quote suffix) "$") folder)
296 elmo-archive-folder-path)
298 (concat folder suffix)
299 elmo-archive-folder-path))
300 (if (and (not (find-file-name-handler dir 'copy-file)) ; dir is local.
301 (or (not (file-exists-p dir))
302 (file-directory-p dir)))
304 (concat elmo-archive-basename suffix)
306 ;; for full-path specification.
307 (if (and (find-file-name-handler dir 'copy-file) ; ange-ftp, efs
310 (setq filename (expand-file-name
311 (concat elmo-archive-basename suffix)
312 (setq dbdir (elmo-msgdb-expand-path nil spec))))
313 (if (file-directory-p dbdir)
315 (if (file-exists-p dbdir)
316 (error "File %s already exists" dbdir)
317 (elmo-make-directory dbdir)))
318 (if (not (file-exists-p filename))
320 (if (file-directory-p dir)
322 (concat elmo-archive-basename suffix)
329 (defun elmo-archive-folder-exists-p (spec)
331 (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec) spec)))
333 (defun elmo-archive-folder-creatable-p (spec)
336 (defun elmo-archive-create-folder (spec)
337 (let* ((dir (directory-file-name ;; remove tail slash.
338 (elmo-archive-get-archive-directory (nth 1 spec))))
340 (arc (elmo-archive-get-archive-name (nth 1 spec) type)))
341 (if elmo-archive-treat-file
342 (setq dir (directory-file-name (file-name-directory dir))))
343 (cond ((and (file-exists-p dir)
344 (not (file-directory-p dir)))
346 (error "Create folder failed; File \"%s\" exists" dir))
347 ((file-directory-p dir)
348 (if (file-exists-p arc)
350 (elmo-archive-create-file arc type spec)))
352 (elmo-make-directory dir)
353 (elmo-archive-create-file arc type spec)
356 (defun elmo-archive-create-file (archive type spec)
358 (let* ((tmp-dir (directory-file-name
359 (elmo-msgdb-expand-path nil spec)))
360 (dummy elmo-archive-dummy-file)
361 (method (or (elmo-archive-get-method type 'create)
362 (elmo-archive-get-method type 'mv)))
363 (args (list archive dummy)))
366 (error "WARNING: read-only mode: %s (method undefined)" type))
368 ((file-directory-p tmp-dir)
370 ((file-exists-p tmp-dir)
372 (error "Create directory failed; File \"%s\" exists" tmp-dir))
374 (elmo-make-directory tmp-dir)))
377 (write-region (point) (point) dummy nil 'no-msg)
379 (elmo-archive-call-method method args)
380 (if (file-exists-p dummy)
381 (delete-file dummy)))
384 (defun elmo-archive-delete-folder (spec)
385 (let* ((arc (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec))))
386 (if (not (file-exists-p arc))
387 (error "no such file: %s" arc)
391 (defun elmo-archive-rename-folder (old-spec new-spec)
392 (let* ((old-arc (elmo-archive-get-archive-name
393 (nth 1 old-spec) (nth 2 old-spec)))
394 (new-arc (elmo-archive-get-archive-name
395 (nth 1 new-spec) (nth 2 new-spec))))
396 (unless (and (eq (nth 2 old-spec) (nth 2 new-spec))
397 (equal (nth 3 old-spec) (nth 3 new-spec)))
398 (error "not same archive type and prefix"))
399 (if (not (file-exists-p old-arc))
400 (error "no such file: %s" old-arc)
401 (if (file-exists-p new-arc)
402 (error "already exists: %s" new-arc)
403 (rename-file old-arc new-arc)
406 (defun elmo-archive-list-folders (spec &optional hierarchy)
407 (let ((folder (concat "$" (nth 1 spec)))
408 (elmo-localdir-folder-path elmo-archive-folder-path))
409 (if elmo-archive-treat-file
410 (let* ((path (elmo-localdir-get-folder-directory spec))
411 (base-folder (or (file-name-directory (nth 1 spec)) ""))
412 (suffix (nth 2 spec))
413 (prefix (if (string= (nth 3 spec) "")
414 "" (concat ";" (nth 3 spec))))
415 (dir (if (file-directory-p path)
416 path (file-name-directory path)))
417 (name (if (file-directory-p path)
418 "" (file-name-nondirectory path)))
419 (flist (and (file-directory-p dir)
420 (directory-files dir nil name nil)))
421 (regexp (format "^\\(.*\\)\\(%s\\)$"
423 '(lambda (x) (regexp-quote (cdr x)))
424 elmo-archive-suffix-alist
430 (when (and (string-match regexp x)
433 (rassoc (elmo-match-string 2 x)
434 elmo-archive-suffix-alist))))
436 (elmo-concat-path base-folder (elmo-match-string 1 x))
440 (elmo-localdir-list-folders-subr folder hierarchy))))
443 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
444 ;;; Article file related functions
445 ;;; read(extract) / append(move) / delete(delete) / query(list)
447 (defun elmo-archive-read-msg (spec number outbuf)
449 (let* ((type (nth 2 spec))
450 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
451 (prefix (nth 3 spec))
452 (method (elmo-archive-get-method type 'cat))
453 (args (list arc (elmo-concat-path
454 prefix (int-to-string number)))))
457 (when (file-exists-p arc)
460 (elmo-archive-call-method method args t))
461 (elmo-delete-cr-get-content-type))))))
463 (defun elmo-archive-append-msg (spec string &optional msg no-see) ;;; verrrrrry slow!!
464 (let* ((type (nth 2 spec))
465 (prefix (nth 3 spec))
466 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
467 (method (elmo-archive-get-method type 'mv))
468 (tmp-buffer (get-buffer-create " *ELMO ARCHIVE mv*"))
470 (1+ (if (file-exists-p arc)
471 (car (elmo-archive-max-of-folder spec)) 0))))
472 (tmp-dir (elmo-msgdb-expand-path nil spec))
476 (error "WARNING: read-only mode: %s (method undefined)" type))
478 (set-buffer tmp-buffer)
480 (let ((tmp-dir (expand-file-name prefix tmp-dir)))
481 (when (not (file-directory-p tmp-dir))
482 (elmo-make-directory (directory-file-name tmp-dir))))
483 (setq newfile (elmo-concat-path
485 (int-to-string next-num)))
489 (if (and (or (functionp method) (car method))
490 (file-writable-p newfile))
493 (as-binary-output-file
494 (write-region (point-min) (point-max) newfile nil 'no-msg))
495 (elmo-archive-call-method method (list arc newfile)))
497 (kill-buffer tmp-buffer)))))
499 ;;; (localdir, maildir, localnews, archive) -> archive
500 (defun elmo-archive-copy-msgs (dst-spec msgs src-spec
501 &optional loc-alist same-number)
502 (let* ((dst-type (nth 2 dst-spec))
503 (arc (elmo-archive-get-archive-name (nth 1 dst-spec) dst-type))
504 (prefix (nth 3 dst-spec))
505 (p-method (elmo-archive-get-method dst-type 'mv-pipe))
506 (n-method (elmo-archive-get-method dst-type 'mv))
507 (new (unless same-number
508 (1+ (car (elmo-archive-max-of-folder dst-spec)))))
509 (src-dir (elmo-localdir-get-folder-directory src-spec))
511 (file-name-as-directory (elmo-msgdb-expand-path nil dst-spec)))
513 src tmp newfile tmp-msgs)
514 (when (not (elmo-archive-folder-exists-p dst-spec))
515 (elmo-archive-create-folder dst-spec))
516 (when (null (or p-method n-method))
518 (error "WARNING: read-only mode: %s (method undefined)" dst-type))
519 (when (and same-number
520 (not (eq (car src-spec) 'maildir))
521 (string-match (concat prefix "$") src-dir)
523 (elmo-archive-get-method dst-type 'cp-pipe)
524 (elmo-archive-get-method dst-type 'cp)))
525 (setq tmp-dir (substring src-dir 0 (match-beginning 0)))
526 (setq p-method (elmo-archive-get-method dst-type 'cp-pipe)
527 n-method (elmo-archive-get-method dst-type 'cp))
528 (setq tmp-msgs (mapcar '(lambda (x)
529 (elmo-concat-path prefix (int-to-string x)))
533 (let ((tmp-dir (expand-file-name prefix tmp-dir)))
534 (when (not (file-directory-p tmp-dir))
535 (elmo-make-directory (directory-file-name tmp-dir))))
537 (setq newfile (elmo-concat-path prefix (int-to-string
541 (setq tmp-msgs (nconc tmp-msgs (list newfile)))
544 (elmo-call-func src-spec "get-msg-filename" (car msgs) loc-alist)
546 (expand-file-name newfile tmp-dir))
547 (setq msgs (cdr msgs))
548 (unless same-number (setq new (1+ new)))))
553 ((functionp n-method)
554 (funcall n-method (cons arc tmp-msgs)))
556 (let ((p-prog (car p-method))
557 (p-prog-arg (cdr p-method)))
558 (elmo-archive-exec-msgs-subr1
559 p-prog (append p-prog-arg (list arc)) tmp-msgs)))
561 (let ((n-prog (car n-method))
562 (n-prog-arg (cdr n-method)))
563 (elmo-archive-exec-msgs-subr2
564 n-prog (append n-prog-arg (list arc)) tmp-msgs (length arc)))))))))
566 ;;; archive -> (localdir, localnews, archive)
567 (defun elmo-archive-copy-msgs-froms (dst-spec msgs src-spec
568 &optional loc-alist same-number)
569 (let* ((src-type (nth 2 src-spec))
570 (arc (elmo-archive-get-archive-name (nth 1 src-spec) src-type))
571 (prefix (nth 3 src-spec))
572 (p-method (elmo-archive-get-method src-type 'ext-pipe))
573 (n-method (elmo-archive-get-method src-type 'ext))
575 (file-name-as-directory (elmo-msgdb-expand-path nil src-spec)))
576 (tmp-msgs (mapcar '(lambda (x) (elmo-concat-path
589 ((functionp n-method)
590 (funcall n-method (cons arc tmp-msgs)))
592 (let ((p-prog (car p-method))
593 (p-prog-arg (cdr p-method)))
594 (elmo-archive-exec-msgs-subr1
595 p-prog (append p-prog-arg (list arc)) tmp-msgs)))
597 (let ((n-prog (car n-method))
598 (n-prog-arg (cdr n-method)))
599 (elmo-archive-exec-msgs-subr2
600 n-prog (append n-prog-arg (list arc)) tmp-msgs (length arc)))))))
601 ;; call elmo-*-copy-msgs of destination folder
602 (elmo-call-func dst-spec "copy-msgs"
603 msgs src-spec loc-alist same-number)))
608 (if (file-exists-p (car tmp-msgs))
609 (delete-file (car tmp-msgs)))
610 (setq tmp-msgs (cdr tmp-msgs))))
613 (defun elmo-archive-delete-msgs (spec msgs)
615 (let* ((type (nth 2 spec))
616 (prefix (nth 3 spec))
617 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
618 (p-method (elmo-archive-get-method type 'rm-pipe))
619 (n-method (elmo-archive-get-method type 'rm))
620 (msgs (mapcar '(lambda (x) (elmo-concat-path
624 (cond ((functionp n-method)
625 (funcall n-method (cons arc msgs)))
627 (let ((p-prog (car p-method))
628 (p-prog-arg (cdr p-method)))
629 (elmo-archive-exec-msgs-subr1
630 p-prog (append p-prog-arg (list arc)) msgs)))
632 (let ((n-prog (car n-method))
633 (n-prog-arg (cdr n-method)))
634 (elmo-archive-exec-msgs-subr2
635 n-prog (append n-prog-arg (list arc)) msgs (length arc))))
638 (error "WARNING: not delete: %s (method undefined)" type))) )))
640 (defun elmo-archive-exec-msgs-subr1 (prog args msgs)
641 (let ((buf (get-buffer-create " *ELMO ARCHIVE exec*")))
643 (insert (mapconcat 'concat msgs "\n")) ;string
646 (apply 'call-process-region (point-min) (point-max)
647 prog nil nil nil args))
650 (defun elmo-archive-exec-msgs-subr2 (prog args msgs arc-length)
651 (let ((max-len (- elmo-archive-cmdstr-max-length arc-length))
654 (setq rest msgs) ;string
658 (while (and rest (<= i n))
660 (let* ((len (length x))
661 (files (member x (reverse rest))))
662 ;; total(previous) + current + white space
663 (if (<= max-len (+ sum len 1))
666 (elmo-archive-call-process
667 prog (append args files))
669 (setq sum 0) ;; reset
670 (setq rest (nthcdr i rest)))
671 (setq sum (+ sum len 1)))
672 (setq i (1+ i)))) msgs))
675 (elmo-archive-call-process prog (append args rest))))
678 (defsubst elmo-archive-article-exists-p (arc msg type)
679 (if (not elmo-archive-check-existance-strict)
681 (save-excursion ;; added 980915
682 (let* ((method (elmo-archive-get-method type 'ls))
683 (args (list arc msg))
684 (buf (get-buffer-create " *ELMO ARCHIVE query*"))
685 (error-msg "\\(no file\\|0 files\\)")
689 (elmo-archive-call-method method args t)
690 ;; pointer: point-max
691 (setq ret-val (not (re-search-backward error-msg nil t)))
695 (defun elmo-archive-tgz-common-func (args exec-type &optional copy)
696 (let* ((arc (car args))
697 (tmp-msgs (cdr args))
698 (decompress (elmo-archive-get-method 'tgz 'decompress))
699 (compress (elmo-archive-get-method 'tgz 'compress))
700 (exec (elmo-archive-get-method 'tgz exec-type))
701 (suffix (elmo-archive-get-suffix 'tgz))
702 (tar-suffix (elmo-archive-get-suffix 'tar))
705 (when (null (and decompress compress exec))
707 (error "WARNING: special method undefined: %s of %s"
708 (or (if (null decompress) 'decompress)
709 (if (null compress) 'compress)
710 (if (null exec) exec-type))
714 (error "WARNING: `tar' suffix undefined"))
715 (if (string-match (concat (regexp-quote suffix) "$") arc)
717 (concat (substring arc 0 (match-beginning 0)) tar-suffix))
718 (error "%s: not match suffix [%s]" arc suffix))
721 (elmo-archive-call-process
722 (car decompress) (append (cdr decompress) (list arc)))
723 ;; append (or delete)
724 (elmo-archive-exec-msgs-subr2
725 (car exec) (append (cdr exec) (list arc-tar)) tmp-msgs (length arc-tar))
728 (elmo-archive-call-process
729 (car compress) (append (cdr compress) (list arc-tar)))))
730 ;; delete tmporary messages
732 (eq exec-type 'append))
734 (if (file-exists-p (car tmp-msgs))
735 (delete-file (car tmp-msgs)))
736 (setq tmp-msgs (cdr tmp-msgs))))
739 (defun elmo-archive-tgz-cp-func (args &optional output)
740 (elmo-archive-tgz-common-func args 'append t))
742 (defun elmo-archive-tgz-mv-func (args &optional output)
743 (elmo-archive-tgz-common-func args 'append))
745 (defun elmo-archive-tgz-rm-func (args &optional output)
746 (elmo-archive-tgz-common-func args 'delete))
748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
749 ;;; MessageDB functions (from elmo-localdir.el)
751 (defsubst elmo-archive-msgdb-create-entity-subr (number)
753 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
754 (goto-char (point-min))
755 (if (re-search-forward "\\(^--.*$\\)\\|\\(\n\n\\)" nil t)
756 (setq header-end (point))
757 (setq header-end (point-max)))
758 (narrow-to-region (point-min) header-end)
759 (elmo-msgdb-create-overview-from-buffer number)))
761 (defsubst elmo-archive-msgdb-create-entity (method archive number type &optional prefix) ;; verrrry slow!!
762 (let* ((msg (elmo-concat-path prefix (int-to-string number)))
763 (arg-list (list archive msg)))
764 (when (elmo-archive-article-exists-p archive msg type)
767 (elmo-archive-call-method method arg-list t))
768 (elmo-archive-msgdb-create-entity-subr number))))
770 (defun elmo-archive-msgdb-create-as-numlist (spec numlist new-mark
771 already-mark seen-mark
772 important-mark seen-list)
774 (save-excursion ;; 981005
775 (if (and elmo-archive-use-izip-agent
776 (elmo-archive-get-method (nth 2 spec) 'cat-headers))
777 (elmo-archive-msgdb-create-as-numlist-subr2
778 spec numlist new-mark already-mark seen-mark important-mark
780 (elmo-archive-msgdb-create-as-numlist-subr1
781 spec numlist new-mark already-mark seen-mark important-mark
784 (defalias 'elmo-archive-msgdb-create 'elmo-archive-msgdb-create-as-numlist)
787 (defun elmo-archive-msgdb-create-as-numlist-subr1 (spec numlist new-mark
788 already-mark seen-mark
791 (let* ((type (nth 2 spec))
792 (file (elmo-archive-get-archive-name (nth 1 spec) type spec))
793 (method (elmo-archive-get-method type 'cat))
794 (tmp-buf (get-buffer-create " *ELMO ARCHIVE msgdb*"))
795 overview number-alist mark-alist entity
796 i percent num message-id seen gmark)
799 (setq num (length numlist))
801 (message "Creating msgdb...")
805 (elmo-archive-msgdb-create-entity
806 method file (car numlist) type (nth 3 spec)))
809 (elmo-msgdb-append-element
812 (elmo-msgdb-number-add
814 (elmo-msgdb-overview-entity-get-number entity)
816 (setq message-id (car entity))
817 (setq seen (member message-id seen-list))
819 (or (elmo-msgdb-global-mark-get message-id)
820 (if (elmo-cache-exists-p message-id) ; XXX
828 (elmo-msgdb-mark-append
830 (elmo-msgdb-overview-entity-get-number entity)
833 (setq percent (/ (* i 100) num))
834 (elmo-display-progress
835 'elmo-archive-msgdb-create-as-numlist-subr1 "Creating msgdb..."
837 (setq numlist (cdr numlist)))
838 (kill-buffer tmp-buf)
839 (message "Creating msgdb...done.")
840 (list overview number-alist mark-alist)) ))
843 (defun elmo-archive-msgdb-create-as-numlist-subr2 (spec numlist new-mark
844 already-mark seen-mark
847 (let* ((buf (get-buffer-create " *ELMO ARCHIVE headers*"))
848 (delim1 elmo-mmdf-delimiter) ;; MMDF
849 (delim2 elmo-unixmail-delimiter) ;; UNIX Mail
851 (prefix (nth 3 spec))
852 (method (elmo-archive-get-method type 'cat-headers))
855 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
856 n i percent num result overview number-alist mark-alist
857 msgs case-fold-search)
859 (setq num (length numlist))
861 (message "Creating msgdb...")
863 (setq n (min (1- elmo-archive-fetch-headers-volume)
864 (1- (length numlist))))
865 (setq msgs (reverse (memq (nth n numlist) (reverse numlist))))
866 (setq numlist (nthcdr (1+ n) numlist))
871 (mapcar '(lambda (x) (elmo-concat-path prefix (int-to-string x))) msgs)
873 (message "Fetching headers...")
874 (as-binary-process (apply 'call-process-region
875 (point-min) (point-max)
876 prog t t nil (append args (list arc))))
877 (goto-char (point-min))
879 ((looking-at delim1) ;; MMDF
880 (setq result (elmo-archive-parse-mmdf msgs
882 already-mark seen-mark
884 (setq overview (append overview (nth 0 result)))
885 (setq number-alist (append number-alist (nth 1 result)))
886 (setq mark-alist (append mark-alist (nth 2 result))))
887 ; ((looking-at delim2) ;; UNIX MAIL
888 ; (setq result (elmo-archive-parse-unixmail msgs))
889 ; (setq overview (append overview (nth 0 result)))
890 ; (setq number-alist (append number-alist (nth 1 result)))
891 ; (setq mark-alist (append mark-alist (nth 2 result))))
893 (error "unknown format!")))
895 (setq percent (/ (* i 100) num))
896 (elmo-display-progress
897 'elmo-archive-msgdb-create-as-numlist-subr2 "Creating msgdb..."
900 (list overview number-alist mark-alist)) )
902 (defun elmo-archive-parse-mmdf (msgs new-mark
906 (let ((delim elmo-mmdf-delimiter)
907 number sp ep rest entity overview number-alist mark-alist ret-val
908 message-id seen gmark)
909 (goto-char (point-min))
911 (while (and rest (re-search-forward delim nil t)
913 (setq number (car rest))
914 (setq sp (1+ (point)))
915 (setq ep (prog2 (re-search-forward delim)
916 (1+ (- (point) (length delim)))))
917 (if (>= sp ep) ; no article!
920 (narrow-to-region sp ep)
921 (setq entity (elmo-archive-msgdb-create-entity-subr number))
923 (elmo-msgdb-append-element
926 (elmo-msgdb-number-add
928 (elmo-msgdb-overview-entity-get-number entity)
930 (setq message-id (car entity))
931 (setq seen (member message-id seen-list))
933 (or (elmo-msgdb-global-mark-get message-id)
934 (if (elmo-cache-exists-p message-id) ; XXX
942 (elmo-msgdb-mark-append
944 (elmo-msgdb-overview-entity-get-number entity)
946 (setq ret-val (append ret-val (list overview number-alist mark-alist)))
949 (setq rest (cdr rest)))
953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
956 (defsubst elmo-archive-field-condition-match (spec number condition prefix)
958 (let* ((type (nth 2 spec))
959 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
960 (method (elmo-archive-get-method type 'cat))
961 (args (list arc (elmo-concat-path prefix (int-to-string number)))))
963 (when (file-exists-p arc)
965 (elmo-archive-call-method method args t))
966 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
967 (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
968 (elmo-buffer-field-condition-match condition))))))
970 (defun elmo-archive-search (spec condition &optional from-msgs)
971 (let* (;;(args (elmo-string-to-list key))
972 ;; XXX: I don't know whether `elmo-archive-list-folder'
973 ;; updates match-data.
974 ;; (msgs (or from-msgs (elmo-archive-list-folder spec)))
975 (msgs (or from-msgs (elmo-archive-list-folder spec)))
978 (case-fold-search nil)
981 (if (elmo-archive-field-condition-match spec (car msgs)
984 (setq ret-val (cons (car msgs) ret-val)))
986 (elmo-display-progress
987 'elmo-archive-search "Searching..."
989 (setq msgs (cdr msgs)))
993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
996 (defun elmo-archive-check-validity (spec validity-file)
999 (defun elmo-archive-sync-validity (spec validity-file)
1004 (if (null elmo-archive-method-alist)
1005 (let ((mlist elmo-archive-method-list) ; from mew-highlight.el
1008 (setq method (car mlist))
1009 (setq mlist (cdr mlist))
1010 (setq str (symbol-name method))
1011 (string-match "elmo-archive-\\([^-].*\\)-method-alist$" str)
1012 (setq type (intern-soft
1013 (elmo-match-string 1 str)))
1014 (setq elmo-archive-method-alist
1016 (symbol-value method))
1017 elmo-archive-method-alist)))))
1019 ;;; valid suffix(list)
1020 (if (null elmo-archive-suffixes)
1021 (let ((slist elmo-archive-suffix-alist)
1024 (setq tmp (car slist))
1025 (setq elmo-archive-suffixes
1026 (nconc elmo-archive-suffixes (list (cdr tmp))))
1027 (setq slist (cdr slist)))))
1029 (defun elmo-archive-use-cache-p (spec number)
1030 elmo-archive-use-cache)
1032 (defun elmo-archive-local-file-p (spec number)
1035 (defun elmo-archive-get-msg-filename (spec number &optional loc-alist)
1036 (let ((tmp-dir (file-name-as-directory (elmo-msgdb-expand-path nil spec)))
1037 (prefix (nth 3 spec)))
1039 (elmo-concat-path prefix (int-to-string number))
1042 (defalias 'elmo-archive-sync-number-alist
1043 'elmo-generic-sync-number-alist)
1044 (defalias 'elmo-archive-list-folder-unread
1045 'elmo-generic-list-folder-unread)
1046 (defalias 'elmo-archive-list-folder-important
1047 'elmo-generic-list-folder-important)
1048 (defalias 'elmo-archive-commit 'elmo-generic-commit)
1051 (run-hooks 'elmo-archive-load-hook)
1052 (provide 'elmo-archive)
1054 ;;; elmo-archive.el ends here