TF-3349 Escape messages when forward and reply email
This commit is contained in:
@@ -27,6 +27,17 @@ extension EmailAddressExtension on EmailAddress {
|
||||
return '';
|
||||
}
|
||||
|
||||
String asFullStringWithLtGtCharacter() {
|
||||
if (displayName.isNotEmpty && emailAddress.isNotEmpty) {
|
||||
return '${displayName.capitalizeFirstEach} <$emailAddress>';
|
||||
} else if (displayName.isNotEmpty) {
|
||||
return displayName.capitalizeFirstEach;
|
||||
} else if (emailAddress.isNotEmpty) {
|
||||
return '<$emailAddress>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
String get emailAddress => email ?? '';
|
||||
|
||||
String get displayName => name ?? '';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:core/presentation/extensions/html_extension.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/mailbox/expand_mode.dart';
|
||||
import 'package:model/extensions/email_address_extension.dart';
|
||||
@@ -27,6 +28,18 @@ extension SetEmailAddressExtension on Set<EmailAddress>? {
|
||||
return listEmail.isNotEmpty ? listEmail.join(', ') : '';
|
||||
}
|
||||
|
||||
String toEscapeHtmlString(String separator) {
|
||||
if (this?.isNotEmpty != true) return '';
|
||||
|
||||
final listEmail = this
|
||||
!.map((emailAddress) => emailAddress.asFullStringWithLtGtCharacter().escapeLtGtHtmlString())
|
||||
.toList();
|
||||
|
||||
return listEmail.isNotEmpty ? listEmail.join(separator) : '';
|
||||
}
|
||||
|
||||
String toEscapeHtmlStringUseCommaSeparator() => toEscapeHtmlString(', ');
|
||||
|
||||
int numberEmailAddress() => this != null ? this!.length : 0;
|
||||
|
||||
List<EmailAddress> filterEmailAddress(String emailAddressNotExist) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/extensions/email_address_extension.dart';
|
||||
|
||||
void main() {
|
||||
group('EmailAddressExtension::asFullStringWithLtGtCharacter::', () {
|
||||
test('Should returns displayName and emailAddress formatted correctly', () {
|
||||
final emailAddress = EmailAddress(
|
||||
'john doe',
|
||||
'john.doe@example.com',
|
||||
);
|
||||
expect(
|
||||
emailAddress.asFullStringWithLtGtCharacter(),
|
||||
'John Doe <john.doe@example.com>',
|
||||
);
|
||||
});
|
||||
|
||||
test('Should returns displayName capitalized when emailAddress is empty', () {
|
||||
final emailAddress = EmailAddress(
|
||||
'jane doe',
|
||||
'',
|
||||
);
|
||||
expect(emailAddress.asFullStringWithLtGtCharacter(), 'Jane Doe');
|
||||
});
|
||||
|
||||
test('Should returns emailAddress enclosed in <> when displayName is empty', () {
|
||||
final emailAddress = EmailAddress(
|
||||
'',
|
||||
'jane.doe@example.com',
|
||||
);
|
||||
expect(emailAddress.asFullStringWithLtGtCharacter(), '<jane.doe@example.com>');
|
||||
});
|
||||
|
||||
test('Should returns an empty string when both displayName and emailAddress are empty', () {
|
||||
final emailAddress = EmailAddress('', '');
|
||||
expect(emailAddress.asFullStringWithLtGtCharacter(), '');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/extensions/list_email_address_extension.dart';
|
||||
|
||||
void main() {
|
||||
group('ListEmailAddressExtension::toEscapeHtmlString::', () {
|
||||
test('Should returns empty string for null or empty list', () {
|
||||
expect((<EmailAddress>{}).toEscapeHtmlString(', '), '');
|
||||
|
||||
Set<EmailAddress>? listEmails;
|
||||
expect(listEmails.toEscapeHtmlString(', '), '');
|
||||
});
|
||||
|
||||
test('Should returns joined HTML strings with separator', () {
|
||||
final emails = {
|
||||
EmailAddress('John Doe', 'john@example.com'),
|
||||
EmailAddress('Jane Smith', 'jane@example.com'),
|
||||
};
|
||||
final result = emails.toEscapeHtmlString(' | ');
|
||||
|
||||
expect(result, 'John Doe <john@example.com> | Jane Smith <jane@example.com>');
|
||||
});
|
||||
|
||||
test('Should handles displayName-only or email-only cases', () {
|
||||
final emails = {
|
||||
EmailAddress('John Doe', ''),
|
||||
EmailAddress('', 'jane@example.com'),
|
||||
};
|
||||
final result = emails.toEscapeHtmlString(', ');
|
||||
|
||||
expect(result, 'John Doe, <jane@example.com>');
|
||||
});
|
||||
});
|
||||
|
||||
group('ListEmailAddressExtension::toEscapeHtmlStringUseCommaSeparator::', () {
|
||||
test('Should uses ", " as separator', () {
|
||||
final emails = {
|
||||
EmailAddress('John Doe', 'john@example.com'),
|
||||
EmailAddress('Jane Smith', 'jane@example.com'),
|
||||
};
|
||||
final result = emails.toEscapeHtmlStringUseCommaSeparator();
|
||||
|
||||
expect(result, 'John Doe <john@example.com>, Jane Smith <jane@example.com>');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user