Add method for wiping the mailbox

This commit is contained in:
Torsten Grote
2022-01-24 08:58:33 -03:00
parent 5c153aeb6c
commit fc5533ec6e
4 changed files with 91 additions and 3 deletions

View File

@@ -35,6 +35,14 @@ interface MailboxApi {
boolean checkStatus(MailboxProperties properties)
throws IOException, ApiException;
/**
* Unpairs Briar and the mailbox (owner only).
* Resets mailbox state to that after first install
* (e.g. removes all stored files as well).
*/
void wipeMailbox(MailboxProperties properties)
throws IOException, ApiException;
/**
* Adds a new contact to the mailbox.
*

View File

@@ -105,6 +105,19 @@ class MailboxApiImpl implements MailboxApi {
return response.isSuccessful();
}
@Override
public void wipeMailbox(MailboxProperties properties)
throws IOException, ApiException {
if (!properties.isOwner()) throw new IllegalArgumentException();
Request request = getRequestBuilder(properties.getAuthToken())
.url(properties.getOnionAddress() + "/")
.delete()
.build();
OkHttpClient client = httpClientProvider.get();
Response response = client.newCall(request).execute();
if (response.code() != 204) throw new ApiException();
}
/* Contact Management API (owner only) */
@Override