about summary refs log tree commit homepage
path: root/scripts
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-07-28 20:44:57 +0000
committerEric Wong <e@80x24.org>2016-07-28 21:02:36 +0000
commitdcba4bf8cc193e22210c91d43fe5eab091bffe06 (patch)
tree08a9eaf4b1cc7baadbb0a444c4c2eeceedb09728 /scripts
parente0b7cf5eb5e6828d07094fa44be67e2d7d63e722 (diff)
downloadpublic-inbox-dcba4bf8cc193e22210c91d43fe5eab091bffe06.tar.gz
In case others want to use it...
Diffstat (limited to 'scripts')
-rw-r--r--scripts/import_vger_from_mbox47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox
new file mode 100644
index 00000000..4976e056
--- /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;