about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-09-12 22:40:34 +0000
committerEric Wong <e@80x24.org>2023-09-15 20:37:47 +0000
commit392d251f97d465796e9497d893b983bfb2a05b74 (patch)
tree140ce27df2883f70ae8942051c8b033d6195fa47
parente281363ba93763a7bc4be41ad814cd972d1775f9 (diff)
downloadpublic-inbox-392d251f97d465796e9497d893b983bfb2a05b74.tar.gz
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>
-rw-r--r--lib/PublicInbox/POP3.pm18
-rw-r--r--xt/pop3d-mpop.t4
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/PublicInbox/POP3.pm b/lib/PublicInbox/POP3.pm
index d32793e4..4a21ef5e 100644
--- a/lib/PublicInbox/POP3.pm
+++ b/lib/PublicInbox/POP3.pm
@@ -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;
         }
diff --git a/xt/pop3d-mpop.t b/xt/pop3d-mpop.t
index fc82bc6b..9da1050c 100644
--- a/xt/pop3d-mpop.t
+++ b/xt/pop3d-mpop.t
@@ -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;