Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Command/AnalyzeBounceMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AnalyzeBounceMailCommand extends Command
/**
* Configure the command by defining the name, options and arguments
*/
public function configure()
public function configure(): void
{
$this->setDescription('This command will get bounce mail from the configured mailbox')
->addOption(
Expand Down
2 changes: 1 addition & 1 deletion Classes/Command/DirectmailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DirectmailCommand extends Command
/**
* Configure the command by defining the name, options and arguments
*/
public function configure()
public function configure(): void
{
$this->setDescription('This command invokes dmailer in order to process queued messages.');
//$this->setHelp('');
Expand Down
2 changes: 1 addition & 1 deletion Classes/Command/InvokeMailerEngineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class InvokeMailerEngineCommand extends Command
/**
* Configure the command by defining the name, options and arguments
*/
public function configure()
public function configure(): void
{
$this->setDescription('Invoke Mailer Engine of EXT:directmail');
$this->setHelp('
Expand Down
12 changes: 7 additions & 5 deletions Classes/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

use DirectMailTeam\DirectMail\Repository\SysDmailCategoryRepository;
use DirectMailTeam\DirectMail\Repository\SysDmailTtContentCategoryMmRepository;
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MailUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Container class for auxilliary functions of tx_directmail
Expand All @@ -34,7 +34,7 @@ class Container
public $boundaryEnd = '<!--DMAILER_SECTION_BOUNDARY_END-->';

/**
* @var TypoScriptFrontendController
* @var ContentObjectRenderer
*/
protected $cObj;

Expand All @@ -58,14 +58,15 @@ public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
*
* @return string content of the email with dmail boundaries
*/
#[AsAllowedCallable]
public function insert_dMailer_boundaries($content, $conf = [])
{
if (isset($conf['useParentCObj']) && $conf['useParentCObj']) {
$this->cObj = $conf['parentObj']->cObj;
}

// this check could probably be moved to TS
if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries']) {
if ($GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getConfigArray()['insertDmailerBoundaries'] ?? false) {
if ($content != '') {
// setting the default
$categoryList = '';
Expand Down Expand Up @@ -119,8 +120,8 @@ public function stripInnerBoundaries($content)
*/
public function breakLines($content, array $conf)
{
$linebreak = $GLOBALS['TSFE']->cObj->stdWrap(($conf['linebreak'] ? $conf['linebreak'] : chr(32) . LF), $conf['linebreak.']);
$charWidth = $GLOBALS['TSFE']->cObj->stdWrap(($conf['charWidth'] ? (int)$conf['charWidth'] : 76), $conf['charWidth.']);
$linebreak = $this->cObj->stdWrap(($conf['linebreak'] ? $conf['linebreak'] : chr(32) . LF), $conf['linebreak.']);
$charWidth = $this->cObj->stdWrap(($conf['charWidth'] ? (int)$conf['charWidth'] : 76), $conf['charWidth.']);

return MailUtility::breakLinesForEmail($content, $linebreak, $charWidth);
}
Expand All @@ -133,6 +134,7 @@ public function breakLines($content, array $conf)
*
* @return string $content: the string wrapped with boundaries
*/
#[AsAllowedCallable]
public function insertSitemapBoundaries($content, array $conf)
{
$uid = (int)$this->cObj->data['uid'];
Expand Down
22 changes: 20 additions & 2 deletions Classes/DirectMailUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public static function getFullUrlsForDirectMailRecord(array $row): array
$result['plainTextUrl'] = '';
} else {
$urlParts = @parse_url($result['plainTextUrl']);
if (!$urlParts['scheme']) {
if (!($urlParts['scheme'] ?? null)) {
$result['plainTextUrl'] = 'http://' . $result['plainTextUrl'];
}
}
Expand All @@ -344,7 +344,7 @@ public static function getFullUrlsForDirectMailRecord(array $row): array
$result['htmlUrl'] = '';
} else {
$urlParts = @parse_url($result['htmlUrl']);
if (!$urlParts['scheme']) {
if (!($urlParts['scheme'] ?? null)) {
$result['htmlUrl'] = 'http://' . $result['htmlUrl'];
}
}
Expand All @@ -367,6 +367,24 @@ public static function intInRangeWrapper(
return MathUtility::forceIntegerInRange($theInt, $min, $max, $zeroValue);
}

/**
* Converts a string between character sets.
*/
public static function convertCharset(string $value, string $fromCharset, string $toCharset): string
{
$fromCharset = strtolower($fromCharset);
$toCharset = strtolower($toCharset);
if ($fromCharset === $toCharset) {
return $value;
}

try {
return mb_convert_encoding($value, $toCharset, $fromCharset);
} catch (\ValueError) {
return $value;
}
}

/**
* Takes a clear-text message body for a plain text email, finds all 'http://' links and if they are longer than 76 chars they are converted to a shorter URL with a hash parameter.
* The real parameter is stored in the database and the hash-parameter/URL will be redirected to the real parameter when the link is clicked.
Expand Down
28 changes: 5 additions & 23 deletions Classes/Dmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Mime\Address;
use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Mail\Mailer;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
Expand Down Expand Up @@ -129,10 +129,6 @@ class Dmailer implements LoggerAwareInterface
*/
protected int $simulateUsergroup = 0;

/**
* @var CharsetConverter
*/
protected $charsetConverter;
protected string $message = '';
protected bool $notificationJob = false;
protected string $jumperURLPrefix = '';
Expand Down Expand Up @@ -220,14 +216,6 @@ public function setJumperURLUseId(bool $jumperURLUseId): void
$this->jumperURLUseId = $jumperURLUseId;
}

protected function getCharsetConverter()
{
if (!$this->charsetConverter) {
$this->charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
}
return $this->charsetConverter;
}

protected function getMarkerBasedTemplateService(): MarkerBasedTemplateService
{
return GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
Expand Down Expand Up @@ -725,7 +713,7 @@ protected function setBeginEnd(int $mid, string $key): void
$this->logger->debug($subject . ': ' . $message);

if ($this->notificationJob === true) {
$fromName = $this->getCharsetConverter()->conv($this->fromName, $this->charset, $this->backendCharset) ?? '';
$fromName = DirectMailUtility::convertCharset($this->fromName, $this->charset, $this->backendCharset);

$mail = GeneralUtility::makeInstance(MailMessage::class);
$mail->setTo($this->fromEmail, $fromName);
Expand All @@ -737,7 +725,7 @@ protected function setBeginEnd(int $mid, string $key): void
}

$mail->text($message);
$mail->send();
GeneralUtility::makeInstance(Mailer::class)->send($mail);
}
}

Expand Down Expand Up @@ -923,7 +911,7 @@ protected function sendTheMail(Address $recipient, array $recipientRow = null):
}
}

$mailer->send();
GeneralUtility::makeInstance(Mailer::class)->send($mailer);
}

/**
Expand Down Expand Up @@ -1451,13 +1439,7 @@ protected function createRecipient(string $email, string $name = ''): Address
protected function ensureCorrectEncoding(string $inputString): string
{
if ($inputString) {
return $this
->getCharsetConverter()
->conv(
$inputString,
$this->backendCharset,
$this->charset
);
return DirectMailUtility::convertCharset($inputString, $this->backendCharset, $this->charset);
}

return '';
Expand Down
52 changes: 0 additions & 52 deletions Classes/Hooks/TypoScriptFrontendController.php

This file was deleted.

3 changes: 2 additions & 1 deletion Classes/Middleware/JumpurlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Crypto\HashService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

Expand Down Expand Up @@ -325,7 +326,7 @@ protected function performFeUserAutoLogin()
*/
protected function calculateJumpUrlHash(string $targetUrl): string
{
return GeneralUtility::hmac($targetUrl, 'jumpurl');
return GeneralUtility::makeInstance(HashService::class)->hmac($targetUrl, 'jumpurl');
}

/**
Expand Down
41 changes: 41 additions & 0 deletions Classes/Middleware/SimulateUsergroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace DirectMailTeam\DirectMail\Middleware;

use DirectMailTeam\DirectMail\Utility\DmRegistryUtility;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;

class SimulateUsergroup implements MiddlewareInterface
{
public function __construct(
private readonly Context $context,
private readonly DmRegistryUtility $registryUtility,
) {}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$queryParams = $request->getQueryParams();
$directMailFeGroup = (int)($queryParams['dmail_fe_group'] ?? 0);
$accessToken = (string)($queryParams['access_token'] ?? '');

if ($directMailFeGroup > 0 && $this->registryUtility->validateAndRemoveAccessToken($accessToken)) {
/** @var UserAspect $userAspect */
$userAspect = $this->context->getAspect('frontend.user');
$frontendUser = $request->getAttribute('frontend.user');

if ($frontendUser instanceof FrontendUserAuthentication && !in_array($directMailFeGroup, $userAspect->getGroupIds(), true)) {
$this->context->setAspect('frontend.user', new UserAspect($frontendUser, [$directMailFeGroup]));
}
}

return $handler->handle($request);
}
}
18 changes: 5 additions & 13 deletions Classes/Module/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Attribute\Controller;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Imaging\IconFactory;
use DirectMailTeam\DirectMail\Repository\PagesRepository;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Type\Bitmask\Permission;

final class ConfigurationController extends MainController
Expand Down Expand Up @@ -82,9 +75,6 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac

public function indexAction(ModuleTemplate $view): ResponseInterface
{
// Load JavaScript via PageRenderer
$this->pageRenderer->loadRequireJs();
$this->pageRenderer->loadJavaScriptModule('@directmailteam/diractmail/Configuration.js');
if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) {

$module = $this->getModulName();
Expand Down Expand Up @@ -138,20 +128,20 @@ public function indexAction(ModuleTemplate $view): ResponseInterface
}

/**
* @return ResponseFactory
* @return ResponseFactoryInterface
*/
protected function getResponseFactory(): ResponseFactoryInterface
{
return GeneralUtility::makeInstance(ResponseFactoryInterface::class);
}

public function updateConfigAction(ServerRequestInterface $request): ResponseInterface
public function updateConfigAction(ServerRequestInterface $request): ?ResponseInterface
{
$this->id = (int)($request->getParsedBody()['uid'] ?? 0);
$permsClause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
$pageAccess = BackendUtility::readPageAccess($this->id, $permsClause);
$this->pageinfo = is_array($pageAccess) ? $pageAccess : [];
$this->access = is_array($this->pageinfo) ? true : false;
$this->access = is_array($this->pageinfo);


if (($this->id && $this->access) || ($this->isAdmin() && !$this->id)) {
Expand Down Expand Up @@ -192,6 +182,8 @@ public function updateConfigAction(ServerRequestInterface $request): ResponseInt

}
}

return null;
}

protected function setDefaultValues(): void
Expand Down
Loading