diff options
Diffstat (limited to 'scripts/import_vger_from_mbox')
-rw-r--r-- | scripts/import_vger_from_mbox | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox index 44055ffd..ca5a408d 100644 --- a/scripts/import_vger_from_mbox +++ b/scripts/import_vger_from_mbox @@ -3,45 +3,43 @@ # 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 Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; +use PublicInbox::MIME; +use PublicInbox::InboxWritable; 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); +use PublicInbox::MDA; +my $usage = "usage: $0 NAME EMAIL DIR <MBOX\n"; +my $dry_run; +my $version = 2; +my $variant = 'mboxrd'; +my %opts = ( + 'n|dry-run' => \$dry_run, + 'V|version=i' => \$version, + 'F|format=s' => \$variant, +); +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 $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"; +my $mainrepo = shift or die $usage; # /path/to/v2/repo +my $ibx = { + mainrepo => $mainrepo, + name => $name, + version => $version, + address => [ $email ], + filter => 'PublicInbox::Filter::Vger', +}; +$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), $mainrepo) == 0 or die; } - $prev = $l; - $msg .= $l; } -do_add($im, \$msg) if $msg; -$im->done; +$ibx = PublicInbox::InboxWritable->new($ibx); +binmode STDIN; +$ibx->import_mbox(\*STDIN, $variant); |