diff options
author | Matthias <git@myrho.net> | 2021-03-26 22:16:13 +0300 |
---|---|---|
committer | Matthias <git@myrho.net> | 2021-03-26 22:37:10 +0300 |
commit | 69b905d92cc6b37b0e5ad506f8ff198d6b87dc0e (patch) | |
tree | aaccb2b69cb2e8e94f7f92817cf24e3119a50214 /lib | |
parent | 5bf2f9667fbefbad5e695b862c5e59bf823190db (diff) |
warn before sending to many recipients in to/cc
Signed-off-by: Matthias <git@myrho.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/AccountsController.php | 9 | ||||
-rw-r--r-- | lib/Exception/ManyRecipientsException.php | 32 |
2 files changed, 40 insertions, 1 deletions
diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php index be3947fbb..893a750d7 100644 --- a/lib/Controller/AccountsController.php +++ b/lib/Controller/AccountsController.php @@ -35,6 +35,7 @@ use OCA\Mail\Contracts\IMailManager; use OCA\Mail\Contracts\IMailTransmission; use OCA\Mail\Db\Mailbox; use OCA\Mail\Exception\ClientException; +use OCA\Mail\Exception\ManyRecipientsException; use OCA\Mail\Exception\ServiceException; use OCA\Mail\Http\JsonResponse as MailJsonResponse; use OCA\Mail\Model\NewMessageData; @@ -383,7 +384,8 @@ class AccountsController extends Controller { int $draftId = null, int $messageId = null, array $attachments = [], - int $aliasId = null): JSONResponse { + int $aliasId = null, + bool $force = false): JSONResponse { $account = $this->accountService->find($this->currentUserId, $id); $alias = $aliasId ? $this->aliasesService->find($aliasId, $this->currentUserId) : null; @@ -391,6 +393,11 @@ class AccountsController extends Controller { $expandedCc = $this->groupsIntegration->expand($cc); $expandedBcc = $this->groupsIntegration->expand($bcc); + $count = substr_count($expandedTo, ',') + substr_count($expandedCc, ','); + if (!$force && $count >= 10) { + throw new ManyRecipientsException(); + } + $messageData = NewMessageData::fromRequest($account, $expandedTo, $expandedCc, $expandedBcc, $subject, $body, $attachments, $isHtml, $requestMdn); $repliedMessageData = null; if ($messageId !== null) { diff --git a/lib/Exception/ManyRecipientsException.php b/lib/Exception/ManyRecipientsException.php new file mode 100644 index 000000000..e90d3c01d --- /dev/null +++ b/lib/Exception/ManyRecipientsException.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/* + * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2021 Matthias Rella <mrella@pisys.eu> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace OCA\Mail\Exception; + +class ManyRecipientsException extends ClientException { + public function __construct() { + parent::__construct("Many recipients in TO and/or CC"); + } +} |