]> Sergey Matveev's repositories - public-inbox.git/commitdiff
imap: use Text::ParseWords::parse_line to handle quoted words
authorEric Wong <e@yhbt.net>
Wed, 10 Jun 2020 07:04:06 +0000 (07:04 +0000)
committerEric Wong <e@yhbt.net>
Sat, 13 Jun 2020 07:55:45 +0000 (07:55 +0000)
IMAP clients may quote args and escape similar to POSIX shell,
so attempt to handle them properly using this standard library
module.

lib/PublicInbox/IMAP.pm

index a2d59e5cccca9014e26416820bfdb4aca83b87d7..7745d9f96f788962c14603bb520101a601a93f8b 100644 (file)
@@ -20,6 +20,7 @@ use fields qw(imapd logged_in ibx long_cb -login_tag
 use PublicInbox::Eml;
 use PublicInbox::DS qw(now);
 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
+use Text::ParseWords qw(parse_line);
 use Errno qw(EAGAIN);
 my $Address;
 for my $mod (qw(Email::Address::XS Mail::Address)) {
@@ -423,7 +424,8 @@ sub args_ok ($$) { # duplicated from PublicInbox::NNTP
 # returns 1 if we can continue, 0 if not due to buffered writes or disconnect
 sub process_line ($$) {
        my ($self, $l) = @_;
-       my ($tag, $req, @args) = split(/[ \t]+/, $l);
+       my ($tag, $req, @args) = parse_line('[ \t]+', 0, $l);
+       pop(@args) if (@args && !defined($args[-1]));
        if (@args && uc($req) eq 'UID') {
                $req .= "_".(shift @args);
        }