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