summaryrefslogtreecommitdiffstats
path: root/tools/tools/mid/mid-index
blob: 053c21e8e9594e5f2fc47cc9ec2e80371fddfaca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/local/bin/perl
#
# create message-id / in-reply-to database
#
# $Id: mid-index,v 1.5 1998/04/13 13:08:47 wosch Exp $

sub usage { die "usage: mid-index name < filelist"; }

sub id {
    local($name, @files) = @_;
    local($bytes, $bytes2, $headlen, $file);
    local($counter);
    local($from,$from2);
    
    $counter = 0;
    open(MID, "| sort -u -o $name.mid") || die "open sort > $name.mid: $!\n";
    open(IRT, "| sort -u -o $name.irt") || die "open sort > $name.irt: $!\n";

    while(<>) {
	local($/) = "\n\n";
	chop;
	$file = $_;

	open(R, $file) || do {
	    warn "open $file:$!\n";
	    next;
	};
	$bytes = 0;

	while(<R>) {    
	    $headlen = length($_);
	    $from2 = substr($_, 0, 6);
	    $from =  substr($from2, 0, 5);

	    # warn "xxx" . $from . "yyy\n";
	    if ($from eq "From " || $from2 eq "\nFrom ") {

		if ($from eq "From ") {
		    $bytes2 = $bytes;
		} else {
		    # One bytes more for "\nFrom "
		    $bytes2 = $bytes + 1;
		}

		$counter++;
		s/\n[ \t]+/ /g;
		if ($debug && $counter % $speedstep == 0) {
		    print STDERR sprintf("\r%7d", $counter); 
		}

		foreach (split("\n")) {
		    if (/^Message-id:\s+\<([^$idsep]+)/oi) {
			print MID "$1 $file $bytes2\n";
		    } elsif (/^Resent-Message-id:\s+\<([^$idsep]+)/oi) {
			print MID "$1 $file $bytes2\n";
		    } elsif (/^References:\s+\<([^$idsep]+)/oi) {
			print IRT "$1 $file $bytes2\n";
		    } elsif (/^In-Reply-to:\s+[^<]*\<([^$idsep]+)/oi) {
			print IRT "$1 $file $bytes2\n";
		    }
		}
	     }
             $bytes += $headlen;
	}
	close R;
    }
    close MID || warn "close: MID\n";
    close IRT || warn "close: IRT\n";
    print STDERR sprintf("\r%7d", $counter) 
	if $debug && $counter % $speedstep != 0;
    print STDERR "\n" if $debug;
}

$idsep = '>';
$idsep = '>@\s';
$debug = 0;
$speedstep = 100;

&usage if $#ARGV != 0;
$name = $ARGV[0]; shift @ARGV;
&id($name);


OpenPOWER on IntegriCloud