Commit 3604c560 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Report / sendmail now controller via token

parent 81605a73
......@@ -3347,6 +3347,8 @@ Type: sendmail
'Auto-Submitted: auto-send' - this suppress a) OoO replies, b) forwarding of emails.
* *sendMailGrId* - Will be copied to the mailLog record. Helps to setup specific logfile queries.
* *sendMailXId* - Will be copied to the mailLog record. Helps to setup specific logfile queries.
* *sendMailXId2* - Will be copied to the mailLog record. Helps to setup specific logfile queries.
* *sendMailXId3* - Will be copied to the mailLog record. Helps to setup specific logfile queries.
* 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 one, use the STORE_RECORD. E.g. `{{id:R}}`
......@@ -5197,7 +5199,7 @@ Easily create Email links.
Column: _sendmail
^^^^^^^^^^^^^^^^^
<TO:email[,email]>|<FROM:email>|<subject>|<body>|[<REPLY-TO:email>]|[<flag autosubmit: on /off>]|[<grid>]|[xId]|<CC:email[,email]>|<BCC:email[,email]>
t:<TO:email[,email]>|f:<FROM:email>|s:<subject>|b:<body>|[F:<REPLY-TO:email>]|[a:<flag autosubmit: on /off>]|[g:<grid>]|[x:xId]|[c:<CC:email[,email]]>|[B:<BCC:email[,email]]|[y:xId2]|[z:xId3]>
Send text emails. Every mail will be logged in the table `mailLog`.
......@@ -5206,32 +5208,37 @@ Send text emails. Every mail will be logged in the table `mailLog`.
::
SELECT "john@doe.com|jane@doe.com|Reminder tomorrow|Please dont miss the meeting tomorrow" AS _sendmail
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow" AS _sendmail
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow|a:off|g:1|x:2|y:3|z:4" AS _sendmail
..
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|**Parameter** |**Description** |**Required**|
|***Token** | **Parameter** |**Description** |**Required**|
+============================================================+==========================================================================================+============+
|TO:email[,email] |Comma-separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
| t | email[,email] |Comma-separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|FROM:email |Sender of the email. Optional: 'realname <john@doe.com>' | yes |
| f | FROM:email |Sender of the email. Optional: 'realname <john@doe.com>' | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|subject |Subject of the email | yes |
| s | subject |Subject of the email | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|body |Message | yes |
| b | body |Message | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|REPLY-TO:email |Email address to reply to (if different from sender) | |
| F | REPLY-TO:email |Email address to reply to (if different from sender) | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
| a | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
| g | grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|xId |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 | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|CC:email[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
| y | xId2 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|BCC:email[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
| z | xId3 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| c | email[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| B | mail[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
......
......@@ -142,7 +142,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] as $key) {
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) {
if (!isset($mailEntry[$key])) {
$mailEntry[$key] = '';
}
......@@ -184,6 +185,9 @@ class AutoCron {
$mail[SENDMAIL_IDX_X_ID] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_X_ID]);
$mail[SENDMAIL_IDX_RECEIVER_CC] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_CC]);
$mail[SENDMAIL_IDX_RECEIVER_BCC] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_BCC]);
$mail[SENDMAIL_IDX_X_ID2] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_X_ID2]);
$mail[SENDMAIL_IDX_X_ID3] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_X_ID3]);
$mail[SENDMAIL_IDX_SRC] = "AutoCron: Cron.id=" . $job[COLUMN_ID];
// Mail: send
......
......@@ -873,6 +873,8 @@ const FE_SENDMAIL_REPLY_TO = 'sendMailReplyTo'; // Reply to email address
const FE_SENDMAIL_FLAG_AUTO_SUBMIT = 'sendMailFlagAutoSubmit'; // on|off - if 'on', suppresses OoO answers from receivers.
const FE_SENDMAIL_GR_ID = 'sendMailGrId'; // gr_id: used to classify mail log entries ind table mailLog
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_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
......@@ -1064,7 +1066,23 @@ const SENDMAIL_IDX_GR_ID = 6;
const SENDMAIL_IDX_X_ID = 7;
const SENDMAIL_IDX_RECEIVER_CC = 8;
const SENDMAIL_IDX_RECEIVER_BCC = 9;
const SENDMAIL_IDX_SRC = 10;
const SENDMAIL_IDX_X_ID2 = 10;
const SENDMAIL_IDX_X_ID3 = 11;
const SENDMAIL_IDX_SRC = 12;
const SENDMAIL_TOKEN_RECEIVER = 't';
const SENDMAIL_TOKEN_SENDER = 'f';
const SENDMAIL_TOKEN_SUBJECT = 's';
const SENDMAIL_TOKEN_BODY = 'b';
const SENDMAIL_TOKEN_REPLY_TO = 'F';
const SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT = 'a';
const SENDMAIL_TOKEN_GR_ID = 'g';
const SENDMAIL_TOKEN_X_ID = 'x';
const SENDMAIL_TOKEN_RECEIVER_CC = 'c';
const SENDMAIL_TOKEN_RECEIVER_BCC = 'B';
const SENDMAIL_TOKEN_X_ID2 = 'y';
const SENDMAIL_TOKEN_X_ID3 = 'z';
const SENDMAIL_TOKEN_SRC = 'S';
//Report: Column Token
const COLUMN_PPAGE = "Page";
......
......@@ -86,6 +86,11 @@ $UPDATE_ARRAY = array(
"ALTER TABLE `FormElement` CHANGE `type` `type` ENUM( 'checkbox', 'date', 'datetime', 'dateJQW', 'datetimeJQW', 'extra', 'gridJQW', 'text', 'editor', 'annotate', 'time', 'note', 'password', 'radio', 'select', 'subrecord', 'upload', 'annotate', 'fieldset', 'pill', 'templateGroup', 'beforeLoad', 'beforeSave', 'beforeInsert', 'beforeUpdate', 'beforeDelete', 'afterLoad', 'afterSave', 'afterInsert', 'afterUpdate', 'afterDelete', 'sendMail', 'paste' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'text';",
],
'0.25.3' => [
"ALTER TABLE `MailLog` ADD `xId2` INT NOT NULL AFTER `xId`, ADD `xId3` INT NOT NULL AFTER `xId2`",
],
);
......
......@@ -252,6 +252,8 @@ class FormAction {
$mail[SENDMAIL_IDX_RECEIVER_CC] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_CC]);
$mail[SENDMAIL_IDX_RECEIVER_BCC] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_BCC]);
$mail[SENDMAIL_IDX_SRC] = "FormId: " . $feSpecAction[FE_FORM_ID] . ", FormElementId: " . $feSpecAction['id'];
$mail[SENDMAIL_IDX_X_ID2] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_X_ID2]);
$mail[SENDMAIL_IDX_X_ID3] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_X_ID3]);
// Mail: send
new Sendmail($mail);
......
......@@ -746,7 +746,8 @@ class Report {
case "sendmail":
// '<receiver1>,<receiver2>,...|<sender>|<subject>|<body>|<reply-to>|<flag autosubmit: on /off>'
$mailarr = explode("|", $columnValue);
// $mailarr = explode("|", $columnValue);
$mailarr = $this->sendmailConvertToken($columnValue);
if (count($mailarr) < 4) {
throw new SyntaxReportException ("Too few parameter for sendmail: $columnValue", ERROR_TOO_FEW_PARAMETER_FOR_SENDMAIL, null, __FILE__, __LINE__, $this->fr_error);
}
......@@ -775,6 +776,18 @@ class Report {
$mailarr[SENDMAIL_IDX_RECEIVER_BCC] = '';
}
if (!isset($mailarr[SENDMAIL_IDX_X_ID])) {
$mailarr[SENDMAIL_IDX_X_ID] = '0';
}
if (!isset($mailarr[SENDMAIL_IDX_X_ID2])) {
$mailarr[SENDMAIL_IDX_X_ID] = '0';
}
if (!isset($mailarr[SENDMAIL_IDX_X_ID3])) {
$mailarr[SENDMAIL_IDX_X_ID] = '0';
}
$mailarr[SENDMAIL_IDX_SRC] = "Report: T3 pageId=" . $this->store->getVar('pageId', STORE_TYPO3) .
", T3 ttcontentId=" . $this->store->getVar('ttcontentUid', STORE_TYPO3) .
", Level=" . $full_level;
......@@ -1230,4 +1243,47 @@ class Report {
return false;
}
private function sendmailConvertToken($data) {
$sendmailToken = [SENDMAIL_TOKEN_RECEIVER => SENDMAIL_IDX_RECEIVER,
SENDMAIL_TOKEN_SENDER => SENDMAIL_IDX_SENDER,
SENDMAIL_TOKEN_SUBJECT => SENDMAIL_IDX_SUBJECT,
SENDMAIL_TOKEN_BODY => SENDMAIL_IDX_BODY,
SENDMAIL_TOKEN_REPLY_TO => SENDMAIL_IDX_REPLY_TO,
SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT => SENDMAIL_IDX_FLAG_AUTO_SUBMIT,
SENDMAIL_TOKEN_GR_ID => SENDMAIL_IDX_GR_ID,
SENDMAIL_TOKEN_X_ID => SENDMAIL_IDX_X_ID,
SENDMAIL_TOKEN_RECEIVER_CC => SENDMAIL_IDX_RECEIVER_CC,
SENDMAIL_TOKEN_RECEIVER_BCC => SENDMAIL_IDX_RECEIVER_BCC,
SENDMAIL_TOKEN_SRC => SENDMAIL_IDX_SRC,
SENDMAIL_TOKEN_X_ID2 => SENDMAIL_IDX_X_ID2,
SENDMAIL_TOKEN_X_ID3 => SENDMAIL_IDX_X_ID3
];
if (!isset($data[1]) || $data[1] != ':') {
return explode('|', $data);
}
$segments = explode('|', $data);
$arr = ['', '', '', '', '', '', '', '', '', '', '', '', ''];
foreach ($segments AS $line) {
$piece = explode(':', $line, 2);
if (empty($piece[0])) {
throw new UserReportException ("Missing token in sendmail", ERROR_UNKNOWN_TOKEN);
}
if (!isset($sendmailToken[$piece[0]])) {
throw new UserReportException ("Unknown token in sendmail: $piece[0]", ERROR_UNKNOWN_TOKEN);
}
$idx = $sendmailToken[$piece[0]];
$arr[$idx] = empty($piece[1]) ? '' : $piece[1];
}
return ($arr);
}
}
......@@ -119,10 +119,12 @@ class Sendmail {
$log[4] = $header;
$log[5] = empty($mailarr[SENDMAIL_IDX_GR_ID]) ? 0 : $mailarr[SENDMAIL_IDX_GR_ID];
$log[6] = empty($mailarr[SENDMAIL_IDX_X_ID]) ? 0 : $mailarr[SENDMAIL_IDX_X_ID];
$log[7] = empty($mailarr[SENDMAIL_IDX_SRC]) ? 0 : $mailarr[SENDMAIL_IDX_SRC];
$log[7] = empty($mailarr[SENDMAIL_IDX_X_ID2]) ? 0 : $mailarr[SENDMAIL_IDX_X_ID2];
$log[8] = empty($mailarr[SENDMAIL_IDX_X_ID3]) ? 0 : $mailarr[SENDMAIL_IDX_X_ID3];
$log[9] = empty($mailarr[SENDMAIL_IDX_SRC]) ? 0 : $mailarr[SENDMAIL_IDX_SRC];
$db = new Database();
$db->sql('INSERT INTO MailLog (`receiver`, `sender`, `subject`, `body`, `header`, `grId`, `xId`, `src`, `modified`, `created`) VALUES ( ?, ? ,?, ?, ? ,?, ?, ?, NOW(), NOW() )', ROW_REGULAR, $log);
$db->sql('INSERT INTO MailLog (`receiver`, `sender`, `subject`, `body`, `header`, `grId`, `xId`, `xId2`, `xId3`, `src`, `modified`, `created`) VALUES ( ?, ? , ? , ? ,?, ?, ? ,?, ?, ?, NOW(), NOW() )', ROW_REGULAR, $log);
}
}
......@@ -360,6 +360,8 @@ CREATE TABLE IF NOT EXISTS `MailLog` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`grId` INT(11) NOT NULL DEFAULT '0',
`xId` INT(11) NOT NULL DEFAULT '0',
`xId2` INT(11) NOT NULL DEFAULT '0',
`xId3` INT(11) NOT NULL DEFAULT '0',
`receiver` TEXT NOT NULL,
`sender` VARCHAR(255) NOT NULL DEFAULT '',
`subject` VARCHAR(255) NOT NULL DEFAULT '',
......
Markdown is supported
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