uidSortMessages method
Future<SortImapResult>
uidSortMessages(
- String sortCriteria, [
- String searchCriteria = 'ALL',
- String charset = 'UTF-8',
- List<
ReturnOption> ? returnOptions,
Sorts messages by the given criteria
sortCriteria
the criteria used for sorting the results like 'ARRIVAL' or 'SUBJECT'
searchCriteria
the criteria like 'UNSEEN' or 'RECENT'
charset
the charset used for the searching criteria
When augmented with zero or more returnOptions
, requests an extended search.
The server needs to expose the SORT capability for this command to work.
Implementation
Future<SortImapResult> uidSortMessages(String sortCriteria,
[String searchCriteria = 'ALL',
String charset = 'UTF-8',
List<ReturnOption>? returnOptions]) {
final hasReturnOptions = returnOptions != null;
final parser = SortParser(true, hasReturnOptions);
Command cmd;
final buffer = StringBuffer('UID SORT ');
if (hasReturnOptions) {
buffer..write('RETURN (')..write(returnOptions!.join(' '))..write(') ');
}
buffer
..write('(')
..write(sortCriteria)
..write(') ')
..write(charset)
..write(' ')
..write(searchCriteria);
final cmdText = buffer.toString();
buffer.clear();
final sortLines = cmdText.split('\n');
if (sortLines.length == 1) {
cmd = Command(cmdText);
} else {
cmd = Command.withContinuation(sortLines);
}
return sendCommand<SortImapResult>(cmd, parser);
}