Merge branch '2257-mailbox-wipe' into 'master'

Add method for wiping the mailbox

Closes #2257

See merge request briar/briar!1582
This commit is contained in:
akwizgran
2022-02-14 14:45:51 +00:00
4 changed files with 91 additions and 3 deletions

View File

@@ -37,6 +37,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

@@ -92,6 +92,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