]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/FakeImport.pm
imap+nntp: share COMPRESS implementation
[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 v5.10.1;
8 use PublicInbox::ContentHash qw(git_sha);
9 use PublicInbox::Import;
10
11 sub new { bless { bytes_added => 0 }, __PACKAGE__ }
12
13 sub add {
14         my ($self, $eml, $check_cb, $smsg) = @_;
15         PublicInbox::Import::drop_unwanted_headers($eml);
16         $smsg->populate($eml);
17         my $raw = $eml->as_string;
18         $smsg->{blob} = git_sha(1, \$raw)->hexdigest;
19         $smsg->set_bytes($raw, length($raw));
20         if (my $oidx = delete $smsg->{-oidx}) { # used by LeiStore
21                 $oidx->vivify_xvmd($smsg) or return;
22         }
23         1;
24 }
25
26 1;