Skip to content

Commit 6cfacd9

Browse files
Only remove a stalwart domain entry if there's a domain referencing one. (#535)
1 parent 87b1f87 commit 6cfacd9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/thunderbird_accounts/mail/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,13 @@ def remove_custom_domain(request: HttpRequest):
545545

546546
stalwart_client = MailClient()
547547
try:
548-
stalwart_client.delete_domain(domain.name)
549-
request.user.domains.filter(name=domain_name).delete()
548+
domains = request.user.domains.filter(name=domain_name).all()
549+
# There should only be one here, but just in case...
550+
for domain in domains:
551+
if domain.stalwart_id:
552+
stalwart_client.delete_domain(domain.name)
553+
break
554+
domain.delete()
550555
except Exception as e:
551556
logging.error(f'Error removing custom domain: {e}')
552557
return JsonResponse(

0 commit comments

Comments
 (0)