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 script used for importing git from download.gmane.org
Date: Thu, 28 Jul 2016 21:03:02 +0000	[thread overview]
Message-ID: <20160728210302.25130-1-e@80x24.org> (raw)

In case others want to use it...
---
 scripts/import_vger_from_mbox | 47 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 scripts/import_vger_from_mbox

diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox
new file mode 100644
index 0000000..4976e05
--- /dev/null
+++ b/scripts/import_vger_from_mbox
@@ -0,0 +1,47 @@
+#!/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>
+use strict;
+use warnings;
+use Email::MIME;
+$Email::MIME::ContentType::STRICT_PARAMS = 0; # user input is imperfect
+use PublicInbox::Git;
+use PublicInbox::Import;
+my $usage = "usage: $0 NAME EMAIL <MBOX\n";
+chomp(my $git_dir = `git rev-parse --git-dir`);
+my $git = PublicInbox::Git->new($git_dir);
+my $name = shift or die $usage; # git
+my $email = shift or die $usage; # git@vger.kernel.org
+my $im = PublicInbox::Import->new($git, $name, $email);
+binmode STDIN;
+my $msg = '';
+use PublicInbox::Filter::Vger;
+my $vger = PublicInbox::Filter::Vger->new;
+sub do_add ($$) {
+	my ($im, $msg) = @_;
+	$$msg =~ s/(\r?\n)+\z/$1/s;
+	$msg = Email::MIME->new($$msg);
+	$msg = $vger->scrub($msg);
+	$im->add($msg) or
+		warn "duplicate: ",
+			$msg->header_obj->header_raw('Message-ID'), "\n";
+}
+
+# asctime: From example@example.com Fri Jun 23 02:56:55 2000
+my $from_strict = qr/^From \S+ \S+ \S+ +\S+ [^:]+:[^:]+:[^:]+ [^:]+/;
+my $prev = undef;
+while (defined(my $l = <STDIN>)) {
+	if ($l =~ /$from_strict/o) {
+		if (!defined($prev) || $prev =~ /^\r?$/) {
+			do_add($im, \$msg) if $msg;
+			$msg = '';
+			$prev = $l;
+			next;
+		}
+		warn "W[$.] $l\n";
+	}
+	$prev = $l;
+	$msg .= $l;
+}
+do_add($im, \$msg) if $msg;
+$im->done;
-- 
EW


                 reply	other threads:[~2016-07-28 21:03 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=20160728210302.25130-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).