* [PATCH 1/2] mbox: move mbox_keywords to MboxReader
2021-03-16 1:43 [PATCH 0/2] keyword handling cleanups Eric Wong
@ 2021-03-16 1:43 ` Eric Wong
2021-03-16 1:43 ` [PATCH 2/2] lei_store: remove maildir_keywords Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-03-16 1:43 UTC (permalink / raw)
To: meta
MboxReader is a more appropriate place for it than LeiStore.
---
lib/PublicInbox/LEI.pm | 2 +-
lib/PublicInbox/LeiConvert.pm | 4 ++--
lib/PublicInbox/LeiImport.pm | 3 ++-
lib/PublicInbox/LeiStore.pm | 12 ------------
lib/PublicInbox/LeiToMail.pm | 4 ++--
lib/PublicInbox/MboxReader.pm | 12 ++++++++++++
t/lei_store.t | 8 --------
t/mbox_reader.t | 10 ++++++++++
8 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 31d5b838..a0986f38 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -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;
diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm
index 0c705ba4..fcc67f0b 100644
--- a/lib/PublicInbox/LeiConvert.pm
+++ b/lib/PublicInbox/LeiConvert.pm
@@ -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
diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm
index 815788b3..65e37371 100644
--- a/lib/PublicInbox/LeiImport.pm
+++ b/lib/PublicInbox/LeiImport.pm
@@ -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
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index aaee5874..10fa9c54 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -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');
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 587804bb..27e1338f 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -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;
}
diff --git a/lib/PublicInbox/MboxReader.pm b/lib/PublicInbox/MboxReader.pm
index df7c78fa..f93c2ec6 100644
--- a/lib/PublicInbox/MboxReader.pm
+++ b/lib/PublicInbox/MboxReader.pm
@@ -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 = '';
diff --git a/t/lei_store.t b/t/lei_store.t
index 1c3f7841..258db25a 100644
--- a/t/lei_store.t
+++ b/t/lei_store.t
@@ -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'],
diff --git a/t/mbox_reader.t b/t/mbox_reader.t
index 18d0fd68..da0ce7f1 100644
--- a/t/mbox_reader.t
+++ b/t/mbox_reader.t
@@ -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}')) {
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] lei_store: remove maildir_keywords
2021-03-16 1:43 [PATCH 0/2] keyword handling cleanups Eric Wong
2021-03-16 1:43 ` [PATCH 1/2] mbox: move mbox_keywords to MboxReader Eric Wong
@ 2021-03-16 1:43 ` Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-03-16 1:43 UTC (permalink / raw)
To: meta
It's redundant and the same functionality is in MdirReader.
---
lib/PublicInbox/LeiStore.pm | 8 --------
t/lei_store.t | 6 ------
2 files changed, 14 deletions(-)
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index 10fa9c54..771443db 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -159,14 +159,6 @@ sub remove_eml_keywords {
\@docids;
}
-# TODO: move this to MdirReader, maybe...
-# cf: https://cr.yp.to/proto/maildir.html
-my %c2kw = ('D' => 'draft', F => 'flagged', R => 'answered', S => 'seen');
-sub maildir_keywords {
- $_[-1] =~ /:2,([A-Z]+)\z/i ?
- sort(map { $c2kw{$_} // () } split(//, $1)) : ();
-}
-
sub add_eml {
my ($self, $eml, @kw) = @_;
my $im = $self->importer; # may create new epoch
diff --git a/t/lei_store.t b/t/lei_store.t
index 258db25a..d270e1f6 100644
--- a/t/lei_store.t
+++ b/t/lei_store.t
@@ -21,12 +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->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'],
- 'Maildir answered + seen');
-is_deeply([$sto->maildir_keywords('/foo:2,RSZ')], ['answered', 'seen'],
- 'Maildir answered + seen w/o Z');
{
my $es = $sto->search;
my $msgs = $es->over->query_xover(0, 1000);
^ permalink raw reply related [flat|nested] 3+ messages in thread