TF-2331 Fix Read receipt includes weird attachments that are impossible to download

(cherry picked from commit 72ae6553ea53fa4bbba74bfdb1c9a3ec82103fc0)
This commit is contained in:
dab246
2023-11-22 16:21:35 +07:00
committed by Dat H. Pham
parent 34db6f893d
commit a352bd5ada
7 changed files with 25 additions and 11 deletions
@@ -133,6 +133,8 @@ extension EmailExtension on Email {
return emailContents ?? [];
}
List<Attachment> get htmlBodyAttachments => htmlBody?.map((item) => item.toAttachment()).toList() ?? [];
List<Attachment> get allAttachments => attachments?.map((item) => item.toAttachment()).toList() ?? [];
List<Attachment> get attachmentsWithCid => allAttachments.where((attachment) => attachment.hasCid()).toList();
@@ -1,4 +1,5 @@
import 'package:collection/collection.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:model/email/attachment.dart';
@@ -13,7 +14,19 @@ extension ListAttachmentExtension on List<Attachment> {
return 0;
}
List<Attachment> get listAttachmentsDisplayedOutSide => where((attachment) => attachment.noCid() || !attachment.isInlined()).toList();
List<Attachment> getListAttachmentsDisplayedOutside(List<Attachment>? htmlBodyAttachments) {
return where((attachment) => _validateOutsideAttachment(attachment, htmlBodyAttachments)).toList();
}
bool _validateOutsideAttachment(Attachment attachment, List<Attachment>? htmlBodyAttachments) {
final result = (attachment.noCid() || !attachment.isInlined()) && (htmlBodyAttachments == null || !htmlBodyAttachments._include(attachment));
return result;
}
bool _include(Attachment newAttachment) {
final matchedAttachment = firstWhereOrNull((attachment) => attachment.blobId == newAttachment.blobId);
return matchedAttachment != null;
}
List<Attachment> get listAttachmentsDisplayedInContent => where((attachment) => attachment.hasCid()).toList();