TF-2510 Validate outside & inline attachment

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2024-01-26 08:18:31 +07:00
committed by Dat H. Pham
parent d98fcf72e0
commit ab717517fd
3 changed files with 21 additions and 10 deletions
+8 -1
View File
@@ -11,6 +11,7 @@ class Attachment with EquatableMixin {
static const String eventICSSubtype = 'ics';
static const String eventCalendarSubtype = 'calendar';
static const String applicationRTFType = 'application/rtf';
final PartId? partId;
final Id? blobId;
@@ -34,7 +35,13 @@ class Attachment with EquatableMixin {
bool hasCid() => cid != null && cid?.isNotEmpty == true;
bool isInlined() => disposition == ContentDisposition.inline;
bool isDispositionInlined() => disposition == ContentDisposition.inline;
bool isDispositionAttachment() => disposition == ContentDisposition.attachment;
bool isDispositionAttachmentNoCID() => isDispositionAttachment() && noCid();
bool isApplicationRTFInlined() => type?.mimeType == applicationRTFType && isDispositionInlined();
String getDownloadUrl(String baseDownloadUrl, AccountId accountId) {
final downloadUriTemplate = UriTemplate(baseDownloadUrl);
@@ -27,4 +27,10 @@ extension AttachmentExtension on Attachment {
disposition: disposition ?? this.disposition
);
}
bool isOutsideAttachment(List<Attachment> htmlBodyAttachments) {
return (isDispositionAttachmentNoCID() || !isDispositionInlined()) &&
!isApplicationRTFInlined() &&
!htmlBodyAttachments.include(this);
}
}
@@ -2,6 +2,7 @@
import 'package:collection/collection.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:model/email/attachment.dart';
import 'package:model/extensions/attachment_extension.dart';
extension ListAttachmentExtension on List<Attachment> {
@@ -14,21 +15,18 @@ extension ListAttachmentExtension on List<Attachment> {
return 0;
}
List<Attachment> getListAttachmentsDisplayedOutside(List<Attachment>? htmlBodyAttachments) {
return where((attachment) => _validateOutsideAttachment(attachment, htmlBodyAttachments)).toList();
List<Attachment> getListAttachmentsDisplayedOutside(List<Attachment> htmlBodyAttachments) {
return where((attachment) => attachment.isOutsideAttachment(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) {
bool include(Attachment newAttachment) {
final matchedAttachment = firstWhereOrNull((attachment) => attachment.blobId == newAttachment.blobId);
return matchedAttachment != null;
}
List<Attachment> get listAttachmentsDisplayedInContent => where((attachment) => attachment.hasCid()).toList();
List<Attachment> get listAttachmentsDisplayedInContent =>
where((attachment) => attachment.hasCid() && attachment.isDispositionInlined())
.toList();
Map<String, String> toMapCidImageDownloadUrl({
required AccountId accountId,