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] scripts/import_slrnspool: new incremental importer
Date: Sun, 11 Jan 2015 04:32:21 +0000	[thread overview]
Message-ID: <20150111043221.GA24712@dcvr.yhbt.net> (raw)

This allows incremental imports of slrn spools, ideal for
tracking lists via gmane.
---
 scripts/import_slrnspool | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100755 scripts/import_slrnspool

diff --git a/scripts/import_slrnspool b/scripts/import_slrnspool
new file mode 100755
index 0000000..560c08c
--- /dev/null
+++ b/scripts/import_slrnspool
@@ -0,0 +1,69 @@
+#!/usr/bin/perl -w
+# Copyright (C) 2015, all contributors <meta@public-inbox.org>
+# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+#
+# Incremental (or one-shot) importer of a slrnpull news spool
+=begin usage
+	export ORIGINAL_RECIPIENT=address@example.com
+	public-inbox-init $LISTNAME $GIT_DIR $HTTP_URL $ORIGINAL_RECIPIENT
+	./import_slrnspool SLRNPULL_ROOT/news/foo/bar
+=cut
+use strict;
+use warnings;
+use PublicInbox::Config;
+use Email::Filter;
+use Email::LocalDelivery;
+sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) }
+my $spool = shift @ARGV or die usage();
+my $recipient = $ENV{ORIGINAL_RECIPIENT};
+defined $recipient or die usage();
+my @mda = qw(public-inbox-mda);
+my $config = PublicInbox::Config->new;
+my $cfg = $config->lookup($recipient);
+defined $cfg or exit(1);
+use Data::Dumper; print STDERR Dumper($cfg);
+
+sub get_min {
+	my ($cfg) = @_;
+	$cfg->{importslrnspoolstate} || 1
+}
+
+sub set_min {
+	my ($cfg, $num) = @_;
+	my $f = PublicInbox::Config->default_file;
+	my @cmd = (qw/git config/, "--file=$f",
+		   "publicinbox.$cfg->{listname}.importslrnspoolstate", $num);
+	system(@cmd) == 0 or die join(' ', @cmd). " failed: $?\n";
+}
+
+my $n = get_min();
+my $ok;
+my $max_gap = 10000;
+my $max = $n + $max_gap;
+
+for (; $n < $max; $n++) {
+	my $fn = "$spool/$n";
+	print STDERR $fn, "\n";
+	open(my $fh, '<', $fn) or next;
+	$max = $n + $max_gap;
+	my $f = Email::Filter->new(data => eval { local $/; <$fh> });
+	my $s = $f->simple;
+
+	# gmane rewrites Received headers, which increases spamminess
+	my @h = $s->header('Original-Received');
+	if (@h) {
+		$s->header_set('Received', @h);
+		$s->header_set('Original-Received');
+	}
+
+	# triggers for the SA HEADER_SPAM rule
+	foreach my $drop (qw(Approved)) { $s->header_set($drop) }
+
+	# appears to be an old gmane bug:
+	$s->header_set('connect()');
+
+	$f->exit(0);
+	$f->pipe(@mda);
+	$ok = $n + 1;
+	set_min($cfg, $ok);
+}
-- 
EW

                 reply	other threads:[~2015-01-11  4:32 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=20150111043221.GA24712@dcvr.yhbt.net \
    --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).