* extfs/mailfs.in (parse_date): Output 3 date fields not 4. Range to

output time not year is slightly larger than the range used by
	file_date() in util.c. Prefer using Date::Parse over Date::Manip as the
	former is faster. Fix fallback for "light version".
	(process_header): Match header field names case insensitively.
	(mailfs_list): Improve match for header start.
	(mailfs_copyout): Likewise.
This commit is contained in:
Leonard den Ottolander 2006-05-28 12:35:57 +00:00
parent 5297c50278
commit e494043f82
2 changed files with 95 additions and 28 deletions

View File

@ -1,3 +1,13 @@
2006-05-28 Leonard den Ottolander <leonard den ottolander nl>
* extfs/mailfs.in (parse_date): Output 3 date fields not 4. Range to
output time not year is slightly larger than the range used by
file_date() in util.c. Prefer using Date::Parse over Date::Manip as the
former is faster. Fix fallback for "light version".
(process_header): Match header field names case insensitively.
(mailfs_list): Improve match for header start.
(mailfs_copyout): Likewise.
2006-05-05 Andrew V. Samoilov <andrew@email.zp.ua>
* extfs/uzip.in (print_file): Use %8s instead of %8d

View File

@ -10,43 +10,93 @@ $bzcat="bzip2 -dc"; # bunzip2 to stdout
$file="file"; # "file" command
$TZ='GMT'; # default timezone (for Date module)
if (eval "require Date::Manip") {
if (eval "require Date::Parse") {
import Date::Parse;
$parse_date=
sub {
local $ftime = str2time($_[0],$TZ);
$_ = localtime($ftime);
/^(...) (...) ([ \d]\d) (\d\d:\d\d):\d\d (\d\d\d\d)$/;
if ($ftime + 6 * 30 * 24 * 60 * 60 < $now ||
$ftime + 60 * 60 > $now) {
return "$2 $3 $5";
} else {
return "$2 $3 $4";
}
}
} elsif (eval "require Date::Manip") {
import Date::Manip;
$parse_date=
sub {
return UnixDate($_[0], "%l"); # "ls -l" format
}
} elsif (eval "require Date::Parse") {
import Date::Parse;
$parse_date=
sub {
local $_ =localtime(str2time($_[0],$TZ));
s/^... (.+) (\d\d:\d\d):\d\d (\d\d\d\d)$/$1 $3 $2/;
return $_;
}
} else { # use "light" version
$parse_date= sub {
local $mstring='GeeJanFebMarAprMayJunJulAugSepOctNovDec';
# assumes something like: Mon, 5 Jan 1998 16:08:19 +0200 (GMT+0200)
# if you have mails with another date format, add it here
if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d?:\d\d)/) {
return "$2 $1 $3 $4";
if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d?):(\d\d)/) {
$day = $1;
$month = $2;
$mon = index($mstring,$month) / 3;
$year = $3;
$hour = $4;
$min = $5;
# pass time not year for files younger than roughly 6 months
# but not for files with dates more than 1-2 hours in the future
if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
$year * 12 + $mon <= $thisyear * 12 + $thismon &&
! (($year * 12 + $mon) * 31 + $day ==
($thisyear * 12 + $thismon) * 31 + $thisday &&
$hour > $thishour + 2)) {
return "$month $day $hour:$min";
} else {
return "$month $day $year";
}
}
# Y2K bug.
# Date: Mon, 27 Mar 100 16:30:47 +0000 (GMT)
if (/(\d\d?) ([A-Z][a-z][a-z]) (1?\d\d) (\d\d?:\d\d)/) {
$correct_year = 1900 + $3;
if ($correct_year < 1970) {
$correct_year += 100;
if (/(\d\d?) ([A-Z][a-z][a-z]) (1?\d\d) (\d\d?):(\d\d)/) {
$day = $1;
$month = $2;
$mon = index($mstring,$month) / 3;
$year = 1900 + $3;
$hour = $4;
$min = $5;
if ($year < 1970) {
$year += 100;
}
if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
$year * 12 + $mon <= $thisyear * 12 + $thismon &&
! (($year * 12 + $mon) * 31 + $day ==
($thisyear * 12 + $thismon) * 31 + $thisday &&
$hour > $thishour + 2)) {
return "$month $day $hour:$min";
} else {
return "$month $day $year";
}
return "$2 $1 $correct_year $4";
}
# AOLMail(SM).
# Date: Sat Jul 01 10:06:06 2000
if (/([A-Z][a-z][a-z]) (\d\d?) (\d\d?:\d\d)(:\d\d)? (\d\d\d\d)/) {
return "$1 $2 $5 $3";
if (/([A-Z][a-z][a-z]) (\d\d?) (\d\d?):(\d\d)(:\d\d)? (\d\d\d\d)/) {
$month = $1;
$mon = index($mstring,$month) / 3;
$day = $2;
$hour = $3;
$min = $4;
$year = $6;
if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
$year * 12 + $mon <= $thisyear * 12 + $thismon &&
! (($year * 12 + $mon) * 31 + $day ==
($thisyear * 12 + $thismon) * 31 + $thisday &&
$hour > $thishour + 2)) {
return "$month $day $hour:$min";
} else {
return "$month $day $year";
}
}
# Fallback
return localtime(time);
return $fallback;
}
}
@ -56,15 +106,15 @@ sub process_header {
s/\r$//;
last if /^$/;
die "unexpected EOF\n" if eof;
if (/^Date:\s(.*)$/) {
if (/^date:\s(.*)$/i) {
$date=&$parse_date($1);
} elsif (/^Subject:\s(.*)$/) {
} elsif (/^subject:\s(.*)$/i) {
$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+)\@/) {
} elsif (/^from:\s.*?(\w+)\@/i) {
$from=$1;
} elsif (/^To:\s.*?(\w+)\@/) {
} elsif (/^to:\s.*?(\w+)\@/i) {
$to=lc($1);
}
}
@ -84,7 +134,7 @@ sub mailfs_list {
while(<IN>) {
s/\r$//;
if($blank && /^From /) { # Start of header
if($blank && /^from\s+\w+(\.\w+)*@/i) { # Start of header
print_dir_line unless (!$msg_nr);
$size=length;
$msg_nr++;
@ -109,7 +159,7 @@ sub mailfs_copyout {
my $blank = 1;
while(<IN>) {
s/\r$//;
if($blank && /^From /) {
if($blank && /^from\s+\w+(\.\w+)*@/i) {
$msg_nr++;
exit(0) if ($msg_nr > $nr);
$blank= 0;
@ -138,9 +188,16 @@ if (/gzip/) {
umask 077;
if($cmd eq "list") { &mailfs_list; exit 0; }
if($cmd eq "list") {
$now = time;
$_ = localtime($now);
/^... (... [ \d]\d \d\d:\d\d):\d\d \d\d\d\d$/;
$fallback = $1;
$nowstring=`date "+%Y %m %d %H"`;
($thisyear, $thismon, $thisday, $thishour) = split(/ /, $nowstring);
&mailfs_list;
exit 0;
}
elsif($cmd eq "copyout") { &mailfs_copyout(@ARGV); exit 0; }
exit 1;