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 DFB451FBC6 for ; Wed, 10 Jun 2020 07:05:20 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/82] imap: use Text::ParseWords::parse_line to handle quoted words Date: Wed, 10 Jun 2020 07:04:06 +0000 Message-Id: <20200610070519.18252-10-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: 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index a2d59e5cccc..7745d9f96f7 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -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); }