-
Notifications
You must be signed in to change notification settings - Fork 31
Feat/check max mail size #373
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0800347
Add: check max mail size
tatevikg1 fbd4922
MessageDataManager
tatevikg1 77a6882
Update message status
tatevikg1 d37ecc7
Update coderabbit config
tatevikg1 6a5c209
After review 0
tatevikg1 4492e02
Use HTMLPurifier
tatevikg1 525741a
Use precached message data
tatevikg1 cad6ebb
After review 1
tatevikg1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -73,7 +73,3 @@ reviews: | |
| # code_guidelines: | ||
| # filePatterns: | ||
| # - ".github/AGENT.md" | ||
|
|
||
| checks: | ||
| docstring_coverage: | ||
| enabled: false | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
31 changes: 31 additions & 0 deletions
31
src/Domain/Messaging/Exception/MessageSizeLimitExceededException.php
This file contains hidden or 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,31 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\Core\Domain\Messaging\Exception; | ||
|
|
||
| use RuntimeException; | ||
|
|
||
| class MessageSizeLimitExceededException extends RuntimeException | ||
| { | ||
| public function __construct( | ||
| private readonly int $actualSize, | ||
| private readonly int $maxSize | ||
| ) { | ||
| parent::__construct(sprintf( | ||
| 'Message too large (%d bytes exceeds limit of %d bytes)', | ||
| $actualSize, | ||
| $maxSize | ||
| )); | ||
| } | ||
|
|
||
| public function getActualSize(): int | ||
| { | ||
| return $this->actualSize; | ||
| } | ||
|
|
||
| public function getMaxSize(): int | ||
| { | ||
| return $this->maxSize; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
113 changes: 113 additions & 0 deletions
113
src/Domain/Messaging/Service/Manager/MessageDataManager.php
This file contains hidden or 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,113 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\Core\Domain\Messaging\Service\Manager; | ||
|
|
||
| use Doctrine\ORM\EntityManagerInterface; | ||
| use PhpList\Core\Domain\Messaging\Model\Message; | ||
| use PhpList\Core\Domain\Messaging\Model\MessageData; | ||
| use PhpList\Core\Domain\Messaging\Repository\MessageDataRepository; | ||
|
|
||
| class MessageDataManager | ||
| { | ||
| public function __construct( | ||
| private readonly MessageDataRepository $messageDataRepository, | ||
| private readonly EntityManagerInterface $entityManager, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * Mirrors the legacy setMessageData behavior with safe sanitization and persistence. | ||
| * | ||
| * @param Message $campaign | ||
| * @param string $name | ||
| * @param mixed $value | ||
| */ | ||
| public function setMessageData(Message $campaign, string $name, mixed $value): void | ||
| { | ||
| if ($name === 'PHPSESSID' || $name === session_name()) { | ||
| return; | ||
| } | ||
|
|
||
| $value = $this->normalizeValueByName($name, $value); | ||
|
|
||
| // todo: remove this once we have a proper way to handle targetlists | ||
| // if ($name === 'targetlist' && is_array($value)) { | ||
| // $this->listMessageRepository->removeAllListAssociationsForMessage($campaign); | ||
| // | ||
| // if (!empty($value['all']) || !empty($value['allactive'])) { | ||
| // // todo: should be with $GLOBALS['subselect'] filter for access control | ||
| // foreach ($this->subscriberListRepository->getAllActive() as $list) { | ||
| // $listMessage = (new ListMessage()) | ||
| // ->setMessage($campaign) | ||
| // ->setList($list); | ||
| // $this->listMessageRepository->persist($listMessage); | ||
| // } | ||
| // // once we used "all" to set all, unset it, to avoid confusion trying to unselect lists | ||
| // unset($value['all']); | ||
| // } else { | ||
| // foreach ($value as $listId => $val) { | ||
| // // see #16940 - ignore a list called "unselect" which is there to allow unselecting all | ||
| // if ($listId !== 'unselect') { | ||
| // $list = $this->subscriberListRepository->find($listId); | ||
| // $listMessage = (new ListMessage()) | ||
| // ->setMessage($campaign) | ||
| // ->setList($list); | ||
| // $this->listMessageRepository->persist($listMessage); | ||
| // } | ||
| // } | ||
| // } | ||
| // } | ||
|
|
||
| if (is_array($value) || is_object($value)) { | ||
| $value = 'SER:' . serialize($value); | ||
| } | ||
|
|
||
| $entity = $this->getOrCreateMessageDataEntity($campaign, $name); | ||
| $entity->setData($value !== null ? (string) $value : null); | ||
| } | ||
|
|
||
| /** | ||
| * Remove potentially harmful JavaScript from HTML content. | ||
| * | ||
| * This is a conservative cleaner: removes <script> blocks, javascript: URLs, | ||
| * and inline event handlers (on*) attributes. | ||
| */ | ||
| private function disableJavascript(string $html): string | ||
| { | ||
| // Remove script tags and their content | ||
| $clean = preg_replace('#<script\b[^>]*>.*?</script>#is', '', $html) ?? $html; | ||
|
|
||
| // Remove on*="..." event handler attributes | ||
| $clean = preg_replace('/\s+on[a-zA-Z]+\s*=\s*("[^"]*"|\'[^\']*\'|[^\s>]+)/i', '', $clean) ?? $clean; | ||
|
|
||
| // Neutralize javascript: and data: URIs in href/src/style | ||
| $clean = preg_replace('/\b(href|src)\s*=\s*("|\')\s*(javascript:|data:)[^\2]*\2/i', '$1="#"', $clean) ?? $clean; | ||
| return preg_replace('/\bstyle\s*=\s*("|\')[^\1]*\1/i', '', $clean) ?? $clean; | ||
| } | ||
|
|
||
| private function normalizeValueByName(string $name, mixed $value) | ||
| { | ||
| return match ($name) { | ||
| 'subject', 'campaigntitle' => is_string($value) ? strip_tags($value) : $value, | ||
| 'message' => is_string($value) ? $this->disableJavascript($value) : $value, | ||
| 'excludelist' => is_array($value) ? array_filter($value, fn ($val) => is_numeric($val)) : $value, | ||
| 'footer' => is_string($value) ? preg_replace('/<!--.*?-->/', '', $value) : $value, | ||
| default => $value, | ||
| }; | ||
| } | ||
|
|
||
| private function getOrCreateMessageDataEntity(Message $campaign, string $name) | ||
| { | ||
| $entity = $this->messageDataRepository->findByIdAndName($campaign->getId(), $name); | ||
| if (!$entity instanceof MessageData) { | ||
| $entity = (new MessageData()) | ||
| ->setId($campaign->getId()) | ||
| ->setName($name); | ||
| $this->entityManager->persist($entity); | ||
| } | ||
|
|
||
| return $entity; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.