Commit 030ca7a8 authored by Georgi Mateev's avatar Georgi Mateev
Browse files

[BUGFIX] 1584 Adding placeholders to all sg_mail fields

parent 8d891843
......@@ -332,7 +332,7 @@ class MailController extends ActionController {
if (\count($ccAddresses) > 0) {
foreach ($ccAddresses as $ccAddress) {
if (!filter_var($ccAddress, FILTER_VALIDATE_EMAIL) && trim($ccAddress) !== '') {
if (!preg_match('/{.*}/', $ccAddress) && !filter_var($ccAddress, FILTER_VALIDATE_EMAIL) && trim($ccAddress) !== '') {
$message = LocalizationUtility::translate('backend.error_cc', 'sg_mail');
$this->addFlashMessage($message, '', FlashMessage::WARNING);
......@@ -344,7 +344,7 @@ class MailController extends ActionController {
$bccAddresses = GeneralUtility::trimExplode(',', $parameter['bcc']);
if (\count($bccAddresses) > 0) {
foreach ($bccAddresses as $bccAddress) {
if (!filter_var($bccAddress, FILTER_VALIDATE_EMAIL) && trim($bccAddress) !== '') {
if (!preg_match('/{.*}/', $bccAddress) && !filter_var($bccAddress, FILTER_VALIDATE_EMAIL) && trim($bccAddress) !== '') {
$message = LocalizationUtility::translate('backend.error_bcc', 'sg_mail');
$this->addFlashMessage($message, '', FlashMessage::WARNING);
......
......@@ -391,7 +391,7 @@ class NewsletterController extends ActionController {
if (\count($ccAddresses) > 0) {
foreach ($ccAddresses as $ccAddress) {
if (!filter_var($ccAddress, FILTER_VALIDATE_EMAIL) && trim($ccAddress) !== '') {
if (!preg_match('/{.*}/', $ccAddress) && !filter_var($ccAddress, FILTER_VALIDATE_EMAIL) && trim($ccAddress) !== '') {
$message = LocalizationUtility::translate('backend.error_cc', 'sg_mail');
$this->addFlashMessage($message, '', FlashMessage::WARNING);
......@@ -403,7 +403,7 @@ class NewsletterController extends ActionController {
$bccAddresses = GeneralUtility::trimExplode(',', $parameter['bcc']);
if (\count($bccAddresses) > 0) {
foreach ($bccAddresses as $bccAddress) {
if (!filter_var($bccAddress, FILTER_VALIDATE_EMAIL) && trim($bccAddress) !== '') {
if (!preg_match('/{.*}/', $bccAddress) && !filter_var($bccAddress, FILTER_VALIDATE_EMAIL) && trim($bccAddress) !== '') {
$message = LocalizationUtility::translate('backend.error_bcc', 'sg_mail');
$this->addFlashMessage($message, '', FlashMessage::WARNING);
......@@ -420,20 +420,23 @@ class NewsletterController extends ActionController {
);
$mailIsSend = FALSE;
$mailTemplateService->setSubject($parameter['subject']);
$mailTemplateService->setReplyToAddress($parameter['replyTo']);
$mailTemplateService->setTemplateName($parameters['selectedTemplate']);
$mailTemplateService->setExtensionKey($parameters['selectedExtension']);
$mailTemplateService->setFromAddress($parameter['fromMail']);
$mailTemplateService->setOverwrittenFromName($parameter['fromName']);
$mailTemplateService->setOverwrittenFromMail($parameter['fromMail']);
$mailTemplateService->setSubject($parameter['subject']);
$mailTemplateService->setOverwrittenReplyTo($parameter['replyTo']);
if (!$this->request->getArgument('sendRealEmails')) {
// Send test emails
$message = LocalizationUtility::translate('backend.success_mail', 'sg_mail');
foreach ((array) $parameters['templates'] as $key => $template) {
$mailTemplateService->setLanguage($key);
$mailTemplateService->setToAddresses($parameters['emailAddress']);
$mailTemplateService->setOverwrittenToAddresses($parameters['emailAddress']);
$mailTemplateService->setOverwrittenEmailBody($parameter['content']);
$mailTemplateService->setSubject($template['subject']);
$mailTemplateService->setOverWrittenFromName($template['fromName']);
$mailTemplateService->setOverWrittenFromMail($template['fromMail']);
$mailTemplateService->setMarkers([
'user' => [
'username' => 'username@example.com',
......@@ -470,9 +473,10 @@ class NewsletterController extends ActionController {
foreach ((array) $parameters['templates'] as $key => $template) {
$mailTemplateService->setLanguage($key);
$mailTemplateService->setOverwrittenEmailBody($parameter['content']);
$mailTemplateService->setBccAddresses($parameter['bcc']);
$mailTemplateService->setCcAddresses($parameter['cc']);
$mailTemplateService->setOverwrittenEmailBody($template['content']);
$mailTemplateService->setSubject($template['subject']);
$mailTemplateService->setOverwrittenBcc($template['bcc']);
$mailTemplateService->setOverwrittenCc($template['cc']);
foreach ($recipients as $recipient) {
......
......@@ -113,6 +113,36 @@ class MailTemplateService {
*/
private $overwrittenEmailBody = '';
/**
* @var string $overwrittenBcc
*/
private $overwrittenBcc;
/**
* @var string $overwrittenFromName
*/
private $overwrittenFromName;
/**
* @var string $overwrittenFromMail
*/
private $overwrittenFromMail;
/**
* @var string $overwrittenReplyTo
*/
private $overwrittenReplyTo;
/**
* @var string $overwrittenToAddresses
*/
private $overwrittenToAddresses;
/**
* @var string $overwrittenCc
*/
private $overwrittenCc;
/**
* @var string $extensionKey
*/
......@@ -602,6 +632,22 @@ class MailTemplateService {
$this->setMarkers($previewMarker);
}
/**
* Parses markers in an email View.
* !!! CHANGES THE SOURCE PATH AND IT SHOULD BE RESET BACK TO THE ORIGINAL!!!
*
* @param string $text
* @param StandaloneView $emailView
* @return mixed
*/
protected function parseMarkers($text, $emailView) {
if (strpos($text, '{') !== FALSE) {
$emailView->setTemplateSource($text);
return $emailView->render();
}
return $text;
}
/**
* Send the Email
*
......@@ -668,11 +714,6 @@ class MailTemplateService {
);
}
// if there is a template, prefer those values
if ($template) {
$this->loadTemplateValues($template);
}
// get default template content from register array
$registerService = GeneralUtility::makeInstance(RegisterService::class);
$defaultTemplateContent =
......@@ -725,25 +766,13 @@ class MailTemplateService {
// parse markers
if ($template !== NULL) {
$emailView->setTemplateSource(
\trim(empty($overwrittenSubject) ? $template->getSubject() : $overwrittenSubject)
$subject = $this->parseMarkers(
trim(empty($overwrittenSubject) ? $template->getSubject() : $overwrittenSubject),
$emailView
);
$subject = $emailView->render();
$emailView->setTemplateSource(
$this->getTemplateSource(
$template->getFromMail(),
$template->getLayout(), $siteRootId
)
);
$fromMail = $emailView->render();
$emailView->setTemplateSource(
$this->getTemplateSource(
empty($overwrittenEmailBody) ? $template->getContent() : $overwrittenEmailBody,
$template->getLayout(), $siteRootId
)
);
$layoutId = $template->getLayout();
$templateContent = $template->getContent();
} else {
$subject = $registerService->getRegisterArray()[$this->extensionKey][$this->templateName]['subject'];
if (\is_array($subject)) {
......@@ -752,28 +781,90 @@ class MailTemplateService {
[$this->extensionKey][$this->templateName]['subject'][$this->language]
);
}
$subject = $this->parseMarkers(
(empty($overwrittenSubject) ? $subject : $overwrittenSubject),
$emailView
);
$layoutId = 0;
$templateContent = $defaultTemplateContent;
}
$emailView->setTemplateSource(empty($overwrittenSubject) ? $subject : $overwrittenSubject);
$subject = $emailView->render();
$this->mailMessage->setSubject($subject);
$emailView->setTemplateSource(
if ($this->fromAddress === '') {
$fromMail = $this->parseMarkers(
$this->getTemplateSource(
$template->getFromMail(),
0, $siteRootId
)
(empty($this->overwrittenFromMail) ? $template->getFromMail() : $this->overwrittenFromMail),
$layoutId, $siteRootId
),
$emailView
);
$fromMail = $emailView->render();
$this->setFromAddress($fromMail);
}
$emailView->setTemplateSource(
if ($this->fromName === '') {
$fromName = $this->parseMarkers(
$this->getTemplateSource(
empty($overwrittenEmailBody) ? $defaultTemplateContent : $overwrittenEmailBody,
0, $siteRootId
)
(empty($this->overwrittenFromName) ? $template->getFromName() : $this->overwrittenFromName),
$layoutId, $siteRootId
),
$emailView
);
$this->setFromName($fromName);
}
$this->mailMessage->setSubject($subject);
$this->setFromAddress($fromMail);
if ($this->replyToAddress === '') {
$replyTo = $this->parseMarkers(
$this->getTemplateSource(
(empty($this->overwrittenReplyTo) ? $template->getReplyTo() : $this->overwrittenReplyTo),
$layoutId, $siteRootId
),
$emailView
);
$this->setReplyToAddress($replyTo);
}
if (empty($this->ccAddresses)) {
$cc = $this->parseMarkers(
$this->getTemplateSource(
(empty($this->overwrittenCc) ? $template->getCc() : $this->overwrittenCc),
$layoutId, $siteRootId
),
$emailView
);
$this->setCcAddresses($cc);
}
if (empty($this->bccAddresses)) {
$bcc = $this->parseMarkers(
$this->getTemplateSource(
(empty($this->overwrittenBcc) ? $template->getBcc() : $this->overwrittenBcc),
$layoutId, $siteRootId
),
$emailView
);
$this->setBccAddresses($bcc);
}
if ($this->toAddresses === '') {
$toAddress = $this->parseMarkers(
$this->getTemplateSource(
(empty($this->overwrittenToAddresses) ? $template->getToAddress() : $this->overwrittenToAddresses),
$layoutId, $siteRootId
),
$emailView
);
$this->setToAddresses($toAddress);
}
// reset template source back to default
$emailView->setTemplateSource(
$this->getTemplateSource(
empty($overwrittenEmailBody) ? $templateContent : $overwrittenEmailBody,
$layoutId, $siteRootId
)
);
// insert <br> tags, but replace every instance of three or more successive breaks with just two.
$emailBody = $emailView->render();
......@@ -991,25 +1082,87 @@ class MailTemplateService {
}
/**
* use all values from the given template
*
* @param Template $template
* @return string
*/
private function loadTemplateValues($template) {
$fromName = \trim($template->getFromName());
if ($fromName === '') {
$fromName = $this->fromName;
}
if ($fromName === '' && $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']) {
$fromName = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
}
public function getOverwrittenBcc(): string {
return $this->overwrittenBcc;
}
/**
* @param string $overwrittenBcc
*/
public function setOverwrittenBcc(string $overwrittenBcc): void {
$this->overwrittenBcc = $overwrittenBcc;
}
/**
* @return string
*/
public function getOverwrittenCc(): string {
return $this->overwrittenCc;
}
/**
* @param string $overwrittenCc
*/
public function setOverwrittenCc(string $overwrittenCc): void {
$this->overwrittenCc = $overwrittenCc;
}
$fromMail = $this->getValidFromMail(\trim($template->getFromMail()));
$this->setFromAddress($fromMail, $fromName);
$this->setCcAddresses($template->getCc());
$this->setBccAddresses($template->getBcc());
$this->setReplyToAddress($template->getReplyTo());
$this->setFromName($fromName);
/**
* @return string
*/
public function getOverwrittenFromName(): string {
return $this->overwrittenFromName;
}
/**
* @param string $overwrittenFromName
*/
public function setOverwrittenFromName(string $overwrittenFromName): void {
$this->overwrittenFromName = $overwrittenFromName;
}
/**
* @return string
*/
public function getOverwrittenFromMail(): string {
return $this->overwrittenFromMail;
}
/**
* @param string $overwrittenFromMail
*/
public function setOverwrittenFromMail(string $overwrittenFromMail): void {
$this->overwrittenFromMail = $overwrittenFromMail;
}
/**
* @return string
*/
public function getOverwrittenReplyTo(): string {
return $this->overwrittenReplyTo;
}
/**
* @param string $overwrittenReplyTo
*/
public function setOverwrittenReplyTo(string $overwrittenReplyTo): void {
$this->overwrittenReplyTo = $overwrittenReplyTo;
}
/**
* @return string
*/
public function getOverwrittenToAddresses(): string {
return $this->overwrittenToAddresses;
}
/**
* @param string $overwrittenToAddresses
*/
public function setOverwrittenToAddresses(string $overwrittenToAddresses): void {
$this->overwrittenToAddresses = $overwrittenToAddresses;
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment