collectContentInfo method Null safety

void collectContentInfo(
  1. ContentDisposition disposition,
  2. List<ContentInfo> result,
  3. String? fetchId,
  4. {bool? reverse,
  5. bool? complete}
)

Adds the matching disposition header with the specified disposition of this part and this children parts to the result.

Optionally set reverse to true to add all parts that do not match the specified disposition. Set complete to false to skip the included messages parts.

Implementation

void collectContentInfo(
    ContentDisposition disposition, List<ContentInfo> result, String? fetchId,
    {bool? reverse, bool? complete}) {
  reverse ??= false;
  complete ??= true;
  final header = getHeaderContentDisposition();
  final isMessage = getHeaderContentType()?.mediaType.isMessage ?? false;
  if ((!reverse && header?.disposition == disposition) ||
      (reverse && header?.disposition != disposition)) {
    final info = ContentInfo(fetchId ?? '')
      ..contentDisposition = header
      ..contentType = getHeaderContentType()
      ..cid = _getLowerCaseHeaderValue('content-id');
    result.add(info);
  }
  if (complete || !isMessage) {
    if (parts?.isNotEmpty ?? false) {
      for (var i = 0; i < parts!.length; i++) {
        final part = parts![i];
        final partFetchId = mediaType.sub == MediaSubtype.messageRfc822
            ? fetchId
            : fetchId != null
                ? '$fetchId.${i + 1}'
                : '${i + 1}';
        part.collectContentInfo(disposition, result, partFetchId,
            reverse: reverse, complete: complete);
      }
    }
  }
}