feat: implement global autoresponder plugin
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
final class DirectAdminVacationApi
|
||||
{
|
||||
public function __construct(private string $directadminBinary = '/usr/local/directadmin/directadmin')
|
||||
{
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $rule @return array<string,string> */
|
||||
public function buildSavePayload(string $email, array $rule): array
|
||||
{
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new InvalidArgumentException('Invalid mailbox email');
|
||||
}
|
||||
[$local, $domain] = explode('@', strtolower($email), 2);
|
||||
[$startDate, $startTime] = $this->splitPeriod((string)($rule['start_value'] ?? ''));
|
||||
[$endDate, $endTime] = $this->splitPeriod((string)($rule['end_value'] ?? ''));
|
||||
return [
|
||||
'action' => 'modify',
|
||||
'domain' => $domain,
|
||||
'user' => $local,
|
||||
'email' => $email,
|
||||
'text' => (string)($rule['body'] ?? ''),
|
||||
'subject' => (string)($rule['subject'] ?? ''),
|
||||
'startdate' => $startDate,
|
||||
'starttime' => $startTime,
|
||||
'enddate' => $endDate,
|
||||
'endtime' => $endTime,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{0:string,1:string} */
|
||||
private function splitPeriod(string $value): array
|
||||
{
|
||||
if (!preg_match('/^([0-9]{4}-[0-9]{2}-[0-9]{2})\|(morning|afternoon|evening)$/', $value, $m)) {
|
||||
throw new InvalidArgumentException('DirectAdmin API backend requires directadmin_period values');
|
||||
}
|
||||
return [$m[1], $m[2]];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user