Skip to content

Commit

Permalink
fix(outbox): add recipients check
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <anna@nextcloud.com>
  • Loading branch information
miaulalala committed Feb 26, 2024
1 parent f0389ad commit 403111a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/Service/AntiAbuseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\Mail\Service;

use OCA\Mail\AppInfo\Application;
use OCA\Mail\Exception\ManyRecipientsException;
use OCA\Mail\Model\NewMessageData;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ICacheFactory;
Expand Down Expand Up @@ -58,8 +59,16 @@ public function __construct(IConfig $config,
$this->logger = $logger;
}

/**
* @param IUser $user
* @param NewMessageData $messageData
* @return void
* @throws ManyRecipientsException
*/
public function onBeforeMessageSent(IUser $user,
NewMessageData $messageData): void {
$this->checkNumberOfRecipients($user, $messageData);

$abuseDetection = $this->config->getAppValue(
Application::APP_ID,
'abuse_detection',
Expand All @@ -70,7 +79,6 @@ public function onBeforeMessageSent(IUser $user,
return;
}

$this->checkNumberOfRecipients($user, $messageData);
$this->checkRateLimits($user, $messageData);
}

Expand All @@ -79,7 +87,7 @@ private function checkNumberOfRecipients(IUser $user,
$numberOfRecipientsThreshold = (int)$this->config->getAppValue(
Application::APP_ID,
'abuse_number_of_recipients_per_message_threshold',
'0',
'15',
);
if ($numberOfRecipientsThreshold <= 1) {
return;
Expand All @@ -95,6 +103,7 @@ private function checkNumberOfRecipients(IUser $user,
'expected' => $numberOfRecipientsThreshold,
'actual' => $actualNumberOfRecipients,
]);
throw new ManyRecipientsException();
}
}

Expand Down

0 comments on commit 403111a

Please sign in to comment.