5 # MC extfs for (possibly compressed) Berkeley style mailbox files
6 # Peter Daum <gator@cs.tu-berlin.de> (Jan 1998, mc-4.1.24)
8 $zcat="zcat"; # gunzip to stdout
9 $bzcat="bzip2 -dc"; # bunzip2 to stdout
10 $lzcat="lzma -dc"; # unlzma to stdout
11 $file="file"; # "file" command
12 $TZ='GMT'; # default timezone (for Date module)
14 if (eval "require Date::Parse") {
18 local $ftime = str2time($_[0],$TZ);
19 $_ = localtime($ftime);
20 /^(...) (...) ([ \d]\d) (\d\d:\d\d):\d\d (\d\d\d\d)$/;
21 if ($ftime + 6 * 30 * 24 * 60 * 60 < $now ||
22 $ftime + 60 * 60 > $now) {
28 } elsif (eval "require Date::Manip") {
32 return UnixDate($_[0], "%l"); # "ls -l" format
34 } else { # use "light" version
36 local $mstring='GeeJanFebMarAprMayJunJulAugSepOctNovDec';
37 # assumes something like: Mon, 5 Jan 1998 16:08:19 +0200 (GMT+0200)
38 # if you have mails with another date format, add it here
39 if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d?):(\d\d)/) {
42 $mon = index($mstring,$month) / 3;
46 # pass time not year for files younger than roughly 6 months
47 # but not for files with dates more than 1-2 hours in the future
48 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
49 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
50 ! (($year * 12 + $mon) * 31 + $day ==
51 ($thisyear * 12 + $thismon) * 31 + $thisday &&
52 $hour > $thishour + 2)) {
53 return "$month $day $hour:$min";
55 return "$month $day $year";
59 # Date: Mon, 27 Mar 100 16:30:47 +0000 (GMT)
60 if (/(\d\d?) ([A-Z][a-z][a-z]) (1?\d\d) (\d\d?):(\d\d)/) {
63 $mon = index($mstring,$month) / 3;
70 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
71 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
72 ! (($year * 12 + $mon) * 31 + $day ==
73 ($thisyear * 12 + $thismon) * 31 + $thisday &&
74 $hour > $thishour + 2)) {
75 return "$month $day $hour:$min";
77 return "$month $day $year";
81 # Date: Sat Jul 01 10:06:06 2000
82 if (/([A-Z][a-z][a-z]) (\d\d?) (\d\d?):(\d\d)(:\d\d)? (\d\d\d\d)/) {
84 $mon = index($mstring,$month) / 3;
89 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
90 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
91 ! (($year * 12 + $mon) * 31 + $day ==
92 ($thisyear * 12 + $thismon) * 31 + $thisday &&
93 $hour > $thishour + 2)) {
94 return "$month $day $hour:$min";
96 return "$month $day $year";
109 die "unexpected EOF\n" if eof;
110 if (/^date:\s(.*)$/i) {
111 $date=&$parse_date($1);
112 } elsif (/^subject:\s(.*)$/i) {
114 $subj=~ s/^(re:\s?)+//gi; # no leading Re:
115 $subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters
116 } elsif (/^from:\s.*?(\w+)\@/i) {
118 } elsif (/^to:\s.*?(\w+)\@/i) {
125 $from=$to if ($from eq $user); # otherwise, it would look pretty boring
126 $date=localtime(time) if (!defined $date);
127 printf "-r-------- 1 $< $< %d %s %3.3d_%.25s\n",
128 $size, $date, $msg_nr, "${from}_${subj}";
134 $user=$ENV{USER}||getlogin||getpwuid($<) || "nobody";
138 if($blank && /^from\s+\w+(\.\w+)*@/i) { # Start of header
139 print_dir_line unless (!$msg_nr);
142 ($from,$to,$subj,$date)=("none","none","none", "01-01-80");
151 print_dir_line unless (!$msg_nr);
156 my($source,$dest)=@_;
157 exit 1 unless (open STDOUT, ">$dest");
158 ($nr)= ($source =~ /^(\d+)/); # extract message number from "filename"
163 if($blank && /^from\s+\w+(\.\w+)*@/i) {
165 exit(0) if ($msg_nr > $nr);
170 print if ($msg_nr == $nr);
175 exit 1 unless ($#ARGV >= 1);
179 my $mbox_qname = quotemeta ($mbox_name);
180 $_=`$file $mbox_qname`;
183 exit 1 unless (open IN, "$zcat $mbox_qname|");
185 exit 1 unless (open IN, "$bzcat $mbox_qname|");
187 exit 1 unless (open IN, "$lzcat $mbox_qname|");
189 exit 1 unless (open IN, "<$mbox_name");
196 $_ = localtime($now);
197 /^... (... [ \d]\d \d\d:\d\d):\d\d \d\d\d\d$/;
199 $nowstring=`date "+%Y %m %d %H"`;
200 ($thisyear, $thismon, $thisday, $thishour) = split(/ /, $nowstring);
204 elsif($cmd eq "copyout") { &mailfs_copyout(@ARGV); exit 0; }