about summary refs log tree commit homepage
path: root/scripts
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-20 21:00:00 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-20 21:01:35 +0000
commit54590383027a67d11953690cbb6390347757730b (patch)
tree7d004c6a71a4abaad25acf10cba841777e157775 /scripts
parentbaae46ba22d283706dd821bea19aa9d985d0081d (diff)
downloadpublic-inbox-54590383027a67d11953690cbb6390347757730b.tar.gz
This will make it easier to as well as supporting future
Filter API users.  It allows simplifying our ad-hoc
import_vger_from_mbox script.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/import_vger_from_mbox51
1 files changed, 6 insertions, 45 deletions
diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox
index 1edb987a..369dac79 100644
--- a/scripts/import_vger_from_mbox
+++ b/scripts/import_vger_from_mbox
@@ -5,7 +5,7 @@ use strict;
 use warnings;
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use PublicInbox::MIME;
-use PublicInbox::Inbox;
+use PublicInbox::InboxWritable;
 use PublicInbox::V2Writable;
 use PublicInbox::Import;
 use PublicInbox::MDA;
@@ -30,55 +30,16 @@ my $ibx = {
         name => $name,
         version => $version,
         -primary_address => $email,
+        filter => 'PublicInbox::Filter::Vger',
 };
 $ibx = PublicInbox::Inbox->new($ibx);
-my $im;
 unless ($dry_run) {
         if ($version >= 2) {
-                $im = PublicInbox::V2Writable->new($ibx, 1);
+                PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0);
         } else {
-                system(qw(git init --bare -q), $mainrepo);
-                my $git = PublicInbox::Git->new($mainrepo);
-                $im = PublicInbox::Import->new($git, $name, $email, $ibx);
+                system(qw(git init --bare -q), $mainrepo) == 0 or die;
         }
 }
+$ibx = PublicInbox::InboxWritable->new($ibx);
 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;
-        my $mime = PublicInbox::MIME->new($msg);
-        if ($variant eq 'mboxrd') {
-                $$msg =~ s/^>(>*From )/$1/sm;
-        } elsif ($variant eq 'mboxo') {
-                $$msg =~ s/^>From /From /sm;
-        }
-        $mime = $vger->scrub($mime);
-        return unless $im;
-        $mime->header_set($_) foreach @PublicInbox::MDA::BAD_HEADERS;
-        $im->add($mime) or
-                warn "duplicate: ",
-                        $mime->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 if $im;
+$ibx->import_mbox(\*STDIN, $variant);