2 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
8 use PublicInbox::Inbox;
9 use PublicInbox::V2Writable;
10 use PublicInbox::Import;
11 my $usage = "usage: $0 NAME EMAIL DIR <MBOX\n";
14 my $variant = 'mboxrd';
16 'n|dry-run' => \$dry_run,
17 'V|version=i' => \$version,
18 'F|format=s' => \$variant,
20 GetOptions(%opts) or die $usage;
21 if ($variant ne 'mboxrd' && $variant ne 'mboxo') {
22 die "Unsupported mbox variant: $variant\n";
24 my $name = shift or die $usage; # git
25 my $email = shift or die $usage; # git@vger.kernel.org
26 my $mainrepo = shift or die $usage; # /path/to/v2/repo
28 mainrepo => $mainrepo,
31 -primary_address => $email,
33 $ibx = PublicInbox::Inbox->new($ibx);
37 $im = PublicInbox::V2Writable->new($ibx, 1);
39 system(qw(git init --bare -q), $mainrepo);
40 my $git = PublicInbox::Git->new($mainrepo);
41 $im = PublicInbox::Import->new($git, $name, $email, $ibx);
46 use PublicInbox::Filter::Vger;
47 my $vger = PublicInbox::Filter::Vger->new;
51 $$msg =~ s/(\r?\n)+\z/$1/s;
52 my $mime = PublicInbox::MIME->new($msg);
53 if ($variant eq 'mboxrd') {
54 $$msg =~ s/^>(>*From )/$1/sm;
55 } elsif ($variant eq 'mboxo') {
56 $$msg =~ s/^>From /From /sm;
58 $mime = $vger->scrub($mime);
62 $mime->header_obj->header_raw('Message-ID'), "\n";
65 # asctime: From example@example.com Fri Jun 23 02:56:55 2000
66 my $from_strict = qr/^From \S+ +\S+ \S+ +\S+ [^:]+:[^:]+:[^:]+ [^:]+/;
68 while (defined(my $l = <STDIN>)) {
69 if ($l =~ /$from_strict/o) {
70 if (!defined($prev) || $prev =~ /^\r?$/) {
71 do_add($im, \$msg) if $msg;
81 do_add($im, \$msg) if $msg;