getAlternativePart method

  1. @override
MimePart? getAlternativePart(
  1. MediaSubtype subtype
)
override

Searches for this the given subtype as a part of a Multipart/Alternative mime part.

This is useful if you want to check for your preferred rendering format present as an alternative.

Implementation

@override
MimePart? getAlternativePart(MediaSubtype subtype) {
  final match = super.getAlternativePart(subtype);
  if (match == null) {
    if (mediaType.sub == subtype) {
      return this;
    }
    final partsByFetchId = _individualParts;
    final structure = body;
    if (partsByFetchId != null && structure != null) {
      final alternativeBodyPart =
          structure.findFirst(MediaSubtype.multipartAlternative);
      if (alternativeBodyPart != null) {
        final matchBodyPart = alternativeBodyPart.findFirst(subtype);
        if (matchBodyPart != null) {
          return partsByFetchId[matchBodyPart.fetchId];
        }
      }
    }
  }
  return match;
}