1
- import 'dart:convert' ;
2
-
3
1
import 'package:jmap_dart_client/http/converter/capabilities_converter.dart' ;
4
2
import 'package:jmap_dart_client/http/http_client.dart' ;
5
3
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart' ;
6
4
import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart' ;
7
5
import 'package:jmap_dart_client/jmap/core/session/session.dart' ;
8
6
9
7
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
-
123
8
final HttpClient _httpClient;
9
+ final CapabilitiesConverter _capabilitiesConverter;
10
+
11
+ GetSession (this ._httpClient, this ._capabilitiesConverter);
124
12
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
+ }
126
18
19
+ Session extractData (Map <String , dynamic > body) {
20
+ return Session .fromJson (body, converter: _capabilitiesConverter);
21
+ }
22
+ }
23
+
24
+ class GetSessionBuilder {
25
+ final HttpClient _httpClient;
127
26
final CapabilitiesConverter _capabilitiesConverter = CapabilitiesConverter ();
128
27
28
+ GetSessionBuilder (this ._httpClient);
29
+
129
30
void registerCapabilityConverter (Map <CapabilityIdentifier , CapabilityProperties Function (Map <String , dynamic >)> converters) {
130
31
_capabilitiesConverter.addConverters (converters);
32
+ _capabilitiesConverter.build ();
131
33
}
132
34
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);
142
37
}
143
38
}
0 commit comments