32 lines
1012 B
PHP
32 lines
1012 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
final class MessageClassifier
|
|
{
|
|
/** @param array<string,string> $headers */
|
|
public static function shouldSuppress(array $headers, string $sender): bool
|
|
{
|
|
$sender = strtolower(trim($sender));
|
|
if ($sender === '' || str_starts_with($sender, 'mailer-daemon') || str_starts_with($sender, 'postmaster')) {
|
|
return true;
|
|
}
|
|
$normalized = [];
|
|
foreach ($headers as $key => $value) {
|
|
$normalized[strtolower(trim($key))] = strtolower(trim($value));
|
|
}
|
|
if (($normalized['auto-submitted'] ?? 'no') !== 'no') {
|
|
return true;
|
|
}
|
|
if (in_array($normalized['precedence'] ?? '', ['bulk', 'list', 'junk'], true)) {
|
|
return true;
|
|
}
|
|
if (($normalized['list-id'] ?? '') !== '') {
|
|
return true;
|
|
}
|
|
if (str_contains($normalized['content-type'] ?? '', 'delivery-status')) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|