Commit fcac8be9 authored by Georgi Mateev's avatar Georgi Mateev
Browse files

[BUGFIX] 1584 Removed unnecessary complex logic from the Newsletter and SendEmail

parent d707f363
......@@ -427,21 +427,21 @@ class NewsletterController extends ActionController {
$mailTemplateService->setTemplateName($parameters['selectedTemplate']);
$mailTemplateService->setExtensionKey($parameters['selectedExtension']);
$mailTemplateService->setOverwrittenFromName($parameter['fromName']);
$mailTemplateService->setOverwrittenFromMail($parameter['fromMail']);
$mailTemplateService->setFromName($parameter['fromName']);
$mailTemplateService->setFromAddress($parameter['fromMail']);
$mailTemplateService->setSubject($parameter['subject']);
$mailTemplateService->setOverwrittenReplyTo($parameter['replyTo']);
$mailTemplateService->setReplyToAddress($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->setOverwrittenToAddresses($parameters['emailAddress']);
$mailTemplateService->setToAddresses($parameters['emailAddress']);
$mailTemplateService->setOverwrittenEmailBody($parameter['content']);
$mailTemplateService->setSubject($template['subject']);
$mailTemplateService->setOverWrittenFromName($template['fromName']);
$mailTemplateService->setOverWrittenFromMail($template['fromMail']);
$mailTemplateService->setFromName($template['fromName']);
$mailTemplateService->setFromAddress($template['fromMail']);
$mailTemplateService->setMarkers([
'user' => [
'username' => 'username@example.com',
......@@ -480,8 +480,8 @@ class NewsletterController extends ActionController {
$mailTemplateService->setLanguage($key);
$mailTemplateService->setOverwrittenEmailBody($template['content']);
$mailTemplateService->setSubject($template['subject']);
$mailTemplateService->setOverwrittenBcc($template['bcc']);
$mailTemplateService->setOverwrittenCc($template['cc']);
$mailTemplateService->setBccAddresses($template['bcc']);
$mailTemplateService->setCcAddresses($template['cc']);
foreach ($recipients as $recipient) {
......
......@@ -123,36 +123,6 @@ 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
*/
......@@ -223,7 +193,7 @@ class MailTemplateService {
*/
private $subjectToSend;
/*
/**
* @var string
*/
private $defaultFromAddress;
......@@ -233,90 +203,6 @@ class MailTemplateService {
*/
private $defaultFromName;
/**
* @return string
*/
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;
}
/**
* @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;
}
/**
* MailTemplateService constructor.
*
......@@ -346,12 +232,14 @@ class MailTemplateService {
if (\filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) {
$this->fromAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
$this->defaultFromAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
} else if (!\filter_var($tsSettings['mail']['default']['from'], FILTER_VALIDATE_EMAIL)) {
$this->fromAddress = 'noreply@example.org';
$this->defaultFromAddress = 'noreply@example.org';
} else {
$this->fromAddress = $tsSettings['mail']['default']['from'];
$this->defaultFromAddress = $tsSettings['mail']['default']['from'];
if (!\filter_var($tsSettings['mail']['default']['from'], FILTER_VALIDATE_EMAIL)) {
$this->fromAddress = 'noreply@example.org';
$this->defaultFromAddress = 'noreply@example.org';
} else {
$this->fromAddress = $tsSettings['mail']['default']['from'];
$this->defaultFromAddress = $tsSettings['mail']['default']['from'];
}
}
if ($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']) {
......@@ -783,6 +671,7 @@ class MailTemplateService {
* @return mixed
*/
protected function parseMarkers($text, $emailView) {
$text = (string) $text;
if (strpos($text, '{') !== FALSE) {
$emailView->setTemplateSource($text);
return $emailView->render();
......@@ -939,8 +828,10 @@ class MailTemplateService {
* @param boolean $isNewsletter
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
protected function extractValuesForMail($template, RegisterService $registerService, $defaultTemplateContent,
$siteRootId, $isNewsletter): void {
protected function extractValuesForMail(
$template, RegisterService $registerService, $defaultTemplateContent,
$siteRootId, $isNewsletter
): void {
/** @var StandaloneView $emailView */
$emailView = $this->objectManager->get(StandaloneView::class);
$emailView->assignMultiple($this->markers);
......@@ -980,88 +871,66 @@ class MailTemplateService {
}
$this->setSubjectToSend($subject);
//TODO: is this object even in use somewhere?
$this->mailMessage->setSubject($subject);
$fromMail = '';
// Load the values from the template if they are set
if (!$isNewsletter && $template !== NULL) {
// if it's a non-newsletter email with a template:
// get the values explicitly from the template and parse the markers
$fromMail = $this->parseMarkers($template->getFromMail(), $emailView);
} elseif ($this->fromAddress === $this->defaultFromAddress) {
// in other cases (newsletter or no template) - check for overwritten values
$fromMail = $this->parseMarkers(
empty($this->overwrittenFromMail) && $template ? $template->getFromMail() : $this->overwrittenFromMail,
$emailView
);
}
if ($fromMail) { // we don't want to override the default in that case
$this->setFromAddress($fromMail);
$this->loadTemplateValues($template);
}
$fromName = '';
if (!$isNewsletter && $template !== NULL) {
$fromName = $this->parseMarkers($template->getFromName(), $emailView);
} else if ($this->fromName === $this->defaultFromName) {
$fromName = $this->parseMarkers(
(empty($this->overwrittenFromName) && $template ? $template->getFromName(
) : $this->overwrittenFromName),
$emailView
// Parse the markers
if ($this->fromName) {
$this->setFromName(
$this->parseMarkers(
$this->fromName,
$emailView
)
);
}
if ($fromName) { // we don't want to override the default if this value is empty here
$this->setFromName($fromName);
if ($this->fromAddress) {
$this->setFromAddress(
$this->parseMarkers(
$this->fromAddress,
$emailView
)
);
}
if (!$isNewsletter && $template !== NULL) {
$replyTo = $this->parseMarkers($template->getReplyTo(), $emailView);
$this->setReplyToAddress($replyTo);
} else if ($this->replyToAddress === '') {
$replyTo = $this->parseMarkers(
(empty($this->overwrittenReplyTo) && $template ? $template->getReplyTo(
) : $this->overwrittenReplyTo),
$emailView
if ($this->replyToAddress) {
$this->setReplyToAddress(
$this->parseMarkers(
$this->replyToAddress,
$emailView
)
);
$this->setReplyToAddress($replyTo);
}
if (!$isNewsletter && $template !== NULL) {
$cc = $this->parseMarkers($template->getCc(), $emailView);
if ($cc) {
$this->setCcAddresses($cc);
}
} else if (empty($this->ccAddresses)) {
$cc = $this->parseMarkers(
(empty($this->overwrittenCc) && $template ? $template->getCc() : $this->overwrittenCc),
$emailView
if ($this->bccAddresses) {
$this->setCcAddresses(
$this->parseMarkers(
$this->ccAddresses,
$emailView
)
);
$this->setCcAddresses($cc);
}
if (!$isNewsletter && $template !== NULL) {
$bcc = $this->parseMarkers($template->getBcc(), $emailView);
if ($bcc) {
$this->setBccAddresses($bcc);
}
} else if (empty($this->bccAddresses)) {
$bcc = $this->parseMarkers(
(empty($this->overwrittenBcc) && $template ? $template->getBcc() : $this->overwrittenBcc),
$emailView
if ($this->bccAddresses) {
$this->setBccAddresses(
$this->parseMarkers(
$this->bccAddresses,
$emailView
)
);
$this->setBccAddresses($bcc);
}
if (!$isNewsletter && $template !== NULL) {
$toAddress = $this->parseMarkers($template->getToAddress(), $emailView);
if ($toAddress) {
$this->setToAddresses($toAddress);
}
} else if ($this->toAddresses === '') {
$toAddress = $this->parseMarkers(
(empty($this->overwrittenToAddresses) && $template ? $template->getToAddress() : $this->overwrittenToAddresses),
$emailView
if ($this->toAddresses) {
$this->setToAddresses(
$this->parseMarkers(
$this->toAddresses,
$emailView
)
);
$this->setToAddresses($toAddress);
}
// reset template source back to default
......@@ -1433,4 +1302,26 @@ class MailTemplateService {
return $allMarker;
}
/**
* use all values from the given template
*
* @param Template $template
*/
private function loadTemplateValues($template): void {
$fromName = \trim($template->getFromName());
if ($fromName === '') {
$fromName = $this->fromName;
}
if ($fromName === '' && $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']) {
$fromName = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
}
$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);
}
}
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