2 # Copyright (C) 2014, Eric Wong <e@80x24.org> and all contributors
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
5 # Script to import a Maildir into a public-inbox
7 mkdir -p $HOME/.public-inbox
8 MAINREPO=/path/to/your/repo.git
9 export ORIGINAL_RECIPIENT='list@example.com'
10 git init --bare $MAINREPO
11 export GIT_CONFIG=$HOME/.public-inbox/config
12 git config publicinbox.$INBOX.address $ORIGINAL_RECIPIENT
13 git config publicinbox.$INBOX.mainrepo $MAINREPO
15 ./import_maildir /path/to/maildir/
20 use Date::Parse qw/str2time/;
22 sub usage { "Usage:\n".join('', grep(/\t/, `head -n 24 $0`)) }
23 my $dir = shift @ARGV or die usage();
24 defined $ENV{ORIGINAL_RECIPIENT} or die usage();
25 my @mda = qw(public-inbox-mda);
26 foreach my $sub (qw(cur new tmp)) {
27 -d "$dir/$sub" or die "$dir is not a Maildir (missing $sub)\n";
31 foreach my $sub (qw(cur new)) {
32 foreach my $fn (glob("$dir/$sub/*")) {
33 open my $fh, '<', $fn or next;
34 my $f = Email::Filter->new(data => eval { local $/; <$fh> });
35 my $date = $f->simple->header('Date');
36 my $t = eval { str2time($date) };
40 my @fn = split(m!/!, $fn);
41 push @msgs, [ $t, "$sub/" . pop @fn, $date ];
45 @msgs = sort { $b->[0] <=> $a->[0] } @msgs;
46 while (my $ary = pop @msgs) {
47 my $fn = "$dir/$ary->[1]";
48 local $ENV{GIT_COMMITTER_DATE} = $ary->[2]; # this preserves timezone