* extfs/mailfs.in: Fixed bug when opening empty mailbox. Added

proper message size (not number of lines, like before) counting.
This commit is contained in:
Pavel Roskin 2002-12-14 20:05:29 +00:00
parent 5e039bf28f
commit 90821fb2b8
2 changed files with 26 additions and 16 deletions

View File

@ -1,3 +1,8 @@
2002-12-14 Adam Byrtek <alpha@debian.org>
* extfs/mailfs.in: Fixed bug when opening empty mailbox. Added
proper message size (not number of lines, like before) counting.
2002-12-13 Pavel Roskin <proski@gnu.org> 2002-12-13 Pavel Roskin <proski@gnu.org>
* extfs/uha.in (mchafs_list): Don't parse the month, use * extfs/uha.in (mchafs_list): Don't parse the month, use

View File

@ -1,5 +1,7 @@
#! @PERL@ -w #! @PERL@ -w
use bytes;
# MC extfs for (possibly compressed) Berkeley style mailbox files # MC extfs for (possibly compressed) Berkeley style mailbox files
# Peter Daum <gator@cs.tu-berlin.de> (Jan 1998, mc-4.1.24) # Peter Daum <gator@cs.tu-berlin.de> (Jan 1998, mc-4.1.24)
@ -10,13 +12,13 @@ $TZ='GMT'; # default timezone (for Date module)
if (eval "require Date::Manip") { if (eval "require Date::Manip") {
import Date::Manip; import Date::Manip;
$parse_date= $parse_date=
sub { sub {
return UnixDate($_[0], "%l"); # "ls -l" format return UnixDate($_[0], "%l"); # "ls -l" format
} }
} elsif (eval "require Date::Parse") { } elsif (eval "require Date::Parse") {
import Date::Parse; import Date::Parse;
$parse_date= $parse_date=
sub { sub {
local $_ =localtime(str2time($_[0],$TZ)); local $_ =localtime(str2time($_[0],$TZ));
s/^... (.+) (\d\d:\d\d):\d\d (\d\d\d\d)$/$1 $3 $2/; s/^... (.+) (\d\d:\d\d):\d\d (\d\d\d\d)$/$1 $3 $2/;
@ -44,64 +46,66 @@ if (eval "require Date::Manip") {
return "$1 $2 $5 $3"; return "$1 $2 $5 $3";
} }
# Fallback # Fallback
return "Jan 1 1980 00:00"; return localtime(time);
} }
} }
sub process_header { sub process_header {
while (<IN>) { while (<IN>) {
$size+=length;
s/\r$//; s/\r$//;
last if /^$/; last if /^$/;
die "unexpected EOF\n" if eof; die "unexpected EOF\n" if eof;
if (/^Date:\s(.*)$/) { if (/^Date:\s(.*)$/) {
$date=&$parse_date($1); $date=&$parse_date($1);
} elsif (/^Subject:\s(.*)$/) { } elsif (/^Subject:\s(.*)$/) {
$subj=$1; $subj=lc($1);
$subj=~ s/^(re:\s?)+//gi; # no leading Re: $subj=~ s/^(re:\s?)+//gi; # no leading Re:
$subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters $subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters
} elsif (/^From:\s.*?(\w+)\@/) { } elsif (/^From:\s.*?(\w+)\@/) {
$from=$1; $from=$1;
} elsif (/^To:\s.*?(\w+)\@/) { } elsif (/^To:\s.*?(\w+)\@/) {
$to=$1; $to=lc($1);
} }
} }
} }
sub print_dir_line { sub print_dir_line {
$from=$to if ($from eq $user); # otherwise, it would look pretty boring $from=$to if ($from eq $user); # otherwise, it would look pretty boring
printf "-r-------- 1 $< $< %d %s %3.3d_%.16s\n", $date=localtime(time) if (!defined $date);
$line, $date, $msg_nr, "${from}_${subj}"; printf "-r-------- 1 $< $< %d %s %3.3d_%.25s\n",
$size, $date, $msg_nr, "${from}_${subj}";
} }
sub mailfs_list { sub mailfs_list {
my $blank = 1; my $blank = 1;
$user=$ENV{USER}||getlogin||getpwuid($<) || "nobody"; $user=$ENV{USER}||getlogin||getpwuid($<) || "nobody";
while(1) { while(<IN>) {
$_=<IN>;
if (!defined($_)) { # EOF
print_dir_line;
exit 0;
}
s/\r$//; s/\r$//;
if($blank && /^From /) { # Start of header if($blank && /^From /) { # Start of header
print_dir_line unless (!$msg_nr); print_dir_line unless (!$msg_nr);
$size=length;
$msg_nr++; $msg_nr++;
($from,$to,$subj,$date)=("none","none","none", "01-01-80"); ($from,$to,$subj,$date)=("none","none","none", "01-01-80");
process_header; process_header;
$line=$blank= 0; $line=$blank=0;
} else { } else {
$size+=length;
$line++; $line++;
$blank= /^$/; $blank= /^$/;
} }
} }
print_dir_line unless (!$msg_nr);
exit 0;
} }
sub mailfs_copyout { sub mailfs_copyout {
my($source,$dest)=@_; my($source,$dest)=@_;
exit 1 unless (open STDOUT, ">$dest"); exit 1 unless (open STDOUT, ">$dest");
($nr)= ($source =~ /^(\d+)/); # extract message number from "filename" ($nr)= ($source =~ /^(\d+)/); # extract message number from "filename"
my $blank = 1; my $blank = 1;
while(<IN>) { while(<IN>) {
s/\r$//; s/\r$//;
@ -117,6 +121,7 @@ sub mailfs_copyout {
} }
# main { # main {
exit 1 unless ($#ARGV >= 1);
$msg_nr=0; $msg_nr=0;
$cmd=shift; $cmd=shift;
$mbox_name=shift; $mbox_name=shift;