[Mew-Win32 00368] Re: mew-folder-list (Re: C-uZ)

YAMAGUCHI, Shuhei yamagus at example.com
1998年 3月 5日 (木) 01:19:50 JST


やまぐち@ねっとらぴゅたの住人、です。

OS/2の方では、別の手段で高速化してるらしいです。
#REXXをどうのという話だったんですが、OS/2は一度もさわったことがないの
#で、イメージがつかみきれませんでした。

>>> In article <19980304152156V.yamagus at example.com>,
>>>    "YAMAGUCHI, Shuhei" <yamagus at example.com> writes:

  yamagus> んで、このあたりのバグも、アドホックに事を進めてきたのも原因のひとつで
  yamagus> しょうから、mew-folder-make-listを最初から構成しなおそうと思っています。

というわけで、見直しました、が、ほとんど再利用して、結局あんまりかわっ
てません。
しかし、今回は、mew-use-folders-file-p、mew-use-folder-list-function、
引数updatepのそれぞれの値、あと、~/Mail/.foldersの存在の、計16パターン
で試したので大丈夫だと思います。 ^^;


  yamagus> #そもそも、mew-folder-list関数を使ってるのに、バッファに書き込んで再度
  yamagus> #読み直すってのは無駄ですしね。 ^^;

よくよくコードを読めば、ここのところで、下にさらにフォルダがある場合は
後ろにスラッシュを追加する、という操作もしてました。 ^^;;;
mew-folder-listを使う場合だけ別のところで同じ操作をするのも馬鹿らしい
ので、このあたりのロジックはそのままです。

でわでわ
-- 
yamagus at example.com / やまぐち@ねっとらぴゅたの住人
  yamagus at example.com / 山口 修平
PGP-Fingerprint: 25 0F 6F E1 57 AD 56 08  3A BC D0 9B 48 AF 31 7A
-------------- next part --------------
;; -*- emacs-lisp -*-
;; mew-parasite.el --- Parasitic on Mew, then tune it up!
;;
;;                       "YAMAGUCHI, Shuhei" <yamagus at example.com>
;;                                            Created: <03/03/1998>
;;                                Revised: Time-stamp: <03/05/1998 00:47>
;;
;; To use mew-parasite.el, put the following codes in your .emacs.
;; (eval-after-load "mew" '(load "mew-parasite"))

(eval-when-compile
  (require 'mew))

(defconst mew-parasite-version "Mew parasite version 1.01"
  "Version string of mew-parasite.")

(defvar mew-use-folder-list-function t
  "If t, Mew uses mew-folder-list function as a subsutitute for
'impath --list'.
You decide to use this package, this shall be t.")

(defvar mew-folder-list-use-file-attributes
  (or (not (or (eq system-type 'windows-nt)
	       (memq system-type '(OS/2 emx))))
      (fboundp 'Meadow-version))
  "If t, 2nd element of a returned list from file-attributes, aka
LINK-COUNT, works.
Otherwise, mew-folder-list function never use file-attributes for
checking existence of subfolders, and any system can make list safety,
but too slow.

For Mule for Win32 and OS/2 Mule users:
This might be set to nil.")

(defvar mew-folder-list-skip-pattern "^\\(\\.\\.?\\|^[0-9]+\\)$"
  "If a file-name matches this pattern, mew-folder-list function never
consider it as a folder without checking it's file-type.

Default is \"^\\\\(\\\\.\\\\.?\\\\|^[0-9]+\\\\)$\", and it assumes
you never have numeric folders like \"+foo/199803\".
If you have such numeric folders, \"^\\\\.\\\\.?\" is a good selection,
but it is not good in sight of performance.
If numeric folders assume dates, folders like \"+foo/Mar-1998\" are
better solution other than like \"+foo/199803\".")

(defun mew-file-attributes (filename)
  "Same as file-attributes, but chase it if FILENAME is a symbolic-link."
  (let ((w32-get-true-file-link-count t) ; for Meadow
	attr symlnk)
    (while (stringp (setq symlnk (car (setq attr (file-attributes filename)))))
      (setq filename
	    (expand-file-name symlnk (file-name-directory filename))))
    attr))

(defun mew-folder-list (folder)
  "List up subfolders of FOLDER."
  (let ((case-fold-search t)
	(w32-get-true-file-link-count t)
	folders curdir dirent relpath abspath attr
	subprefix subfolder)
    (setq curdir (mew-expand-folder folder))
    (if (string-match "^[+=]$" folder)
	(setq subprefix folder)
      (setq subprefix (concat folder "/")))
    (setq dirent (directory-files curdir))
    (while dirent
      (setq relpath (car dirent))
      (setq dirent (cdr dirent))
      (setq abspath (expand-file-name relpath curdir))
      (and
       (not (string-match mew-folder-list-skip-pattern relpath))
       (eq (nth 0 (setq attr (mew-file-attributes abspath))) t)
       (setq subfolder (concat subprefix relpath))
       (setq folders (nconc folders (list subfolder)))
       (or
	(and
	 mew-folder-list-use-file-attributes
	 (>= 2 (nth 1 attr)))
	(setq folders (nconc folders (mew-folder-list subfolder))))))
    folders))

(defun mew-folder-make-list (updatep)
  (save-excursion
    (let ((case-fold-search t)
	  (folders ())
	  (folder nil)
	  (start nil)
	  (file (expand-file-name mew-folders-file mew-mail-path)))
      (mew-set-buffer-tmp)
      (cond
       ((and (not updatep)
	     mew-use-folders-file-p
	     (file-readable-p file))
	(insert-file-contents file))
       (mew-use-folder-list-function
	(mapcar
	 (lambda (x)
	   (insert x "\n"))
	 (nconc (mew-folder-list "+")
		(mew-folder-list "=")))
	(if mew-use-folders-file-p
	    (write-region (point-min) (point-max) file nil 'no-msg)))
       (t
	(mew-im-call-process nil mew-prog-impath "--list=yes" "--src=+")
	(mew-im-call-process nil mew-prog-impath "--list=yes" "--src==")
	(if mew-use-folders-file-p
	    (write-region (point-min) (point-max) file nil 'no-msg))))
      (goto-char (point-min))
      (while (not (eobp))
	(setq start (point))
	(if (not (looking-at "[+=]"))
	    (forward-line)
	  (forward-line)
	  (setq folder (mew-buffer-substring start (1- (point))))
	  (if (and (car folders)
		   (string-match (concat "^" (regexp-quote 
					      (file-name-as-directory
					       (car folders))))
				 folder))
	      ;; regexp-quote is not necessary since not "+".
	      (setq folders 
		    (cons folder 
			  (cons (file-name-as-directory (car folders))
				(cdr folders))))
	    (setq folders (cons folder folders))))
	)
      folders ;; return value
      )))

(provide 'mew-parasite)


Mew-win32 メーリングリストの案内