Skip to content

Commit

Permalink
Convert EmailId to optional variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Mar 21, 2023
1 parent 8c6f7aa commit fb65ebf
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
15 changes: 7 additions & 8 deletions lib/jmap/mail/email/email.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/http/converter/email/email_body_value_converter.dart';
import 'package:jmap_dart_client/http/converter/email/email_keyword_identifier_converter.dart';
import 'package:jmap_dart_client/http/converter/email/email_mailbox_ids_converter.dart';
import 'package:jmap_dart_client/http/converter/email_id_converter.dart';
import 'package:jmap_dart_client/http/converter/email_id_nullable_converter.dart';
import 'package:jmap_dart_client/http/converter/id_nullable_converter.dart';
import 'package:jmap_dart_client/http/converter/individual_header_identifier_converter.dart';
import 'package:jmap_dart_client/http/converter/message_ids_header_value_converter.dart';
Expand All @@ -28,7 +28,7 @@ class Email with EquatableMixin {
'sentAt', 'replyTo', 'preview', 'hasAttachment'
});

final EmailId id;
final EmailId? id;
final Id? blobId;
final ThreadId? threadId;
final Map<MailboxId, bool>? mailboxIds;
Expand Down Expand Up @@ -57,9 +57,9 @@ class Email with EquatableMixin {
final Map<IndividualHeaderIdentifier, String?>? headerUserAgent;
final Map<IndividualHeaderIdentifier, String>? headerMdn;

Email(
Email({
this.id,
{this.blobId,
this.blobId,
this.threadId,
this.mailboxIds,
this.keywords,
Expand Down Expand Up @@ -90,7 +90,7 @@ class Email with EquatableMixin {

factory Email.fromJson(Map<String, dynamic> json) {
return Email(
const EmailIdConverter().fromJson(json['id'] as String),
id: const EmailIdNullableConverter().fromJson(json['id'] as String),
blobId: const IdNullableConverter().fromJson(json['blobId'] as String?),
threadId: const ThreadIdNullableConverter().fromJson(json['threadId'] as String?),
mailboxIds: (json['mailboxIds'] as Map<String, dynamic>?)?.map((key, value) => EmailMailboxIdsConverter().parseEntry(key, value)),
Expand Down Expand Up @@ -132,16 +132,15 @@ class Email with EquatableMixin {
}

Map<String, dynamic> toJson() {
final val = <String, dynamic>{
'id': const EmailIdConverter().toJson(id),
};
final val = <String, dynamic>{};

void writeNotNull(String key, dynamic value) {
if (value != null) {
val[key] = value;
}
}

writeNotNull('id', const EmailIdNullableConverter().toJson(id));
writeNotNull('blobId', const IdNullableConverter().toJson(blobId));
writeNotNull('threadId', const ThreadIdNullableConverter().toJson(threadId));
writeNotNull('mailboxIds', mailboxIds?.map((key, value) => EmailMailboxIdsConverter().toJson(key, value)));
Expand Down
6 changes: 3 additions & 3 deletions test/jmap/email/changes/get_changes_email_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ void main() {
group('[Email/changes]', () {

final expectMail1 = Email(
EmailId(Id("a59d5ca0-258e-11ec-a759-2fef1ee78d9e")),
id: EmailId(Id("a59d5ca0-258e-11ec-a759-2fef1ee78d9e")),
mailboxIds: { MailboxId(Id('aba7e8d0-18d9-11eb-a677-2990b970028d')): true },
keywords: { KeyWordIdentifier.emailSeen: true}
);

final expectMail2 = Email(
EmailId(Id("a59d5ca0-258e-11ec-a759-2fef1ee78d9e")),
id: EmailId(Id("a59d5ca0-258e-11ec-a759-2fef1ee78d9e")),
preview: "This event is about to begin test TimeTuesday 29 September 2020 06:00 - 06:30 Europe/Paris (See in Calendar)Location1 thai ha (See in Map)Attendees - User A <[email protected]> (Organizer) - <[email protected]> Resourcesnew directoryNotesaaaa *#",
hasAttachment: false,
size: UnsignedInt(24946),
Expand All @@ -43,7 +43,7 @@ void main() {
);

final expectMail3 = Email(
EmailId(Id("54fa3000-2595-11ec-a759-2fef1ee78d9e")),
id: EmailId(Id("54fa3000-2595-11ec-a759-2fef1ee78d9e")),
preview: "This event is about to begin A - show datetime1 TimeTuesday 15 September 2020 07:03 - 07:33 Europe/Paris (See in Calendar)Location1 thai ha1 (See in Map)Attendees - User A <[email protected]> (Organizer) - Thanh Loan LE <[email protected]> - User C <u",
hasAttachment: false,
size: UnsignedInt(24857),
Expand Down
10 changes: 5 additions & 5 deletions test/jmap/email/get_list_email_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
void main() {
group('get list email test', () {
final expectMail1 = Email(
EmailId(Id("382312d0-fa5c-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("382312d0-fa5c-11eb-b647-2fef1ee78d9e")),
preview: "Dear QA,I attached image here",
hasAttachment: false,
subject: "test inline image",
Expand All @@ -34,7 +34,7 @@ void main() {
);

final expectMail2 = Email(
EmailId(Id("bc8a5320-fa58-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("bc8a5320-fa58-11eb-b647-2fef1ee78d9e")),
preview: "This event is about to begin Noti check TimeFriday 23 October 2020 12:00 - 12:30 Europe/Paris (See in Calendar)Location1 thai ha (See in Map)Attendees - User A <[email protected]> (Organizer) - Lê Nguyễn <[email protected]> - User C <[email protected]",
hasAttachment: false,
subject: "Notification: Noti check",
Expand All @@ -44,7 +44,7 @@ void main() {
);

final expectMail3 = Email(
EmailId(Id("ba7e0860-fa58-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("ba7e0860-fa58-11eb-b647-2fef1ee78d9e")),
preview: "This event is about to begin Recurrencr TimeWednesday 26 August 2020 05:30 - 06:30 Europe/Paris (See in Calendar)Location1 thai ha (See in Map)Attendees - [email protected] <[email protected]> (Organizer) - User A <[email protected]> Resourc",
hasAttachment: false,
subject: "Notification: Recurrencr",
Expand All @@ -54,7 +54,7 @@ void main() {
);

final expectMail4 = Email(
EmailId(Id("d9b3b880-fa6f-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("d9b3b880-fa6f-11eb-b647-2fef1ee78d9e")),
preview: "alo -- desktop signature",
hasAttachment: true,
subject: "test attachment",
Expand All @@ -64,7 +64,7 @@ void main() {
);

final expectMail5 = Email(
EmailId(Id("637f1ef0-fa5d-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("637f1ef0-fa5d-11eb-b647-2fef1ee78d9e")),
preview: "Dear, test inline Thanks and BRs-- desktop signature",
hasAttachment: false,
subject: "test inline image",
Expand Down
10 changes: 5 additions & 5 deletions test/jmap/email/query/query_with_operator_emails_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import 'package:jmap_dart_client/jmap/mail/email/query/query_email_method.dart';
void main() {
group('get list email test', () {
final expectMail1 = Email(
EmailId(Id("382312d0-fa5c-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("382312d0-fa5c-11eb-b647-2fef1ee78d9e")),
preview: "Dear QA,I attached image here",
hasAttachment: false,
subject: "test inline image",
Expand All @@ -34,7 +34,7 @@ void main() {
receivedAt: UTCDate(DateTime.parse("2021-08-11T04:25:55Z")));

final expectMail2 = Email(
EmailId(Id("bc8a5320-fa58-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("bc8a5320-fa58-11eb-b647-2fef1ee78d9e")),
preview:
"This event is about to begin Noti check TimeFriday 23 October 2020 12:00 - 12:30 Europe/Paris (See in Calendar)Location1 thai ha (See in Map)Attendees - User A <[email protected]> (Organizer) - Lê Nguyễn <[email protected]> - User C <[email protected]",
hasAttachment: false,
Expand All @@ -44,7 +44,7 @@ void main() {
receivedAt: UTCDate(DateTime.parse("2021-08-11T04:00:59Z")));

final expectMail3 = Email(
EmailId(Id("ba7e0860-fa58-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("ba7e0860-fa58-11eb-b647-2fef1ee78d9e")),
preview:
"This event is about to begin Recurrencr TimeWednesday 26 August 2020 05:30 - 06:30 Europe/Paris (See in Calendar)Location1 thai ha (See in Map)Attendees - [email protected] <[email protected]> (Organizer) - User A <[email protected]> Resourc",
hasAttachment: false,
Expand All @@ -54,7 +54,7 @@ void main() {
receivedAt: UTCDate(DateTime.parse("2021-08-11T04:00:55Z")));

final expectMail4 = Email(
EmailId(Id("d9b3b880-fa6f-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("d9b3b880-fa6f-11eb-b647-2fef1ee78d9e")),
preview: "alo -- desktop signature",
hasAttachment: true,
subject: "test attachment",
Expand All @@ -63,7 +63,7 @@ void main() {
receivedAt: UTCDate(DateTime.parse("2021-08-11T06:46:26Z")));

final expectMail5 = Email(
EmailId(Id("637f1ef0-fa5d-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("637f1ef0-fa5d-11eb-b647-2fef1ee78d9e")),
preview: "Dear, test inline Thanks and BRs-- desktop signature",
hasAttachment: false,
subject: "test inline image",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import 'package:jmap_dart_client/jmap/mail/email/get/get_email_response.dart';
import 'package:jmap_dart_client/jmap/mail/email/query/query_email_method.dart';

void main() {
final expectMail = Email(EmailId(Id("04f27c50-e879-11ec-aae4-43ebf0340ebd")),
final expectMail = Email(
id: EmailId(Id("04f27c50-e879-11ec-aae4-43ebf0340ebd")),
preview: "AAAA",
hasAttachment: false,
subject: "AAAA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import 'package:jmap_dart_client/jmap/mail/email/get/get_email_response.dart';
import 'package:jmap_dart_client/jmap/mail/email/query/query_email_method.dart';

void main() {
final expectMail = Email(EmailId(Id("04f27c50-e879-11ec-aae4-43ebf0340ebd")),
final expectMail = Email(
id: EmailId(Id("04f27c50-e879-11ec-aae4-43ebf0340ebd")),
preview: "AAAA",
hasAttachment: false,
subject: "AAAA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import 'package:jmap_dart_client/jmap/mail/email/get/get_email_response.dart';
import 'package:jmap_dart_client/jmap/mail/email/query/query_email_method.dart';

void main() {
final expectMail = Email(EmailId(Id("04f27c50-e879-11ec-aae4-43ebf0340ebd")),
final expectMail = Email(
id: EmailId(Id("04f27c50-e879-11ec-aae4-43ebf0340ebd")),
preview: "AAAA",
hasAttachment: false,
subject: "AAAA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import 'package:jmap_dart_client/jmap/mail/email/query/query_email_method.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';

void main() {
final expectMail1 = Email(EmailId(Id("5baf2a10-3f4d-11eb-b3ca-69d8f333e2f2")),
final expectMail1 = Email(
id: EmailId(Id("5baf2a10-3f4d-11eb-b3ca-69d8f333e2f2")),
preview:
"DJ REPEAT:Ercot Sees 56,373 MW Summer Peak,2% Below '00 Peak DJ Ercot: New Units Will Boost Supply to 65,064 MW DJ Ercot: 21% Summer Reserve If Normal Weather DJ Ercot Summer -2: New 345-Kv Line To Relieve Congestion By Eileen O'Grady Of DOW JONES NEWSWIRE",
hasAttachment: false,
Expand All @@ -41,7 +42,8 @@ void main() {
"2020-12-16T03:18:24Z",
)));

final expectMail2 = Email(EmailId(Id("2ef049e0-3f5d-11eb-bf20-f1a8da6866c8")),
final expectMail2 = Email(
id: EmailId(Id("2ef049e0-3f5d-11eb-bf20-f1a8da6866c8")),
preview:
"---------------------- Forwarded by Lorna Brennan/ET&S/Enron on 12/18/2000 10:59 AM --------------------------- \"[email protected]\" <webmaster on 12/15/2000 06:15:19 PM To: cc: Subject: STRATOSPHERIC LEVELS -- CERA Monthly Briefing Title: Into the Stratos",
hasAttachment: false,
Expand All @@ -54,7 +56,8 @@ void main() {
"2020-12-16T05:11:41Z",
)));

final expectMail3 = Email(EmailId(Id("2ef049e0-3f5d-11eb-bf20-f1a8da6866c8")),
final expectMail3 = Email(
id: EmailId(Id("2ef049e0-3f5d-11eb-bf20-f1a8da6866c8")),
preview:
"---------------------- Forwarded by Lorna Brennan/ET&S/Enron on 12/18/2000 10:59 AM --------------------------- \"[email protected]\" <webmaster on 12/15/2000 06:15:19 PM To: cc: Subject: STRATOSPHERIC LEVELS -- CERA Monthly Briefing Title: Into the Stratos",
hasAttachment: false,
Expand Down
10 changes: 5 additions & 5 deletions test/jmap/email/set/set_email_method_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
void main() {
group('test to json set email method', () {
final expectedCreated = Email(
EmailId(Id('29a7f870-0596-11ec-b153-2fef1ee78d9e')),
id: EmailId(Id('29a7f870-0596-11ec-b153-2fef1ee78d9e')),
blobId: Id('29a7f870-0596-11ec-b153-2fef1ee78d9e'),
threadId: ThreadId(Id('29a7f870-0596-11ec-b153-2fef1ee78d9e')),
size: UnsignedInt(657)
Expand Down Expand Up @@ -110,7 +110,7 @@ void main() {
final setEmailMethod = SetEmailMethod(AccountId(Id('3ce33c876a726662c627746eb9537a1d13c2338193ef27bd051a3ce5c0fe5b12')))
..addCreate(Id('aa1234'),
Email(
EmailId(Id('ea12345')),
id: EmailId(Id('ea12345')),
mailboxIds: {
MailboxId(Id('fe00a5c0-0584-11ec-b153-2fef1ee78d9e')): true
},
Expand Down Expand Up @@ -228,7 +228,7 @@ void main() {
final setEmailMethod = SetEmailMethod(AccountId(Id('3ce33c876a726662c627746eb9537a1d13c2338193ef27bd051a3ce5c0fe5b12')))
..addCreate(Id('aa1234'),
Email(
EmailId(Id('ea12345')),
id: EmailId(Id('ea12345')),
mailboxIds: {
MailboxId(Id('fe00a5c0-0584-11ec-b153-2fef1ee78d9e')): true
},
Expand Down Expand Up @@ -342,7 +342,7 @@ void main() {
final setEmailMethod = SetEmailMethod(AccountId(Id('587a9c5a4a9c0a4d36243b7417700d5383cbbfa25f0909ab7f6f4baaa5bf4e9b')))
..addCreate(Id('e01'),
Email(
EmailId(Id('e102')),
id: EmailId(Id('e102')),
mailboxIds: {
MailboxId(Id('a6f488c0-964b-11ec-83d6-c1ded34233a9')): true
},
Expand All @@ -368,7 +368,7 @@ void main() {
SetEmailResponse.deserialize);

final expectedCreated1 = Email(
EmailId(Id("77664010-4ab1-11ed-88ee-ffc86e0cde67")),
id: EmailId(Id("77664010-4ab1-11ed-88ee-ffc86e0cde67")),
blobId: Id("77664010-4ab1-11ed-88ee-ffc86e0cde67"),
threadId: ThreadId(Id("77664010-4ab1-11ed-88ee-ffc86e0cde67")),
size: UnsignedInt(600),
Expand Down
10 changes: 5 additions & 5 deletions test/jmap/email/sort_list_email_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
void main() {

final expectMail1 = Email(
EmailId(Id("382312d0-fa5c-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("382312d0-fa5c-11eb-b647-2fef1ee78d9e")),
preview: "Dear QA,I attached image here",
hasAttachment: false,
subject: "A",
Expand All @@ -36,7 +36,7 @@ void main() {
);

final expectMail2 = Email(
EmailId(Id("bc8a5320-fa58-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("bc8a5320-fa58-11eb-b647-2fef1ee78d9e")),
preview: "This event is about to begin Noti check TimeFriday 23 October 2020 12:00 - 12:30 Europe/Paris (See in Calendar)Location1 thai ha (See in Map)Attendees - User A <[email protected]> (Organizer) - Lê Nguyễn <[email protected]> - User C <[email protected]",
hasAttachment: false,
subject: "B",
Expand All @@ -47,7 +47,7 @@ void main() {
);

final expectMail3 = Email(
EmailId(Id("ba7e0860-fa58-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("ba7e0860-fa58-11eb-b647-2fef1ee78d9e")),
preview: "This event is about to begin Recurrencr TimeWednesday 26 August 2020 05:30 - 06:30 Europe/Paris (See in Calendar)Location1 thai ha (See in Map)Attendees - [email protected] <[email protected]> (Organizer) - User A <[email protected]> Resourc",
hasAttachment: false,
subject: "C",
Expand All @@ -58,7 +58,7 @@ void main() {
);

final expectMail4 = Email(
EmailId(Id("d9b3b880-fa6f-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("d9b3b880-fa6f-11eb-b647-2fef1ee78d9e")),
preview: "alo -- desktop signature",
hasAttachment: true,
subject: "D",
Expand All @@ -69,7 +69,7 @@ void main() {
);

final expectMail5 = Email(
EmailId(Id("637f1ef0-fa5d-11eb-b647-2fef1ee78d9e")),
id: EmailId(Id("637f1ef0-fa5d-11eb-b647-2fef1ee78d9e")),
preview: "Dear, test inline Thanks and BRs-- desktop signature",
hasAttachment: false,
subject: "E",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
void main() {
group('test to json set email submission method', () {
final expectedCreated = Email(
EmailId(Id('64469f10-8e15-11ec-984e-e3f8b83572b4')),
id: EmailId(Id('64469f10-8e15-11ec-984e-e3f8b83572b4')),
blobId: Id('64469f10-8e15-11ec-984e-e3f8b83572b4'),
threadId: ThreadId(Id('64469f10-8e15-11ec-984e-e3f8b83572b4')),
size: UnsignedInt(742)
Expand Down Expand Up @@ -165,7 +165,7 @@ void main() {
final setEmailMethod = SetEmailMethod(AccountId(Id('3ce33c876a726662c627746eb9537a1d13c2338193ef27bd051a3ce5c0fe5b12')))
..addCreate(Id('dab1234'),
Email(
EmailId(Id('dab1234')),
id: EmailId(Id('dab1234')),
mailboxIds: {MailboxId(Id('5dfb3290-0a14-11ec-b57c-2fef1ee78d9e')): true},
subject: 'test send email',
from: {EmailAddress("userB", '[email protected]')},
Expand Down Expand Up @@ -354,7 +354,7 @@ void main() {
final setEmailMethod = SetEmailMethod(AccountId(Id('3ce33c876a726662c627746eb9537a1d13c2338193ef27bd051a3ce5c0fe5b12')))
..addCreate(Id('dab1234'),
Email(
EmailId(Id('dab1234')),
id: EmailId(Id('dab1234')),
mailboxIds: {MailboxId(Id('5dfb3290-0a14-11ec-b57c-2fef1ee78d9e')): true},
subject: 'test send email',
from: {EmailAddress("userB", '[email protected]')},
Expand Down

0 comments on commit fb65ebf

Please sign in to comment.