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 f1fda99
Show file tree
Hide file tree
Showing 30 changed files with 58 additions and 617 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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 @@ -304,15 +303,4 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
Future<EmailRecoveryAction> getRestoredDeletedMessage(EmailRecoveryActionId emailRecoveryActionId) {
throw UnimplementedError();
}

@override
Future<void> downloadMessageAsEML(
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
Id blobId,
String subjectEmail
) {
throw UnimplementedError();
}
}
49 changes: 1 addition & 48 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,15 +76,8 @@ 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,
);
EmailAPI(this._httpClient, this._downloadManager, this._dioClient, this._uuid);

Future<Email> getEmailContent(Session session, AccountId accountId, EmailId emailId) async {
final processingInvocation = ProcessingInvocation();
Expand Down Expand Up @@ -742,43 +734,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.

2 changes: 0 additions & 2 deletions lib/features/email/domain/exceptions/email_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ class EmptyEmailContentException implements Exception {}

class NotFoundEmailRecoveryActionException implements Exception {}

class NotFoundByteFileDownloadedException implements Exception {}

class NotFoundEmailBlobIdException implements Exception {}
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.

Loading

0 comments on commit f1fda99

Please sign in to comment.