Skip to content

Commit

Permalink
run php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Neyman committed Jan 5, 2023
1 parent 6c824ec commit bffb576
Show file tree
Hide file tree
Showing 59 changed files with 898 additions and 1,094 deletions.
35 changes: 14 additions & 21 deletions Classes/Command/AnalyzeBounceMailCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace DirectMailTeam\DirectMail\Command;

use DirectMailTeam\DirectMail\Dmailer;
use DirectMailTeam\DirectMail\Repository\SysDmailMaillogRepository;
use DirectMailTeam\DirectMail\Utility\ReadmailUtility;
use Fetch\Server;
Expand Down Expand Up @@ -106,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('type')) {
$type = $input->getOption('type');
//$io->writeln($type);
if(!in_array($type, ['imap', 'pop3'])) {
if (!in_array($type, ['imap', 'pop3'])) {
$io->warning('Type: only imap or pop3');
return Command::FAILURE;
}
Expand All @@ -122,16 +122,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
// we are connected to mail server
// get unread mails
$messages = $mailServer->search('UNSEEN', $count);
if(count($messages)) {
if (count($messages)) {
/** @var Message $message The message object */
foreach ($messages as $message) {
// process the mail
if ($this->processBounceMail($message)) {
//$io->writeln($message->getSubject());
// set delete
$message->delete();
}
else {
} else {
$message->setFlag('SEEN');
}
}
Expand All @@ -141,9 +140,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
imap_close($mailServer->getImapStream());
return Command::SUCCESS;
}
else {
return Command::FAILURE;
}

return Command::FAILURE;

return Command::SUCCESS;
}
Expand All @@ -167,13 +165,12 @@ private function processBounceMail($message)
$bouncedMail = $attachment->getData();
// Find mail id
$midArray = $readMail->find_XTypo3MID($bouncedMail);
if (false === empty($midArray)) {
if (empty($midArray) === false) {
// if mid, rid and rtbl are found, then stop looping
break;
}
}
}
else {
} else {
// search in MessageBody (see rfc822-headers as Attachments placed )
$midArray = $readMail->find_XTypo3MID($message->getMessageBody());
}
Expand All @@ -191,7 +188,6 @@ private function processBounceMail($message)

// only write to log table, if we found a corresponding recipient record
if (!empty($row)) {

$midArray['email'] = $row['email'];
try {
return $sysDmailMaillogRepository->analyzeBounceMailAddToMailLog(
Expand All @@ -204,8 +200,7 @@ private function processBounceMail($message)
// Log $e->getMessage();
return false;
}
}
else {
} else {
return false;
}
}
Expand Down Expand Up @@ -240,24 +235,22 @@ private function connectMailServer(string $server, int $port, string $type, stri
$imapStream = $mailServer->getImapStream();
return $mailServer;
} catch (\Exception $e) {
$io->error($this->languageService->getLL('scheduler.bounceMail.dataVerification').$e->getMessage());
$io->error($this->languageService->getLL('scheduler.bounceMail.dataVerification') . $e->getMessage());
return false;
}
}

/**
*
* @return int
*/
private function getTimestampFromAspect(): int {
private function getTimestampFromAspect(): int
{
$context = GeneralUtility::makeInstance(Context::class);
return $context->getPropertyFromAspect('date', 'timestamp');
}

/**
* @return void
*/
private function setLanguageService(): void {
private function setLanguageService(): void
{
$languageServiceFactory = GeneralUtility::makeInstance(LanguageServiceFactory::class);
$this->languageService = $languageServiceFactory->create('en'); //@TODO
$this->languageService->includeLLFile('EXT:direct_mail/Resources/Private/Language/locallang_mod2-6.xlf');
Expand Down
1 change: 1 addition & 0 deletions Classes/Command/DirectmailCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace DirectMailTeam\DirectMail\Command;

use DirectMailTeam\DirectMail\Dmailer;
Expand Down
7 changes: 2 additions & 5 deletions Classes/Command/InvokeMailerEngineCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace DirectMailTeam\DirectMail\Command;

/*
Expand Down Expand Up @@ -32,14 +33,11 @@
* This class replaces the earlier version of EXT:direct_mail/cli/cli_direct_mail.php from Ivan Kartolo, (c) 2008
* Executes the earlier solely option named 'masssend' which has been dropped as optional argument
*
* @package TYPO3
* @subpackage tx_directmail
* @author 2019 J.Kummer
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 2
*/
class InvokeMailerEngineCommand extends Command
{

/**
* Configure the command by defining the name, options and arguments
*/
Expand Down Expand Up @@ -71,9 +69,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (filemtime($lockfile) > (time() - (60 * 60 * 24))) {
$io->warning('TYPO3 Direct Mail Cron: Aborting, another process is already running!');
return Command::FAILURE;
} else {
$io->writeln('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...');
}
$io->writeln('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...');
}

touch($lockfile);
Expand Down
8 changes: 3 additions & 5 deletions Classes/Container.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace DirectMailTeam\DirectMail;

/*
Expand Down Expand Up @@ -26,9 +27,6 @@
*
* @author Kasper Skårhøj <kasperYYYY>@typo3.com>
* @author Thorsten Kahler <[email protected]>
*
* @package TYPO3
* @subpackage tx_directmail
*/
class Container
{
Expand Down Expand Up @@ -71,7 +69,7 @@ public function insert_dMailer_boundaries($content, $conf = [])
if ($content != '') {
// setting the default
$categoryList = '';
if (intval($this->cObj->data['module_sys_dmail_category']) >= 1) {
if ((int)($this->cObj->data['module_sys_dmail_category']) >= 1) {
// if content type "RECORDS" we have to strip off
// boundaries from indcluded records
if ($this->cObj->data['CType'] == 'shortcut') {
Expand Down Expand Up @@ -122,7 +120,7 @@ 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'] ? intval($conf['charWidth']) : 76), $conf['charWidth.']);
$charWidth = $GLOBALS['TSFE']->cObj->stdWrap(($conf['charWidth'] ? (int)($conf['charWidth']) : 76), $conf['charWidth.']);

return MailUtility::breakLinesForEmail($content, $linebreak, $charWidth);
}
Expand Down
63 changes: 25 additions & 38 deletions Classes/DirectMailUtility.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace DirectMailTeam\DirectMail;

/*
Expand All @@ -17,9 +18,9 @@
use DirectMailTeam\DirectMail\Repository\SysDmailRepository;
use DirectMailTeam\DirectMail\Utility\DmRegistryUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand All @@ -33,9 +34,6 @@
* @author Jan-Erik Revsbech <[email protected]>
* @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
* @author Ivan-Dharma Kartolo <[email protected]>
*
* @package TYPO3
* @subpackage tx_directmail
*/
class DirectMailUtility
{
Expand Down Expand Up @@ -64,7 +62,7 @@ public static function getLanguageService(): LanguageService
*
* @param string $url
*
* @return string & or ?
* @return string&or ?
*/
public static function getURLGlue(string $url): string
{
Expand All @@ -80,15 +78,14 @@ public static function getTypolinkURL(
string $parameter,
bool $forceAbsoluteUrl = true,
bool $linkAccessRestrictedPages = true
): string
{
): string {
$typolinkPageUrl = 't3://page?uid=';
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);

return $cObj->typolink_URL([
'parameter' => $typolinkPageUrl . $parameter,
'forceAbsoluteUrl' => $forceAbsoluteUrl,
'linkAccessRestrictedPages' => $linkAccessRestrictedPages
'linkAccessRestrictedPages' => $linkAccessRestrictedPages,
]);
}

Expand Down Expand Up @@ -120,7 +117,7 @@ public static function fetchUrlContentsForDirectMailRecord(array $row, array $pa
$htmlmail->setJumperURLPrefix(
$urls['baseUrl'] . $glue .
'mid=###SYS_MAIL_ID###' .
(intval($params['jumpurl_tracking_privacy']) ? '' : '&rid=###SYS_TABLE_NAME###_###USER_uid###') .
((int)($params['jumpurl_tracking_privacy']) ? '' : '&rid=###SYS_TABLE_NAME###_###USER_uid###') .
'&aC=###SYS_AUTHCODE###' .
'&jumpurl='
);
Expand All @@ -141,8 +138,7 @@ public static function fetchUrlContentsForDirectMailRecord(array $row, array $pa
$htmlmail->addPlain($mailContent);
if (!$mailContent || !$htmlmail->getPartPlainConfig('content')) {
$errorMsg[] = $lang->getLL('dmail_no_plain_content');
}
elseif (!strstr($htmlmail->getPartPlainConfig('content'), '<!--DMAILER_SECTION_BOUNDARY')) {
} elseif (!strstr($htmlmail->getPartPlainConfig('content'), '<!--DMAILER_SECTION_BOUNDARY')) {
$warningMsg[] = $lang->getLL('dmail_no_plain_boundaries');
}
}
Expand All @@ -162,21 +158,17 @@ public static function fetchUrlContentsForDirectMailRecord(array $row, array $pa
);
if ($res == 1) {
$htmlmail->setCharset($matches[1]);
}
elseif (isset($params['direct_mail_charset'])) {
} elseif (isset($params['direct_mail_charset'])) {
$htmlmail->setCharset($params['direct_mail_charset']);
}
else {
} else {
$htmlmail->setCharset('iso-8859-1');
}
}
if ($htmlmail->extractFramesInfo()) {
$errorMsg[] = $lang->getLL('dmail_frames_not allowed');
}
elseif (!$success || !$htmlmail->getPartHtmlConfig('content')) {
} elseif (!$success || !$htmlmail->getPartHtmlConfig('content')) {
$errorMsg[] = $lang->getLL('dmail_no_html_content');
}
elseif (!strstr($htmlmail->getPartHtmlConfig('content'), '<!--DMAILER_SECTION_BOUNDARY')) {
} elseif (!strstr($htmlmail->getPartHtmlConfig('content'), '<!--DMAILER_SECTION_BOUNDARY')) {
$warningMsg[] = $lang->getLL('dmail_no_html_boundaries');
}
}
Expand All @@ -191,7 +183,7 @@ public static function fetchUrlContentsForDirectMailRecord(array $row, array $pa
'charset' => $htmlmail->getCharset(),
'mailContent' => $mailContent,
'renderedSize' => strlen($mailContent),
'long_link_rdct_url' => $urls['baseUrl']
'long_link_rdct_url' => $urls['baseUrl'],
];

$done = GeneralUtility::makeInstance(SysDmailRepository::class)->updateSysDmailRecord((int)$row['uid'], $updateData);
Expand All @@ -202,26 +194,25 @@ public static function fetchUrlContentsForDirectMailRecord(array $row, array $pa
$output .= $flashMessageRendererResolver
->resolve()
->render([
self::createFlashMessage($warning, $lang->getLL('dmail_warning'), FlashMessage::WARNING, false)
self::createFlashMessage($warning, $lang->getLL('dmail_warning'), FlashMessage::WARNING, false),
]);
}
}
}
else {
} else {
$flashMessageRendererResolver = self::getFlashMessageRendererResolver();
foreach ($errorMsg as $error) {
$output .= $flashMessageRendererResolver
->resolve()
->render([
self::createFlashMessage($error, $lang->getLL('dmail_error'), FlashMessage::ERROR, false)
self::createFlashMessage($error, $lang->getLL('dmail_error'), FlashMessage::ERROR, false),
]);
}
}

if ($returnArray) {
return [
'errors' => $errorMsg,
'warnings' => $warningMsg
'warnings' => $warningMsg,
];
}

Expand All @@ -233,9 +224,9 @@ protected static function createFlashMessage(
string $messageHeader = '',
int $messageType = 0,
bool $storeInSession = false
): FlashMessage
{
return GeneralUtility::makeInstance(FlashMessage::class,
): FlashMessage {
return GeneralUtility::makeInstance(
FlashMessage::class,
$messageText,
$messageHeader,
$messageType,
Expand Down Expand Up @@ -267,7 +258,7 @@ protected static function addUserPass(string $url, array $params): string
}
if (($params['simulate_usergroup'] ?? false) && MathUtility::canBeInterpretedAsInteger($params['simulate_usergroup'])) {
$glue = self::getURLGlue($url);
$url = $url . $glue . 'dmail_fe_group=' . (int)$params['simulate_usergroup'] . '&access_token=' . GeneralUtility::makeInstance(DmRegistryUtility::class)->createAndGetAccessToken();
$url = $url . $glue . 'dmail_fe_group=' . (int)$params['simulate_usergroup'] . '&access_token=' . GeneralUtility::makeInstance(DmRegistryUtility::class)->createAndGetAccessToken();
}
return $url;
}
Expand All @@ -285,7 +276,7 @@ public static function getFullUrlsForDirectMailRecord(array $row): array
$result = [
'baseUrl' => self::getTypolinkURL((int)$row['page']),
'htmlUrl' => '',
'plainTextUrl' => ''
'plainTextUrl' => '',
];

// Finding the url to fetch content from
Expand All @@ -305,8 +296,7 @@ public static function getFullUrlsForDirectMailRecord(array $row): array
if ($result['plainTextUrl']) {
if (!($row['sendOptions'] & 1)) {
$result['plainTextUrl'] = '';
}
else {
} else {
$urlParts = @parse_url($result['plainTextUrl']);
if (!$urlParts['scheme']) {
$result['plainTextUrl'] = 'http://' . $result['plainTextUrl'];
Expand All @@ -318,8 +308,7 @@ public static function getFullUrlsForDirectMailRecord(array $row): array
if ($result['htmlUrl']) {
if (!($row['sendOptions'] & 2)) {
$result['htmlUrl'] = '';
}
else {
} else {
$urlParts = @parse_url($result['htmlUrl']);
if (!$urlParts['scheme']) {
$result['htmlUrl'] = 'http://' . $result['htmlUrl'];
Expand All @@ -340,8 +329,7 @@ public static function intInRangeWrapper(
int $min,
int $max = 2000000000,
int $zeroValue = 0
): int
{
): int {
return MathUtility::forceIntegerInRange($theInt, $min, $max, $zeroValue);
}

Expand Down Expand Up @@ -374,8 +362,7 @@ public static function substUrlsInPlainText($message, $urlmode = '76', $index_sc
if ($lengthLimit === false) {
// No processing
$messageSubstituted = $message;
}
else {
} else {
$messageSubstituted = preg_replace_callback(
'/(http|https):\\/\\/.+(?=[\\]\\.\\?]*([\\! \'"()<>]+|$))/iU',
function (array $matches) use ($lengthLimit, $index_script_url) {
Expand Down
Loading

0 comments on commit bffb576

Please sign in to comment.