* 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>
* extfs/uha.in (mchafs_list): Don't parse the month, use

View File

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