TF-1608 Set references and inReplyTo fields for reply/replyAll email
(cherry picked from commit 775c2485c947567015551c1a2f47272acf4f2ced)
This commit is contained in:
@@ -620,13 +620,14 @@ class ComposerController extends BaseController {
|
||||
}
|
||||
|
||||
Future<Email> _generateEmail(
|
||||
BuildContext context,
|
||||
UserProfile userProfile,
|
||||
{
|
||||
bool asDrafts = false,
|
||||
MailboxId? draftMailboxId,
|
||||
MailboxId? outboxMailboxId
|
||||
}
|
||||
BuildContext context,
|
||||
UserProfile userProfile,
|
||||
{
|
||||
bool asDrafts = false,
|
||||
MailboxId? draftMailboxId,
|
||||
MailboxId? outboxMailboxId,
|
||||
ComposerArguments? arguments,
|
||||
}
|
||||
) async {
|
||||
Set<EmailAddress> listFromEmailAddress = {EmailAddress(null, userProfile.email)};
|
||||
if (identitySelected?.email?.isNotEmpty == true) {
|
||||
@@ -673,6 +674,9 @@ class ComposerController extends BaseController {
|
||||
mapKeywords[KeyWordIdentifier.emailSeen] = true;
|
||||
}
|
||||
|
||||
final inReplyTo = _generateInReplyTo(arguments);
|
||||
final references = _generateReferences(arguments);
|
||||
|
||||
final generatePartId = PartId(_uuid.v1());
|
||||
|
||||
return Email(
|
||||
@@ -682,6 +686,8 @@ class ComposerController extends BaseController {
|
||||
cc: listCcEmailAddress.toSet(),
|
||||
bcc: listBccEmailAddress.toSet(),
|
||||
replyTo: listReplyToEmailAddress,
|
||||
inReplyTo: inReplyTo,
|
||||
references: references,
|
||||
keywords: mapKeywords.isNotEmpty ? mapKeywords : null,
|
||||
subject: subjectEmail.value,
|
||||
htmlBody: {
|
||||
@@ -698,6 +704,31 @@ class ComposerController extends BaseController {
|
||||
);
|
||||
}
|
||||
|
||||
MessageIdsHeaderValue? _generateInReplyTo(ComposerArguments? arguments) {
|
||||
if (arguments?.emailActionType == EmailActionType.reply ||
|
||||
arguments?.emailActionType == EmailActionType.replyAll) {
|
||||
return arguments?.messageId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
MessageIdsHeaderValue? _generateReferences(ComposerArguments? arguments) {
|
||||
if (arguments?.emailActionType == EmailActionType.reply ||
|
||||
arguments?.emailActionType == EmailActionType.replyAll) {
|
||||
Set<String> ids = {};
|
||||
if (arguments?.messageId?.ids.isNotEmpty == true) {
|
||||
ids.addAll(arguments!.messageId!.ids);
|
||||
}
|
||||
if (arguments?.references?.ids.isNotEmpty == true) {
|
||||
ids.addAll(arguments!.references!.ids);
|
||||
}
|
||||
if (ids.isNotEmpty) {
|
||||
return MessageIdsHeaderValue(ids);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<Tuple2<String, List<Attachment>>> _getMapContent(String emailBodyText) async {
|
||||
if (kIsWeb) {
|
||||
return await richTextWebController.refactorContentHasInlineImage(
|
||||
@@ -813,7 +844,13 @@ class ComposerController extends BaseController {
|
||||
final userProfile = mailboxDashBoardController.userProfile.value;
|
||||
|
||||
if (arguments != null && accountId != null && userProfile != null && session != null) {
|
||||
final createdEmail = await _generateEmail(context, userProfile, outboxMailboxId: outboxMailboxId);
|
||||
final createdEmail = await _generateEmail(
|
||||
context,
|
||||
userProfile,
|
||||
outboxMailboxId: outboxMailboxId,
|
||||
arguments: arguments
|
||||
);
|
||||
|
||||
final emailRequest = arguments.emailActionType == EmailActionType.editSendingEmail
|
||||
? arguments.sendingEmail!.toEmailRequest(newEmail: createdEmail)
|
||||
: EmailRequest(
|
||||
@@ -1061,7 +1098,8 @@ class ComposerController extends BaseController {
|
||||
context,
|
||||
userProfile,
|
||||
asDrafts: true,
|
||||
draftMailboxId: draftMailboxId
|
||||
draftMailboxId: draftMailboxId,
|
||||
arguments: arguments,
|
||||
);
|
||||
|
||||
if (arguments.emailActionType == EmailActionType.editDraft) {
|
||||
@@ -1112,6 +1150,7 @@ class ComposerController extends BaseController {
|
||||
userProfile: userProfile,
|
||||
draftMailboxId: draftMailboxId,
|
||||
emailIdEditing: _emailIdEditing,
|
||||
arguments: mailboxDashBoardController.composerArguments,
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1122,7 +1161,8 @@ class ComposerController extends BaseController {
|
||||
event.context,
|
||||
event.userProfile,
|
||||
asDrafts: true,
|
||||
draftMailboxId: event.draftMailboxId
|
||||
draftMailboxId: event.draftMailboxId,
|
||||
arguments: event.arguments
|
||||
);
|
||||
|
||||
if (event.emailIdEditing == null) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
|
||||
|
||||
class SaveToDraftViewEvent extends ViewEvent {
|
||||
final BuildContext context;
|
||||
@@ -13,6 +14,7 @@ class SaveToDraftViewEvent extends ViewEvent {
|
||||
final UserProfile userProfile;
|
||||
final MailboxId draftMailboxId;
|
||||
final EmailId? emailIdEditing;
|
||||
final ComposerArguments? arguments;
|
||||
|
||||
SaveToDraftViewEvent({
|
||||
required this.context,
|
||||
@@ -20,7 +22,8 @@ class SaveToDraftViewEvent extends ViewEvent {
|
||||
required this.accountId,
|
||||
required this.userProfile,
|
||||
required this.draftMailboxId,
|
||||
this.emailIdEditing
|
||||
this.emailIdEditing,
|
||||
this.arguments,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -31,5 +34,6 @@ class SaveToDraftViewEvent extends ViewEvent {
|
||||
userProfile,
|
||||
draftMailboxId,
|
||||
emailIdEditing,
|
||||
arguments,
|
||||
];
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
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/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
@@ -16,6 +17,8 @@ class ComposerArguments extends RouterArguments {
|
||||
final Role? mailboxRole;
|
||||
final SendingEmail? sendingEmail;
|
||||
final String? uri;
|
||||
final MessageIdsHeaderValue? messageId;
|
||||
final MessageIdsHeaderValue? references;
|
||||
|
||||
ComposerArguments({
|
||||
this.emailActionType = EmailActionType.compose,
|
||||
@@ -27,6 +30,8 @@ class ComposerArguments extends RouterArguments {
|
||||
this.listSharedMediaFile,
|
||||
this.sendingEmail,
|
||||
this.uri,
|
||||
this.messageId,
|
||||
this.references,
|
||||
});
|
||||
|
||||
factory ComposerArguments.fromSendingEmail(SendingEmail sendingEmail) =>
|
||||
@@ -83,22 +88,30 @@ class ComposerArguments extends RouterArguments {
|
||||
required PresentationEmail presentationEmail,
|
||||
required String content,
|
||||
Role? mailboxRole,
|
||||
MessageIdsHeaderValue? messageId,
|
||||
MessageIdsHeaderValue? references,
|
||||
}) => ComposerArguments(
|
||||
emailActionType: EmailActionType.reply,
|
||||
presentationEmail: presentationEmail,
|
||||
emailContents: content,
|
||||
mailboxRole: mailboxRole
|
||||
mailboxRole: mailboxRole,
|
||||
messageId: messageId,
|
||||
references: references,
|
||||
);
|
||||
|
||||
factory ComposerArguments.replyAllEmail({
|
||||
required PresentationEmail presentationEmail,
|
||||
required String content,
|
||||
Role? mailboxRole,
|
||||
MessageIdsHeaderValue? messageId,
|
||||
MessageIdsHeaderValue? references,
|
||||
}) => ComposerArguments(
|
||||
emailActionType: EmailActionType.replyAll,
|
||||
presentationEmail: presentationEmail,
|
||||
emailContents: content,
|
||||
mailboxRole: mailboxRole
|
||||
mailboxRole: mailboxRole,
|
||||
messageId: messageId,
|
||||
references: references,
|
||||
);
|
||||
|
||||
factory ComposerArguments.forwardEmail({
|
||||
|
||||
Reference in New Issue
Block a user