-
Notifications
You must be signed in to change notification settings - Fork 17
Implement MDN/send
method/response
#43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f65f07
add send message method
sherlockvn 333606f
Add `MDN` object
dab246 a72fd1c
Add `Send` method/response abstraction
dab246 349a311
Implement `MDN/send` method/response
dab246 4a32f37
Add unit test for `MDN/send` method/response
dab246 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,13 @@ | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
import 'package:jmap_dart_client/jmap/identities/identity.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
class IdentityIdConverter implements JsonConverter<IdentityId, String> { | ||
const IdentityIdConverter(); | ||
|
||
@override | ||
IdentityId fromJson(String json) => IdentityId(Id(json)); | ||
|
||
@override | ||
String toJson(IdentityId object) => object.id.value; | ||
} |
This file contains hidden or 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/http/converter/id_converter.dart'; | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
import 'package:jmap_dart_client/jmap/mdn/mdn.dart'; | ||
|
||
class MdnConverter { | ||
MapEntry<Id, Mdn> parseEntry(String key, dynamic value) { | ||
if(value is Map<String, dynamic>) { | ||
return MapEntry(Id(key), Mdn.fromJson(value)); | ||
} else { | ||
return MapEntry(Id(key), value); | ||
} | ||
} | ||
|
||
MapEntry<String, dynamic> toJson(Id id, Mdn mdn) { | ||
return MapEntry(IdConverter().toJson(id), mdn.toJson()); | ||
} | ||
} |
This file contains hidden or 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,12 @@ | ||
import 'package:jmap_dart_client/jmap/core/error/set_error.dart'; | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
|
||
class SetErrorConverter { | ||
MapEntry<Id, SetError> parseEntry(String key, dynamic value) { | ||
if (value is Map<String, dynamic>) { | ||
return MapEntry(Id(key), SetError.fromJson(value)); | ||
} else { | ||
return MapEntry(Id(key), value); | ||
} | ||
} | ||
} |
This file contains hidden or 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,80 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'disposition.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Disposition with EquatableMixin { | ||
final ActionMode actionMode; | ||
final SendingMode sendingMode; | ||
final DispositionType type; | ||
|
||
Disposition({ | ||
required this.actionMode, | ||
required this.sendingMode, | ||
required this.type, | ||
}); | ||
|
||
@override | ||
List<Object?> get props => [actionMode, sendingMode, type]; | ||
|
||
factory Disposition.fromJson(Map<String, dynamic> json) => | ||
_$DispositionFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$DispositionToJson(this); | ||
} | ||
|
||
enum ActionMode { | ||
manual('manual-action'), | ||
automatic('automatic-action'); | ||
|
||
final String value; | ||
|
||
const ActionMode(this.value); | ||
|
||
String toJson() => value; | ||
|
||
static ActionMode fromJson(String json) { | ||
final parts = json.split('-'); | ||
if (parts.isNotEmpty && values.contains(parts[0])) { | ||
return values.byName(parts[0]); | ||
} | ||
throw Exception('wrong parsed actionMode: $json'); | ||
} | ||
} | ||
|
||
enum SendingMode { | ||
manually('mdn-sent-manually'), | ||
automatically('mdn-sent-automatically'); | ||
|
||
final String value; | ||
|
||
const SendingMode(this.value); | ||
dab246 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
String toJson() => value; | ||
|
||
static SendingMode fromJson(String json) { | ||
final parts = json.split('-'); | ||
if (parts.length >= 2 && values.contains(parts[2])) { | ||
return values.byName(parts[2]); | ||
} | ||
throw Exception('wrong parsed SendingMode: $json'); | ||
} | ||
} | ||
|
||
enum DispositionType { | ||
deleted, | ||
dispatched, | ||
displayed, | ||
processed; | ||
|
||
String toJson() => name; | ||
|
||
static DispositionType fromJson(String json) { | ||
try { | ||
return values.byName(json); | ||
} catch (e) { | ||
throw Exception('wrong parsed type'); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,72 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:jmap_dart_client/http/converter/id_nullable_converter.dart'; | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
import 'package:jmap_dart_client/jmap/mdn/disposition.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'mdn.g.dart'; | ||
|
||
@IdNullableConverter() | ||
@JsonSerializable() | ||
class Mdn with EquatableMixin { | ||
|
||
final Id? forEmailId; | ||
|
||
final String? subject; | ||
|
||
final String? textBody; | ||
|
||
final bool includeOriginalMessage; | ||
|
||
final String? reportingUA; | ||
|
||
final Disposition disposition; | ||
|
||
final String? mdnGateway; | ||
|
||
final String? originalRecipient; | ||
|
||
final String? finalRecipient; | ||
|
||
final String? originalMessageId; | ||
|
||
final List<String>? error; | ||
|
||
final Map<String,String>? extensionFields; | ||
|
||
Mdn({ | ||
required this.disposition, | ||
this.forEmailId, | ||
this.subject, | ||
this.textBody, | ||
this.includeOriginalMessage = false, | ||
this.reportingUA, | ||
this.mdnGateway, | ||
this.originalRecipient, | ||
this.finalRecipient, | ||
this.originalMessageId, | ||
this.error, | ||
this.extensionFields, | ||
}); | ||
|
||
|
||
@override | ||
List<Object?> get props => [ | ||
forEmailId, | ||
subject, | ||
textBody, | ||
includeOriginalMessage, | ||
reportingUA, | ||
disposition, | ||
mdnGateway, | ||
originalRecipient, | ||
finalRecipient, | ||
originalMessageId, | ||
error, | ||
extensionFields, | ||
]; | ||
|
||
factory Mdn.fromJson(Map<String, dynamic> json) => _$MdnFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$MdnToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,69 @@ | ||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart'; | ||
import 'package:jmap_dart_client/http/converter/identities/identity_id_converter.dart'; | ||
import 'package:jmap_dart_client/http/converter/mdn/mdn_converter.dart'; | ||
import 'package:jmap_dart_client/http/converter/set/set_method_properties_converter.dart'; | ||
import 'package:jmap_dart_client/jmap/account_id.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
import 'package:jmap_dart_client/jmap/core/method/method.dart'; | ||
import 'package:jmap_dart_client/jmap/core/patch_object.dart'; | ||
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart'; | ||
import 'package:jmap_dart_client/jmap/identities/identity.dart'; | ||
import 'package:jmap_dart_client/jmap/mdn/mdn.dart'; | ||
|
||
class SendMessageMethod extends MethodRequiringAccountId { | ||
final IdentityId identityId; | ||
|
||
final Map<Id, Mdn> send; | ||
|
||
final Map<Id, PatchObject>? onSuccessUpdateEmail; | ||
|
||
SendMessageMethod( | ||
AccountId accountId, { | ||
required this.identityId, | ||
required this.send, | ||
this.onSuccessUpdateEmail, | ||
}) : super(accountId); | ||
|
||
@override | ||
MethodName get methodName => MethodName('MDN/send'); | ||
|
||
@override | ||
Set<CapabilityIdentifier> get requiredCapabilities => { | ||
CapabilityIdentifier.jmapMdn, | ||
CapabilityIdentifier.jmapMail, | ||
CapabilityIdentifier.jmapCore, | ||
}; | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
final val = <String, dynamic>{ | ||
'accountId': const AccountIdConverter().toJson(accountId), | ||
'identityId': const IdentityIdConverter().toJson(identityId), | ||
}; | ||
|
||
void writeNotNull(String key, dynamic value) { | ||
if (value != null) { | ||
val[key] = value; | ||
} | ||
} | ||
|
||
writeNotNull( | ||
'send', send.map((key, value) => MdnConverter().toJson(key, value))); | ||
writeNotNull( | ||
'onSuccessUpdateEmail', | ||
onSuccessUpdateEmail?.map((key, value) => | ||
SetMethodPropertiesConverter().fromMapIdToJson(key, value))); | ||
return val; | ||
} | ||
|
||
@override | ||
List<Object?> get props => [ | ||
methodName, | ||
accountId, | ||
identityId, | ||
send, | ||
onSuccessUpdateEmail, | ||
requiredCapabilities | ||
]; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.