listMailboxesByReferenceAndName method
Lists all mailboxes in the path referenceName that match
the given mailboxName that can contain wildcards.
If the server exposes the LIST-STATUS capability, a list of attributes
can be provided with returnOptions.
The LIST command will set the serverInfo.pathSeparator as a side-effect
Implementation
Future<List<Mailbox>> listMailboxesByReferenceAndName(
String referenceName,
String mailboxName, [
List<String>? mailboxPatterns,
List<String>? selectionOptions,
List<ReturnOption>? returnOptions,
]) {
final buffer = StringBuffer('LIST');
final bool hasSelectionOptions;
if (selectionOptions != null && selectionOptions.isNotEmpty) {
hasSelectionOptions = true;
buffer
..write(' (')
..write(selectionOptions.join(' '))
..write(')');
} else {
hasSelectionOptions = false;
}
buffer
..write(' ')
..write(_encodeMailboxPath(referenceName, true));
final bool hasMailboxPatterns;
if (mailboxPatterns != null && mailboxPatterns.isNotEmpty) {
hasMailboxPatterns = true;
buffer
..write(' (')
..write(
mailboxPatterns.map((e) => _encodeMailboxPath(e, true)).join(' '),
)
..write(')');
} else {
hasMailboxPatterns = false;
buffer
..write(' ')
..write(_encodeMailboxPath(mailboxName, true));
}
final bool hasReturnOptions;
if (returnOptions != null && returnOptions.isNotEmpty) {
hasReturnOptions = true;
buffer
..write(' RETURN (')
..write(returnOptions.join(' '))
..write(')');
} else {
hasReturnOptions = false;
}
final cmd = Command(
buffer.toString(),
writeTimeout: defaultWriteTimeout,
responseTimeout: defaultResponseTimeout,
);
final parser = ListParser(
serverInfo,
isExtended: hasSelectionOptions || hasMailboxPatterns || hasReturnOptions,
hasReturnOptions: hasReturnOptions,
);
return sendCommand<List<Mailbox>>(cmd, parser);
}