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/
15 use Date::Parse qw/str2time/;
16 use PublicInbox::MIME;
18 use PublicInbox::Import;
19 sub usage { "Usage:\n".join('', grep(/\t/, `head -n 24 $0`)) }
20 my $dir = shift @ARGV or die usage();
21 my $git_dir = `git rev-parse --git-dir`;
23 foreach my $sub (qw(cur new tmp)) {
24 -d "$dir/$sub" or die "$dir is not a Maildir (missing $sub)\n";
28 foreach my $sub (qw(cur new)) {
29 foreach my $fn (glob("$dir/$sub/*")) {
30 open my $fh, '<', $fn or next;
31 my $s = Email::Simple->new(eval { local $/; <$fh> });
32 my $date = $s->header('Date');
33 my $t = eval { str2time($date) };
35 my @fn = split(m!/!, $fn);
36 push @msgs, [ $t, "$sub/" . pop @fn, $date ];
40 my $git = PublicInbox::Git->new($git_dir);
41 chomp(my $name = `git config user.name`);
42 chomp(my $email = `git config user.email`);
43 my $im = PublicInbox::Import->new($git, $name, $email);
44 @msgs = sort { $b->[0] <=> $a->[0] } @msgs;
45 while (my $ary = pop @msgs) {
46 my $fn = "$dir/$ary->[1]";
47 open my $fh, '<', $fn or next;
48 my $mime = PublicInbox::MIME->new(eval { local $/; <$fh> });