]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/FakeImport.pm
lei index: new command to index mail w/o git storage
[public-inbox.git] / lib / PublicInbox / FakeImport.pm
1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # pretend to do PublicInbox::Import::add for "lei index"
5 package PublicInbox::FakeImport;
6 use strict;
7 use PublicInbox::ContentHash qw(git_sha);
8
9 sub new { bless { bytes_added => 0 }, __PACKAGE__ }
10
11 sub add {
12         my ($self, $eml, $check_cb, $smsg) = @_;
13         $smsg->populate($eml);
14         my $raw = $eml->as_string;
15         $smsg->{blob} = git_sha(1, \$raw)->hexdigest;
16         $smsg->set_bytes($raw, length($raw));
17         if (my $oidx = delete $smsg->{-oidx}) { # used by LeiStore
18                 $oidx->vivify_xvmd($smsg) or return;
19         }
20         1;
21 }
22
23 1;