TF-3449 Cleanup EmailExtension & PresentationEmailExtension

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-02-10 11:07:54 +07:00
committed by Dat H. Pham
parent 77a62a2711
commit f40056ea99
2 changed files with 94 additions and 226 deletions
+84 -82
View File
@@ -4,9 +4,14 @@ import 'dart:convert';
import 'package:core/domain/extensions/datetime_extension.dart'; import 'package:core/domain/extensions/datetime_extension.dart';
import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart'; import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_body_part.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_body_value.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_header.dart';
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart'; import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart'; import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
@@ -82,30 +87,9 @@ extension EmailExtension on Email {
} }
Email updatedEmail({Map<KeyWordIdentifier, bool>? newKeywords, Map<MailboxId, bool>? newMailboxIds}) { Email updatedEmail({Map<KeyWordIdentifier, bool>? newKeywords, Map<MailboxId, bool>? newMailboxIds}) {
return Email( return copyWith(
id: id, keywords: newKeywords,
blobId: blobId, mailboxIds: newMailboxIds,
keywords: newKeywords ?? keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: newMailboxIds ?? mailboxIds,
htmlBody: htmlBody,
bodyValues: bodyValues,
headerUserAgent: headerUserAgent,
attachments: attachments,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
); );
} }
@@ -113,9 +97,10 @@ extension EmailExtension on Email {
SelectMode selectMode = SelectMode.INACTIVE, SelectMode selectMode = SelectMode.INACTIVE,
String? searchSnippetSubject, String? searchSnippetSubject,
String? searchSnippetPreview, String? searchSnippetPreview,
EmailId? emailId,
}) { }) {
return PresentationEmail( return PresentationEmail(
id: id, id: emailId ?? id,
blobId: blobId, blobId: blobId,
keywords: keywords, keywords: keywords,
size: size, size: size,
@@ -208,69 +193,86 @@ extension EmailExtension on Email {
EmailId? emailId, EmailId? emailId,
} }
) { ) {
return PresentationEmail( return toPresentationEmail(selectMode: selectMode, emailId: emailId);
id: emailId ?? id,
blobId: blobId,
keywords: keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: mailboxIds,
selectMode: selectMode,
emailHeader: headers?.toList(),
bodyValues: bodyValues,
htmlBody: htmlBody,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
);
} }
Email updateEmailHeaderMdn( Email updateEmailHeaderMdn(
Map<IndividualHeaderIdentifier, String?> value, Map<IndividualHeaderIdentifier, String?> value,
) { ) {
return copyWith(headerMdn: value);
}
Email copyWith({
EmailId? id,
Id? blobId,
ThreadId? threadId,
Map<MailboxId, bool>? mailboxIds,
Map<KeyWordIdentifier, bool>? keywords,
UnsignedInt? size,
UTCDate? receivedAt,
Set<EmailHeader>? headers,
MessageIdsHeaderValue? messageId,
MessageIdsHeaderValue? inReplyTo,
MessageIdsHeaderValue? references,
String? subject,
UTCDate? sentAt,
bool? hasAttachment,
String? preview,
Set<EmailAddress>? sender,
Set<EmailAddress>? from,
Set<EmailAddress>? to,
Set<EmailAddress>? cc,
Set<EmailAddress>? bcc,
Set<EmailAddress>? replyTo,
Set<EmailBodyPart>? textBody,
Set<EmailBodyPart>? htmlBody,
Set<EmailBodyPart>? attachments,
EmailBodyPart? bodyStructure,
Map<PartId, EmailBodyValue>? bodyValues,
Map<IndividualHeaderIdentifier, String?>? headerUserAgent,
Map<IndividualHeaderIdentifier, String?>? headerMdn,
Map<IndividualHeaderIdentifier, String?>? headerCalendarEvent,
Map<IndividualHeaderIdentifier, String?>? sMimeStatusHeader,
Map<IndividualHeaderIdentifier, String?>? identityHeader,
Map<IndividualHeaderIdentifier, String?>? xPriorityHeader,
Map<IndividualHeaderIdentifier, String?>? importanceHeader,
Map<IndividualHeaderIdentifier, String?>? priorityHeader,
}) {
return Email( return Email(
id: id, id: id ?? this.id,
blobId: blobId, blobId: blobId ?? this.blobId,
threadId: threadId, threadId: threadId ?? this.threadId,
mailboxIds: mailboxIds, mailboxIds: mailboxIds ?? this.mailboxIds,
keywords: keywords, keywords: keywords ?? this.keywords,
size: size, size: size ?? this.size,
receivedAt: receivedAt, receivedAt: receivedAt ?? this.receivedAt,
headers: headers, headers: headers ?? this.headers,
messageId: messageId, messageId: messageId ?? this.messageId,
inReplyTo: inReplyTo, inReplyTo: inReplyTo ?? this.inReplyTo,
references: references, references: references ?? this.references,
subject: subject, subject: subject ?? this.subject,
sentAt: sentAt, sentAt: sentAt ?? this.sentAt,
hasAttachment: hasAttachment, hasAttachment: hasAttachment ?? this.hasAttachment,
preview: preview, preview: preview ?? this.preview,
sender: sender, sender: sender ?? this.sender,
from: from, from: from ?? this.from,
to: to, to: to ?? this.to,
cc: cc, cc: cc ?? this.cc,
bcc: bcc, bcc: bcc ?? this.bcc,
replyTo: replyTo, replyTo: replyTo ?? this.replyTo,
textBody: textBody, textBody: textBody ?? this.textBody,
htmlBody: htmlBody, htmlBody: htmlBody ?? this.htmlBody,
attachments: attachments, attachments: attachments ?? this.attachments,
bodyStructure: bodyStructure, bodyStructure: bodyStructure ?? this.bodyStructure,
bodyValues: bodyValues, bodyValues: bodyValues ?? this.bodyValues,
headerUserAgent: headerUserAgent, headerUserAgent: headerUserAgent ?? this.headerUserAgent,
headerMdn: value, headerMdn: headerMdn ?? this.headerMdn,
headerCalendarEvent: headerCalendarEvent, headerCalendarEvent: headerCalendarEvent ?? this.headerCalendarEvent,
xPriorityHeader: xPriorityHeader, sMimeStatusHeader: sMimeStatusHeader ?? this.sMimeStatusHeader,
importanceHeader: importanceHeader, identityHeader: identityHeader ?? this.identityHeader,
priorityHeader: priorityHeader, xPriorityHeader: xPriorityHeader ?? this.xPriorityHeader,
importanceHeader: importanceHeader ?? this.importanceHeader,
priorityHeader: priorityHeader ?? this.priorityHeader,
); );
} }
} }
@@ -61,59 +61,17 @@ extension PresentationEmailExtension on PresentationEmail {
Set<EmailAddress> get listEmailAddressSender => from.asSet()..addAll(replyTo.asSet()); Set<EmailAddress> get listEmailAddressSender => from.asSet()..addAll(replyTo.asSet());
PresentationEmail toggleSelect() { PresentationEmail toggleSelect() {
return PresentationEmail( return copyWith(
id: id, selectMode: selectMode == SelectMode.INACTIVE
blobId: blobId, ? SelectMode.ACTIVE
keywords: keywords, : SelectMode.INACTIVE,
size: size, )
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: mailboxIds,
selectMode: selectMode == SelectMode.INACTIVE ? SelectMode.ACTIVE : SelectMode.INACTIVE,
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
)
..searchSnippetSubject = searchSnippetSubject ..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview; ..searchSnippetPreview = searchSnippetPreview;
} }
PresentationEmail toSelectedEmail({required SelectMode selectMode}) { PresentationEmail toSelectedEmail({required SelectMode selectMode}) {
return PresentationEmail( return copyWith(selectMode: selectMode)
id: id,
blobId: blobId,
keywords: keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: mailboxIds,
selectMode: selectMode,
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
)
..searchSnippetSubject = searchSnippetSubject ..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview; ..searchSnippetPreview = searchSnippetPreview;
} }
@@ -155,30 +113,7 @@ extension PresentationEmailExtension on PresentationEmail {
final matchedMailbox = findMailboxContain(mapMailboxes); final matchedMailbox = findMailboxContain(mapMailboxes);
return PresentationEmail( return copyWith(mailboxContain: matchedMailbox)
id: id,
blobId: blobId,
keywords: keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: mailboxIds,
selectMode: selectMode,
routeWeb: routeWeb,
mailboxContain: matchedMailbox,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
)
..searchSnippetSubject = searchSnippetSubject ..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview; ..searchSnippetPreview = searchSnippetPreview;
} }
@@ -197,30 +132,7 @@ extension PresentationEmailExtension on PresentationEmail {
} }
PresentationEmail withRouteWeb(Uri routeWeb) { PresentationEmail withRouteWeb(Uri routeWeb) {
return PresentationEmail( return copyWith(routeWeb: routeWeb)
id: id,
blobId: blobId,
keywords: keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: mailboxIds,
selectMode: selectMode,
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
)
..searchSnippetSubject = searchSnippetSubject ..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview; ..searchSnippetPreview = searchSnippetPreview;
} }
@@ -229,59 +141,13 @@ extension PresentationEmailExtension on PresentationEmail {
final combinedMap = {...(keywords ?? {}), ...newKeywords}; final combinedMap = {...(keywords ?? {}), ...newKeywords};
combinedMap.removeWhere((key, value) => !value); combinedMap.removeWhere((key, value) => !value);
log('PresentationEmailExtension::updateKeywords:combinedMap = $combinedMap'); log('PresentationEmailExtension::updateKeywords:combinedMap = $combinedMap');
return PresentationEmail( return copyWith(keywords: combinedMap)
id: id,
blobId: blobId,
keywords: combinedMap,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: mailboxIds,
selectMode: selectMode,
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
)
..searchSnippetSubject = searchSnippetSubject ..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview; ..searchSnippetPreview = searchSnippetPreview;
} }
PresentationEmail syncPresentationEmail({PresentationMailbox? mailboxContain, Uri? routeWeb}) { PresentationEmail syncPresentationEmail({PresentationMailbox? mailboxContain, Uri? routeWeb}) {
return PresentationEmail( return copyWith(routeWeb: routeWeb, mailboxContain: mailboxContain)
id: id,
blobId: blobId,
keywords: keywords,
size: size,
receivedAt: receivedAt,
hasAttachment: hasAttachment,
preview: preview,
subject: subject,
sentAt: sentAt,
from: from,
to: to,
cc: cc,
bcc: bcc,
replyTo: replyTo,
mailboxIds: mailboxIds,
selectMode: selectMode,
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent,
xPriorityHeader: xPriorityHeader,
importanceHeader: importanceHeader,
priorityHeader: priorityHeader,
)
..searchSnippetSubject = searchSnippetSubject ..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview; ..searchSnippetPreview = searchSnippetPreview;
} }