6 # MC extfs for (possibly compressed) Berkeley style mailbox files
7 # Peter Daum <gator@cs.tu-berlin.de> (Jan 1998, mc-4.1.24)
9 $zcat="zcat"; # gunzip to stdout
10 $bzcat="bzip2 -dc"; # bunzip2 to stdout
11 $lzipcat="lzip -dc"; # unlzip to stdout
12 $lz4cat="lz4 -dc"; # unlz4 to stdout
13 $lzcat="lzma -dc"; # unlzma to stdout
14 $lzocat="lzop -dc"; # unlzo to stdout
15 $xzcat="xz -dc"; # unxz to stdout
16 $zstdcat="zstd -dc"; # unzstd to stdout
17 $file="file"; # "file" command
18 $TZ='GMT'; # default timezone (for Date module)
20 if (eval "require Date::Parse") {
24 local $ftime = str2time($_[0],$TZ);
25 $_ = localtime($ftime);
26 /^(...) (...) ([ \d]\d) (\d\d:\d\d):\d\d (\d\d\d\d)$/;
27 if ($ftime + 6 * 30 * 24 * 60 * 60 < $now ||
28 $ftime + 60 * 60 > $now) {
34 } elsif (eval "require Date::Manip") {
38 return UnixDate($_[0], "%l"); # "ls -l" format
40 } else { # use "light" version
42 local $mstring='GeeJanFebMarAprMayJunJulAugSepOctNovDec';
43 # assumes something like: Mon, 5 Jan 1998 16:08:19 +0200 (GMT+0200)
44 # if you have mails with another date format, add it here
45 if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d?):(\d\d)/) {
48 $mon = index($mstring,$month) / 3;
52 # pass time not year for files younger than roughly 6 months
53 # but not for files with dates more than 1-2 hours in the future
54 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
55 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
56 ! (($year * 12 + $mon) * 31 + $day ==
57 ($thisyear * 12 + $thismon) * 31 + $thisday &&
58 $hour > $thishour + 2)) {
59 return "$month $day $hour:$min";
61 return "$month $day $year";
65 # Date: Mon, 27 Mar 100 16:30:47 +0000 (GMT)
66 if (/(\d\d?) ([A-Z][a-z][a-z]) (1?\d\d) (\d\d?):(\d\d)/) {
69 $mon = index($mstring,$month) / 3;
76 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
77 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
78 ! (($year * 12 + $mon) * 31 + $day ==
79 ($thisyear * 12 + $thismon) * 31 + $thisday &&
80 $hour > $thishour + 2)) {
81 return "$month $day $hour:$min";
83 return "$month $day $year";
87 # Date: Sat Jul 01 10:06:06 2000
88 if (/([A-Z][a-z][a-z]) (\d\d?) (\d\d?):(\d\d)(:\d\d)? (\d\d\d\d)/) {
90 $mon = index($mstring,$month) / 3;
95 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
96 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
97 ! (($year * 12 + $mon) * 31 + $day ==
98 ($thisyear * 12 + $thismon) * 31 + $thisday &&
99 $hour > $thishour + 2)) {
100 return "$month $day $hour:$min";
102 return "$month $day $year";
115 die "unexpected EOF\n" if eof;
116 if (/^date:\s(.*)$/i) {
117 $date=&$parse_date($1);
118 } elsif (/^subject:\s(.*)$/i) {
120 $subj=~ s/^(re:\s?)+//gi; # no leading Re:
121 $subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters
122 } elsif (/^from:\s.*?(\w+)\@/i) {
124 } elsif (/^to:\s.*?(\w+)\@/i) {
131 $from=$to if ($from eq $user); # otherwise, it would look pretty boring
132 $date=localtime(time) if (!defined $date);
133 printf "-r-------- 1 $< $< %d %s %3.3d_%.25s\n",
134 $size, $date, $msg_nr, "${from}_${subj}";
140 $user=$ENV{USER}||getlogin||getpwuid($<) || "nobody";
144 if($blank && /^from\s+\w+(\.\w+)*@/i) { # Start of header
145 print_dir_line unless (!$msg_nr);
148 ($from,$to,$subj,$date)=("none","none","none", "01-01-80");
157 print_dir_line unless (!$msg_nr);
162 my($source,$dest)=@_;
163 exit 1 unless (open STDOUT, ">$dest");
164 ($nr)= ($source =~ /^(\d+)/); # extract message number from "filename"
169 if($blank && /^from\s+\w+(\.\w+)*@/i) {
171 exit(0) if ($msg_nr > $nr);
176 print if ($msg_nr == $nr);
181 exit 1 unless ($#ARGV >= 1);
185 my $mbox_qname = quotemeta ($mbox_name);
186 $_=`$file $mbox_qname`;
189 exit 1 unless (open IN, "$zcat $mbox_qname|");
191 exit 1 unless (open IN, "$bzcat $mbox_qname|");
193 exit 1 unless (open IN, "$lzipcat $mbox_qname|");
195 exit 1 unless (open IN, "$lz4cat $mbox_qname|");
197 exit 1 unless (open IN, "$lzcat $mbox_qname|");
199 exit 1 unless (open IN, "$lzocat $mbox_qname|");
201 exit 1 unless (open IN, "$xzcat $mbox_qname|");
203 exit 1 unless (open IN, "$zstdcat $mbox_qname|");
205 exit 1 unless (open IN, "<$mbox_name");
212 $_ = localtime($now);
213 /^... (... [ \d]\d \d\d:\d\d):\d\d \d\d\d\d$/;
215 $nowstring=`date "+%Y %m %d %H"`;
216 ($thisyear, $thismon, $thisday, $thishour) = split(/ /, $nowstring);
220 elsif($cmd eq "copyout") { &mailfs_copyout(@ARGV); exit 0; }