[mew-dist 27458] mewest for Windows

KIMURA Yasuhiro yasu at example.com
2006年 11月 3日 (金) 22:02:24 JST


Hyper Estraierによる検索を試してみようと思ったら、mewestがWindowsでは
動かなくて悲しかったので、添付したようなperl scriptを書いてみました。

* Windows XP SP2
* Meadow 2.10
* Mew 5.1.51
* Hyper Estraier 1.4.7
* ActivePerl 5.8.8 Build 819
* このperl script

という組合せと、~/.mew.elに

(setq mew-prog-est-update "mewest4win.pl")

という設定を追加することで、取り敢えず

* kM
* km
* ASCIIなキーワードでの検索

までは出来るようになりました。

ところが日本語キーワードで検索すると、どんなキーワードを指定しても何も
引っかかってきません。UnixやMacだと日本語キーワードでもちゃんと検索で
きているようなのに、Windowsだと駄目というのは悲しいです。

なんとなく文字コードの問題のように思えるのですが、EmacsLispもperlも
Hyper Estraierも詳しくないので、どこに問題があるのか切り分けが出来ず、
お手上げ状態になってしまいました。

何か思い当たる点がありましたら指摘していただけないでしょうか。

---
木村 康浩 
-------------- next part --------------
#!/usr/bin/perl -w
#
# mewest4win.pl: Rewrite of 'mewest' as perl script
#
# Author: KIMURA Yasuhiro <yasu at example.com>
# Created: Nov 03, 2006
#
# This program is intended to be used on Windows with ActivePerl,
# rather than Cygwin perl.
# It is available under same license conditions as original 'mewest'.
#

require 5.008;
use Getopt::Long;

$dirsep = "\\";

$basedir = $ENV{'HOME'} . $dirsep . "Mail";
$indexsubdir = "casket";
$indexdir = $basedir . $dirsep . $indexsubdir;
$trashsubdir = "trash";
$lock = $basedir . $dirsep . ".mewest.lock";

#
# Subroutines
#

sub usage {
    print <<"EOM";
USAGE: $0 [directory]
  -h help
  -v verbose mode
EOM
    exit 1;
}

sub lock {
    return mkdir $lock, "0700";
}

sub unlock {
    return rmdir $lock;
}

sub unlock_exit {
    unlock();
    exit 4;
}

sub find_msg_sub {
    my $dir = shift;
    my $outputfh = shift;
    opendir my $dh, $dir || return 0;
    foreach my $dirent (readdir($dh)) {
	if ($dirent =~ /^\.{1,2}$/) {
	    next;
	}
	my $path = $dir . $dirsep . $dirent;
	if (-d $path) {
	    find_msg_sub($path, $outputfh) || return 0;
	}
	elsif (-f $path && $dirent =~ /^\d+(\.mew)?$/) {
	    print $outputfh "$path\n";
	}
    }
    closedir $dh || return 0;
    return 1;
}

sub find_msg {
    my $dir = shift;
    my $outputfh = shift;
    opendir my $dh, $dir || return 0;
    foreach my $dirent (readdir($dh)) {
	my $path = $dir . $dirsep . $dirent;
	if ($dirent =~ /^\.{1,2}$/ || $dirent eq $indexsubdir ||
	    $dirent eq $trashsubdir || ! -d $path) {
	    next;
	}
	find_msg_sub($path, $outputfh) || return 0;
    }
    closedir $dh || return 0;
    return 1;
}

#
# Main routine
#

$help = 0;
$verbose = 0;
$targetdir = $basedir;

if (!GetOptions('h' => \$help, 'v' => \$verbose)) {
    usage();
}

if ($help) {
    usage();
}

if (defined $ARGV[0]) {
    $targetdir = $ARGV[0];
}

if (!-d $targetdir) {
    print "$targetdir not found\n";
    exit 4;
}

$SIG{'HUP'} = \&unlock_exit;
$SIG{'INT'} = \&unlock_exit;
$SIG{'QUIT'} = \&unlock_exit;
$SIG{'KILL'} = \&unlock_exit;
$SIG{'TERM'} = \&unlock_exit;

if (!lock()) {
    print "$lock exists\n";
    exit 5;
}

$purgecmd = "estcmd purge \"$indexdir\" \"$targetdir\"";
if (!$verbose) {
    $purgecmd .= " > NUL";
}
if (-d $indexdir) {
    print "Purging old messages...\n";
    if (system($purgecmd)) {
	print "Purging old messages...failed\n";
	unlock_exit();
    }
    print "Purging old messages...done\n";
}
    
$gathercmd = "| estcmd gather -cl -fm -cm -sd -xh \"$indexdir\" -";
if (!$verbose) {
    $gathercmd .= " > NUL";
}
print "Indexing new messages...\n";
if (!open(GATHER, $gathercmd)) {
    print "Indexing new messages...failed\n";
    unlock_exit();
}
if (!find_msg($targetdir, GATHER)) {
    print "Indexing new messages...failed\n";
    unlock_exit();
}
if (!close(GATHER)) {
    print "Indexing new messages...failed\n";
    unlock_exit();
}
print "Indexing new messages...done\n";

unlock();
exit 0;


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