Skip to content

Commit

Permalink
chore: disable filtering invalid emails in MailToFileSender
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jan 16, 2025
1 parent cb9044d commit 49eb5da
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/Sender/MailToFileSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public function send(iterable $frames): void
continue;
}

foreach ($this->collectUniqueEmails($frame->message) as $email) {
$email = self::normalizeEmail($email);

$path = $this->path . DIRECTORY_SEPARATOR . $email;
foreach (tr(self::fetchDirectories($frame->message)) as $dirName) {

Check failure on line 36 in src/Sender/MailToFileSender.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedAssignment

src/Sender/MailToFileSender.php:36:69: MixedAssignment: Unable to determine the type that $dirName is being assigned to (see https://psalm.dev/032)
$path = $this->path . DIRECTORY_SEPARATOR . $dirName;

Check failure on line 37 in src/Sender/MailToFileSender.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedOperand

src/Sender/MailToFileSender.php:37:61: MixedOperand: Right operand cannot be mixed (see https://psalm.dev/059)
FileSystem::mkdir($path);
$filepath = \sprintf("%s/%s.json", $path, $frame->time->format('Y-m-d-H-i-s-v'));

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

Check failure on line 54 in src/Sender/MailToFileSender.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

LessSpecificReturnStatement

src/Sender/MailToFileSender.php:54:16: LessSpecificReturnStatement: The type 'null|string' is more general than the declared return type 'non-empty-string' for Buggregator\Trap\Sender\MailToFileSender::normalizeEmail (see https://psalm.dev/129)
}

/**
* @return list<non-empty-string>

Check failure on line 58 in src/Sender/MailToFileSender.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MoreSpecificReturnType

src/Sender/MailToFileSender.php:58:16: MoreSpecificReturnType: The declared return type 'list<non-empty-string>' for Buggregator\Trap\Sender\MailToFileSender::fetchDirectories is more specific than the inferred return type 'array<array-key, non-falsy-string>' (see https://psalm.dev/070)
*/
private function collectUniqueEmails(Message\Smtp $message): array
private static function fetchDirectories(Message\Smtp $message): array
{
$fn = static fn(Contact $c) => $c->email;

return \array_unique(
return
\array_filter(

Check failure on line 63 in src/Sender/MailToFileSender.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

LessSpecificReturnStatement

src/Sender/MailToFileSender.php:63:13: LessSpecificReturnStatement: The type 'array<array-key, non-falsy-string>' is more general than the declared return type 'list<non-empty-string>' for Buggregator\Trap\Sender\MailToFileSender::fetchDirectories (see https://psalm.dev/129)
\array_merge(
\array_map($fn, $message->getBcc()),
\array_map($fn, $message->getTo()),
\array_unique(
\array_map(
static fn(Contact $c) => self::normalizeEmail($c->email),

Check failure on line 66 in src/Sender/MailToFileSender.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyNullArgument

src/Sender/MailToFileSender.php:66:71: PossiblyNullArgument: Argument 1 of Buggregator\Trap\Sender\MailToFileSender::normalizeEmail cannot be null, possibly null value provided (see https://psalm.dev/078)
\array_merge($message->getBcc(), $message->getTo()),
),
),
static fn(string $email): bool => false !== \filter_var($email, \FILTER_VALIDATE_EMAIL)
),
);
);
}
}

0 comments on commit 49eb5da

Please sign in to comment.