#!/usr/bin/perl

use strict;

my(%msgid);

foreach my $fname (@ARGV) {
    unless (open(MSG, $fname)) {
	print(STDERR "couldn't open file '$fname'\n");
    } else {
	my($exit) = 0;
	while ((my $line = <MSG>) and (!$exit)) {
	    chomp($line);
	    if ($line =~ /^Message-ID: <[^>]+>$/i) {
		print ("$fname: ".$msgid{$line}."\n") if ($msgid{$line});
		$msgid{$line} .= ":$fname";
		$exit = 1;
	    }
	    $exit = 1 if ($line =~ /^[\r\n]*$/);
	}
	close(MSG);
    }
}
