2 # Copyright (C) 2014, Eric Wong <e@80x24.org> and all contributors
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # Script to import a Maildir into a public-inbox
7 export GIT_DIR=/path/to/your/repo.git
8 export GIT_AUTHOR_EMAIL='list@example.com'
9 export GIT_AUTHOR_NAME='list name'
10 ./import_maildir /path/to/maildir/
14 use Date::Parse qw/str2time/;
17 use PublicInbox::Import;
18 sub usage { "Usage:\n".join('', grep(/\t/, `head -n 24 $0`)) }
19 my $dir = shift @ARGV or die usage();
20 my $git_dir = `git rev-parse --git-dir`;
22 foreach my $sub (qw(cur new tmp)) {
23 -d "$dir/$sub" or die "$dir is not a Maildir (missing $sub)\n";
27 foreach my $sub (qw(cur new)) {
28 foreach my $fn (glob("$dir/$sub/*")) {
29 open my $fh, '<', $fn or next;
30 my $s = PublicInbox::Eml->new(do { local $/; <$fh> });
31 my $date = $s->header('Date');
32 my $t = eval { str2time($date) };
34 my @fn = split(m!/!, $fn);
35 push @msgs, [ $t, "$sub/" . pop @fn, $date ];
39 my $git = PublicInbox::Git->new($git_dir);
40 chomp(my $name = `git config user.name`);
41 chomp(my $email = `git config user.email`);
42 my $im = PublicInbox::Import->new($git, $name, $email);
43 @msgs = sort { $b->[0] <=> $a->[0] } @msgs;
44 while (my $ary = pop @msgs) {
45 my $fn = "$dir/$ary->[1]";
46 open my $fh, '<', $fn or next;
47 my $mime = PublicInbox::Eml->new(do { local $/; <$fh> });