-
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.
TF-3189 composer now correctly encodes subaddresses
- Loading branch information
1 parent
028e3d7
commit 2e44ad2
Showing
6 changed files
with
229 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ void main() { | |
"[email protected]", | ||
"user+mailbox/[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"user+my [email protected]", | ||
"user+Dossier d'été@domain.com", | ||
"\"Abc@def\"@example.com", | ||
"\"Fred Bloggs\"@example.com", | ||
"\"Joe.\\Blow\"@example.com", | ||
|
@@ -56,6 +59,10 @@ void main() { | |
"server-dev@#123.apache.org", | ||
"server-dev@[127.0.1.1.1]", | ||
"server-dev@[127.0.1.-1]", | ||
"[email protected]", | ||
"user+ @domain.com", | ||
"user+#[email protected]", | ||
"user+test-_.!~*'() @domain.com", | ||
"\"a..b\"@domain.com", // jakarta.mail is unable to handle this so we better reject it | ||
"server-dev\\[email protected]", // jakarta.mail is unable to handle this so we better reject it | ||
"[email protected]", | ||
|
@@ -165,5 +172,46 @@ void main() { | |
final mailAddress = MailAddress.validateAddress(GOOD_ADDRESS); | ||
expect(mailAddress.toString(), equals(GOOD_ADDRESS)); | ||
}); | ||
|
||
test('MailAddress.encodeLocalPartDetails() should work with characters to encode', () { | ||
final mailAddress = MailAddress.validateAddress("user+my [email protected]"); | ||
expect(mailAddress.asEncodedString(), equals("user+my%[email protected]")); | ||
}); | ||
|
||
test('MailAddress.encodeLocalPartDetails() should work with many characters to encode', () { | ||
final mailAddress = MailAddress.validateAddress("user+Dossier d'été@domain.com"); | ||
expect(mailAddress.asEncodedString(), equals("user+Dossier%20d%27%C3%A9t%C3%[email protected]")); | ||
}); | ||
|
||
test('MailAddress.encodeLocalPartDetails() should encode the rights characters', () { | ||
final mailAddress = MailAddress.validateAddress("user+test-_.!~'() @domain.com"); | ||
expect(mailAddress.asEncodedString(), equals("user+test-_.%21~%27%28%29%[email protected]")); | ||
}); | ||
|
||
test('getLocalPartDetails() should work', () { | ||
final mailAddress = MailAddress.validateAddress("[email protected]"); | ||
expect(mailAddress.getLocalPartDetails(), equals("details")); | ||
}); | ||
|
||
test('getLocalPartWithoutDetails() should work', () { | ||
final mailAddress = MailAddress.validateAddress("[email protected]"); | ||
expect(mailAddress.getLocalPartWithoutDetails(), equals("user")); | ||
}); | ||
|
||
test('stripDetails() should work', () { | ||
final mailAddress = MailAddress.validateAddress("[email protected]"); | ||
expect(mailAddress.stripDetails().asString(), equals("[email protected]")); | ||
}); | ||
|
||
test('stripDetails() should work with encoded local part', () { | ||
final mailAddress = MailAddress.validateAddress("user+Dossier%20d%27%C3%A9t%C3%[email protected]"); | ||
expect(mailAddress.stripDetails().asString(), equals("[email protected]")); | ||
}); | ||
|
||
test('stripDetails() should work when local part needs encoding', () { | ||
final mailAddress = MailAddress.validateAddress("user+super [email protected]"); | ||
expect(mailAddress.stripDetails().asString(), equals("[email protected]")); | ||
}); | ||
|
||
}); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
lib/features/composer/presentation/extensions/mail_address_extension.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,17 @@ | ||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; | ||
import 'package:core/core.dart'; | ||
|
||
extension MailAddressExtension on MailAddress { | ||
String? get getDisplayName { | ||
String? localPartDetails = getLocalPartDetails(); | ||
if(localPartDetails == null) { | ||
return null; | ||
} else { | ||
return '${getLocalPartWithoutDetails()} [${getLocalPartDetails()}]'; | ||
} | ||
} | ||
|
||
EmailAddress asEmailAddress() { | ||
return EmailAddress(getDisplayName, asEncodedString()); | ||
} | ||
} |
Oops, something went wrong.