sortMessages method
Future<SortImapResult>
sortMessages(
- 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, in this case the server must support the ESORT capability.
The server needs to expose the SORT capability for this command to work.
Implementation
Future<SortImapResult> sortMessages(String sortCriteria,
[String searchCriteria = 'ALL',
String charset = 'UTF-8',
List<ReturnOption>? returnOptions]) {
final hasReturnOptions = returnOptions != null;
final parser = SortParser(false, hasReturnOptions);
Command cmd;
final buffer = StringBuffer('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);
}