#!/usr/bin/perl
# This program is exceedingly ugly; it's just mdscan modified to leave
# out files in "cur". At the moment, it's the easiest way to achieve
# semi-stability in message numbers.

use strict;
my ($a, $sender, $subject, @senders, @subjects);

format main::STDOUT =
@>>> @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$a, $sender, $subject
.

main: {
    my $maildir = shift @ARGV;
    die "usage: mdscan maildir" unless $maildir;
    chdir $maildir or die "can't chdir to $maildir";

    # Read in file list
    opendir CUR, "./cur" or die "can't open ./cur";
    my @msgs = grep {
	$_ = "./cur/$_"; /^\.\/cur\/[^.]/ && -f "$_"
	} readdir(CUR);
    closedir CUR;
    $a = scalar(@msgs);
    opendir NEW, "./new" or die "can't open ./new";
    @msgs = grep {
	$_ = "./new/$_"; /^\.\/new\/[^.]/ && -f "$_"
	} readdir(NEW);
    closedir NEW;
    @msgs = sort @msgs;

    # Now read out the data
    my $msg;
    foreach $msg (@msgs) {
	$a++;
	$sender  = `822field from < "$msg"`; push @senders, $sender;
	$subject = `822field subject < "$msg"`; push @subjects, $subject;
	write;
    }
}
