about summary refs log tree commit homepage
path: root/scripts/xhdr-num2mid
blob: f1e7ea34e17e179a51c5a88fc99e3796fbe74746 (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
#!/usr/bin/perl -w
# Copyright (C) 2016 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Useful for mapping article IDs from existing NNTP servers to MIDs
use strict;
use warnings;
use Net::NNTP;
use Data::Dumper;
my $usage = "usage: NNTPSERVER=news.example.org $0 GROUP [FIRST_NUM]\n";
my $group = shift or die $usage;
my $nntp = Net::NNTP->new($ENV{NNTPSERVER} || '127.0.0.1');
my ($num, $first, $last) = $nntp->group($group);
die "Invalid group\n" if !(defined $num && defined $first && defined $last);
my $arg_first = shift;
if (defined $arg_first) {
	$arg_first =~ /\A\d+\z/ or die $usage;
	$first = $arg_first;
}

my $batch = 1000;
my $i;
for ($i = $first; $i < $last; $i += $batch) {
	my $j = $i + $batch;
	$j = $last if $j > $last;
	my $num2mid = $nntp->xhdr('Message-ID', "$i-$j");
	for my $n ($i..$j) {
		defined(my $mid = $num2mid->{$n}) or next;
		print "$n $mid\n";
	}
}