fix: match directadmin vacation controls
This commit is contained in:
@@ -28,8 +28,8 @@ class DirectAdminVacationApi
|
||||
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'] ?? ''));
|
||||
[$startDate, $startTime] = $this->splitScheduleValue((string)($rule['start_value'] ?? ''), true);
|
||||
[$endDate, $endTime] = $this->splitScheduleValue((string)($rule['end_value'] ?? ''), false);
|
||||
[$startYear, $startMonth, $startDay] = explode('-', $startDate);
|
||||
[$endYear, $endMonth, $endDay] = explode('-', $endDate);
|
||||
$subjectPrefix = (string)($rule['subject_prefix'] ?? $rule['subject'] ?? '');
|
||||
@@ -108,12 +108,16 @@ class DirectAdminVacationApi
|
||||
}
|
||||
|
||||
/** @return array{0:string,1:string} */
|
||||
private function splitPeriod(string $value): array
|
||||
private function splitScheduleValue(string $value, bool $start): 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');
|
||||
if (preg_match('/^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2})$/', $value, $m)) {
|
||||
return [$m[1], $m[2]];
|
||||
}
|
||||
return [$m[1], $m[2]];
|
||||
if (!preg_match('/^([0-9]{4}-[0-9]{2}-[0-9]{2})\|(morning|afternoon|evening)$/', $value, $m)) {
|
||||
throw new InvalidArgumentException('DirectAdmin API backend requires exact date-time values');
|
||||
}
|
||||
$time = ['morning' => '08:00', 'afternoon' => '13:00', 'evening' => $start ? '18:00' : '23:59'][$m[2]];
|
||||
return [$m[1], $time];
|
||||
}
|
||||
|
||||
/** @param array<string,string> $payload */
|
||||
@@ -144,9 +148,11 @@ class DirectAdminVacationApi
|
||||
private function replyOnceTime(array $rule): string
|
||||
{
|
||||
if (!empty($rule['reply_every_message'])) {
|
||||
return '0';
|
||||
return '1m';
|
||||
}
|
||||
return match ((int)($rule['repeat_minutes'] ?? 1440)) {
|
||||
1 => '1m',
|
||||
10 => '10m',
|
||||
30 => '30m',
|
||||
60 => '1h',
|
||||
120 => '2h',
|
||||
@@ -154,7 +160,18 @@ class DirectAdminVacationApi
|
||||
720 => '12h',
|
||||
1440 => '1d',
|
||||
2880 => '2d',
|
||||
4320 => '3d',
|
||||
5760 => '4d',
|
||||
7200 => '5d',
|
||||
8640 => '6d',
|
||||
10080 => '1w',
|
||||
11520 => '8d',
|
||||
12960 => '9d',
|
||||
14400 => '10d',
|
||||
15840 => '11d',
|
||||
17280 => '12d',
|
||||
18720 => '13d',
|
||||
20160 => '14d',
|
||||
default => '1d',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user