]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mbox: move mbox_keywords to MboxReader
authorEric Wong <e@80x24.org>
Tue, 16 Mar 2021 01:43:44 +0000 (07:43 +0600)
committerEric Wong <e@80x24.org>
Tue, 16 Mar 2021 10:32:06 +0000 (06:32 -0400)
MboxReader is a more appropriate place for it than LeiStore.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiConvert.pm
lib/PublicInbox/LeiImport.pm
lib/PublicInbox/LeiStore.pm
lib/PublicInbox/LeiToMail.pm
lib/PublicInbox/MboxReader.pm
t/lei_store.t
t/mbox_reader.t

index 31d5b838e7b66c44d4612d5b8dbb598950a86f22..a0986f386a165de5690ded33bca4c3042df51898 100644 (file)
@@ -412,9 +412,9 @@ sub check_input_format ($;$) {
                return fail($self, "--$opt_key unset for $err");
        }
        require PublicInbox::MboxLock if $files;
+       require PublicInbox::MboxReader;
        return 1 if $fmt eq 'eml';
        # XXX: should this handle {gz,bz2,xz}? that's currently in LeiToMail
-       require PublicInbox::MboxReader;
        PublicInbox::MboxReader->can($fmt) or
                return fail($self, "--$opt_key=$fmt unrecognized");
        1;
index 0c705ba4c1bba82a744b8dac51d97236a3481423..fcc67f0bfe25ea3d2b72fee28e593cb1a3da3a6d 100644 (file)
@@ -12,9 +12,9 @@ use PublicInbox::LeiOverview;
 
 sub mbox_cb {
        my ($eml, $self) = @_;
-       my @kw = PublicInbox::LeiStore::mbox_keywords($eml);
+       my $kw = PublicInbox::MboxReader::mbox_keywords($eml);
        $eml->header_set($_) for qw(Status X-Status);
-       $self->{wcb}->(undef, { kw => \@kw }, $eml);
+       $self->{wcb}->(undef, { kw => $kw }, $eml);
 }
 
 sub net_cb { # callback for ->imap_each, ->nntp_each
index 815788b38149c5f8f84d298f88fb3b1b65505659..65e37371cdd275254e936f095a08d5c5543ac360 100644 (file)
@@ -11,7 +11,8 @@ use PublicInbox::PktOp qw(pkt_do);
 
 sub _import_eml { # MboxReader callback
        my ($eml, $sto, $set_kw) = @_;
-       $sto->ipc_do('set_eml', $eml, $set_kw ? $sto->mbox_keywords($eml) : ());
+       $sto->ipc_do('set_eml', $eml, $set_kw ?
+               @{PublicInbox::MboxReader::mbox_keywords($eml)} : ());
 }
 
 sub import_done_wait { # dwaitpid callback
index aaee587460b4d25815c9c6e72d7d7a11260866f3..10fa9c5489f62d999cd064f918eb0318d0cb83db 100644 (file)
@@ -159,18 +159,6 @@ sub remove_eml_keywords {
        \@docids;
 }
 
-# cf: https://doc.dovecot.org/configuration_manual/mail_location/mbox/
-my %status2kw = (F => 'flagged', A => 'answered', R => 'seen', T => 'draft');
-# O (old/non-recent), and D (deleted) aren't in JMAP,
-# so probably won't be supported by us.
-sub mbox_keywords {
-       my $eml = $_[-1];
-       my $s = "@{[$eml->header_raw('X-Status'),$eml->header_raw('Status')]}";
-       my %kw;
-       $s =~ s/([FART])/$kw{$status2kw{$1}} = 1/sge;
-       sort(keys %kw);
-}
-
 # TODO: move this to MdirReader, maybe...
 # cf: https://cr.yp.to/proto/maildir.html
 my %c2kw = ('D' => 'draft', F => 'flagged', R => 'answered', S => 'seen');
index 587804bbc1aa52c167efb6d570a958c7b99092f3..27e1338f7f1bb57305dc43b67cc1fde5ede59b8b 100644 (file)
@@ -246,8 +246,8 @@ sub _augment { # MboxReader eml_cb
 
 sub _mbox_augment_kw_maybe {
        my ($eml, $lei, $lse, $augment) = @_;
-       my @kw = PublicInbox::LeiStore::mbox_keywords($eml);
-       update_kw_maybe($lei, $lse, $eml, \@kw);
+       my $kw = PublicInbox::MboxReader::mbox_keywords($eml);
+       update_kw_maybe($lei, $lse, $eml, $kw);
        _augment($eml, $lei) if $augment;
 }
 
index df7c78faf885c6cf9dae692ef30cfdac43741f0f..f93c2ec634496d8c4ba8d4a7bfde0c8b9ab260a3 100644 (file)
@@ -11,6 +11,18 @@ $Data::Dumper::Useqq = 1; # should've been the default, for bad data
 my $from_strict =
        qr/^From \S+ +\S+ \S+ +\S+ [^\n:]+:[^\n:]+:[^\n:]+ [^\n:]+\n/sm;
 
+# cf: https://doc.dovecot.org/configuration_manual/mail_location/mbox/
+my %status2kw = (F => 'flagged', A => 'answered', R => 'seen', T => 'draft');
+# O (old/non-recent), and D (deleted) aren't in JMAP,
+# so probably won't be supported by us.
+sub mbox_keywords {
+       my $eml = $_[-1];
+       my $s = "@{[$eml->header_raw('X-Status'),$eml->header_raw('Status')]}";
+       my %kw;
+       $s =~ s/([FART])/$kw{$status2kw{$1}} = 1/sge;
+       [ sort(keys %kw) ];
+}
+
 sub _mbox_from {
        my ($mbfh, $from_re, $eml_cb, @arg) = @_;
        my $buf = '';
index 1c3f78413bd8f84a6a2cb5321c367ad79208f486..258db25a8171f7d9a6a7c7b550fe3f781238cb55 100644 (file)
@@ -21,14 +21,6 @@ like($smsg->{blob}, qr/\A[0-9a-f]+\z/, 'add returned OID');
 my $eml = eml_load('t/data/0001.patch');
 is($sto->add_eml($eml), undef, 'idempotent');
 $sto->done;
-is_deeply([$sto->mbox_keywords($eml)], [], 'no keywords');
-$eml->header_set('Status', 'RO');
-is_deeply([$sto->mbox_keywords($eml)], ['seen'], 'seen extracted');
-$eml->header_set('X-Status', 'A');
-is_deeply([$sto->mbox_keywords($eml)], [qw(answered seen)],
-       'seen+answered extracted');
-$eml->header_set($_) for qw(Status X-Status);
-
 is_deeply([$sto->maildir_keywords('/foo:2,')], [], 'Maildir no keywords');
 is_deeply([$sto->maildir_keywords('/foo:2,S')], ['seen'], 'Maildir seen');
 is_deeply([$sto->maildir_keywords('/foo:2,RS')], ['answered', 'seen'],
index 18d0fd6818a35f4ac519347fd48cd1fe18231c2d..da0ce7f1e58aff03c0c82eebfaf7536e550af96f 100644 (file)
@@ -24,6 +24,16 @@ my %raw = (
                (("b: ".('b' x 72)."\n") x 1000) .
                "From hell\n",
 );
+{
+       my $eml = PublicInbox::Eml->new($raw{small});
+       my $mbox_keywords = PublicInbox::MboxReader->can('mbox_keywords');
+       is_deeply($mbox_keywords->($eml), [], 'no keywords');
+       $eml->header_set('Status', 'RO');
+       is_deeply($mbox_keywords->($eml), ['seen'], 'seen extracted');
+       $eml->header_set('X-Status', 'A');
+       is_deeply($mbox_keywords->($eml), [qw(answered seen)],
+               'seen+answered extracted');
+}
 
 if ($ENV{TEST_EXTRA}) {
        for my $fn (glob('t/*.eml'), glob('t/*/*.{patch,eml}')) {