1
1
/*
2
2
* Infomaniak Mail - Android
3
- * Copyright (C) 2022-2023 Infomaniak Network SA
3
+ * Copyright (C) 2022-2024 Infomaniak Network SA
4
4
*
5
5
* This program is free software: you can redistribute it and/or modify
6
6
* it under the terms of the GNU General Public License as published by
@@ -24,99 +24,133 @@ import com.infomaniak.mail.utils.Utils
24
24
25
25
object ApiRoutes {
26
26
27
- fun resource (resource : String ) = " $MAIL_API$resource "
28
-
29
- fun ping () = " $MAIL_API /api/ping-with-auth"
30
-
31
- fun addressBooks () = " $MAIL_API /api/pim/addressbook"
32
-
33
- fun contact () = " $MAIL_API /api/pim/contact"
34
-
35
- fun contacts () = " ${contact()} /all?with=emails,details,others,contacted_times&filters=has_email"
36
-
37
- fun mailbox () = " $MAIL_API /api/mailbox?with=unseen,aliases,external_mail_flag_enabled"
38
-
39
- fun permissions (linkId : Int , hostingId : Int ): String {
40
- return " $MAIL_API /api/mailbox/permissions?user_mailbox_id=$linkId &product_id=$hostingId "
27
+ // region API V1
28
+ fun getCredentialsPassword (): String {
29
+ return " $INFOMANIAK_API_V1 /profile/password"
41
30
}
42
31
43
- private fun ai (): String = " $MAIL_API /api/ai"
32
+ private fun mailboxV1 (mailboxHostingId : Int , mailboxName : String ): String {
33
+ return " $INFOMANIAK_API_V1 /mail_hostings/$mailboxHostingId /mailboxes/$mailboxName "
34
+ }
44
35
45
- fun featureFlag ( featureName : String , currentMailboxUuid : String ): String {
46
- return " $MAIL_API /api/feature-flag/check/ $featureName${mailboxUuidParameter(currentMailboxUuid)} "
36
+ fun backups ( mailboxHostingId : Int , mailboxName : String ): String {
37
+ return " ${mailboxV1(mailboxHostingId, mailboxName)} /backups "
47
38
}
48
39
49
- private fun apiMailbox (mailboxHostingId : Int , mailboxName : String ): String {
50
- return " $INFOMANIAK_API_V1 /mail_hostings/ $ mailboxHostingId/mailboxes/ $ mailboxName"
40
+ fun requestMailboxPassword (mailboxHostingId : Int , mailboxName : String ): String {
41
+ return " ${mailboxV1( mailboxHostingId, mailboxName)} /ask_password "
51
42
}
52
43
53
- fun signatures (mailboxHostingId : Int , mailboxName : String ) = " ${apiMailbox(mailboxHostingId, mailboxName)} /signatures"
44
+ fun signatures (mailboxHostingId : Int , mailboxName : String ): String {
45
+ return " ${mailboxV1(mailboxHostingId, mailboxName)} /signatures"
46
+ }
54
47
55
48
fun signature (mailboxHostingId : Int , mailboxName : String , signatureId : Int ): String {
56
49
return " ${signatures(mailboxHostingId, mailboxName)} /$signatureId "
57
50
}
51
+ // endregion
58
52
59
- fun manageMailboxes () = " $MAIL_API /api/securedProxy/profile/workspace/mailbox"
60
-
61
- fun manageMailbox (mailboxId : Int ) = " ${manageMailboxes()} /$mailboxId "
53
+ // region Personal Information Manager
54
+ private fun pim (): String {
55
+ return " $MAIL_API /api/pim"
56
+ }
62
57
63
- fun updateMailboxPassword ( mailboxId : Int ): String {
64
- return " $MAIL_API /api/securedProxy/cache/invalidation/profile/workspace/mailbox/ $mailboxId /update_password "
58
+ fun addressBooks ( ): String {
59
+ return " ${pim()} /addressbook "
65
60
}
66
61
67
- fun requestMailboxPassword ( mailboxHostingId : Int , mailboxName : String ): String {
68
- return " ${apiMailbox(mailboxHostingId, mailboxName )} /ask_password "
62
+ fun contact ( ): String {
63
+ return " ${pim( )} /contact "
69
64
}
70
65
71
- fun backups (mailboxHostingId : Int , mailboxName : String ) = " ${apiMailbox(mailboxHostingId, mailboxName)} /backups"
66
+ fun contacts (): String {
67
+ return " ${contact()} /all?with=emails,details,others,contacted_times&filters=has_email"
68
+ }
69
+ // endregion
72
70
73
- fun folders (mailboxUuid : String ) = " $MAIL_API /api/mail/$mailboxUuid /folder"
71
+ // region Secured Proxy
72
+ private fun securedProxy (): String {
73
+ return " $MAIL_API /api/securedProxy"
74
+ }
74
75
75
- private fun folder (mailboxUuid : String , folderId : String ) = " ${folders(mailboxUuid)} /$folderId "
76
+ fun updateMailboxPassword (mailboxId : Int ): String {
77
+ return " ${securedProxy()} /cache/invalidation/profile/workspace/mailbox/$mailboxId /update_password"
78
+ }
76
79
77
- fun flushFolder (mailboxUuid : String , folderId : String ) = " ${folder(mailboxUuid, folderId)} /flush"
80
+ fun manageMailboxes (): String {
81
+ return " ${securedProxy()} /profile/workspace/mailbox"
82
+ }
78
83
79
- fun quotas (mailboxHostingId : Int , mailboxName : String ): String =
80
- " $MAIL_API /api/mailbox/quotas?mailbox=$mailboxName &product_id=$mailboxHostingId "
84
+ fun manageMailbox (mailboxId : Int ): String {
85
+ return " ${manageMailboxes()} /$mailboxId "
86
+ }
87
+ // endregion
81
88
82
- private fun messages (mailboxUuid : String ) = " $MAIL_API /api/mail/$mailboxUuid /message"
89
+ // region Mailbox
90
+ private fun mailbox (): String {
91
+ return " $MAIL_API /api/mailbox"
92
+ }
83
93
84
- private fun message ( mailboxUuid : String , folderId : String , shortUid : Int ): String {
85
- return " ${folder(mailboxUuid, folderId)} /message/ $shortUid "
94
+ fun mailboxes ( ): String {
95
+ return " ${mailbox()} ?with=aliases,unseen "
86
96
}
87
97
88
- fun moveMessages (mailboxUuid : String ) = " ${messages(mailboxUuid)} /move"
98
+ fun permissions (linkId : Int , mailboxHostingId : Int ): String {
99
+ return " ${mailbox()} /permissions?user_mailbox_id=$linkId &product_id=$mailboxHostingId "
100
+ }
89
101
90
- fun deleteMessages (mailboxUuid : String ) = " ${messages(mailboxUuid)} /delete"
102
+ fun quotas (mailboxHostingId : Int , mailboxName : String ): String {
103
+ return " ${mailbox()} /quotas?mailbox=$mailboxName &product_id=$mailboxHostingId "
104
+ }
105
+ // endregion
91
106
92
- fun messagesSeen (mailboxUuid : String ) = " ${messages(mailboxUuid)} /seen"
107
+ // region Folder
108
+ private fun mailMailbox (mailboxUuid : String ): String {
109
+ return " $MAIL_API /api/mail/$mailboxUuid "
110
+ }
93
111
94
- fun messagesUnseen (mailboxUuid : String ) = " ${messages(mailboxUuid)} /unseen"
112
+ fun folders (mailboxUuid : String ): String {
113
+ return " ${mailMailbox(mailboxUuid)} /folder"
114
+ }
95
115
96
- fun starMessages (mailboxUuid : String , star : Boolean ): String = " ${messages(mailboxUuid)} /${if (star) " star" else " unstar" } "
116
+ private fun folder (mailboxUuid : String , folderId : String ): String {
117
+ return " ${folders(mailboxUuid)} /$folderId "
118
+ }
97
119
98
- fun draft (mailboxUuid : String ) = " $MAIL_API /api/mail/$mailboxUuid /draft"
120
+ fun flushFolder (mailboxUuid : String , folderId : String ): String {
121
+ return " ${folder(mailboxUuid, folderId)} /flush"
122
+ }
99
123
100
- fun draft (mailboxUuid : String , remoteDraftUuid : String ) = " ${draft(mailboxUuid)} /$remoteDraftUuid "
124
+ fun search (mailboxUuid : String , folderId : String , filters : String ): String {
125
+ return " ${folder(mailboxUuid, folderId)} /message?thread=on&offset=0&$filters "
126
+ }
127
+ // region Folder
101
128
102
- fun createAttachment (mailboxUuid : String ) = " ${draft(mailboxUuid)} /attachment"
129
+ // region Messages from Folder/Message
130
+ private fun message (mailboxUuid : String , folderId : String , shortUid : Int ): String {
131
+ return " ${folder(mailboxUuid, folderId)} /message/$shortUid "
132
+ }
103
133
104
134
fun downloadAttachments (mailboxUuid : String , folderId : String , shortUid : Int ): String {
105
135
return " ${message(mailboxUuid, folderId, shortUid)} /attachmentsArchive"
106
136
}
107
137
108
- fun attachmentToForward (mailboxUuid : String ) = " ${draft(mailboxUuid)} /attachmentsToForward"
109
-
110
- fun search (mailboxUuid : String , folderId : String , filters : String ): String {
111
- return " ${folder(mailboxUuid, folderId)} /message?thread=on&offset=0&$filters "
138
+ fun blockUser (mailboxUuid : String , folderId : String , shortUid : Int ): String {
139
+ return " ${message(mailboxUuid, folderId, shortUid)} /blacklist"
112
140
}
113
141
114
142
fun reportPhishing (mailboxUuid : String , folderId : String , shortUid : Int ): String {
115
143
return " ${message(mailboxUuid, folderId, shortUid)} /report"
116
144
}
145
+ // endregion
117
146
118
- fun blockUser (mailboxUuid : String , folderId : String , shortUid : Int ): String {
119
- return " ${message(mailboxUuid, folderId, shortUid)} /blacklist"
147
+ // Message from Folder/Mobile
148
+ private fun getMessages (mailboxUuid : String , folderId : String ): String {
149
+ return " ${folder(mailboxUuid, folderId)} /mobile"
150
+ }
151
+
152
+ fun getMessagesUidsDelta (mailboxUuid : String , folderId : String , cursor : String ): String {
153
+ return " ${getMessages(mailboxUuid, folderId)} /activities?signature=$cursor "
120
154
}
121
155
122
156
fun getMessagesUids (mailboxUuid : String , folderId : String , info : PaginationInfo ? ): String {
@@ -127,31 +161,86 @@ object ApiRoutes {
127
161
return " ${endpoint}${messages}${offset}${direction} "
128
162
}
129
163
130
- fun getMessagesUidsDelta (mailboxUuid : String , folderId : String , cursor : String ): String {
131
- return " ${getMessages(mailboxUuid, folderId)} /activities?signature=${cursor} "
132
- }
133
-
134
164
fun getMessagesByUids (mailboxUuid : String , folderId : String , uids : List <Int >): String {
135
165
return " ${getMessages(mailboxUuid, folderId)} /messages?uids=${uids.joinToString(" ," )} "
136
166
}
167
+ // endregion
137
168
138
- private fun mailboxUuidParameter (currentMailboxUuid : String ) = " ?mailbox_uuid=$currentMailboxUuid "
169
+ // region Message from Mailbox
170
+ private fun messages (mailboxUuid : String ): String {
171
+ return " ${mailMailbox(mailboxUuid)} /message"
172
+ }
139
173
140
- fun aiConversation ( currentMailboxUuid : String ): String {
141
- return " ${ai()}${mailboxUuidParameter(currentMailboxUuid)} "
174
+ fun deleteMessages ( mailboxUuid : String ): String {
175
+ return " ${messages(mailboxUuid)} /delete "
142
176
}
143
177
144
- fun aiShortcutWithContext ( contextId : String , action : String , currentMailboxEmail : String ): String {
145
- return " ${ai( )} /mobile/ $contextId / $action${mailboxUuidParameter(currentMailboxEmail)} "
178
+ fun moveMessages ( mailboxUuid : String ): String {
179
+ return " ${messages(mailboxUuid )} /move "
146
180
}
147
181
148
- fun aiShortcutNoContext ( action : String , currentMailboxEmail : String ): String {
149
- return " ${ai( )} /mobile/ $action${mailboxUuidParameter(currentMailboxEmail)} "
182
+ fun messagesSeen ( mailboxUuid : String ): String {
183
+ return " ${messages(mailboxUuid )} /seen "
150
184
}
151
185
152
- private fun getMessages (mailboxUuid : String , folderId : String ): String {
153
- return " $MAIL_API /api/mail/${mailboxUuid} /folder/${folderId} /mobile"
186
+ fun messagesUnseen (mailboxUuid : String ): String {
187
+ return " ${messages(mailboxUuid)} /unseen"
188
+ }
189
+
190
+ fun starMessages (mailboxUuid : String , star : Boolean ): String {
191
+ return " ${messages(mailboxUuid)} /${if (star) " star" else " unstar" } "
192
+ }
193
+ // endregion
194
+
195
+ // region Draft from Mailbox
196
+ fun draft (mailboxUuid : String ): String {
197
+ return " ${mailMailbox(mailboxUuid)} /draft"
198
+ }
199
+
200
+ fun draft (mailboxUuid : String , remoteDraftUuid : String ): String {
201
+ return " ${draft(mailboxUuid)} /$remoteDraftUuid "
154
202
}
155
203
156
- fun getCredentialsPassword (): String = " $INFOMANIAK_API_V1 /profile/password"
204
+ fun createAttachment (mailboxUuid : String ): String {
205
+ return " ${draft(mailboxUuid)} /attachment"
206
+ }
207
+
208
+ fun attachmentToForward (mailboxUuid : String ): String {
209
+ return " ${draft(mailboxUuid)} /attachmentsToForward"
210
+ }
211
+ // endregion
212
+
213
+ // region AI
214
+ private fun ai (): String {
215
+ return " $MAIL_API /api/ai"
216
+ }
217
+
218
+ fun aiConversation (mailboxUuid : String ): String {
219
+ return " ${ai()}${mailboxUuidParameter(mailboxUuid)} "
220
+ }
221
+
222
+ fun aiShortcutWithContext (contextId : String , action : String , mailboxUuid : String ): String {
223
+ return " ${ai()} /mobile/$contextId /${action}${mailboxUuidParameter(mailboxUuid)} "
224
+ }
225
+
226
+ fun aiShortcutNoContext (action : String , mailboxUuid : String ): String {
227
+ return " ${ai()} /mobile/${action}${mailboxUuidParameter(mailboxUuid)} "
228
+ }
229
+ // endregion
230
+
231
+ private fun mailboxUuidParameter (mailboxUuid : String ): String {
232
+ return " ?mailbox_uuid=$mailboxUuid "
233
+ }
234
+
235
+ fun featureFlag (featureName : String , mailboxUuid : String ): String {
236
+ return " $MAIL_API /api/feature-flag/check/${featureName}${mailboxUuidParameter(mailboxUuid)} "
237
+ }
238
+
239
+ fun ping (): String {
240
+ return " $MAIL_API /api/ping-with-auth"
241
+ }
242
+
243
+ fun resource (resource : String ): String {
244
+ return " ${MAIL_API }${resource} "
245
+ }
157
246
}
0 commit comments