Skip to content

Commit

Permalink
TF-3349 Escape messages when print email
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Dec 18, 2024
1 parent 667ed6f commit 92472e7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/features/composer/presentation/composer_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class ComposerBindings extends BaseBindings {
Get.find<PrintUtils>(),
Get.find<ImagePaths>(),
Get.find<FileUtils>(),
Get.find<HtmlAnalyzer>(),
Get.find<CacheExceptionThrower>()
));
Get.lazyPut(() => EmailHiveCacheDataSourceImpl(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import 'package:core/data/model/print_attachment.dart';
import 'package:core/domain/extensions/datetime_extension.dart';
import 'package:core/presentation/extensions/html_extension.dart';
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/file_utils.dart';
import 'package:core/utils/print_utils.dart';
import 'package:filesize/filesize.dart';
import 'package:model/email/attachment.dart';
import 'package:model/extensions/email_extension.dart';
import 'package:tmail_ui_user/features/email/data/datasource/print_file_datasource.dart';
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
import 'package:tmail_ui_user/features/email/domain/model/email_print.dart';
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
Expand All @@ -16,18 +20,23 @@ class PrintFileDataSourceImpl extends PrintFileDataSource {
final PrintUtils _printUtils;
final ImagePaths _imagePaths;
final FileUtils _fileUtils;
final HtmlAnalyzer _htmlAnalyzer;
final ExceptionThrower _exceptionThrower;

PrintFileDataSourceImpl(
this._printUtils,
this._imagePaths,
this._fileUtils,
this._htmlAnalyzer,
this._exceptionThrower
);

@override
Future<void> printEmail(EmailPrint emailPrint) {
return Future.sync(() async {
final emailContentEscaped = await _transformHtmlEmailContent(
emailPrint.emailContent);

final sender = emailPrint.emailInformation.from?.isNotEmpty == true
? emailPrint.emailInformation.from!.first
: null;
Expand All @@ -43,7 +52,7 @@ class PrintFileDataSourceImpl extends PrintFileDataSource {
final iconBase64Data = await _fileUtils.convertImageAssetToBase64(attachment.getIcon(_imagePaths));
final printAttachment = PrintAttachment(
iconBase64Data: iconBase64Data,
name: attachment.name ?? '',
name: attachment.name.escapeLtGtHtmlString(),
size: filesize(attachment.size?.value)
);
listPrintAttachment.add(printAttachment);
Expand All @@ -53,9 +62,9 @@ class PrintFileDataSourceImpl extends PrintFileDataSource {
return await _printUtils.printEmail(
appName: emailPrint.appName,
userName: emailPrint.userName,
subject: emailPrint.emailInformation.subject ?? '',
emailContent: emailPrint.emailContent,
senderName: sender?.name ?? '',
subject: emailPrint.emailInformation.subject?.escapeLtGtHtmlString() ?? '',
emailContent: emailContentEscaped,
senderName: sender?.name.escapeLtGtHtmlString() ?? '',
senderEmailAddress: sender?.email ?? '',
dateTime: receiveTime,
fromPrefix: emailPrint.fromPrefix,
Expand All @@ -72,4 +81,17 @@ class PrintFileDataSourceImpl extends PrintFileDataSource {
);
}).catchError(_exceptionThrower.throwException);
}

Future<String> _transformHtmlEmailContent(String emailContent) async {
try {
final htmlContentTransformed = await _htmlAnalyzer.transformHtmlEmailContent(
emailContent,
TransformConfiguration.forPrintEmail(),
);
return htmlContentTransformed;
} catch (e) {
logError('PrintFileDataSourceImpl::_transformHtmlEmailContent: Exception: $e');
return emailContent;
}
}
}
18 changes: 1 addition & 17 deletions lib/features/email/domain/usecases/print_email_interactor.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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:dartz/dartz.dart';
import 'package:tmail_ui_user/features/email/domain/model/email_print.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
Expand All @@ -14,24 +12,10 @@ class PrintEmailInteractor {

Stream<Either<Failure, Success>> execute(EmailPrint emailPrint) async* {
try {
final htmlContentTransformed = await _transformHtmlEmailContent(emailPrint.emailContent);
final newEmailPrint = emailPrint.fromEmailContent(htmlContentTransformed);
await emailRepository.printEmail(newEmailPrint);
await emailRepository.printEmail(emailPrint);
yield Right(PrintEmailSuccess());
} catch (e) {
yield Left(PrintEmailFailure(exception: e));
}
}

Future<String> _transformHtmlEmailContent(String emailContent) async {
try {
final htmlContentTransformed = await emailRepository.transformHtmlEmailContent(
emailContent,
TransformConfiguration.forPrintEmail());
return htmlContentTransformed;
} catch (e) {
logError('PrintEmailInteractor::_transformHtmlEmailContent: Exception: $e');
return emailContent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class EmailBindings extends BaseBindings {
Get.find<PrintUtils>(),
Get.find<ImagePaths>(),
Get.find<FileUtils>(),
Get.find<HtmlAnalyzer>(),
Get.find<CacheExceptionThrower>()
));
Get.lazyPut(() => EmailHiveCacheDataSourceImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.find<PrintUtils>(),
Get.find<ImagePaths>(),
Get.find<FileUtils>(),
Get.find<HtmlAnalyzer>(),
Get.find<CacheExceptionThrower>()
));
Get.lazyPut(() => MailboxDataSourceImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SendEmailInteractorBindings extends InteractorsBindings {
Get.find<PrintUtils>(),
Get.find<ImagePaths>(),
Get.find<FileUtils>(),
Get.find<HtmlAnalyzer>(),
Get.find<CacheExceptionThrower>(),
));
Get.lazyPut(() => EmailHiveCacheDataSourceImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class FcmInteractorBindings extends InteractorsBindings {
Get.find<PrintUtils>(),
Get.find<ImagePaths>(),
Get.find<FileUtils>(),
Get.find<HtmlAnalyzer>(),
Get.find<CacheExceptionThrower>()
));
Get.lazyPut(() => EmailHiveCacheDataSourceImpl(
Expand Down

0 comments on commit 92472e7

Please sign in to comment.