--- index.cgi.orig	2006-07-28 16:30:02.000000000 -0400
+++ index.cgi	2011-08-09 14:49:29.000000000 -0400
@@ -36,8 +36,17 @@
 $prev_month = sprintf("%02d", $prev_month);
 $next_month = sprintf("%02d", $next_month);
 
-@matches = glob ("$year/$month/*/*/index.html");
-@match_list = reverse @matches;
+@matches = glob ("../*/*/index.html");
+my @temparray = ();
+foreach $file (@matches) {
+	my $mtime = (stat($file))[9];
+	my ($day,$mon,$yr) = (localtime($mtime))[3..5];
+	$yr += 1900;
+	$mon++;
+	$name = "$yr/" . sprintf("%02d", $mon) . '/' . sprintf("%02d", $day) . '/' . substr($file,3);
+	push (@temparray, $name) if $name =~ m#^$year/$month#;
+}
+@match_list = reverse sort @temparray;
 
 print $cgi->start_html(
                        -title=>"Detach report for $year/$month");
@@ -51,7 +60,9 @@
 my $last_month="0";
 
 foreach $detach (@match_list) {
-	my ($yr,$mon,$day,$key,$file) = split('/',$detach);
+	my ($yr,$mon,$day,$d1,$d2,$f) = split('/',$detach);
+	my $file = "../$d1/$d2/$f";
+	my $key = "$d1$d2";
 	my ($from, $subject, @detach_file_list);
 
 	# Inject separator as necc.
@@ -76,7 +87,7 @@
 	$last_month = $mon;
 
 	# Scrape the details out of the file.
-	open(DETACH, "$detach");
+	open(DETACH, "$file");
 	while (<DETACH>) {
 		#next unless /^(Subj|<LI>|<HTML>)/;
 		if ($_ =~ m/^<HTML>/)  {
@@ -91,7 +102,7 @@
 	close(DETACH);
 
 	# Print useful data
-	print "<TD class='wd'><A HREF=\"delete.cgi?key=$yr/$mon/$day/$key\">X</A></TD>\n";
+	print "<TD class='wd'><A HREF=\"delete.cgi?key=$key\">X</A></TD>\n";
 	print "<TD class='wd'>$mon/$day/$yr</TD>\n";	
 	print "<TD class='wd'>$from</TD>\n";
 	print "<TD class='wd'>$subject</TD>\n";
@@ -99,6 +110,11 @@
 	print "</TR><TR>\n";
 }
 
-print "</TR></TABLE>\n";
+if (@match_list) {
+	print "</TR></TABLE>\n";
+} else {
+	print "<br />No files found<br />\n";
+	print "<a href=\"index.cgi\">View all files</a><br />\n" if $month ne "*";
+}
 
 print $cgi->end_html();
