From 07839767c4ea313958bd965901e68979293590f4 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 17 Jul 2023 17:08:07 +0200 Subject: [PATCH] remove mailing list --- app/Maildispatcher/Actions/DestroyAction.php | 1 + app/Maildispatcher/Models/Maildispatcher.php | 9 --------- app/Mailgateway/Types/LocalType.php | 4 ++++ app/Mailgateway/Types/MailmanType.php | 5 +++++ app/Mailgateway/Types/Type.php | 2 ++ app/Mailman/Support/MailmanService.php | 7 +++++++ 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/Maildispatcher/Actions/DestroyAction.php b/app/Maildispatcher/Actions/DestroyAction.php index bc13542c..13056a09 100644 --- a/app/Maildispatcher/Actions/DestroyAction.php +++ b/app/Maildispatcher/Actions/DestroyAction.php @@ -12,6 +12,7 @@ class DestroyAction public function handle(Maildispatcher $maildispatcher): void { + $maildispatcher->gateway->type->deleteList($maildispatcher->name, $maildispatcher->gateway->domain); $maildispatcher->delete(); } diff --git a/app/Maildispatcher/Models/Maildispatcher.php b/app/Maildispatcher/Models/Maildispatcher.php index b8246a16..bab4f14d 100644 --- a/app/Maildispatcher/Models/Maildispatcher.php +++ b/app/Maildispatcher/Models/Maildispatcher.php @@ -20,15 +20,6 @@ class Maildispatcher extends Model 'filter' => 'json', ]; - public static function booted(): void - { - static::deleting(function ($dispatcher) { - foreach ($dispatcher->gateway->type->list($dispatcher->name, $dispatcher->gateway->domain) as $email) { - $dispatcher->gateway->type->remove($dispatcher->name, $dispatcher->gateway->domain, $email->email); - } - }); - } - /** * @return BelongsTo */ diff --git a/app/Mailgateway/Types/LocalType.php b/app/Mailgateway/Types/LocalType.php index 0965b2ad..81d3f60c 100644 --- a/app/Mailgateway/Types/LocalType.php +++ b/app/Mailgateway/Types/LocalType.php @@ -57,6 +57,10 @@ class LocalType extends Type { } + public function deleteList(string $name, string $domain): void + { + } + public function remove(string $name, string $domain, string $email): void { Localmaildispatcher::where('from', "{$name}@{$domain}")->where('to', $email)->delete(); diff --git a/app/Mailgateway/Types/MailmanType.php b/app/Mailgateway/Types/MailmanType.php index 1360febb..71018f31 100644 --- a/app/Mailgateway/Types/MailmanType.php +++ b/app/Mailgateway/Types/MailmanType.php @@ -113,6 +113,11 @@ class MailmanType extends Type $this->service()->createList("{$name}@{$domain}"); } + public function deleteList(string $name, string $domain): void + { + $this->service()->deleteList("{$name}@{$domain}"); + } + private function getList(string $name, string $domain): MailingList { $list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}"); diff --git a/app/Mailgateway/Types/Type.php b/app/Mailgateway/Types/Type.php index e7e08066..1e0b926a 100644 --- a/app/Mailgateway/Types/Type.php +++ b/app/Mailgateway/Types/Type.php @@ -22,6 +22,8 @@ abstract class Type abstract public function createList(string $name, string $domain): void; + abstract public function deleteList(string $name, string $domain): void; + abstract public function remove(string $name, string $domain, string $email): void; /** diff --git a/app/Mailman/Support/MailmanService.php b/app/Mailman/Support/MailmanService.php index 25cd4fb4..ffc85f36 100644 --- a/app/Mailman/Support/MailmanService.php +++ b/app/Mailman/Support/MailmanService.php @@ -59,6 +59,13 @@ class MailmanService return $list; } + public function deleteList(string $mailAddress): void + { + $list = $this->getLists()->first(fn ($list) => $list->fqdnListname === $mailAddress); + $response = $this->http()->delete("/lists/{$list->listId}"); + throw_unless(204 === $response->status(), MailmanServiceException::class, 'Deleting list failed'); + } + public function check(): bool { try {