#!/usr/bin/perl
#
# Mlist folder [dir]
#
# Produce a list of the messages (i.e., subdirectories) of the given
# folder ($HOME/M/in by default), and a list of the number of mail
# messages (i.e., files whose names end with a digit) in each.
#

$folder = $ARGV[0] || "in";
$foldir = $ARGV[1] || "$ENV{'HOME'}/M";
$dir = "$foldir/$folder";

for $x (<$dir/*[0-9]>) {
	$mrk = '-';
	$frm = &line1("${x}f",'?');
	$sbj = &line1("${x}s",'?');
	($fil = $x) =~ s'.*/'';
	$mrk = '+' if (-f "${x}x");

	print "$mrk$fil $frm $sbj\n" if $fil;
}
exit 0;

sub line1 {
	local($f,$l) = @_;
	if (open(F,"<$f")) {
		$l = <F>;
		close F;
		$l =~ s/\s+$//;
	}
	return $l;
}
