fix: match directadmin vacation controls

This commit is contained in:
Marek Miklewicz
2026-06-03 09:21:51 +02:00
parent 0617798821
commit 9174d62706
12 changed files with 176 additions and 53 deletions
+24 -7
View File
@@ -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',
};
}
+18 -2
View File
@@ -5,6 +5,8 @@ final class RuleValidator
{
/** @var array<string,int> */
private const REPLY_FREQUENCIES = [
'1' => 1,
'10' => 10,
'30' => 30,
'60' => 60,
'120' => 120,
@@ -12,7 +14,18 @@ final class RuleValidator
'720' => 720,
'1440' => 1440,
'2880' => 2880,
'4320' => 4320,
'5760' => 5760,
'7200' => 7200,
'8640' => 8640,
'10080' => 10080,
'11520' => 11520,
'12960' => 12960,
'14400' => 14400,
'15840' => 15840,
'17280' => 17280,
'18720' => 18720,
'20160' => 20160,
];
/** @param array<string,mixed> $input @return array<string,mixed> */
@@ -45,7 +58,7 @@ final class RuleValidator
if ($endTs <= $startTs) {
throw new InvalidArgumentException('Data zakończenia musi być późniejsza niż data rozpoczęcia.');
}
[$replyEveryMessage, $repeatMinutes] = self::parseReplyFrequency((string)($input['reply_frequency'] ?? '1440'));
[$replyEveryMessage, $repeatMinutes] = self::parseReplyFrequency((string)($input['reply_frequency'] ?? '1440'), $settings);
return [
'subject_prefix' => $subjectPrefix,
@@ -64,10 +77,13 @@ final class RuleValidator
}
/** @return array{0:bool,1:int} */
private static function parseReplyFrequency(string $value): array
private static function parseReplyFrequency(string $value, Settings $settings): array
{
$value = trim(strtolower($value));
if ($value === 'every') {
if ($settings->backendMode() === 'da') {
throw new InvalidArgumentException('Częstość odpowiedzi jest nieprawidłowa.');
}
return [true, 0];
}
if (isset(self::REPLY_FREQUENCIES[$value])) {
+1 -1
View File
@@ -98,7 +98,7 @@ final class Settings
public function scheduleMode(): string
{
return $this->backendMode() === 'da' ? 'directadmin_period' : 'exact_hour';
return 'exact_hour';
}
public function dynamicMailboxScope(): bool