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 $xzcat="xz -dc"; # unxz to stdout
12 $file="file"; # "file" command
13 $TZ='GMT'; # default timezone (for Date module)
15 if (eval "require Date::Parse") {
19 local $ftime = str2time($_[0],$TZ);
20 $_ = localtime($ftime);
21 /^(...) (...) ([ \d]\d) (\d\d:\d\d):\d\d (\d\d\d\d)$/;
22 if ($ftime + 6 * 30 * 24 * 60 * 60 < $now ||
23 $ftime + 60 * 60 > $now) {
29 } elsif (eval "require Date::Manip") {
33 return UnixDate($_[0], "%l"); # "ls -l" format
35 } else { # use "light" version
37 local $mstring='GeeJanFebMarAprMayJunJulAugSepOctNovDec';
38 # assumes something like: Mon, 5 Jan 1998 16:08:19 +0200 (GMT+0200)
39 # if you have mails with another date format, add it here
40 if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d?):(\d\d)/) {
43 $mon = index($mstring,$month) / 3;
47 # pass time not year for files younger than roughly 6 months
48 # but not for files with dates more than 1-2 hours in the future
49 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
50 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
51 ! (($year * 12 + $mon) * 31 + $day ==
52 ($thisyear * 12 + $thismon) * 31 + $thisday &&
53 $hour > $thishour + 2)) {
54 return "$month $day $hour:$min";
56 return "$month $day $year";
60 # Date: Mon, 27 Mar 100 16:30:47 +0000 (GMT)
61 if (/(\d\d?) ([A-Z][a-z][a-z]) (1?\d\d) (\d\d?):(\d\d)/) {
64 $mon = index($mstring,$month) / 3;
71 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
72 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
73 ! (($year * 12 + $mon) * 31 + $day ==
74 ($thisyear * 12 + $thismon) * 31 + $thisday &&
75 $hour > $thishour + 2)) {
76 return "$month $day $hour:$min";
78 return "$month $day $year";
82 # Date: Sat Jul 01 10:06:06 2000
83 if (/([A-Z][a-z][a-z]) (\d\d?) (\d\d?):(\d\d)(:\d\d)? (\d\d\d\d)/) {
85 $mon = index($mstring,$month) / 3;
90 if ($year * 12 + $mon > $thisyear * 12 + $thismon - 7 &&
91 $year * 12 + $mon <= $thisyear * 12 + $thismon &&
92 ! (($year * 12 + $mon) * 31 + $day ==
93 ($thisyear * 12 + $thismon) * 31 + $thisday &&
94 $hour > $thishour + 2)) {
95 return "$month $day $hour:$min";
97 return "$month $day $year";
110 die "unexpected EOF\n" if eof;
111 if (/^date:\s(.*)$/i) {
112 $date=&$parse_date($1);
113 } elsif (/^subject:\s(.*)$/i) {
115 $subj=~ s/^(re:\s?)+//gi; # no leading Re:
116 $subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters
117 } elsif (/^from:\s.*?(\w+)\@/i) {
119 } elsif (/^to:\s.*?(\w+)\@/i) {
126 $from=$to if ($from eq $user); # otherwise, it would look pretty boring
127 $date=localtime(time) if (!defined $date);
128 printf "-r-------- 1 $< $< %d %s %3.3d_%.25s\n",
129 $size, $date, $msg_nr, "${from}_${subj}";
135 $user=$ENV{USER}||getlogin||getpwuid($<) || "nobody";
139 if($blank && /^from\s+\w+(\.\w+)*@/i) { # Start of header
140 print_dir_line unless (!$msg_nr);
143 ($from,$to,$subj,$date)=("none","none","none", "01-01-80");
152 print_dir_line unless (!$msg_nr);
157 my($source,$dest)=@_;
158 exit 1 unless (open STDOUT, ">$dest");
159 ($nr)= ($source =~ /^(\d+)/); # extract message number from "filename"
164 if($blank && /^from\s+\w+(\.\w+)*@/i) {
166 exit(0) if ($msg_nr > $nr);
171 print if ($msg_nr == $nr);
176 exit 1 unless ($#ARGV >= 1);
180 my $mbox_qname = quotemeta ($mbox_name);
181 $_=`$file $mbox_qname`;
184 exit 1 unless (open IN, "$zcat $mbox_qname|");
186 exit 1 unless (open IN, "$bzcat $mbox_qname|");
188 exit 1 unless (open IN, "$lzcat $mbox_qname|");
190 exit 1 unless (open IN, "$xzcat $mbox_qname|");
192 exit 1 unless (open IN, "<$mbox_name");
199 $_ = localtime($now);
200 /^... (... [ \d]\d \d\d:\d\d):\d\d \d\d\d\d$/;
202 $nowstring=`date "+%Y %m %d %H"`;
203 ($thisyear, $thismon, $thisday, $thishour) = split(/ /, $nowstring);
207 elsif($cmd eq "copyout") { &mailfs_copyout(@ARGV); exit 0; }