From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 989A51FC0C for ; Mon, 22 Mar 2021 07:54:03 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 8/8] lei import: ignore Status headers in "eml" messages Date: Mon, 22 Mar 2021 07:54:02 +0000 Message-Id: <20210322075402.27834-9-e@80x24.org> In-Reply-To: <20210322075402.27834-1-e@80x24.org> References: <20210322075402.27834-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Those headers only have meaning with for mboxes. Don't surprise users by trying to make sense of a header that is defined for mboxes. It's possible to send email with (Status|X-Status) headers and have those headers show up in a recipient's IMAP mailbox. This was bad because an IMAP user may want to import a single message through their MUA and pipe its contents to "lei import" without noticing a mischievious sender stuck "X-Status: F" (flagged/important) in there. --- lib/PublicInbox/LeiImport.pm | 14 +++++++------- t/lei-import.t | 27 ++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index 767cae60..9ad2ff12 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -10,19 +10,19 @@ use PublicInbox::Eml; use PublicInbox::PktOp qw(pkt_do); sub eml_cb { # used by PublicInbox::LeiInput::input_fh - my ($self, $eml) = @_; - my $vmd; - if ($self->{-import_kw}) { # FIXME - my $kw = PublicInbox::MboxReader::mbox_keywords($eml); - $vmd = { kw => $kw } if scalar(@$kw); - } + my ($self, $eml, $vmd) = @_; my $xoids = $self->{lei}->{ale}->xoids_for($eml); $self->{lei}->{sto}->ipc_do('set_eml', $eml, $vmd, $xoids); } sub mbox_cb { # MboxReader callback used by PublicInbox::LeiInput::input_fh my ($eml, $self) = @_; - eml_cb($self, $eml); + my $vmd; + if ($self->{-import_kw}) { + my $kw = PublicInbox::MboxReader::mbox_keywords($eml); + $vmd = { kw => $kw } if scalar(@$kw); + } + eml_cb($self, $eml, $vmd); } sub import_done_wait { # dwaitpid callback diff --git a/t/lei-import.t b/t/lei-import.t index eef1e4e2..a697d756 100644 --- a/t/lei-import.t +++ b/t/lei-import.t @@ -39,27 +39,44 @@ lei_ok(qw(q m:testmessage@example.com)); is(json_utf8->decode($lei_out)->[0]->{'blob'}, $oid, 'got expected OID w/o From'); -my $str = <<''; +my $eml_str = <<''; From: a@b Message-ID: Status: RO -my $opt = { %$lei_opt, 0 => \$str }; +my $opt = { %$lei_opt, 0 => \$eml_str }; lei_ok([qw(import -F eml -)], undef, $opt, \'import single file with keywords from stdin'); lei_ok(qw(q m:x@y)); my $res = json_utf8->decode($lei_out); is($res->[1], undef, 'only one result'); -is_deeply($res->[0]->{kw}, ['seen'], "message `seen' keyword set"); +is($res->[0]->{'m'}, 'x@y', 'got expected message'); +is($res->[0]->{kw}, undef, 'Status ignored for eml'); +lei_ok(qw(q -f mboxrd m:x@y)); +unlike($lei_out, qr/^Status:/, 'no Status: in imported message'); -$str =~ tr/x/v/; # v@y -lei_ok([qw(import --no-kw -F eml -)], undef, $opt, + +$eml->header_set('Message-ID', ''); +$eml->header_set('Status', 'RO'); +$in = 'From v@y Fri Oct 2 00:00:00 1993'."\n".$eml->as_string; +lei_ok([qw(import --no-kw -F mboxrd -)], undef, { %$lei_opt, 0 => \$in }, \'import single file with --no-kw from stdin'); lei(qw(q m:v@y)); $res = json_utf8->decode($lei_out); is($res->[1], undef, 'only one result'); +is($res->[0]->{'m'}, 'v@y', 'got expected message'); is($res->[0]->{kw}, undef, 'no keywords set'); +$eml->header_set('Message-ID', ''); +$in = 'From k@y Fri Oct 2 00:00:00 1993'."\n".$eml->as_string; +lei_ok([qw(import -F mboxrd -)], undef, { %$lei_opt, 0 => \$in }, + \'import single file with --kw (default) from stdin'); +lei(qw(q m:k@y)); +$res = json_utf8->decode($lei_out); +is($res->[1], undef, 'only one result'); +is($res->[0]->{'m'}, 'k@y', 'got expected message'); +is_deeply($res->[0]->{kw}, ['seen'], "`seen' keywords set"); + # see t/lei_to_mail.t for "import -F mbox*" }); done_testing;