X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=scripts%2Fimport_vger_from_mbox;h=0e5ba6b47b73fc0994f99f1dab6669329d74cd28;hb=95bdac7f09c69036efed537a4d03d5bdd2ae4eb6;hp=6a00fae3fa5ff4414d9dbc2007400c09be606d70;hpb=fe99e1e4900b5fbe8da4aef25bb0dd05eacb25a3;p=public-inbox.git diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox index 6a00fae3..0e5ba6b4 100644 --- a/scripts/import_vger_from_mbox +++ b/scripts/import_vger_from_mbox @@ -1,13 +1,13 @@ #!/usr/bin/perl -w -# Copyright (C) 2016-2018 all contributors +# Copyright (C) 2016-2020 all contributors # License: AGPL-3.0+ use strict; use warnings; use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; use PublicInbox::MIME; -use PublicInbox::Inbox; -use PublicInbox::V2Writable; +use PublicInbox::InboxWritable; use PublicInbox::Import; +use PublicInbox::MDA; my $usage = "usage: $0 NAME EMAIL DIR $mainrepo, + inboxdir => $inboxdir, name => $name, version => $version, - -primary_address => $email, + 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); + require PublicInbox::V2Writable; + 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), $inboxdir) == 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; - $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 = )) { - 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);