#!/usr/bin/perl

##  Munge .overview data into something suitable for test data.
##
##  This script isn't used regularly and is here only for the use of INN
##  developers and other people needing to generate more overview test data.
##  It expects overview data but possibly with extra fields at the end, snips
##  off To: data (to avoid putting people's e-mail addresses into INN test
##  data), and if Newsgroups: data is present, rewrites the Xref header to use
##  it instead of keeping the Xref data (this is so that I can use .overview
##  files from Gnus as test data).  It generates overview data but with the
##  newsgroup name and a colon prepended to the article number so that it can
##  be split apart into overview data for multiple groups.
##
##  Please don't include overview information for people's articles into INN's
##  test suite without their permission.
##
##  Written by Russ Allbery in 2004.
##
##  Various bug fixes, code and documentation improvements since then
##  in 2021, 2026.

my %number;
while (<>) {
    s/\s+$//;
    my @data = split /\t/;
    @data = grep { !/^To:/ } @data;
    my $group = pop @data;
    my $xref = pop @data;
    if ($group =~ s/^Newsgroups: //) {
        my @groups = split(/\s*,\s*/, $group);
        for (@groups) {
            $number{$_} = 1 unless $number{$_};
            $data[0] = $_ . ':' . $number{$_}++;
            $number{$_} += int(rand 5) if rand(10) > 8;
            print join("\t", @data, "Xref: inn.example.com $data[0]"), "\n";
        }
    } else {
        $xref =~ s/Xref:\s*\S+\s+//;
        my @xref = split(' ', $xref);
        for (@xref) {
            $data[0] = $_;
            print join("\t", @data, "Xref: inn.example.com $xref"), "\n";
        }
    }
}
