listMailboxesByReferenceAndName method

Future<List<Mailbox>> listMailboxesByReferenceAndName(
  1. String referenceName,
  2. String mailboxName, [
  3. List<String>? mailboxPatterns,
  4. List<String>? selectionOptions,
  5. List<ReturnOption>? returnOptions,
])

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 returnStatuses. 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]) {
  referenceName = _encodeMailboxPath(referenceName, true);
  mailboxName = _encodeMailboxPath(mailboxName, true);
  final hasReturnOptions = returnOptions?.isNotEmpty ?? false;
  final hasSelectionOptions = selectionOptions?.isNotEmpty ?? false;
  final hasMailboxPatterns = mailboxPatterns?.isNotEmpty ?? false;
  final buffer = StringBuffer('LIST');
  if (hasSelectionOptions) {
    buffer..write(' (')..write(selectionOptions!.join(' '))..write(')');
  }
  buffer..write(' ')..write(referenceName);
  if (hasMailboxPatterns) {
    buffer
      ..write(' (')
      ..write(
          mailboxPatterns!.map((e) => _encodeMailboxPath(e, true)).join(' '))
      ..write(')');
  } else {
    buffer..write(' ')..write(mailboxName);
  }
  if (hasReturnOptions) {
    buffer..write(' RETURN (')..write(returnOptions!.join(' '))..write(')');
  }
  final cmd = Command(buffer.toString());
  final parser = ListParser(serverInfo,
      isExtended:
          hasSelectionOptions || hasMailboxPatterns || hasReturnOptions,
      hasReturnOptions: hasReturnOptions);
  return sendCommand<List<Mailbox>>(cmd, parser);
}