#!/usr/bin/perl -s $minhdr = 'minhdr -m'; $txt2html = 'webrowse -mqnok 0'; $frmcolor = '#009900'; # header color for sender lines $to_color = '#999900'; # header color for recipient lines $datcolor = '#009999'; # header color for date lines $sbjcolor = '#990099'; # header color for subject lines $txtcolor = '#DDDDDD'; # background color for text attachments $attcolor = '#FF0000'; # listing color for unpresented attachments # mimeindex - create a msg-index.html file in the given directories # Steve Kinzler, kinzler@cs.indiana.edu, Oct 05 # http://www.cs.indiana.edu/~kinzler/home.html#unix $usage = "usage: $0 directory ...\n"; die $usage if $h || ! @ARGV; $mbxre = 'mimebrowse|mbx-\d+-\d'; $txtre = 'txt|html?'; $imgre = 'gif|jpe?g|png|bmp'; chop($wd = `pwd`); foreach $dir (@ARGV) { warn("$0: cannot chdir $dir ($!)\n"), chdir($wd), next unless chdir($dir); warn("$0: cannot opendir $dir/. ($!)\n"), chdir($wd), next unless opendir(DIR, '.'); warn("$0: cannot open $dir/msg-index.html ($!)\n"), close DIR, chdir($wd), next unless open(INDEX, '>msg-index.html'); select INDEX; @files = sort readdir DIR; close DIR; $hdrs = $subj = ''; foreach (grep(/^($mbxre)/, @files)) { warn("$0: cannot run $minhdr ($!)\n"), next unless open(HDR, "$minhdr " . &shencode($_) . '|'); $hdrs .= '

' . &ahref($_) . ''; while () { chop; last if /^$/; $_ = &htmlencode($_); s/^\s+/' ' x 8/e; s/^[-\w]*:/$&<\/B>/; s/^From:.*/&color($frmcolor, $&)/ei; s/^(To|Cc|Bcc):.*/&color($to_color, $&)/ei; s/^Date:.*/&color($datcolor, $&)/ei; s/^Subject:.*/&color($sbjcolor, $&)/ei && ($subj = $&); $hdrs .= "
\n$_"; } $hdrs .= "

\n\n"; close HDR; } $subj =~ s/^\S*\s*//; $subj =~ s/\s*$//; $subj .= ' - ' if $subj ne ''; chop($cwd = &htmlencode(`pwd`)); print < ${subj}mimeindex - $cwd EOF print $hdrs; print '

';
	foreach (`ls -al`) {
		s/( \w\w\w +\d+ +\d+:\d+ )(.*)/$1 . &ahref($2)/e;
		s/.*/&color($attcolor, "$&<\/B>")/e
			unless $2 =~ /^(\.{0,2}$|$mbxre|cid-)/
			    || $2 =~ /\.($txtre|$imgre)$/i;
		print;
	}
	print "

\n\n"; foreach (grep(/\.($txtre)$/i, @files)) { if (/\.txt$/i) { print '

\n
', &ahref($_), "
"; warn("$0: cannot run $txt2html ($!)\n") unless open(TXT, "$txt2html < " . &shencode($_) . '|'); while () { print } close TXT; print "

\n\n"; } else { next if /\bmsg-index\b/i; print '
', &ahref($_), "
\n
\n"; warn("$0: cannot run cat ($!)\n") unless open(HTML, "cat < " . &shencode($_) . '|'); while () { s/\b((src|href)\s*=\s*['"]?cid):/$1-/gi; print; } close HTML; print "
\n\n"; } } foreach (grep(/\.($imgre)$/i, @files)) { $url = &urlencode($_); print "

", &htmlencode($_), "\n", "

\n\n"; } print "\n"; close INDEX; chdir($wd); } ## Subroutines ################################################################ sub ahref { local($_) = join('', @_); '' . &htmlencode($_) . ''; } sub color { local($c) = shift; local($_) = join('', @_); "$_"; } sub urlencode { local($_, $mlm) = (join('', @_), $*); $* = 1; s/[^ \w!\$'()*,\-.]/sprintf('%%%02x', ord $&)/ge; # s/ /+/g; $* = $mlm; $_; } sub htmlencode { local($_, $mlm) = (join('', @_), $*); $* = 1; s/&/&/g; s//>/g; s/"/"/g; $* = $mlm; $_; } sub shencode { local($_, $mlm) = (join('', @_), $*); $* = 1; s/'/'\\''/g; s/^/'/; s/$/'/; $* = $mlm; $_; }