]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
pop3: support `?limit=$NUM' parameter in mailbox name
authorEric Wong <e@80x24.org>
Tue, 12 Sep 2023 22:40:34 +0000 (22:40 +0000)
committerEric Wong <e@80x24.org>
Fri, 15 Sep 2023 20:37:47 +0000 (20:37 +0000)
I'm not sure if `?' or `=' are allowed characters in POP3
mailbox names.  In fact, I can't find any information on
valid characters allowed in RFC 1081 nor RFC 1939.

In any case, it works fine with mpop, Claws-Mail, and
Thunderbird.

Tested-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
lib/PublicInbox/POP3.pm
xt/pop3d-mpop.t

index d32793e492da80a31680846fc25d23c07a8d7d71..4a21ef5e3b10adb9483453a320ff9ce6927d621e 100644 (file)
@@ -41,6 +41,7 @@ use PublicInbox::IMAP; # for UID slice stuff
 
 use constant {
        LINE_MAX => 512, # XXX unsure
+       UID_SLICE => PublicInbox::IMAP::UID_SLICE,
 };
 
 # XXX FIXME: duplicated stuff from NNTP.pm and IMAP.pm
@@ -70,20 +71,25 @@ sub cmd_user ($$) {
        my $user = $1;
        $user =~ tr/-//d; # most have dashes, some (dbus-uuidgen) don't
        $user =~ m!\A[a-f0-9]{32}\z!i or return \"-ERR user has no UUID\r\n";
-       my $slice;
-       $mailbox =~ s/\.([0-9]+)\z// and $slice = $1 + 0;
+
+       my $limit = UID_SLICE;
+       $mailbox =~ s/\?limit=([0-9]+)\z// and
+               $limit = $1 > UID_SLICE ? UID_SLICE : $1;
+
+       my $slice = $mailbox =~ s/\.([0-9]+)\z// ? $1 + 0 : undef;
+
        my $ibx = $self->{pop3d}->{pi_cfg}->lookup_newsgroup($mailbox) //
                return \"-ERR $mailbox does not exist\r\n";
        my $uidmax = $ibx->mm(1)->num_highwater // 0;
        if (defined $slice) {
-               my $max = int($uidmax / PublicInbox::IMAP::UID_SLICE);
+               my $max = int($uidmax / UID_SLICE);
                my $tip = "$mailbox.$max";
                return \"-ERR $mailbox.$slice does not exist ($tip does)\r\n"
                        if $slice > $max;
-               $self->{uid_base} = $slice * PublicInbox::IMAP::UID_SLICE;
+               $self->{uid_base} = ($slice * UID_SLICE) + UID_SLICE - $limit;
                $self->{slice} = $slice;
-       } else { # latest 50K messages
-               my $base = $uidmax - PublicInbox::IMAP::UID_SLICE;
+       } else { # latest $limit messages
+               my $base = $uidmax - $limit;
                $self->{uid_base} = $base < 0 ? 0 : $base;
                $self->{slice} = -1;
        }
index fc82bc6ba0ca78e10089561a00d86ece9f101bfd..9da1050c569c3e48645f997358a7eb7e53e820b0 100644 (file)
@@ -53,7 +53,7 @@ delivery maildir $tmpdir/md
 account default
 host ${\$sock->sockhost}
 port ${\$sock->sockport}
-user $uuid\@$newsgroup
+user $uuid\@$newsgroup?limit=10000
 auth user
 password anonymous
 received_header off
@@ -65,7 +65,7 @@ EOM
        my $pid = spawn($cmd, undef, { 1 => 2 });
        $pids{$pid} = $cmd;
 }
-
+diag "mpop is writing to $tmpdir/md ...";
 while (scalar keys %pids) {
        my $pid = waitpid(-1, 0) or next;
        my $cmd = delete $pids{$pid} or next;