Skip to content

Commit

Permalink
fix: phishing detection fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Dec 10, 2024
1 parent c0f17db commit 338f0ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Service/PhishingDetection/DateCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Mail\Service\PhishingDetection;

use DateException;
use OCA\Mail\PhishingDetectionResult;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N;
Expand All @@ -24,7 +25,11 @@ public function __construct(IL10N $l10n, ITimeFactory $timeFactory) {

public function run(string $date): PhishingDetectionResult {
$now = $this->timeFactory->getDateTime('now');
$dt = $this->timeFactory->getDateTime($date);
try {
$dt = $this->timeFactory->getDateTime($date);
} catch (DateException $e) {
return new PhishingDetectionResult(PhishingDetectionResult::DATE_CHECK, false);

Check warning on line 31 in lib/Service/PhishingDetection/DateCheck.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/PhishingDetection/DateCheck.php#L30-L31

Added lines #L30 - L31 were not covered by tests
}
if ($dt > $now) {
return new PhishingDetectionResult(PhishingDetectionResult::DATE_CHECK, true, $this->l10n->t('Sent date is in the future'));
}
Expand Down
8 changes: 8 additions & 0 deletions lib/Service/PhishingDetection/LinkCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public function run(string $htmlMessage) : PhishingDetectionResult {
if ($href === '') {
continue;
}
// handle links that are wrapped in brackets, quotes, etc.
$firstChar = $linkText[0];
$lastChar = $linkText[strlen($linkText) - 1];

if (!ctype_alpha($firstChar) && !ctype_alpha($lastChar)) {
$linkText = substr($linkText, 1, -1);

Check warning on line 71 in lib/Service/PhishingDetection/LinkCheck.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/PhishingDetection/LinkCheck.php#L71

Added line #L71 was not covered by tests
}

$zippedArray[] = [
'href' => $href,
'linkText' => $linkText
Expand Down

0 comments on commit 338f0ed

Please sign in to comment.