-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathApiRoutes.kt
286 lines (225 loc) · 9.06 KB
/
ApiRoutes.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
* Infomaniak Mail - Android
* Copyright (C) 2022-2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.mail.data.api
import com.infomaniak.lib.core.BuildConfig.INFOMANIAK_API_V1
import com.infomaniak.mail.BuildConfig.MAIL_API
import com.infomaniak.mail.utils.Utils
object ApiRoutes {
//region API V1
fun getCredentialsPassword(): String {
return "$INFOMANIAK_API_V1/profile/password"
}
private fun mailboxV1(mailboxHostingId: Int, mailboxName: String): String {
return "$INFOMANIAK_API_V1/mail_hostings/$mailboxHostingId/mailboxes/$mailboxName"
}
fun backups(mailboxHostingId: Int, mailboxName: String): String {
return "${mailboxV1(mailboxHostingId, mailboxName)}/backups"
}
fun requestMailboxPassword(mailboxHostingId: Int, mailboxName: String): String {
return "${mailboxV1(mailboxHostingId, mailboxName)}/ask_password"
}
fun signatures(mailboxHostingId: Int, mailboxName: String): String {
return "${mailboxV1(mailboxHostingId, mailboxName)}/signatures"
}
fun signature(mailboxHostingId: Int, mailboxName: String): String {
return "${signatures(mailboxHostingId, mailboxName)}/set_defaults"
}
//endregion
//region Personal Information Manager
private fun pim(): String {
return "$MAIL_API/api/pim"
}
fun addressBooks(): String {
return "${pim()}/addressbook"
}
fun contact(): String {
return "${pim()}/contact"
}
fun contacts(): String {
return "${contact()}/all?with=emails,details,others,contacted_times&filters=has_email"
}
//endregion
//region Calendar
fun infomaniakCalendarEventReply(calendarEventId: Int): String {
return "${pim()}/event/$calendarEventId/reply"
}
fun calendarEvent(resource: String): String {
return "${resource(resource)}?format=render"
}
fun icsCalendarEventReply(resource: String): String {
return "${resource(resource)}/reply"
}
//endregion
//region Secured Proxy
private fun securedProxy(): String {
return "$MAIL_API/api/securedProxy"
}
fun externalMailInfo(mailboxHostingId: Int, mailboxName: String): String {
return "${securedProxy()}/1/mail_hostings/$mailboxHostingId/mailboxes/$mailboxName/external_mail_flag"
}
fun updateMailboxPassword(mailboxId: Int): String {
return "${securedProxy()}/cache/invalidation/profile/workspace/mailbox/$mailboxId/update_password"
}
fun manageMailboxes(): String {
return "${securedProxy()}/profile/workspace/mailbox"
}
fun manageMailbox(mailboxId: Int): String {
return "${manageMailboxes()}/$mailboxId"
}
//endregion
//region Mailbox
private fun mailbox(): String {
return "$MAIL_API/api/mailbox"
}
fun mailboxes(): String {
return "${mailbox()}?with=aliases,unseen"
}
fun permissions(linkId: Int, mailboxHostingId: Int): String {
return "${mailbox()}/permissions?user_mailbox_id=$linkId&product_id=$mailboxHostingId"
}
fun quotas(mailboxHostingId: Int, mailboxName: String): String {
return "${mailbox()}/quotas?mailbox=$mailboxName&product_id=$mailboxHostingId"
}
//endregion
//region Folder
private fun mailMailbox(mailboxUuid: String): String {
return "$MAIL_API/api/mail/$mailboxUuid"
}
fun folders(mailboxUuid: String): String {
return "${mailMailbox(mailboxUuid)}/folder"
}
private fun folder(mailboxUuid: String, folderId: String): String {
return "${folders(mailboxUuid)}/$folderId"
}
fun flushFolder(mailboxUuid: String, folderId: String): String {
return "${folder(mailboxUuid, folderId)}/flush"
}
fun search(mailboxUuid: String, folderId: String, filters: String): String {
return "${folder(mailboxUuid, folderId)}/message?thread=on&offset=0&$filters"
}
//endregion
//region Message from Folder/Message
private fun message(mailboxUuid: String, folderId: String, shortUid: Int): String {
return "${folder(mailboxUuid, folderId)}/message/$shortUid"
}
fun downloadAttachments(mailboxUuid: String, folderId: String, shortUid: Int): String {
return "${message(mailboxUuid, folderId, shortUid)}/attachmentsArchive"
}
fun blockUser(mailboxUuid: String, folderId: String, shortUid: Int): String {
return "${message(mailboxUuid, folderId, shortUid)}/blacklist"
}
fun reportPhishing(mailboxUuid: String, folderId: String, shortUid: Int): String {
return "${message(mailboxUuid, folderId, shortUid)}/report"
}
fun downloadMessage(mailboxUuid: String, folderId: String, shortUid: Int): String {
return "${message(mailboxUuid, folderId, shortUid)}/download"
}
//endregion
//region Messages from Folder/Mobile
private fun getMessages(mailboxUuid: String, folderId: String): String {
return "${folder(mailboxUuid, folderId)}/mobile"
}
fun getMessagesUidsDelta(mailboxUuid: String, folderId: String, cursor: String): String {
return "${getMessages(mailboxUuid, folderId)}/activities?signature=$cursor"
}
fun getDateOrderedMessagesUids(mailboxUuid: String, folderId: String): String {
val parameters = "?messages=${Utils.NUMBER_OF_OLD_UIDS_TO_FETCH}&direction=desc"
return "${getMessages(mailboxUuid, folderId)}/date-ordered-messages-uids${parameters}"
}
fun getMessagesByUids(mailboxUuid: String, folderId: String, uids: List<Int>): String {
return "${getMessages(mailboxUuid, folderId)}/messages?uids=${uids.joinToString(separator = ",")}"
}
//endregion
//region Messages from Mailbox
private fun messages(mailboxUuid: String): String {
return "${mailMailbox(mailboxUuid)}/message"
}
fun deleteMessages(mailboxUuid: String): String {
return "${messages(mailboxUuid)}/delete"
}
fun moveMessages(mailboxUuid: String): String {
return "${messages(mailboxUuid)}/move"
}
fun messagesSeen(mailboxUuid: String): String {
return "${messages(mailboxUuid)}/seen"
}
fun messagesUnseen(mailboxUuid: String): String {
return "${messages(mailboxUuid)}/unseen"
}
fun starMessages(mailboxUuid: String): String {
return "${messages(mailboxUuid)}/star"
}
fun unstarMessages(mailboxUuid: String): String {
return "${messages(mailboxUuid)}/unstar"
}
//endregion
//region Draft from Mailbox
fun draft(mailboxUuid: String): String {
return "${mailMailbox(mailboxUuid)}/draft"
}
fun draft(mailboxUuid: String, remoteDraftUuid: String): String {
return "${draft(mailboxUuid)}/$remoteDraftUuid"
}
fun createAttachment(mailboxUuid: String): String {
return "${draft(mailboxUuid)}/attachment"
}
fun attachmentToForward(mailboxUuid: String): String {
return "${draft(mailboxUuid)}/attachmentsToForward"
}
//endregion
//region AI
private fun ai(): String {
return "$MAIL_API/api/ai"
}
fun aiConversation(mailboxUuid: String): String {
return "${ai()}${mailboxUuidParameter(mailboxUuid)}"
}
fun aiShortcutWithContext(contextId: String, action: String, mailboxUuid: String): String {
return "${ai()}/mobile/$contextId/${action}${mailboxUuidParameter(mailboxUuid)}"
}
fun aiShortcutNoContext(action: String, mailboxUuid: String): String {
return "${ai()}/mobile/${action}${mailboxUuidParameter(mailboxUuid)}"
}
//endregion
//region SwissTransfer
fun swissTransferContainer(containerUuid: String): String {
return "$MAIL_API/api/swisstransfer/containers/$containerUuid"
}
fun swissTransferContainerDownloadUrl(containerUuid: String): String {
return "${swissTransferContainer(containerUuid)}/files/download"
}
//endregion
private fun mailboxUuidParameter(mailboxUuid: String): String {
return "?mailbox_uuid=$mailboxUuid"
}
fun featureFlags(mailboxUuid: String): String {
return "$MAIL_API/api/feature-flag/check${mailboxUuidParameter(mailboxUuid)}"
}
fun ping(): String {
return "$MAIL_API/api/ping-with-auth"
}
fun resource(resource: String): String {
return "$MAIL_API$resource"
}
fun bimi(bimi: String): String {
return "$MAIL_API$bimi"
}
fun shareLink(mailboxUuid: String, folderId: String, mailId: Int): String {
return "${message(mailboxUuid, folderId, mailId)}/share"
}
}