Skip to content

Commit

Permalink
[FEATURE] Add contentObject functionality to form MailPostProcessor
Browse files Browse the repository at this point in the history
and introduce replyToEmail

If the form configuration is defined by TypoScript the following
items for the MailPostProcessor in ext:form have now
contentObject functionality:

* subject
* senderEmail
* senderName
* recipientEmail
* ccEmail
* replyToEmail (newly introduced, replyToEmailField as fallback)
* priority
* organization

This is disabled in the form wizard for security concerns.

Resolves: #68771
Releases: master
Change-Id: I13913b806b86bcfbe35d760b50e193a066cbcc4c
Reviewed-on: http://review.typo3.org/42290
Reviewed-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Tested-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Tested-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
  • Loading branch information
waldhacker1 authored and fsaris committed Oct 6, 2015
1 parent b3908e9 commit 0f5ded1
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 11 deletions.
@@ -0,0 +1,41 @@
======================================================================================================
Feature: #68771 - Add contentObject functionality to form MailPostProcessor and introduce replyToEmail
======================================================================================================

Description
===========

If the form configuration is defined by TypoScript the following items for the MailPostProcessor
in ext:form have now contentObject functionality:
- subject
- senderEmail
- senderName
- recipientEmail
- ccEmail
- replyToEmail (newly introduced, replyToEmailField as fallback)
- priority
- organization

This feature is not available when building the form with the help of
the wizard. The functionality can only be used be setting up the form
via TypoScript.

Usage
=====

In the mail postProcessor configuration one could do something like this
(depending on the names of the form elements):

.. code-block:: typoscript
replyToEmail = TEXT
replyToEmail {
data = GP:tx_form_form|tx_form|e-mail
htmlSpecialChars = 1
}
subject = TEXT
subject {
data = GP:tx_form_form|tx_form|subject
htmlSpecialChars = 1
noTrimWrap = |Mail from Form: ||
}
73 changes: 62 additions & 11 deletions typo3/sysext/form/Classes/PostProcess/MailPostProcessor.php
Expand Up @@ -120,6 +120,7 @@ public function process() {
$this->setFrom();
$this->setTo();
$this->setCc();
$this->setReplyTo();
$this->setPriority();
$this->setOrganization();
$this->setHtmlContent();
Expand All @@ -138,7 +139,10 @@ public function process() {
*/
protected function setSubject() {
if (isset($this->typoScript['subject'])) {
$subject = $this->typoScript['subject'];
$subject = $this->formUtility->renderItem(
$this->typoScript['subject.'],
$this->typoScript['subject']
);
} elseif ($this->getTypoScriptValueFromIncomingData('subjectField') !== NULL) {
$subject = $this->getTypoScriptValueFromIncomingData('subjectField');
} else {
Expand All @@ -157,8 +161,11 @@ protected function setSubject() {
* @return void
*/
protected function setFrom() {
if ($this->typoScript['senderEmail']) {
$fromEmail = $this->typoScript['senderEmail'];
if (isset($this->typoScript['senderEmail'])) {
$fromEmail = $this->formUtility->renderItem(
$this->typoScript['senderEmail.'],
$this->typoScript['senderEmail']
);
} elseif ($this->getTypoScriptValueFromIncomingData('senderEmailField') !== NULL) {
$fromEmail = $this->getTypoScriptValueFromIncomingData('senderEmailField');
} else {
Expand All @@ -167,8 +174,11 @@ protected function setFrom() {
if (!GeneralUtility::validEmail($fromEmail)) {
$fromEmail = MailUtility::getSystemFromAddress();
}
if ($this->typoScript['senderName']) {
$fromName = $this->typoScript['senderName'];
if (isset($this->typoScript['senderName'])) {
$fromName = $this->formUtility->renderItem(
$this->typoScript['senderName.'],
$this->typoScript['senderName']
);
} elseif ($this->getTypoScriptValueFromIncomingData('senderNameField') !== NULL) {
$fromName = $this->getTypoScriptValueFromIncomingData('senderNameField');
} else {
Expand Down Expand Up @@ -221,7 +231,11 @@ protected function filterValidEmails($emails) {
* @return void
*/
protected function setTo() {
$validEmails = $this->filterValidEmails($this->typoScript['recipientEmail']);
$emails = $this->formUtility->renderItem(
$this->typoScript['recipientEmail.'],
$this->typoScript['recipientEmail']
);
$validEmails = $this->filterValidEmails($emails);
if (!empty($validEmails)) {
$this->mailMessage->setTo($validEmails);
}
Expand All @@ -235,12 +249,38 @@ protected function setTo() {
* @return void
*/
protected function setCc() {
$validEmails = $this->filterValidEmails($this->typoScript['ccEmail']);
$emails = $this->formUtility->renderItem(
$this->typoScript['ccEmail.'],
$this->typoScript['ccEmail']
);
$validEmails = $this->filterValidEmails($emails);
if (!empty($validEmails)) {
$this->mailMessage->setCc($validEmails);
}
}

/**
* Adds the reply to header of the mail message when configured
*
* Checks the address if it is a valid email address
*
* @return void
*/
protected function setReplyTo() {
if (isset($this->typoScript['replyToEmail'])) {
$emails = $this->formUtility->renderItem(
$this->typoScript['replyToEmail.'],
$this->typoScript['replyToEmail']
);
} elseif ($this->getTypoScriptValueFromIncomingData('replyToEmailField') !== NULL) {
$emails = $this->getTypoScriptValueFromIncomingData('replyToEmailField');
}
$validEmails = $this->filterValidEmails($emails);
if (!empty($validEmails)) {
$this->mailMessage->setReplyTo($validEmails);
}
}

/**
* Set the priority of the mail message
*
Expand All @@ -251,8 +291,14 @@ protected function setCc() {
*/
protected function setPriority() {
$priority = 3;
if ($this->typoScript['priority']) {
$priority = MathUtility::forceIntegerInRange($this->typoScript['priority'], 1, 5);
if (isset($this->typoScript['priority'])) {
$priorityFromTs = $this->formUtility->renderItem(
$this->typoScript['priority.'],
$this->typoScript['priority']
);
}
if (!empty($priorityFromTs)) {
$priority = MathUtility::forceIntegerInRange($priorityFromTs, 1, 5);
}
$this->mailMessage->setPriority($priority);
}
Expand All @@ -265,8 +311,13 @@ protected function setPriority() {
* @return void
*/
protected function setOrganization() {
if ($this->typoScript['organization']) {
$organization = $this->typoScript['organization'];
if (isset($this->typoScript['organization'])) {
$organization = $this->formUtility->renderItem(
$this->typoScript['organization.'],
$this->typoScript['organization']
);
}
if (!empty($organization)) {
$organization = $this->sanitizeHeaderString($organization);
$this->mailMessage->getHeaders()->addTextHeader('Organization', $organization);
}
Expand Down

0 comments on commit 0f5ded1

Please sign in to comment.