Skip to content

Commit 49eb5da

Browse files
committed
chore: disable filtering invalid emails in MailToFileSender
1 parent cb9044d commit 49eb5da

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/Sender/MailToFileSender.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public function send(iterable $frames): void
3333
continue;
3434
}
3535

36-
foreach ($this->collectUniqueEmails($frame->message) as $email) {
37-
$email = self::normalizeEmail($email);
38-
39-
$path = $this->path . DIRECTORY_SEPARATOR . $email;
36+
foreach (tr(self::fetchDirectories($frame->message)) as $dirName) {
37+
$path = $this->path . DIRECTORY_SEPARATOR . $dirName;
4038
FileSystem::mkdir($path);
4139
$filepath = \sprintf("%s/%s.json", $path, $frame->time->format('Y-m-d-H-i-s-v'));
4240

@@ -53,24 +51,22 @@ public function send(iterable $frames): void
5351
*/
5452
private static function normalizeEmail(string $email): string
5553
{
56-
return \str_replace('@', '[at]', \trim($email));
54+
return \preg_replace(['/[^a-z0-9.\\- @]/i', '/@/', '/\s+/'], ['!', '[at]', '_'], $email);
5755
}
5856

5957
/**
6058
* @return list<non-empty-string>
6159
*/
62-
private function collectUniqueEmails(Message\Smtp $message): array
60+
private static function fetchDirectories(Message\Smtp $message): array
6361
{
64-
$fn = static fn(Contact $c) => $c->email;
65-
66-
return \array_unique(
62+
return
6763
\array_filter(
68-
\array_merge(
69-
\array_map($fn, $message->getBcc()),
70-
\array_map($fn, $message->getTo()),
64+
\array_unique(
65+
\array_map(
66+
static fn(Contact $c) => self::normalizeEmail($c->email),
67+
\array_merge($message->getBcc(), $message->getTo()),
68+
),
7169
),
72-
static fn(string $email): bool => false !== \filter_var($email, \FILTER_VALIDATE_EMAIL)
73-
),
74-
);
70+
);
7571
}
7672
}

0 commit comments

Comments
 (0)