unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] scripts/import_maildir: rewrite to use Import
Date: Thu, 29 Jun 2017 07:15:03 +0000	[thread overview]
Message-ID: <20170629071503.19876-1-e@80x24.org> (raw)

This will be much faster and invoking -mda for every message.
---
 scripts/import_maildir | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/scripts/import_maildir b/scripts/import_maildir
index c87ca1b..43a8c1a 100755
--- a/scripts/import_maildir
+++ b/scripts/import_maildir
@@ -4,25 +4,22 @@
 #
 # 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 Email::Simple;
 use Date::Parse qw/str2time/;
-use IPC::Run qw/run/;
+use PublicInbox::MIME;
+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 +28,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 = Email::Simple->new(eval { 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::MIME->new(eval { local $/; <$fh> });
+	$im->add($mime);
 }
+$im->done;
 
 1;
-- 
EW


                 reply	other threads:[~2017-06-29  7:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170629071503.19876-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).