]> Sergey Matveev's repositories - public-inbox.git/commitdiff
pop3: TOP requests do not expire messages
authorEric Wong <e@80x24.org>
Wed, 20 Jul 2022 09:24:11 +0000 (09:24 +0000)
committerEric Wong <e@80x24.org>
Wed, 20 Jul 2022 16:52:11 +0000 (16:52 +0000)
RFC 2449 only documents "EXPIRE 0" behavior for RETR requests
which fetch the whole message.  TOP requests only fetch
the headers and top $N lines of the body, so it's probably
harmful for deletions to be triggered in those cases.

lib/PublicInbox/POP3.pm
t/pop3d.t

index 51c2b71a560fd10e041ad8bb949e2b8c3ab6486e..2c20c84b0e1022f6594227d8de9f1a4cb2aaf4fb 100644 (file)
@@ -300,12 +300,13 @@ sub retr_cb { # called by git->cat_async via ibx_async_cat
                $hdr .= "\r\n\r\n";
                my @tmp = split(/^/m, $bdy);
                $hdr .= join('', splice(@tmp, 0, $top_nr));
+       } elsif (exists $self->{expire}) {
+               $self->{expire} .= pack('S', $off + 1);
        }
        $$bref =~ s/^\./../gms;
        $$bref .= substr($$bref, -2, 2) eq "\r\n" ? ".\r\n" : "\r\n.\r\n";
        $self->msg_more("+OK message follows\r\n");
        $self->write($bref);
-       $self->{expire} .= pack('S', $off + 1) if exists $self->{expire};
        $self->requeue;
 }
 
index d5ccb0d8c5b4922d0e275986e45b604ff384dfff..3d70935fa69d162db37e5ffef1b0906a839f5454 100644 (file)
--- a/t/pop3d.t
+++ b/t/pop3d.t
@@ -240,8 +240,17 @@ EOF
        ok(defined($capa->{PIPELINING}), 'pipelining supported by CAPA');
        is($capa->{EXPIRE}, 0, 'EXPIRE 0 set');
 
-       # clients which see "EXPIRE 0" can elide DELE requests
+       # ensure TOP doesn't trigger "EXPIRE 0" like RETR does (cf. RFC2449)
        my $list = $oldc->list;
+       ok(scalar keys %$list, 'got a listing of messages');
+       ok($oldc->top($_, 1), "TOP $_ 1") for keys %$list;
+       ok($oldc->quit, 'QUIT after TOP');
+
+       # clients which see "EXPIRE 0" can elide DELE requests
+       $oldc = Net::POP3->new(@old_args);
+       ok($oldc->apop("$locked_mb.0", 'anonymous'), 'APOP for RETR');
+       is_deeply($oldc->capa, $capa, 'CAPA unchanged');
+       is_deeply($oldc->list, $list, 'LIST unchanged by previous TOP');
        ok($oldc->get($_), "RETR $_") for keys %$list;
        ok($oldc->quit, 'QUIT after RETR');