* extfs/mailfs (parse_date): Workaround for Y2K bugs. Support

for dates found in AOLMail(SM) messages. Provide a fallback if
cannot parse the date.
(process_header): Typo fix. Use s instead of space in regular
expressions.
This commit is contained in:
Pavel Roskin 2001-02-11 07:10:49 +00:00
parent 4c7f17ce21
commit 27d7ebd2a3
2 changed files with 31 additions and 7 deletions

View File

@ -1,3 +1,11 @@
2001-02-11 Pavel Roskin <proski@gnu.org>
* extfs/mailfs (parse_date): Workaround for Y2K bugs. Support
for dates found in AOLMail(SM) messages. Provide a fallback if
cannot parse the date.
(process_header): Typo fix. Use \s instead of space in regular
expressions.
2001-02-10 Pavel Roskin <proski@gnu.org>
* extfs/uzip.in: Preserve permissions of FAT and NTFS archives,

View File

@ -20,25 +20,41 @@ if (eval "require Date::Parse") { # fancy date parsing available?
$parse_date= sub {
# 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):\d\d/) {
if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d?:\d\d)/) {
return "$2 $1 $3 $4";
}
# 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 < 2000) {
$correct_year += 100;
}
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";
}
# Fallback
return "Jan 1 1980 00:00";
}
}
sub process_header {
while (<IN>) {
last if /^$/;
die "unexpeced EOF\n" if eof;
if (/^Date: (.*)$/) {
die "unexpected EOF\n" if eof;
if (/^Date:\s(.*)$/) {
$date=&$parse_date($1);
} elsif (/^Subject: (.*)$/) {
} elsif (/^Subject:\s(.*)$/) {
$subj=$1;
$subj=~ s/^(re: ?)+//gi; # no leading Re:
$subj=~ s/^(re:\s?)+//gi; # no leading Re:
$subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters
} elsif (/^From: .*?(\w+)\@/) {
} elsif (/^From:\s.*?(\w+)\@/) {
$from=$1;
} elsif (/^To: .*?(\w+)\@/) {
} elsif (/^To:\s.*?(\w+)\@/) {
$to=$1;
}
}