Skip to content

Commit

Permalink
TF-1912 Sanitize html for email content when type is text/plain
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Jul 17, 2023
1 parent fcdd529 commit 937fc43
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import 'dart:convert';

import 'package:core/presentation/utils/html_transformer/base/text_transformer.dart';
import 'package:core/utils/app_logger.dart';

class SanitizeHtmlTransformers extends TextTransformer {

const SanitizeHtmlTransformers();

@override
String process(String text) {
final htmlEncoded = const HtmlEscape().convert(text);
log('HtmlSanitizerTransformers::process:htmlEncoded: $htmlEncoded');
return htmlEncoded;
}
}
10 changes: 8 additions & 2 deletions lib/features/email/data/local/html_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:core/data/network/dio_client.dart';
import 'package:core/presentation/utils/html_transformer/dom/add_tooltip_link_transformers.dart';
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
import 'package:core/presentation/utils/html_transformer/text/convert_url_string_to_html_links_transformers.dart';
import 'package:core/presentation/utils/html_transformer/text/sanitize_html_transformers.dart';
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
import 'package:model/email/email_content.dart';
import 'package:model/email/email_content_type.dart';
Expand Down Expand Up @@ -33,8 +34,13 @@ class HtmlAnalyzer {
case EmailContentType.textPlain:
final htmlTransform = HtmlTransform(emailContent.content);
final message = htmlTransform.transformToTextPlain(
transformConfiguration: TransformConfiguration.create(
customTextTransformers: [const ConvertUrlStringToHtmlLinksTransformers()]));
transformConfiguration: TransformConfiguration.create(
customTextTransformers: [
const ConvertUrlStringToHtmlLinksTransformers(),
const SanitizeHtmlTransformers(),
]
)
);
return EmailContent(emailContent.type, message);
default:
return emailContent;
Expand Down

0 comments on commit 937fc43

Please sign in to comment.