2002-12-11 23:57:00 +03:00
|
|
|
#! @PERL@ -w
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-12-14 23:05:29 +03:00
|
|
|
use bytes;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
# MC extfs for (possibly compressed) Berkeley style mailbox files
|
|
|
|
# Peter Daum <gator@cs.tu-berlin.de> (Jan 1998, mc-4.1.24)
|
|
|
|
|
|
|
|
$zcat="zcat"; # gunzip to stdout
|
|
|
|
$bzcat="bzip2 -dc"; # bunzip2 to stdout
|
|
|
|
$file="file"; # "file" command
|
|
|
|
$TZ='GMT'; # default timezone (for Date module)
|
|
|
|
|
2002-12-11 22:10:05 +03:00
|
|
|
if (eval "require Date::Manip") {
|
|
|
|
import Date::Manip;
|
2002-12-14 23:05:29 +03:00
|
|
|
$parse_date=
|
2002-12-11 22:10:05 +03:00
|
|
|
sub {
|
|
|
|
return UnixDate($_[0], "%l"); # "ls -l" format
|
|
|
|
}
|
|
|
|
} elsif (eval "require Date::Parse") {
|
1998-02-27 07:54:42 +03:00
|
|
|
import Date::Parse;
|
2002-12-14 23:05:29 +03:00
|
|
|
$parse_date=
|
1998-02-27 07:54:42 +03:00
|
|
|
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 {
|
|
|
|
# assumes something like: Mon, 5 Jan 1998 16:08:19 +0200 (GMT+0200)
|
|
|
|
# if you have mails with another date format, add it here
|
2001-02-11 10:10:49 +03:00
|
|
|
if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d?:\d\d)/) {
|
1998-02-27 07:54:42 +03:00
|
|
|
return "$2 $1 $3 $4";
|
|
|
|
}
|
2001-02-11 10:10:49 +03:00
|
|
|
# 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;
|
2001-02-19 21:42:12 +03:00
|
|
|
if ($correct_year < 1970) {
|
2001-02-11 10:10:49 +03:00
|
|
|
$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
|
2002-12-14 23:05:29 +03:00
|
|
|
return localtime(time);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process_header {
|
|
|
|
while (<IN>) {
|
2002-12-14 23:05:29 +03:00
|
|
|
$size+=length;
|
2001-07-10 00:07:43 +04:00
|
|
|
s/\r$//;
|
1998-02-27 07:54:42 +03:00
|
|
|
last if /^$/;
|
2001-02-11 10:10:49 +03:00
|
|
|
die "unexpected EOF\n" if eof;
|
|
|
|
if (/^Date:\s(.*)$/) {
|
1998-02-27 07:54:42 +03:00
|
|
|
$date=&$parse_date($1);
|
2001-02-11 10:10:49 +03:00
|
|
|
} elsif (/^Subject:\s(.*)$/) {
|
2002-12-14 23:05:29 +03:00
|
|
|
$subj=lc($1);
|
2001-02-11 10:10:49 +03:00
|
|
|
$subj=~ s/^(re:\s?)+//gi; # no leading Re:
|
1998-02-27 07:54:42 +03:00
|
|
|
$subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters
|
2001-02-11 10:10:49 +03:00
|
|
|
} elsif (/^From:\s.*?(\w+)\@/) {
|
1998-02-27 07:54:42 +03:00
|
|
|
$from=$1;
|
2001-02-11 10:10:49 +03:00
|
|
|
} elsif (/^To:\s.*?(\w+)\@/) {
|
2002-12-14 23:05:29 +03:00
|
|
|
$to=lc($1);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_dir_line {
|
|
|
|
$from=$to if ($from eq $user); # otherwise, it would look pretty boring
|
2002-12-14 23:05:29 +03:00
|
|
|
$date=localtime(time) if (!defined $date);
|
|
|
|
printf "-r-------- 1 $< $< %d %s %3.3d_%.25s\n",
|
|
|
|
$size, $date, $msg_nr, "${from}_${subj}";
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sub mailfs_list {
|
|
|
|
my $blank = 1;
|
|
|
|
$user=$ENV{USER}||getlogin||getpwuid($<) || "nobody";
|
2002-12-14 23:05:29 +03:00
|
|
|
|
|
|
|
while(<IN>) {
|
2002-12-11 22:10:05 +03:00
|
|
|
s/\r$//;
|
1998-02-27 07:54:42 +03:00
|
|
|
if($blank && /^From /) { # Start of header
|
|
|
|
print_dir_line unless (!$msg_nr);
|
2002-12-14 23:05:29 +03:00
|
|
|
$size=length;
|
1998-02-27 07:54:42 +03:00
|
|
|
$msg_nr++;
|
|
|
|
($from,$to,$subj,$date)=("none","none","none", "01-01-80");
|
|
|
|
process_header;
|
2002-12-14 23:05:29 +03:00
|
|
|
$line=$blank=0;
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
2002-12-14 23:05:29 +03:00
|
|
|
$size+=length;
|
1998-02-27 07:54:42 +03:00
|
|
|
$line++;
|
|
|
|
$blank= /^$/;
|
|
|
|
}
|
|
|
|
}
|
2002-12-14 23:05:29 +03:00
|
|
|
print_dir_line unless (!$msg_nr);
|
|
|
|
exit 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sub mailfs_copyout {
|
|
|
|
my($source,$dest)=@_;
|
|
|
|
exit 1 unless (open STDOUT, ">$dest");
|
|
|
|
($nr)= ($source =~ /^(\d+)/); # extract message number from "filename"
|
2002-12-14 23:05:29 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
my $blank = 1;
|
|
|
|
while(<IN>) {
|
2001-07-10 00:07:43 +04:00
|
|
|
s/\r$//;
|
1998-02-27 07:54:42 +03:00
|
|
|
if($blank && /^From /) {
|
|
|
|
$msg_nr++;
|
|
|
|
exit(0) if ($msg_nr > $nr);
|
|
|
|
$blank= 0;
|
|
|
|
} else {
|
|
|
|
$blank= /^$/;
|
|
|
|
}
|
|
|
|
print if ($msg_nr == $nr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# main {
|
2002-12-14 23:05:29 +03:00
|
|
|
exit 1 unless ($#ARGV >= 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
$msg_nr=0;
|
|
|
|
$cmd=shift;
|
|
|
|
$mbox_name=shift;
|
2002-12-24 09:56:16 +03:00
|
|
|
my $mbox_qname = quotemeta ($mbox_name);
|
|
|
|
$_=`$file $mbox_qname`;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (/gzip/) {
|
2002-12-24 09:56:16 +03:00
|
|
|
exit 1 unless (open IN, "$zcat $mbox_qname|");
|
1998-02-27 07:54:42 +03:00
|
|
|
} elsif (/bzip/) {
|
2002-12-24 09:56:16 +03:00
|
|
|
exit 1 unless (open IN, "$bzcat $mbox_qname|");
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
|
|
|
exit 1 unless (open IN, "<$mbox_name");
|
|
|
|
}
|
|
|
|
|
1998-12-16 09:16:13 +03:00
|
|
|
umask 077;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if($cmd eq "list") { &mailfs_list; exit 0; }
|
|
|
|
elsif($cmd eq "copyout") { &mailfs_copyout(@ARGV); exit 0; }
|
|
|
|
|
|
|
|
exit 1;
|
|
|
|
|
|
|
|
|