3 # MC extfs for (possibly compressed) Berkeley style mailbox files
4 # Peter Daum <gator@cs.tu-berlin.de> (Jan 1998, mc-4.1.24)
6 $zcat="zcat"; # gunzip to stdout
7 $bzcat="bzip2 -dc"; # bunzip2 to stdout
8 $file="file"; # "file" command
9 $TZ='GMT'; # default timezone (for Date module)
11 if (eval "require Date::Parse") { # fancy date parsing available?
15 local $_ =localtime(str2time($_[0],$TZ));
16 s/^... (.+) (\d\d:\d\d):\d\d (\d\d\d\d)$/$1 $3 $2/;
19 } else { # use "light" version
21 # assumes something like: Mon, 5 Jan 1998 16:08:19 +0200 (GMT+0200)
22 # if you have mails with another date format, add it here
23 if (/(\d\d?) ([A-Z][a-z][a-z]) (\d\d\d\d) (\d\d:\d\d):\d\d/) {
32 die "unexpeced EOF\n" if eof;
34 $date=&$parse_date($1);
35 } elsif (/^Subject: (.*)$/) {
37 $subj=~ s/^(re: ?)+//gi; # no leading Re:
38 $subj=~ tr/a-zA-Z0-9//cd; # strip all "special" characters
39 } elsif (/^From: .*?(\w+)\@/) {
41 } elsif (/^To: .*?(\w+)\@/) {
48 $from=$to if ($from eq $user); # otherwise, it would look pretty boring
49 printf "-r-------- 1 $< $< %d %s %3.3d_%.16s\n",
50 $line, $date, $msg_nr, "${from}_${subj}";
55 $user=$ENV{USER}||getlogin||getpwuid($<) || "nobody";
59 if (!defined($_)) { # EOF
63 if($blank && /^From /) { # Start of header
64 print_dir_line unless (!$msg_nr);
66 ($from,$to,$subj,$date)=("none","none","none", "01-01-80");
78 exit 1 unless (open STDOUT, ">$dest");
79 ($nr)= ($source =~ /^(\d+)/); # extract message number from "filename"
83 if($blank && /^From /) {
85 exit(0) if ($msg_nr > $nr);
90 print if ($msg_nr == $nr);
98 $_=`$file $mbox_name`;
101 exit 1 unless (open IN, "$zcat $mbox_name|");
103 exit 1 unless (open IN, "$bzcat $mbox_name|");
105 exit 1 unless (open IN, "<$mbox_name");
110 if($cmd eq "list") { &mailfs_list; exit 0; }
111 elsif($cmd eq "copyout") { &mailfs_copyout(@ARGV); exit 0; }