[Mew-dist 1600] Re: qmail patch of LocalMbox.pm

Motonori Nakamura motonori at example.com
1997年 8月 24日 (日) 11:16:31 JST


>>>>> On Sat, 23 Aug 1997 17:04:53 +0900, Yoshitomi Kentaro <yositomi at example.com> said:

yositomi>  IM-62 の LocalMbox.pm.in の qmail の maildir 形式への暫定対
yositomi> 応版 patch です。たたけばきっとほこりが出てきます。(^ ^;

patch をもとにして、こんなのにしてみましたが、いかがでしょうか。
Config の #MBoxStyle=qmail のコメントアウトをはずすと、qmail の maildir
形式*も*扱うようになります。

yositomi> patch をあてたあと, qmail を使ってなければ これを 0 にしない
yositomi> と当然動きません。

MBoxStyle=qmail になっていても、mailbox の path が明示的に指定されて
いない場合は、従来の形式のものも探しに行きます。

システムレベルで qmail のフォルダを明示的に限定したい場合は、
Config に Imget.Src=local:${HOME}/MailDir と書けばいいでしょう。

- motonori

-------------- next part --------------
diff -ur ../im-62-2/IM.in/Config.pm.in ./IM.in/Config.pm.in
--- ../im-62-2/IM.in/Config.pm.in	Sun Aug 24 09:24:53 1997
+++ ./IM.in/Config.pm.in	Sun Aug 24 11:09:36 1997
@@ -39,6 +39,7 @@
     aliases_file context_file
     address addresses_regex
     msgdbfile msgdbtype getsbrfile scansbrfile petnamefile
+    mbox_style
     nntpservers nntphistoryfile
     popaccount pophistoryfile imapaccount httpproxy noproxy
     unixp win95p wntp os2p
@@ -147,6 +148,7 @@
     'petnamefile;s;;PetNameFile'        => 'PetName file',
     'getsbr;s;;GetSbrFile'              => 'Get hook subroutine script',
     'scansbr;s;;ScanSbrFile'            => 'Scan hook subroutine script',
+    'mboxstyle;s;;MBoxStyle'            => 'Style of local MBox format',
     'nntpservers;s;;NNTPservers'        => 'List of NNTP servers',
     'nntphistory;s;;NNTPhistory'        => 'Status file of NNTP access',
     'popaccount;s;;POPaccount'          => 'Account info for POP access',
@@ -499,6 +501,7 @@
     my ($name, $val, $case) = @_;
     my ($mnam, $desc, $vnam);
 
+    $val =~ s/\${(\w+)}/$ENV{$1}/ge;
     if ($val =~ /^\$(.*)/) {
 	# $InboxFolder -> +inbox
 	$val = ${$C_VNAM{lc($1)}};
@@ -717,6 +720,10 @@
 
 sub scansbrfile {
     return &expand_path($ScanSbrFile);
+}
+
+sub mbox_style {
+    return $MBoxStyle;
 }
 
 sub nntpservers {
diff -ur ../im-62-2/IM.in/LocalMbox.pm.in ./IM.in/LocalMbox.pm.in
--- ../im-62-2/IM.in/LocalMbox.pm.in	Tue Aug 19 14:49:19 1997
+++ ./IM.in/LocalMbox.pm.in	Sun Aug 24 11:05:59 1997
@@ -48,13 +48,6 @@
 # local mailbox access routines #
 #################################
 
- at example.com = (
-    '/var/mail',
-    '/var/spool/mail',
-    '/usr/mail',
-    '/usr/spool/mail'
-);
-
 ##### LOCAL SPOOL MANAGEMENT #####
 #
 # local_get_msg(src, dst, how)
@@ -62,7 +55,7 @@
 #
 sub local_get_msg ($$$$) {
     my ($src, $dst, $how, $lock_type) = @_;
-    my ($need_lock, $msgs, $l, $file);
+    my ($need_lock, $qmail_ok, $msgs, $l, $file, $p);
 
     if ($how eq 'get') {
 	$need_lock = 1;
@@ -70,20 +63,48 @@
 	$need_lock = 0;
     }
 
-    $src =~ /local:(.*)/i;
-    my ($mbox) = $1;
+    (my $mbox = $src) =~ s/local:?//i;
+
+    if (&mbox_style() =~ /qmail/i) {
+	$qmail_ok = 1;
+	im_notice("qmail access enabled.\n");
+    } else {
+	$qmail_ok = 0;
+	im_notice("qmail access disabled.\n");
+    }
+
+#   my $user = $ENV{'USER'};
+#   $user = $ENV{'LOGNAME'} unless ($user);
+    my $user = getlogin;
+    $user = (getpwuid($<))[0] unless ($user);
 
+    # set default
     unless ($mbox) {
-	# set default
-#	my $user = $ENV{'USER'};
-#	$user = $ENV{'LOGNAME'} unless ($user);
-	my $user = getlogin;
-	$user = (getpwuid($<))[0] unless ($user);
-
-	foreach $p (@MailDrops) {
-	    if ( -f "$p/$user" ) {
-		$mbox = "$p/$user";
-		last;
+	if ($qmail_ok) {
+	    $home = (getpwuid($<))[7] unless ($home);
+	    push(@MailDrops, $ENV{'MAILDIR'}) if ($ENV{'MAILDIR'});
+	    push(@MailDrops, $ENV{'MAILDROP'}) if ($ENV{'MAILDROP'});
+	    push(@MailDrops, $ENV{'MAIL'}) if ($ENV{'MAIL'});
+	    push(@MailDrops, "$home/Maildir", "$home/Mailbox");
+	    foreach $p (@MailDrops) {
+		if ( -d $p && -d "$p/new" ) {
+		    $mbox = $p;
+		    last;
+		}
+	    }
+	}
+	unless ($mbox) {
+	    @MailDrops = (
+		"/var/mail",
+		"/var/spool/mail",
+		"/usr/mail",
+		"/usr/spool/mail"
+	    );
+	    foreach $p (@MailDrops) {
+		if ( -f "$p/$user" ) {
+		    $mbox = "$p/$user";
+		    last;
+		}
 	    }
 	}
 	unless ($mbox) {
@@ -91,28 +112,48 @@
 	    return -1;
 	}
     }
+    im_notice("mailbox for $user is $mbox\n");
 
     if (-d $mbox) {
 	# DIRECTORY
+	my $qmail_folder = 0;
+	if ($qmail_ok && -d "$mbox/new") {
+	    $mbox = "$mbox/new";
+	    $qmail_folder = 1;
+	}
 	my $msgs = 0;
-	unless (opendir(FOLDER, $mbox)) {
+	unless (opendir(FLDR, $mbox)) {
 	    im_warn("can't open directory: $mbox\n");
 	    return -1;
 	}
 	im_info("Getting new messages from maildir into $dst....\n")
 	  if ($how eq 'get');
-	foreach $f (sort {$a <=> $b} readdir(FOLDER)) {
-	    if ($f =~ /^\d+$/ && -s "$mbox/$f") {
-		if (&process_file("$mbox/$f", $dst, $how) < 0) {
-		    return -1;
+	if ($qmail_folder) {
+	    foreach $f (sort {(-M $b) <=> (-M $a) || $a cmp $b} readdir(FLDR)) {
+		if ($f =~ /^\d+\.\d+\..+/ && -s "$mbox/$f") {
+		    if (&process_file("$mbox/$f", $dst, $how) < 0) {
+			return -1;
+		    }
+		    if ($how eq 'get' && $main::opt_keep == 0) {
+			unlink("$mbox/$f");
+		    }
+		    $msgs++;
 		}
-		if ($how eq 'get' && $main::opt_keep == 0) {
-		    unlink("$mbox/$f");
+	    }
+	} else {
+	    foreach $f (sort {$a <=> $b} readdir(FLDR)) {
+		if ($f =~ /^\d+$/ && -s "$mbox/$f") {
+		    if (&process_file("$mbox/$f", $dst, $how) < 0) {
+			return -1;
+		    }
+		    if ($how eq 'get' && $main::opt_keep == 0) {
+			unlink("$mbox/$f");
+		    }
+		    $msgs++;
 		}
-		$msgs++;
 	    }
 	}
-	closedir(FOLDER);
+	closedir(FLDR);
 	if ($msgs == 0) {
 	    if ($how eq 'check') {
 		im_msg("no message in local maildir.\n");
diff -ur ../im-62-2/cnf.im/Config ./cnf.im/Config
--- ../im-62-2/cnf.im/Config	Sun Aug 24 09:28:38 1997
+++ ./cnf.im/Config	Sun Aug 24 11:13:25 1997
@@ -46,6 +46,8 @@
 Src=$InboxFolder
 Imrm.Src=$TrashFolder
 Imget.Src=local
+#Imget.Src=local:${HOME}/MailDir
+#MBoxStyle=qmail
 ##
 ## Command depend
 ##
diff -ur ../im-62-2/dot.im/Config ./dot.im/Config
--- ../im-62-2/dot.im/Config	Sun Aug 17 18:54:06 1997
+++ ./dot.im/Config	Sun Aug 24 11:13:53 1997
@@ -46,6 +46,8 @@
 #Src=$InboxFolder
 #Imrm.Src=$TrashFolder
 #Imget.Src=local
+#Imget.Src=local:${HOME}/MailDir
+#MBoxStyle=qmail
 ##
 ## Command depend
 ##


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