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 06EDC1FBD1 for ; Wed, 10 Jun 2020 07:07:30 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 57/82] imap: remove dummies from sequence number FETCH Date: Wed, 10 Jun 2020 07:04:54 +0000 Message-Id: <20200610070519.18252-58-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Dummy messages make for bad user experience with MUAs which still use sequence numbers. Not being able to fetch a message doesn't seem fatal in mutt, so just ignore (sometimes large) gaps. --- lib/PublicInbox/IMAP.pm | 61 ++++------------------------------------- t/imapd.t | 3 +- 2 files changed, 6 insertions(+), 58 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 78042b9e2ee..8307343cf15 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -9,8 +9,9 @@ # data notes: # * NNTP article numbers are UIDs and message sequence numbers (MSNs) # * Message sequence numbers (MSNs) can be stable since we're read-only. -# Most IMAP clients use UIDs (I hope), and we can return a dummy -# message if a client requests a non-existent MSN. +# Most IMAP clients use UIDs (I hope). We may return a dummy message +# in the future if a client requests a non-existent MSN, but that seems +# unecessary with mutt. package PublicInbox::IMAP; use strict; @@ -398,22 +399,6 @@ sub fetch_body ($;$) { join('', @hold); } -sub dummy_message ($$) { - my ($self, $seqno) = @_; - my $ret = <{ibx}->{newsgroup}>\r -Subject: dummy message #$seqno\r -\r -You're seeing this message because your IMAP client didn't use UIDs.\r -The message which used to use this sequence number was likely spam\r -and removed by the administrator.\r -EOF - \$ret; -} - sub requeue_once ($) { my ($self) = @_; # COMPRESS users all share the same DEFLATE context. @@ -437,8 +422,7 @@ sub uid_fetch_cb { # called by git->cat_async via git_async_cat if (!defined($oid)) { # it's possible to have TOCTOU if an admin runs # public-inbox-(edit|purge), just move onto the next message - return requeue_once($self) unless defined $want->{-seqno}; - $bref = dummy_message($self, $smsg->{num}); + return requeue_once($self); } else { $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid"; } @@ -764,42 +748,6 @@ sub cmd_uid_fetch ($$$;@) { $args; # error } -sub seq_fetch_m { # long_response - my ($self, $tag, $msgs, $range_info, $want) = @_; - while (!@$msgs) { # rare - if (my $end = refill_range($self, $msgs, $range_info)) { - $self->write(\"$tag $end\r\n"); - return; - } - } - my $seq = $want->{-seqno}++; - my $cur_num = $msgs->[0]->{num}; - if ($cur_num == $seq) { # as expected - git_async_cat($self->{ibx}->git, $msgs->[0]->{blob}, - \&uid_fetch_cb, \@_); - } elsif ($cur_num > $seq) { - # send dummy messages until $seq catches up to $cur_num - my $smsg = bless { num => $seq, ts => 0 }, 'PublicInbox::Smsg'; - unshift @$msgs, $smsg; - my $bref = dummy_message($self, $seq); - uid_fetch_cb($bref, undef, undef, undef, \@_); - $smsg; # blessed response since uid_fetch_cb requeues - } else { # should not happen - die "BUG: cur_num=$cur_num < seq=$seq"; - } -} - -sub cmd_fetch ($$$;@) { - my ($self, $tag, $range_csv, @want) = @_; - my $args = fetch_common($self, $tag, $range_csv, \@want); - ref($args) eq 'ARRAY' ? do { - my $want = $args->[-1]; - $want->{-seqno} = $args->[2]->[0]; # $beg == $range_info->[0]; - long_response($self, \&seq_fetch_m, @$args) - } : $args; # error -} - - sub parse_date ($) { # 02-Oct-1993 my ($date_text) = @_; my ($dd, $mon, $yyyy) = split(/-/, $_[0], 3); @@ -1147,5 +1095,6 @@ sub close { # we're read-only, so SELECT and EXAMINE do the same thing no warnings 'once'; *cmd_select = \&cmd_examine; +*cmd_fetch = \&cmd_uid_fetch; 1; diff --git a/t/imapd.t b/t/imapd.t index 2546ab51ac6..233be9f2c0a 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -348,8 +348,7 @@ is(scalar keys %$ret, 3, 'got all 3 messages'); run_script(\@cmd, $env, $rdr) or BAIL_OUT('-learn rm'); } my $r2 = $mic->fetch_hash('1:*', 'BODY.PEEK[]') or BAIL_OUT "FETCH $@"; -is(scalar keys %$r2, 3, 'still got all 3 messages'); -like($r2->{1}->{'BODY[]'}, qr/dummy message #1/, 'got dummy message 1'); +is(scalar keys %$r2, 2, 'did not get all 3 messages'); is($r2->{2}->{'BODY[]'}, $ret->{2}->{RFC822}, 'message 2 unchanged'); is($r2->{3}->{'BODY[]'}, $ret->{3}->{RFC822}, 'message 3 unchanged'); $r2 = $mic->fetch_hash(2, 'BODY.PEEK[HEADER.FIELDS (message-id)]')