2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 Ancient script to import a Maildir into a v1 public-inbox
7 # this is only if you want a v1 inbox
8 export GIT_DIR=/path/to/your/repo.git
9 export GIT_AUTHOR_EMAIL='list@example.com'
10 export GIT_AUTHOR_NAME='list name'
11 ./import_maildir /path/to/maildir/
13 For v2 (strongly recommended), use:
15 lei convert /path/to/maildir -o /path/to/v2-inbox
16 # (and `lei daemon-kill' if you don't want the daemon to linger)
19 use Date
::Parse qw
/str2time/;
22 use PublicInbox
::Import
;
24 open my $fh, '<', __FILE__
;
25 ("Usage:\n", grep { /^=begin usage/../^=cut/ and !/^=/m } <$fh>);
27 my $dir = shift @ARGV or die usage
();
28 my $git_dir = `git rev-parse --git-dir`;
30 foreach my $sub (qw(cur new tmp)) {
31 -d
"$dir/$sub" or die "$dir is not a Maildir (missing $sub)\n";
35 foreach my $sub (qw(cur new)) {
36 foreach my $fn (glob("$dir/$sub/*")) {
37 open my $fh, '<', $fn or next;
38 my $s = PublicInbox
::Eml
->new(do { local $/; <$fh> });
39 my $date = $s->header('Date');
40 my $t = eval { str2time
($date) };
42 my @fn = split(m!/!, $fn);
43 push @msgs, [ $t, "$sub/" . pop @fn, $date ];
47 my $git = PublicInbox
::Git
->new($git_dir);
48 chomp(my $name = `git config user.name`);
49 chomp(my $email = `git config user.email`);
50 my $im = PublicInbox
::Import
->new($git, $name, $email);
51 @msgs = sort { $b->[0] <=> $a->[0] } @msgs;
52 while (my $ary = pop @msgs) {
53 my $fn = "$dir/$ary->[1]";
54 open my $fh, '<', $fn or next;
55 my $mime = PublicInbox
::Eml
->new(do { local $/; <$fh> });