feat: use vacation subject prefix

This commit is contained in:
Marek Miklewicz
2026-06-02 21:28:31 +02:00
parent 64b62a5793
commit 56709817b5
18 changed files with 220 additions and 68 deletions
+30 -2
View File
@@ -55,15 +55,19 @@ final class GlobalAutoresponderWorker
if ($ruleId === '') {
continue;
}
$repeatMinutes = $this->settings->replyEveryMessage() ? 0 : $this->settings->repeatMinutes();
$repeatMinutes = !empty($rule['reply_every_message']) ? 0 : max(0, (int)($rule['repeat_minutes'] ?? 1440));
if (!$this->repeat->shouldSend($owner, $ruleId, $recipient, $sender, $repeatMinutes)) {
continue;
}
$replySubject = self::replySubject(
(string)($rule['subject_prefix'] ?? $rule['subject'] ?? ''),
self::headerValue($headers, 'subject')
);
$ok = (bool)call_user_func(
$this->send,
$recipient,
strtolower($sender),
(string)$rule['subject'],
$replySubject,
(string)$rule['body']
);
if ($ok) {
@@ -155,6 +159,30 @@ final class GlobalAutoresponderWorker
}
return $headers;
}
/** @param array<string,string> $headers */
private static function headerValue(array $headers, string $name): string
{
foreach ($headers as $key => $value) {
if (strcasecmp($key, $name) === 0) {
return trim($value);
}
}
return '';
}
private static function replySubject(string $prefix, string $originalSubject): string
{
$prefix = trim($prefix);
$originalSubject = trim($originalSubject);
if ($prefix !== '' && $originalSubject !== '') {
return str_ends_with($prefix, ':') ? $prefix . ' ' . $originalSubject : $prefix . ': ' . $originalSubject;
}
if ($prefix !== '') {
return $prefix;
}
return $originalSubject !== '' ? $originalSubject : 'Automatic reply';
}
}
if (PHP_SAPI === 'cli' && realpath((string)($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {