Skip to content

Commit 452fcfc

Browse files
dab246hoangdat
authored andcommitted
Directly call to /.well-known/jmap
1 parent b919f8d commit 452fcfc

File tree

2 files changed

+30
-132
lines changed

2 files changed

+30
-132
lines changed

lib/http/http_client.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ class HttpClient {
3636
}
3737

3838
Future<dynamic> get(
39-
String path, {
40-
Map<String, dynamic>? queryParameters,
41-
Options? options,
42-
CancelToken? cancelToken,
43-
ProgressCallback? onReceiveProgress,
44-
}) async {
39+
String path, {
40+
Map<String, dynamic>? queryParameters,
41+
Options? options,
42+
CancelToken? cancelToken,
43+
ProgressCallback? onReceiveProgress,
44+
}) async {
45+
final newOptions = options?.appendHeaders({HttpHeaders.acceptHeader : jmapHeader})
46+
?? Options(headers: {HttpHeaders.acceptHeader : jmapHeader}) ;
47+
4548
return await _dio.get(
4649
path,
4750
queryParameters: queryParameters,
48-
options: options,
51+
options: newOptions,
4952
cancelToken: cancelToken,
5053
onReceiveProgress: onReceiveProgress)
5154
.then((value) => value.data)
Lines changed: 20 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,38 @@
1-
import 'dart:convert';
2-
31
import 'package:jmap_dart_client/http/converter/capabilities_converter.dart';
42
import 'package:jmap_dart_client/http/http_client.dart';
53
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
64
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart';
75
import 'package:jmap_dart_client/jmap/core/session/session.dart';
86

97
class GetSession {
10-
final String jsonSession = '''
11-
{
12-
"capabilities": {
13-
"urn:ietf:params:jmap:mail": {
14-
"maxMailboxesPerEmail": 10000000,
15-
"maxMailboxDepth": null,
16-
"maxSizeMailboxName": 200,
17-
"maxSizeAttachmentsPerEmail": 20000000,
18-
"emailQuerySortOptions": [
19-
"receivedAt",
20-
"sentAt",
21-
"size",
22-
"from",
23-
"to",
24-
"subject"
25-
],
26-
"mayCreateTopLevelMailbox": true
27-
},
28-
"urn:ietf:params:jmap:submission": {
29-
"maxDelayedSend": 0,
30-
"submissionExtensions": []
31-
},
32-
"urn:ietf:params:jmap:core": {
33-
"maxSizeUpload": 31457280,
34-
"maxConcurrentUpload": 4,
35-
"maxSizeRequest": 10000000,
36-
"maxConcurrentRequests": 4,
37-
"maxCallsInRequest": 16,
38-
"maxObjectsInGet": 500,
39-
"maxObjectsInSet": 500,
40-
"collationAlgorithms": [
41-
"i;unicode-casemap"
42-
]
43-
}
44-
},
45-
"accounts": {
46-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba": {
47-
"name": "benoit@localhost",
48-
"isPersonal": true,
49-
"isReadOnly": false,
50-
"accountCapabilities": {
51-
"urn:ietf:params:jmap:mail": {
52-
"maxMailboxesPerEmail": 10000000,
53-
"maxMailboxDepth": null,
54-
"maxSizeMailboxName": 200,
55-
"maxSizeAttachmentsPerEmail": 20000000,
56-
"emailQuerySortOptions": [
57-
"receivedAt",
58-
"sentAt",
59-
"size",
60-
"from",
61-
"to",
62-
"subject"
63-
],
64-
"mayCreateTopLevelMailbox": true
65-
},
66-
"urn:ietf:params:jmap:websocket": {
67-
"supportsPush": true,
68-
"url": "http://localhost/jmap/ws"
69-
},
70-
"urn:ietf:params:jmap:submission": {
71-
"maxDelayedSend": 0,
72-
"submissionExtensions": []
73-
},
74-
"urn:ietf:params:jmap:core": {
75-
"maxSizeUpload": 31457280,
76-
"maxConcurrentUpload": 4,
77-
"maxSizeRequest": 10000000,
78-
"maxConcurrentRequests": 4,
79-
"maxCallsInRequest": 16,
80-
"maxObjectsInGet": 500,
81-
"maxObjectsInSet": 500,
82-
"collationAlgorithms": ["i;unicode-casemap"]
83-
},
84-
"urn:ietf:params:jmap:vacationresponse": {}
85-
}
86-
}
87-
},
88-
"primaryAccounts": {
89-
"urn:ietf:params:jmap:submission":
90-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
91-
"com:linagora:params:jmap:pgp":
92-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
93-
"urn:ietf:params:jmap:websocket":
94-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
95-
"com:linagora:params:jmap:ws:ticket":
96-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
97-
"urn:apache:james:params:jmap:mail:shares":
98-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
99-
"urn:ietf:params:jmap:vacationresponse":
100-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
101-
"urn:ietf:params:jmap:mail":
102-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
103-
"com:linagora:params:jmap:filter":
104-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
105-
"urn:ietf:params:jmap:mdn":
106-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
107-
"urn:apache:james:params:jmap:mail:quota":
108-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
109-
"urn:ietf:params:jmap:core":
110-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba",
111-
"com:linagora:params:jmap:echo":
112-
"2bdee8dcc7f7a6817e2699d21c0462f3ab0b66d25de7e71ae2762d4ae8c591ba"
113-
},
114-
"username": "alice@localhost",
115-
"apiUrl": "http://localhost/jmap",
116-
"downloadUrl": "http://localhost/download/{accountId}/{blobId}/?type={type}&name={name}",
117-
"uploadUrl": "http://localhost/upload/{accountId}",
118-
"eventSourceUrl": "http://localhost/eventSource?types={types}&closeAfter={closeafter}&ping={ping}",
119-
"state": "2c9f1b12-b35a-43e6-9af2-0106fb53a943"
120-
}
121-
''';
122-
1238
final HttpClient _httpClient;
9+
final CapabilitiesConverter _capabilitiesConverter;
10+
11+
GetSession(this._httpClient, this._capabilitiesConverter);
12412

125-
GetSession(this._httpClient);
13+
Future<Session> execute() async {
14+
return await _httpClient.get('/.well-known/jmap')
15+
.then((value) => extractData(value))
16+
.catchError((error) => throw error);
17+
}
12618

19+
Session extractData(Map<String, dynamic> body) {
20+
return Session.fromJson(body, converter: _capabilitiesConverter);
21+
}
22+
}
23+
24+
class GetSessionBuilder {
25+
final HttpClient _httpClient;
12726
final CapabilitiesConverter _capabilitiesConverter = CapabilitiesConverter();
12827

28+
GetSessionBuilder(this._httpClient);
29+
12930
void registerCapabilityConverter(Map<CapabilityIdentifier, CapabilityProperties Function(Map<String, dynamic>)> converters) {
13031
_capabilitiesConverter.addConverters(converters);
32+
_capabilitiesConverter.build();
13133
}
13234

133-
Future<Session> execute() async {
134-
return await getFakeSession()
135-
.then((value) => Session.fromJson(value, converter: _capabilitiesConverter))
136-
.catchError((error) => throw error);
137-
}
138-
139-
Future<Map<String, dynamic>> getFakeSession() async {
140-
final session = json.decode(jsonSession);
141-
return Future.value(session);
35+
GetSession build() {
36+
return GetSession(_httpClient, _capabilitiesConverter);
14237
}
14338
}

0 commit comments

Comments
 (0)