flagMessage method Null safety

Future<void> flagMessage(
  1. MimeMessage message,
  2. {bool? isSeen,
  3. bool? isFlagged,
  4. bool? isAnswered,
  5. bool? isForwarded,
  6. bool? isDeleted,
  7. @Deprecated('use isReadRecieptSent instead') bool? isMdnSent,
  8. bool? isReadReceiptSent}
)

Flags the message with the specified flags.

Set any bool parameter to either true or false if you want to change the corresponding flag. Keep a parameter null to not change the corresponding flag.

Implementation

Future<void> flagMessage(
  MimeMessage message, {
  bool? isSeen,
  bool? isFlagged,
  bool? isAnswered,
  bool? isForwarded,
  bool? isDeleted,
  @Deprecated('use isReadRecieptSent instead') bool? isMdnSent,
  bool? isReadReceiptSent,
}) {
  if (isSeen != null) {
    message.isSeen = isSeen;
  }
  if (isFlagged != null) {
    message.isFlagged = isFlagged;
  }
  if (isAnswered != null) {
    message.isAnswered = isAnswered;
  }
  if (isForwarded != null) {
    message.isForwarded = isForwarded;
  }
  if (isDeleted != null) {
    message.isDeleted = isDeleted;
  }
  if (isMdnSent != null) {
    message.isReadReceiptSent = isMdnSent;
  }
  if (isReadReceiptSent != null) {
    message.isReadReceiptSent = isReadReceiptSent;
  }
  if (message.flags != null) {
    final sequence = MessageSequence.fromMessage(message);
    final flags = [...message.flags!];
    flags.remove(MessageFlags.recent);
    return store(sequence, flags, action: StoreAction.replace);
  } else {
    throw MailException(this, 'No message flags defined');
  }
}