Fix display header message email quoted when forward email

This commit is contained in:
dab246
2022-04-14 15:14:46 +07:00
committed by Dat H. Pham
parent e3a4371eae
commit 451f37d4e4
6 changed files with 113 additions and 22 deletions
@@ -17,12 +17,14 @@ extension HtmlExtension on String {
String addBlockTag(String tag, {String? attribute}) => attribute != null ? '<$tag $attribute>$this</$tag>' : '<$tag>$this</$tag>';
String append(String value) => this + value;
String addNewLineTag({int count = 1}) {
if (count == 1) return '$this<br>';
if (count == 1) return '$this</br>';
var htmlString = this;
for (var i = 0; i < count; i++) {
htmlString = '$htmlString<br>';
htmlString = '$htmlString</br>';
}
return htmlString;
}
@@ -236,11 +236,70 @@ class ComposerController extends BaseController {
htmlControllerBrowser.setFullScreen();
}
Tuple2<String, String>? _getHeaderEmailQuoted(String locale, ComposerArguments arguments) {
if (arguments.presentationEmail != null) {
final sentDate = arguments.presentationEmail?.sentAt;
final emailAddress = arguments.presentationEmail?.from.listEmailAddressToString(isFullEmailAddress: true) ?? '';
return Tuple2(sentDate.formatDate(pattern: 'MMM d, y h:mm a', locale: locale), emailAddress);
String? _getHeaderEmailQuoted(BuildContext context, ComposerArguments arguments) {
final presentationEmail = arguments.presentationEmail;
if (presentationEmail != null) {
final locale = Localizations.localeOf(context).toLanguageTag();
log('ComposerController::_getHeaderEmailQuoted(): emailActionType: ${arguments.emailActionType}');
switch(arguments.emailActionType) {
case EmailActionType.reply:
case EmailActionType.replyAll:
final sentDate = presentationEmail.sentAt;
final emailAddress = presentationEmail.from.listEmailAddressToString(isFullEmailAddress: true);
return AppLocalizations.of(context).header_email_quoted(
sentDate.formatDate(pattern: 'MMM d, y h:mm a', locale: locale),
emailAddress);
case EmailActionType.forward:
var headerQuoted = '------- ${AppLocalizations.of(context).forwarded_message} -------'.addNewLineTag();
final subject = presentationEmail.subject ?? '';
final sentDate = presentationEmail.sentAt;
final fromEmailAddress = presentationEmail.from.listEmailAddressToString(isFullEmailAddress: true);
final toEmailAddress = presentationEmail.to.listEmailAddressToString(isFullEmailAddress: true);
final ccEmailAddress = presentationEmail.cc.listEmailAddressToString(isFullEmailAddress: true);
final bccEmailAddress = presentationEmail.bcc.listEmailAddressToString(isFullEmailAddress: true);
if (subject.isNotEmpty) {
headerQuoted = headerQuoted
.append('${AppLocalizations.of(context).subject_email}: ')
.append(subject)
.addNewLineTag();
}
if (sentDate != null) {
headerQuoted = headerQuoted
.append('${AppLocalizations.of(context).date}: ')
.append(sentDate.formatDate(pattern: 'MMM d, y h:mm a', locale: locale))
.addNewLineTag();
}
if (fromEmailAddress.isNotEmpty) {
headerQuoted = headerQuoted
.append('${AppLocalizations.of(context).from_email_address_prefix}: ')
.append(fromEmailAddress)
.addNewLineTag();
}
if (toEmailAddress.isNotEmpty) {
headerQuoted = headerQuoted
.append('${AppLocalizations.of(context).to_email_address_prefix}: ')
.append(toEmailAddress)
.addNewLineTag();
}
if (ccEmailAddress.isNotEmpty) {
headerQuoted = headerQuoted
.append('${AppLocalizations.of(context).cc_email_address_prefix}: ')
.append(ccEmailAddress)
.addNewLineTag();
}
if (bccEmailAddress.isNotEmpty) {
headerQuoted = headerQuoted
.append('${AppLocalizations.of(context).bcc_email_address_prefix}: ')
.append(bccEmailAddress)
.addNewLineTag();
}
return headerQuoted;
default:
return null;
}
}
return null;
}
@@ -312,11 +371,9 @@ class ComposerController extends BaseController {
}
String getEmailContentQuotedAsHtml(BuildContext context, ComposerArguments arguments) {
final headerEmailQuoted = _getHeaderEmailQuoted(Localizations.localeOf(context).toLanguageTag(), arguments);
final headerEmailQuotedAsHtml = headerEmailQuoted != null
? AppLocalizations.of(context).header_email_quoted(headerEmailQuoted.value1, headerEmailQuoted.value2).addBlockTag('cite')
: '';
final headerEmailQuoted = _getHeaderEmailQuoted(context, arguments);
log('ComposerController::getEmailContentQuotedAsHtml(): headerEmailQuoted: $headerEmailQuoted');
final headerEmailQuotedAsHtml = headerEmailQuoted != null ? headerEmailQuoted.addBlockTag('cite') : '';
final trustAsHtml = arguments.emailContents?.asHtmlString ?? '';
final emailQuotedHtml = '<p></br></p>$headerEmailQuotedAsHtml${trustAsHtml.addBlockQuoteTag()}';
@@ -596,7 +596,7 @@ class EmailController extends BaseController {
emailActionType: emailActionType,
presentationEmail: mailboxDashBoardController.selectedEmail.value!,
emailContents: initialEmailContents,
attachments: attachments,
attachments: emailActionType == EmailActionType.forward ? attachments : null,
mailboxRole: mailboxDashBoardController.selectedMailbox.value?.role);
if (kIsWeb) {
@@ -522,12 +522,12 @@ class EmailView extends GetView with UserSettingPopupMenuMixin, NetworkConnectio
(failure) => SizedBox.shrink(),
(success) {
if (success is LoadingState) {
return Padding(
return Align(alignment: Alignment.topCenter, child: Padding(
padding: EdgeInsets.all(16),
child: SizedBox(
width: 30,
height: 30,
child: CupertinoActivityIndicator(color: AppColor.colorLoading)));
child: CupertinoActivityIndicator(color: AppColor.colorLoading))));
} else {
if (emailController.emailContents.isNotEmpty) {
final allEmailContents = emailController.emailContents.asHtmlString;
+25 -7
View File
@@ -1,5 +1,5 @@
{
"@@last_modified": "2022-04-07T15:43:45.603676",
"@@last_modified": "2022-04-14T15:13:36.565629",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
@@ -214,12 +214,6 @@
"placeholders_order": [],
"placeholders": {}
},
"move_to_mailbox": "Move to mailbox",
"@move_to_mailbox": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"mark_as_star": "Star",
"@mark_as_star": {
"type": "text",
@@ -1041,5 +1035,29 @@
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"exchange": "Exchange",
"@exchange": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"move_message": "Move message",
"@move_message": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"forwarded_message": "Forwarded message",
"@forwarded_message": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"date": "Date",
"@date": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
@@ -1097,4 +1097,18 @@ class AppLocalizations {
name: 'move_message',
);
}
String get forwarded_message {
return Intl.message(
'Forwarded message',
name: 'forwarded_message',
);
}
String get date {
return Intl.message(
'Date',
name: 'date',
);
}
}