TF-105 [BUG] Fix loading is blinking when reading email
This commit is contained in:
@@ -9,5 +9,5 @@ extension EmailBodyPartExtension on EmailBodyPart {
|
||||
name: name,
|
||||
type: type,
|
||||
cid: cid,
|
||||
disposition: disposition);
|
||||
disposition: disposition.toContentDisposition());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/email/email_property.dart';
|
||||
import 'package:model/model.dart';
|
||||
@@ -22,15 +24,6 @@ extension EmailExtension on Email {
|
||||
return listEmailAddress;
|
||||
}
|
||||
|
||||
EmailContent toEmailContent() {
|
||||
return EmailContent(
|
||||
id,
|
||||
htmlBody: htmlBody,
|
||||
attachments: attachments,
|
||||
bodyValues: bodyValues
|
||||
);
|
||||
}
|
||||
|
||||
Email updatedEmail({Map<KeyWordIdentifier, bool>? newKeywords}) {
|
||||
return Email(
|
||||
id,
|
||||
@@ -86,4 +79,32 @@ extension EmailExtension on Email {
|
||||
mailboxIds: updatedProperties.contain(EmailProperty.mailboxIds) ? newEmail.mailboxIds : mailboxIds,
|
||||
);
|
||||
}
|
||||
|
||||
List<EmailContent> get emailContentList {
|
||||
final newHtmlBody = htmlBody
|
||||
?.where((emailBody) => emailBody.partId != null && emailBody.type != null)
|
||||
.toList() ?? <EmailBodyPart>[];
|
||||
|
||||
final mapHtmlBody = Map<PartId, MediaType>.fromIterable(
|
||||
newHtmlBody,
|
||||
key: (emailBody) => emailBody.partId!,
|
||||
value: (emailBody) => emailBody.type!,
|
||||
);
|
||||
|
||||
final emailContents = bodyValues?.entries
|
||||
.map((entries) => EmailContent(mapHtmlBody[entries.key].toEmailContentType(), entries.value.value))
|
||||
.toList();
|
||||
|
||||
return emailContents ?? [];
|
||||
}
|
||||
|
||||
List<Attachment> get allAttachments {
|
||||
if (attachments != null) {
|
||||
return attachments!
|
||||
.where((element) => element.disposition != null)
|
||||
.map((item) => item.toAttachment())
|
||||
.toList();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:model/email/email_content_type.dart';
|
||||
|
||||
extension MediaTypeExtension on MediaType? {
|
||||
|
||||
EmailContentType toEmailContentType() {
|
||||
if (this == null) {
|
||||
return EmailContentType.textHtml;
|
||||
} else {
|
||||
switch(this!.mimeType) {
|
||||
case 'text/html':
|
||||
return EmailContentType.textHtml;
|
||||
case 'text/plain':
|
||||
return EmailContentType.textPlain;
|
||||
default:
|
||||
return EmailContentType.other;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user