-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardize HTML sanitizing when preview email
- Loading branch information
Showing
10 changed files
with
146 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
core/lib/presentation/utils/html_transformer/sanitize_html.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:core/utils/app_logger.dart'; | ||
import 'package:sanitize_html/sanitize_html.dart'; | ||
|
||
class SanitizeHtml { | ||
String process({ | ||
required String inputHtml, | ||
List<String>? allowAttributes, | ||
List<String>? allowTags, | ||
List<String>? allowClassNames, | ||
}) { | ||
final outputHtml = sanitizeHtml( | ||
inputHtml, | ||
allowAttributes: allowAttributes, | ||
allowTags: allowTags, | ||
allowClassName: (className) => | ||
allowClassNames?.contains(className.toLowerCase()) == true | ||
); | ||
return outputHtml; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ib/presentation/utils/html_transformer/text/standardize_html_sanitizing_transformers.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'dart:convert'; | ||
import 'package:core/presentation/utils/html_transformer/base/text_transformer.dart'; | ||
import 'package:core/presentation/utils/html_transformer/sanitize_html.dart'; | ||
|
||
class StandardizeHtmlSanitizingTransformers extends TextTransformer { | ||
|
||
static const List<String> mailAllowedHtmlAttributes = [ | ||
'style', | ||
'public-asset-id', | ||
'data-filename', | ||
'bgcolor', | ||
]; | ||
|
||
static const List<String> mailAllowedHtmlTags = [ | ||
'font', | ||
'u', | ||
'[email protected]', | ||
'center', | ||
]; | ||
|
||
static const List<String> mailAllowedHtmlClassNames = [ | ||
'tmail-signature', | ||
'tmail-signature-blocked', | ||
'tmail-signature-button', | ||
'tmail-signature-content', | ||
'tmail_signature_prefix', | ||
]; | ||
|
||
const StandardizeHtmlSanitizingTransformers(); | ||
|
||
@override | ||
String process(String text, HtmlEscape htmlEscape) => | ||
SanitizeHtml().process( | ||
inputHtml: text, | ||
allowAttributes: mailAllowedHtmlAttributes, | ||
allowTags: mailAllowedHtmlTags, | ||
allowClassNames: mailAllowedHtmlClassNames, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters