TF-1718 Handle unsubscribe mail by mailto links

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit f96273c52456ecd758d8bbbafc4d2c7af6ec7921)
This commit is contained in:
dab246
2023-11-16 10:40:58 +07:00
committed by Dat Vu
parent 67f0b702ab
commit 41eb95257d
10 changed files with 95 additions and 3 deletions
@@ -489,6 +489,9 @@ class ComposerController extends BaseController {
isInitialRecipient.value = true;
toAddressExpandMode.value = ExpandMode.COLLAPSE;
}
if (arguments.body?.isNotEmpty == true) {
_getEmailContentFromMailtoUri(arguments.body!);
}
_updateStatusEmailSendButton();
break;
case EmailActionType.reply:
@@ -524,6 +527,21 @@ class ComposerController extends BaseController {
_initAttachments(arguments.attachments ?? []);
_getEmailContentFromSessionStorageBrowser(arguments.emailContents!);
break;
case EmailActionType.composeFromUnsubscribeMailtoLink:
if (arguments.subject != null) {
setSubjectEmail(arguments.subject!);
subjectEmailInputController.text = arguments.subject!;
}
if (arguments.emailAddress != null) {
listToEmailAddress.add(arguments.emailAddress!);
isInitialRecipient.value = true;
toAddressExpandMode.value = ExpandMode.COLLAPSE;
}
if (arguments.body?.isNotEmpty == true) {
_getEmailContentFromUnsubscribeMailtoLink(arguments.body!);
}
_updateStatusEmailSendButton();
break;
default:
break;
}
@@ -1422,6 +1440,26 @@ class ComposerController extends BaseController {
));
}
void _getEmailContentFromMailtoUri(String content) {
log('ComposerController::_getEmailContentFromMailtoUri:content: $content');
consumeState(Stream.value(
Right(GetEmailContentSuccess(
htmlEmailContent: content,
attachments: [],
))
));
}
void _getEmailContentFromUnsubscribeMailtoLink(String content) {
log('ComposerController::_getEmailContentFromUnsubscribeMailtoLink:content: $content');
consumeState(Stream.value(
Right(GetEmailContentSuccess(
htmlEmailContent: content,
attachments: [],
))
));
}
void _getEmailContentFromEmailId({required EmailId emailId, bool isDraftEmail = false}) {
final session = mailboxDashBoardController.sessionCurrent;
final accountId = mailboxDashBoardController.accountId.value;
@@ -47,6 +47,8 @@ class MobileEditorView extends StatelessWidget with EditorViewMixin {
case EmailActionType.editSendingEmail:
case EmailActionType.composeFromContentShared:
case EmailActionType.reopenComposerBrowser:
case EmailActionType.composeFromMailtoUri:
case EmailActionType.composeFromUnsubscribeMailtoLink:
if (contentViewState == null) {
return const SizedBox.shrink();
}
@@ -81,6 +81,8 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
case EmailActionType.editSendingEmail:
case EmailActionType.composeFromContentShared:
case EmailActionType.reopenComposerBrowser:
case EmailActionType.composeFromUnsubscribeMailtoLink:
case EmailActionType.composeFromMailtoUri:
if (contentViewState == null) {
return const SizedBox.shrink();
}
@@ -1407,6 +1407,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
onConfirmAction: () {
if (emailUnsubscribe.value?.httpLinks.isNotEmpty == true) {
_handleUnsubscribeMailByHttpsLink(context, emailUnsubscribe.value!.httpLinks);
} else if (emailUnsubscribe.value?.mailtoLinks.isNotEmpty == true) {
_handleUnsubscribeMailByMailtoLink(context, emailUnsubscribe.value!.mailtoLinks);
}
},
showAsBottomSheet: true,
@@ -1441,4 +1443,16 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
AppLocalizations.of(context).unsubscribedFromThisMailingList);
}
}
void _handleUnsubscribeMailByMailtoLink(BuildContext context, List<String> mailtoLinks) {
log('SingleEmailController::_handleUnsubscribeMailByMailtoLink:mailtoLinks: $mailtoLinks');
final navigationRouter = RouteUtils.generateNavigationRouterFromMailtoLink(mailtoLinks.first);
mailboxDashBoardController.goToComposer(
ComposerArguments.fromUnsubscribeMailtoLink(
emailAddress: navigationRouter.emailAddress,
subject: navigationRouter.subject,
body: navigationRouter.body
)
);
}
}
@@ -18,6 +18,7 @@ class ComposerArguments extends RouterArguments {
final Role? mailboxRole;
final SendingEmail? sendingEmail;
final String? subject;
final String? body;
final MessageIdsHeaderValue? messageId;
final MessageIdsHeaderValue? references;
@@ -31,6 +32,7 @@ class ComposerArguments extends RouterArguments {
this.listSharedMediaFile,
this.sendingEmail,
this.subject,
this.body,
this.messageId,
this.references,
});
@@ -59,11 +61,12 @@ class ComposerArguments extends RouterArguments {
emailAddress: emailAddress
);
factory ComposerArguments.fromMailtoUri({EmailAddress? emailAddress, String? subject}) =>
factory ComposerArguments.fromMailtoUri({EmailAddress? emailAddress, String? subject, String? body}) =>
ComposerArguments(
emailActionType: EmailActionType.composeFromMailtoUri,
emailAddress: emailAddress,
subject: subject,
body: body,
);
factory ComposerArguments.editDraftEmail(PresentationEmail presentationEmail) =>
@@ -136,6 +139,15 @@ class ComposerArguments extends RouterArguments {
? SendingEmailActionType.edit
: SendingEmailActionType.create;
factory ComposerArguments.fromUnsubscribeMailtoLink({EmailAddress? emailAddress, String? subject, String? body}) =>
ComposerArguments(
emailActionType: EmailActionType.composeFromUnsubscribeMailtoLink,
emailAddress: emailAddress,
subject: subject,
body: body,
);
@override
List<Object?> get props => [
emailActionType,
@@ -147,6 +159,7 @@ class ComposerArguments extends RouterArguments {
listSharedMediaFile,
sendingEmail,
subject,
body,
messageId,
references,
];
@@ -425,7 +425,8 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
mailboxDashBoardController.goToComposer(
ComposerArguments.fromMailtoUri(
emailAddress: navigationRouter?.emailAddress,
subject: navigationRouter?.subject
subject: navigationRouter?.subject,
body: navigationRouter?.body
)
);
}