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;
12 my $usage = "usage: $0 NAME EMAIL DIR <MBOX\n";
15 my $variant = 'mboxrd';
17 'n|dry-run' => \$dry_run,
18 'V|version=i' => \$version,
19 'F|format=s' => \$variant,
21 GetOptions(%opts) or die $usage;
22 if ($variant ne 'mboxrd' && $variant ne 'mboxo') {
23 die "Unsupported mbox variant: $variant\n";
25 my $name = shift or die $usage; # git
26 my $email = shift or die $usage; # git@vger.kernel.org
27 my $mainrepo = shift or die $usage; # /path/to/v2/repo
29 mainrepo => $mainrepo,
32 -primary_address => $email,
34 $ibx = PublicInbox::Inbox->new($ibx);
38 $im = PublicInbox::V2Writable->new($ibx, 1);
40 system(qw(git init --bare -q), $mainrepo);
41 my $git = PublicInbox::Git->new($mainrepo);
42 $im = PublicInbox::Import->new($git, $name, $email, $ibx);
47 use PublicInbox::Filter::Vger;
48 my $vger = PublicInbox::Filter::Vger->new;
52 $$msg =~ s/(\r?\n)+\z/$1/s;
53 my $mime = PublicInbox::MIME->new($msg);
54 if ($variant eq 'mboxrd') {
55 $$msg =~ s/^>(>*From )/$1/sm;
56 } elsif ($variant eq 'mboxo') {
57 $$msg =~ s/^>From /From /sm;
59 $mime = $vger->scrub($mime);
61 $mime->header_set($_) foreach @PublicInbox::MDA::BAD_HEADERS;
64 $mime->header_obj->header_raw('Message-ID'), "\n";
67 # asctime: From example@example.com Fri Jun 23 02:56:55 2000
68 my $from_strict = qr/^From \S+ +\S+ \S+ +\S+ [^:]+:[^:]+:[^:]+ [^:]+/;
70 while (defined(my $l = <STDIN>)) {
71 if ($l =~ /$from_strict/o) {
72 if (!defined($prev) || $prev =~ /^\r?$/) {
73 do_add($im, \$msg) if $msg;
83 do_add($im, \$msg) if $msg;