Commit 6a5fd2d6 authored by Elias Villiger's avatar Elias Villiger
Browse files

Merge branch '6314-sendmail-html-mode' into 'master'

Feature #6314 - HTML Mode & sendMailSubjectHtmlEntity for Forms. Also fixed some…

See merge request !60
parents d42b5711 ab5bfc34
Pipeline #870 passed with stage
in 1 minute and 45 seconds
......@@ -3782,8 +3782,9 @@ Type: sendmail
* *sendMailXId* = `<string>` - Will be copied to the mailLog record. Helps to setup specific logfile queries.
* *sendMailXId2* = `<string>` - Will be copied to the mailLog record. Helps to setup specific logfile queries.
* *sendMailXId3* = `<string>` - Will be copied to the mailLog record. Helps to setup specific logfile queries.
* *sendMailSubjectHtmlEntity* = `<string>` - **encode|decode|none** - the mail subject will htmlspecialchar() encoded / decoded (default) or none (untouched).
* *sendMailBodyHtmlEntity*= `<string>` - **encode|decode|none** - the mail body will htmlspecialchar() encoded, decoded (default) or none (untouched).
* *sendMailMode* = `<string>` - **html** - if set, the e-mail body will be rendered as html.
* *sendMailSubjectHtmlEntity* = `<string>` - **encode|decode|none** - the mail subject will be htmlspecialchar() encoded / decoded (default) or none (untouched).
* *sendMailBodyHtmlEntity*= `<string>` - **encode|decode|none** - the mail body will be htmlspecialchar() encoded, decoded (default) or none (untouched).
* To use values of the submitted form, use the STORE_FORM. E.g. `{{name:F:allbut}}`
* To use the `id` of a new created or already existing primary record, use the STORE_RECORD. E.g. `{{id:R}}`.
......@@ -5706,7 +5707,7 @@ Format: ::
t:<TO:email[,email]>|f:<FROM:email>|s:<subject>|b:<body>
[|c:<CC:email[,email]]>[|B:<BCC:email[,email]]>[|r:<REPLY-TO:email>]
[|A:<flag autosubmit: on/off>][|g:<grId>][|x:<xId>][|y:<xId2>][|z:<xId3>][|h:<mail header>]
[|e:<subject encode: encode/decode/none>][E:<body encode: encode/decode/none>][|M:html]
[|e:<subject encode: encode/decode/none>][E:<body encode: encode/decode/none>][|mode:html]
[|C][d:<filename of the attachment>][|F:<file to attach>][|u:<url>][|p:<T3 uri>]
The following parameters can also be written as complete words for ease of use: ::
......@@ -5714,7 +5715,7 @@ The following parameters can also be written as complete words for ease of use:
to:<email[,email]>|from:<email>|subject:<subject>|body:<body>
[|cc:<email[,email]]>[|bcc:<email[,email]]>[|reply-to:<email>]
[|autosubmit:<on/off>][|grid:<grid>][|xid:<xId>][|xid2:<xId2>][|xid3:<xId3>][|header:<mail header>]
[|M:html]
[|mode:html]
Send emails. Every mail will be logged in the table `mailLog`. Attachments are supported.
......
......@@ -203,7 +203,8 @@ class AutoCron {
private function mailEntryFill(array $mailEntry) {
foreach ([FE_SENDMAIL_TO, FE_SENDMAIL_CC, FE_SENDMAIL_BCC, FE_SENDMAIL_FROM, FE_SENDMAIL_SUBJECT,
FE_SENDMAIL_REPLY_TO, FE_SENDMAIL_FLAG_AUTO_SUBMIT, FE_SENDMAIL_GR_ID, FE_SENDMAIL_X_ID,
FE_SENDMAIL_X_ID2, FE_SENDMAIL_X_ID3] as $key) {
FE_SENDMAIL_X_ID2, FE_SENDMAIL_X_ID3, FE_SENDMAIL_BODY_MODE,
FE_SENDMAIL_BODY_HTML_ENTITY, FE_SENDMAIL_SUBJECT_HTML_ENTITY] as $key) {
if (!isset($mailEntry[$key])) {
$mailEntry[$key] = '';
}
......@@ -257,6 +258,9 @@ class AutoCron {
$mail[SENDMAIL_TOKEN_RECEIVER_BCC] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_BCC]);
$mail[SENDMAIL_TOKEN_X_ID2] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_X_ID2]);
$mail[SENDMAIL_TOKEN_X_ID3] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_X_ID3]);
$mail[SENDMAIL_TOKEN_BODY_MODE] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_BODY_MODE]);
$mail[SENDMAIL_TOKEN_BODY_HTML_ENTITY] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_BODY_HTML_ENTITY]);
$mail[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_SUBJECT_HTML_ENTITY]);
$mail[SENDMAIL_TOKEN_SRC] = "AutoCron: Cron.id=" . $job[COLUMN_ID];
......
......@@ -995,9 +995,10 @@ const FE_SENDMAIL_GR_ID = 'sendMailGrId'; // gr_id: used to classify mail log en
const FE_SENDMAIL_X_ID = 'sendMailXId'; // x_id: used to classify mail log entries ind table mailLog
const FE_SENDMAIL_X_ID2 = 'sendMailXId2'; // x_id: used to classify mail log entries ind table mailLog
const FE_SENDMAIL_X_ID3 = 'sendMailXId3'; // x_id: used to classify mail log entries ind table mailLog
const FE_SENDMAIL_SUBJECT_HTML_ENTITY = 'sendMailSubjectHtmlEntity'; // encode|decode >> DECODE, ENCODE
const FE_SENDMAIL_BODY_HTML_ENTITY = 'sendMailBodyHtmlEntity'; // encode | decode >> DECODE, ENCODE
const FE_SENDMAIL_ATTACHMENT = 'sendMailAttachment'; // x_id: used to classify mail log entries in table mailLog
const FE_SENDMAIL_SUBJECT_HTML_ENTITY = 'sendMailSubjectHtmlEntity'; // encode|decode|none >> DECODE, ENCODE, NONE
const FE_SENDMAIL_BODY_HTML_ENTITY = 'sendMailBodyHtmlEntity'; // encode|decode|none >> DECODE, ENCODE, NONE
const FE_SENDMAIL_ATTACHMENT = 'sendMailAttachment';
const FE_SENDMAIL_BODY_MODE = 'sendMailMode'; // html >> render body as html
const FE_AUTOFOCUS = 'autofocus'; // value: <none>|0|1 , <none>==1, this element becomes the focus during form load.
const FE_RETYPE = 'retype'; // value: <none>|0|1 , <none>==1, this element becomes the focus during form load.
const FE_RETYPE_LABEL = 'retypeLabel'; // value: label text for retype FormElement
......@@ -1260,7 +1261,7 @@ const SENDMAIL_TOKEN_ATTACHMENT_FILE = 'F';
const SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED = 'a'; // since 5.12.17
const SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY = 'e';
const SENDMAIL_TOKEN_BODY_HTML_ENTITY = 'E';
const SENDMAIL_TOKEN_BODY_MODE = 'M';
const SENDMAIL_TOKEN_BODY_MODE = 'mode';
const SENDMAIL_TOKEN_BODY_MODE_LONG = 'mode';
const SENDMAIL_TOKEN_BODY_MODE_HTML = 'html';
......
......@@ -278,6 +278,9 @@ class FormAction {
$args[] = SENDMAIL_TOKEN_SRC . PARAM_TOKEN_DELIMITER . "FormId: " . $feSpecAction[FE_FORM_ID] . ", FormElementId: " . $feSpecAction['id'];
$args[] = SENDMAIL_TOKEN_X_ID2 . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_X_ID2]);
$args[] = SENDMAIL_TOKEN_X_ID3 . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_X_ID3]);
$args[] = SENDMAIL_TOKEN_BODY_MODE . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_BODY_MODE]);
$args[] = SENDMAIL_TOKEN_BODY_HTML_ENTITY . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_BODY_HTML_ENTITY]);
$args[] = SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_SUBJECT_HTML_ENTITY]);
$args[] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_ATTACHMENT]);
// Mail: send
......@@ -441,28 +444,6 @@ class FormAction {
return false;
}
/**
* Set all necessary keys - subsequent 'isset()' are not necessary anymore.
*
* @param array $fe
*
* @return array
*/
private function initActionFormElement(array $fe) {
$list = [FE_TYPE, FE_SLAVE_ID, FE_SQL_VALIDATE, FE_SQL_BEFORE, FE_SQL_INSERT, FE_SQL_UPDATE, FE_SQL_DELETE,
FE_SQL_AFTER, FE_EXPECT_RECORDS, FE_REQUIRED_LIST, FE_MESSAGE_FAIL, FE_SENDMAIL_TO, FE_SENDMAIL_CC,
FE_SENDMAIL_BCC, FE_SENDMAIL_FROM, FE_SENDMAIL_SUBJECT, FE_SENDMAIL_REPLY_TO, FE_SENDMAIL_FLAG_AUTO_SUBMIT,
FE_SENDMAIL_GR_ID, FE_SENDMAIL_X_ID];
foreach ($list as $key) {
Support::setIfNotSet($fe, $key);
}
return $fe;
}
/**
* Will be called for each master record (clipboard).
* Process all FE.type='paste' for the given master record in clipboard.
......
......@@ -269,7 +269,8 @@ class HelperFormElement {
$list = [FE_TYPE, FE_SLAVE_ID, FE_SQL_VALIDATE, FE_SQL_BEFORE, FE_SQL_INSERT, FE_SQL_UPDATE, FE_SQL_DELETE,
FE_SQL_AFTER, FE_EXPECT_RECORDS, FE_REQUIRED_LIST, FE_MESSAGE_FAIL, FE_SENDMAIL_TO, FE_SENDMAIL_CC,
FE_SENDMAIL_BCC, FE_SENDMAIL_FROM, FE_SENDMAIL_SUBJECT, FE_SENDMAIL_REPLY_TO, FE_SENDMAIL_FLAG_AUTO_SUBMIT,
FE_SENDMAIL_GR_ID, FE_SENDMAIL_X_ID, FE_SENDMAIL_X_ID2, FE_SENDMAIL_X_ID3];
FE_SENDMAIL_GR_ID, FE_SENDMAIL_X_ID, FE_SENDMAIL_X_ID2, FE_SENDMAIL_X_ID3, FE_SENDMAIL_BODY_MODE,
FE_SENDMAIL_BODY_HTML_ENTITY, FE_SENDMAIL_SUBJECT_HTML_ENTITY];
foreach ($list as $key) {
Support::setIfNotSet($fe, $key);
......
......@@ -105,12 +105,16 @@ class SendMail {
}
// Subject
if (empty($mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY]) || $mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY] !== MODE_ENCODE) {
if (empty($mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY]) ||
($mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY] !== MODE_ENCODE &&
$mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY] !== MODE_NONE)) {
$mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY] = MODE_DECODE;
}
// Body
if (empty($mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY]) || $mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY] !== MODE_ENCODE) {
if (empty($mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY]) ||
($mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY] !== MODE_ENCODE &&
$mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY] !== MODE_NONE)) {
$mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY] = MODE_DECODE;
}
......@@ -179,7 +183,7 @@ class SendMail {
$encodedSubject = Support::escapeDoubleTick($encodedSubject); // now, escape double ticks.
$args[] = '-u "' . $encodedSubject . '"';;
$args[] = '-u "' . $encodedSubject . '"';
}
if (!empty($mailConfig[SENDMAIL_TOKEN_BODY])) {
......@@ -330,7 +334,7 @@ class SendMail {
break;
case SENDMAIL_TOKEN_ATTACHMENT_FILE:
if ($downloadMode == '') { // Set only if not explicit given.
if ($downloadMode == '') { // Set only if not explicitly given.
$downloadMode = DOWNLOAD_MODE_FILE;
}
break;
......@@ -338,7 +342,7 @@ class SendMail {
case SENDMAIL_TOKEN_ATTACHMENT_URL:
case SENDMAIL_TOKEN_ATTACHMENT_URL_PARAM:
case SENDMAIL_TOKEN_ATTACHMENT_PAGE:
if ($downloadMode == '') { // Set only if not explicit given.
if ($downloadMode == '') { // Set only if not explicitly given.
$downloadMode = DOWNLOAD_MODE_PDF;
}
break;
......
......@@ -111,7 +111,8 @@ class HelperFormElementTest extends TestCase {
$list = [FE_TYPE, FE_SLAVE_ID, FE_SQL_VALIDATE, FE_SQL_BEFORE, FE_SQL_INSERT, FE_SQL_UPDATE, FE_SQL_DELETE,
FE_SQL_AFTER, FE_EXPECT_RECORDS, FE_REQUIRED_LIST, FE_MESSAGE_FAIL, FE_SENDMAIL_TO, FE_SENDMAIL_CC,
FE_SENDMAIL_BCC, FE_SENDMAIL_FROM, FE_SENDMAIL_SUBJECT, FE_SENDMAIL_REPLY_TO, FE_SENDMAIL_FLAG_AUTO_SUBMIT,
FE_SENDMAIL_GR_ID, FE_SENDMAIL_X_ID, FE_SENDMAIL_X_ID2, FE_SENDMAIL_X_ID3];
FE_SENDMAIL_GR_ID, FE_SENDMAIL_X_ID, FE_SENDMAIL_X_ID2, FE_SENDMAIL_X_ID3, FE_SENDMAIL_BODY_MODE,
FE_SENDMAIL_BODY_HTML_ENTITY, FE_SENDMAIL_SUBJECT_HTML_ENTITY];
$expect = array();
foreach ($list as $key) {
......
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