X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=scripts%2Fimport_maildir;h=269f2550fc94591d3ed227485154097671c045c0;hb=21fcd8a37c82c1ef654d402cf592f0c9d803aa26;hp=c87ca1b2bb5e49ca38d47b3481f28047c61b8eed;hpb=f850effe0baef8a37ad2eef3ef581b79539cc304;p=public-inbox.git diff --git a/scripts/import_maildir b/scripts/import_maildir index c87ca1b2..269f2550 100755 --- a/scripts/import_maildir +++ b/scripts/import_maildir @@ -1,28 +1,24 @@ #!/usr/bin/perl -w # Copyright (C) 2014, Eric Wong and all contributors -# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) +# License: AGPL-3.0+ # # Script to import a Maildir into a public-inbox =begin usage - mkdir -p $HOME/.public-inbox - MAINREPO=/path/to/your/repo.git - export ORIGINAL_RECIPIENT='list@example.com' - git init --bare $MAINREPO - export GIT_CONFIG=$HOME/.public-inbox/config - git config publicinbox.$INBOX.address $ORIGINAL_RECIPIENT - git config publicinbox.$INBOX.mainrepo $MAINREPO - unset GIT_CONFIG + export GIT_DIR=/path/to/your/repo.git + export GIT_AUTHOR_EMAIL='list@example.com' + export GIT_AUTHOR_NAME='list name' ./import_maildir /path/to/maildir/ =cut use strict; use warnings; -use Email::Filter; use Date::Parse qw/str2time/; -use IPC::Run qw/run/; +use PublicInbox::Eml; +use PublicInbox::Git; +use PublicInbox::Import; sub usage { "Usage:\n".join('', grep(/\t/, `head -n 24 $0`)) } my $dir = shift @ARGV or die usage(); -defined $ENV{ORIGINAL_RECIPIENT} or die usage(); -my @mda = qw(public-inbox-mda); +my $git_dir = `git rev-parse --git-dir`; +chomp $git_dir; foreach my $sub (qw(cur new tmp)) { -d "$dir/$sub" or die "$dir is not a Maildir (missing $sub)\n"; } @@ -31,22 +27,26 @@ my @msgs; foreach my $sub (qw(cur new)) { foreach my $fn (glob("$dir/$sub/*")) { open my $fh, '<', $fn or next; - my $f = Email::Filter->new(data => eval { local $/; <$fh> }); - my $date = $f->simple->header('Date'); + my $s = PublicInbox::Eml->new(do { local $/; <$fh> }); + my $date = $s->header('Date'); my $t = eval { str2time($date) }; - $f->exit(0); - $f->ignore; defined $t or next; my @fn = split(m!/!, $fn); push @msgs, [ $t, "$sub/" . pop @fn, $date ]; } } +my $git = PublicInbox::Git->new($git_dir); +chomp(my $name = `git config user.name`); +chomp(my $email = `git config user.email`); +my $im = PublicInbox::Import->new($git, $name, $email); @msgs = sort { $b->[0] <=> $a->[0] } @msgs; while (my $ary = pop @msgs) { my $fn = "$dir/$ary->[1]"; - local $ENV{GIT_COMMITTER_DATE} = $ary->[2]; # this preserves timezone - run(\@mda, '<', $fn); + open my $fh, '<', $fn or next; + my $mime = PublicInbox::Eml->new(do { local $/; <$fh> }); + $im->add($mime); } +$im->done; 1;