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 (killed (and elmo-use-killed-list
269 (elmo-msgdb-killed-list-load
270 (elmo-msgdb-expand-path nil spec))))
272 (setq numbers (elmo-archive-list-folder-subr arc type prefix))
275 (mapcar (lambda (number)
276 (unless (memq number killed) number))
280 (defun elmo-archive-max-of-folder (spec)
281 (let* ((type (nth 2 spec))
282 (prefix (nth 3 spec))
283 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec)))
284 (elmo-archive-list-folder-subr arc type prefix t)))
287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
288 ;;; Folder related functions
290 (defsubst elmo-archive-get-archive-directory (name)
291 ;; allow fullpath. return format is "/foo/bar/".
292 (if (file-name-absolute-p name)
293 (if (find-file-name-handler name 'copy-file)
295 (expand-file-name name))
296 (expand-file-name name elmo-archive-folder-path)))
298 (defun elmo-archive-get-archive-name (folder type &optional spec)
299 (let ((dir (elmo-archive-get-archive-directory folder))
300 (suffix (elmo-archive-get-suffix type))
302 (if elmo-archive-treat-file
303 (if (string-match (concat (regexp-quote suffix) "$") folder)
306 elmo-archive-folder-path)
308 (concat folder suffix)
309 elmo-archive-folder-path))
310 (if (and (let ((handler (find-file-name-handler dir 'copy-file))) ; dir is local.
312 (if (featurep 'xemacs)
313 (eq handler 'dired-handler-fn))))
314 (or (not (file-exists-p dir))
315 (file-directory-p dir)))
317 (concat elmo-archive-basename suffix)
319 ;; for full-path specification.
320 (if (and (find-file-name-handler dir 'copy-file) ; ange-ftp, efs
323 (setq filename (expand-file-name
324 (concat elmo-archive-basename suffix)
325 (setq dbdir (elmo-msgdb-expand-path nil spec))))
326 (if (file-directory-p dbdir)
328 (if (file-exists-p dbdir)
329 (error "File %s already exists" dbdir)
330 (elmo-make-directory dbdir)))
331 (if (not (file-exists-p filename))
333 (if (file-directory-p dir)
335 (concat elmo-archive-basename suffix)
342 (defun elmo-archive-folder-exists-p (spec)
344 (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec) spec)))
346 (defun elmo-archive-folder-creatable-p (spec)
349 (defun elmo-archive-create-folder (spec)
350 (let* ((dir (directory-file-name ;; remove tail slash.
351 (elmo-archive-get-archive-directory (nth 1 spec))))
353 (arc (elmo-archive-get-archive-name (nth 1 spec) type)))
354 (if elmo-archive-treat-file
355 (setq dir (directory-file-name (file-name-directory dir))))
356 (cond ((and (file-exists-p dir)
357 (not (file-directory-p dir)))
359 (error "Create folder failed; File \"%s\" exists" dir))
360 ((file-directory-p dir)
361 (if (file-exists-p arc)
363 (elmo-archive-create-file arc type spec)))
365 (elmo-make-directory dir)
366 (elmo-archive-create-file arc type spec)
369 (defun elmo-archive-create-file (archive type spec)
371 (let* ((tmp-dir (directory-file-name
372 (elmo-msgdb-expand-path nil spec)))
373 (dummy elmo-archive-dummy-file)
374 (method (or (elmo-archive-get-method type 'create)
375 (elmo-archive-get-method type 'mv)))
376 (args (list archive dummy)))
379 (error "WARNING: read-only mode: %s (method undefined)" type))
381 ((file-directory-p tmp-dir)
383 ((file-exists-p tmp-dir)
385 (error "Create directory failed; File \"%s\" exists" tmp-dir))
387 (elmo-make-directory tmp-dir)))
390 (write-region (point) (point) dummy nil 'no-msg)
392 (elmo-archive-call-method method args)
393 (if (file-exists-p dummy)
394 (delete-file dummy)))
397 (defun elmo-archive-delete-folder (spec)
398 (let* ((arc (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec))))
399 (if (not (file-exists-p arc))
400 (error "no such file: %s" arc)
404 (defun elmo-archive-rename-folder (old-spec new-spec)
405 (let* ((old-arc (elmo-archive-get-archive-name
406 (nth 1 old-spec) (nth 2 old-spec)))
407 (new-arc (elmo-archive-get-archive-name
408 (nth 1 new-spec) (nth 2 new-spec))))
409 (unless (and (eq (nth 2 old-spec) (nth 2 new-spec))
410 (equal (nth 3 old-spec) (nth 3 new-spec)))
411 (error "not same archive type and prefix"))
412 (if (not (file-exists-p old-arc))
413 (error "no such file: %s" old-arc)
414 (if (file-exists-p new-arc)
415 (error "already exists: %s" new-arc)
416 (rename-file old-arc new-arc)
419 (defun elmo-archive-list-folders (spec &optional hierarchy)
420 (let ((folder (concat "$" (nth 1 spec)))
421 (elmo-localdir-folder-path elmo-archive-folder-path))
422 (if elmo-archive-treat-file
423 (let* ((path (elmo-localdir-get-folder-directory spec))
424 (base-folder (or (nth 1 spec) ""))
425 (suffix (nth 2 spec))
426 (prefix (if (string= (nth 3 spec) "")
427 "" (concat ";" (nth 3 spec))))
428 (dir (if (file-directory-p path)
429 path (file-name-directory path)))
430 (name (if (file-directory-p path)
431 "" (file-name-nondirectory path)))
432 (flist (and (file-directory-p dir)
433 (directory-files dir nil name nil)))
434 (regexp (format "^\\(.*\\)\\(%s\\)$"
436 '(lambda (x) (regexp-quote (cdr x)))
437 elmo-archive-suffix-alist
439 (if (string-match "\\(.*\\)/$" base-folder) ; ends with '/'.
440 (setq base-folder (elmo-match-string 1 base-folder))
441 (unless (file-directory-p path)
442 (setq base-folder (or (file-name-directory base-folder)
448 (when (and (string-match regexp x)
451 (rassoc (elmo-match-string 2 x)
452 elmo-archive-suffix-alist))))
454 (elmo-concat-path base-folder (elmo-match-string 1 x))
457 (elmo-localdir-list-folders-subr folder hierarchy))))
460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
461 ;;; Article file related functions
462 ;;; read(extract) / append(move) / delete(delete) / query(list)
464 (defun elmo-archive-read-msg (spec number outbuf)
466 (let* ((type (nth 2 spec))
467 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
468 (prefix (nth 3 spec))
469 (method (elmo-archive-get-method type 'cat))
470 (args (list arc (elmo-concat-path
471 prefix (int-to-string number)))))
474 (when (file-exists-p arc)
477 (elmo-archive-call-method method args t))
478 (elmo-delete-cr-get-content-type))))))
480 (defun elmo-archive-append-msg (spec string &optional msg no-see) ;;; verrrrrry slow!!
481 (let* ((type (nth 2 spec))
482 (prefix (nth 3 spec))
483 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
484 (method (elmo-archive-get-method type 'mv))
485 (tmp-buffer (get-buffer-create " *ELMO ARCHIVE mv*"))
487 (1+ (if (file-exists-p arc)
488 (car (elmo-archive-max-of-folder spec)) 0))))
489 (tmp-dir (elmo-msgdb-expand-path nil spec))
493 (error "WARNING: read-only mode: %s (method undefined)" type))
495 (set-buffer tmp-buffer)
497 (let ((tmp-dir (expand-file-name prefix tmp-dir)))
498 (when (not (file-directory-p tmp-dir))
499 (elmo-make-directory (directory-file-name tmp-dir))))
500 (setq newfile (elmo-concat-path
502 (int-to-string next-num)))
506 (if (and (or (functionp method) (car method))
507 (file-writable-p newfile))
510 (as-binary-output-file
511 (write-region (point-min) (point-max) newfile nil 'no-msg))
512 (elmo-archive-call-method method (list arc newfile)))
514 (kill-buffer tmp-buffer)))))
516 ;;; (localdir, maildir, localnews, archive) -> archive
517 (defun elmo-archive-copy-msgs (dst-spec msgs src-spec
518 &optional loc-alist same-number)
519 (let* ((dst-type (nth 2 dst-spec))
520 (arc (elmo-archive-get-archive-name (nth 1 dst-spec) dst-type))
521 (prefix (nth 3 dst-spec))
522 (p-method (elmo-archive-get-method dst-type 'mv-pipe))
523 (n-method (elmo-archive-get-method dst-type 'mv))
524 (new (unless same-number
525 (1+ (car (elmo-archive-max-of-folder dst-spec)))))
526 (src-dir (elmo-localdir-get-folder-directory src-spec))
528 (file-name-as-directory (elmo-msgdb-expand-path nil dst-spec)))
530 src tmp newfile tmp-msgs)
531 (when (not (elmo-archive-folder-exists-p dst-spec))
532 (elmo-archive-create-folder dst-spec))
533 (when (null (or p-method n-method))
535 (error "WARNING: read-only mode: %s (method undefined)" dst-type))
536 (when (and same-number
537 (not (eq (car src-spec) 'maildir))
538 (string-match (concat prefix "$") src-dir)
540 (elmo-archive-get-method dst-type 'cp-pipe)
541 (elmo-archive-get-method dst-type 'cp)))
542 (setq tmp-dir (substring src-dir 0 (match-beginning 0)))
543 (setq p-method (elmo-archive-get-method dst-type 'cp-pipe)
544 n-method (elmo-archive-get-method dst-type 'cp))
545 (setq tmp-msgs (mapcar '(lambda (x)
546 (elmo-concat-path prefix (int-to-string x)))
550 (let ((tmp-dir (expand-file-name prefix tmp-dir)))
551 (when (not (file-directory-p tmp-dir))
552 (elmo-make-directory (directory-file-name tmp-dir))))
554 (setq newfile (elmo-concat-path prefix (int-to-string
558 (setq tmp-msgs (nconc tmp-msgs (list newfile)))
561 (elmo-call-func src-spec "get-msg-filename" (car msgs) loc-alist)
563 (expand-file-name newfile tmp-dir))
564 (setq msgs (cdr msgs))
565 (unless same-number (setq new (1+ new)))))
570 ((functionp n-method)
571 (funcall n-method (cons arc tmp-msgs)))
573 (let ((p-prog (car p-method))
574 (p-prog-arg (cdr p-method)))
575 (elmo-archive-exec-msgs-subr1
576 p-prog (append p-prog-arg (list arc)) tmp-msgs)))
578 (let ((n-prog (car n-method))
579 (n-prog-arg (cdr n-method)))
580 (elmo-archive-exec-msgs-subr2
581 n-prog (append n-prog-arg (list arc)) tmp-msgs (length arc)))))))))
583 ;;; archive -> (localdir, localnews, archive)
584 (defun elmo-archive-copy-msgs-froms (dst-spec msgs src-spec
585 &optional loc-alist same-number)
586 (let* ((src-type (nth 2 src-spec))
587 (arc (elmo-archive-get-archive-name (nth 1 src-spec) src-type))
588 (prefix (nth 3 src-spec))
589 (p-method (elmo-archive-get-method src-type 'ext-pipe))
590 (n-method (elmo-archive-get-method src-type 'ext))
592 (file-name-as-directory (elmo-msgdb-expand-path nil src-spec)))
593 (tmp-msgs (mapcar '(lambda (x) (elmo-concat-path
606 ((functionp n-method)
607 (funcall n-method (cons arc tmp-msgs)))
609 (let ((p-prog (car p-method))
610 (p-prog-arg (cdr p-method)))
611 (elmo-archive-exec-msgs-subr1
612 p-prog (append p-prog-arg (list arc)) tmp-msgs)))
614 (let ((n-prog (car n-method))
615 (n-prog-arg (cdr n-method)))
616 (elmo-archive-exec-msgs-subr2
617 n-prog (append n-prog-arg (list arc)) tmp-msgs (length arc)))))))
618 ;; call elmo-*-copy-msgs of destination folder
619 (elmo-call-func dst-spec "copy-msgs"
620 msgs src-spec loc-alist same-number)))
625 (if (file-exists-p (car tmp-msgs))
626 (delete-file (car tmp-msgs)))
627 (setq tmp-msgs (cdr tmp-msgs))))
630 (defun elmo-archive-delete-msgs (spec msgs)
632 (let* ((type (nth 2 spec))
633 (prefix (nth 3 spec))
634 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
635 (p-method (elmo-archive-get-method type 'rm-pipe))
636 (n-method (elmo-archive-get-method type 'rm))
637 (msgs (mapcar '(lambda (x) (elmo-concat-path
641 (cond ((functionp n-method)
642 (funcall n-method (cons arc msgs)))
644 (let ((p-prog (car p-method))
645 (p-prog-arg (cdr p-method)))
646 (elmo-archive-exec-msgs-subr1
647 p-prog (append p-prog-arg (list arc)) msgs)))
649 (let ((n-prog (car n-method))
650 (n-prog-arg (cdr n-method)))
651 (elmo-archive-exec-msgs-subr2
652 n-prog (append n-prog-arg (list arc)) msgs (length arc))))
655 (error "WARNING: not delete: %s (method undefined)" type))) )))
657 (defun elmo-archive-exec-msgs-subr1 (prog args msgs)
658 (let ((buf (get-buffer-create " *ELMO ARCHIVE exec*")))
660 (insert (mapconcat 'concat msgs "\n")) ;string
663 (apply 'call-process-region (point-min) (point-max)
664 prog nil nil nil args))
667 (defun elmo-archive-exec-msgs-subr2 (prog args msgs arc-length)
668 (let ((max-len (- elmo-archive-cmdstr-max-length arc-length))
671 (setq rest msgs) ;string
675 (while (and rest (<= i n))
677 (let* ((len (length x))
678 (files (member x (reverse rest))))
679 ;; total(previous) + current + white space
680 (if (<= max-len (+ sum len 1))
683 (elmo-archive-call-process
684 prog (append args files))
686 (setq sum 0) ;; reset
687 (setq rest (nthcdr i rest)))
688 (setq sum (+ sum len 1)))
689 (setq i (1+ i)))) msgs))
692 (elmo-archive-call-process prog (append args rest))))
695 (defsubst elmo-archive-article-exists-p (arc msg type)
696 (if (not elmo-archive-check-existance-strict)
698 (save-excursion ;; added 980915
699 (let* ((method (elmo-archive-get-method type 'ls))
700 (args (list arc msg))
701 (buf (get-buffer-create " *ELMO ARCHIVE query*"))
702 (error-msg "\\(no file\\|0 files\\)")
706 (elmo-archive-call-method method args t)
707 ;; pointer: point-max
708 (setq ret-val (not (re-search-backward error-msg nil t)))
712 (defun elmo-archive-tgz-common-func (args exec-type &optional copy)
713 (let* ((arc (car args))
714 (tmp-msgs (cdr args))
715 (decompress (elmo-archive-get-method 'tgz 'decompress))
716 (compress (elmo-archive-get-method 'tgz 'compress))
717 (exec (elmo-archive-get-method 'tgz exec-type))
718 (suffix (elmo-archive-get-suffix 'tgz))
719 (tar-suffix (elmo-archive-get-suffix 'tar))
722 (when (null (and decompress compress exec))
724 (error "WARNING: special method undefined: %s of %s"
725 (or (if (null decompress) 'decompress)
726 (if (null compress) 'compress)
727 (if (null exec) exec-type))
731 (error "WARNING: `tar' suffix undefined"))
732 (if (string-match (concat (regexp-quote suffix) "$") arc)
734 (concat (substring arc 0 (match-beginning 0)) tar-suffix))
735 (error "%s: not match suffix [%s]" arc suffix))
738 (elmo-archive-call-process
739 (car decompress) (append (cdr decompress) (list arc)))
740 ;; append (or delete)
741 (elmo-archive-exec-msgs-subr2
742 (car exec) (append (cdr exec) (list arc-tar)) tmp-msgs (length arc-tar))
745 (elmo-archive-call-process
746 (car compress) (append (cdr compress) (list arc-tar)))))
747 ;; delete tmporary messages
749 (eq exec-type 'append))
751 (if (file-exists-p (car tmp-msgs))
752 (delete-file (car tmp-msgs)))
753 (setq tmp-msgs (cdr tmp-msgs))))
756 (defun elmo-archive-tgz-cp-func (args &optional output)
757 (elmo-archive-tgz-common-func args 'append t))
759 (defun elmo-archive-tgz-mv-func (args &optional output)
760 (elmo-archive-tgz-common-func args 'append))
762 (defun elmo-archive-tgz-rm-func (args &optional output)
763 (elmo-archive-tgz-common-func args 'delete))
765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
766 ;;; MessageDB functions (from elmo-localdir.el)
768 (defsubst elmo-archive-msgdb-create-entity-subr (number)
770 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
771 (goto-char (point-min))
772 (if (re-search-forward "\\(^--.*$\\)\\|\\(\n\n\\)" nil t)
773 (setq header-end (point))
774 (setq header-end (point-max)))
775 (narrow-to-region (point-min) header-end)
776 (elmo-msgdb-create-overview-from-buffer number)))
778 (defsubst elmo-archive-msgdb-create-entity (method archive number type &optional prefix) ;; verrrry slow!!
779 (let* ((msg (elmo-concat-path prefix (int-to-string number)))
780 (arg-list (list archive msg)))
781 (when (elmo-archive-article-exists-p archive msg type)
784 (elmo-archive-call-method method arg-list t))
785 (elmo-archive-msgdb-create-entity-subr number))))
787 (defun elmo-archive-msgdb-create-as-numlist (spec numlist new-mark
788 already-mark seen-mark
789 important-mark seen-list)
791 (save-excursion ;; 981005
792 (if (and elmo-archive-use-izip-agent
793 (elmo-archive-get-method (nth 2 spec) 'cat-headers))
794 (elmo-archive-msgdb-create-as-numlist-subr2
795 spec numlist new-mark already-mark seen-mark important-mark
797 (elmo-archive-msgdb-create-as-numlist-subr1
798 spec numlist new-mark already-mark seen-mark important-mark
801 (defalias 'elmo-archive-msgdb-create 'elmo-archive-msgdb-create-as-numlist)
804 (defun elmo-archive-msgdb-create-as-numlist-subr1 (spec numlist new-mark
805 already-mark seen-mark
808 (let* ((type (nth 2 spec))
809 (file (elmo-archive-get-archive-name (nth 1 spec) type spec))
810 (method (elmo-archive-get-method type 'cat))
811 (tmp-buf (get-buffer-create " *ELMO ARCHIVE msgdb*"))
812 overview number-alist mark-alist entity
813 i percent num message-id seen gmark)
816 (setq num (length numlist))
818 (message "Creating msgdb...")
822 (elmo-archive-msgdb-create-entity
823 method file (car numlist) type (nth 3 spec)))
826 (elmo-msgdb-append-element
829 (elmo-msgdb-number-add
831 (elmo-msgdb-overview-entity-get-number entity)
833 (setq message-id (car entity))
834 (setq seen (member message-id seen-list))
836 (or (elmo-msgdb-global-mark-get message-id)
837 (if (elmo-cache-exists-p message-id) ; XXX
845 (elmo-msgdb-mark-append
847 (elmo-msgdb-overview-entity-get-number entity)
849 (when (> num elmo-display-progress-threshold)
851 (setq percent (/ (* i 100) num))
852 (elmo-display-progress
853 'elmo-archive-msgdb-create-as-numlist-subr1 "Creating msgdb..."
855 (setq numlist (cdr numlist)))
856 (kill-buffer tmp-buf)
857 (message "Creating msgdb...done.")
858 (list overview number-alist mark-alist)) ))
861 (defun elmo-archive-msgdb-create-as-numlist-subr2 (spec numlist new-mark
862 already-mark seen-mark
865 (let* ((buf (get-buffer-create " *ELMO ARCHIVE headers*"))
866 (delim1 elmo-mmdf-delimiter) ;; MMDF
867 (delim2 elmo-unixmail-delimiter) ;; UNIX Mail
869 (prefix (nth 3 spec))
870 (method (elmo-archive-get-method type 'cat-headers))
873 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
874 n i percent num result overview number-alist mark-alist
875 msgs case-fold-search)
877 (setq num (length numlist))
879 (message "Creating msgdb...")
881 (setq n (min (1- elmo-archive-fetch-headers-volume)
882 (1- (length numlist))))
883 (setq msgs (reverse (memq (nth n numlist) (reverse numlist))))
884 (setq numlist (nthcdr (1+ n) numlist))
889 (mapcar '(lambda (x) (elmo-concat-path prefix (int-to-string x))) msgs)
891 (message "Fetching headers...")
892 (as-binary-process (apply 'call-process-region
893 (point-min) (point-max)
894 prog t t nil (append args (list arc))))
895 (goto-char (point-min))
897 ((looking-at delim1) ;; MMDF
898 (setq result (elmo-archive-parse-mmdf msgs
900 already-mark seen-mark
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))))
905 ; ((looking-at delim2) ;; UNIX MAIL
906 ; (setq result (elmo-archive-parse-unixmail msgs))
907 ; (setq overview (append overview (nth 0 result)))
908 ; (setq number-alist (append number-alist (nth 1 result)))
909 ; (setq mark-alist (append mark-alist (nth 2 result))))
911 (error "unknown format!")))
912 (when (> num elmo-display-progress-threshold)
914 (setq percent (/ (* i 100) num))
915 (elmo-display-progress
916 'elmo-archive-msgdb-create-as-numlist-subr2 "Creating msgdb..."
919 (list overview number-alist mark-alist)) )
921 (defun elmo-archive-parse-mmdf (msgs new-mark
925 (let ((delim elmo-mmdf-delimiter)
926 number sp ep rest entity overview number-alist mark-alist ret-val
927 message-id seen gmark)
928 (goto-char (point-min))
930 (while (and rest (re-search-forward delim nil t)
932 (setq number (car rest))
933 (setq sp (1+ (point)))
934 (setq ep (prog2 (re-search-forward delim)
935 (1+ (- (point) (length delim)))))
936 (if (>= sp ep) ; no article!
939 (narrow-to-region sp ep)
940 (setq entity (elmo-archive-msgdb-create-entity-subr number))
942 (elmo-msgdb-append-element
945 (elmo-msgdb-number-add
947 (elmo-msgdb-overview-entity-get-number entity)
949 (setq message-id (car entity))
950 (setq seen (member message-id seen-list))
952 (or (elmo-msgdb-global-mark-get message-id)
953 (if (elmo-cache-exists-p message-id) ; XXX
961 (elmo-msgdb-mark-append
963 (elmo-msgdb-overview-entity-get-number entity)
965 (setq ret-val (append ret-val (list overview number-alist mark-alist)))
968 (setq rest (cdr rest)))
972 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
975 (defsubst elmo-archive-field-condition-match (spec number condition prefix)
977 (let* ((type (nth 2 spec))
978 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
979 (method (elmo-archive-get-method type 'cat))
980 (args (list arc (elmo-concat-path prefix (int-to-string number)))))
982 (when (file-exists-p arc)
984 (elmo-archive-call-method method args t))
985 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
986 (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
987 (elmo-buffer-field-condition-match condition))))))
989 (defun elmo-archive-search (spec condition &optional from-msgs)
990 (let* (;;(args (elmo-string-to-list key))
991 ;; XXX: I don't know whether `elmo-archive-list-folder'
992 ;; updates match-data.
993 ;; (msgs (or from-msgs (elmo-archive-list-folder spec)))
994 (msgs (or from-msgs (elmo-archive-list-folder spec)))
997 (case-fold-search nil)
1000 (if (elmo-archive-field-condition-match spec (car msgs)
1003 (setq ret-val (cons (car msgs) ret-val)))
1004 (when (> num elmo-display-progress-threshold)
1006 (elmo-display-progress
1007 'elmo-archive-search "Searching..."
1009 (setq msgs (cdr msgs)))
1010 (nreverse ret-val)))
1013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1016 (defun elmo-archive-check-validity (spec validity-file)
1019 (defun elmo-archive-sync-validity (spec validity-file)
1024 (if (null elmo-archive-method-alist)
1025 (let ((mlist elmo-archive-method-list) ; from mew-highlight.el
1028 (setq method (car mlist))
1029 (setq mlist (cdr mlist))
1030 (setq str (symbol-name method))
1031 (string-match "elmo-archive-\\([^-].*\\)-method-alist$" str)
1032 (setq type (intern-soft
1033 (elmo-match-string 1 str)))
1034 (setq elmo-archive-method-alist
1036 (symbol-value method))
1037 elmo-archive-method-alist)))))
1039 ;;; valid suffix(list)
1040 (if (null elmo-archive-suffixes)
1041 (let ((slist elmo-archive-suffix-alist)
1044 (setq tmp (car slist))
1045 (setq elmo-archive-suffixes
1046 (nconc elmo-archive-suffixes (list (cdr tmp))))
1047 (setq slist (cdr slist)))))
1049 (defun elmo-archive-use-cache-p (spec number)
1050 elmo-archive-use-cache)
1052 (defun elmo-archive-local-file-p (spec number)
1055 (defun elmo-archive-get-msg-filename (spec number &optional loc-alist)
1056 (let ((tmp-dir (file-name-as-directory (elmo-msgdb-expand-path nil spec)))
1057 (prefix (nth 3 spec)))
1059 (elmo-concat-path prefix (int-to-string number))
1062 (defalias 'elmo-archive-sync-number-alist
1063 'elmo-generic-sync-number-alist)
1064 (defalias 'elmo-archive-list-folder-unread
1065 'elmo-generic-list-folder-unread)
1066 (defalias 'elmo-archive-list-folder-important
1067 'elmo-generic-list-folder-important)
1068 (defalias 'elmo-archive-commit 'elmo-generic-commit)
1071 (run-hooks 'elmo-archive-load-hook)
1072 (provide 'elmo-archive)
1074 ;;; elmo-archive.el ends here