TF-4050 Preview and download uploaded file in composer on web

This commit is contained in:
dab246
2025-11-07 01:12:20 +07:00
committed by Dat H. Pham
parent ecd3ac0295
commit 972b20ec16
72 changed files with 2438 additions and 1751 deletions
@@ -1 +0,0 @@
class DownloadAttachmentInteractorIsNull implements Exception {}
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:core/data/network/download/downloaded_response.dart';
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
import 'package:dio/dio.dart';
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
@@ -12,8 +11,6 @@ import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:model/account/account_request.dart';
import 'package:model/email/attachment.dart';
import 'package:model/email/email_content.dart';
import 'package:model/email/mark_star_action.dart';
import 'package:model/email/read_actions.dart';
@@ -52,14 +49,6 @@ abstract class EmailRepository {
ReadActions readActions,
);
Future<DownloadedResponse> exportAttachment(
Attachment attachment,
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
CancelToken cancelToken
);
Future<({
List<EmailId> emailIdsSuccess,
Map<Id, SetError> mapErrors,
@@ -170,14 +159,5 @@ abstract class EmailRepository {
Future<void> printEmail(EmailPrint emailPrint);
Future<DownloadedResponse> exportAllAttachments(
AccountId accountId,
EmailId emailId,
String baseDownloadAllUrl,
String outputFileName,
AccountRequest accountRequest,
{CancelToken? cancelToken}
);
Future<String> generateEntireMessageAsDocument(ViewEntireMessageRequest entireMessageRequest);
}
@@ -1,54 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dio/dio.dart';
import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart';
class StartDownloadAllAttachmentsForWeb extends UIState {
StartDownloadAllAttachmentsForWeb(this.taskId, this.attachment, {this.cancelToken});
final DownloadTaskId taskId;
final Attachment attachment;
final CancelToken? cancelToken;
@override
List<Object?> get props => [taskId, attachment, cancelToken];
}
class DownloadingAllAttachmentsForWeb extends LoadingState {
DownloadingAllAttachmentsForWeb(
this.taskId,
this.fileName,
this.progress,
this.downloaded,
this.total,
);
final DownloadTaskId taskId;
final String fileName;
final double progress;
final int downloaded;
final int total;
@override
List<Object?> get props => [taskId, fileName, progress, downloaded, total];
}
class DownloadAllAttachmentsForWebSuccess extends UIState {
DownloadAllAttachmentsForWebSuccess({required this.taskId});
final DownloadTaskId taskId;
@override
List<Object> get props => [taskId];
}
class DownloadAllAttachmentsForWebFailure extends FeatureFailure {
DownloadAllAttachmentsForWebFailure({super.exception, required this.taskId, this.cancelToken});
final DownloadTaskId taskId;
final CancelToken? cancelToken;
@override
List<Object?> get props => [exception, taskId, cancelToken];
}
@@ -1,77 +0,0 @@
import 'dart:typed_data';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dio/dio.dart';
import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart';
class IdleDownloadAttachmentForWeb extends UIState {}
class StartDownloadAttachmentForWeb extends UIState {
final DownloadTaskId taskId;
final Attachment attachment;
final CancelToken? cancelToken;
final bool previewerSupported;
StartDownloadAttachmentForWeb(this.taskId, this.attachment, [this.cancelToken, this.previewerSupported = false]);
@override
List<Object?> get props => [taskId, attachment, cancelToken, previewerSupported];
}
class DownloadingAttachmentForWeb extends UIState {
final DownloadTaskId taskId;
final Attachment attachment;
final double progress;
final int downloaded;
final int total;
DownloadingAttachmentForWeb(
this.taskId,
this.attachment,
this.progress,
this.downloaded,
this.total
);
@override
List<Object> get props => [
taskId,
attachment,
progress,
downloaded,
total
];
}
class DownloadAttachmentForWebSuccess extends UIState {
final DownloadTaskId taskId;
final Attachment attachment;
final Uint8List bytes;
final bool previewerSupported;
DownloadAttachmentForWebSuccess(this.taskId, this.attachment, this.bytes, this.previewerSupported);
@override
List<Object> get props => [taskId, attachment, bytes, previewerSupported];
}
class DownloadAttachmentForWebFailure extends FeatureFailure {
final DownloadTaskId? taskId;
final Attachment? attachment;
final CancelToken? cancelToken;
DownloadAttachmentForWebFailure({
this.attachment,
this.taskId,
this.cancelToken,
super.exception
});
@override
List<Object?> get props => [attachment, taskId, cancelToken, ...super.props];
}
@@ -1,18 +0,0 @@
import 'package:core/data/network/download/downloaded_response.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class ExportingAllAttachments extends LoadingState {}
class ExportAllAttachmentsSuccess extends UIState {
ExportAllAttachmentsSuccess(this.downloadedResponse);
final DownloadedResponse downloadedResponse;
@override
List<Object> get props => [downloadedResponse];
}
class ExportAllAttachmentsFailure extends FeatureFailure {
ExportAllAttachmentsFailure({super.exception});
}
@@ -1,17 +0,0 @@
import 'package:core/data/network/download/downloaded_response.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class ExportAttachmentSuccess extends UIState {
final DownloadedResponse downloadedResponse;
ExportAttachmentSuccess(this.downloadedResponse);
@override
List<Object> get props => [downloadedResponse];
}
class ExportAttachmentFailure extends FeatureFailure {
ExportAttachmentFailure(dynamic exception) : super(exception: exception);
}
@@ -1,40 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:model/email/attachment.dart';
class GettingHtmlContentFromAttachment extends LoadingState {
GettingHtmlContentFromAttachment({required this.attachment});
final Attachment attachment;
@override
List<Object?> get props => [attachment];
}
class GetHtmlContentFromAttachmentSuccess extends UIState {
GetHtmlContentFromAttachmentSuccess({
required this.sanitizedHtmlContent,
required this.htmlAttachmentTitle,
required this.attachment,
});
final String sanitizedHtmlContent;
final String htmlAttachmentTitle;
final Attachment attachment;
@override
List<Object?> get props => [
sanitizedHtmlContent,
htmlAttachmentTitle,
attachment,
];
}
class GetHtmlContentFromAttachmentFailure extends FeatureFailure {
GetHtmlContentFromAttachmentFailure({super.exception, required this.attachment});
final Attachment attachment;
@override
List<Object?> get props => [attachment];
}
@@ -1,27 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:tmail_ui_user/features/email/presentation/model/eml_previewer.dart';
class GettingPreviewEmailEMLContentShared extends LoadingState {}
class GetPreviewEmailEMLContentSharedSuccess extends UIState {
final EMLPreviewer emlPreviewer;
GetPreviewEmailEMLContentSharedSuccess(this.emlPreviewer);
@override
List<Object?> get props => [emlPreviewer];
}
class GetPreviewEmailEMLContentSharedFailure extends FeatureFailure {
final String? keyStored;
GetPreviewEmailEMLContentSharedFailure({
this.keyStored,
dynamic exception,
}) : super(exception: exception);
@override
List<Object?> get props => [keyStored, exception];
}
@@ -1,26 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:tmail_ui_user/features/email/presentation/model/eml_previewer.dart';
class GettingPreviewEMLContentInMemory extends LoadingState {}
class GetPreviewEMLContentInMemorySuccess extends UIState {
final EMLPreviewer emlPreviewer;
GetPreviewEMLContentInMemorySuccess(this.emlPreviewer);
@override
List<Object?> get props => [emlPreviewer];
}
class GetPreviewEMLContentInMemoryFailure extends FeatureFailure {
final String? keyStored;
GetPreviewEMLContentInMemoryFailure({
this.keyStored,
dynamic exception,
}) : super(exception: exception);
@override
List<Object?> get props => [keyStored, exception];
}
@@ -1,11 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class MovingPreviewEmailEMLContentFromPersistentToMemory extends LoadingState {}
class MovePreviewEmailEMLContentFromPersistentToMemorySuccess extends UIState {}
class MovePreviewEmailEMLContentFromPersistentToMemoryFailure extends FeatureFailure {
MovePreviewEmailEMLContentFromPersistentToMemoryFailure(dynamic exception) : super(exception: exception);
}
@@ -1,37 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
class ParsingEmailByBlobId extends LoadingState {}
class ParseEmailByBlobIdSuccess extends UIState {
final AccountId? accountId;
final Session? session;
final String ownEmailAddress;
final Email email;
final Id blobId;
ParseEmailByBlobIdSuccess({
required this.email,
required this.blobId,
required this.accountId,
required this.session,
required this.ownEmailAddress,
});
@override
List<Object?> get props => [
email,
blobId,
accountId,
session,
ownEmailAddress,
];
}
class ParseEmailByBlobIdFailure extends FeatureFailure {
ParseEmailByBlobIdFailure(dynamic exception) : super(exception: exception);
}
@@ -1,34 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:tmail_ui_user/features/email/presentation/model/eml_previewer.dart';
class PreviewingEmailFromEmlFile extends LoadingState {}
class PreviewEmailFromEmlFileSuccess extends UIState {
final EMLPreviewer emlPreviewer;
final AccountId? accountId;
final Session? session;
final String ownEmailAddress;
PreviewEmailFromEmlFileSuccess(
this.emlPreviewer,
this.accountId,
this.session,
this.ownEmailAddress,
);
@override
List<Object?> get props => [
emlPreviewer,
accountId,
session,
ownEmailAddress,
];
}
class PreviewEmailFromEmlFileFailure extends FeatureFailure {
PreviewEmailFromEmlFileFailure(dynamic exception)
: super(exception: exception);
}
@@ -1,11 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class RemovingPreviewEmailEMLContentShared extends LoadingState {}
class RemovePreviewEmailEMLContentSharedSuccess extends UIState {}
class RemovePreviewEmailEMLContentSharedFailure extends FeatureFailure {
RemovePreviewEmailEMLContentSharedFailure(dynamic exception) : super(exception: exception);
}
@@ -1,88 +0,0 @@
import 'dart:async';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:model/account/account_request.dart';
import 'package:model/account/authentication_type.dart';
import 'package:model/account/password.dart';
import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart';
import 'package:tmail_ui_user/features/email/domain/state/download_all_attachments_for_web_state.dart';
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class DownloadAllAttachmentsForWebInteractor {
const DownloadAllAttachmentsForWebInteractor(
this._downloadRepository,
this._accountRepository,
this._authenticationOIDCRepository,
this.credentialRepository,
);
final DownloadRepository _downloadRepository;
final AccountRepository _accountRepository;
final AuthenticationOIDCRepository _authenticationOIDCRepository;
final CredentialRepository credentialRepository;
Stream<Either<Failure, Success>> execute(
AccountId accountId,
EmailId emailId,
String baseDownloadAllUrl,
Attachment attachment,
DownloadTaskId taskId, {
StreamController<Either<Failure, Success>>? onReceiveController,
CancelToken? cancelToken,
}) async* {
try {
yield Right(StartDownloadAllAttachmentsForWeb(
taskId,
attachment,
));
onReceiveController?.add(Right(StartDownloadAllAttachmentsForWeb(
taskId,
attachment,
cancelToken: cancelToken,
)));
final currentAccount = await _accountRepository.getCurrentAccount();
AccountRequest accountRequest;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
accountRequest = AccountRequest.withOidc(token: tokenOidc);
} else {
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
accountRequest = AccountRequest.withBasic(
userName: UserName(authenticationInfoCache.username),
password: Password(authenticationInfoCache.password),
);
}
await _downloadRepository.downloadAllAttachmentsForWeb(
accountId,
emailId,
baseDownloadAllUrl,
attachment.name!,
accountRequest,
taskId,
onReceiveController: onReceiveController,
cancelToken: cancelToken
);
yield Right(DownloadAllAttachmentsForWebSuccess(taskId: taskId));
} catch (e) {
logError('DownloadAllAttachmentsForWebInteractor::execute():EXCEPTION: $e');
yield Left(DownloadAllAttachmentsForWebFailure(
exception: e,
taskId: taskId,
cancelToken: cancelToken,
));
}
}
}
@@ -1,88 +0,0 @@
import 'dart:async';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/account/account_request.dart';
import 'package:model/account/authentication_type.dart';
import 'package:model/account/password.dart';
import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart';
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class DownloadAttachmentForWebInteractor {
final DownloadRepository downloadRepository;
final CredentialRepository credentialRepository;
final AccountRepository _accountRepository;
final AuthenticationOIDCRepository _authenticationOIDCRepository;
DownloadAttachmentForWebInteractor(
this.downloadRepository,
this.credentialRepository,
this._accountRepository,
this._authenticationOIDCRepository);
Stream<Either<Failure, Success>> execute(
DownloadTaskId taskId,
Attachment attachment,
AccountId accountId,
String baseDownloadUrl, {
StreamController<Either<Failure, Success>>? onReceiveController,
CancelToken? cancelToken,
bool previewerSupported = false,
}) async* {
try {
yield Right<Failure, Success>(StartDownloadAttachmentForWeb(taskId, attachment, cancelToken, previewerSupported));
onReceiveController?.add(Right(StartDownloadAttachmentForWeb(taskId, attachment, cancelToken, previewerSupported)));
final currentAccount = await _accountRepository.getCurrentAccount();
AccountRequest? accountRequest;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
accountRequest = AccountRequest.withOidc(token: tokenOidc);
} else {
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
accountRequest = AccountRequest.withBasic(
userName: UserName(authenticationInfoCache.username),
password: Password(authenticationInfoCache.password),
);
}
final bytesDownloaded = await downloadRepository.downloadAttachmentForWeb(
taskId,
attachment,
accountId,
baseDownloadUrl,
accountRequest,
onReceiveController: onReceiveController,
cancelToken: cancelToken
);
yield Right<Failure, Success>(
DownloadAttachmentForWebSuccess(
taskId,
attachment,
bytesDownloaded,
previewerSupported,
)
);
} catch (exception) {
yield Left<Failure, Success>(
DownloadAttachmentForWebFailure(
attachment: attachment,
taskId: taskId,
exception: exception,
cancelToken: cancelToken,
)
);
}
}
}
@@ -1,68 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:model/account/account_request.dart';
import 'package:model/account/authentication_type.dart';
import 'package:model/account/password.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/email/domain/state/export_all_attachments_state.dart';
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
class ExportAllAttachmentsInteractor {
const ExportAllAttachmentsInteractor(
this._emailRepository,
this._accountRepository,
this._authenticationOIDCRepository,
this.credentialRepository,
);
final EmailRepository _emailRepository;
final AccountRepository _accountRepository;
final AuthenticationOIDCRepository _authenticationOIDCRepository;
final CredentialRepository credentialRepository;
Stream<Either<Failure, Success>> execute(
AccountId accountId,
EmailId emailId,
String baseDownloadAllUrl,
String outputFileName,
{CancelToken? cancelToken}
) async* {
try {
yield Right(ExportingAllAttachments());
final currentAccount = await _accountRepository.getCurrentAccount();
AccountRequest accountRequest;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
accountRequest = AccountRequest.withOidc(token: tokenOidc);
} else {
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
accountRequest = AccountRequest.withBasic(
userName: UserName(authenticationInfoCache.username),
password: Password(authenticationInfoCache.password),
);
}
final result = await _emailRepository.exportAllAttachments(
accountId,
emailId,
baseDownloadAllUrl,
outputFileName,
accountRequest,
cancelToken: cancelToken,
);
yield Right(ExportAllAttachmentsSuccess(result));
} catch (e) {
logError('ExportAllAttachmentsInteractor::execute():EXCEPTION: $e');
yield Left(ExportAllAttachmentsFailure(exception: e));
}
}
}
@@ -1,64 +0,0 @@
import 'dart:async';
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/model.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/email/domain/state/export_attachment_state.dart';
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
class ExportAttachmentInteractor {
final EmailRepository emailRepository;
final CredentialRepository credentialRepository;
final AccountRepository _accountRepository;
final AuthenticationOIDCRepository _authenticationOIDCRepository;
ExportAttachmentInteractor(
this.emailRepository,
this.credentialRepository,
this._accountRepository,
this._authenticationOIDCRepository,
);
Stream<Either<Failure, Success>> execute(
Attachment attachment,
AccountId accountId,
String baseDownloadUrl,
CancelToken cancelToken
) async* {
try {
final currentAccount = await _accountRepository.getCurrentAccount();
AccountRequest? accountRequest;
if (currentAccount.authenticationType == AuthenticationType.oidc) {
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
accountRequest = AccountRequest.withOidc(token: tokenOidc);
} else {
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
accountRequest = AccountRequest.withBasic(
userName: UserName(authenticationInfoCache.username),
password: Password(authenticationInfoCache.password),
);
}
final downloadedResponse = await emailRepository.exportAttachment(
attachment,
accountId,
baseDownloadUrl,
accountRequest,
cancelToken
);
yield Right<Failure, Success>(ExportAttachmentSuccess(downloadedResponse));
} catch (exception) {
log('ExportAttachmentInteractor::execute(): exception: $exception');
yield Left<Failure, Success>(ExportAttachmentFailure(exception));
}
}
}
@@ -1,105 +0,0 @@
import 'dart:async';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/string_convert.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart';
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
import 'package:tmail_ui_user/features/email/domain/state/get_html_content_from_attachment_state.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
class GetHtmlContentFromAttachmentInteractor {
GetHtmlContentFromAttachmentInteractor(
this._downloadAttachmentForWebInteractor,
);
final DownloadAttachmentForWebInteractor _downloadAttachmentForWebInteractor;
Stream<Either<Failure, Success>> execute(
AccountId accountId,
Attachment attachment,
DownloadTaskId taskId,
String baseDownloadUrl,
TransformConfiguration transformConfiguration,
) async* {
try {
yield Right(GettingHtmlContentFromAttachment(attachment: attachment));
final downloadState = await _downloadAttachmentForWebInteractor.execute(
taskId,
attachment,
accountId,
baseDownloadUrl,
).last;
Either<Failure, Success>? sanitizeState;
await downloadState.fold(
(failure) {
sanitizeState = Left(GetHtmlContentFromAttachmentFailure(
exception: failure is FeatureFailure ? failure.exception : null,
attachment: attachment,
));
},
(success) async {
if (success is! DownloadAttachmentForWebSuccess) {
sanitizeState = Right(GettingHtmlContentFromAttachment(attachment: attachment));
} else {
final htmlContent = StringConvert.decodeFromBytes(
success.bytes,
charset: success.attachment.charset,
isHtml: true,
);
sanitizeState = await _sanitizeHtmlContent(
htmlContent,
transformConfiguration,
attachment,
);
}
},
);
if (sanitizeState != null) {
yield sanitizeState!;
} else {
yield Left(GetHtmlContentFromAttachmentFailure(
exception: null,
attachment: attachment,
));
}
} catch (e) {
logError('GetHtmlContentFromAttachmentInteractor:exception: $e');
yield Left(GetHtmlContentFromAttachmentFailure(
exception: e,
attachment: attachment,
));
}
}
Future<Either<Failure, Success>?> _sanitizeHtmlContent(
String htmlContent,
TransformConfiguration transformConfiguration,
Attachment attachment,
) async {
try {
final sanitizedHtmlContent = await _downloadAttachmentForWebInteractor
.downloadRepository
.sanitizeHtmlContent(htmlContent, transformConfiguration);
return Right(GetHtmlContentFromAttachmentSuccess(
sanitizedHtmlContent: sanitizedHtmlContent,
htmlAttachmentTitle: attachment.generateFileName(),
attachment: attachment,
));
} catch (e) {
return Left(GetHtmlContentFromAttachmentFailure(
exception: e,
attachment: attachment,
));
}
}
}
@@ -1,27 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:tmail_ui_user/features/email/domain/state/get_preview_email_eml_content_shared_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class GetPreviewEmailEMLContentSharedInteractor {
final DownloadRepository _downloadRepository;
const GetPreviewEmailEMLContentSharedInteractor(this._downloadRepository);
Stream<Either<Failure, Success>> execute(String keyStored) async* {
try {
yield Right<Failure, Success>(GettingPreviewEmailEMLContentShared());
final previewEMLContent = await _downloadRepository
.getPreviewEmailEMLContentShared(keyStored);
yield Right<Failure, Success>(GetPreviewEmailEMLContentSharedSuccess(previewEMLContent));
} catch (e) {
yield Left<Failure, Success>(GetPreviewEmailEMLContentSharedFailure(
keyStored: keyStored,
exception: e,
));
}
}
}
@@ -1,24 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:tmail_ui_user/features/email/domain/state/get_preview_eml_content_in_memory_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class GetPreviewEmlContentInMemoryInteractor {
final DownloadRepository _downloadRepository;
const GetPreviewEmlContentInMemoryInteractor(this._downloadRepository);
Stream<Either<Failure, Success>> execute(String keyStored) async* {
try {
yield Right<Failure, Success>(GettingPreviewEMLContentInMemory());
final emlPreviewer = await _downloadRepository.getPreviewEMLContentInMemory(keyStored);
yield Right<Failure, Success>(GetPreviewEMLContentInMemorySuccess(emlPreviewer));
} catch (e) {
yield Left<Failure, Success>(GetPreviewEMLContentInMemoryFailure(
keyStored: keyStored,
exception: e,
));
}
}
}
@@ -1,27 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:tmail_ui_user/features/email/domain/state/move_preview_eml_content_from_persistent_to_memory_state.dart';
import 'package:tmail_ui_user/features/email/presentation/model/eml_previewer.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class MovePreviewEmlContentFromPersistentToMemoryInteractor {
final DownloadRepository _downloadRepository;
const MovePreviewEmlContentFromPersistentToMemoryInteractor(
this._downloadRepository,
);
Stream<Either<Failure, Success>> execute(EMLPreviewer emlPreviewer) async* {
try {
yield Right<Failure, Success>(MovingPreviewEmailEMLContentFromPersistentToMemory());
await Future.wait([
_downloadRepository.removePreviewEmailEMLContentShared(emlPreviewer.id),
_downloadRepository.storePreviewEMLContentToSessionStorage(emlPreviewer),
]);
yield Right<Failure, Success>(MovePreviewEmailEMLContentFromPersistentToMemorySuccess());
} catch (e) {
yield Left<Failure, Success>(MovePreviewEmailEMLContentFromPersistentToMemoryFailure(e));
}
}
}
@@ -1,40 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:tmail_ui_user/features/email/domain/state/parse_email_by_blob_id_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class ParseEmailByBlobIdInteractor {
final DownloadRepository _downloadRepository;
const ParseEmailByBlobIdInteractor(this._downloadRepository);
Stream<Either<Failure, Success>> execute(
AccountId accountId,
Session session,
String ownEmailAddress,
Id blobId,
) async* {
try {
yield Right<Failure, Success>(ParsingEmailByBlobId());
final emailParsed = await _downloadRepository.parseEmailByBlobIds(
accountId,
{blobId},
);
yield Right<Failure, Success>(ParseEmailByBlobIdSuccess(
email: emailParsed.first,
blobId: blobId,
session: session,
accountId: accountId,
ownEmailAddress: ownEmailAddress,
));
} catch (e) {
yield Left<Failure, Success>(ParseEmailByBlobIdFailure(e));
}
}
}
@@ -1,52 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/platform_info.dart';
import 'package:dartz/dartz.dart';
import 'package:tmail_ui_user/features/email/domain/model/preview_email_eml_request.dart';
import 'package:tmail_ui_user/features/email/domain/state/preview_email_from_eml_file_state.dart';
import 'package:tmail_ui_user/features/email/presentation/model/eml_previewer.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class PreviewEmailFromEmlFileInteractor {
final DownloadRepository _downloadRepository;
const PreviewEmailFromEmlFileInteractor(this._downloadRepository);
Stream<Either<Failure, Success>> execute(
PreviewEmailEMLRequest previewEmailEMLRequest,
) async* {
try {
yield Right<Failure, Success>(PreviewingEmailFromEmlFile());
final previewEMLContent = await _downloadRepository
.generatePreviewEmailEMLContent(previewEmailEMLRequest);
final emlPreviewer = EMLPreviewer(
id: previewEmailEMLRequest.keyStored,
title: previewEmailEMLRequest.title,
content: previewEMLContent,
);
if (PlatformInfo.isWeb) {
if (previewEmailEMLRequest.isShared) {
await _downloadRepository.sharePreviewEmailEMLContent(emlPreviewer);
} else {
await _downloadRepository.storePreviewEMLContentToSessionStorage(
emlPreviewer,
);
}
}
yield Right<Failure, Success>(
PreviewEmailFromEmlFileSuccess(
emlPreviewer,
previewEmailEMLRequest.accountId,
previewEmailEMLRequest.session,
previewEmailEMLRequest.ownEmailAddress,
),
);
} catch (e) {
yield Left<Failure, Success>(PreviewEmailFromEmlFileFailure(e));
}
}
}
@@ -1,21 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:tmail_ui_user/features/email/domain/state/remove_preview_email_eml_content_shared_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
class RemovePreviewEmailEmlContentSharedInteractor {
final DownloadRepository _downloadRepository;
const RemovePreviewEmailEmlContentSharedInteractor(this._downloadRepository);
Stream<Either<Failure, Success>> execute(String keyStored) async* {
try {
yield Right<Failure, Success>(RemovingPreviewEmailEMLContentShared());
await _downloadRepository.removePreviewEmailEMLContentShared(keyStored);
yield Right<Failure, Success>(RemovePreviewEmailEMLContentSharedSuccess());
} catch (e) {
yield Left<Failure, Success>(RemovePreviewEmailEMLContentSharedFailure(e));
}
}
}