Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(phishing): NPEs #10371

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions lib/Service/PhishingDetection/PhishingDetectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Mail\Service\PhishingDetection;

use Horde_Mime_Headers;
use Horde_Mime_Headers_Element_Address;
use OCA\Mail\AddressList;
use OCA\Mail\PhishingDetectionList;

Expand All @@ -31,20 +32,31 @@

public function checkHeadersForPhishing(Horde_Mime_Headers $headers, bool $hasHtmlMessage, string $htmlMessage = ''): array {
$list = new PhishingDetectionList();
/** @psalm-suppress UndefinedMethod */
$fromFN = AddressList::fromHorde($headers->getHeader('From')->getAddressList(true))->first()->getLabel();
/** @psalm-suppress UndefinedMethod */
$fromEmail = AddressList::fromHorde($headers->getHeader('From')->getAddressList(true))->first()->getEmail();
/** @psalm-suppress UndefinedMethod */
$replyToEmailHeader = $headers->getHeader('Reply-To')?->getAddressList(true);
$replyToEmail = isset($replyToEmailHeader)? AddressList::fromHorde($replyToEmailHeader)->first()->getEmail() : null ;
$fromHeader = $headers->getHeader('From');
$sender = AddressList::fromHorde($fromHeader->getAddressList(true))->first();

Check failure on line 36 in lib/Service/PhishingDetection/PhishingDetectionService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedMethod

lib/Service/PhishingDetection/PhishingDetectionService.php:36:49: UndefinedMethod: Method Horde_Mime_Headers_Element::getAddressList does not exist (see https://psalm.dev/022)
$fromFN = $sender?->getLabel();
$fromEmail = $sender?->getEmail();
$replyToHeader = $headers->getHeader('Reply-To');
if ($replyToHeader instanceof Horde_Mime_Headers_Element_Address) {
$replyToEmailHeader = $replyToHeader->getAddressList(true);
$replyToEmail = AddressList::fromHorde($replyToEmailHeader)->first()?->getEmail();
} else {
$replyToEmail = null;

Check warning on line 44 in lib/Service/PhishingDetection/PhishingDetectionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/PhishingDetection/PhishingDetectionService.php#L44

Added line #L44 was not covered by tests
}
$date = $headers->getHeader('Date')->__get('value');
/** @psalm-suppress UndefinedMethod */
$customEmail = AddressList::fromHorde($headers->getHeader('From')->getAddressList(true))->first()->getCustomEmail();
$list->addCheck($this->replyToCheck->run($fromEmail, $replyToEmail));
$list->addCheck($this->contactCheck->run($fromFN, $fromEmail));
$list->addCheck($this->dateCheck->run($date));
$list->addCheck($this->customEmailCheck->run($fromEmail, $customEmail));
$customEmail = $sender?->getCustomEmail();
if ($fromEmail !== null) {
$list->addCheck($this->replyToCheck->run($fromEmail, $replyToEmail));
}
if ($fromFN !== null) {
$list->addCheck($this->contactCheck->run($fromFN, $fromEmail));
}
if (is_string($date)) {
$list->addCheck($this->dateCheck->run($date));
}
if ($fromEmail !== null) {
$list->addCheck($this->customEmailCheck->run($fromEmail, $customEmail));
}
if ($hasHtmlMessage) {
$list->addCheck($this->linkCheck->run($htmlMessage));
}
Expand Down
Loading