(aliases) delete all aliases of a given local part

added a bulk delete method for aliases, when filtering on local part
this is convenient when in need to delete the local part and all its
destinations in a single call
This commit is contained in:
Marie PUPO JEAMMET
2026-01-09 15:55:08 +01:00
committed by Marie
parent 8ab1b2e2ef
commit bc1cbef168
4 changed files with 178 additions and 1 deletions

View File

@@ -778,11 +778,32 @@ class DimailAPIClient:
str(alias.domain),
)
# we don't raise error because we actually want this alias to be deleted
# to match dimail's states
return response
return self._raise_exception_for_unexpected_response(response)
def delete_multiple_alias(self, local_part, domain_name):
"""Send a Delete alias request to mail provisioning API."""
try:
response = session.delete(
f"{self.API_URL}/domains/{domain_name}/aliases/{local_part}/all",
json={},
headers=self._get_headers(),
verify=True,
timeout=self.API_TIMEOUT,
)
except requests.exceptions.ConnectionError as error:
logger.error(
"Connection error while trying to reach %s.",
self.API_URL,
exc_info=error,
)
raise error
# response.raise_for_status()
return response
def import_aliases(self, domain):
"""Import aliases from dimail. Useful if people fall out of sync with dimail."""