Skip to content

Commit

Permalink
TF-825 Synchronize download messages as EML like download attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed May 16, 2024
1 parent 05c67fd commit b0aa59e
Show file tree
Hide file tree
Showing 25 changed files with 53 additions and 591 deletions.
9 changes: 0 additions & 9 deletions lib/features/email/data/datasource/email_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:dio/dio.dart';
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
import 'package:email_recovery/email_recovery/email_recovery_action_id.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/core/user_name.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
Expand Down Expand Up @@ -113,12 +112,4 @@ abstract class EmailDataSource {
Future<EmailRecoveryAction> restoreDeletedMessage(RestoredDeletedMessageRequest restoredDeletedMessageRequest);

Future<EmailRecoveryAction> getRestoredDeletedMessage(EmailRecoveryActionId emailRecoveryActionId);

Future<void> downloadMessageAsEML(
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
Id blobId,
String subjectEmail
);
}
19 changes: 0 additions & 19 deletions lib/features/email/data/datasource_impl/email_datasource_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:email_recovery/email_recovery/email_recovery_action.dart';
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
import 'package:get/get.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/core/user_name.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
Expand Down Expand Up @@ -253,22 +252,4 @@ class EmailDataSourceImpl extends EmailDataSource {
return await emailAPI.getRestoredDeletedMessage(emailRecoveryActionId);
}).catchError(_exceptionThrower.throwException);
}

@override
Future<void> downloadMessageAsEML(
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
Id blobId,
String subjectEmail
) {
return Future.sync(() async {
return await emailAPI.downloadMessageAsEML(
accountId,
baseDownloadUrl,
accountRequest,
blobId,
subjectEmail);
}).catchError(_exceptionThrower.throwException);
}
}
42 changes: 0 additions & 42 deletions lib/features/email/data/network/email_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import 'package:path_provider/path_provider.dart';
import 'package:tmail_ui_user/features/base/mixin/handle_error_mixin.dart';
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart';
import 'package:tmail_ui_user/features/email/data/utils/download_utils.dart';
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
import 'package:tmail_ui_user/features/email/domain/model/move_action.dart';
import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_request.dart';
Expand All @@ -77,14 +76,12 @@ class EmailAPI with HandleSetErrorMixin {
final DownloadManager _downloadManager;
final DioClient _dioClient;
final Uuid _uuid;
final DownloadUtils _downloadUtils;

EmailAPI(
this._httpClient,
this._downloadManager,
this._dioClient,
this._uuid,
this._downloadUtils,
);

Future<Email> getEmailContent(Session session, AccountId accountId, EmailId emailId) async {
Expand Down Expand Up @@ -742,43 +739,4 @@ class EmailAPI with HandleSetErrorMixin {
throw NotFoundEmailRecoveryActionException();
}
}

Future<void> downloadMessageAsEML(
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
Id blobId,
String subjectEmail,
) async {
final authentication = accountRequest.authenticationType == AuthenticationType.oidc
? accountRequest.bearerToken
: accountRequest.basicAuth;

final fileName = _downloadUtils.createEMLFileName(subjectEmail);

final downloadUrl = _downloadUtils.getEMLDownloadUrl(
baseDownloadUrl: baseDownloadUrl,
accountId: accountId,
blobId: blobId,
subject: subjectEmail
);

final headerParam = _dioClient.getHeaders();
headerParam[HttpHeaders.authorizationHeader] = authentication;
headerParam[HttpHeaders.acceptHeader] = DioClient.jmapHeader;

final result = await _dioClient.get(
downloadUrl,
options: Options(
headers: headerParam,
responseType: ResponseType.bytes
)
);

if (result is Uint8List) {
_downloadManager.createAnchorElementDownloadFileWeb(result, fileName);
} else {
throw NotFoundByteFileDownloadedException();
}
}
}
17 changes: 0 additions & 17 deletions lib/features/email/data/repository/email_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:dio/dio.dart';
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
import 'package:email_recovery/email_recovery/email_recovery_action_id.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/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
Expand Down Expand Up @@ -238,20 +237,4 @@ class EmailRepositoryImpl extends EmailRepository {
Future<void> printEmail(EmailPrint emailPrint) {
return _printFileDataSource.printEmail(emailPrint);
}

@override
Future<void> downloadMessageAsEML(
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
Id blobId,
String subjectEmail
) {
return emailDataSource[DataSourceType.network]!.downloadMessageAsEML(
accountId,
baseDownloadUrl,
accountRequest,
blobId,
subjectEmail);
}
}
60 changes: 0 additions & 60 deletions lib/features/email/data/utils/download_utils.dart

This file was deleted.

9 changes: 0 additions & 9 deletions lib/features/email/domain/repository/email_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:dio/dio.dart';
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
import 'package:email_recovery/email_recovery/email_recovery_action_id.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/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
Expand Down Expand Up @@ -116,12 +115,4 @@ abstract class EmailRepository {
Future<EmailRecoveryAction> getRestoredDeletedMessage(EmailRecoveryActionId emailRecoveryActionId);

Future<void> printEmail(EmailPrint emailPrint);

Future<void> downloadMessageAsEML(
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
Id blobId,
String subjectEmail
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:typed_data';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:model/download/download_task_id.dart';
import 'package:model/email/attachment.dart';

Expand Down Expand Up @@ -59,14 +58,14 @@ class DownloadAttachmentForWebSuccess extends UIState {
class DownloadAttachmentForWebFailure extends FeatureFailure {

final DownloadTaskId? taskId;
final Id? attachmentBlobId;
final Attachment? attachment;

DownloadAttachmentForWebFailure({
required this.attachmentBlobId,
this.attachment,
this.taskId,
dynamic exception
}) : super(exception: exception);

@override
List<Object?> get props => [taskId, ...super.props];
List<Object?> get props => [attachment, taskId, ...super.props];
}
11 changes: 0 additions & 11 deletions lib/features/email/domain/state/download_message_as_eml_state.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ViewAttachmentForWebSuccess extends DownloadAttachmentForWebSuccess {

class ViewAttachmentForWebFailure extends DownloadAttachmentForWebFailure {
ViewAttachmentForWebFailure({
required super.attachmentBlobId,
required super.attachment,
super.taskId,
super.exception,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DownloadAttachmentForWebInteractor {
} catch (exception) {
yield Left<Failure, Success>(
DownloadAttachmentForWebFailure(
attachmentBlobId: attachment.blobId,
attachment: attachment,
taskId: taskId,
exception: exception
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ViewAttachmentForWebInteractor {
(failure) {
if (failure is DownloadAttachmentForWebFailure) {
return Left(ViewAttachmentForWebFailure(
attachmentBlobId: attachment.blobId,
attachment: attachment,
taskId: failure.taskId,
exception: failure.exception,
));
Expand Down
7 changes: 0 additions & 7 deletions lib/features/email/presentation/bindings/email_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:tmail_ui_user/features/email/data/repository/email_repository_im
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachments_interactor.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/download_message_as_eml_interactor.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/export_attachment_interactor.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/get_stored_email_state_interactor.dart';
Expand Down Expand Up @@ -71,7 +70,6 @@ class EmailBindings extends BaseBindings {
Get.find<StoreOpenedEmailInteractor>(),
Get.find<ViewAttachmentForWebInteractor>(),
Get.find<PrintEmailInteractor>(),
Get.find<DownloadMessageAsEMLInteractor>(),
));
}

Expand Down Expand Up @@ -154,11 +152,6 @@ class EmailBindings extends BaseBindings {
Get.find<DownloadAttachmentForWebInteractor>()));
Get.lazyPut(() => StoreOpenedEmailInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => PrintEmailInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => DownloadMessageAsEMLInteractor(
Get.find<EmailRepository>(),
Get.find<CredentialRepository>(),
Get.find<AccountRepository>(),
Get.find<AuthenticationOIDCRepository>()));
IdentityInteractorsBindings().dependencies();
}

Expand Down
Loading

0 comments on commit b0aa59e

Please sign in to comment.