X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=scripts%2Fimport_vger_from_mbox;h=c33e42e45c2823e1e87e9a2139fea60efc132468;hb=21fcd8a37c82c1ef654d402cf592f0c9d803aa26;hp=d30e8a3096e10848823e71773bc1bef3be3018aa;hpb=feabfb1809b911fc97538282234c8b1f087ddb6a;p=public-inbox.git diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox index d30e8a30..c33e42e4 100644 --- a/scripts/import_vger_from_mbox +++ b/scripts/import_vger_from_mbox @@ -1,60 +1,44 @@ #!/usr/bin/perl -w -# Copyright (C) 2016-2018 all contributors +# Copyright (C) 2016-2021 all contributors # License: AGPL-3.0+ use strict; use warnings; use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; -use Date::Parse qw/str2time/; -use Email::MIME; -$Email::MIME::ContentType::STRICT_PARAMS = 0; # user input is imperfect -use PublicInbox::Inbox; -use PublicInbox::V2Writable; +use PublicInbox::InboxWritable; my $usage = "usage: $0 NAME EMAIL DIR \$dry_run ); +my $version = 2; +my $variant = 'mboxrd'; +my $filter = 'PublicInbox::Filter::Vger'; +my %opts = ( + 'n|dry-run' => \$dry_run, + 'V|version=i' => \$version, + 'F|format=s' => \$variant, + 'filter=s' => \$filter, +); GetOptions(%opts) or die $usage; +if ($variant ne 'mboxrd' && $variant ne 'mboxo') { + die "Unsupported mbox variant: $variant\n"; +} my $name = shift or die $usage; # git my $email = shift or die $usage; # git@vger.kernel.org -my $mainrepo = shift or die $usage; # /path/to/v2/repo -my $v2ibx = { - mainrepo => $mainrepo, +my $inboxdir = shift or die $usage; # /path/to/v2/repo +my $ibx = { + inboxdir => $inboxdir, name => $name, - version => 2, - -primary_address => $email, + version => $version, + address => [ $email ], + filter => $filter, }; -$v2ibx = PublicInbox::Inbox->new($v2ibx); -my $im = $dry_run ? undef : PublicInbox::V2Writable->new($v2ibx, 1); -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); - return unless $im; - $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 = )) { - if ($l =~ /$from_strict/o) { - if (!defined($prev) || $prev =~ /^\r?$/) { - do_add($im, \$msg) if $msg; - $msg = ''; - $prev = $l; - next; - } - warn "W[$.] $l\n"; +$ibx = PublicInbox::Inbox->new($ibx); +unless ($dry_run) { + if ($version >= 2) { + require PublicInbox::V2Writable; + PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0); + } else { + system(qw(git init --bare -q), $inboxdir) == 0 or die; } - $prev = $l; - $msg .= $l; } -do_add($im, \$msg) if $msg; -$im->done if $im; +$ibx = PublicInbox::InboxWritable->new($ibx); +binmode STDIN; +$ibx->import_mbox(\*STDIN, $variant);