Yesterday I was trying to sort the emails coming from imap using the Mail::IMAPClient library doing the following:
my $imap = Mail::IMAPClient->new(
#my imap settings
);
#folder selection
my @messages = $imap->sort('(REVERSE ARRIVAL) UTF-8 ALL');
But I got:
4 BAD Error in IMAP command UID SORT: Invalid sort list argument (0.000 + 0.000 secs). at /var/www/localhost/htdocs/user/mail.pl line 93.: /var/www/localhost/htdocs/user/mail.pl
I was several hours trying to resolve this issue until I found the answer. (below)