1 ;;; elmo-archive.el -- Archive folder of ELMO.
3 ;; Copyright (C) 1998,1999,2000 OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
4 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Author: OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
7 ;; Yuuichi Teranishi <teranisi@gohome.org>
8 ;; Keywords: mail, net news
9 ;; Created: Sep 13, 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 ;; [¥Ü¥½] append-msgs() ¤¬Íߤ·¤¤¡Ê¤±¤É multi-refile ÉԲġˡ£
33 ;; Info-Zip ÀìÍÑ¥¨¡¼¥¸¥§¥ó¥È¤òÍѤ¤¤¿ÆüËܸ측º÷¡ÊOS/2 ÀìÍÑ¡Ë¡£
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 (static-if (boundp 'NEMACS)
221 (defsubst elmo-archive-call-process (prog args &optional output)
222 (apply 'call-process prog nil output nil args)
224 (defsubst elmo-archive-call-process (prog args &optional output)
225 (= (apply 'call-process prog nil output nil args) 0)))
227 (defsubst elmo-archive-call-method (method args &optional output)
230 (funcall method args output))
232 (elmo-archive-call-process
233 (car method) (append (cdr method) args) output))))
235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
238 (defsubst elmo-archive-list-folder-subr (spec &optional nonsort)
239 "*Returns list of number-file(int, not string) in archive FILE.
240 TYPE specifies the archiver's symbol."
241 (let* ((type (nth 2 spec))
242 (prefix (nth 3 spec))
243 (file (elmo-archive-get-archive-name (nth 1 spec) type spec))
244 (method (elmo-archive-get-method type 'ls))
246 (file-regexp (format (elmo-archive-get-regexp type)
247 (elmo-concat-path (regexp-quote prefix) "")))
248 (killed (and elmo-use-killed-list
249 (elmo-msgdb-killed-list-load
250 (elmo-msgdb-expand-path spec))))
251 numbers buf file-list header-end)
252 (when (file-exists-p file)
254 (set-buffer (setq buf (get-buffer-create " *ELMO ARCHIVE ls*")))
255 (unless (elmo-archive-call-method method args t)
256 (error "%s exited abnormally!" method))
257 (goto-char (point-min))
258 (when (re-search-forward elmo-archive-header-regexp nil t)
260 (setq header-end (point))
261 (when (re-search-forward elmo-archive-header-regexp nil t)
263 (narrow-to-region header-end (point))
264 (goto-char (point-min))))
265 (while (and (re-search-forward file-regexp nil t)
266 (not (eobp))) ; for GNU tar 981010
267 (setq file-list (nconc file-list (list (string-to-int
268 (match-string 1))))))
271 (cons (or (elmo-max-of-list file-list) 0)
273 (- (length file-list)
274 (elmo-msgdb-killed-list-length killed))
276 (setq numbers (sort file-list '<))
277 (elmo-living-messages numbers killed))))
279 (defun elmo-archive-list-folder (spec)
280 (elmo-archive-list-folder-subr spec))
282 (defun elmo-archive-max-of-folder (spec)
283 (elmo-archive-list-folder-subr spec t))
286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
287 ;;; Folder related functions
289 (defsubst elmo-archive-get-archive-directory (name)
290 ;; allow fullpath. return format is "/foo/bar/".
291 (if (file-name-absolute-p name)
292 (if (find-file-name-handler name 'copy-file)
294 (expand-file-name name))
295 (expand-file-name name elmo-archive-folder-path)))
297 (defun elmo-archive-get-archive-name (folder type &optional spec)
298 (let ((dir (elmo-archive-get-archive-directory folder))
299 (suffix (elmo-archive-get-suffix type))
301 (if elmo-archive-treat-file
302 (if (string-match (concat (regexp-quote suffix) "$") folder)
305 elmo-archive-folder-path)
307 (concat folder suffix)
308 elmo-archive-folder-path))
309 (if (and (let ((handler (find-file-name-handler dir 'copy-file))) ; dir is local.
311 (if (featurep 'xemacs)
312 (eq handler 'dired-handler-fn))))
313 (or (not (file-exists-p dir))
314 (file-directory-p dir)))
316 (concat elmo-archive-basename suffix)
318 ;; for full-path specification.
319 (if (and (find-file-name-handler dir 'copy-file) ; ange-ftp, efs
322 (setq filename (expand-file-name
323 (concat elmo-archive-basename suffix)
324 (setq dbdir (elmo-msgdb-expand-path spec))))
325 (if (file-directory-p dbdir)
327 (if (file-exists-p dbdir)
328 (error "File %s already exists" dbdir)
329 (elmo-make-directory dbdir)))
330 (if (not (file-exists-p filename))
332 (if (file-directory-p dir)
334 (concat elmo-archive-basename suffix)
341 (defun elmo-archive-folder-exists-p (spec)
343 (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec) spec)))
345 (defun elmo-archive-folder-creatable-p (spec)
348 (defun elmo-archive-create-folder (spec)
349 (let* ((dir (directory-file-name ; remove tail slash.
350 (elmo-archive-get-archive-directory (nth 1 spec))))
352 (arc (elmo-archive-get-archive-name (nth 1 spec) type)))
353 (if elmo-archive-treat-file
354 (setq dir (directory-file-name (file-name-directory dir))))
355 (cond ((and (file-exists-p dir)
356 (not (file-directory-p dir)))
358 (error "Create folder failed; File \"%s\" exists" dir))
359 ((file-directory-p dir)
360 (if (file-exists-p arc)
362 (elmo-archive-create-file arc type spec)))
364 (elmo-make-directory dir)
365 (elmo-archive-create-file arc type spec)
368 (defun elmo-archive-create-file (archive type spec)
370 (let* ((tmp-dir (directory-file-name
371 (elmo-msgdb-expand-path spec)))
372 (dummy elmo-archive-dummy-file)
373 (method (or (elmo-archive-get-method type 'create)
374 (elmo-archive-get-method type 'mv)))
375 (args (list archive dummy)))
378 (error "WARNING: read-only mode: %s (method undefined)" type))
380 ((file-directory-p tmp-dir)
382 ((file-exists-p tmp-dir)
384 (error "Create directory failed; File \"%s\" exists" tmp-dir))
386 (elmo-make-directory tmp-dir)))
389 (write-region (point) (point) dummy nil 'no-msg)
391 (elmo-archive-call-method method args)
392 (if (file-exists-p dummy)
393 (delete-file dummy)))
396 (defun elmo-archive-delete-folder (spec)
397 (let* ((arc (elmo-archive-get-archive-name (nth 1 spec) (nth 2 spec))))
398 (if (not (file-exists-p arc))
399 (error "No such file: %s" arc)
403 (defun elmo-archive-rename-folder (old-spec new-spec)
404 (let* ((old-arc (elmo-archive-get-archive-name
405 (nth 1 old-spec) (nth 2 old-spec)))
406 (new-arc (elmo-archive-get-archive-name
407 (nth 1 new-spec) (nth 2 new-spec))))
408 (unless (and (eq (nth 2 old-spec) (nth 2 new-spec))
409 (equal (nth 3 old-spec) (nth 3 new-spec)))
410 (error "Not same archive type and prefix"))
411 (if (not (file-exists-p old-arc))
412 (error "No such file: %s" old-arc)
413 (if (file-exists-p new-arc)
414 (error "Already exists: %s" new-arc)
415 (rename-file old-arc new-arc)
418 (defun elmo-archive-list-folders (spec &optional hierarchy)
419 (let ((folder (concat "$" (nth 1 spec)))
420 (elmo-localdir-folder-path elmo-archive-folder-path))
421 (if elmo-archive-treat-file
422 (let* ((path (elmo-localdir-get-folder-directory spec))
423 (base-folder (or (nth 1 spec) ""))
424 (suffix (nth 2 spec))
425 (prefix (if (string= (nth 3 spec) "")
426 "" (concat ";" (nth 3 spec))))
427 (dir (if (file-directory-p path)
428 path (file-name-directory path)))
429 (name (if (file-directory-p path)
430 "" (file-name-nondirectory path)))
431 (flist (and (file-directory-p dir)
432 (directory-files dir nil name nil)))
433 (regexp (format "^\\(.*\\)\\(%s\\)$"
435 '(lambda (x) (regexp-quote (cdr x)))
436 elmo-archive-suffix-alist
438 (if (string-match "\\(.*\\)/$" base-folder) ; ends with '/'.
439 (setq base-folder (elmo-match-string 1 base-folder))
440 (unless (file-directory-p path)
441 (setq base-folder (or (file-name-directory base-folder)
447 (when (and (string-match regexp x)
450 (rassoc (elmo-match-string 2 x)
451 elmo-archive-suffix-alist))))
453 (elmo-concat-path base-folder (elmo-match-string 1 x))
456 (elmo-localdir-list-folders-subr folder hierarchy))))
459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
460 ;;; Article file related functions
461 ;;; read(extract) / append(move) / delete(delete) / query(list)
463 (defun elmo-archive-read-msg (spec number outbuf &optional msgdb unread)
465 (let* ((type (nth 2 spec))
466 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
467 (prefix (nth 3 spec))
468 (method (elmo-archive-get-method type 'cat))
469 (args (list arc (elmo-concat-path
470 prefix (int-to-string number)))))
473 (when (file-exists-p arc)
476 (elmo-archive-call-method method args t))
477 (elmo-delete-cr-get-content-type))))))
480 (defun elmo-archive-append-msg (spec string &optional msg no-see)
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 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 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 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)))
779 (defsubst elmo-archive-msgdb-create-entity (method archive number type &optional prefix)
780 (let* ((msg (elmo-concat-path prefix (int-to-string number)))
781 (arg-list (list archive msg)))
782 (when (elmo-archive-article-exists-p archive msg type)
785 (elmo-archive-call-method method arg-list t))
786 (elmo-archive-msgdb-create-entity-subr number))))
788 (defun elmo-archive-msgdb-create-as-numlist (spec numlist new-mark
789 already-mark seen-mark
790 important-mark seen-list)
792 (save-excursion ;; 981005
793 (if (and elmo-archive-use-izip-agent
794 (elmo-archive-get-method (nth 2 spec) 'cat-headers))
795 (elmo-archive-msgdb-create-as-numlist-subr2
796 spec numlist new-mark already-mark seen-mark important-mark
798 (elmo-archive-msgdb-create-as-numlist-subr1
799 spec numlist new-mark already-mark seen-mark important-mark
802 (defalias 'elmo-archive-msgdb-create 'elmo-archive-msgdb-create-as-numlist)
805 (defun elmo-archive-msgdb-create-as-numlist-subr1 (spec numlist new-mark
806 already-mark seen-mark
809 (let* ((type (nth 2 spec))
810 (file (elmo-archive-get-archive-name (nth 1 spec) type spec))
811 (method (elmo-archive-get-method type 'cat))
812 (tmp-buf (get-buffer-create " *ELMO ARCHIVE msgdb*"))
813 overview number-alist mark-alist entity
814 i percent num message-id seen gmark)
817 (setq num (length numlist))
819 (message "Creating msgdb...")
823 (elmo-archive-msgdb-create-entity
824 method file (car numlist) type (nth 3 spec)))
827 (elmo-msgdb-append-element
830 (elmo-msgdb-number-add
832 (elmo-msgdb-overview-entity-get-number entity)
834 (setq message-id (car entity))
835 (setq seen (member message-id seen-list))
837 (or (elmo-msgdb-global-mark-get message-id)
838 (if (elmo-cache-exists-p message-id) ; XXX
846 (elmo-msgdb-mark-append
848 (elmo-msgdb-overview-entity-get-number entity)
850 (when (> num elmo-display-progress-threshold)
852 (setq percent (/ (* i 100) num))
853 (elmo-display-progress
854 'elmo-archive-msgdb-create-as-numlist-subr1 "Creating msgdb..."
856 (setq numlist (cdr numlist)))
857 (kill-buffer tmp-buf)
858 (message "Creating msgdb...done")
859 (list overview number-alist mark-alist)) ))
862 (defun elmo-archive-msgdb-create-as-numlist-subr2 (spec numlist new-mark
863 already-mark seen-mark
866 (let* ((buf (get-buffer-create " *ELMO ARCHIVE headers*"))
867 (delim1 elmo-mmdf-delimiter) ;; MMDF
868 (delim2 elmo-unixmail-delimiter) ;; UNIX Mail
870 (prefix (nth 3 spec))
871 (method (elmo-archive-get-method type 'cat-headers))
874 (arc (elmo-archive-get-archive-name (nth 1 spec) type))
875 n i percent num result overview number-alist mark-alist
876 msgs case-fold-search)
878 (setq num (length numlist))
880 (message "Creating msgdb...")
882 (setq n (min (1- elmo-archive-fetch-headers-volume)
883 (1- (length numlist))))
884 (setq msgs (reverse (memq (nth n numlist) (reverse numlist))))
885 (setq numlist (nthcdr (1+ n) numlist))
890 (mapcar '(lambda (x) (elmo-concat-path prefix (int-to-string x))) msgs)
892 (message "Fetching headers...")
893 (as-binary-process (apply 'call-process-region
894 (point-min) (point-max)
895 prog t t nil (append args (list arc))))
896 (goto-char (point-min))
898 ((looking-at delim1) ;; MMDF
899 (setq result (elmo-archive-parse-mmdf msgs
901 already-mark seen-mark
903 (setq overview (append overview (nth 0 result)))
904 (setq number-alist (append number-alist (nth 1 result)))
905 (setq mark-alist (append mark-alist (nth 2 result))))
906 ;;; ((looking-at delim2) ;; UNIX MAIL
907 ;;; (setq result (elmo-archive-parse-unixmail msgs))
908 ;;; (setq overview (append overview (nth 0 result)))
909 ;;; (setq number-alist (append number-alist (nth 1 result)))
910 ;;; (setq mark-alist (append mark-alist (nth 2 result))))
912 (error "Unknown format!")))
913 (when (> num elmo-display-progress-threshold)
915 (setq percent (/ (* i 100) num))
916 (elmo-display-progress
917 'elmo-archive-msgdb-create-as-numlist-subr2 "Creating msgdb..."
920 (list overview number-alist mark-alist)) )
922 (defun elmo-archive-parse-mmdf (msgs new-mark
926 (let ((delim elmo-mmdf-delimiter)
927 number sp ep rest entity overview number-alist mark-alist ret-val
928 message-id seen gmark)
929 (goto-char (point-min))
931 (while (and rest (re-search-forward delim nil t)
933 (setq number (car rest))
934 (setq sp (1+ (point)))
935 (setq ep (prog2 (re-search-forward delim)
936 (1+ (- (point) (length delim)))))
937 (if (>= sp ep) ; no article!
940 (narrow-to-region sp ep)
941 (setq entity (elmo-archive-msgdb-create-entity-subr number))
943 (elmo-msgdb-append-element
946 (elmo-msgdb-number-add
948 (elmo-msgdb-overview-entity-get-number entity)
950 (setq message-id (car entity))
951 (setq seen (member message-id seen-list))
953 (or (elmo-msgdb-global-mark-get message-id)
954 (if (elmo-cache-exists-p message-id) ; XXX
962 (elmo-msgdb-mark-append
964 (elmo-msgdb-overview-entity-get-number entity)
966 (setq ret-val (append ret-val (list overview number-alist mark-alist)))
969 (setq rest (cdr rest)))
973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
976 (defsubst elmo-archive-field-condition-match (spec number number-list
979 (let* ((type (nth 2 spec))
980 (arc (elmo-archive-get-archive-name (nth 1 spec) type spec))
981 (method (elmo-archive-get-method type 'cat))
982 (args (list arc (elmo-concat-path prefix (int-to-string number)))))
984 (when (file-exists-p arc)
986 (elmo-archive-call-method method args t))
987 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
988 (decode-mime-charset-region (point-min)(point-max) elmo-mime-charset)
989 (elmo-buffer-field-condition-match condition number number-list))))))
991 (defun elmo-archive-search (spec condition &optional from-msgs)
992 (let* (;;(args (elmo-string-to-list key))
993 ;; XXX: I don't know whether `elmo-archive-list-folder'
994 ;; updates match-data.
995 ;; (msgs (or from-msgs (elmo-archive-list-folder spec)))
996 (msgs (or from-msgs (elmo-archive-list-folder spec)))
999 (case-fold-search nil)
1000 number-list ret-val)
1001 (setq number-list msgs)
1003 (if (elmo-archive-field-condition-match spec (car msgs) number-list
1006 (setq ret-val (cons (car msgs) ret-val)))
1007 (when (> num elmo-display-progress-threshold)
1009 (elmo-display-progress
1010 'elmo-archive-search "Searching..."
1012 (setq msgs (cdr msgs)))
1013 (nreverse ret-val)))
1016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1019 (defun elmo-archive-check-validity (spec validity-file)
1022 (defun elmo-archive-sync-validity (spec validity-file)
1027 (if (null elmo-archive-method-alist)
1028 (let ((mlist elmo-archive-method-list) ; from mew-highlight.el
1031 (setq method (car mlist))
1032 (setq mlist (cdr mlist))
1033 (setq str (symbol-name method))
1034 (string-match "elmo-archive-\\([^-].*\\)-method-alist$" str)
1035 (setq type (intern-soft
1036 (elmo-match-string 1 str)))
1037 (setq elmo-archive-method-alist
1039 (symbol-value method))
1040 elmo-archive-method-alist)))))
1042 ;;; valid suffix(list)
1043 (if (null elmo-archive-suffixes)
1044 (let ((slist elmo-archive-suffix-alist)
1047 (setq tmp (car slist))
1048 (setq elmo-archive-suffixes
1049 (nconc elmo-archive-suffixes (list (cdr tmp))))
1050 (setq slist (cdr slist)))))
1052 (defun elmo-archive-use-cache-p (spec number)
1053 elmo-archive-use-cache)
1055 (defun elmo-archive-local-file-p (spec number)
1058 (defun elmo-archive-get-msg-filename (spec number &optional loc-alist)
1059 (let ((tmp-dir (file-name-as-directory (elmo-msgdb-expand-path spec)))
1060 (prefix (nth 3 spec)))
1062 (elmo-concat-path prefix (int-to-string number))
1065 (defalias 'elmo-archive-sync-number-alist
1066 'elmo-generic-sync-number-alist)
1067 (defalias 'elmo-archive-list-folder-unread
1068 'elmo-generic-list-folder-unread)
1069 (defalias 'elmo-archive-list-folder-important
1070 'elmo-generic-list-folder-important)
1071 (defalias 'elmo-archive-commit 'elmo-generic-commit)
1072 (defalias 'elmo-archive-folder-diff 'elmo-generic-folder-diff)
1075 (run-hooks 'elmo-archive-load-hook)
1078 (product-provide (provide 'elmo-archive) (require 'elmo-version))
1080 ;;; elmo-archive.el ends here