-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
- Loading branch information
Showing
26 changed files
with
860 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail; | ||
|
||
use JsonSerializable; | ||
use ReturnTypeWillChange; | ||
|
||
class PhishingDetectionList implements JsonSerializable { | ||
|
||
/** @var PhishingDetectionResult[] */ | ||
private array $checks; | ||
|
||
private bool $warning = false; | ||
|
||
/** | ||
* @param PhishingDetectionResult[] $checks | ||
*/ | ||
public function __construct(array $checks = []) { | ||
$this->checks = $checks; | ||
} | ||
|
||
public function addCheck(PhishingDetectionResult $check) { | ||
$this->checks[] = $check; | ||
} | ||
|
||
private function isWarning() { | ||
foreach ($this->checks as $check) { | ||
if (in_array($check->getType(), [PhishingDetectionResult::DATE_CHECK, PhishingDetectionResult::LINK_CHECK, PhishingDetectionResult::CUSTOM_EMAIL_CHECK, PhishingDetectionResult::CONTACTS_CHECK]) && $check->isPhishing()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
#[ReturnTypeWillChange] | ||
public function jsonSerialize() { | ||
$result = array_map(static function (PhishingDetectionResult $check) { | ||
return $check->jsonSerialize(); | ||
}, $this->checks); | ||
return [ | ||
'checks' => $result, | ||
'warning' => $this->isWarning(), | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Mail; | ||
|
||
use JsonSerializable; | ||
use ReturnTypeWillChange; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
class PhishingDetectionResult implements JsonSerializable { | ||
|
||
public const DATE_CHECK = "Date"; | ||
public const LINK_CHECK = "Link"; | ||
public const REPLYTO_CHECK = "Reply-To"; | ||
public const CUSTOM_EMAIL_CHECK = "Custom Email"; | ||
public const CONTACTS_CHECK = "Contacts"; | ||
public const TRUSTED_CHECK = "Trusted"; | ||
|
||
private string $message = ""; | ||
private bool $isPhishing; | ||
private array $additionalData = []; | ||
private string $type; | ||
|
||
public function __construct(string $type, bool $isPhishing, string $message = "", array $additionalData = []) { | ||
$this->type = $type; | ||
$this->message = $message; | ||
$this->isPhishing = $isPhishing; | ||
$this->additionalData = $additionalData; | ||
|
||
} | ||
|
||
public function getType(): string { | ||
return $this->type; | ||
} | ||
|
||
public function isPhishing(): bool { | ||
return $this->isPhishing; | ||
} | ||
|
||
#[ReturnTypeWillChange] | ||
public function jsonSerialize() { | ||
return [ | ||
'type' => $this->type, | ||
'isPhishing' => $this->isPhishing, | ||
'message' => $this->message, | ||
'additionalData' => $this->additionalData, | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.