[FEATURE] Add contentObject functionality to form MailPostProcessor 90/42290/14
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Tue, 6 Oct 2015 10:41:51 +0000 (12:41 +0200)
committerFrans Saris <franssaris@gmail.com>
Tue, 6 Oct 2015 18:03:48 +0000 (20:03 +0200)
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>
typo3/sysext/core/Documentation/Changelog/master/Feature-68771-AddContentObjectFunctionalityToFormMailPostProcessorAndIntroduceReplyToEmail.rst [new file with mode: 0644]
typo3/sysext/form/Classes/PostProcess/MailPostProcessor.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-68771-AddContentObjectFunctionalityToFormMailPostProcessorAndIntroduceReplyToEmail.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-68771-AddContentObjectFunctionalityToFormMailPostProcessorAndIntroduceReplyToEmail.rst
new file mode 100644 (file)
index 0000000..19ddded
--- /dev/null
@@ -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: ||
+       }
\ No newline at end of file
index 4caa4f5..c704b4a 100644 (file)
@@ -120,6 +120,7 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
                $this->setFrom();
                $this->setTo();
                $this->setCc();
+               $this->setReplyTo();
                $this->setPriority();
                $this->setOrganization();
                $this->setHtmlContent();
@@ -138,7 +139,10 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         */
        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 {
@@ -157,8 +161,11 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         * @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 {
@@ -167,8 +174,11 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
                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 {
@@ -221,7 +231,11 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         * @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);
                }
@@ -235,13 +249,39 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         * @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
         *
         * When not in settings, the value will be 3. If the priority is configured,
@@ -251,8 +291,14 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         */
        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);
        }
@@ -265,8 +311,13 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         * @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);
                }