]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/Import.pm
update and add documentation for repository formats
[public-inbox.git] / lib / PublicInbox / Import.pm
1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 #
4 # git fast-import-based ssoma-mda MDA replacement
5 # This is only ever run by public-inbox-mda and public-inbox-learn,
6 # not the WWW or NNTP code which only requires read-only access.
7 package PublicInbox::Import;
8 use strict;
9 use warnings;
10 use base qw(PublicInbox::Lock);
11 use PublicInbox::Spawn qw(spawn);
12 use PublicInbox::MID qw(mids mid_mime mid2path);
13 use PublicInbox::Address;
14 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
15 use PublicInbox::ContentId qw(content_digest);
16 use PublicInbox::MDA;
17 use POSIX qw(strftime);
18
19 sub new {
20         my ($class, $git, $name, $email, $ibx) = @_;
21         my $ref = 'refs/heads/master';
22         if ($ibx) {
23                 $ref = $ibx->{ref_head} || 'refs/heads/master';
24                 $name ||= $ibx->{name};
25                 $email ||= $ibx->{-primary_address};
26         }
27         bless {
28                 git => $git,
29                 ident => "$name <$email>",
30                 mark => 1,
31                 ref => $ref,
32                 inbox => $ibx,
33                 path_type => '2/38', # or 'v2'
34                 lock_path => "$git->{git_dir}/ssoma.lock", # v2 changes this
35                 bytes_added => 0,
36         }, $class
37 }
38
39 # idempotent start function
40 sub gfi_start {
41         my ($self) = @_;
42
43         return ($self->{in}, $self->{out}) if $self->{pid};
44
45         my ($in_r, $in_w, $out_r, $out_w);
46         pipe($in_r, $in_w) or die "pipe failed: $!";
47         pipe($out_r, $out_w) or die "pipe failed: $!";
48         my $git = $self->{git};
49
50         $self->lock_acquire;
51
52         local $/ = "\n";
53         my $ref = $self->{ref};
54         chomp($self->{tip} = $git->qx(qw(rev-parse --revs-only), $ref));
55         if ($self->{path_type} ne '2/38' && $self->{tip}) {
56                 local $/ = "\0";
57                 my @tree = $git->qx(qw(ls-tree -r -z --name-only), $ref);
58                 chomp @tree;
59                 $self->{-tree} = { map { $_ => 1 } @tree };
60         }
61
62         my $git_dir = $git->{git_dir};
63         my @cmd = ('git', "--git-dir=$git_dir", qw(fast-import
64                         --quiet --done --date-format=raw));
65         my $rdr = { 0 => fileno($out_r), 1 => fileno($in_w) };
66         my $pid = spawn(\@cmd, undef, $rdr);
67         die "spawn fast-import failed: $!" unless defined $pid;
68         $out_w->autoflush(1);
69         $self->{in} = $in_r;
70         $self->{out} = $out_w;
71         $self->{pid} = $pid;
72         $self->{nchg} = 0;
73         binmode $out_w, ':raw' or die "binmode :raw failed: $!";
74         binmode $in_r, ':raw' or die "binmode :raw failed: $!";
75         ($in_r, $out_w);
76 }
77
78 sub wfail () { die "write to fast-import failed: $!" }
79
80 sub now_raw () { time . ' +0000' }
81
82 sub norm_body ($) {
83         my ($mime) = @_;
84         my $b = $mime->body_raw;
85         $b =~ s/(\r?\n)+\z//s;
86         $b
87 }
88
89 # only used for v1 (ssoma) inboxes
90 sub _check_path ($$$$) {
91         my ($r, $w, $tip, $path) = @_;
92         return if $tip eq '';
93         print $w "ls $tip $path\n" or wfail;
94         local $/ = "\n";
95         defined(my $info = <$r>) or die "EOF from fast-import: $!";
96         $info =~ /\Amissing / ? undef : $info;
97 }
98
99 sub _cat_blob ($$$) {
100         my ($r, $w, $oid) = @_;
101         print $w "cat-blob $oid\n" or wfail;
102         local $/ = "\n";
103         my $info = <$r>;
104         defined $info or die "EOF from fast-import / cat-blob: $!";
105         $info =~ /\A[a-f0-9]{40} blob (\d+)\n\z/ or return;
106         my $left = $1;
107         my $offset = 0;
108         my $buf = '';
109         my $n;
110         while ($left > 0) {
111                 $n = read($r, $buf, $left, $offset);
112                 defined($n) or die "read cat-blob failed: $!";
113                 $n == 0 and die 'fast-export (cat-blob) died';
114                 $left -= $n;
115                 $offset += $n;
116         }
117         $n = read($r, my $lf, 1);
118         defined($n) or die "read final byte of cat-blob failed: $!";
119         die "bad read on final byte: <$lf>" if $lf ne "\n";
120
121         # fixup some bugginess in old versions:
122         $buf =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
123         \$buf;
124 }
125
126 sub cat_blob {
127         my ($self, $oid) = @_;
128         my ($r, $w) = $self->gfi_start;
129         _cat_blob($r, $w, $oid);
130 }
131
132 sub check_remove_v1 {
133         my ($r, $w, $tip, $path, $mime) = @_;
134
135         my $info = _check_path($r, $w, $tip, $path) or return ('MISSING',undef);
136         $info =~ m!\A100644 blob ([a-f0-9]{40})\t!s or die "not blob: $info";
137         my $oid = $1;
138         my $msg = _cat_blob($r, $w, $oid) or die "BUG: cat-blob $1 failed";
139         my $cur = PublicInbox::MIME->new($msg);
140         my $cur_s = $cur->header('Subject');
141         $cur_s = '' unless defined $cur_s;
142         my $cur_m = $mime->header('Subject');
143         $cur_m = '' unless defined $cur_m;
144         if ($cur_s ne $cur_m || norm_body($cur) ne norm_body($mime)) {
145                 return ('MISMATCH', $cur);
146         }
147         (undef, $cur);
148 }
149
150 sub checkpoint {
151         my ($self) = @_;
152         return unless $self->{pid};
153         print { $self->{out} } "checkpoint\n" or wfail;
154         undef;
155 }
156
157 sub progress {
158         my ($self, $msg) = @_;
159         return unless $self->{pid};
160         print { $self->{out} } "progress $msg\n" or wfail;
161         $self->{in}->getline eq "progress $msg\n" or die
162                 "progress $msg not received\n";
163         undef;
164 }
165
166 sub _update_git_info ($$) {
167         my ($self, $do_gc) = @_;
168         # for compatibility with existing ssoma installations
169         # we can probably remove this entirely by 2020
170         my $git_dir = $self->{git}->{git_dir};
171         my @cmd = ('git', "--git-dir=$git_dir");
172         my $index = "$git_dir/ssoma.index";
173         if (-e $index && !$ENV{FAST}) {
174                 my $env = { GIT_INDEX_FILE => $index };
175                 run_die([@cmd, qw(read-tree -m -v -i), $self->{ref}], $env);
176         }
177         run_die([@cmd, 'update-server-info'], undef);
178         ($self->{path_type} eq '2/38') and eval {
179                 require PublicInbox::SearchIdx;
180                 my $inbox = $self->{inbox} || $git_dir;
181                 my $s = PublicInbox::SearchIdx->new($inbox);
182                 $s->index_sync({ ref => $self->{ref} });
183         };
184         eval { run_die([@cmd, qw(gc --auto)], undef) } if $do_gc;
185 }
186
187 sub barrier {
188         my ($self) = @_;
189
190         # For safety, we ensure git checkpoint is complete before because
191         # the data in git is still more important than what is in Xapian
192         # in v2.  Performance may be gained by delaying the ->progress
193         # call but we lose safety
194         if ($self->{nchg}) {
195                 $self->checkpoint;
196                 $self->progress('checkpoint');
197                 _update_git_info($self, 0);
198                 $self->{nchg} = 0;
199         }
200 }
201
202 # used for v2
203 sub get_mark {
204         my ($self, $mark) = @_;
205         die "not active\n" unless $self->{pid};
206         my ($r, $w) = $self->gfi_start;
207         print $w "get-mark $mark\n" or wfail;
208         defined(my $oid = <$r>) or die "get-mark failed, need git 2.6.0+\n";
209         chomp($oid);
210         $oid;
211 }
212
213 # returns undef on non-existent
214 # ('MISMATCH', Email::MIME) on mismatch
215 # (:MARK, Email::MIME) on success
216 #
217 # v2 callers should check with Xapian before calling this as
218 # it is not idempotent.
219 sub remove {
220         my ($self, $mime, $msg) = @_; # mime = Email::MIME
221
222         my $path_type = $self->{path_type};
223         my ($path, $err, $cur, $blob);
224
225         my ($r, $w) = $self->gfi_start;
226         my $tip = $self->{tip};
227         if ($path_type eq '2/38') {
228                 $path = mid2path(v1_mid0($mime));
229                 ($err, $cur) = check_remove_v1($r, $w, $tip, $path, $mime);
230                 return ($err, $cur) if $err;
231         } else {
232                 my $sref;
233                 if (ref($mime) eq 'SCALAR') { # optimization used by V2Writable
234                         $sref = $mime;
235                 } else { # XXX should not be necessary:
236                         my $str = $mime->as_string;
237                         $sref = \$str;
238                 }
239                 my $len = length($$sref);
240                 $blob = $self->{mark}++;
241                 print $w "blob\nmark :$blob\ndata $len\n",
242                         $$sref, "\n" or wfail;
243         }
244
245         my $ref = $self->{ref};
246         my $commit = $self->{mark}++;
247         my $parent = $tip =~ /\A:/ ? $tip : undef;
248         unless ($parent) {
249                 print $w "reset $ref\n" or wfail;
250         }
251         my $ident = $self->{ident};
252         my $now = now_raw();
253         $msg ||= 'rm';
254         my $len = length($msg) + 1;
255         print $w "commit $ref\nmark :$commit\n",
256                 "author $ident $now\n",
257                 "committer $ident $now\n",
258                 "data $len\n$msg\n\n",
259                 'from ', ($parent ? $parent : $tip), "\n" or wfail;
260         if (defined $path) {
261                 print $w "D $path\n\n" or wfail;
262         } else {
263                 clean_tree_v2($self, $w, 'd');
264                 print $w "M 100644 :$blob d\n\n" or wfail;
265         }
266         $self->{nchg}++;
267         (($self->{tip} = ":$commit"), $cur);
268 }
269
270 sub git_timestamp {
271         my ($ts, $zone) = @_;
272         $ts = 0 if $ts < 0; # git uses unsigned times
273         "$ts $zone";
274 }
275
276 sub extract_author_info ($) {
277         my ($mime) = @_;
278
279         my $sender = '';
280         my $from = $mime->header('From');
281         $from ||= '';
282         my ($email) = PublicInbox::Address::emails($from);
283         my ($name) = PublicInbox::Address::names($from);
284         if (!defined($name) || !defined($email)) {
285                 $sender = $mime->header('Sender');
286                 $sender ||= '';
287                 if (!defined($name)) {
288                         ($name) = PublicInbox::Address::names($sender);
289                 }
290                 if (!defined($email)) {
291                         ($email) = PublicInbox::Address::emails($sender);
292                 }
293         }
294         if (defined $email) {
295                 # quiet down wide character warnings with utf8::encode
296                 utf8::encode($email);
297         } else {
298                 $email = '';
299                 warn "no email in From: $from or Sender: $sender\n";
300         }
301
302         # git gets confused with:
303         #  "'A U Thor <u@example.com>' via foo" <foo@example.com>
304         # ref:
305         # <CAD0k6qSUYANxbjjbE4jTW4EeVwOYgBD=bXkSu=akiYC_CB7Ffw@mail.gmail.com>
306         if (defined $name) {
307                 $name =~ tr/<>//d;
308                 utf8::encode($name);
309         } else {
310                 $name = '';
311                 warn "no name in From: $from or Sender: $sender\n";
312         }
313         ($name, $email);
314 }
315
316 # kill potentially confusing/misleading headers
317 sub drop_unwanted_headers ($) {
318         my ($mime) = @_;
319
320         $mime->header_set($_) for qw(bytes lines content-length status);
321         $mime->header_set($_) for @PublicInbox::MDA::BAD_HEADERS;
322 }
323
324 # used by V2Writable, too
325 sub append_mid ($$) {
326         my ($hdr, $mid0) = @_;
327         # @cur is likely empty if we need to call this sub, but it could
328         # have random unparseable crap which we'll preserve, too.
329         my @cur = $hdr->header_raw('Message-ID');
330         $hdr->header_set('Message-ID', @cur, "<$mid0>");
331 }
332
333 sub v1_mid0 ($) {
334         my ($mime) = @_;
335         my $hdr = $mime->header_obj;
336         my $mids = mids($hdr);
337
338         if (!scalar(@$mids)) { # spam often has no Message-Id
339                 my $mid0 = digest2mid(content_digest($mime), $hdr);
340                 append_mid($hdr, $mid0);
341                 return $mid0;
342         }
343         $mids->[0];
344 }
345 sub clean_tree_v2 ($$$) {
346         my ($self, $w, $keep) = @_;
347         my $tree = $self->{-tree} or return; #v2 only
348         delete $tree->{$keep};
349         foreach (keys %$tree) {
350                 print $w "D $_\n" or wfail;
351         }
352         %$tree = ($keep => 1);
353 }
354
355 # returns undef on duplicate
356 # returns the :MARK of the most recent commit
357 sub add {
358         my ($self, $mime, $check_cb) = @_; # mime = Email::MIME
359
360         my ($name, $email) = extract_author_info($mime);
361         my $hdr = $mime->header_obj;
362         my @at = msg_datestamp($hdr);
363         my @ct = msg_timestamp($hdr);
364         my $author_time_raw = git_timestamp(@at);
365         my $commit_time_raw = git_timestamp(@ct);
366         my $subject = $mime->header('Subject');
367         $subject = '(no subject)' unless defined $subject;
368         my $path_type = $self->{path_type};
369
370         my $path;
371         if ($path_type eq '2/38') {
372                 $path = mid2path(v1_mid0($mime));
373         } else { # v2 layout, one file:
374                 $path = 'm';
375         }
376
377         my ($r, $w) = $self->gfi_start;
378         my $tip = $self->{tip};
379         if ($path_type eq '2/38') {
380                 _check_path($r, $w, $tip, $path) and return;
381         }
382
383         drop_unwanted_headers($mime);
384
385         # spam check:
386         if ($check_cb) {
387                 $mime = $check_cb->($mime) or return;
388         }
389
390         my $blob = $self->{mark}++;
391         my $str = $mime->as_string;
392         my $n = length($str);
393         $self->{bytes_added} += $n;
394         print $w "blob\nmark :$blob\ndata ", $n, "\n" or wfail;
395         print $w $str, "\n" or wfail;
396
397         # v2: we need this for Xapian
398         if ($self->{want_object_info}) {
399                 my $oid = $self->get_mark(":$blob");
400                 $self->{last_object} = [ $oid, $n, \$str ];
401         }
402         my $ref = $self->{ref};
403         my $commit = $self->{mark}++;
404         my $parent = $tip =~ /\A:/ ? $tip : undef;
405
406         unless ($parent) {
407                 print $w "reset $ref\n" or wfail;
408         }
409
410         # Mime decoding can create nulls replace them with spaces to protect git
411         $subject =~ tr/\0/ /;
412         utf8::encode($subject);
413         print $w "commit $ref\nmark :$commit\n",
414                 "author $name <$email> $author_time_raw\n",
415                 "committer $self->{ident} $commit_time_raw\n" or wfail;
416         print $w "data ", (length($subject) + 1), "\n",
417                 $subject, "\n\n" or wfail;
418         if ($tip ne '') {
419                 print $w 'from ', ($parent ? $parent : $tip), "\n" or wfail;
420         }
421         clean_tree_v2($self, $w, $path);
422         print $w "M 100644 :$blob $path\n\n" or wfail;
423         $self->{nchg}++;
424         $self->{tip} = ":$commit";
425 }
426
427 sub run_die ($;$$) {
428         my ($cmd, $env, $rdr) = @_;
429         my $pid = spawn($cmd, $env, $rdr);
430         defined $pid or die "spawning ".join(' ', @$cmd)." failed: $!";
431         waitpid($pid, 0) == $pid or die join(' ', @$cmd) .' did not finish';
432         $? == 0 or die join(' ', @$cmd) . " failed: $?\n";
433 }
434
435 sub done {
436         my ($self) = @_;
437         my $w = delete $self->{out} or return;
438         my $r = delete $self->{in} or die 'BUG: missing {in} when done';
439         print $w "done\n" or wfail;
440         my $pid = delete $self->{pid} or die 'BUG: missing {pid} when done';
441         waitpid($pid, 0) == $pid or die 'fast-import did not finish';
442         $? == 0 or die "fast-import failed: $?";
443
444         _update_git_info($self, 1) if delete $self->{nchg};
445
446         $self->lock_release;
447
448         $self->{git}->cleanup;
449 }
450
451 sub atfork_child {
452         my ($self) = @_;
453         foreach my $f (qw(in out)) {
454                 next unless defined($self->{$f});
455                 close $self->{$f} or die "failed to close import[$f]: $!\n";
456         }
457 }
458
459 sub digest2mid ($$) {
460         my ($dig, $hdr) = @_;
461         my $b64 = $dig->clone->b64digest;
462         # Make our own URLs nicer:
463         # See "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC4648
464         $b64 =~ tr!+/=!-_!d;
465
466         # Add a date prefix to prevent a leading '-' in case that trips
467         # up some tools (e.g. if a Message-ID were a expected as a
468         # command-line arg)
469         my $dt = msg_datestamp($hdr);
470         $dt = POSIX::strftime('%Y%m%d%H%M%S', gmtime($dt));
471         "$dt.$b64" . '@z';
472 }
473
474 sub clean_purge_buffer {
475         my ($oids, $buf) = @_;
476         my $cmt_msg = 'purged '.join(' ',@$oids)."\n";
477         @$oids = ();
478
479         foreach my $i (0..$#$buf) {
480                 my $l = $buf->[$i];
481                 if ($l =~ /^author .* (\d+ [\+-]?\d+)$/) {
482                         $buf->[$i] = "author <> $1\n";
483                 } elsif ($l =~ /^data (\d+)/) {
484                         $buf->[$i++] = "data " . length($cmt_msg) . "\n";
485                         $buf->[$i] = $cmt_msg;
486                         last;
487                 }
488         }
489 }
490
491 sub purge_oids {
492         my ($self, $purge) = @_;
493         my $tmp = "refs/heads/purge-".((keys %$purge)[0]);
494         my $old = $self->{'ref'};
495         my $git = $self->{git};
496         my @export = (qw(fast-export --no-data --use-done-feature), $old);
497         my ($rd, $pid) = $git->popen(@export);
498         my ($r, $w) = $self->gfi_start;
499         my @buf;
500         my $npurge = 0;
501         my @oids;
502         my ($done, $mark);
503         my $tree = $self->{-tree};
504         while (<$rd>) {
505                 if (/^reset (?:.+)/) {
506                         push @buf, "reset $tmp\n";
507                 } elsif (/^commit (?:.+)/) {
508                         if (@buf) {
509                                 $w->print(@buf) or wfail;
510                                 @buf = ();
511                         }
512                         push @buf, "commit $tmp\n";
513                 } elsif (/^data (\d+)/) {
514                         # only commit message, so $len is small:
515                         my $len = $1; # + 1 for trailing "\n"
516                         push @buf, $_;
517                         my $n = read($rd, my $buf, $len) or die "read: $!";
518                         $len == $n or die "short read ($n < $len)";
519                         push @buf, $buf;
520                 } elsif (/^M 100644 ([a-f0-9]+) (\w+)/) {
521                         my ($oid, $path) = ($1, $2);
522                         $tree->{$path} = 1;
523                         if ($purge->{$oid}) {
524                                 push @oids, $oid;
525                                 my $cmd = "M 100644 inline $path\ndata 0\n\n";
526                                 push @buf, $cmd;
527                         } else {
528                                 push @buf, $_;
529                         }
530                 } elsif (/^D (\w+)/) {
531                         my $path = $1;
532                         push @buf, $_ if $tree->{$path};
533                 } elsif ($_ eq "\n") {
534                         if (@oids) {
535                                 my $out = join('', @buf);
536                                 $out =~ s/^/# /sgm;
537                                 warn "purge rewriting\n", $out, "\n";
538                                 clean_purge_buffer(\@oids, \@buf);
539                                 $npurge++;
540                         }
541                         $w->print(@buf, "\n") or wfail;
542                         @buf = ();
543                 } elsif ($_ eq "done\n") {
544                         $done = 1;
545                 } elsif (/^mark :(\d+)$/) {
546                         push @buf, $_;
547                         $mark = $1;
548                 } else {
549                         push @buf, $_;
550                 }
551         }
552         if (@buf) {
553                 $w->print(@buf) or wfail;
554         }
555         die 'done\n not seen from fast-export' unless $done;
556         chomp(my $cmt = $self->get_mark(":$mark")) if $npurge;
557         $self->{nchg} = 0; # prevent _update_git_info until update-ref:
558         $self->done;
559         my @git = ('git', "--git-dir=$git->{git_dir}");
560
561         run_die([@git, qw(update-ref), $old, $tmp]) if $npurge;
562
563         run_die([@git, qw(update-ref -d), $tmp]);
564
565         return if $npurge == 0;
566
567         run_die([@git, qw(-c gc.reflogExpire=now gc --prune=all)]);
568         my $err = 0;
569         foreach my $oid (keys %$purge) {
570                 my @info = $git->check($oid);
571                 if (@info) {
572                         warn "$oid not purged\n";
573                         $err++;
574                 }
575         }
576         _update_git_info($self, 0);
577         die "Failed to purge $err object(s)\n" if $err;
578         $cmt;
579 }
580
581 1;
582 __END__
583 =pod
584
585 =head1 NAME
586
587 PublicInbox::Import - message importer for public-inbox
588
589 =head1 VERSION
590
591 version 1.0
592
593 =head1 SYNOPSYS
594
595         use Email::MIME;
596         use PublicInbox::Git;
597         use PublicInbox::Import;
598
599         chomp(my $git_dir = `git rev-parse --git-dir`);
600         $git_dir or die "GIT_DIR= must be specified\n";
601         my $git = PublicInbox::Git->new($git_dir);
602         my @committer = ('inbox', 'inbox@example.org');
603         my $im = PublicInbox::Import->new($git, @committer);
604
605         # to add a message:
606         my $message = "From: <u\@example.org>\n".
607                 "Subject: test message \n" .
608                 "Date: Thu, 01 Jan 1970 00:00:00 +0000\n" .
609                 "Message-ID: <m\@example.org>\n".
610                 "\ntest message";
611         my $parsed = Email::MIME->new($message);
612         my $ret = $im->add($parsed);
613         if (!defined $ret) {
614                 warn "duplicate: ",
615                         $parsed->header_obj->header_raw('Message-ID'), "\n";
616         } else {
617                 print "imported at mark $ret\n";
618         }
619         $im->done;
620
621         # to remove a message
622         my $junk = Email::MIME->new($message);
623         my ($mark, $orig) = $im->remove($junk);
624         if ($mark eq 'MISSING') {
625                 print "not found\n";
626         } elsif ($mark eq 'MISMATCH') {
627                 print "Message exists but does not match\n\n",
628                         $orig->as_string, "\n",;
629         } else {
630                 print "removed at mark $mark\n\n",
631                         $orig->as_string, "\n";
632         }
633         $im->done;
634
635 =head1 DESCRIPTION
636
637 An importer and remover for public-inboxes which takes L<Email::MIME>
638 messages as input and stores them in a git repository as
639 documented in L<https://public-inbox.org/public-inbox-v1-format.txt>,
640 except it does not allow duplicate Message-IDs.
641
642 It requires L<git(1)> and L<git-fast-import(1)> to be installed.
643
644 =head1 METHODS
645
646 =cut
647
648 =head2 new
649
650         my $im = PublicInbox::Import->new($git, @committer);
651
652 Initialize a new PublicInbox::Import object.
653
654 =head2 add
655
656         my $parsed = Email::MIME->new($message);
657         $im->add($parsed);
658
659 Adds a message to to the git repository.  This will acquire
660 C<$GIT_DIR/ssoma.lock> and start L<git-fast-import(1)> if necessary.
661
662 Messages added will not be visible to other processes until L</done>
663 is called, but L</remove> may be called on them.
664
665 =head2 remove
666
667         my $junk = Email::MIME->new($message);
668         my ($code, $orig) = $im->remove($junk);
669
670 Removes a message from the repository.  On success, it returns
671 a ':'-prefixed numeric code representing the git-fast-import
672 mark and the original messages as an Email::MIME object.
673 If the message could not be found, the code is "MISSING"
674 and the original message is undef.  If there is a mismatch where
675 the "Message-ID" is matched but the subject and body do not match,
676 the returned code is "MISMATCH" and the conflicting message
677 is returned as orig.
678
679 =head2 done
680
681 Finalizes the L<git-fast-import(1)> and unlocks the repository.
682 Calling this is required to finalize changes to a repository.
683
684 =head1 SEE ALSO
685
686 L<Email::MIME>
687
688 =head1 CONTACT
689
690 All feedback welcome via plain-text mail to L<mailto:meta@public-inbox.org>
691
692 The mail archives are hosted at L<https://public-inbox.org/meta/>
693
694 =head1 COPYRIGHT
695
696 Copyright (C) 2016 all contributors L<mailto:meta@public-inbox.org>
697
698 License: AGPL-3.0+ L<http://www.gnu.org/licenses/agpl-3.0.txt>
699
700 =cut