user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] add scripts/xhdr-num2mid example
Date: Thu, 28 Jul 2016 22:01:45 +0000	[thread overview]
Message-ID: <20160728220145.13024-1-e@80x24.org> (raw)

This is used to quickly generate an article number to Message-ID
mapping.

Usage:

NNTPSERVER=news.example.org ./scripts/xhdr-num2mid GROUP >file
---
 MANIFEST             |  1 +
 scripts/xhdr-num2mid | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100755 scripts/xhdr-num2mid

diff --git a/MANIFEST b/MANIFEST
index 297301d..308da06 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -102,6 +102,7 @@ scripts/import_vger_from_mbox
 scripts/report-spam
 scripts/slrnspool2maildir
 scripts/ssoma-replay
+scripts/xhdr-num2mid
 t/address.t
 t/cgi.t
 t/check-www-inbox.perl
diff --git a/scripts/xhdr-num2mid b/scripts/xhdr-num2mid
new file mode 100755
index 0000000..f1e7ea3
--- /dev/null
+++ b/scripts/xhdr-num2mid
@@ -0,0 +1,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";
+	}
+}
-- 
EW


                 reply	other threads:[~2016-07-28 22:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160728220145.13024-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).