Commit 1835d381 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch '5318-sendmail-parameters-speaking-word' into 'master'

5318 sendmail parameters speaking word

See merge request !37
parents 612e79bd 8e1e30a4
......@@ -5506,10 +5506,19 @@ Column: _sendmail
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>]
[|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>]
[|C][d:<filename of the attachment>][|F:<file to attach>][|u:<url>][|p:<T3 uri>]
Send text emails. Every mail will be logged in the table `mailLog`. Attachments are supported.
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>]
Send emails. Every mail will be logged in the table `mailLog`. Attachments are supported.
**Syntax**
......@@ -5520,50 +5529,63 @@ Send text emails. Every mail will be logged in the table `mailLog`. Attachments
..
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
|**Token** | **Parameter** |**Description** |**Required**|
+==========+========================================+==================================================================================================+============+
| f | email |**FROM**: Sender of the email. Optional: 'realname <john@doe.com>' | yes |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| t | email[,email] |**TO**: Comma separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| c | email[,email] |**CC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| B | email[,email] |**BCC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| r | REPLY-TO:email |**Reply-to**: Email address to reply to (if different from sender) | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| s | Subject |**Subject**: Subject of the email | yes |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| b | Body |**Body**: Message - see also: `html-formatting`_ | yes |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| h | Mail header |**Custom mail header**: Separate multiple header with \\r\\n | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| F | Attach file |**Attachment**: File to attach to the mail. Repeatable. | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| u | Attach created PDF of a given URL |**Attachment**: Convert the given URL to a PDF and attach it the mail. Repeatable. | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| p | Attach created PDF of a given T3 URL |**Attachment**: Convert the given URL to a PDF and attach it the mail. Repeatable. | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| d | Filename of the attachment |**Attachment**: Useful for URL to PDF converted attachments. Repeatable. | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| C | Concat multiple F|p|u| together |**Attachment**: All following (until the next 'C') 'F|p|u' concatenated to one attachment. | |
| | | Repeatable. | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| A | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| g | grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| x | xId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| y | xId2 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| z | xId3 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| e | encode|decode|none |**Subject**: will be htmlspecialchar() encoded, decoded (default) or none (untouched) | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| E | encode|decode|none |**Body**: will be htmlspecialchar() encoded, decoded (default) or none (untouched). | |
+----------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
|**Token** | **Parameter** |**Description** |**Required**|
+============+========================================+==================================================================================================+============+
| f | email |**FROM**: Sender of the email. Optional: 'realname <john@doe.com>' | yes |
| from | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| t | email[,email] |**TO**: Comma separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
| to | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| c | email[,email] |**CC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
| cc | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| B | email[,email] |**BCC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
| bcc | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| r | REPLY-TO:email |**Reply-to**: Email address to reply to (if different from sender) | |
| reply-to | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| s | Subject |**Subject**: Subject of the email | yes |
| subject | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| b | Body |**Body**: Message - see also: `html-formatting`_ | yes |
| body | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| h | Mail header |**Custom mail header**: Separate multiple header with \\r\\n | |
| header | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| F | Attach file |**Attachment**: File to attach to the mail. Repeatable. | |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| u | Attach created PDF of a given URL |**Attachment**: Convert the given URL to a PDF and attach it the mail. Repeatable. | |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| p | Attach created PDF of a given T3 URL |**Attachment**: Convert the given URL to a PDF and attach it the mail. Repeatable. | |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| d | Filename of the attachment |**Attachment**: Useful for URL to PDF converted attachments. Repeatable. | |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| C | Concat multiple F|p|u| together |**Attachment**: All following (until the next 'C') 'F|p|u' concatenated to one attachment. | |
| | | Repeatable. | |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| A | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
| autosubmit | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| g | grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
| grid | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| x | xId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
| xid | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| y | xId2 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
| xid2 | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| z | xId3 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
| xid3 | | | yes |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| e | encode|decode|none |**Subject**: will be htmlspecialchar() encoded, decoded (default) or none (untouched) | |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| E | encode|decode|none |**Body**: will be htmlspecialchar() encoded, decoded (default) or none (untouched). | |
+------------+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
* **e|E**: By default, QFQ stores values 'htmlspecialchars()' encoded. If such values have to send by email, the html entities are
unwanted. Therefore the default setting for 'subject' und 'body' is to decode the values via 'htmlspecialchars_decode()'.
......
......@@ -1109,24 +1109,38 @@ const EXISTING_PATH_FILE_NAME = '_existingPathFileName';
//SENDMAIL
const SENDMAIL_TOKEN_RECEIVER = 't';
const SENDMAIL_TOKEN_RECEIVER_LONG = 'to';
const SENDMAIL_TOKEN_SENDER = 'f';
const SENDMAIL_TOKEN_SENDER_LONG = 'from';
const SENDMAIL_TOKEN_SUBJECT = 's';
const SENDMAIL_TOKEN_SUBJECT_LONG = 'subject';
const SENDMAIL_TOKEN_BODY = 'b';
const SENDMAIL_TOKEN_BODY_LONG = 'body';
const SENDMAIL_TOKEN_REPLY_TO = 'r';
const SENDMAIL_TOKEN_REPLY_TO_LONG = 'reply-to';
const SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT = 'A';
const SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT_LONG = 'autosubmit';
const SENDMAIL_TOKEN_GR_ID = 'g';
const SENDMAIL_TOKEN_GR_ID_LONG = 'grid';
const SENDMAIL_TOKEN_X_ID = 'x';
const SENDMAIL_TOKEN_X_ID_LONG = 'xid';
const SENDMAIL_TOKEN_X_ID2 = 'y';
const SENDMAIL_TOKEN_X_ID2_LONG = 'xid2';
const SENDMAIL_TOKEN_X_ID3 = 'z';
const SENDMAIL_TOKEN_X_ID3_LONG = 'xid3';
const SENDMAIL_TOKEN_HEADER = 'h';
const SENDMAIL_TOKEN_HEADER_LONG = 'header';
const SENDMAIL_TOKEN_SRC = 'S';
const SENDMAIL_TOKEN_SRC_LONG = 'source';
const SENDMAIL_TOKEN_RECEIVER_CC = 'c';
const SENDMAIL_TOKEN_RECEIVER_CC_LONG = 'cc';
const SENDMAIL_TOKEN_RECEIVER_BCC = 'B';
const SENDMAIL_TOKEN_RECEIVER_BCC_LONG = 'bcc';
const SENDMAIL_TOKEN_ATTACHMENT = 'attachment';
const SENDMAIL_TOKEN_ATTACHMENT_FILE = 'F';
const SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED = 'a'; // since 5.12.17
const SENDMAIL_TOKEN_HEADER = 'h';
const SENDMAIL_TOKEN_X_ID2 = 'y';
const SENDMAIL_TOKEN_X_ID3 = 'z';
const SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY = 'e';
const SENDMAIL_TOKEN_BODY_HTML_ENTITY = 'E';
const SENDMAIL_TOKEN_SRC = 'S';
const SENDMAIL_TOKEN_CONCAT = 'C';
const SENDMAIL_TOKEN_DOWNLOAD_FILENAME = 'd';
......
......@@ -339,7 +339,7 @@ class SendMail {
/**
* Convert a token based sendMail string into an array.
* - Each attachment (single file or mulitple concatenated files) is an array in the array.
* - Each attachment (single file or multiple concatenated files) is an array in the array.
*
* @param string $data E.g.: 't:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John ...'
* @return array
......@@ -355,6 +355,23 @@ class SendMail {
$flagSource = false;
$flagFilename = false;
$convertToShorthandToken = [
SENDMAIL_TOKEN_RECEIVER_LONG => SENDMAIL_TOKEN_RECEIVER,
SENDMAIL_TOKEN_SENDER_LONG => SENDMAIL_TOKEN_SENDER,
SENDMAIL_TOKEN_SUBJECT_LONG => SENDMAIL_TOKEN_SUBJECT,
SENDMAIL_TOKEN_BODY_LONG => SENDMAIL_TOKEN_BODY,
SENDMAIL_TOKEN_RECEIVER_CC_LONG => SENDMAIL_TOKEN_RECEIVER_CC,
SENDMAIL_TOKEN_RECEIVER_BCC_LONG => SENDMAIL_TOKEN_RECEIVER_BCC,
SENDMAIL_TOKEN_REPLY_TO_LONG => SENDMAIL_TOKEN_REPLY_TO,
SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT_LONG => SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT,
SENDMAIL_TOKEN_GR_ID_LONG => SENDMAIL_TOKEN_GR_ID,
SENDMAIL_TOKEN_X_ID_LONG => SENDMAIL_TOKEN_X_ID,
SENDMAIL_TOKEN_X_ID2_LONG => SENDMAIL_TOKEN_X_ID2,
SENDMAIL_TOKEN_X_ID3_LONG => SENDMAIL_TOKEN_X_ID3,
SENDMAIL_TOKEN_HEADER_LONG => SENDMAIL_TOKEN_HEADER,
SENDMAIL_TOKEN_SRC_LONG => SENDMAIL_TOKEN_SRC,
];
$param = explode(PARAM_DELIMITER, $data);
// Iterate over all parameter: use token as key. Collect corresponding attachments arguments in separate array elements
......@@ -364,12 +381,22 @@ class SendMail {
continue;
}
$token = $line[0];
if (strlen($line) > 2 && $line[1] != PARAM_TOKEN_DELIMITER) {
$tokenAndValue = explode(PARAM_TOKEN_DELIMITER, $line, 2);
if (count($tokenAndValue) < 2 && $tokenAndValue[0] !== SENDMAIL_TOKEN_CONCAT) {
throw new UserFormException('Missing token delimiter "' . PARAM_TOKEN_DELIMITER . '" in: ' . $line, ERROR_UNKNOWN_TOKEN);
}
$token = $tokenAndValue[0];
// convert speaking word tokens to shorthand
if (strlen($token) > 1) {
$token = strtolower($token); // speaking word tokens are all lowercase
if (isset($convertToShorthandToken[$token])) {
$token = $convertToShorthandToken[$token];
} else {
throw new UserFormException('Unknown token "' . $token . '" in: ' . $line, ERROR_UNKNOWN_TOKEN);
}
}
// Check for deprecated token.
if ($token == SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED) {
throw new UserFormException('Sendmail: Option "a:" is deprecated, please use "' . SENDMAIL_TOKEN_ATTACHMENT_FILE . '" instead', ERROR_UNKNOWN_TOKEN);
......@@ -408,7 +435,7 @@ class SendMail {
break;
default:
$args[$token] = substr($line, 2);
$args[$token] = $tokenAndValue[1];
break;
}
}
......
......@@ -30,16 +30,22 @@ class SendMailTest extends \PHPUnit_Framework_TestCase {
$expect = [];
$this->assertEquals($expect, $result);
// Simple 'fixed position' DEPRECATED - not sure if it's ok that the array is not fillled up to the maximum.
// Simple 'fixed position' DEPRECATED - not sure if it's ok that the array is not filled up to the maximum.
// $result = $this->sendMail->parseStringToArray('john@doe.com|jane@miller.com|Latest|Dear John');
// $expect = ['john@doe.com', 'jane@miller.com', 'Latest', 'Dear John'];
// $this->assertEquals($expect, $result);
// Simple 'token based'
// Simple 'shorthand token based'
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John');
$expect = [SENDMAIL_TOKEN_RECEIVER => 'john@doe.com', SENDMAIL_TOKEN_SENDER => 'jane@miller.com',
SENDMAIL_TOKEN_SUBJECT => 'Latest', SENDMAIL_TOKEN_BODY => 'Dear John'];
$this->assertEquals($expect, $result);
// Simple 'speaking word based'
$result = $this->sendMail->parseStringToArray('to:john@doe.com|from:jane@miller.com|subject:Latest|body:Dear John');
$this->assertEquals($expect, $result);
// Simple 'speaking word / shorthand' mixed tokens
$result = $this->sendMail->parseStringToArray('to:john@doe.com|f:jane@miller.com|s:Latest|body:Dear John');
$this->assertEquals($expect, $result);
// All (but attachment) 'token based'
$result = $this->sendMail->parseStringToArray('t:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John|r:reply@doe.com|A:on|g:123|x:234|c:july@doe.com,steve@doe.com|B:ceo@doe.com|h:Auto-Submit: fake|y:345|z:456|S:test.php');
......@@ -49,6 +55,9 @@ class SendMailTest extends \PHPUnit_Framework_TestCase {
SENDMAIL_TOKEN_RECEIVER_CC => 'july@doe.com,steve@doe.com', SENDMAIL_TOKEN_RECEIVER_BCC => 'ceo@doe.com',
SENDMAIL_TOKEN_HEADER => 'Auto-Submit: fake', SENDMAIL_TOKEN_X_ID2 => '345', SENDMAIL_TOKEN_X_ID3 => '456', SENDMAIL_TOKEN_SRC => 'test.php'];
$this->assertEquals($expect, $result);
// All (but attachment) 'speaking word based'
$result = $this->sendMail->parseStringToArray('to:john@doe.com|from:jane@miller.com|subject:Latest|body:Dear John|reply-to:reply@doe.com|autosubmit:on|grid:123|xid:234|cc:july@doe.com,steve@doe.com|bcc:ceo@doe.com|header:Auto-Submit: fake|xid2:345|xid3:456|source:test.php');
$this->assertEquals($expect, $result);
// Single attachment 'token based'
$attach = [['F:fileadmin/test1.pdf']];
......
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